#include <raw_ofstream.h>
Public Member Functions | |
int | write_event (const char *pbuf, int size) |
void | close () |
Static Public Member Functions | |
static raw_ofstream * | instance (const std::string &fname) |
static void | release () |
static void | lock () |
static void | unlock () |
Private Member Functions | |
raw_ofstream (const std::string &fname) | |
virtual | ~raw_ofstream () |
void | init_fstream () |
std::string | real_fname () |
raw_ofstream () | |
Private Attributes | |
int | m_nevt |
int | m_nfile |
std::string | m_fname |
FileStartRecord | m_fileStartRecord |
FileNameStrings | m_fileNameStrings |
RunParametersRecord | m_runParametersRecord |
DataSeparatorRecord | m_dataSeparatorRecord |
FileEndRecord | m_fileEndRecord |
Static Private Attributes | |
static int | _nHandler = 0 |
static raw_ofstream * | _instance = 0 |
static pthread_mutex_t | _pthread_lock = PTHREAD_MUTEX_INITIALIZER |
Definition at line 11 of file raw_ofstream.h.
raw_ofstream::raw_ofstream | ( | const std::string & | fname | ) | [private] |
Definition at line 40 of file raw_ofstream.cxx.
References init_fstream().
00041 : m_nevt(0), 00042 m_nfile(0), 00043 m_fname(fname) 00044 { 00045 init_fstream(); 00046 }
raw_ofstream::~raw_ofstream | ( | ) | [private, virtual] |
Definition at line 48 of file raw_ofstream.cxx.
References close().
00049 { 00050 this->close(); 00051 }
raw_ofstream::raw_ofstream | ( | ) | [private] |
Referenced by instance().
void raw_ofstream::close | ( | ) |
Definition at line 70 of file raw_ofstream.cxx.
References m_fileEndRecord, m_nevt, real_fname(), and FileEndRecord::setEventsInFile().
Referenced by write_event(), and ~raw_ofstream().
00071 { 00072 if ( is_open() ) { 00073 m_fileEndRecord.setEventsInFile(m_nevt); 00074 m_nevt = 0; 00075 00076 (*this) << m_fileEndRecord; 00077 std::ofstream::close(); 00078 00079 std::cout << "[RawFile] Finished writing file: " << real_fname() << std::endl; 00080 } 00081 }
void raw_ofstream::init_fstream | ( | ) | [private] |
Definition at line 83 of file raw_ofstream.cxx.
References fname, m_fileNameStrings, m_fileStartRecord, m_nfile, m_runParametersRecord, real_fname(), and deljobs::string.
Referenced by raw_ofstream(), and write_event().
00084 { 00085 ++m_nfile; 00086 00087 std::string fname = real_fname(); 00088 00089 if ( access( fname.c_str(), F_OK ) == 0 ) { 00090 std::cerr << "[RawFile] Attempt to create an exist file: " << fname << std::endl; 00091 exit(1); 00092 } 00093 00094 std::cout << "[RawFile] Creating a new file: " << real_fname() << std::endl; 00095 open( fname.c_str(), std::ios::binary ); 00096 00097 (*this) << m_fileStartRecord << m_fileNameStrings << m_runParametersRecord; 00098 }
raw_ofstream * raw_ofstream::instance | ( | const std::string & | fname | ) | [static] |
Definition at line 13 of file raw_ofstream.cxx.
References _instance, _nHandler, lock(), raw_ofstream(), and unlock().
Referenced by RawFileWriter::RawFileWriter().
00014 { 00015 lock(); 00016 00017 if ( _instance == 0 ) { 00018 _instance = new raw_ofstream(fname); 00019 } 00020 00021 ++_nHandler; 00022 00023 unlock(); 00024 00025 return _instance; 00026 }
static void raw_ofstream::lock | ( | ) | [inline, static] |
Definition at line 18 of file raw_ofstream.h.
References _pthread_lock.
Referenced by instance(), release(), and RawFileWriter::writeEvent().
00018 { 00019 int lstat = pthread_mutex_lock( &_pthread_lock ); 00020 assert( lstat == 0 ); 00021 };
std::string raw_ofstream::real_fname | ( | ) | [private] |
Definition at line 100 of file raw_ofstream.cxx.
References fname, RawFileTools::itoa(), m_fname, m_nfile, and deljobs::string.
Referenced by close(), and init_fstream().
00101 { 00102 std::string fname = m_fname; 00103 00104 if ( m_nfile > 1 ) { 00105 fname += ".part" + RawFileTools::itoa( m_nfile ); 00106 } 00107 00108 return fname; 00109 }
void raw_ofstream::release | ( | ) | [static] |
Definition at line 28 of file raw_ofstream.cxx.
References _instance, _nHandler, lock(), and unlock().
Referenced by RawFileWriter::~RawFileWriter().
00029 { 00030 lock(); 00031 00032 if ( _nHandler > 0 && --_nHandler == 0 ) { 00033 delete _instance; 00034 _instance = 0; 00035 } 00036 00037 unlock(); 00038 }
static void raw_ofstream::unlock | ( | ) | [inline, static] |
Definition at line 22 of file raw_ofstream.h.
References _pthread_lock.
Referenced by instance(), release(), and RawFileWriter::writeEvent().
00022 { 00023 int lstat = pthread_mutex_unlock( &_pthread_lock ); 00024 assert( lstat == 0 ); 00025 };
int raw_ofstream::write_event | ( | const char * | pbuf, | |
int | size | |||
) |
Definition at line 53 of file raw_ofstream.cxx.
References close(), init_fstream(), m_dataSeparatorRecord, m_nevt, m_nfile, MAX_RAWFILE_SiZE, DataSeparatorRecord::setDataBlockNumber(), and DataSeparatorRecord::setDataBlockSize().
Referenced by RawFileWriter::writeEvent().
00054 { 00055 uint32_t fsize = tellp(); 00056 if ( fsize >= MAX_RAWFILE_SiZE ) { 00057 this->close(); 00058 init_fstream(); 00059 } 00060 00061 m_dataSeparatorRecord.setDataBlockNumber(++m_nevt); 00062 m_dataSeparatorRecord.setDataBlockSize(size); 00063 00064 (*this) << m_dataSeparatorRecord; 00065 std::ofstream::write(pbuf, size); 00066 00067 return m_nfile; 00068 }
raw_ofstream * raw_ofstream::_instance = 0 [static, private] |
int raw_ofstream::_nHandler = 0 [static, private] |
pthread_mutex_t raw_ofstream::_pthread_lock = PTHREAD_MUTEX_INITIALIZER [static, private] |
FileEndRecord raw_ofstream::m_fileEndRecord [private] |
std::string raw_ofstream::m_fname [private] |
int raw_ofstream::m_nevt [private] |
int raw_ofstream::m_nfile [private] |
Definition at line 44 of file raw_ofstream.h.
Referenced by init_fstream(), real_fname(), and write_event().