Unverified Commit 62219bd0 authored by Jesse Mapel's avatar Jesse Mapel Committed by GitHub
Browse files

Added the ability to pass lists instead of directories and filters to kerneldbgen (#3398)

* Added file list option to spicedbgen

* First pass at actual params

* Fixed scoping error

* Updated no parameters selected check

* Added historty comment to SpiceDbGen

* Fixed weird type logic
parent c7c6947a
Loading
Loading
Loading
Loading
+77 −17
Original line number Diff line number Diff line
@@ -74,12 +74,10 @@ SpiceDbGen::SpiceDbGen(QString type) {
PvlObject SpiceDbGen::Direct(QString quality, QString location,
                             std::vector<QString> &filter, double startOffset, double endOffset) {
  PvlObject result;
  QString type = "none";

  for (unsigned int i = 0; i < filter.size(); ++i) {
    //Create a list of all of the files matching the current filter
    QStringList files = GetFiles(FileName(location), filter[i]);
    PvlObject pvlKernel("change");

    // Throw an error if no files are being added to this database for
    // this filter/regex
@@ -105,32 +103,94 @@ PvlObject SpiceDbGen::Direct(QString quality, QString location,
    if (grp->name() == "No coverage" || grp->name() == "Null") {
      result.deleteGroup(grp->name());
    }
    // This is used for the first time thru the while loop
    // DO NOT increment grp here
    else if (type == "none") {
      type = grp->name();
    else if (grp->name() == p_type) {
      grp->setName("Selection");
      grp++;
    }
    else {
      QString message = "A kernel of type [" + grp->name() + "] has been found in a directory for type [" + p_type + "]" ;
      throw IException(IException::Programmer, message, _FILEINFO_);
      break;
    }
  }

  if (p_type == "SPK") {
    result.setName("SpacecraftPosition");
  }
  else if (p_type == "CK") {
    result.setName("SpacecraftPointing");
  }

  return result;
}
    else if (grp->name() == type) {


/**
 * Creates a Pvl object that stores all of the kernels specified by a list
 *
 * @param quality   The quality of the kernels that are being filtered into
 *                  the database. For example, "Reconstructed".
 *
 * @param fileList  The list of files to create a database for. The files must
 *                  be ordered in ascending priority. That is, if two kernels
 *                  cover the same time period, the kernel later in the file
 *                  will be used.
 *
 * @return PvlObject
 *
 * @internal
 *   @history 2019-08-13 Jesse Mapel Created method that takes a file list.
 *
 * @throws Isis::iException::Message
*/
PvlObject SpiceDbGen::Direct(QString quality, FileList fileList,
                             double startOffset, double endOffset) {
  PvlObject result;

  // Throw an error if no files are being added to this database for
  // this filter/regex
  if (fileList.empty()) {
    QString message = "Input filelist is empty!";
    throw IException(IException::User, message, _FILEINFO_);
  }

  for (int fileNum = 0 ; fileNum < fileList.size() ; fileNum++) {
    FileName currFile = fileList[fileNum];
    PvlGroup selection = AddSelection(currFile, startOffset, endOffset);
    selection += PvlKeyword("Type", quality);
    result.addGroup(selection);
  }

  // Check each group to make sure it is the same type as others
  PvlObject::PvlGroupIterator grp = result.beginGroup();

  while (grp != result.endGroup()) {
    // The kernel did not have any time coverage, so ignore it
    if (grp->name() == "No coverage" || grp->name() == "Null") {
      result.deleteGroup(grp->name());
    }
    else if (grp->name() == p_type) {
      grp->setName("Selection");
      grp++;
    }
    else {
      QString message = "A kernel of type [" + grp->name() + "] has been found in a directory for type [" + type + "]" ;
      QString message = "A kernel of type [" + grp->name() + "] has been found in a directory for type [" + p_type + "]" ;
      throw IException(IException::Programmer, message, _FILEINFO_);
      break;
    }
  }

  if (type == "SPK") {
  if (p_type == "SPK") {
    result.setName("SpacecraftPosition");
  }
  else if (type == "CK") {
  else if (p_type == "CK") {
    result.setName("SpacecraftPointing");
  }

  return result;
}


/**
  * Essenetially a method call to the underlying QDir class which will filter
  * the files needed by Direct(). Files are returned in order of the time they
+7 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <SpiceUsr.h>

#include "FileName.h"
#include "FileList.h"
#include "IException.h"
#include "IString.h"
#include "KernelDb.h"
@@ -52,6 +53,8 @@
 *                            now select spice "time intervals" at the level specified. This is
 *                            either a SPICE Segment (coarse) or a SPICE interval (fine.)
 *                            Fixes #5410.
 *   @history 2019-08-13 Jesse Mapel - Added the ability to pass an explicit lsit
 *                           of files to the Direct method. Fixes #3390.
 *
 */
class SpiceDbGen {
@@ -60,6 +63,8 @@ class SpiceDbGen {
    SpiceDbGen(QString type);
    Isis::PvlObject Direct(QString quality, QString location,
                           std::vector<QString> & filter, double startOffset, double endOffset);
    Isis::PvlObject Direct(QString quality, Isis::FileList fileList,
                           double startOffset, double endOffset);
    void FurnishDependencies(QList<Isis::FileName> sclks, QList<Isis::FileName> fks,
                             QList<Isis::FileName> extras);
    void setCoverageLevel(QString level);
+76 −10
Original line number Diff line number Diff line
@@ -156,6 +156,9 @@
      Added the LEVEL=(SEGMENT*, INTERVAL) option to specify the time coverage level to be used for the generated database. SPICE segements are made up of SPICE intervals.
      Segments (the only option in the past) are now the default, but interval can be selected if needed. Fixes #5410.
    </change>
    <change name="Jesse Mapel" date="2019-08-13">
      Added the ability to use a list of kernels instead of a location and filters. Fixes #3390.
    </change>
  </history>

  <groups>
@@ -291,6 +294,27 @@
          to ASCII order and added to the list of available kernels.
        </description>
      </parameter>
      <parameter name="PREDICTLIST">
        <type>filename</type>
        <fileMode>input</fileMode>
        <brief>
          Prioritized list of predict quality kernels
        </brief>
        <description>
          This parameter is used to specify a file list that contains the
          kernel or kernels to be identified as predicted. The order of the
          kernels in the file list will be retained with kernels later in the
          list taking precedence when multiple kernels cover the same time
          range.
        </description>
        <filter>
          *.txt *.lis
        </filter>
        <exclusions>
          <item>PREDICTDIR</item>
          <item>PREDICTFILTER</item>
        </exclusions>
      </parameter>
    </group>
    <group name="Reconstructed">
      <parameter name="RECONDIR">
@@ -327,6 +351,27 @@
          <item>none</item>
        </default>
      </parameter>
      <parameter name="RECONLIST">
        <type>filename</type>
        <fileMode>input</fileMode>
        <brief>
          Prioritized list of reconstructed quality kernels
        </brief>
        <description>
          This parameter is used to specify a file list that contains the
          kernel or kernels to be identified as reconstructed. The order of the
          kernels in the file list will be retained with kernels later in the
          list taking precedence when multiple kernels cover the same time
          range.
        </description>
        <filter>
          *.txt *.lis
        </filter>
        <exclusions>
          <item>RECONDIR</item>
          <item>RECONFILTER</item>
        </exclusions>
      </parameter>
    </group>
    <group name="Smithed">
      <parameter name="SMITHEDDIR">
@@ -363,6 +408,27 @@
          <item>none</item>
        </default>
      </parameter>
      <parameter name="SMITHEDLIST">
        <type>filename</type>
        <fileMode>input</fileMode>
        <brief>
          Prioritized list of smithed quality kernels
        </brief>
        <description>
          This parameter is used to specify a file list that contains the
          kernel or kernels to be identified as smithed. The order of the
          kernels in the file list will be retained with kernels later in the
          list taking precedence when multiple kernels cover the same time
          range.
        </description>
        <filter>
          *.txt *.lis
        </filter>
        <exclusions>
          <item>SMITHEDDIR</item>
          <item>SMITHEDFILTER</item>
        </exclusions>
      </parameter>
    </group>
    <group name="Offset">
      <parameter name="STARTOFFSET">
+40 −10
Original line number Diff line number Diff line
#include "Isis.h"
#include "SpiceDbGen.h"
#include "FileList.h"
#include "iTime.h"

using namespace std;
@@ -80,6 +81,15 @@ void IsisMain() {
      grp++;
    }
  }
  else if (ui.WasEntered("PREDICTLIST")) {
    FileList kernList(ui.GetFileName("PREDICTLIST"));
    PvlObject result = sdg.Direct("Predicted", kernList, startOffset, endOffset);
    PvlObject::PvlGroupIterator grp = result.beginGroup();
    while(grp != result.endGroup()) {
      selections.addGroup(*grp);
      grp++;
    }
  }

  if (ui.GetString("RECONDIR") != "none" &&
      ui.GetString("RECONFILTER") != "none") {
@@ -95,6 +105,15 @@ void IsisMain() {
      grp++;
    }
  }
  else if (ui.WasEntered("RECONLIST")) {
    FileList kernList(ui.GetFileName("RECONLIST"));
    PvlObject result = sdg.Direct("Reconstructed", kernList, startOffset, endOffset);
    PvlObject::PvlGroupIterator grp = result.beginGroup();
    while(grp != result.endGroup()) {
      selections.addGroup(*grp);
      grp++;
    }
  }

  if (ui.GetString("SMITHEDDIR") != "none" &&
      ui.GetString("SMITHEDFILTER") != "none") {
@@ -110,12 +129,23 @@ void IsisMain() {
      grp++;
    }
  }
  else if (ui.WasEntered("SMITHEDLIST")) {
    FileList kernList(ui.GetFileName("SMITHEDLIST"));
    PvlObject result = sdg.Direct("Smithed", kernList, startOffset, endOffset);
    PvlObject::PvlGroupIterator grp = result.beginGroup();
    while(grp != result.endGroup()) {
      selections.addGroup(*grp);
      grp++;
    }
  }

  //if (filter == ""){
  if (!ui.WasEntered("PREDICTFILTER") && !ui.WasEntered("RECONFILTER") &&
      !ui.WasEntered("SMITHEDFILTER")) {
  if (!(ui.WasEntered("PREDICTFILTER") || ui.WasEntered("PREDICTLIST")) &&
      !(ui.WasEntered("RECONFILTER")   || ui.WasEntered("RECONLIST")) &&
      !(ui.WasEntered("SMITHEDFILTER") || ui.WasEntered("SMITHEDLIST"))) {
    QString message =
      "You must enter a filter AND directory for at least one type of kernel";
      "No kernel selection arguments were entered. A directory and filter or a "
      "list must be entered for at least one quality of kernel.";
    throw IException(IException::User, message, _FILEINFO_);
  }