12.2.4.1.4 : Le fichier RawHdf5_hdf5.cpp
Le RawHdf5_hdf5.cpp complet :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
/*************************************** Auteur : Pierre Aubert Mail : pierre.aubert@lapp.in2p3.fr Licence : CeCILL-C ****************************************/ //Warning : this file has been generated automatically by the phoenix_hdf5 program //You can find it at https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixHDF5 //Do NOT modify it #include <string.h> #include <sstream> #include "RawHdf5_hdf5.h" ///Constructor of the class RawHdf5H5 RawHdf5H5::RawHdf5H5() :RawHdf5() { initialisationRawHdf5H5(); } ///Copy constructor of the class RawHdf5H5 /** @param other : RawHdf5H5 to be copied */ RawHdf5H5::RawHdf5H5(const RawHdf5H5 & other) :RawHdf5(other) { initialisationRawHdf5H5(); copyRawHdf5H5(other); } ///Destructor of the class RawHdf5H5 RawHdf5H5::~RawHdf5H5(){ clear(); } ///Equal operator of the class RawHdf5H5 /** @param other : RawHdf5H5 to be copied * @return copied RawHdf5H5 */ RawHdf5H5 & RawHdf5H5::operator = (const RawHdf5H5 & other){ copyRawHdf5H5(other); return *this; } ///Set the HDF5 name of the Table RawHdf5H5 /** @param name : name of the table to be saved */ void RawHdf5H5::setTableName(const std::string & name){ p__tableName = name; } ///Read the table RawHdf5H5 from given file /** @param fileName : name of the HDF5 file to be used */ void RawHdf5H5::read(const std::string & fileName){ H5::H5File file(fileName, H5F_ACC_RDONLY); read(file); } ///Read the table RawHdf5H5 from given file /** @param file : HDF5 file to be used */ void RawHdf5H5::read(const H5::H5File & file){ H5::DataSet dataset = openDataSet(file); readDataSet(dataset); } ///Read the table RawHdf5H5 from given group /** @param group : HDF5 group to be used */ void RawHdf5H5::read(const H5::Group & group){ H5::DataSet dataset = openDataSet(group); readDataSet(dataset); } ///Read the table RawHdf5H5 from given file /** @param fileName : name of the HDF5 file to be used * @param offset : index of the first row the RawHdf5H5 class needs to load * @param nbRow : number of rows the RawHdf5H5 class needs to load (Will reallocate the RawHdf5H5 is the number of rows is greater than the number off already allocated rows) */ void RawHdf5H5::read(const std::string & fileName, size_t offset, size_t nbRow){ H5::H5File file(fileName, H5F_ACC_RDONLY); read(file, offset, nbRow); } ///Read the table RawHdf5H5 from given file /** @param file : HDF5 file to be used * @param offset : index of the first row the RawHdf5H5 class needs to load * @param nbRow : number of rows the RawHdf5H5 class needs to load (Will reallocate the RawHdf5H5 is the number of rows is greater than the number off already allocated rows) */ void RawHdf5H5::read(const H5::H5File & file, size_t offset, size_t nbRow){ H5::DataSet dataset = openDataSet(file); readDataSet(dataset, offset, nbRow); } ///Read the table RawHdf5H5 from given group /** @param group : HDF5 group to be used * @param offset : index of the first row the RawHdf5H5 class needs to load * @param nbRow : number of rows the RawHdf5H5 class needs to load (Will reallocate the RawHdf5H5 is the number of rows is greater than the number off already allocated rows) */ void RawHdf5H5::read(const H5::Group & group, size_t offset, size_t nbRow){ H5::DataSet dataset = openDataSet(group); readDataSet(dataset, offset, nbRow); } ///Create and write the table RawHdf5H5 in given file /** @param fileName : name of the HDF5 file to be used */ void RawHdf5H5::write(const std::string & fileName) const{ H5::H5File file(fileName, H5F_ACC_TRUNC); write(file); } ///Create and write the table RawHdf5H5 in given file /** @param file : HDF5 file to be used */ void RawHdf5H5::write(H5::H5File & file) const{ H5::DataSet dataset = createDataSet(file, p__nbRow); writeDataSet(dataset); } ///Create and write the table RawHdf5H5 in given file /** @param group : HDF5 group to be used */ void RawHdf5H5::write(H5::Group & group) const{ H5::DataSet dataset = createDataSet(group, p__nbRow); writeDataSet(dataset); } ///Create and write the table RawHdf5H5 in given file /** @param fileName : name of the HDF5 file to be used * @param nbRow : full number of rows in the DataSet * @return created DataSet */ H5::DataSet RawHdf5H5::createDataSet(const std::string & fileName, size_t nbRow) const{ H5::H5File file(fileName, H5F_ACC_TRUNC); return createDataSet(file, nbRow); } ///Create the DataSet of the table RawHdf5H5 in given file /** @param file : HDF5 file to be used * @param nbRow : full number of rows in the DataSet * @return created DataSet */ H5::DataSet RawHdf5H5::createDataSet(H5::H5File & file, size_t nbRow) const{ hsize_t dim[1]; dim[0] = nbRow; H5::DataSpace space(1, dim); H5::DataSet dataset = file.createDataSet(p__tableName, getCompTypeAll(), space); return dataset; } ///Create the DataSet of the table RawHdf5H5 in given group /** @param group : HDF5 group to be used * @param nbRow : full number of rows in the DataSet * @return created DataSet */ H5::DataSet RawHdf5H5::createDataSet(H5::Group & group, size_t nbRow) const{ hsize_t dim[1]; dim[0] = nbRow; H5::DataSpace space(1, dim); H5::DataSet dataset = group.createDataSet(p__tableName, getCompTypeAll(), space); return dataset; } ///Open and write the table RawHdf5H5 in given file /** @param fileName : name of the HDF5 file to be used * @return opened DataSet */ H5::DataSet RawHdf5H5::openDataSet(const std::string & fileName) const{ H5::H5File file(fileName, H5F_ACC_RDONLY); return openDataSet(file); } ///Open the DataSet of the table RawHdf5H5 in given file /** @param file : HDF5 file to be used * @return opened DataSet */ H5::DataSet RawHdf5H5::openDataSet(const H5::H5File & file) const{ H5::DataSet dataset = file.openDataSet(p__tableName); return dataset; } ///Open the DataSet of the table RawHdf5H5 in given group /** @param group : HDF5 group to be used * @return opened DataSet */ H5::DataSet RawHdf5H5::openDataSet(const H5::Group & group) const{ H5::DataSet dataset = group.openDataSet(p__tableName); return dataset; } ///Open the DataSet of the table RawHdf5H5 in given file (for block usage) /** @param fileName : name of the HDF5 file to be used * @param nbMaxRowPerBlock : maximum number of rows in the block */ void RawHdf5H5::openDataSetBlock(const std::string & fileName, size_t nbMaxRowPerBlock){ H5::H5File file(fileName, H5F_ACC_RDONLY); openDataSetBlock(file, nbMaxRowPerBlock); } ///Open the DataSet of the table RawHdf5H5 in given file (for block usage) /** @param file : HDF5 file to be used * @param nbMaxRowPerBlock : maximum number of rows in the block */ void RawHdf5H5::openDataSetBlock(const H5::H5File & file, size_t nbMaxRowPerBlock){ H5::DataSet dataset = file.openDataSet(p__tableName); openDataSetBlock(dataset, nbMaxRowPerBlock); } ///Open the DataSet of the table RawHdf5H5 in given group (for block usage) /** @param group : HDF5 group to be used * @param nbMaxRowPerBlock : maximum number of rows in the block */ void RawHdf5H5::openDataSetBlock(const H5::Group & group, size_t nbMaxRowPerBlock){ H5::DataSet dataset = group.openDataSet(p__tableName); openDataSetBlock(dataset, nbMaxRowPerBlock); } ///Get the offset of the attribute signal /** @return offset of the attribute in bytes */ size_t RawHdf5H5::getOffsetSignal() const{ return 0lu; } H5::CompType RawHdf5H5::getCompTypeAll() const{ size_t sizeAll(sizeof(float)*RAWHDF5_SIGNAL_0); H5::CompType typeCol(sizeAll); typeCol.insertMember("signal", getOffsetSignal(), getTypeSignal()); return typeCol; } ///Get DataType of attribute signal (column signal) /** @return DataType of the attribute signal */ H5::CompType RawHdf5H5::getCompTypeSignal() const{ H5::CompType typeCol(sizeof(float)*RAWHDF5_SIGNAL_0); typeCol.insertMember("signal", 0, getTypeSignal()); return typeCol; } ///Get DataType of attribute signal (column signal) /** @return DataType of the attribute signal */ H5::DataType RawHdf5H5::getTypeSignal() const{ hsize_t dims[1]; dims[0] = RAWHDF5_SIGNAL_0; H5::ArrayType arrayType(H5::PredType::NATIVE_FLOAT, 1, dims); return arrayType; } ///Read the given DataSet and fill the Table with it /** @param dataset : dataset to be used */ void RawHdf5H5::readDataSet(const H5::DataSet & dataset){ H5::CompType compType = dataset.getCompType(); readDimSignal(compType); H5::DataSpace dataSpace = dataset.getSpace(); size_t nbEntries(dataSpace.getSimpleExtentNpoints()); resize(nbEntries); if(p__isEnableSignal){ dataset.read(p_signal, getCompTypeSignal()); } } ///Read the given DataSet and fill the Table with it /** @param dataset : dataset to be used * @param offset : index of the first row the RawHdf5H5 class needs to load * @param nbRow : number of rows the RawHdf5H5 class needs to load (Will reallocate the RawHdf5H5 is the number of rows is greater than the number off already allocated rows) */ void RawHdf5H5::readDataSet(const H5::DataSet & dataset, size_t offset, size_t nbRow){ H5::CompType compType = dataset.getCompType(); readDimSignal(compType); H5::DataSpace dataSpace = dataset.getSpace(); size_t nbEntries(dataSpace.getSimpleExtentNpoints()); resize(nbRow); hsize_t dimBlockFile[1]; dimBlockFile[0] = nbEntries; hsize_t offsetBlockBase[1]; offsetBlockBase[0] = offset; hsize_t countFile[1]; countFile[0] = nbRow; H5::DataSpace spaceBlockFile(1, dimBlockFile); spaceBlockFile.selectHyperslab(H5S_SELECT_SET, countFile, offsetBlockBase); hsize_t dimBlockMem[1]; dimBlockMem[0] = nbRow; H5::DataSpace blockMem(1, dimBlockMem); if(p__isEnableSignal){ dataset.read(p_signal, getCompTypeSignal(), blockMem, spaceBlockFile); } } ///Write the given DataSet and fill the Table with it /** @param[out] dataset : dataset to be modified */ void RawHdf5H5::writeDataSet(H5::DataSet & dataset) const{ if(p__isEnableSignal){ dataset.write(p_signal, getCompTypeSignal()); } } ///Open the given DataSet and prepare the block usage (do not load data) /** @param dataset : dataset to be loaded * @param nbMaxRowPerBlock : maximum number of rows in the block * You have to use this method with iterateBlock() and getBlockSize() methods */ void RawHdf5H5::openDataSetBlock(const H5::DataSet & dataset, size_t nbMaxRowPerBlock){ p__blockOffset = 0lu; H5::DataSpace spaceEvent = dataset.getSpace(); p__totalDataSetRow = spaceEvent.getSelectNpoints(); p__dataset = dataset; if(p__totalDataSetRow > nbMaxRowPerBlock){ //If there are more rows than block's size p__blockSize = nbMaxRowPerBlock; }else{ //Otherwise we get all rows p__blockSize = p__totalDataSetRow; } } ///Iterate over the blocks and load the current block /** @return true if the current block has been loaded, false if we reach the end of the blocks */ bool RawHdf5H5::iterateBlock(){ if(p__blockOffset >= p__totalDataSetRow){p__blockOffset = 0lu;return false;} //We reach the end of the DataSet if(p__blockOffset + p__blockSize > p__totalDataSetRow){ p__blockSize = p__totalDataSetRow - p__blockOffset; } readDataSet(p__dataset, p__blockOffset, p__blockSize); //Let's read the current block p__blockOffset += p__blockSize; //Let's increment the offset return true; } ///Get the full size of the loaded DataSet /** @return full size of the loaded DataSet */ size_t RawHdf5H5::getFullDataSetSize() const{ return p__totalDataSetRow; } ///Get the size of the current block /** @return size of the currently loaded block */ size_t RawHdf5H5::getBlockSize() const{ return p__blockSize; } ///Get the offset of the current block /** @return offset of the currently loaded block */ size_t RawHdf5H5::getBlockOffset() const{ return p__blockOffset; } ///Initialises the table RawHdf5H5 void RawHdf5H5::initialisationRawHdf5H5(){ p__tableName = "raw"; } ///Copy function of the class RawHdf5H5 /** @param other : RawHdf5H5 to be copied */ void RawHdf5H5::copyRawHdf5H5(const RawHdf5H5 & other){ //Let's copy proper attributes of the RawHdf5H5 p__tableName = other.p__tableName; p__totalDataSetRow = other.p__totalDataSetRow; p__blockSize = other.p__blockSize; p__blockOffset = other.p__blockOffset; copyRawHdf5(other); } ///Update the dimentions of the tensor signal (column 'signal') /** @param compType : main type to be used to update the tensor dimentions*/ void RawHdf5H5::readDimSignal(const H5::CompType & compType){ int indexCol = compType.getMemberIndex("signal"); H5::ArrayType arrayType = compType.getMemberArrayType(indexCol); //Check if the number of dientions matches if(arrayType.getArrayNDims() != 1){ std::stringstream strError; strError << "RawHdf5H5::readDimSignal wrong number of dimentions : expect 1 but "<< arrayType.getArrayNDims() <<" provided from the file" << std::endl; throw std::runtime_error(strError.str()); } hsize_t dims[1]; arrayType.getArrayDims(dims); } |