Commit 2db201dc authored by Makayla Shepherd's avatar Makayla Shepherd
Browse files

Removed hdf5 serialization. Fixes #4795.

parent a17060f5
Loading
Loading
Loading
Loading
+0 −608

File changed.

Preview size limit exceeded, changes collapsed.

+0 −11
Original line number Diff line number Diff line
@@ -30,11 +30,6 @@
#include <QString>
#include <QVector>

// hdf5 Library
#include <H5Cpp.h>
#include <hdf5_hl.h>
#include <hdf5.h>

// Isis Library
#include "BundleControlPoint.h"
#include "BundleObservationVector.h"
@@ -248,12 +243,6 @@ namespace Isis {
      QDataStream &write(QDataStream &stream) const;
      QDataStream &read(QDataStream &stream);

      void createH5Group(hid_t locationId, QString locationName) const;// delete these
      void parseH5Group(hid_t locationId, QString locationName);       // delete these

      void createH5Group(H5::CommonFG &locationObject, QString locationName) const;
      void openH5Group(H5::CommonFG &locationObject, QString locationName);
      BundleResults(H5::CommonFG &locationObject, QString locationName);

    private:
      /**
+1 −271
Original line number Diff line number Diff line
@@ -7,10 +7,6 @@
#include <QUuid>
#include <QXmlStreamWriter>

#include <hdf5_hl.h> // in the hdf5 library
#include <hdf5.h>
#include <H5Cpp.h>

#include "BundleResults.h"
#include "ControlMeasure.h"
#include "ControlNet.h"
@@ -75,26 +71,6 @@ namespace Isis {
    xmlReader->setErrorHandler(new XmlHandler(this, project));
  }

  /**
   * Constructor. Creates a BundleSolutionInfo.
   * 
   * @param bundleSolutionInfo Filename of another BundleSolutionInfo and reads the settings and 
   *        BundleResults from that.
   */
  BundleSolutionInfo::BundleSolutionInfo(FileName bundleSolutionInfoFile) {
    m_id = NULL;
    m_id = new QUuid(QUuid::createUuid());

    m_statisticsResults = NULL;
    m_statisticsResults = new BundleResults();

    m_settings = BundleSettingsQsp(new BundleSettings);

    m_images = NULL;
    m_images = new QList<ImageList *>;// change to QList<QStringList> ???

    openH5File(bundleSolutionInfoFile);
  }
  
  /**
   * Constructor. Creates a BundleSolutionInfo.
@@ -1747,250 +1723,4 @@ namespace Isis {
    return bundleSolutionInfo.read(stream);
  }


  /**
   * Reads the settings and results from another BundleSolutionInfo
   * 
   * @throws IException::Io "No file with the given name was found."
   * @throws IException::Io "The given file is unsupported for constructing BundleSolutionInfo 
   *                        objects. Supported file types include [hdf]."
   * @throws IException::Unknown "H5 exception handler has detected an error when invoking the 
   *                             function"
   * @throws IException::Unknown "Unable to read bundle solution information from the given HDF5 
   *                             file"
   * 
   * @param bundleSolutionInfoFile The name of the BundleSolutionInfo we are reading from
   */
  void BundleSolutionInfo::openH5File(FileName bundleSolutionInfoFile) {

    try {
      if (!bundleSolutionInfoFile.fileExists()) {
        QString msg = "No file with the given name was found.";
        throw IException(IException::Io, msg, _FILEINFO_);
      }

      if (QString::compare(bundleSolutionInfoFile.extension(), "hdf", Qt::CaseInsensitive) != 0) {
        QString msg = "The given file is unsupported for constructing BundleSolutionInfo objects. "
                      "Supported file types include [hdf].";
        throw IException(IException::Io, msg, _FILEINFO_);
      }

      // catch H5 exceptions and rethrow
      try {
        /*
         * Turn off the auto-printing when failure occurs so that we can
         * handle the errors appropriately
         */
//        H5::Exception::dontPrint();//??? uncomment
    
        /* 
         * Create and open an H5File object with read-only access. This will throw an
         * H5 exception if the open fails.
         * 
         * The static H5Fopen() function will returns a negative file ID if it fails. So, in this
         * case, we would have to take the extra step of checking whether the return
         * is negative.
         */

        const H5std_string hdfFileName(bundleSolutionInfoFile.expanded().toStdString()); 
        H5::H5File hdfFile( hdfFileName, H5F_ACC_RDONLY ); // valgrind: Invalid read of size 4

        // get the BundleSolutionInfo group
        QString root = "/";
        QString bundleRunGroupName = root + "BundleSolutionInfo";
        H5::Group bundleRunGroup = hdfFile.openGroup(bundleRunGroupName.toLatin1());

        /* 
         * Add basic attributes
         */ 
        H5std_string attValue;

        Attribute att = bundleRunGroup.openAttribute("runTime");
        H5::StrType strDataType(H5::PredType::C_S1, att.getStorageSize());
        att.read(strDataType, attValue);
        m_runTime = QString::fromStdString(attValue);

        att = bundleRunGroup.openAttribute("controlNetworkFileName");
        strDataType = H5::StrType(H5::PredType::C_S1, att.getStorageSize());
        att.read(strDataType, attValue);
        m_controlNetworkFileName = new FileName(QString::fromStdString(attValue));

        m_settings->openH5Group(bundleRunGroup, bundleRunGroupName);
        m_statisticsResults->openH5Group(bundleRunGroup, bundleRunGroupName);

        // ???Let's just save off the image list file names for now...
        QString   imagesGroupName = bundleRunGroupName + "/imageLists";
        H5::Group imagesGroup     = bundleRunGroup.openGroup(imagesGroupName.toLatin1());
        int imagesGroupSize = (int)imagesGroup.getNumObjs();

        for (int i = 0; i < imagesGroupSize; i++) {
          H5std_string listGroupName = imagesGroup.getObjnameByIdx(i);
          H5::Group listGroup = imagesGroup.openGroup(listGroupName);
          
          H5std_string attValue;
          att = listGroup.openAttribute("path");
          strDataType = H5::StrType(H5::PredType::C_S1, att.getStorageSize());
          att.read(strDataType, attValue);
          QString listPath = QString::fromStdString(attValue);
          QString listName = QString::fromStdString(listGroupName).remove(imagesGroupName + "/");

          ImageList *imageList = new ImageList(listName, listPath);

          att = listGroup.openAttribute("fileNames");
          strDataType = H5::StrType(H5::PredType::C_S1, att.getStorageSize());
          att.read(strDataType, attValue);
          QStringList fileList = QString::fromStdString(attValue).split(",");
          for (int j = 0; j < fileList.size();j++) {
            imageList->append(new Image(fileList[j]));
          }

          m_images->append(imageList);// delete and null imageList???

        }
  #if 0
        
        QString   imagesGroupName = bundleRunGroupName + "/imageLists";
        H5::Group imagesGroup     = bundleRunGroup.openGroup(imagesGroupName.toLatin1());
        int imagesGroupSize = (int)imagesGroup.getNumObjs();

        for (int i = 0; i < imagesGroupSize; i++) {
          H5std_string listGroupName = imagesGroup.getObjnameByIdx(i);
          H5::Group listGroup = imagesGroup.openGroup(listGroupName);

          H5std_string attValue;
          att = listGroup.openAttribute("path");
          strDataType = H5::StrType(H5::PredType::C_S1, att.getStorageSize());
          att.read(strDataType, attValue);
          QString listPath = QString::fromStdString(attValue);
          QString listName = QString::fromStdString(listGroupName).remove(imagesGroupName + "/");

          ImageList *imageList = new ImageList(listName, listPath);
          imageList->openH5Group(bundleRunGroup, bundleRunGroupName);
          m_images.append(imageList);
        }
#endif

      }
      catch (H5::Exception error) {  //?? how to improve printed msg using major/minor error codes?
        QString msg = "H5 Exception Message: " + QString::fromStdString(error.getDetailMsg());
        IException hpfError(IException::Unknown, msg, _FILEINFO_);
        msg = "H5 exception handler has detected an error when invoking the function " 
              + QString::fromStdString(error.getFuncName()) + ".";
        throw IException(hpfError, IException::Unknown, msg, _FILEINFO_);
      }
    }
    catch (IException &e) {
      QString msg = "Unable to read bundle solution information from the given HDF5 file ["
                    + bundleSolutionInfoFile.expanded() + "].";
      throw IException(e, IException::Unknown, msg, _FILEINFO_);
    }
  }


  /**
   * Creates a new file using H5F_ACC_EXCL
   * 
   * @throws IException::Io "A file already exists with the given name ["
   * @throws IException::Unknown "H5 exception handler has detected an error when invoking the 
   *                             function"
   * @throws IException::Unknown "Unable to save bundle solution information to an HDF5 file."
   * 
   * @param outputFileName The name of the file we are creating.
   */
  void BundleSolutionInfo::createH5File(FileName outputFileName) const {

    try {
      if (outputFileName.fileExists()) {
        QString msg = "A file already exists with the given name ["
                      + outputFileName.expanded() + "].";
        throw IException(IException::Io, msg, _FILEINFO_);
      }

      // Try block to detect exceptions raised by any of the calls inside it
      try {
        /*
         * Turn off the auto-printing when failure occurs so that we can
         * handle the errors appropriately
         */
        //H5::Exception::dontPrint();

        /*
         * Create a new file using H5F_ACC_EXCL access,
         * default file creation properties, and default file
         * access properties.
         */
        const H5std_string hdfFileName(outputFileName.expanded().toStdString());
//        const H5std_string hdfFileName("./BundleSolutionInfo.hdf");
        H5::H5File hdfFile(hdfFileName, H5F_ACC_EXCL); // valgrind: Invalid read of size 4???

        // create BundleSolutionInfo group
        QString   root               = "/";
        QString   bundleRunGroupName = root + "BundleSolutionInfo";
        H5::Group bundleRunGroup     = hdfFile.createGroup(bundleRunGroupName.toLatin1());

        /* 
         * Add basic attributes
         */
        Attribute     att;
        H5::DataSpace spc(H5S_SCALAR); // single value space
        QString       attValue    = "";

        H5::StrType   strDataType(H5::PredType::C_S1, m_runTime.length());
        att = bundleRunGroup.createAttribute("runTime", strDataType, spc);
        att.write(strDataType, m_runTime.toStdString());

        attValue = m_controlNetworkFileName->expanded();
        strDataType = H5::StrType(H5::PredType::C_S1, attValue.length());
        att = bundleRunGroup.createAttribute("controlNetworkFileName", strDataType, spc);
        att.write(strDataType, attValue.toStdString());

        m_settings->createH5Group(bundleRunGroup, bundleRunGroupName);
        m_statisticsResults->createH5Group(bundleRunGroup, bundleRunGroupName);

        // Let's just save off the image list file names for now...
        QString   imagesGroupName = bundleRunGroupName + "/imageLists";
        H5::Group imagesGroup     = bundleRunGroup.createGroup(imagesGroupName.toLatin1());

        QString listGroupName = "";
        int     stringSize    = 0;

        for (int i = 0; i < m_images->size(); i++) {
          listGroupName = imagesGroupName + "/" + (*m_images)[i]->name();

          H5::Group listGroup = imagesGroup.createGroup(listGroupName.toLatin1());

          attValue = (*m_images)[i]->path();
          strDataType = H5::StrType(H5::PredType::C_S1, attValue.length());
          att = listGroup.createAttribute("path", strDataType, spc);
          att.write(strDataType, attValue.toStdString());

          QStringList fileList;
          for (int j = 0; j < (*m_images)[i]->size(); j++) {
            fileList += (*(*m_images)[i])[j]->fileName(); //???
          }

          QString fileNames = fileList.join(",");
          stringSize = qMax(fileNames.length(), 1);
          strDataType = H5::StrType(H5::PredType::C_S1, stringSize);
          att = listGroup.createAttribute("fileNames", strDataType, spc);
          att.write(strDataType, fileNames.toStdString());

        }
      }
      catch (H5::Exception error) {  //??? how to improve printed msg using major/minor error codes?
        QString msg = "H5 Exception Message: " + QString::fromStdString(error.getDetailMsg());
        IException hpfError(IException::Unknown, msg, _FILEINFO_);
        msg = "H5 exception handler has detected an error when invoking the function "
              + QString::fromStdString(error.getFuncName()) + ".";
        throw IException(hpfError, IException::Unknown, msg, _FILEINFO_);
      }
    }
    catch (IException &e) {
      throw IException(e,
                       IException::Unknown,
                       "Unable to save bundle solution information to an HDF5 file.",
                       _FILEINFO_);
    }
  }

}
+0 −6
Original line number Diff line number Diff line
@@ -105,7 +105,6 @@ namespace Isis {
      BundleSolutionInfo(Project *project, 
                    XmlStackedHandlerReader *xmlReader, 
                    QObject *parent = 0);  //TODO does xml stuff need project???
      BundleSolutionInfo(FileName bundleSolutionInfoFile);
      BundleSolutionInfo(const BundleSolutionInfo &src);
      ~BundleSolutionInfo();
      BundleSolutionInfo &operator=(const BundleSolutionInfo &src);
@@ -140,11 +139,6 @@ namespace Isis {
      QDataStream &write(QDataStream &stream) const;
      QDataStream &read(QDataStream &stream);

      void writeH5File(FileName outputFileName) const;
      void readH5File(FileName outputFileName) const;

      void createH5File(FileName outputFileName) const;
      void openH5File(FileName outputFileName);
//      BundleSolutionInfo(FileName bundleSolutionInfoFile);
      
      public slots:
+0 −68
Original line number Diff line number Diff line
@@ -10,11 +10,6 @@
#include <QXmlInputSource>
#include <QXmlStreamWriter>

// in the hdf5 library
#include <hdf5.h>
#include <hdf5_hl.h> 
#include <H5Cpp.h>

#include "BundleImage.h"
#include "Camera.h"
#include "FileName.h"
@@ -1232,67 +1227,4 @@ namespace Isis {
    return settings.read(stream);
  }


#if 0
  /** 
   *  H5 compound data type uses the offesets from the QDataStream returned by
   *  the write(QDataStream &stream) method.
   */
  H5::CompType BundleObservationSolveSettings::compoundH5DataType() {

    H5::CompType compoundDataType((size_t)   );

    size_t offset = 0;

    compoundDataType.insertMember("InstrumentId", offset, H5::PredType::C_S1);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("InstrumentPointingSolveOption", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("NumCamAngleCoefSolved", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("CkDegree", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("CkSolveDegree", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("SolveTwist", offset, H5::PredType::NATIVE_HBOOL);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("SolvePointingPolynomialOverExisting", offset, H5::PredType::NATIVE_HBOOL);

    offset += sizeof(m_instrumentId);
???    compoundDataType.insertMember("AnglesAprioriSigma", offset, H5::PredType::NATIVE_DOUBLE);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("PointingInterpolationType", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("InstrumentPositionSolveOption", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_instrumentId);
    compoundDataType.insertMember("NumCamPosCoefSolved", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_numberCamPosCoefSolved);
    compoundDataType.insertMember("SpkDegree", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_spkDegree);
    compoundDataType.insertMember("SpkSolveDegree", offset, H5::PredType::NATIVE_INT);

    offset += sizeof(m_spkSolveDegree);
    compoundDataType.insertMember("SolvePositionOverHermiteSpline", offset, H5::PredType::NATIVE_HBOOL);

    offset += sizeof(m_solvePositionOverHermiteSpline);
???    compoundDataType.insertMember("PositionAprioriSigma", offset, H5::PredType::NATIVE_DOUBLE);

    offset += sizeof(m_positionAprioriSigma);
    compoundDataType.insertMember("PositionInterpolationType", offset, H5::PredType::NATIVE_INT);

    return compoundDataType;

  }
#endif
}
Loading