Ejemplo n.º 1
0
H5::DataSet CompartmentReportHDF5::_createDataset( const uint32_t gid,
                                                   const size_t compCount )
{
    LBASSERT( compCount > 0 );
    LBASSERT( !_reportName.empty( ));

    std::ostringstream neuronName;
    neuronName << "a" << gid;

    H5::Group neuronGroup = _file.createGroup( neuronName.str().c_str( ));
    H5::Group reportGroup = neuronGroup.createGroup( _reportName );

    const int dims = 2;
    const size_t numSteps = (getEndTime() - getStartTime()) / getTimestep();
    const hsize_t mappingDim[dims] = { 1, compCount };
    const hsize_t dataDim[dims] = { numSteps, compCount };
    LBASSERT( numSteps > 0 );

    H5::DataSpace mappingDataspace( dims, mappingDim );
    H5::DataSpace dataDataspace( dims, dataDim );

    H5::DataSet mappingDataset = reportGroup.createDataSet(
             mappingDatasetName, H5::PredType::NATIVE_FLOAT, mappingDataspace );
    H5::DataSet dataDataset = reportGroup.createDataSet( dataDatasetName,
                                    H5::PredType::NATIVE_FLOAT, dataDataspace );

    _datas[gid] = dataDataset;

    _createMappingAttributes( mappingDataset );
    _createDataAttributes( dataDataset );

    return mappingDataset;
}
Ejemplo n.º 2
0
int Channel::read_state_from_hdf5(H5::H5File & H5StateFile, const string & rootStr){
	clear_data();
	// read waveform data
	waveform_ = h5array2vector<float>(&H5StateFile, rootStr + "/waveformLib",   H5::PredType::NATIVE_INT16);

	// load state information
	H5::Group tmpGroup = H5StateFile.openGroup(rootStr);
	offset_    = h5element2element<float>("offset",&tmpGroup, H5::PredType::NATIVE_FLOAT);
	scale_     = h5element2element<float>("scale",&tmpGroup, H5::PredType::NATIVE_FLOAT);
	enabled_   = h5element2element<bool>("enabled",&tmpGroup, H5::PredType::NATIVE_UINT);
	trigDelay_ = h5element2element<int>("trigDelay",&tmpGroup, H5::PredType::NATIVE_INT);

	//Load the linklist data
	//First figure our how many banks there are from the attribute
	tmpGroup = H5StateFile.openGroup(rootStr + "/linkListData");
	USHORT numBanks;
	numBanks = h5element2element<USHORT>("numBanks",&tmpGroup, H5::PredType::NATIVE_UINT16);
  tmpGroup.close();

	std::ostringstream tmpStream;
	//Now loop over the number of banks found and add the bank
	for (USHORT bankct=0; bankct<numBanks; bankct++){
		LLBank bank;
		tmpStream.str(rootStr);
		tmpStream << "/linkListData/bank" << bankct+1;
		FILE_LOG(logDEBUG) << "Reading State Bank: " << bankct+1 << " from hdf5";
		bank.read_state_from_hdf5( H5StateFile, tmpStream.str());
//		banks_.push_back(bank);
	}
	return 0;
}
Ejemplo n.º 3
0
	/**
	 * TODO
	 * Retrieves the number of global attributes in the selected file.  This is useful for iterating over all
	 * available global attributes.
	 * @return The number of global attributes stored in the selected file.
	 */
	int HDF5FileReader::getNumberOfGlobalAttributes()
	{
		long num_attributes;
		H5::Group group = this->current_file->openGroup("/");
		num_attributes = group.getNumAttrs();
		return (int)num_attributes;
	}
