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


C++ nexus::File类代码示例

本文整理汇总了C++中nexus::File的典型用法代码示例。如果您正苦于以下问题:C++ File类的具体用法?C++ File怎么用?C++ File使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: loadNXLog

/**
 * Load an NX log entry a group type that has value and time entries.
 * @param file :: A reference to the NeXus file handle opened at the parent
 * group
 * @param entry_name :: The name of the log entry
 * @param entry_class :: The type of the entry
 * @param workspace :: A pointer to the workspace to store the logs
 */
void LoadNexusLogs::loadNXLog(
    ::NeXus::File &file, const std::string &entry_name,
    const std::string &entry_class,
    boost::shared_ptr<API::MatrixWorkspace> workspace) const {
  g_log.debug() << "processing " << entry_name << ":" << entry_class << "\n";

  file.openGroup(entry_name, entry_class);
  // Validate the NX log class.
  std::map<std::string, std::string> entries = file.getEntries();
  if ((entries.find("value") == entries.end()) ||
      (entries.find("time") == entries.end())) {
    g_log.warning() << "Invalid NXlog entry " << entry_name
                    << " found. Did not contain 'value' and 'time'.\n";
    file.closeGroup();
    return;
  }
  // whether or not to overwrite logs on workspace
  bool overwritelogs = this->getProperty("OverwriteLogs");
  try {
    if (overwritelogs || !(workspace->run().hasProperty(entry_name))) {
      Kernel::Property *logValue = createTimeSeries(file, entry_name);
      workspace->mutableRun().addProperty(logValue, overwritelogs);
    }
  } catch (::NeXus::Exception &e) {
    g_log.warning() << "NXlog entry " << entry_name
                    << " gave an error when loading:'" << e.what() << "'.\n";
  }

  file.closeGroup();
}
开发者ID:dezed,项目名称:mantid,代码行数:38,代码来源:LoadNexusLogs.cpp

示例2: runtime_error

void
SaveNXTomo::writeImageKeyValue(const DataObjects::Workspace2D_sptr workspace,
                               ::NeXus::File &nxFile, int thisFileInd) {
  // Add ImageKey to instrument/image_key if present, use 0 if not
  try {
    nxFile.openPath("/entry1/tomo_entry/instrument/detector");
  } catch (...) {
    throw std::runtime_error("Unable to create a valid NXTomo file");
  }

  // Set the default key value for this WS
  std::vector<double> keyValue;
  keyValue.push_back(0);

  if (workspace->run().hasProperty("ImageKey")) {
    std::string tmpVal = workspace->run().getLogData("ImageKey")->value();
    try {
      keyValue[0] = boost::lexical_cast<double>(tmpVal);
    } catch (...) {
    }
    // Invalid Cast is handled below
  }

  nxFile.openData("image_key");
  nxFile.putSlab(keyValue, thisFileInd, 1);
  nxFile.closeData();

  nxFile.closeGroup();
}
开发者ID:mkoennecke,项目名称:mantid,代码行数:29,代码来源:SaveNXTomo.cpp

示例3: loadPulseTimes

/** Load the pulse times, if needed. This sets
 * thisBankPulseTimes to the right pointer.
 * */
void LoadBankFromDiskTask::loadPulseTimes(::NeXus::File &file) {
  try {
    // First, get info about the event_time_zero field in this bank
    file.openData("event_time_zero");
  } catch (::NeXus::Exception &) {
    // Field not found error is most likely.
    // Use the "proton_charge" das logs.
    thisBankPulseTimes = m_loader.alg->m_allBanksPulseTimes;
    return;
  }
  std::string thisStartTime;
  size_t thisNumPulses = 0;
  file.getAttr("offset", thisStartTime);
  if (!file.getInfo().dims.empty())
    thisNumPulses = file.getInfo().dims[0];
  file.closeData();

  // Now, we look through existing ones to see if it is already loaded
  // thisBankPulseTimes = NULL;
  for (auto &bankPulseTime : m_loader.m_bankPulseTimes) {
    if (bankPulseTime->equals(thisNumPulses, thisStartTime)) {
      thisBankPulseTimes = bankPulseTime;
      return;
    }
  }

  // Not found? Need to load and add it
  thisBankPulseTimes = boost::make_shared<BankPulseTimes>(boost::ref(file),
                                                          m_framePeriodNumbers);
  m_loader.m_bankPulseTimes.push_back(thisBankPulseTimes);
}
开发者ID:mantidproject,项目名称:mantid,代码行数:34,代码来源:LoadBankFromDiskTask.cpp

