示例#1
0
int H5PlanckDataManager::getPointing(string channel, long iStart, int nElements, int * pix, double * qw, double * uw){


    int NPIX = getNPIX();
    if (iStart >= LengthPerChannel) {
        cout << "istart over " << iStart << endl;
    } else {

        //cout << "istart + nELEm " << iStart + nElements << endl;
        if (iStart + nElements > LengthPerChannel) {
            nElements = LengthPerChannel - iStart;
            cout << "istart " << iStart << " new nElem " << nElements << endl;
        }

        H5File file( PointingPath+"_pix_"+channel+".h5", H5F_ACC_RDONLY );
        DataSet dataset = file.openDataSet( "pix" );

        //DATASPACE
        DataSpace dataspace = dataset.getSpace();
        hsize_t  offset[1];       // hyperslab offset in memory
        hsize_t  count[1];        // size of the hyperslab in memory
        offset[0] = GlobalOffset + iStart;
        count[0]  = nElements;
        dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );

        //MEMSPACE
        hsize_t     dimsm[1];
        dimsm[0] = nElements;
        hsize_t      offset_out[1];       // hyperslab offset in memory
        offset_out[0] = 0;
        hsize_t      count_out[1];        // size of the hyperslab in memory
        count_out[0]  = nElements;
        DataSpace memspace( 1, dimsm );
        memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out );

        dataset.read(pix, PredType::NATIVE_INT, memspace, dataspace );

        file = H5File( PointingPath+"_qw_"+channel+".h5", H5F_ACC_RDONLY );
        dataset = file.openDataSet( "qw" );
        //DATASPACE
        dataspace = dataset.getSpace();
        dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );
        //MEMSPACE
        memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out );
        dataset.read(qw, PredType::NATIVE_DOUBLE, memspace, dataspace );

        file = H5File( PointingPath+"_uw_"+channel+".h5", H5F_ACC_RDONLY );
        dataset = file.openDataSet( "uw" );
        //DATASPACE
        dataspace = dataset.getSpace();
        dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );
        //MEMSPACE
        memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out );
        dataset.read(uw, PredType::NATIVE_DOUBLE, memspace, dataspace );
        
    }
    return 0;
}
示例#2
0
int H5PlanckDataManager::getData(string channel, long iStart, int nElements, double* data){
    H5File file( DataPath+"_"+channel+".h5", H5F_ACC_RDONLY );

    if (iStart < LengthPerChannel) {
        if (iStart + nElements >= LengthPerChannel) {
            nElements = LengthPerChannel - iStart;
        }

        DataSet dataset = file.openDataSet( channel );

        //DATASPACE
        DataSpace dataspace = dataset.getSpace();
        hsize_t  offset[1];       // hyperslab offset in memory
        hsize_t  count[1];        // size of the hyperslab in memory
        offset[0] = GlobalOffset + iStart;
        count[0]  = nElements;
        dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );

        //MEMSPACE
        hsize_t     dimsm[1];
        dimsm[0] = nElements;
        hsize_t      offset_out[1];       // hyperslab offset in memory
        offset_out[0] = 0;
        hsize_t      count_out[1];        // size of the hyperslab in memory
        count_out[0]  = nElements;
        DataSpace memspace( 1, dimsm );
        memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out );

        dataset.read( data, PredType::NATIVE_DOUBLE, memspace, dataspace );
    }
    return 0;
}
void
BlockReader::getBlock(int level, int blkno, uchar* block)
{
  int lod2 = qPow(2, level);
  int bb = m_blockSize/lod2;

  int dno = blkno/(m_wblocks*m_hblocks);
  int wno = (blkno - dno*m_wblocks*m_hblocks)/m_hblocks;
  int hno = blkno - dno*m_wblocks*m_hblocks - wno*m_hblocks;

  if (! m_hdf5file)
    {
      QString filename;
      filename = m_baseFilename + ".h5";

      m_hdf5file = new H5File(filename.toAscii().data(),
			      H5F_ACC_RDONLY);

      for(int il=0; il<m_minLevel; il++)
	{
	  QString dataname = QString("lod-%1").arg(il);
	  m_hdf5dataset[il] = m_hdf5file->openDataSet(dataname.toAscii().data());
	}

      m_dataType.copy(m_hdf5dataset[0]);
    }

  DataSpace dataspace = m_hdf5dataset[level].getSpace();

  hsize_t offset[3], count[3];
  offset[0] = dno*bb;
  offset[1] = wno*bb;
  offset[2] = hno*bb;
  count[0] = count[1] = count[2] = bb;

  count[0] = qMin(m_blockSize, m_depth -dno*m_blockSize-1)/lod2;
  count[1] = qMin(m_blockSize, m_width -wno*m_blockSize-1)/lod2;
  count[2] = qMin(m_blockSize, m_height-hno*m_blockSize-1)/lod2;

  dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );

  hsize_t mdim[3];
  mdim[0] = bb;
  mdim[1] = bb;
  mdim[2] = bb;
  hsize_t memoffset[3];
  memoffset[0] = 0;
  memoffset[1] = 0;
  memoffset[2] = 0;
  DataSpace memspace( 3, mdim );
  memspace.selectHyperslab(H5S_SELECT_SET,
			   count,
			   memoffset);

  m_hdf5dataset[level].read( block,
			     m_dataType,
			     memspace,
			     dataspace );
}
int HDF5RecordingData::writeDataRow(int yPos, int xDataSize, HDF5FileBase::DataTypes type, void* data)
{
    hsize_t dim[2],offset[2];
    DataSpace fSpace;
    DataType nativeType;
    if (dimension > 2) return -4; //We're not going to write rows in datasets bigger than 2d.
    //    if (xDataSize != rowDataSize) return -2;
    if ((yPos < 0) || (yPos >= size[1])) return -2;

    try
    {
        if (rowXPos[yPos]+xDataSize > size[0])
        {
            dim[1] = size[1];
            dim[0] = rowXPos[yPos] + xDataSize;
            dSet->extend(dim);

            fSpace = dSet->getSpace();
            fSpace.getSimpleExtentDims(dim);
            size[0]=dim[0];
        }
        if (rowXPos[yPos]+xDataSize > xPos)
        {
            xPos = rowXPos[yPos]+xDataSize;
        }

        dim[0] = xDataSize;
        dim[1] = 1;
        DataSpace mSpace(dimension,dim);

        fSpace = dSet->getSpace();
        offset[0] = rowXPos[yPos];
        offset[1] = yPos;
        fSpace.selectHyperslab(H5S_SELECT_SET, dim, offset);

        nativeType = HDF5FileBase::getNativeType(type);


        dSet->write(data,nativeType,mSpace,fSpace);

        rowXPos.set(yPos,rowXPos[yPos] + xDataSize);
    }
    catch (DataSetIException error)
    {
        PROCESS_ERROR;
    }
    catch (DataSpaceIException error)
    {
        PROCESS_ERROR;
    }
    catch (FileIException error)
    {
        PROCESS_ERROR;
    }
    return 0;
}
示例#5
0
void read_hdf5_image(H5File h5f, Mat &image_out, const char *name, const Rect &roi=Rect(0,0,0,0))
{
    DataSet dataset = h5f.openDataSet(name);
    DataSpace dspace = dataset.getSpace();
    assert (dspace.getSimpleExtentNdims() == 2);
    hsize_t dims[2];
    dspace.getSimpleExtentDims(dims);
    if ((roi.width == 0) && (roi.height == 0)) {
        image_out.create(dims[0], dims[1], CV_32F);
        dspace.selectAll();
    } else {
        image_out.create(roi.height, roi.width, CV_32F);
        hsize_t _offset[2], _size[2];
        _offset[0] = roi.y; _offset[1] = roi.x;
        _size[0] = roi.height; _size[1] = roi.width;
        dspace.selectHyperslab(H5S_SELECT_SET, _size, _offset);
    }
    
    DataSpace imspace;
    float *imdata;
    if (image_out.isContinuous()) {
        dims[0] = image_out.size().height; dims[1] = image_out.size().width;
        imspace = DataSpace(2, dims);
        imspace.selectAll();
        imdata = image_out.ptr<float>();
    } else {
        // we are working with an ROI
        assert (image_out.isSubmatrix());
        Size parent_size; Point parent_ofs;
        image_out.locateROI(parent_size, parent_ofs);
        hsize_t parent_count[2];
        parent_count[0] = parent_size.height; parent_count[1] = parent_size.width;
        imspace.setExtentSimple(2, parent_count);
        hsize_t im_offset[2], im_size[2];
        im_offset[0] = parent_ofs.y; im_offset[1] = parent_ofs.x;
        im_size[0] = image_out.size().height; im_size[1] = image_out.size().width;
        imspace.selectHyperslab(H5S_SELECT_SET, im_size, im_offset);
        imdata = image_out.ptr<float>() - parent_ofs.x - parent_ofs.y * parent_size.width;
    }
    dataset.read(imdata, PredType::NATIVE_FLOAT, imspace, dspace);
}
示例#6
0
H5PlanckDataManager::H5PlanckDataManager(int FirstOd,int  LastOd, Teuchos::Array<string> Channels, string DataPath, string PointingPath, WeightDict Weights) : Channels(Channels),
    DataPath(DataPath), PointingPath(PointingPath), Weights(Weights)
{
    H5File file( PointingPath+".h5", H5F_ACC_RDONLY );

    DataSet dataset = file.openDataSet( "OD" );

    //DATASPACE
    DataSpace dataspace = dataset.getSpace();
    hsize_t  offset[1];       // hyperslab offset in memory
    hsize_t  count[1];        // size of the hyperslab in memory
    offset[0] = FirstOd - 91;
    count[0]  = 1;
    dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );

    //MEMSPACE
    hsize_t     dimsm[1];
    dimsm[0] = 1;
    hsize_t      offset_out[1];       // hyperslab offset in memory
    offset_out[0] = 0;
    hsize_t      count_out[1];        // size of the hyperslab in memory
    count_out[0]  = 1;
    DataSpace memspace( 1, dimsm );
    memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out );

    long odstart[1];
    dataset.read( odstart, PredType::NATIVE_LONG, memspace, dataspace );

    GlobalOffset = odstart[0]; //computed from first OD


    offset[0] = LastOd + 1 - 91;
    dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );
    dataset.read( odstart, PredType::NATIVE_LONG, memspace, dataspace );

    LengthPerChannel = odstart[0] - GlobalOffset;
    //LengthPerChannel = 3000000 * 6 / 4.;
    TotalLength = LengthPerChannel * Channels.size(); //computed from last OD - first OD

};
int HDF5RecordingData::writeDataBlock(int xDataSize, int yDataSize, HDF5FileBase::DataTypes type, void* data)
{
    hsize_t dim[3],offset[3];
    DataSpace fSpace;
    DataType nativeType;

    dim[2] = size[2];
    //only modify y size if new required size is larger than what we had.
    if (yDataSize > size[1])
        dim[1] = yDataSize;
    else
        dim[1] = size[1];
    dim[0] = xPos + xDataSize;
    try
    {
        //First be sure that we have enough space
        dSet->extend(dim);

        fSpace = dSet->getSpace();
        fSpace.getSimpleExtentDims(dim);
        size[0]=dim[0];
        if (dimension > 1)
            size[1]=dim[1];

        //Create memory space
        dim[0]=xDataSize;
        dim[1]=yDataSize;
        dim[2] = size[2];

        DataSpace mSpace(dimension,dim);
        //select where to write
        offset[0]=xPos;
        offset[1]=0;
        offset[2]=0;

        fSpace.selectHyperslab(H5S_SELECT_SET, dim, offset);

        nativeType = HDF5FileBase::getNativeType(type);

        dSet->write(data,nativeType,mSpace,fSpace);
        xPos += xDataSize;
    }
    catch (DataSetIException error)
    {
        PROCESS_ERROR;
    }
    catch (DataSpaceIException error)
    {
        PROCESS_ERROR;
    }
    return 0;
}
示例#8
0
void write_hdf5_image(H5File h5f, const char *name, const Mat &im)
{
    DSetCreatPropList cparms;
    hsize_t chunk_dims[2] = {256, 256};
    hsize_t dims[2];
    dims[0] = im.size().height;
    dims[1] = im.size().width;
  
    if (chunk_dims[0] > dims[0]) {
        chunk_dims[0] = dims[0];
    }
    if (chunk_dims[1] > dims[1]) {
        chunk_dims[1] = dims[1];
    }

    cparms.setChunk(2, chunk_dims);
    cparms.setShuffle();
    cparms.setDeflate(5);

    DataSet dataset = h5f.createDataSet(name, PredType::NATIVE_FLOAT,
                                        DataSpace(2, dims, dims),
                                        cparms);

    Mat image;
    if (im.type() !=  CV_32F)
        im.convertTo(image, CV_32F);
    else
        image = im;
    
    DataSpace imspace;
    float *imdata;
    if (image.isContinuous()) {
        imspace = dataset.getSpace(); // same size as 
        imspace.selectAll();
        imdata = image.ptr<float>();
    } else {
        // we are working with an ROI
        assert (image.isSubmatrix());
        Size parent_size; Point parent_ofs;
        image.locateROI(parent_size, parent_ofs);
        hsize_t parent_count[2];
        parent_count[0] = parent_size.height; parent_count[1] = parent_size.width;
        imspace.setExtentSimple(2, parent_count);
        hsize_t im_offset[2], im_size[2];
        im_offset[0] = parent_ofs.y; im_offset[1] = parent_ofs.x;
        im_size[0] = image.size().height; im_size[1] = image.size().width;
        imspace.selectHyperslab(H5S_SELECT_SET, im_size, im_offset);
        imdata = image.ptr<float>() - parent_ofs.x - parent_ofs.y * parent_size.width;
    }
    dataset.write(imdata, PredType::NATIVE_FLOAT, imspace);
}
示例#9
0
  H5::DataSpace dataspace_from_LS (  
    mini_vector<hsize_t, R> const & Ltot, 
    mini_vector<hsize_t, R> const & L, 
    mini_vector<hsize_t, R> const & S, 
    mini_vector<hsize_t, R> const & offset = mini_vector<hsize_t,R>() ) { 
#ifdef TRIQS_ARRAYS_DEBUG_H5_SLICE
   std::cerr  << "total lens in dataspace_from_LS"<< Ltot.to_string() << std::endl ;
   std::cerr  << "lens in dataspace_from_LS"<< L.to_string() << std::endl ;
   std::cerr  << "Strides in dataspace_from_LS "<< S.to_string() << std::endl ;
   std::cerr  << "offset in dataspace_from_LS"<< offset.to_string() << std::endl ;
#endif
   static const unsigned int rank = R + (IsComplex ? 1 : 0);
   hsize_t totdimsf[rank], dimsf [rank], stridesf[rank], offsetf[rank];  // dataset dimensions
   for (size_t u=0; u<R ; ++u) { offsetf[u] = offset[u]; dimsf[u] = L[u]; totdimsf[u] = Ltot[u]; stridesf[u] = S[u]; }
   if (IsComplex) { offsetf[rank-1]=0; dimsf[rank-1]=2; totdimsf[rank-1] = 2; stridesf[rank-1]=1; }
   DataSpace ds ( rank, totdimsf );
   ds.selectHyperslab (H5S_SELECT_SET , dimsf, offsetf, stridesf);
   return ds;
  }
