コード例 #1
0
ファイル: LoadMcStas.cpp プロジェクト: stothe2/mantid
/**
 * Return the confidence with with this algorithm can load the file
 * @param descriptor A descriptor for the file
 * @returns An integer specifying the confidence level. 0 indicates it will not
 * be used
 */
int LoadMcStas::confidence(Kernel::NexusDescriptor &descriptor) const {
  using namespace ::NeXus;
  // look at to see if entry1/simulation/name exist first and then
  // if its value = mccode
  int confidence(0);
  if(descriptor.pathExists("/entry1/simulation/name")) {
    try {
        // need to look inside file to check value of entry1/simulation/name 
        ::NeXus::File file = ::NeXus::File(descriptor.filename());
        file.openGroup( descriptor.firstEntryNameType().first, descriptor.firstEntryNameType().second);
        file.openGroup("simulation", "NXnote");
        std::string value;
        // check if entry1/simulation/name equals mccode
        file.readData("name", value);
        if (boost::iequals(value, "mccode"))
          confidence = 98;
        file.closeGroup();
        file.closeGroup();
    } catch (::NeXus::Exception &) {
    }
  }
  return confidence;
}
コード例 #2
0
ファイル: LoadMuonNexus2.cpp プロジェクト: DanNixon/mantid
/**
 * Return the confidence with with this algorithm can load the file
 * @param descriptor A descriptor for the file
 * @returns An integer specifying the confidence level. 0 indicates it will not
 * be used
 */
int LoadMuonNexus2::confidence(Kernel::NexusDescriptor &descriptor) const {
  const auto &firstEntryNameType = descriptor.firstEntryNameType();
  const std::string root = "/" + firstEntryNameType.first;
  if (!descriptor.pathExists(root + "/definition"))
    return 0;

  bool upperIDF(true);
  if (descriptor.pathExists(root + "/IDF_version"))
    upperIDF = true;
  else {
    if (descriptor.pathExists(root + "/idf_version"))
      upperIDF = false;
    else
      return 0;
  }

  try {
    std::string versionField = "idf_version";
    if (upperIDF)
      versionField = "IDF_version";

    auto &file = descriptor.data();
    file.openPath(root + "/" + versionField);
    int32_t version = 0;
    file.getData(&version);
    if (version != 2)
      return 0;

    file.openPath(root + "/definition");
    std::string def = file.getStrData();
    if (def == "muonTD" || def == "pulsedTD") {
      // If all this succeeded then we'll assume this is an ISIS Muon NeXus file
      // version 2
      return 81;
    }
  } catch (...) {
  }
  return 0;
}