Commit aef634ae authored by Kim Oyama's avatar Kim Oyama
Browse files

In spiceserver, instead of opening $base/testdata/isisTruth.cub spiceserver...

In spiceserver, instead of opening $base/testdata/isisTruth.cub spiceserver now creates a cube from the label information that it receives from spiceinit. This change was made because the camera classes (Camera, CameraFactory, Sensor, Spice,...) now take a cube as input to their constructors instead of a pvl. The isisTruth.cub dimensions did not match the dimensions in the label (from spiceinit), causing spiceserver to return an incorrect end time for the spice information. Added TEMPFILE parameter for testing purposes. Fixes #2030.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@5819 41f8697f-d340-4b68-9986-7bafba869bb8
parent 01aa97ad
Loading
Loading
Loading
Loading
+68 −43
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include "Camera.h"
#include "CameraFactory.h"
#include "Cube.h"
#include "FileName.h"
#include "IString.h"
#include "Kernel.h"
#include "KernelDb.h"
@@ -71,18 +72,33 @@ void IsisMain() {
    g_startPad = 0.0;
    g_endPad = 0.0;

    // Get the single line of encoded XML from the input file that the client,
    //   spiceinit, sent us.
    // Get the single line of encoded XML from the input file that the client, spiceinit, sent us.
    TextFile inFile( ui.GetFileName("FROM") );
    QString hexCode;
    
    // GetLine returns false if it was the last line... so we can't check for
    //   problems really
    // GetLine returns false if it was the last line... so we can't check for problems really
    inFile.GetLine(hexCode);

    Cube cube;
    cube.open("$base/testData/isisTruth.cub", "r");
    Pvl &label = *cube.label();
    /*
     * For Debugging, you may want to run spiceserver locally (without spiceinit).
     *
     * Uncomment the following code and run the spiceinit with web=true. An error will be thrown
     * with the file name of the stored input hex file. You can rsync that file to your work area
     * and run spice server locally.
     */
    /*
     * const char *inmode = "overwrite";
     * const char *ext  = "dat";
     * TextFile newInput;
     * newInput.Open(QString("/tmp/spice_web_service/input"), inmode, ext);
     * newInput.Rewind();//start at begining
     * newInput.PutLine(hexCode);
     * newInput.Close();
     * QString msg = "In: " + ui.GetFileName("FROM") + "   " + ui.GetFileName("TO");
     * throw IException(IException::Programmer, msg, _FILEINFO_);
     */

    Pvl label;
    label.clear();
    QString otherVersion;

@@ -105,8 +121,7 @@ void IsisMain() {
          // Store off the other isis version
          if (element.tagName() == "isis_version") {
            QString encoded = element.firstChild().toText().data();
            otherVersion =
                QByteArray::fromHex(encoded.toAscii()).constData();
            otherVersion = QByteArray::fromHex( encoded.toAscii() ).constData();
          }
          else if (element.tagName() == "parameters") {
            // Read the spiceinit parameters
@@ -116,8 +131,7 @@ void IsisMain() {
            // Get the cube label
            QString encoded = element.firstChild().toText().data();
            stringstream labStream;
            labStream <<
                QString(QByteArray::fromHex(encoded.toAscii()).constData());
            labStream << QString( QByteArray::fromHex( encoded.toAscii() ).constData() );
            labStream >> label;
          }
        }
@@ -148,8 +162,7 @@ void IsisMain() {

    // Set up for getting the mission name
    // Get the directory where the system missions translation table is.
    QString transFile = p.MissionData("base",
                                      "translations/MissionName2DataDir.trn");
    QString transFile = p.MissionData("base", "translations/MissionName2DataDir.trn");

    // Get the mission translation manager ready
    PvlTranslationManager missionXlater(label, transFile);
@@ -188,6 +201,7 @@ void IsisMain() {
    fk        = ckKernels.frame(label);
    ck        = ckKernels.spacecraftPointing(label);
    spk       = spkKernels.spacecraftPosition(label);

    if (g_ckNadir) {
      // Only add nadir if no spacecraft pointing found
      QStringList nadirCk;
@@ -228,29 +242,34 @@ void IsisMain() {
                       _FILEINFO_);
    }

    FileName inputLabels;
    
    while (ck.at(0).size() != 0 && !kernelSuccess) {
      // create an empty kernel
      Kernel realCkKernel;
      QStringList ckKernelList;

      // Add the list of cks from each Kernel object at the top of each
      // priority queue. If multiple priority queues exist, we will not
      // pop of the top priority from any of the queues except for the
      // first one.  So each time tryKernels() fails, the same files
      // will be loaded with the next priority from the first queue.
      /*
       * Add the list of cks from each Kernel object at the top of each
       * priority queue. If multiple priority queues exist, we will not\
       * pop of the top priority from any of the queues except for the
       * first one.  So each time tryKernels() fails, the same files
       * will be loaded with the next priority from the first queue.
       */
      for (int i = ck.size() - 1; i >= 0; i--) {
        if (ck.at(i).size() != 0) {
          Kernel topPriority = ck.at(i).top();
          ckKernelList.append( topPriority.kernels() );
          // set the type to equal the type of the to priority of the first
          //queue 
          // set the type to equal the type of the to priority of the first queue
          realCkKernel.setType( topPriority.type() );
        }
      }

      // pop the top priority ck off only the first queue so that the next 
      // iteration will test the next highest priority of the first queue with
      // the top priority of each of the other queues.
      /*
       * pop the top priority ck off only the first queue so that the next
       * iteration will test the next highest priority of the first queue with
       * the top priority of each of the other queues.
       */
      ck[0].pop();

      // Merge SpacecraftPointing and Frame into ck
@@ -260,20 +279,29 @@ void IsisMain() {

      realCkKernel.setKernels(ckKernelList);
      
      /*
       * Create a dummy cube from the labels that spiceinit sent. We do this because the camera
       * classes take a cube instead of a pvl as input.
       *
       * This program has read and write access on the spice server in /tmp/spice_web_service.
       */
      inputLabels = FileName::createTempFile("/tmp/spice_web_service/inputLabels.cub");// ui.GetFileName("TEMPFILE") );
      //"/tmp/spice_web_service/inputLabels.cub");
      label.write( inputLabels.expanded() );
      Cube cube;
      cube.open(inputLabels.expanded(), "r");
      kernelSuccess = tryKernels(cube, label, p, lk, pck, targetSpk,
                                 realCkKernel, fk, ik, sclk, spk,
                                 iak, dem, exk);
    }

    if (!kernelSuccess) {
      throw IException(IException::Unknown,
                       "Unable to initialize camera model",
                       _FILEINFO_);
      throw IException(IException::Unknown, "Unable to initialize camera model", _FILEINFO_);
    }
    else {
      packageKernels( ui.GetFileName("TO") );
    }

    remove( inputLabels.expanded().toAscii() ); //clean up
    p.EndProcess();
  }
  catch (...) {
@@ -350,7 +378,7 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
  }

  PvlGroup originalKernels = lab.findGroup("Kernels", Pvl::Traverse);
  PvlGroup &currentKernels = lab.findGroup("Kernels", Pvl::Traverse);
  PvlGroup currentKernels = lab.findGroup("Kernels", Pvl::Traverse);
  currentKernels.addKeyword(lkKeyword, Pvl::Replace);
  currentKernels.addKeyword(pckKeyword, Pvl::Replace);
  currentKernels.addKeyword(targetSpkKeyword, Pvl::Replace);
@@ -360,6 +388,7 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
  currentKernels.addKeyword(spkKeyword, Pvl::Replace);
  currentKernels.addKeyword(iakKeyword, Pvl::Replace);
  currentKernels.addKeyword(emptyDemKeyword, Pvl::Replace);
  currentKernels.addKeyword(demKeyword, Pvl::Replace);

  // report qualities
  PvlKeyword spkQuality("InstrumentPositionQuality");
@@ -401,9 +430,12 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
  if (g_endPad > DBL_EPSILON)
    currentKernels.addKeyword( PvlKeyword("EndPadding", toString(g_endPad), "seconds") );


  currentKernels.addKeyword(
      PvlKeyword("CameraVersion", toString(CameraFactory::CameraVersion(cube))),
      Pvl::Replace);
      PvlKeyword( "CameraVersion", toString( CameraFactory::CameraVersion(cube) ) ), Pvl::Replace);

  // Add the modified Kernels group to the input cube labels
  cube.putGroup(currentKernels);

  // Create the camera so we can get blobs if necessary
  try {
@@ -412,23 +444,19 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
      cam = CameraFactory::Create(cube);

      // If success then pretend we had the shape model keyword in there...
      //   this doesn't actually effect the blobs that we care about
      currentKernels.addKeyword(demKeyword, Pvl::Replace);
      Pvl applicationLog;
      applicationLog += lab.findGroup("Kernels", Pvl::Traverse);
      applicationLog += currentKernels;
      applicationLog.write(ui.GetFileName("TO") + ".print");
    }
    catch (IException &e) {
      Pvl errPvl = e.toPvl();

      if (errPvl.groups() > 0)
        currentKernels += PvlKeyword("Error",
            errPvl.group(errPvl.groups() - 1)["Message"][0]);
        currentKernels += PvlKeyword("Error", errPvl.group(errPvl.groups() - 1)["Message"][0]);

      Application::Log(currentKernels);
      throw e;
    }

    Table ckTable = cam->instrumentRotation()->Cache("InstrumentPointing");
    ckTable.Label() += PvlKeyword("Description", "Created by spiceinit");
    ckTable.Label() += PvlKeyword("Kernels");
@@ -455,8 +483,7 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
    for (int i = 0; i < pckKeyword.size(); i++)
      bodyTable.Label()["Kernels"].addValue(pckKeyword[i]);

    bodyTable.Label() += PvlKeyword("SolarLongitude",
                                    toString(cam->solarLongitude().degrees()));
    bodyTable.Label() += PvlKeyword( "SolarLongitude", toString( cam->solarLongitude().degrees() ) );
    bodyTable.Write(ui.GetFileName("TO") + ".bodyrot");

    Table sunTable = cam->sunPosition()->Cache("SunPosition");
@@ -485,7 +512,7 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
      currentKernels["TargetPosition"].addValue(origTargPos[i]);

    Pvl kernelsLabels;
    kernelsLabels += lab.findGroup("Kernels", Pvl::Traverse);
    kernelsLabels += currentKernels;
    kernelsLabels += cam->getStoredNaifKeywords();
    kernelsLabels.write(ui.GetFileName("TO") + ".lab");
  }
@@ -590,8 +617,7 @@ void packageKernels(QString toFile) {
  QFile::remove(logFile);
  stringstream logStream;
  logStream << logMessage;
  xml +=
      QString(QByteArray(logStream.str().c_str()).toHex().constData()) + "\n";
  xml += QString( QByteArray( logStream.str().c_str() ).toHex().constData() ) + "\n";
  xml += "  </application_log>\n";

  xml += "  <kernels_label>\n";
@@ -602,8 +628,7 @@ void packageKernels(QString toFile) {
  stringstream labelStream;
  labelStream << kernLabels;

  xml +=
      QString(QByteArray(labelStream.str().c_str()).toHex().constData()) + "\n";
  xml += QString( QByteArray( labelStream.str().c_str() ).toHex().constData() ) + "\n";

  xml += "  </kernels_label>\n";

+23 −0
Original line number Diff line number Diff line
@@ -39,6 +39,14 @@
        Modified so the kernel quality parameters from XML are tested as case insensitive. This
        change was made in a branch of ISIS, but was not yet moved to the publice version yet.
    </change>
    <change name="Kimberly Oyama" date="2014-04-28">
      Instead of opening $base/testdata/isisTruth.cub spiceserver now creates a cube from the label
      information that it receives from spiceinit. This change was made because the camera classes
      (Camera, CameraFactory, Sensor, Spice,...) now take a cube as input to their constructors
      instead of a pvl. The isisTruth.cub dimensions did not match the dimensions in the label
      (from spiceinit), causing spiceserver to return an incorrect end time for the spice
      information. Added TEMPFILE parameter for testing purposes. Fixes #2030.
    </change>
  </history>

  <groups>
@@ -88,6 +96,21 @@
          causes spiceserver to throw an error if the versions of Isis do not match.
        </description>
      </parameter>

      <parameter name="TEMPFILE">
        <type>filename</type>
        <fileMode>output</fileMode>
        <default><item>/tmp/spice_web_service/inputLabels.cub</item></default>
        <brief>
          Location of temp cube
        </brief>
        <description>
          This parameter was added for testing purposes only. The spice server has access to the
          default location but the app tests will use their own output directory as the temp cube 
          location.
        </description>
        <filter>*.cub</filter>
      </parameter>
    </group>
  </groups>

+1 −1
Original line number Diff line number Diff line
@@ -15,4 +15,4 @@ include $(ISISROOT)/make/isismake.tsts
# Valid text comes out magically. I promise! :)
commands:
	$(APPNAME) from=$(INPUT)/request.txt checkversion=false to=$(OUTPUT)/result.txt \
	  > /dev/null;
	  tempfile=$(OUTPUT)/tempCube.cub > /dev/null;