void HDF5HandlerBase::save(const std::vector<int> &dataPoints) {

    // Return if no data to add
    if (dataPoints.size() < 1)
        return;

    // dataset.write needs not const value of data
    int *data = const_cast<int*>(&dataPoints[0]);

    // Determine value of
    hsize_t dimsext[1];
    dimsext[0] = dataPoints.size();

    hsize_t size[1];
    hsize_t offset[1];


    try {
        DataSpace filespace = dataset.getSpace();
        int ndims = filespace.getSimpleExtentNdims();
        hsize_t dims[ndims];
        filespace.getSimpleExtentDims(dims);

        size[0] = dims[0] + dimsext[0];
        dataset.extend(size);

        offset[0] = dims[0];
        filespace = dataset.getSpace();
        filespace.selectHyperslab(H5S_SELECT_SET, dimsext, offset);

        DataSpace memspace = DataSpace(1, dimsext, NULL);

        dataset.write(data, PredType::NATIVE_INT, memspace, filespace);

        filespace.close();
        memspace.close();

    } catch (Exception &error) {
        throw;
    }


}
示例#11
0
//Writes data into an array of HDF5 datatype TYPE
void ArfRecordingData::writeCompoundData(int xDataSize, int yDataSize, DataType type, void* data)
{
    hsize_t dim[3],offset[3];
    DataSpace fSpace;
    DataType nativeType;

    dim[2] = size[2];
    //only modify y size if new required size is larger than what we had.
    if (yDataSize > size[1])
        dim[1] = yDataSize;
    else
        dim[1] = size[1];
    dim[0] = xPos + xDataSize;

        //First be sure that we have enough space
        dSet->extend(dim);

        fSpace = dSet->getSpace();
        fSpace.getSimpleExtentDims(dim);
        size[0]=dim[0];
        if (dimension > 1)
            size[1]=dim[1];

        //Create memory space
        dim[0]=xDataSize;
        dim[1]=yDataSize;
        dim[2] = size[2];

        DataSpace mSpace(dimension,dim);
        //select where to write
        offset[0]=xPos;
        offset[1]=0;
        offset[2]=0;

        fSpace.selectHyperslab(H5S_SELECT_SET, dim, offset);

        dSet->write(data,type,mSpace,fSpace);
        xPos += xDataSize;
}
示例#12
0
//write data into a 1-d array, with type wrapped by ArfFileBase::DataTypes, instead of raw HDF5 type
int ArfRecordingData::writeDataChannel(int dataSize, ArfFileBase::DataTypes type, void* data)
{
    //Data is 1-dimensional
    hsize_t dim[3],offset[3];
    DataSpace fSpace;
    
    DataType nativeType = ArfFileBase::getNativeType(type);
    if (xPos+dataSize > size[0])
    {
        dim[0] = xPos + dataSize;
        dim[1] = 0;
        dim[2] = 0;
        dSet->extend(dim);
    }
    
    fSpace = dSet->getSpace();
    fSpace.getSimpleExtentDims(dim);
    size[0]=dim[0];
    if (dimension > 1)
        size[1]=dim[1];

    //Create memory space
    dim[0]= dataSize;
    dim[1]= 0;
    dim[2]= 0;

    DataSpace mSpace(dimension,dim);
    //select where to write
    offset[0]=xPos;
    offset[1]=0;
    offset[2]=0;

    fSpace.selectHyperslab(H5S_SELECT_SET, dim, offset);
    
    
    dSet->write(data,nativeType,mSpace,fSpace);
    xPos = xPos + dataSize;
}
示例#13
0
void write_feature(H5File h5f, const Mat &image_in, const char *name)
{
    // make sure the sizes match
    assert (imsize == image_in.size());

    // make sure the image is in native float
    Mat image;
    if (image_in.type() !=  CV_32F)
        image_in.convertTo(image, CV_32F);
    else
        image = image_in;
    
    DataSet dataset = create_dataset(h5f, name);

    DataSpace imspace;
    float *imdata;
    if (image.isContinuous()) {
        imspace = dataset.getSpace(); // same size as 
        imspace.selectAll();
        imdata = image.ptr<float>();
    } else {
        // we are working with an ROI
        assert (image.isSubmatrix());
        Size parent_size; Point parent_ofs;
        image.locateROI(parent_size, parent_ofs);
        hsize_t parent_count[2];
        parent_count[0] = parent_size.height; parent_count[1] = parent_size.width;
        imspace.setExtentSimple(2, parent_count);
        hsize_t im_offset[2], im_size[2];
        im_offset[0] = parent_ofs.y; im_offset[1] = parent_ofs.x;
        im_size[0] = image.size().height; im_size[1] = image.size().width;
        imspace.selectHyperslab(H5S_SELECT_SET, im_size, im_offset);
        imdata = image.ptr<float>() - parent_ofs.x - parent_ofs.y * parent_size.width;
    }
    dataset.write(imdata, PredType::NATIVE_FLOAT, imspace);
}
示例#14
0
/*
 * Compile history information in every epoch.
 *
 * @param[in] vtClr      Vector of pointer to the Cluster object.
 * @param[in] vtClrInfo  Vecttor of pointer to the ClusterInfo object.
 */
