bool TraceChunkSerializer::Write(H5File &h5, GridMesh<TraceChunk> &dataMesh) { mNumChunks = dataMesh.GetNumBin(); ClockTimer timer; mChunks = (struct FlowChunk *) malloc(sizeof(struct FlowChunk) * mNumChunks); ArrangeDataForWriting(dataMesh, mChunks); computeMicroSec = timer.GetMicroSec(); hsize_t dims1[1]; dims1[0] = mNumChunks; hid_t fcDataSpace = H5Screate_simple(1, dims1, NULL); hid_t charArrayType = H5Tvlen_create (H5T_NATIVE_CHAR); hid_t charArrayType2 = H5Tvlen_create (H5T_NATIVE_CHAR); hid_t fcType = H5Tcreate(H5T_COMPOUND, sizeof(struct FlowChunk)); H5Tinsert(fcType, "CompressionType", HOFFSET(struct FlowChunk, CompressionType), H5T_NATIVE_B64); H5Tinsert(fcType, "ChipRow", HOFFSET(struct FlowChunk, ChipRow), H5T_NATIVE_B64); H5Tinsert(fcType, "ChipCol", HOFFSET(struct FlowChunk, ChipCol), H5T_NATIVE_B64); H5Tinsert(fcType, "ChipFrame", HOFFSET(struct FlowChunk, ChipFrame), H5T_NATIVE_B64); H5Tinsert(fcType, "RowStart", HOFFSET(struct FlowChunk, RowStart), H5T_NATIVE_B64); H5Tinsert(fcType, "ColStart", HOFFSET(struct FlowChunk, ColStart), H5T_NATIVE_B64); H5Tinsert(fcType, "FrameStart", HOFFSET(struct FlowChunk, FrameStart), H5T_NATIVE_B64); H5Tinsert(fcType, "FrameStep", HOFFSET(struct FlowChunk, FrameStep), H5T_NATIVE_B64); H5Tinsert(fcType, "Height", HOFFSET(struct FlowChunk, Height), H5T_NATIVE_B64); H5Tinsert(fcType, "Width", HOFFSET(struct FlowChunk, Width), H5T_NATIVE_B64); H5Tinsert(fcType, "Depth", HOFFSET(struct FlowChunk, Depth), H5T_NATIVE_B64); H5Tinsert(fcType, "OrigFrames", HOFFSET(struct FlowChunk, OrigFrames), H5T_NATIVE_B64); H5Tinsert(fcType, "StartDetailedTime", HOFFSET(struct FlowChunk, StartDetailedTime), H5T_NATIVE_INT); H5Tinsert(fcType, "StopDetailedTime", HOFFSET(struct FlowChunk, StopDetailedTime), H5T_NATIVE_INT); H5Tinsert(fcType, "LeftAvg", HOFFSET(struct FlowChunk, LeftAvg), H5T_NATIVE_INT); H5Tinsert(fcType, "T0", HOFFSET(struct FlowChunk, T0), H5T_NATIVE_FLOAT); H5Tinsert(fcType, "Sigma", HOFFSET(struct FlowChunk, Sigma), H5T_NATIVE_FLOAT); H5Tinsert(fcType, "TMidNuc", HOFFSET(struct FlowChunk, TMidNuc), H5T_NATIVE_FLOAT); H5Tinsert(fcType, "BaseFrameRate", HOFFSET(struct FlowChunk, BaseFrameRate), H5T_NATIVE_FLOAT); H5Tinsert(fcType, "DeltaFrame", HOFFSET(struct FlowChunk, DeltaFrame), charArrayType2); H5Tinsert(fcType, "Data", HOFFSET(struct FlowChunk, Data), charArrayType); timer.StartTimer(); hid_t dataset = H5Dcreate2(h5.GetFileId(), "FlowChunk", fcType, fcDataSpace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); herr_t status = H5Dwrite(dataset, fcType, H5S_ALL, H5S_ALL, H5P_DEFAULT, mChunks); status = H5Dvlen_reclaim(fcType, fcDataSpace, H5P_DEFAULT, mChunks); // // delete [] mChunks; free(mChunks); mChunks = NULL; ION_ASSERT(status == 0, "Couldn't write dataset"); H5Tclose(fcType); H5Tclose(charArrayType); H5Tclose(charArrayType2); H5Sclose(fcDataSpace); H5Dclose(dataset); ioMicroSec += timer.GetMicroSec(); return status == 0; }
bool TraceChunkSerializer::Read(H5File &h5, GridMesh<TraceChunk> &dataMesh) { hid_t dataset = H5Dopen2(h5.GetFileId(), "FlowChunk", H5P_DEFAULT); // hid_t datatype = H5Dget_type(dataset); /* datatype handle */ static pthread_once_t onceControl = PTHREAD_ONCE_INIT; int err = pthread_once(&onceControl, InitSdatReadSem); if (err != 0) { cout << "Error with pthread once." << endl; } hid_t dataspace = H5Dget_space(dataset); int rank = H5Sget_simple_extent_ndims(dataspace); std::vector<hsize_t> dims; dims.resize(rank); int status = H5Sget_simple_extent_dims(dataspace, &dims[0], NULL); if (mChunks != NULL) { delete [] mChunks; } mChunks = new FlowChunk[dims[0]]; mNumChunks = dims[0]; hid_t fcDataSpace = H5Screate_simple(1, &dims[0], NULL); hid_t charArrayType = H5Tvlen_create (H5T_NATIVE_CHAR); hid_t charArrayType2 = H5Tvlen_create (H5T_NATIVE_CHAR); hid_t fcType = H5Tcreate(H5T_COMPOUND, sizeof(struct FlowChunk)); H5Tinsert(fcType, "CompressionType", HOFFSET(struct FlowChunk, CompressionType), H5T_NATIVE_B64); H5Tinsert(fcType, "ChipRow", HOFFSET(struct FlowChunk, ChipRow), H5T_NATIVE_B64); H5Tinsert(fcType, "ChipCol", HOFFSET(struct FlowChunk, ChipCol), H5T_NATIVE_B64); H5Tinsert(fcType, "ChipFrame", HOFFSET(struct FlowChunk, ChipFrame), H5T_NATIVE_B64); H5Tinsert(fcType, "RowStart", HOFFSET(struct FlowChunk, RowStart), H5T_NATIVE_B64); H5Tinsert(fcType, "ColStart", HOFFSET(struct FlowChunk, ColStart), H5T_NATIVE_B64); H5Tinsert(fcType, "FrameStart", HOFFSET(struct FlowChunk, FrameStart), H5T_NATIVE_B64); H5Tinsert(fcType, "FrameStep", HOFFSET(struct FlowChunk, FrameStep), H5T_NATIVE_B64); H5Tinsert(fcType, "Height", HOFFSET(struct FlowChunk, Height), H5T_NATIVE_B64); H5Tinsert(fcType, "Width", HOFFSET(struct FlowChunk, Width), H5T_NATIVE_B64); H5Tinsert(fcType, "Depth", HOFFSET(struct FlowChunk, Depth), H5T_NATIVE_B64); H5Tinsert(fcType, "OrigFrames", HOFFSET(struct FlowChunk, OrigFrames), H5T_NATIVE_B64); H5Tinsert(fcType, "StartDetailedTime", HOFFSET(struct FlowChunk, StartDetailedTime), H5T_NATIVE_INT); H5Tinsert(fcType, "StopDetailedTime", HOFFSET(struct FlowChunk, StopDetailedTime), H5T_NATIVE_INT); H5Tinsert(fcType, "LeftAvg", HOFFSET(struct FlowChunk, LeftAvg), H5T_NATIVE_INT); H5Tinsert(fcType, "T0", HOFFSET(struct FlowChunk, T0), H5T_NATIVE_FLOAT); H5Tinsert(fcType, "Sigma", HOFFSET(struct FlowChunk, Sigma), H5T_NATIVE_FLOAT); H5Tinsert(fcType, "TMidNuc", HOFFSET(struct FlowChunk, TMidNuc), H5T_NATIVE_FLOAT); H5Tinsert(fcType, "BaseFrameRate", HOFFSET(struct FlowChunk, BaseFrameRate), H5T_NATIVE_FLOAT); H5Tinsert(fcType, "DeltaFrame", HOFFSET(struct FlowChunk, DeltaFrame), charArrayType2); H5Tinsert(fcType, "Data", HOFFSET(struct FlowChunk, Data), charArrayType); ClockTimer timer; IonImageSem::Take(); status = H5Dread(dataset, fcType, H5S_ALL, H5S_ALL, H5P_DEFAULT, mChunks); IonImageSem::Give(); ioMicroSec = timer.GetMicroSec(); ION_ASSERT(status == 0, "Couldn' read dataset"); timer.StartTimer(); dataMesh.Init(mChunks[0].ChipRow, mChunks[0].ChipCol, mChunks[0].Height, mChunks[0].Width); ION_ASSERT(dataMesh.GetNumBin() == mNumChunks, "Didn't get number of chunks expected"); DecompressFromReading(mChunks, dataMesh); computeMicroSec = timer.GetMicroSec(); timer.StartTimer(); status = H5Dvlen_reclaim(fcType, fcDataSpace, H5P_DEFAULT, mChunks); delete [] mChunks; mChunks = NULL; H5Tclose(fcType); H5Tclose(charArrayType); H5Tclose(charArrayType2); H5Sclose(fcDataSpace); H5Dclose(dataset); ioMicroSec += timer.GetMicroSec(); return status == 0; }