当前位置: 首页>>代码示例>>C++>>正文


C++ typenameMDEventWorkspace::fileNeedsUpdating方法代码示例

本文整理汇总了C++中typenameMDEventWorkspace::fileNeedsUpdating方法的典型用法代码示例。如果您正苦于以下问题:C++ typenameMDEventWorkspace::fileNeedsUpdating方法的具体用法?C++ typenameMDEventWorkspace::fileNeedsUpdating怎么用?C++ typenameMDEventWorkspace::fileNeedsUpdating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在typenameMDEventWorkspace的用法示例。


在下文中一共展示了typenameMDEventWorkspace::fileNeedsUpdating方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doSaveEvents

void SaveMD::doSaveEvents(typename MDEventWorkspace<MDE, nd>::sptr ws) {
  bool updateFileBackend = getProperty("UpdateFileBackEnd");
  bool makeFileBackend = getProperty("MakeFileBacked");
  if (updateFileBackend && makeFileBackend)
    throw std::invalid_argument(
        "Please choose either UpdateFileBackEnd or MakeFileBacked, not both.");

  bool wsIsFileBacked = ws->isFileBacked();
  std::string filename = getPropertyValue("Filename");
  BoxController_sptr bc = ws->getBoxController();
  auto copyFile =
      wsIsFileBacked && !filename.empty() && filename != bc->getFilename();
  if (wsIsFileBacked) {
    if (makeFileBackend) {
      throw std::runtime_error(
          "MakeFileBacked selected but workspace is already file backed.");
    }
  } else {
    if (updateFileBackend) {
      throw std::runtime_error(
          "UpdateFileBackEnd selected but workspace is not file backed.");
    }
  }

  if (!wsIsFileBacked) {
    Poco::File oldFile(filename);
    if (oldFile.exists())
      oldFile.remove();
  }

  auto prog = new Progress(this, 0.0, 0.05, 1);
  if (updateFileBackend) // workspace has its own file and ignores any changes
                         // to the
                         // algorithm parameters
  {
    if (!ws->isFileBacked())
      throw std::runtime_error(" attempt to update non-file backed workspace");
    filename = bc->getFileIO()->getFileName();
  }

  //-----------------------------------------------------------------------------------------------------
  // create or open WS group and put there additional information about WS and
  // its dimensions
  int nDims = static_cast<int>(nd);
  bool data_exist;
  auto file = file_holder_type(MDBoxFlatTree::createOrOpenMDWSgroup(
      filename, nDims, MDE::getTypeName(), false, data_exist));

  // Save each NEW ExperimentInfo to a spot in the file
  MDBoxFlatTree::saveExperimentInfos(file.get(), ws);
  if (!updateFileBackend || !data_exist) {
    MDBoxFlatTree::saveWSGenericInfo(file.get(), ws);
  }
  file->closeGroup();
  file->close();

  MDBoxFlatTree BoxFlatStruct;
  //-----------------------------------------------------------------------------------------------------
  if (updateFileBackend) // the workspace is already file backed;
  {
    prepareUpdate<MDE, nd>(BoxFlatStruct, bc.get(), ws, filename);
  } else if (copyFile) {
    // Update the original file
    if (ws->fileNeedsUpdating()) {
      prepareUpdate<MDE, nd>(BoxFlatStruct, bc.get(), ws, filename);
      BoxFlatStruct.saveBoxStructure(filename);
    }
    Poco::File(bc->getFilename()).copyTo(filename);
  } else // not file backed;
  {
    // the boxes file positions are unknown and we need to calculate it.
    BoxFlatStruct.initFlatStructure(ws, filename);
    // create saver class
    auto Saver = boost::shared_ptr<API::IBoxControllerIO>(
        new DataObjects::BoxControllerNeXusIO(bc.get()));
    Saver->setDataType(sizeof(coord_t), MDE::getTypeName());
    if (makeFileBackend) {
      // store saver with box controller
      bc->setFileBacked(Saver, filename);
      // get access to boxes array
      std::vector<API::IMDNode *> &boxes = BoxFlatStruct.getBoxes();
      // calculate the position of the boxes on file, indicating to make them
      // saveable and that the boxes were not saved.
      BoxFlatStruct.setBoxesFilePositions(true);
      prog->resetNumSteps(boxes.size(), 0.06, 0.90);
      for (auto &boxe : boxes) {
        auto saveableTag = boxe->getISaveable();
        if (saveableTag) // only boxes can be saveable
        {
          // do not spend time on empty or masked boxes
          if (boxe->getDataInMemorySize() == 0 || boxe->getIsMasked())
            continue;
          // save boxes directly using the boxes file postion, precalculated in
          // boxFlatStructure.
          saveableTag->save();
          // remove boxes data from memory. This will actually correctly set the
          // tag indicatin that data were not loaded.
          saveableTag->clearDataFromMemory();
          // put boxes into write buffer wich will save them when necessary
          // Saver->toWrite(saveTag);
//.........这里部分代码省略.........
开发者ID:rosswhitfield,项目名称:mantid,代码行数:101,代码来源:SaveMD.cpp


注:本文中的typenameMDEventWorkspace::fileNeedsUpdating方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。