Beispiel #1
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();
}