Ejemplo n.º 4
0
void HDF5IO::saveMatrix(const std::string& GroupName, const std::string& Name,
    const ComplexMatrixType& M)
{
  try{
    H5::CompType ComplexDataType = this->openCompType("complex");
    hsize_t Dims[2] = {hsize_t(M.rows()),hsize_t(M.cols())};
    H5::DataSpace dataspace(2,Dims);
    H5::Group FG = getGroup( GroupName );
    try{
      H5::Exception::dontPrint();
      H5::DataSet dset = FG.openDataSet(Name.c_str());
      // dset.extend( Dims );not working
      dset.write(M.data(), ComplexDataType);
    } catch ( const H5::GroupIException not_found_error ){
      H5::DataSet dset = FG.createDataSet(Name.c_str(), ComplexDataType, dataspace);
      dset.write(M.data(), ComplexDataType);
    } catch ( const H5::DataSetIException error ){
      error.printError();
      RUNTIME_ERROR("HDF5IO::saveComplexMatrix at ");
    }
    FG.close();
  } catch( const H5::Exception error ){
    error.printError();
    RUNTIME_ERROR("HDF5IO::saveComplexMatrix at ");
  }
}
Ejemplo n.º 5
0
	/**
	 *@return
	 */
	int HDF5FileReader::getNumberOfVariables()
	{
		long numVars;
		H5::Group group = this->current_file->openGroup("Variables");
		numVars = group.getNumObjs();
		return (int)numVars;
	}
Ejemplo n.º 6
0
void HDF5IO::saveStdVector(const std::string& GroupName, const std::string& Name,
    const std::vector<std::complex<double> >& V)
{
  try{
    H5::CompType ComplexDataType = openCompType("complex");
    hsize_t Dim[1] = {hsize_t(V.size())};
    H5::DataSpace dataspace(1,Dim);
    H5::Group FG = getGroup( GroupName.c_str() );
    try{
      H5::Exception::dontPrint();
      H5::DataSet dataset = FG.openDataSet(Name.c_str());
      dataset.write(V.data(), ComplexDataType, dataspace);
    } catch( const H5::GroupIException not_found_error ){
      H5::DataSet dataset = FG.createDataSet(Name.c_str(), ComplexDataType,
        dataspace);
      dataset.write(V.data(), ComplexDataType);
    } catch( const H5::FileIException error){
      error.printError();
    } catch( const H5::DataSetIException error){
      error.printError();
    }
    FG.close();
  } catch( const H5::Exception err ){
    err.printError();
    RUNTIME_ERROR("HDF5IO::saveComplexStdVector. ");
  }
}
Ejemplo n.º 7
0
void pyne::Material::_load_comp_protocol0(H5::H5File * db, std::string datapath, int row)
{
  H5::Group matgroup = (*db).openGroup(datapath);
  H5::DataSet nucset;

  double nucvalue;
  hsize_t matG = matgroup.getNumObjs();

  // Iterate over datasets in the group.
  for (int matg = 0; matg < matG; matg++)
  {
    std::string nuckey = matgroup.getObjnameByIdx(matg);
    nucset = matgroup.openDataSet(nuckey);
    nucvalue = h5wrap::get_array_index<double>(&nucset, row);

    if (nuckey == "Mass" || nuckey == "MASS" || nuckey == "mass")
      mass = nucvalue;
    else
      comp[pyne::nucname::zzaaam(nuckey)] = nucvalue;

    nucset.close();
  };

  // Set meta data
  name = datapath.substr(datapath.rfind("/")+1, datapath.length());
  atoms_per_mol = -1.0;
};
Ejemplo n.º 8
0
// Stream saving mode
void Bundle2::openSaveStream(const boost::filesystem::path& fileName) {
	// Open file for streaming
	streamFile_ = new H5::H5File(fileName.string(), H5F_ACC_TRUNC);
	storeParameters(*streamFile_);

	// Creating basic file structure
	H5::Group group = streamFile_->createGroup("/POI");
	group.close();
	initFrameStream_();
	initGeometryStream_();
}
Ejemplo n.º 9
0
bool loadStackHDF5( const char* fileName, Image4DSimple& img )
{
#ifdef USE_HDF5
    H5::Exception::dontPrint();
    H5::H5File file( fileName, H5F_ACC_RDONLY );

    for ( size_t i = 0; i < file.getObjCount(); i++ )
    {
        H5std_string name = file.getObjnameByIdx( i );
        if ( name == "Channels" )
        {
            H5::Group channels = file.openGroup( name );

            // Grab the attributes
            H5::Attribute attr = channels.openAttribute( "width" );
            H5::DataType type = attr.getDataType();
            long width, height;
            attr.read( type, &width );
            attr.close();

            attr = channels.openAttribute( "height" );
            attr.read( type, &height );
            attr.close();

            int num_channels = 0;
            // Count the number of channels
            for ( size_t obj = 0; obj < channels.getNumObjs(); obj++ )
                if ( channels.getObjTypeByIdx( obj ) == H5G_DATASET )
                    num_channels++;

            int channel_idx = 0;
            for ( size_t obj = 0; obj < channels.getNumObjs(); obj++ )
            {
                if ( channels.getObjTypeByIdx( obj ) == H5G_DATASET )
                {
                    H5std_string ds_name = channels.getObjnameByIdx( obj );
                    H5::DataSet data = channels.openDataSet( ds_name );
                    uint8_t* buffer = new uint8_t[ data.getStorageSize() ];
                    data.read( buffer, data.getDataType() );
                    QByteArray qbarray( ( const char* )buffer, data.getStorageSize() );
                    data.close();

                    if ( !loadIndexedStackFFMpeg( &qbarray, img, channel_idx++, num_channels,
                                                  width, height ) )
                    {
                        v3d_msg( "Error happened in HDF file reading. Stop. \n", false );
                        return false;
                    }

                    delete [] buffer;
                }
            }
        }
    }

#endif

    return true;
}
Ejemplo n.º 10
0
Archivo: HDF5.hpp Proyecto: rseal/HDF5R
      void ReadAttrib(const std::string& name, T& value, const H5::DataType& dType){
         //attributes are clunky in HDF5++ implementation - this is a workaround
         //template is required to pass the proper value type

         //access the built-in root group and create a new attribute for it.
         H5::Group rootGroup = file_->openGroup("/");
         H5::Attribute attrib = rootGroup.openAttribute(name);

         //write the value to the attribute and close
         attrib.read(dType,reinterpret_cast<void*>(&value));
         attrib.close();
      }