void Hdf5Recorder::compileHistories(vector<Cluster *> &vtClr, vector<ClusterInfo *> &vtClrInfo)
{
    int max_spikes = (int) ((m_sim_info->epochDuration * m_sim_info->maxFiringRate));

    unsigned int iProbe = 0;    // index of the probedNeuronsLayout vector
    bool fProbe = false;

    for (CLUSTER_INDEX_TYPE iCluster = 0; iCluster < vtClr.size(); iCluster++)
    {
        AllSpikingNeurons *neurons = dynamic_cast<AllSpikingNeurons*>(vtClr[iCluster]->m_neurons);

        // output spikes
        int neuronLayoutIndex = vtClrInfo[iCluster]->clusterNeuronsBegin;
        int totalClusterNeurons = vtClrInfo[iCluster]->totalClusterNeurons;
        for (int iNeuron = 0; iNeuron < totalClusterNeurons; iNeuron++, neuronLayoutIndex++)
        {
            // true if this is a probed neuron
            fProbe = ((iProbe < m_model->getLayout()->m_probed_neuron_list.size()) && (neuronLayoutIndex == m_model->getLayout()->m_probed_neuron_list[iProbe]));

            uint64_t* pSpikes = neurons->spike_history[iNeuron];

            int& spike_count = neurons->spikeCount[iNeuron];
            int& offset = neurons->spikeCountOffset[iNeuron];
            for (int i = 0, idxSp = offset; i < spike_count; i++, idxSp++)
            {
                // Single precision (float) gives you 23 bits of significand, 8 bits of exponent, 
                // and 1 sign bit. Double precision (double) gives you 52 bits of significand, 
                // 11 bits of exponent, and 1 sign bit. 
                // Therefore, single precision can only handle 2^23 = 8,388,608 simulation steps 
                // or 8 epochs (1 epoch = 100s, 1 simulation step = 0.1ms).

                if (idxSp >= max_spikes) idxSp = 0;
                // compile network wide burstiness index data in 1s bins
                int idx1 = static_cast<int>( static_cast<double>( pSpikes[idxSp] ) *  m_sim_info->deltaT
                    - ( (m_sim_info->currentStep - 1) * m_sim_info->epochDuration ) );
                assert(idx1 >= 0 && idx1 < m_sim_info->epochDuration);
                burstinessHist[idx1]++;

                // compile network wide spike count in 10ms bins
                int idx2 = static_cast<int>( static_cast<double>( pSpikes[idxSp] ) * m_sim_info->deltaT * 100
                    - ( (m_sim_info->currentStep - 1) * m_sim_info->epochDuration * 100 ) );
                assert(idx2 >= 0 && idx2 < m_sim_info->epochDuration * 100);
                spikesHistory[idx2]++;

                // compile spikes time of the probed neuron (append spikes time)
                if (fProbe)
                {
                    spikesProbedNeurons[iProbe].insert(spikesProbedNeurons[iProbe].end(), pSpikes[idxSp]);
                }
            }

            if (fProbe)
            {
                iProbe++;
            }
        }

        // clear spike count
        neurons->clearSpikeCounts(m_sim_info, vtClrInfo[iCluster], vtClr[iCluster]);
    }
    try
    {
        // write burstiness index
        hsize_t offset[2], count[2];
        hsize_t dimsm[2];
        DataSpace* dataspace;
        DataSpace* memspace;

        offset[0] = (m_sim_info->currentStep - 1) * m_sim_info->epochDuration;
        count[0] = m_sim_info->epochDuration;
        dimsm[0] = m_sim_info->epochDuration;
        memspace = new DataSpace(1, dimsm, NULL);
        dataspace = new DataSpace(dataSetBurstHist->getSpace());
        dataspace->selectHyperslab(H5S_SELECT_SET, count, offset);
        dataSetBurstHist->write(burstinessHist, PredType::NATIVE_INT, *memspace, *dataspace); 
        memset(burstinessHist, 0, static_cast<int>(m_sim_info->epochDuration * sizeof(int)));
        delete dataspace;
        delete memspace;

        // write network wide spike count in 10ms bins
        offset[0] = (m_sim_info->currentStep - 1) * m_sim_info->epochDuration * 100;
        count[0] = m_sim_info->epochDuration * 100;
        dimsm[0] = m_sim_info->epochDuration * 100;
        memspace = new DataSpace(1, dimsm, NULL);
        dataspace = new DataSpace(dataSetSpikesHist->getSpace());
        dataspace->selectHyperslab(H5S_SELECT_SET, count, offset);
        dataSetSpikesHist->write(spikesHistory, PredType::NATIVE_INT, *memspace, *dataspace); 
        memset(spikesHistory, 0, static_cast<int>(m_sim_info->epochDuration * 100 * sizeof(int)));
        delete dataspace;
        delete memspace;

        // write spikes data of probed neurons
        if (m_model->getLayout()->m_probed_neuron_list.size() > 0)
        {
            unsigned int max_size = 0;
            for (unsigned int i = 0; i < m_model->getLayout()->m_probed_neuron_list.size(); i++)
            {
                unsigned int size = spikesProbedNeurons[i].size() + offsetSpikesProbedNeurons[i];
                max_size = (max_size > size) ? max_size : size;
            }
            dimsm[0] = static_cast<hsize_t>(max_size);
            dimsm[1] = static_cast<hsize_t>(m_model->getLayout()->m_probed_neuron_list.size());

            // extend the dataset
            dataSetSpikesProbedNeurons->extend(dimsm);
            dataspace = new DataSpace(dataSetSpikesProbedNeurons->getSpace());

            // write it!
            for (unsigned int i = 0; i < m_model->getLayout()->m_probed_neuron_list.size(); i++)
            {
                dimsm[0] = spikesProbedNeurons[i].size();
                dimsm[1] = 1;
                memspace = new DataSpace(2, dimsm, NULL);

                offset[0] = offsetSpikesProbedNeurons[i];
                offset[1] = i;
                count[0] = spikesProbedNeurons[i].size();
                count[1] = 1;
                dataspace->selectHyperslab(H5S_SELECT_SET, count, offset);
                offsetSpikesProbedNeurons[i] += spikesProbedNeurons[i].size(); 

                dataSetSpikesProbedNeurons->write(static_cast<uint64_t*>(&(spikesProbedNeurons[i][0])), PredType::NATIVE_UINT64, *memspace, *dataspace);

                // clear the probed spike data
                spikesProbedNeurons[i].clear();
                delete memspace;
            }

            delete dataspace;
        }
    }

    // catch failure caused by the H5File operations
    catch( FileIException error )
    {
        error.printError();
        return;
    }

    // catch failure caused by the DataSet operations
    catch( DataSetIException error )
    {
        error.printError();
        return;
    }

    // catch failure caused by the DataSpace operations
    catch( DataSpaceIException error )
    {
        error.printError();
        return;
    }

    // catch failure caused by the DataType operations
    catch( DataTypeIException error )
    {
        error.printError();
        return;
    }
}
示例#15
0
文件: chunks.cpp 项目: Starlink/hdf5
int main (void)
{
    hsize_t	i, j;

    // Try block to detect exceptions raised by any of the calls inside it
    try
    {
	/*
	 * Turn off the auto-printing when failure occurs so that we can
	 * handle the errors appropriately
	 */
	Exception::dontPrint();

	/*
	 * Open the file and the dataset.
	 */
	H5File file( FILE_NAME, H5F_ACC_RDONLY );
	DataSet dataset = file.openDataSet( DATASET_NAME );

	/*
	 * Get filespace for rank and dimension
	 */
	DataSpace filespace = dataset.getSpace();

	/*
	 * Get number of dimensions in the file dataspace
	 */
	int rank = filespace.getSimpleExtentNdims();

	/*
	 * Get and print the dimension sizes of the file dataspace
	 */
	hsize_t dims[2]; 	// dataset dimensions
	rank = filespace.getSimpleExtentDims( dims );
	cout << "dataset rank = " << rank << ", dimensions "
	     << (unsigned long)(dims[0]) << " x "
	     << (unsigned long)(dims[1]) << endl;

	/*
	 * Define the memory space to read dataset.
	 */
	DataSpace mspace1(RANK, dims);

	/*
	 * Read dataset back and display.
	 */
	int data_out[NX][NY];  // buffer for dataset to be read
	dataset.read( data_out, PredType::NATIVE_INT, mspace1, filespace );

	cout << "\n";
	cout << "Dataset: \n";
	for (j = 0; j < dims[0]; j++)
	{
	    for (i = 0; i < dims[1]; i++)
		cout << data_out[j][i] << " ";
	    cout << endl;
	}

	/*
	 *	    dataset rank 2, dimensions 10 x 5
	 *	    chunk rank 2, dimensions 2 x 5

	 *	    Dataset:
	 *	    1 1 1 3 3
	 *	    1 1 1 3 3
	 *	    1 1 1 0 0
	 *	    2 0 0 0 0
	 *	    2 0 0 0 0
	 *	    2 0 0 0 0
	 *	    2 0 0 0 0
	 *	    2 0 0 0 0
	 *	    2 0 0 0 0
	 *	    2 0 0 0 0
	 */

	/*
	 * Read the third column from the dataset.
	 * First define memory dataspace, then define hyperslab
	 * and read it into column array.
	 */
	hsize_t col_dims[1];
	col_dims[0] = 10;
	DataSpace mspace2( RANKC, col_dims );

	/*
	 * Define the column (hyperslab) to read.
	 */
	hsize_t offset[2] = { 0, 2 };
	hsize_t  count[2] = { 10, 1 };
	int column[10];  // buffer for column to be read

	/*
	 * Define hyperslab and read.
	 */
	filespace.selectHyperslab( H5S_SELECT_SET, count, offset );
	dataset.read( column, PredType::NATIVE_INT, mspace2, filespace );

	cout << endl;
	cout << "Third column: " << endl;
	for (i = 0; i < 10; i++)
	    cout << column[i] << endl;

	/*
	 *	    Third column:
	 *	    1
	 *	    1
	 *	    1
	 *	    0
	 *	    0
	 *	    0
	 *	    0
	 *	    0
	 *	    0
	 *	    0
	 */

	/*
	 * Get creation properties list.
	 */
	DSetCreatPropList cparms = dataset.getCreatePlist();

	/*
	 * Check if dataset is chunked.
	 */
	hsize_t chunk_dims[2];
	int     rank_chunk;
	if( H5D_CHUNKED == cparms.getLayout() )
	{
	    /*
	     * Get chunking information: rank and dimensions
	     */
	    rank_chunk = cparms.getChunk( 2, chunk_dims);
	    cout << "chunk rank " << rank_chunk << "dimensions "
		<< (unsigned long)(chunk_dims[0]) << " x "
		<< (unsigned long)(chunk_dims[1]) << endl;

	    /*
	     * Define the memory space to read a chunk.
	     */
	    DataSpace mspace3( rank_chunk, chunk_dims );

	    /*
	     * Define chunk in the file (hyperslab) to read.
	     */
	    offset[0] = 2;
	    offset[1] = 0;
	    count[0]  = chunk_dims[0];
	    count[1]  = chunk_dims[1];
	    filespace.selectHyperslab( H5S_SELECT_SET, count, offset );

	    /*
	     * Read chunk back and display.
	     */
	    int chunk_out[2][5];   // buffer for chunk to be read
	    dataset.read( chunk_out, PredType::NATIVE_INT, mspace3, filespace );
	    cout << endl;
	    cout << "Chunk:" << endl;
	    for (j = 0; j < chunk_dims[0]; j++)
	    {
		for (i = 0; i < chunk_dims[1]; i++)
		    cout << chunk_out[j][i] << " ";
		cout << endl;
	    }
	    /*
	     *	 Chunk:
	     *	 1 1 1 0 0
	     *	 2 0 0 0 0
	     */
	}
    }  // end of try block

    // catch failure caused by the H5File operations
    catch( FileIException error )
    {
	error.printErrorStack();
	return -1;
    }

    // catch failure caused by the DataSet operations
    catch( DataSetIException error )
    {
	error.printErrorStack();
	return -1;
    }

    // catch failure caused by the DataSpace operations
    catch( DataSpaceIException error )
    {
	error.printErrorStack();
	return -1;
    }
    return 0;
}