示例4: loadEventIndex

/** Load the event_index field
(a list of size of # of pulses giving the index in the event list for that
pulse)

* @param file :: File handle for the NeXus file
* @param event_index :: ref to the vector
*/
void LoadBankFromDiskTask::loadEventIndex(::NeXus::File &file,
                                          std::vector<uint64_t> &event_index) {
  // Get the event_index (a list of size of # of pulses giving the index in
  // the event list for that pulse)
  file.openData("event_index");
  // Must be uint64
  if (file.getInfo().type == ::NeXus::UINT64)
    file.getData(event_index);
  else {
    m_loader.alg->getLogger().warning()
        << "Entry " << entry_name
        << "'s event_index field is not UINT64! It will be skipped.\n";
    m_loadError = true;
  }
  file.closeData();

  // Look for the sign that the bank is empty
  if (event_index.size() == 1) {
    if (event_index[0] == 0) {
      // One entry, only zero. This means NO events in this bank.
      m_loadError = true;
      m_loader.alg->getLogger().debug() << "Bank " << entry_name
                                        << " is empty.\n";
    }
  }
}
开发者ID:DanNixon,项目名称:mantid,代码行数:33,代码来源:LoadBankFromDiskTask.cpp

示例5: openFirstNXentry

/**
 * Open the first NXentry of the supplied nexus file.
 *
 * @param handle Object to work on.
 */
void MuonNexusReader::openFirstNXentry(NeXus::File &handle) {
  std::map<string, string> entries = handle.getEntries();
  const auto entry =
      std::find_if(entries.cbegin(), entries.cend(),
                   [](const auto entry) { return entry.second == NXENTRY; });
  if (entry == entries.cend())
    throw std::runtime_error("Failed to find NXentry");
  handle.openGroup(entry->first, NXENTRY);
}
开发者ID:mantidproject,项目名称:mantid,代码行数:14,代码来源:MuonNexusReader.cpp

示例6: writeLogValues

void SaveNXTomo::writeLogValues(const DataObjects::Workspace2D_sptr workspace,
                                ::NeXus::File &nxFile, int thisFileInd) {
  // Add Log information (minus special values - Rotation, ImageKey, Intensity)
  // Unable to add multidimensional string data, storing strings as
  // multidimensional data set of uint8 values
  try {
    nxFile.openPath("/entry1/log_info");
  } catch (...) {
    throw std::runtime_error("Unable to create a valid NXTomo file");
  }

  // Loop through all log values, create it if it doesn't exist. Then append
  // value
  std::vector<Property *> logVals = workspace->run().getLogData();

  for (auto it = logVals.begin(); it != logVals.end(); ++it) {
    auto prop = *it;
    if (prop->name() != "ImageKey" && prop->name() != "Rotation" &&
        prop->name() != "Intensity" && prop->name() != "Axis1" &&
        prop->name() != "Axis2") {
      try {
        nxFile.openData(prop->name());
      } catch (::NeXus::Exception &) {
        // Create the data entry if it doesn't exist yet, and open.
        std::vector<int64_t> infDim;
        infDim.push_back(NX_UNLIMITED);
        infDim.push_back(NX_UNLIMITED);
        nxFile.makeData(prop->name(), ::NeXus::UINT8, infDim, true);
      }

      size_t strSize = prop->value().length();

      char *val = new char[80]();

      // If log value is from FITS file as it should be,
      // it won't be greater than this. Otherwise Shorten it
      if (strSize > 80)
        strSize = 80;

      strncpy(val, prop->value().c_str(), strSize);

      std::vector<int64_t> start, size;
      start.push_back(thisFileInd);
      start.push_back(0);
      size.push_back(1);
      size.push_back(strSize);

      // single item
      nxFile.putSlab(val, start, size);

      nxFile.closeData();
    }
  }
}
开发者ID:mkoennecke,项目名称:mantid,代码行数:54,代码来源:SaveNXTomo.cpp

