14#include "CameraFactory.h"
16#include "IException.h"
20#include "Preference.h"
21#include "Preference.h"
23#include "PvlKeyword.h"
156 return findLast(
"TargetAttitudeShape", lab);
177 return findLast(
"TargetPosition", lab);
198 return findAll(
"SpacecraftPointing", lab);
218 return findLast(
"SpacecraftClock", lab);
239 return findLast(
"SpacecraftPosition", lab);
301 return findLast(
"InstrumentAddendum", lab);
343 if (queues.size() > 0 && queues.at(0).size() > 0) {
344 lastKernel = queues.at(0).top();
369 PvlObject &cube = lab.findObject(
"IsisCube");
370 int cameraVersion = -1;
375 catch (IException &) {
380 priority_queue<Kernel> emptyKernelQueue;
381 emptyKernelQueue.push(
Kernel());
382 queues.push_back(emptyKernelQueue);
390 if (cube.hasGroup(
"Instrument")) {
391 start = (QString) cube.findGroup(
"Instrument")[
"StartTime"];
393 if (cube.findGroup(
"Instrument").hasKeyword(
"StopTime")) {
394 end = ((QString) cube.findGroup(
"Instrument")[
"StopTime"]);
397 end = ((QString) cube.findGroup(
"Instrument")[
"StartTime"]);
404 priority_queue<Kernel> filesFound;
407 for (
int groupIndex = obj.groups() - 1; groupIndex >= 0; groupIndex--) {
410 PvlGroup &grp = obj.group(groupIndex);
413 if (!grp.isNamed(
"Selection"))
continue;
418 if (grp.hasKeyword(
"Type")) {
419 type = (QString) grp[
"Type"];
432 bool startMatches =
matches(lab, grp, start, cameraVersion);
433 bool endMatches =
matches(lab, grp, end, cameraVersion);
435 if (startMatches && endMatches) {
440 else if (startMatches) {
443 for (
int endTimeIndex = obj.groups() - 1;
447 PvlGroup &endTimeGrp = obj.group(endTimeIndex);
457 if (endTimeIndex == groupIndex)
continue;
458 if (!endTimeGrp.isNamed(
"Selection"))
continue;
459 if (grp.hasKeyword(
"Type") != endTimeGrp.hasKeyword(
"Type"))
continue;
460 if (grp.hasKeyword(
"Type") &&
461 grp[
"Type"] != endTimeGrp[
"Type"])
continue;
462 if (!
matches(lab, endTimeGrp, end, cameraVersion))
continue;
465 bool betterMatch =
false;
468 bool endTimesMatch =
true;
471 for (
int keyIndex = 0;
472 !betterMatch && keyIndex < grp.keywords();
474 PvlKeyword &key = grp[keyIndex];
476 if (!key.isNamed(
"Time"))
continue;
478 iTime timeRangeStart((QString)key[0]);
479 iTime timeRangeEnd((QString)key[1]);
481 bool thisEndMatches =
matches(lab, endTimeGrp,
482 timeRangeEnd, cameraVersion);
483 endTimesMatch = endTimesMatch && thisEndMatches;
485 if (
matches(lab, endTimeGrp, start, cameraVersion)
486 &&
matches(lab, endTimeGrp, end, cameraVersion)) {
494 if (!betterMatch && endTimesMatch) {
498 while (endMatchFiles.size()) {
499 startMatchFiles.push_back(endMatchFiles[endMatchFiles.size() - 1]);
500 endMatchFiles.pop_back();
507 else if (betterMatch) {
515 queues.push_back(filesFound);
519 if (queues.size() == 0) {
520 priority_queue<Kernel> emptyKernelQueue;
521 emptyKernelQueue.push(
Kernel());
522 queues.push_back(emptyKernelQueue);
572 iTime timeToMatch,
int cameraVersion) {
581 const PvlObject &cube = lab.findObject(
"IsisCube");
582 bool matchTime = !grp.hasKeyword(
"Time");
583 bool matchKeywords =
true;
584 double startOffset = 0;
585 double endOffset = 0;
588 if (grp.hasKeyword(
"StartOffset")){
589 startOffset = (double) grp[
"StartOffset"] + 0.001;
591 if (grp.hasKeyword(
"EndOffset")){
592 endOffset = (double) grp[
"EndOffset"] + 0.001;
594 if (grp.hasKeyword(
"Instrument")){
601 for (
int keyword = 0; keyword < grp.keywords(); keyword++) {
602 PvlKeyword key = grp[keyword];
604 if (key.isNamed(
"Time")) {
607 iTime kernelStart = (QString) key[0];
608 iTime kernelEnd = (QString) key[1];
612 if ((kernelStart - startOffset <= timeToMatch) && (kernelEnd + endOffset >= timeToMatch)) {
618 const PvlGroup &inst = lab.findGroup(
"Instrument", Pvl::Traverse);
619 QString instId = (QString) inst.findKeyword(
"InstrumentId");
626 else if (key.isNamed(
"Match")) {
628 QString matchGroup = key[0];
629 QString matchKey = key[1];
630 QString matchValue = key[2];
632 QString cubeValue = cube.findGroup(matchGroup)[matchKey];
633 cubeValue = cubeValue.simplified().trimmed().toUpper();
634 matchValue = matchValue.simplified().trimmed().toUpper();
637 if (cubeValue.compare(matchValue) != 0) {
638 matchKeywords =
false;
641 catch (IException &e) {
643 matchKeywords =
false;
646 else if (key.isNamed(
"CameraVersion")) {
648 for (
int camVersionKeyIndex = 0;
649 camVersionKeyIndex < key.size();
650 camVersionKeyIndex++) {
652 bool versionMatch =
false;
653 IString val = key[camVersionKeyIndex];
656 while ((commaTok = val.Token(
",")).ToQt().length() > 0) {
657 if (commaTok.find(
'-') != string::npos) {
659 int start = commaTok.Token(
"-").ToInteger();
660 int end = commaTok.Token(
"-").ToInteger();
662 direction = (start <= end) ? 1 : -1;
664 for (
int version = start;
665 version != end + direction;
666 version += direction) {
667 if (version == cameraVersion) {
674 if (commaTok.ToInteger() == cameraVersion) {
681 matchKeywords =
false;
685 catch (IException &) {
686 matchKeywords =
false;
691 return matchKeywords && matchTime;
734 PvlGroup &dataDir = Preference::Preferences().findGroup(
"DataDirectory");
735 QString baseDir = dataDir[
"Base"];
738 QString missionDir = dataDir[mission];
748 catch (IException &e) {
752 FileName tpDbPath(missionDir +
"/kernels/tspk");
753 if (tpDbPath.fileExists()) {
805 QString directory,
const Pvl &lab) {
807 FileName configFile = directory +
"/kernels.????.conf";
808 bool noConfigFile =
false;
811 configFile = configFile.highestVersion();
813 catch (IException &e) {
817 FileName kernelDb(directory +
"/kernels.????.db");
821 PvlObject inst = Pvl(configFile.expanded()).findObject(
"Instrument");
822 bool foundMatch =
false;
824 for (
int groupIndex = 0; groupIndex < inst.groups(); groupIndex++) {
826 PvlGroup &grp = inst.group(groupIndex);
828 if (grp.isNamed(
"Selection")
832 for (
int keyIndex = 0; keyIndex < grp.keywords(); keyIndex++) {
833 PvlKeyword keyword = grp[keyIndex];
834 if (keyword.isNamed(
"File")) {
835 QString dir = dataDir[keyword[0]];
836 FileName kernelDb( dir +
"/" + keyword[1]);
871 catch (IException &e) {
872 QString msg =
"Unable to read kernel database file ["
873 + kernelDbFile.expanded() +
"].";
874 throw IException(e, IException::Unknown, msg, _FILEINFO_);
903 for (
int i = 0; i < grp.keywords(); i++) {
904 PvlKeyword kfile = grp[i];
905 if (kfile.name() !=
"File")
continue;
910 if (kfile.size() == 2) {
911 QString pref = kfile[0];
912 QString version = kfile[1];
913 FileName filename(
"$" + pref +
"/" + version);
914 if (filename.isVersioned())
915 filename = filename.highestVersion();
916 files.push_back(filename.originalPath() +
"/" + filename.name());
919 else if (kfile.size() == 1) {
920 FileName filename(kfile[0]);
921 if (filename.isVersioned())
922 filename = filename.highestVersion();
923 files.push_back(filename.originalPath() +
"/" + filename.name());
926 QString msg =
"Invalid File keyword value in [Group = ";
927 msg += grp.name() +
"] in database file [";
929 throw IException(IException::Unknown, msg, _FILEINFO_);
static int CameraVersion(Cube &cube)
This looks up the current camera model version from the cube.
Kernel instrumentAddendum(Pvl &lab)
This method finds the highest version of all Instrument Addendum kernels (iak) identified by the data...
QStringList files(PvlGroup &grp)
This method retrieves the values of all of the "File" keywords in the given PvlGroup.
Kernel spacecraftClock(Pvl &lab)
This method finds the highest version of all Spacecraft Clock kernels (sclk) identified by the databa...
Kernel targetAttitudeShape(Pvl &lab)
This method finds the highest version of all Target Attitude Shape kernels (pck) identified by the da...
void loadKernelDbFiles(PvlGroup &dataDir, QString directory, const Pvl &lab)
This method is called by loadSystemDb() to create a list of all appropriate kernel database files to ...
QList< FileName > m_kernelDbFiles
List of the kernel database file names that were read in when the loadSystemDb() method is called.
Kernel instrument(Pvl &lab)
This method finds the last Instrument kernel found that matches the (ik) criteria in the database and...
~KernelDb()
Destructs KernelDb object.
void loadSystemDb(const QString &mission, const Pvl &lab)
Loads the appropriate kernel database files with the defined BASE and MISSION info for each type of k...
static bool matches(const Pvl &lab, PvlGroup &kernelDbGrp, iTime timeToMatch, int cameraVersion)
This static method determines whether the given cube label matches the given criteria.
Kernel targetPosition(Pvl &lab)
This method finds the highest version of all Target Position kernels (tspk) identified by the databas...
Kernel findLast(const QString &entry, Pvl &lab)
Finds the highest priority Kernel object for the given entry based on the allowed Kernel types.
Pvl m_kernelData
Pvl containing the information in the kernel database(s) that is read in from the constructor and whe...
QList< std::priority_queue< Kernel > > findAll(const QString &entry, Pvl &lab)
Finds all of the Kernel objects for the given entry value based on the allowed Kernel types.
QString m_filename
The name of the kernel database file.
Kernel spacecraftPosition(Pvl &lab)
This method finds the highest version of all Spacecraft Position kernels (spk) identified by the data...
unsigned int m_allowedKernelTypes
This integer value represents which Kernel::Types are allowed.
Kernel frame(Pvl &lab)
This method finds the highest version of all Frame kernels (fk) identified by the database and the al...
QList< std::priority_queue< Kernel > > spacecraftPointing(Pvl &lab)
This method finds a list of the highest versions of all Spacecraft Pointing kernels (ck) identified b...
QList< FileName > kernelDbFiles()
Accessor method to retrieve the list of kernel database files that were read in when loadSystemDb() i...
Kernel dem(Pvl &lab)
This method finds the highest version of all Digital Terrain Models (DEMs) found that match the crite...
Kernel leapSecond(Pvl &lab)
This method finds the top priority of all Leap Second kernels (lsk) identified by the database and th...
void readKernelDbFiles()
This method is called by loadSystemDb() to read kernel database file list compiled by loadKernelDbFil...
KernelDb(const unsigned int allowedKernelTypes)
Constructs a new KernelDb object with a given integer value representing the Kernel::Type enumeration...
This class stores Kernel information, including Type and kernel file names.
static Type typeEnum(const QString &type)
Converts the given string to a character as follows.
Parse and return pieces of a time string.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.