1#include "RawFile/raw_ofstream.h"
2#include "RawFile/RawFileTools.h"
6#define MAX_RAWFILE_SiZE 2000000000
9int raw_ofstream::_nHandler = 0;
11pthread_mutex_t raw_ofstream::_pthread_lock = PTHREAD_MUTEX_INITIALIZER;
16 if ( _instance == 0 ) { _instance =
new raw_ofstream( fname, run ); }
28 if ( _nHandler > 0 && --_nHandler == 0 )
37raw_ofstream::raw_ofstream(
const std::string& fname,
int run )
38 : m_nevt( 0 ), m_nfile( 0 ), m_fname( fname ) {
43raw_ofstream::~raw_ofstream() { this->
close(); }
46 uint32_t fsize = tellp();
53 m_dataSeparatorRecord.setDataBlockNumber( ++m_nevt );
54 m_dataSeparatorRecord.setDataBlockSize( size );
56 ( *this ) << m_dataSeparatorRecord;
57 std::ofstream::write( pbuf, size );
65 m_fileEndRecord.setEventsInFile( m_nevt );
68 ( *this ) << m_fileEndRecord;
69 std::ofstream::close();
71 std::cout <<
"[RawFile] Finished writing file: " << real_fname() << std::endl;
75void raw_ofstream::init_fstream() {
78 std::string fname = real_fname();
80 if ( access( fname.c_str(), F_OK ) == 0 )
82 std::cerr <<
"[RawFile] Attempt to create an exist file: " << fname << std::endl;
86 std::cout <<
"[RawFile] Creating a new file: " << real_fname() << std::endl;
87 open( fname.c_str(), std::ios::binary );
89 ( *this ) << m_fileStartRecord << m_fileNameStrings << m_runParametersRecord;
92std::string raw_ofstream::real_fname() {
93 std::string fname = m_fname;
m_outputFile open("YYYY/m_txt_dir/LumTau_XXXX.txt", ios_base::app)
void setRunNumber(uint32_t runId)
static raw_ofstream * instance(const std::string &fname, int run=0)
int write_event(const char *pbuf, int size)