示例7: openFirstNXentry

/**
 * Open the first NXentry of the supplied nexus file.
 *
 * @param handle Object to work on.
 */
void MuonNexusReader::openFirstNXentry(NeXus::File &handle) {
  std::map<string, string> entries = handle.getEntries();
  bool found = false;
  for (auto &entrie : entries) {
    if (entrie.second == NXENTRY) {
      handle.openGroup(entrie.first, NXENTRY);
      found = true;
      break;
    }
  }
  if (!found)
    throw std::runtime_error("Failed to find NXentry");
}
开发者ID:liyulun,项目名称:mantid,代码行数:18,代码来源:MuonNexusReader.cpp

示例8: catch

/**
 * Can we get a histogram (non event data) for every monitor?
 *
 * @param file :: NeXus file object (open)
 * @param monitorNames :: names of monitors of interest
 * @return If there seems to be histograms for all monitors (they have "data")
 **/
bool LoadNexusMonitors2::allMonitorsHaveHistoData(
    ::NeXus::File &file, const std::vector<std::string> &monitorNames) {
  bool res = true;

  try {
    for (std::size_t i = 0; i < m_monitor_count; ++i) {
      file.openGroup(monitorNames[i], "NXmonitor");
      file.openData("data");
      file.closeData();
      file.closeGroup();
    }
  } catch (::NeXus::Exception &) {
    file.closeGroup();
    res = false;
  }
  return res;
}
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:24,代码来源:LoadNexusMonitors2.cpp

示例9: readLibisisNxs

    /**
     *
     * @param nxsFile A reference to the open NeXus fileIt should be opened at the
     *                "full_reference_detector" group
     * @param detInfo A reference to the struct that will hold the data from the file
     */
    void LoadDetectorInfo::readLibisisNxs(::NeXus::File & nxsFile, DetectorInfo & detInfo) const
    {
      nxsFile.readData<int32_t>("det_no", detInfo.ids);
      nxsFile.readData<int32_t>("det_type", detInfo.codes);
      nxsFile.readData<double>("delay_time", detInfo.delays);
      const size_t numDets = detInfo.ids.size();

      if(m_moveDets)
      {
        nxsFile.readData<double>("L2", detInfo.l2);
        nxsFile.readData<double>("theta", detInfo.theta);
        nxsFile.readData<double>("phi", detInfo.phi);
      }
      else
      {
        // these will get ignored
        detInfo.l2.resize(numDets, -1.0);
        detInfo.theta.resize(numDets, -1.0);
        detInfo.phi.resize(numDets, -1.0);
      }

      // pressure & wall thickness are global here
      double pressure = -1.0;
      double thickness = -1.0;
      nxsFile.openGroup("det_he3", "NXIXTdet_he3");
      nxsFile.readData<double>("gas_pressure", pressure);
      nxsFile.readData<double>("wall_thickness", thickness);
      nxsFile.closeGroup();
      if(pressure <= 0.0)
      {
        g_log.warning("The data file does not contain correct He3 pressure, "
                      "default value of 10 bar is used instead");
        pressure = 10.0;
      }
      if(thickness <= 0.0)
      {
        g_log.warning("The data file does not contain correct detector's wall "
                      "thickness, default value of 0.8mm is used instead");
        thickness = 0.0008;
      }
      detInfo.pressures.resize(numDets, pressure);
      detInfo.thicknesses.resize(numDets, thickness);
    }
开发者ID:BigShows,项目名称:mantid,代码行数:49,代码来源:LoadDetectorInfo.cpp

示例10: loadNPeriods

void LoadNexusLogs::loadNPeriods(
    ::NeXus::File &file,
    boost::shared_ptr<API::MatrixWorkspace> workspace) const {
  int value = 1; // Default to 1-period unless
  try {
    file.openGroup("periods", "IXperiods");
    file.openData("number");
    file.getData(&value);
    file.closeData();
    file.closeGroup();
  } catch (::NeXus::Exception &) {
    // Likely missing IXperiods.
    return;
  }

  API::Run &run = workspace->mutableRun();
  const std::string nPeriodsLabel = "nperiods";
  if (!run.hasProperty(nPeriodsLabel)) {
    run.addProperty(new PropertyWithValue<int>(nPeriodsLabel, value));
  }
}
开发者ID:dezed,项目名称:mantid,代码行数:21,代码来源:LoadNexusLogs.cpp