Ejemplo n.º 11
0
	/**
	 * @brief Returns a pointer to a std::vector<float> containing the values of the selected variable
	 *
	 * This allocates a new std::vector<float> pointer.  Make sure you
	 * delete the contents when you done using it, or you will have a memory leak.
	 *
	 * @param variable
	 * @return std::vector<float> containing the values of the selected variable.
	 */
	std::vector<float>* HDF5FileReader::getVariable(const std::string& variable)
	{
		std::vector<float>* variableData = new std::vector<float>();

		if (this->doesVariableExist(variable))
		{
			//std::cout << "reading " << variable << std::endl;
			//get variable number
//			long variableNum = this->getVariableID(variable);

			//std::cout << "variableNum for " << variable << ": " << variableNum << std::endl;
			//get dim sizes

			H5::Group group = this->current_file->openGroup("Variables");
			//cout << "variable: " << variable << ": " << counts[0] << endl;
			H5::DataSet * dataset = new H5::DataSet(group.openDataSet(variable));
			H5::DataSpace dataspace = dataset->getSpace();
			int rank = dataspace.getSimpleExtentNdims(); //should be 1
			hsize_t count[1];
			hsize_t offset[1] = {0};
//			int ndims = dataspace.getSimpleExtentDims(count, NULL);

			//std::cout << "count[0]: " << count[0] << std::endl;
			float * buffer = new float[count[0]];



			dataspace.selectHyperslab(H5S_SELECT_SET, count, offset);

			H5::DataSpace memspace( rank, count);
			memspace.selectHyperslab(H5S_SELECT_SET, count, offset);

			dataset->read(buffer, H5::PredType::NATIVE_FLOAT, memspace, dataspace);
			//std::cout << "after read" << std::endl;

			//add data to vector type, and delete original array
			variableData->reserve(count[0]);
			for (int i = 0; i < count[0]; i++)
			{
				variableData->push_back(buffer[i]);
			}
			//std::cout << "after adding to variableData vector" << std::endl;

			delete[] buffer;
			delete dataset;
			//std::cout << "finished reading " << variable << std::endl;
			//std::cout << "size of variable: " << variableData.size() << std::endl;
			//std::cout << "dimSizes[0]: " << dimSizes[0] << std::endl;

		}

		return variableData;
	}
