#include <raw_ofstream.h>
Public Member Functions | |
void | close () |
void | close () |
int | write_event (const char *pbuf, int size) |
int | write_event (const char *pbuf, int size) |
Static Public Member Functions | |
raw_ofstream * | instance (const std::string &fname) |
raw_ofstream * | instance (const std::string &fname) |
void | lock () |
void | lock () |
void | release () |
void | release () |
void | unlock () |
void | unlock () |
Private Member Functions | |
void | init_fstream () |
void | init_fstream () |
raw_ofstream () | |
raw_ofstream (const std::string &fname) | |
raw_ofstream () | |
raw_ofstream (const std::string &fname) | |
std::string | real_fname () |
std::string | real_fname () |
virtual | ~raw_ofstream () |
virtual | ~raw_ofstream () |
Private Attributes | |
DataSeparatorRecord | m_dataSeparatorRecord |
FileEndRecord | m_fileEndRecord |
FileNameStrings | m_fileNameStrings |
FileStartRecord | m_fileStartRecord |
std::string | m_fname |
int | m_nevt |
int | m_nfile |
RunParametersRecord | m_runParametersRecord |
Static Private Attributes | |
raw_ofstream * | _instance |
raw_ofstream * | _instance = 0 |
int | _nHandler = 0 |
pthread_mutex_t | _pthread_lock = PTHREAD_MUTEX_INITIALIZER |
|
00041 : m_nevt(0), 00042 m_nfile(0), 00043 m_fname(fname) 00044 { 00045 init_fstream(); 00046 }
|
|
00049 { 00050 this->close(); 00051 }
|
|
|
|
|
|
|
|
|
|
|
|
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 }
|
|
|
|
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 }
|
|
|
|
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 }
|
|
00018 {
00019 int lstat = pthread_mutex_lock( &_pthread_lock );
00020 assert( lstat == 0 );
00021 };
|
|
00018 {
00019 int lstat = pthread_mutex_lock( &_pthread_lock );
00020 assert( lstat == 0 );
00021 };
|
|
|
|
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 }
|
|
|
|
00029 { 00030 lock(); 00031 00032 if ( _nHandler > 0 && --_nHandler == 0 ) { 00033 delete _instance; 00034 _instance = 0; 00035 } 00036 00037 unlock(); 00038 }
|
|
00022 {
00023 int lstat = pthread_mutex_unlock( &_pthread_lock );
00024 assert( lstat == 0 );
00025 };
|
|
00022 {
00023 int lstat = pthread_mutex_unlock( &_pthread_lock );
00024 assert( lstat == 0 );
00025 };
|
|
|
|
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 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|