9#define DefaultEventBufferSize 1024*32
10#define EstimatedEventSize 1024*14
15 std::vector<int> vNevt;
18 VFileNames_t::const_iterator it = newfnames.begin();
19 while ( it != newfnames.end() ) {
20 if ( access( it->c_str(), F_OK ) < 0 ) {
21 std::cerr <<
"[RawFile] Invalid IDX file: " << *it << std::endl;
25 std::ifstream fs( it->c_str(), std::ios::binary );
27 fs.read( (
char*)(itmp),
sizeof(uint32_t)*2 );
29 std::cerr <<
"[RawFile] Wrong IdxFileStartMarker!" << std::endl;
32 vNevt.push_back(itmp[1]);
48 for (
int i = 0; i < newfnames.size (); ++i ) {
49 int size = newfnames[i].size();
50 if ( size > 4 && newfnames[i].substr(size-4) ==
".idx" ) {
51 datafnames.push_back(newfnames[i].substr(0, size-4));
54 if ( datafnames.size() == newfnames.size() ) {
72 for (
int i = 0; i < newfnames.size (); ++i ) {
73 int size = newfnames[i].size();
74 if ( size > 4 && newfnames[i].substr(size-4) ==
".idx" ) {
75 datafnames.push_back(newfnames[i].substr(0, size-4));
78 if ( datafnames.size() == newfnames.size() ) {
94 if ( newidxfnames.size() != newfnames.size() ) {
95 std::cerr <<
"[RawFile] Num(IdxFiles) != Num(DataFiles)" << std::endl;
110 if ( newidxfnames.size() != newfnames.size() ) {
111 std::cerr <<
"[RawFile] Num(IdxFiles) != Num(DataFiles)" << std::endl;
132 if ( m_idxHandler == 0 ) {
157 int nnIgnore = nIgnore;
160 if ( m_idxHandler != 0 ) {
161 int nleft = m_idxHandler->
nEvtLeft(nnIgnore);
163 m_rfs->seekg( m_idxHandler->
nextPos( nnIgnore ) );
172 while ( nnIgnore > 0 ) {
173 (*m_rfs) >> m_dataSeparatorRecord;
175 m_rfs->seekg( size + m_rfs->tellg() );
194 if ( m_idxHandler == 0 ) {
197 uint32_t curEvtId = m_buffer[ m_buffer[5] + 8 ];
198 if ( curEvtId == evtId ) {
226 assert( (evtByte&3) == 0 );
228 uint32_t prePos = m_rfs->tellg();
229 m_rfs->seekg( prePos + nIgnore*evtByte);
231 uint32_t halfEvtWord = evtByte / 8;
232 uint32_t halfEvtByte = halfEvtWord * 4;
234 while ( m_rfs->read((
char*)m_buffer, halfEvtByte).good() ) {
236 while ( i < halfEvtWord && m_buffer[i] != 0x1234cccc ) {
239 if ( i < halfEvtWord ) {
240 uint32_t curPos = m_rfs->tellg();
241 m_rfs->seekg( curPos - (halfEvtWord-i)*4 );
249 m_rfs->seekg( -40, std::ios::end );
250 uint32_t curPos = m_rfs->tellg();
252 int nnIgnore = nIgnore - (curPos - prePos) / evtByte;
253 if ( nnIgnore < 0 ) nnIgnore = 0;
260 return m_rfs->
runNo();
270 return m_rfs->tellg();
277 if ( m_rfs->eof() )
stat |= 1;
278 if ( m_rfs->fail() )
stat |= 2;
279 if ( m_rfs->bad() )
stat |= 4;
284const uint32_t* RawFileReader::notSafeNextEvent()
290 nextFile(e).notSafeNextEvent();
296void RawFileReader::read_one_event()
298 (*m_rfs) >> m_dataSeparatorRecord;
301 if ( size > m_bufferSize*4 ) {
302 while ( size > m_bufferSize*4 ) {
306 m_buffer =
new uint32_t[m_bufferSize];
309 m_rfs->read((
char*)m_buffer, size);
310 if ( ! m_rfs->good() ) {
323 if ( m_idxHandler != 0 ) {
#define DefaultEventBufferSize
#define EstimatedEventSize
std::vector< std::string > VFileNames_t
const data_separator_record & getRecord() const
static EvtIdxHandler * instance(const std::vector< std::string > &fnames)
uint32_t findPosById(uint32_t evtId)
static uint32_t IdxFileStartMarker()
int nEvtLeft(int nIgnore) const
uint32_t nextPos(int nIgnore)
virtual void print() const
const uint32_t * findEventById(uint32_t evtId)
const uint32_t * roughlyNextEvent(int nIgnore, int evtByte=0)
RawFileReader(const std::string &fname)
const uint32_t * nextEvent()
static std::vector< int > getEventNumber(const VFileNames_t &idxfnames)
std::string currentFile()
virtual void print() const
static raw_ifstream * instance(const std::vector< std::string > &fnames)
std::string currentFile() const