Ejemplo n.º 12
0
int HDF5IO::loadInt(const std::string& GroupName, const std::string& Name)
{
    try{
      H5::Group FG = getGroup( GroupName );
      H5::DataSet DataSet = FG.openDataSet( Name.c_str());
      int x;
      DataSet.read(&x,H5::PredType::NATIVE_INT);
      FG.close();
      return x;
    }catch( H5::GroupIException not_found_error ){
      RUNTIME_ERROR("No dataset found in loadInt. ");
    }
}
void FeaturePointsRANSAC::loadModel(std::string modelPath)
{
	H5::H5File h5Model;

	try {
		h5Model = H5::H5File(modelPath, H5F_ACC_RDONLY);
	}
	catch (H5::Exception& e) {
		std::string msg( std::string( "Could not open HDF5 file \n" ) + e.getCDetailMsg() );
		throw msg;
	}

	// Load the Shape
	H5::Group modelReconstructive = h5Model.openGroup("/shape/ReconstructiveModel/model");
	H5::DataSet dsMean = modelReconstructive.openDataSet("./mean");
	hsize_t dims[1];
	dsMean.getSpace().getSimpleExtentDims(dims, NULL);	// dsMean.getSpace() leaks memory... maybe a hdf5 bug, maybe vlenReclaim(...) could be a fix. No idea.
	//H5::DataSpace dsp = dsMean.getSpace();
	//dsp.close();

	std::cout << "Dims: " << dims[0] << std::endl;		// TODO: I guess this whole part could be done A LOT better!
	float* testData = new float[dims[0]];
	dsMean.read(testData, H5::PredType::NATIVE_FLOAT);
	this->modelMeanShp.reserve(dims[0]);

	for (unsigned int i=0; i < dims[0]; ++i)	{
		modelMeanShp.push_back(testData[i]);
	}
	delete[] testData;
	testData = NULL;
	dsMean.close();

	// // Load the Texture
	H5::Group modelReconstructiveTex = h5Model.openGroup("/color/ReconstructiveModel/model");
	H5::DataSet dsMeanTex = modelReconstructiveTex.openDataSet("./mean");
	hsize_t dimsTex[1];
	dsMeanTex.getSpace().getSimpleExtentDims(dimsTex, NULL);
	std::cout << "Dims: " << dimsTex[0] << std::endl;		// TODO: I guess this whole part could be done A LOT better!
	float* testDataTex = new float[dimsTex[0]];
	dsMeanTex.read(testDataTex, H5::PredType::NATIVE_FLOAT);
	this->modelMeanTex.reserve(dimsTex[0]);

	for (unsigned int i=0; i < dimsTex[0]; ++i)	{
		modelMeanTex.push_back(testDataTex[i]);
	}
	delete[] testDataTex;
	testDataTex = NULL;
	dsMeanTex.close();

	h5Model.close();
}
Ejemplo n.º 14
0
Archivo: HDF5.hpp Proyecto: rseal/HDF5R
      void WriteAttrib(const std::string& name, const T& value, 
            const H5::DataType& dType, const H5::DataSpace& dSpace){

         //attributes are clunky in HDF5++ implementation - this is a workaround
         //template is required to pass the proper value type

         //access the built-in root group and create a new attribute for it.
         H5::Group rootGroup = file_->openGroup("/");
         H5::Attribute attrib = rootGroup.createAttribute(name,dType,dSpace);

         //write the value to the attribute and close
         attrib.write(dType,&value);
         attrib.close();
      }