示例11: catch

/** Load weight of weigthed events if they exist
 * @param file An NeXus::File object opened at the correct group
 * @returns A new array containing the weights or a nullptr if the weights
 * are not present
 */
std::unique_ptr<float[]>
LoadBankFromDiskTask::loadEventWeights(::NeXus::File &file) {
  try {
    // First, get info about the event_weight field in this bank
    file.openData("event_weight");
  } catch (::NeXus::Exception &) {
    // Field not found error is most likely.
    m_have_weight = false;
    return std::unique_ptr<float[]>();
  }
  // OK, we've got them
  m_have_weight = true;

  // Allocate the array
  auto event_weight = Mantid::Kernel::make_unique<float[]>(m_loadSize[0]);

  ::NeXus::Info weight_info = file.getInfo();
  int64_t weight_dim0 = recalculateDataSize(weight_info.dims[0]);
  if (weight_dim0 < m_loadSize[0] + m_loadStart[0]) {
    m_loader.alg->getLogger().warning()
        << "Entry " << entry_name
        << "'s event_weight field is too small to load the desired data.\n";
    m_loadError = true;
  }

  // Check that the type is what it is supposed to be
  if (weight_info.type == ::NeXus::FLOAT32)
    file.getSlab(event_weight.get(), m_loadStart, m_loadSize);
  else {
    m_loader.alg->getLogger().warning()
        << "Entry " << entry_name
        << "'s event_weight field is not FLOAT32! It will be skipped.\n";
    m_loadError = true;
  }

  if (!m_loadError) {
    file.closeData();
  }
  return event_weight;
}
开发者ID:mantidproject,项目名称:mantid,代码行数:45,代码来源:LoadBankFromDiskTask.cpp

示例12: loadVetoPulses

/** Try to load the "Veto_pulse" field in DASLogs
 * and convert it to a sample log.
 *
 * @param file :: open nexus file at the DASLogs group
 * @param workspace :: workspace to add to.
 */
void LoadNexusLogs::loadVetoPulses(
    ::NeXus::File &file,
    boost::shared_ptr<API::MatrixWorkspace> workspace) const {
  try {
    file.openGroup("Veto_pulse", "NXgroup");
  } catch (::NeXus::Exception &) {
    // No group. This is common in older files
    return;
  }
  file.openData("veto_pulse_time");

  // Load the start date/time as ISO8601 string.
  std::string start_time;
  file.getAttr("start_time", start_time);
  DateAndTime start(start_time);

  // Read the offsets
  std::vector<double> time_double;
  file.getData(time_double);

  // Fake values with zeroes.
  std::vector<double> values(time_double.size(), 0.0);
  TimeSeriesProperty<double> *tsp =
      new TimeSeriesProperty<double>("veto_pulse_time");
  tsp->create(start, time_double, values);
  tsp->setUnits("");

  // Add the log
  workspace->mutableRun().addProperty(tsp);

  file.closeData();
  file.closeGroup();
}
开发者ID:dezed,项目名称:mantid,代码行数:39,代码来源:LoadNexusLogs.cpp

示例13: recalculateDataSize

/** Open and load the times-of-flight data
 * @param file An NeXus::File object opened at the correct group
 * @returns A new array containing the time of flights for this bank
 */
