#include <EvtIdxHandler.h>
Public Member Functions | |
void | addPos (uint32_t evtId, uint32_t pos) |
void | addPos (uint32_t evtId, uint32_t pos) |
EvtIdxHandler () | |
EvtIdxHandler () | |
uint32_t | findPosById (uint32_t evtId) |
uint32_t | findPosById (uint32_t evtId) |
int | nEvtLeft (int nIgnore) const |
int | nEvtLeft (int nIgnore) const |
void | next_file () |
void | next_file () |
uint32_t | nextPos (int nIgnore) |
uint32_t | nextPos (int nIgnore) |
void | write (std::string fname) |
void | write (std::string fname) |
virtual | ~EvtIdxHandler () |
virtual | ~EvtIdxHandler () |
Static Public Member Functions | |
uint32_t | IdxFileStartMarker () |
uint32_t | IdxFileStartMarker () |
uint32_t | IdxIdBlockMarker () |
uint32_t | IdxIdBlockMarker () |
uint32_t | IdxPosBlockMarker () |
uint32_t | IdxPosBlockMarker () |
EvtIdxHandler * | instance (const std::vector< std::string > &fnames) |
EvtIdxHandler * | instance (const std::vector< std::string > &fnames) |
void | release () |
void | release () |
Private Member Functions | |
void | enlarge_block (int min_size) |
void | enlarge_block (int min_size) |
EvtIdxHandler (const std::vector< std::string > &idxfnames) | |
EvtIdxHandler (const std::vector< std::string > &idxfnames) | |
void | init_idx () |
void | init_idx () |
Private Attributes | |
int | m_blockSize |
std::vector< std::string >::iterator | m_curFile |
std::vector< std::string >::iterator | m_curFile |
uint32_t * | m_EIdBlock |
uint32_t * | m_EIdBlock |
std::vector< std::string > | m_fnames |
std::vector< std::string > | m_fnames |
std::fstream | m_fs |
int | m_idxPos |
uint32_t * | m_PosBlock |
uint32_t * | m_PosBlock |
int | m_totEvt |
Static Private Attributes | |
EvtIdxHandler * | _instance |
EvtIdxHandler * | _instance = 0 |
int | _nHandler = 0 |
|
00042 : m_totEvt(0), 00043 m_idxPos(-1), 00044 m_blockSize(DefaultIdxBlockSize) 00045 { 00046 m_EIdBlock = new uint32_t[m_blockSize]; 00047 m_PosBlock = new uint32_t[m_blockSize]; 00048 }
|
|
00051 { 00052 delete[] m_EIdBlock; 00053 delete[] m_PosBlock; 00054 }
|
|
00030 : m_idxPos(0), 00031 m_blockSize(DefaultIdxBlockSize), 00032 m_fnames(idxfnames) 00033 { 00034 m_EIdBlock = new uint32_t[m_blockSize]; 00035 m_PosBlock = new uint32_t[m_blockSize]; 00036 00037 m_curFile = m_fnames.begin(); 00038 init_idx(); 00039 }
|
|
|
|
|
|
|
|
|
|
00082 { 00083 ++m_totEvt; 00084 00085 if ( m_totEvt > m_blockSize ) enlarge_block( m_totEvt ); 00086 00087 m_EIdBlock[m_totEvt-1] = evtId; 00088 m_PosBlock[m_totEvt-1] = pos; 00089 }
|
|
|
|
00172 { 00173 while ( min_size > m_blockSize ) { 00174 m_blockSize *= 2; 00175 } 00176 00177 delete[] m_EIdBlock; 00178 delete[] m_PosBlock; 00179 00180 m_EIdBlock = new uint32_t[m_blockSize]; 00181 m_PosBlock = new uint32_t[m_blockSize]; 00182 }
|
|
|
|
00071 { 00072 while ( m_totEvt > m_idxPos ) { 00073 if ( m_EIdBlock[m_idxPos] == evtId ) { 00074 return m_PosBlock[m_idxPos++]; 00075 } 00076 ++m_idxPos; 00077 } 00078 return 0; 00079 }
|
|
00012 { return 0xFFFFAAAA; }
|
|
00012 { return 0xFFFFAAAA; }
|
|
00013 { return 0xFFFFBBBB; }
|
|
00013 { return 0xFFFFBBBB; }
|
|
00014 { return 0xFFFFCCCC; }
|
|
00014 { return 0xFFFFCCCC; }
|
|
|
|
00125 { 00126 if ( access( m_curFile->c_str(), F_OK ) < 0 ) { 00127 std::cerr << "[RawFile] Invalid IDX file: " << *m_curFile << std::endl; 00128 exit(1); 00129 } 00130 00131 std::cout << "[RawFile] Initialize IDX with file: " << *m_curFile << std::endl; 00132 00133 m_fs.open( m_curFile->c_str(), std::ios::in | std::ios::binary ); 00134 00135 uint32_t marker; 00136 00137 m_fs.read( (char*)&marker, sizeof(marker) ); 00138 if ( marker != EvtIdxHandler::IdxFileStartMarker() ) { 00139 std::cerr << "[RawFile] Wrong IdxFileStartMarker!" << std::endl; 00140 exit(1); 00141 } 00142 00143 m_fs.read( (char*)&m_totEvt, sizeof(m_totEvt) ); 00144 00145 if ( m_totEvt > m_blockSize ) enlarge_block( m_totEvt ); 00146 00147 m_fs.read( (char*)&marker, sizeof(marker) ); 00148 if ( marker != EvtIdxHandler::IdxIdBlockMarker() ) { 00149 std::cerr << "[RawFile] Wrong IdxIdBlockMarker!" << std::endl; 00150 exit(1); 00151 } 00152 00153 m_fs.read( (char*)m_EIdBlock, m_totEvt*sizeof(uint32_t) ); 00154 00155 m_fs.read( (char*)&marker, sizeof(marker) ); 00156 if ( marker != EvtIdxHandler::IdxPosBlockMarker() ) { 00157 std::cerr << "[RawFile] Wrong IdxPosBlockMarker!" << std::endl; 00158 exit(1); 00159 } 00160 00161 m_fs.read( (char*)m_PosBlock, m_totEvt*sizeof(uint32_t) ); 00162 00163 if ( ! m_fs.good() ) { 00164 std::cerr << "[RawFile] Error occured while initialize the IDX file!" << std::endl; 00165 exit(1); 00166 } 00167 00168 m_fs.close(); 00169 }
|
|
|
|
00011 { 00012 if ( _instance == 0 ) { 00013 _instance = new EvtIdxHandler(idxfnames); 00014 } 00015 00016 ++_nHandler; 00017 00018 return _instance; 00019 }
|
|
|
|
|
|
|
|
|
|
|
|
00065 { 00066 m_idxPos += nIgnore; 00067 return m_PosBlock[m_idxPos++]; 00068 }
|
|
|
|
00022 { 00023 if ( _nHandler > 0 && --_nHandler == 0 ) { 00024 delete _instance; 00025 _instance = 0; 00026 } 00027 }
|
|
|
|
00092 { 00093 if ( m_idxPos >= 0 ) { 00094 std::cerr << "[RawFile] Writing an EvtIdxHandler for reading !!!" << std::endl; 00095 exit(1); 00096 } 00097 00098 m_fs.open( fname.c_str(), std::ios::out | std::ios::binary ); 00099 00100 uint32_t marker = EvtIdxHandler::IdxFileStartMarker(); 00101 m_fs.write( (char*)&marker, sizeof(marker) ); 00102 m_fs.write( (char*)&m_totEvt, sizeof(m_totEvt) ); 00103 00104 marker = EvtIdxHandler::IdxIdBlockMarker(); 00105 m_fs.write( (char*)&marker, sizeof(marker) ); 00106 m_fs.write( (char*)m_EIdBlock, m_totEvt*sizeof(uint32_t) ); 00107 00108 marker = EvtIdxHandler::IdxPosBlockMarker(); 00109 m_fs.write( (char*)&marker, sizeof(marker) ); 00110 m_fs.write( (char*)m_PosBlock, m_totEvt*sizeof(uint32_t) ); 00111 00112 if ( ! m_fs.good() ) { 00113 std::cerr << "[RawFile] Error writing IDX file: " << fname << std::endl; 00114 exit(1); 00115 } 00116 00117 m_fs.close(); 00118 00119 std::cout << "[RawFile] Written IDX file: " << fname << std::endl; 00120 00121 m_totEvt = 0; 00122 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|