17 LOGGER(
mlog,
"MMonarch3" );
23 fMutexPtr( new
std::mutex() )
44 if(
fFile !=
nullptr )
62 tMonarch3->
fFile =
new H5::H5File( aFilename.c_str(), H5F_ACC_RDONLY );
64 catch( H5::Exception& e )
67 throw M3Exception() <<
"Could not open <" << aFilename <<
"> for reading; an H5::Exception was thrown: " << e.getCDetailMsg();
70 catch( std::exception& e )
73 throw M3Exception() <<
"Could not open <" << aFilename <<
"> for reading; a std::exception was thrown: " << e.
what();
76 if( tMonarch3->
fFile ==
nullptr )
79 throw M3Exception() <<
"Could not open <" << aFilename <<
"> for reading";
82 LDEBUG(
mlog,
"Opened egg file <" << aFilename <<
"> for reading" );
85 tMonarch3->
fHeader->Filename() = aFilename;
98 tMonarch3->
fFile =
new H5::H5File( aFilename.c_str(), H5F_ACC_TRUNC );
100 catch( H5::Exception& e )
103 throw M3Exception() <<
"Could not open <" << aFilename <<
"> for writing; an H5::Exception was thrown: " << e.getCDetailMsg();
106 catch( std::exception& e )
109 throw M3Exception() <<
"Could not open <" << aFilename <<
"> for writing; a std::exception was thrown: " << e.
what();
112 if( tMonarch3->
fFile ==
nullptr )
115 throw M3Exception() <<
"Could not open <" << aFilename <<
"> for writing";
118 LDEBUG(
mlog,
"Opened egg file <" << aFilename <<
"> for writing" );
121 tMonarch3->
fHeader->Filename() = aFilename;
140 catch( H5::Exception& e )
142 throw M3Exception() <<
"HDF5 error while reading the header:\n\t" << e.getCDetailMsg() <<
" (function: " << e.getFuncName() <<
")";
155 for( M3Header::M3StreamHeaders::const_iterator streamIt =
fHeader->StreamHeaders().begin();
156 streamIt !=
fHeader->StreamHeaders().end();
163 catch( H5::Exception& e )
165 throw M3Exception() <<
"HDF5 error while creating stream objects for reading:\n\t" << e.getDetailMsg() <<
" (function: " << e.getFuncName() <<
")";
189 catch( H5::Exception& e )
191 throw M3Exception() <<
"HDF5 error while writing header:\n\t" << e.getDetailMsg() <<
" (function: " << e.getFuncName() <<
")";
203 for( M3Header::M3StreamHeaders::const_iterator streamIt =
fHeader->StreamHeaders().begin();
204 streamIt !=
fHeader->StreamHeaders().end();
211 catch( H5::Exception& e )
213 throw M3Exception() <<
"HDF5 error while creating stream objects:\n\t" << e.getDetailMsg() <<
" (function: " << e.getFuncName() <<
")";
226 LDEBUG(
mlog,
"Finishing reading <" <<
fHeader->Filename() <<
">" );
234 for( std::vector< M3Stream* >::iterator streamIt =
fStreams.begin(); streamIt !=
fStreams.end(); ++streamIt )
240 if(
fFile !=
nullptr )
247 catch( H5::Exception& e )
249 throw M3Exception() <<
"Error while closing: " << e.getDetailMsg() <<
" (function: " << e.getFuncName() <<
")";
257 LINFO(
mlog,
"Finishing writing <" <<
fHeader->Filename() <<
">" );
265 for( std::vector< M3Stream* >::iterator streamIt =
fStreams.begin(); streamIt !=
fStreams.end(); ++streamIt )
267 (*streamIt)->Close();
271 if(
fFile !=
nullptr )
279 catch( H5::Exception& e )
281 throw M3Exception() <<
"Error while closing: " << e.getDetailMsg() <<
" (function: " << e.getFuncName() <<
")";
void FinishReading() const
Close the file.
void Close() const
Close the file.
static const Monarch3 * OpenForReading(const std::string &filename)
void FinishWriting()
Close the file.
virtual const char * what() const
Read/write access for a data stream.
Specialized exception class for Monarch3.
static scarab::logger mlog("M3Header")
std::vector< M3Stream *> fStreams
static Monarch3 * OpenForWriting(const std::string &filename)
Egg file read/write access.