std::unique_ptr<float[]> LoadBankFromDiskTask::loadTof(::NeXus::File &file) {
  // Allocate the array
  auto event_time_of_flight =
      Mantid::Kernel::make_unique<float[]>(m_loadSize[0]);

  // Get the list of event_time_of_flight's
  std::string key, tof_unit;
  if (!m_oldNexusFileNames)
    key = "event_time_offset";
  else
    key = "event_time_of_flight";
  file.openData(key);

  // Check that the required space is there in the file.
  ::NeXus::Info tof_info = file.getInfo();
  int64_t tof_dim0 = recalculateDataSize(tof_info.dims[0]);
  if (tof_dim0 < m_loadSize[0] + m_loadStart[0]) {
    m_loader.alg->getLogger().warning()
        << "Entry " << entry_name
        << "'s event_time_offset field is too small "
           "to load the desired data.\n";
    m_loadError = true;
  }

  // The Nexus standard does not specify if event_time_offset should be float or
  // integer, so we use the NeXusIOHelper to perform the conversion to float on
  // the fly. If the data field already contains floats, the conversion is
  // skipped.
  auto vec = NeXus::NeXusIOHelper::readNexusSlab<float>(file, key, m_loadStart,
                                                        m_loadSize);
  file.getAttr("units", tof_unit);
  file.closeData();
  // Convert Tof to microseconds
  Kernel::Units::timeConversionVector(vec, tof_unit, "microseconds");
  std::copy(vec.begin(), vec.end(), event_time_of_flight.get());

  return event_time_of_flight;
}
开发者ID:mantidproject,项目名称:mantid,代码行数:42,代码来源:LoadBankFromDiskTask.cpp

示例14: loadLogs

/**
 * Load log entries from the given group
 * @param file :: A reference to the NeXus file handle opened such that the
 * next call can be to open the named group
 * @param entry_name :: The name of the log entry
 * @param entry_class :: The class type of the log entry
 * @param workspace :: A pointer to the workspace to store the logs
 */
void LoadNexusLogs::loadLogs(
    ::NeXus::File &file, const std::string &entry_name,
    const std::string &entry_class,
    boost::shared_ptr<API::MatrixWorkspace> workspace) const {
  file.openGroup(entry_name, entry_class);
  std::map<std::string, std::string> entries = file.getEntries();
  std::map<std::string, std::string>::const_iterator iend = entries.end();
  for (std::map<std::string, std::string>::const_iterator itr = entries.begin();
       itr != iend; ++itr) {
    std::string log_class = itr->second;
    if (log_class == "NXlog" || log_class == "NXpositioner") {
      loadNXLog(file, itr->first, log_class, workspace);
    } else if (log_class == "IXseblock") {
      loadSELog(file, itr->first, workspace);
    } else if (log_class == "NXcollection") {
      int jj = 0;
      ++jj;
    }
  }
  loadVetoPulses(file, workspace);

  file.closeGroup();
}
开发者ID:dezed,项目名称:mantid,代码行数:31,代码来源:LoadNexusLogs.cpp

示例15: loadTof

/** Open and load the times-of-flight data
*/
void LoadBankFromDiskTask::loadTof(::NeXus::File &file) {
  // Allocate the array
  auto temp = new float[m_loadSize[0]];
  delete[] m_event_time_of_flight;
  m_event_time_of_flight = temp;

  // Get the list of event_time_of_flight's
  if (!m_oldNexusFileNames)
    file.openData("event_time_offset");
  else
    file.openData("event_time_of_flight");

  // Check that the required space is there in the file.
  ::NeXus::Info tof_info = file.getInfo();
  int64_t tof_dim0 = recalculateDataSize(tof_info.dims[0]);
  if (tof_dim0 < m_loadSize[0] + m_loadStart[0]) {
    m_loader.alg->getLogger().warning()
        << "Entry " << entry_name << "'s event_time_offset field is too small "
                                     "to load the desired data.\n";
    m_loadError = true;
  }

  // Check that the type is what it is supposed to be
  if (tof_info.type == ::NeXus::FLOAT32)
    file.getSlab(m_event_time_of_flight, m_loadStart, m_loadSize);
  else {
    m_loader.alg->getLogger().warning()
        << "Entry " << entry_name
        << "'s event_time_offset field is not FLOAT32! It will be skipped.\n";
    m_loadError = true;
  }

  if (!m_loadError) {
    std::string units;
    file.getAttr("units", units);
    if (units != "microsecond") {
      m_loader.alg->getLogger().warning()
          << "Entry " << entry_name << "'s event_time_offset field's units are "
                                       "not microsecond. It will be skipped.\n";
      m_loadError = true;
    }
    file.closeData();
  } // no error
}
开发者ID:DanNixon,项目名称:mantid,代码行数:46,代码来源:LoadBankFromDiskTask.cpp


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