示例#1
0
 GetPathFixture()
 {
   file1=nexus::create_file("GetPathFixture1.nxs",hdf5::file::AccessFlags::TRUNCATE);
   nexus::xml::create_from_file(file1.root(),"simple_structure.xml");
   file2=nexus::create_file("GetPathFixture2.nxs",hdf5::file::AccessFlags::TRUNCATE);
   nexus::xml::create_from_file(file2.root(),"detector_with_transformation.xml");
 }
示例#2
0
//----------------------------------------------------------------------------
nexus::PathObject get_base(const hdf5::file::File &file,
                           const nexus::Path &path)
{
  nexus::PathObjectList objects;

  // check if the path references the root group
  if(path.size()==1 &&  !nexus::has_attribute_section(path))
  {
    return file.root();
  }

  try
  {
    nexus::Path file_root;
    file_root.filename(path.filename());
    file_root.push_back({"/","NXroot"});
    nexus::Path search_path = nexus::make_relative(file_root,path);
    search_path.attribute(path.attribute());

    objects = nexus::get_objects(file.root(),search_path);

  }
  catch(pni::core::key_error &error)
  {
    std::cerr<<error<<std::endl;
    std::cerr<<"The path entered does not exist!"<<std::endl;
    std::exit(1);
  }
  catch(std::runtime_error &error)
  {
    std::cerr<<error.what()<<std::endl;
    std::exit(1);
  }

  if(objects.size()!=1)
  {
    std::stringstream ss;

    if(objects.size()>1)
      ss<<"The path ["<<path<<"] is not unique - cannot identify base object!";
    else if(objects.size()==0)
      ss<<"Could not find base with ["<<path<<"]!";

    throw std::runtime_error(ss.str());
  }

  return objects.front();
}