Ejemplo n.º 15
0
void HDF5IO::saveNumber(const std::string& GroupName, const std::string& Name,
    unsigned long x)
{
    H5::Group FG = getGroup( GroupName );
    try{
      H5::Exception::dontPrint();
      H5::DataSet dataset = FG.openDataSet( Name.c_str() );
      dataset.write(&x, H5::PredType::NATIVE_ULONG);
    } catch ( const H5::GroupIException not_found_error ){
      H5::DataSet dataset = FG.createDataSet( Name.c_str(), H5::PredType::NATIVE_ULONG, H5::DataSpace());
      dataset.write(&x, H5::PredType::NATIVE_ULONG);
    }
    FG.close();
}
Ejemplo n.º 16
0
bool Bundle2::checkGeometry_(H5::H5File& file) const {
	bool found = false;

	H5::Group root = file.openGroup("/");

	const hsize_t maxObjs = root.getNumObjs();
	for(hsize_t obj = 0; obj < maxObjs; ++obj) {
		string objName = root.getObjnameByIdx(obj);
		if(objName == string("Geometry")) found = true;
	}

	root.close();
	return found;
}
Ejemplo n.º 17
0
size_t HDF5IO::loadUlong(const std::string& GroupName, const std::string& Name)
{
  try{
    H5::Group FG = getGroup( GroupName );
    H5::DataSet DataSet = FG.openDataSet( Name.c_str() );
    size_t x;
    DataSet.read(&x, H5::PredType::NATIVE_ULONG);
    return x;
    FG.close();
  }catch( H5::GroupIException not_found_error ){
    INFO("In Group - " << GroupName << ", and Name is " << Name);
    RUNTIME_ERROR("No dataset found in loadUlong. ");
  }
}
Ejemplo n.º 18
0
	/**
	 * @param attribute
	 * @return
	 */
	bool HDF5FileReader::doesAttributeExist(const std::string& attribute)
	{
		bool exists = false;
		H5::Group group = this->current_file->openGroup("/");
		try
		{
			group.openAttribute(attribute);
			exists = true;
		} catch (H5::AttributeIException& e)
		{
			exists = false;
		}
		return exists;

	}
Ejemplo n.º 19
0
ComplexType HDF5IO::loadComplex(const std::string& GroupName, const std::string& Name)
{
  try{
    H5::CompType ComplexDataType = this->openCompType("complex");
    H5::Group FG = getGroup( GroupName );
    H5::DataSet DataSet = FG.openDataSet(Name.c_str());
    ComplexType C;
    RealType RealImag[2];
    DataSet.read(RealImag, ComplexDataType);
    FG.close();
    return ComplexType(RealImag[0],RealImag[1]);
  }catch( H5::GroupIException not_found_error ){
    RUNTIME_ERROR("No dataset found in loadComplex. ");
  }
}
Ejemplo n.º 20
0
void save_string_attr(H5::Group &g, const char *name, const char *val)
{
  H5::DataSpace string_space(H5S_SCALAR);
  H5::StrType strdatatype(H5::PredType::C_S1, strlen(val)+1);
  H5::Attribute attr = g.createAttribute(name, strdatatype, string_space);
  attr.write(strdatatype, val);
}
Ejemplo n.º 21
0
void HDF5IO::loadStdVector(const std::string& GroupName, const std::string& Name,
    std::vector<RealType>& V)
{
  try{
    H5::Group FG = getGroup( GroupName );
    H5::DataSet DataSet = FG.openDataSet(Name.c_str());
    H5::DataSpace DataSpace = DataSet.getSpace();
    if(DataSpace.getSimpleExtentNdims() != 1)
      throw(H5::DataSpaceIException("HDF5IO::loadRealVector()","Unexpected multidimentional dataspace."));
    V.resize(DataSpace.getSimpleExtentNpoints());
    DataSet.read(V.data(),H5::PredType::NATIVE_DOUBLE);
    FG.close();
  } catch( const H5::Exception err ){
    RUNTIME_ERROR("HDF5IO::loadRealStdVector");
  }
}
Ejemplo n.º 22
0
 H5::DataSet create_dataset(std::string const & key, Args && ... args) const {
  unlink_key_if_exists(key); 
  H5::DataSet res;
  try{ res = _g.createDataSet(key.c_str(), std::forward<Args>(args)...);} 
  catch (H5::GroupIException const & e){ TRIQS_RUNTIME_ERROR << "Error in creating the dataset "<< key <<"\n H5 error message : \n "<< e.getCDetailMsg(); } 
  return res;
 }
Ejemplo n.º 23
0
 /// Open an existing DataSet. Throw it if does not exists
 H5::DataSet open_dataset(std::string const & key) const { 
  if (!has_key(key))  TRIQS_RUNTIME_ERROR << "no dataset "<<key <<" in the group";
  H5::DataSet res;
  try { res = _g.openDataSet(key.c_str());} 
  catch (H5::GroupIException const & e){ TRIQS_RUNTIME_ERROR << "Error in opening the dataset "<< key <<"\n H5 error message : \n "<< e.getCDetailMsg(); } 
  return res;
 }
Ejemplo n.º 24
0
void writeArray(H5::Group &group, const std::string &name,
                const std::string &value) {
  StrType dataType(0, value.length() + 1);
  DataSpace dataSpace = getDataSpace(1);
  H5::DataSet data = group.createDataSet(name, dataType, dataSpace);
  data.write(value, dataType);
}
Ejemplo n.º 25
0
 /// Open a subgroup. Throw it if does not exists
 group open_group(std::string const & key) const { 
  if (!has_key(key))  TRIQS_RUNTIME_ERROR << "no subgroup "<<key <<" in the group";
  group res; 
  try { res = _g.openGroup(key.c_str());} 
  catch (H5::GroupIException const & e){ TRIQS_RUNTIME_ERROR << "Error in opening the subgroup "<< key <<"\n H5 error message : \n "<< e.getCDetailMsg(); } 
  return res;
 }
Ejemplo n.º 26
0
void writeStrAttribute(H5::Group &location, const std::string &name,
                       const std::string &value) {
  StrType attrType(0, H5T_VARIABLE);
  DataSpace attrSpace(H5S_SCALAR);
  auto groupAttr = location.createAttribute(name, attrType, attrSpace);
  groupAttr.write(attrType, value);
}
Ejemplo n.º 27
0
/* only for Eigen3 matrix/vector */
void HDF5IO::saveVector(const std::string& GroupName,
  const std::string& Name, const RealVectorType& V)
{
    hsize_t Dim[1] = {hsize_t(V.size())};
    H5::DataSpace dspace(1,Dim);
    H5::Group FG = getGroup( GroupName );
    try{
      H5::Exception::dontPrint();
      H5::DataSet DataSet = FG.openDataSet(Name.c_str());
      DataSet.write(V.data(),H5::PredType::NATIVE_DOUBLE, dspace);
    } catch ( const H5::GroupIException not_found_error ){
      H5::DataSet DataSet = FG.createDataSet(Name.c_str(),
        H5::PredType::NATIVE_DOUBLE,dspace);
      DataSet.write(V.data(),H5::PredType::NATIVE_DOUBLE);
    }
    FG.close();
}
Ejemplo n.º 28
0
void HDF5IO::loadVector(const std::string& GroupName, const std::string& Name,
  RealVectorType& V)
{
  H5::Group FG = getGroup( GroupName );
  H5::DataSet DataSet = FG.openDataSet(Name.c_str());
  H5::DataSpace DataSpace = DataSet.getSpace();
  if(DataSpace.getSimpleExtentNdims() != 1)
	throw(H5::DataSpaceIException("HDF5IO::loadRealVector()",
    "Unexpected multidimentional dataspace."));
  V.resize(DataSpace.getSimpleExtentNpoints());
  try{
    DataSet.read(V.data(),H5::PredType::NATIVE_DOUBLE);
  }catch( H5::GroupIException not_found_error ){
    RUNTIME_ERROR("No dataset found in loadRealVector. ");
  }
  FG.close();
}
Ejemplo n.º 29
0
void Bundle2::closeSaveStream() {
	H5::DataSpace scalar;

	// Saving remaining POI information
	H5::Group poiGroup = streamFile_->openGroup("/POI");
	H5::Attribute attr = poiGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
	hsize_t count = poiFirstFrame_;
	attr.write(H5::PredType::NATIVE_HSIZE, &count);
	attr.close();
	poiGroup.close();
	scalar.close();

	// Closing HDF5 file
	streamFile_->close();
	delete streamFile_;
	streamFile_ = NULL;
}
Ejemplo n.º 30
0
void File::doAddAttribute(H5::H5Object&loc, std::string name, void*data) {
    double v;
    //hsize_t size;
    H5::Group *d = (H5::Group *)data;

    H5::Attribute a(loc.openAttribute(name));
    //size = loc.getStorageSize();

    //FIXME: double
    a.read( H5::PredType::NATIVE_DOUBLE, &v );

    hsize_t dataSize = 1;
    H5::DataSpace spaceParameters(1,&dataSize,&dataSize);
    H5::Attribute b(d->createAttribute(name,H5::PredType::NATIVE_DOUBLE,
				       spaceParameters));
    b.write( H5::PredType::NATIVE_DOUBLE, &v );
    }