#include <RawFileReader.h>
Inheritance diagram for RawFileReader:
Public Types | |
typedef const VFileNames_t | ReaderArgType |
Public Member Functions | |
RawFileReader (const std::string &fname) | |
RawFileReader (const VFileNames_t &fnames) | |
RawFileReader (const std::string &fname, const std::string &idxfname) | |
RawFileReader (const VFileNames_t &fnames, const VFileNames_t &idxfnames) | |
virtual | ~RawFileReader () |
const uint32_t * | nextEvent () |
const uint32_t * | currentEvent () const |
const uint32_t * | nextEvent (int nIgnore) |
const uint32_t * | findEventById (uint32_t evtId) |
const uint32_t * | roughlyNextEvent (int nIgnore, int evtByte=0) |
uint32_t | runNo () |
std::string | currentFile () |
uint32_t | tellg () |
uint32_t | stat () |
Static Public Member Functions | |
static std::vector< int > | getEventNumber (const VFileNames_t &idxfnames) |
Private Member Functions | |
const uint32_t * | notSafeNextEvent () |
void | read_one_event () |
RawFileReader & | nextFile (RawFileException &e) |
RawFileReader () | |
Private Attributes | |
uint32_t | m_bufferSize |
uint32_t * | m_buffer |
raw_ifstream * | m_rfs |
EvtIdxHandler * | m_idxHandler |
DataSeparatorRecord | m_dataSeparatorRecord |
Definition at line 16 of file RawFileReader.h.
typedef const VFileNames_t RawFileReader::ReaderArgType |
Definition at line 20 of file RawFileReader.h.
RawFileReader::RawFileReader | ( | const std::string & | fname | ) |
Definition at line 38 of file RawFileReader.cxx.
References raw_ifstream::instance(), m_rfs, and RawFileTools::wildcard_correct().
00039 : m_bufferSize(DefaultEventBufferSize), 00040 m_buffer( new uint32_t[DefaultEventBufferSize] ), 00041 m_idxHandler(0) 00042 { 00043 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fname); 00044 00045 m_rfs = raw_ifstream::instance(newfnames); 00046 }
RawFileReader::RawFileReader | ( | const VFileNames_t & | fnames | ) |
Definition at line 48 of file RawFileReader.cxx.
References raw_ifstream::instance(), m_rfs, and RawFileTools::wildcard_correct().
00049 : m_bufferSize(DefaultEventBufferSize), 00050 m_buffer( new uint32_t[DefaultEventBufferSize] ), 00051 m_idxHandler(0) 00052 { 00053 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fnames); 00054 00055 m_rfs = raw_ifstream::instance(newfnames); 00056 }
RawFileReader::RawFileReader | ( | const std::string & | fname, | |
const std::string & | idxfname | |||
) |
Definition at line 58 of file RawFileReader.cxx.
References EvtIdxHandler::instance(), raw_ifstream::instance(), m_idxHandler, m_rfs, and RawFileTools::wildcard_correct().
00059 : m_bufferSize(DefaultEventBufferSize), 00060 m_buffer( new uint32_t[DefaultEventBufferSize] ) 00061 { 00062 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fname); 00063 const VFileNames_t newidxfnames = RawFileTools::wildcard_correct(idxfname); 00064 00065 if ( newidxfnames.size() != newfnames.size() ) { 00066 std::cerr << "[RawFile] Num(IdxFiles) != Num(DataFiles)" << std::endl; 00067 exit(1); 00068 } 00069 00070 m_rfs = raw_ifstream::instance(newfnames); 00071 m_idxHandler = EvtIdxHandler::instance(newidxfnames); 00072 }
RawFileReader::RawFileReader | ( | const VFileNames_t & | fnames, | |
const VFileNames_t & | idxfnames | |||
) |
Definition at line 74 of file RawFileReader.cxx.
References EvtIdxHandler::instance(), raw_ifstream::instance(), m_idxHandler, m_rfs, and RawFileTools::wildcard_correct().
00075 : m_bufferSize(DefaultEventBufferSize), 00076 m_buffer( new uint32_t[DefaultEventBufferSize] ) 00077 { 00078 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fnames); 00079 const VFileNames_t newidxfnames = RawFileTools::wildcard_correct(idxfnames); 00080 00081 if ( newidxfnames.size() != newfnames.size() ) { 00082 std::cerr << "[RawFile] Num(IdxFiles) != Num(DataFiles)" << std::endl; 00083 exit(1); 00084 } 00085 00086 m_rfs = raw_ifstream::instance(newfnames); 00087 m_idxHandler = EvtIdxHandler::instance(newidxfnames); 00088 }
RawFileReader::~RawFileReader | ( | ) | [virtual] |
Definition at line 90 of file RawFileReader.cxx.
References m_buffer, EvtIdxHandler::release(), and raw_ifstream::release().
00091 { 00092 delete[] m_buffer; 00093 raw_ifstream::release(); 00094 EvtIdxHandler::release(); 00095 }
RawFileReader::RawFileReader | ( | ) | [private] |
const uint32_t* RawFileReader::currentEvent | ( | ) | const [inline, virtual] |
Implements IRawReader.
Definition at line 33 of file RawFileReader.h.
References m_buffer.
Referenced by MixerAlg::nextEvent().
00033 { return m_buffer; }
std::string RawFileReader::currentFile | ( | ) | [virtual] |
Implements IRawReader.
Definition at line 229 of file RawFileReader.cxx.
References raw_ifstream::currentFile(), and m_rfs.
Referenced by findEventById(), main(), nextEvent(), and roughlyNextEvent().
00230 { 00231 return m_rfs->currentFile(); 00232 }
const uint32_t * RawFileReader::findEventById | ( | uint32_t | evtId | ) |
Definition at line 155 of file RawFileReader.cxx.
References EvtCyclic3::c_str(), currentFile(), findEventById(), EvtIdxHandler::findPosById(), m_buffer, m_idxHandler, m_rfs, nextFile(), boss::pos, and read_one_event().
Referenced by findEventById(), and main().
00156 { 00157 // not thread safe !!! 00158 // find an event by ID ( only backward !!! ) 00159 try { 00160 if ( m_idxHandler == 0 ) { 00161 while ( true ) { 00162 read_one_event(); 00163 uint32_t curEvtId = m_buffer[ m_buffer[5] + 8 ]; 00164 if ( curEvtId == evtId ) { 00165 break; 00166 } 00167 } 00168 } 00169 else { 00170 uint32_t pos = m_idxHandler->findPosById( evtId ); 00171 if ( pos != 0 ) { 00172 m_rfs->seekg( pos ); 00173 read_one_event(); 00174 } 00175 else { 00176 throw ReachEndOfFile( currentFile().c_str() ); 00177 } 00178 } 00179 } 00180 catch (RawFileException& e) { 00181 return nextFile(e).findEventById(evtId); 00182 } 00183 00184 return m_buffer; 00185 }
std::vector< int > RawFileReader::getEventNumber | ( | const VFileNames_t & | idxfnames | ) | [static] |
Definition at line 11 of file RawFileReader.cxx.
References EvtIdxHandler::IdxFileStartMarker(), and RawFileTools::wildcard_correct().
Referenced by MixerAlg::execute().
00012 { 00013 uint32_t itmp[2]; 00014 std::vector<int> vNevt; 00015 00016 const VFileNames_t newfnames = RawFileTools::wildcard_correct(idxfnames); 00017 VFileNames_t::const_iterator it = newfnames.begin(); 00018 while ( it != newfnames.end() ) { 00019 if ( access( it->c_str(), F_OK ) < 0 ) { 00020 std::cerr << "[RawFile] Invalid IDX file: " << *it << std::endl; 00021 exit(1); 00022 } 00023 00024 std::ifstream fs( it->c_str(), std::ios::binary ); 00025 00026 fs.read( (char*)(itmp), sizeof(uint32_t)*2 ); 00027 if ( itmp[0] != EvtIdxHandler::IdxFileStartMarker() ) { 00028 std::cerr << "[RawFile] Wrong IdxFileStartMarker!" << std::endl; 00029 exit(1); 00030 } 00031 vNevt.push_back(itmp[1]); 00032 ++it; 00033 } 00034 00035 return vNevt; 00036 }
const uint32_t * RawFileReader::nextEvent | ( | int | nIgnore | ) |
Definition at line 120 of file RawFileReader.cxx.
References EvtCyclic3::c_str(), currentFile(), m_buffer, m_dataSeparatorRecord, m_idxHandler, m_rfs, EvtIdxHandler::nEvtLeft(), nextEvent(), nextFile(), EvtIdxHandler::nextPos(), read_one_event(), and delete_small_size::size.
00121 { 00122 // not thread safe !!! 00123 int nnIgnore = nIgnore; 00124 00125 try { 00126 if ( m_idxHandler != 0 ) { 00127 int nleft = m_idxHandler->nEvtLeft(nnIgnore); 00128 if ( nleft > 0 ) { 00129 m_rfs->seekg( m_idxHandler->nextPos( nnIgnore ) ); 00130 nnIgnore = 0; 00131 } 00132 else { 00133 nnIgnore = -nleft; 00134 throw ReachEndOfFile( currentFile().c_str() ); 00135 } 00136 } 00137 else { 00138 while ( nnIgnore > 0 ) { 00139 (*m_rfs) >> m_dataSeparatorRecord; 00140 uint32_t size = m_dataSeparatorRecord.getRecord().data_block_size; 00141 m_rfs->seekg( size + m_rfs->tellg() ); 00142 --nnIgnore; 00143 } 00144 } 00145 00146 read_one_event(); 00147 } 00148 catch (RawFileException& e) { 00149 nextFile(e).nextEvent(nnIgnore); 00150 } 00151 00152 return m_buffer; 00153 }
const uint32_t * RawFileReader::nextEvent | ( | ) | [virtual] |
Implements IRawReader.
Definition at line 97 of file RawFileReader.cxx.
References raw_ifstream::lock(), m_buffer, notSafeNextEvent(), RawFileException::print(), and raw_ifstream::unlock().
Referenced by main(), MixerAlg::nextEvent(), nextEvent(), and RawEventReader::readEvent().
00098 { 00099 // thread safe 00100 raw_ifstream::lock(); 00101 00102 try { 00103 notSafeNextEvent(); 00104 } 00105 catch ( ReachEndOfFileList& e) { 00106 raw_ifstream::unlock(); 00107 throw e; 00108 } 00109 catch ( RawFileException& e) { 00110 raw_ifstream::unlock(); 00111 e.print(); 00112 throw e; 00113 } 00114 00115 raw_ifstream::unlock(); 00116 00117 return m_buffer; 00118 }
RawFileReader & RawFileReader::nextFile | ( | RawFileException & | e | ) | [private] |
Definition at line 282 of file RawFileReader.cxx.
References m_idxHandler, m_rfs, EvtIdxHandler::next_file(), raw_ifstream::next_file(), and RawFileException::print().
Referenced by findEventById(), nextEvent(), notSafeNextEvent(), and roughlyNextEvent().
00283 { 00284 e.print(); 00285 00286 m_rfs->clear(); 00287 m_rfs->next_file(); 00288 00289 if ( m_idxHandler != 0 ) { 00290 m_idxHandler->next_file(); 00291 } 00292 00293 return *this; 00294 }
const uint32_t * RawFileReader::notSafeNextEvent | ( | ) | [private] |
Definition at line 250 of file RawFileReader.cxx.
References m_buffer, nextFile(), notSafeNextEvent(), and read_one_event().
Referenced by nextEvent(), and notSafeNextEvent().
00251 { 00252 try { 00253 read_one_event(); 00254 } 00255 catch (RawFileException& e) { 00256 nextFile(e).notSafeNextEvent(); 00257 } 00258 00259 return m_buffer; 00260 }
void RawFileReader::read_one_event | ( | ) | [private] |
Definition at line 262 of file RawFileReader.cxx.
References m_buffer, m_bufferSize, m_dataSeparatorRecord, m_rfs, and delete_small_size::size.
Referenced by findEventById(), nextEvent(), notSafeNextEvent(), and roughlyNextEvent().
00263 { 00264 (*m_rfs) >> m_dataSeparatorRecord; 00265 00266 uint32_t size = m_dataSeparatorRecord.getRecord().data_block_size; 00267 if ( size > m_bufferSize*4 ) { 00268 while ( size > m_bufferSize*4 ) { 00269 m_bufferSize *= 2; 00270 } 00271 delete[] m_buffer; 00272 m_buffer = new uint32_t[m_bufferSize]; 00273 } 00274 00275 m_rfs->read((char*)m_buffer, size); 00276 if ( ! m_rfs->good() ) { 00277 //std::cerr << "[RawFile] Failed to read FullEventFragment to buffer" << std::endl; 00278 throw BadInputStream("event_data_block"); 00279 } 00280 }
const uint32_t * RawFileReader::roughlyNextEvent | ( | int | nIgnore, | |
int | evtByte = 0 | |||
) |
Definition at line 187 of file RawFileReader.cxx.
References EvtCyclic3::c_str(), currentFile(), deljobs::end, EstimatedEventSize, genRecEmupikp::i, m_buffer, m_rfs, nextFile(), read_one_event(), and roughlyNextEvent().
Referenced by MixerAlg::nextEvent(), and roughlyNextEvent().
00188 { 00189 // not thread safe !!! 00190 if ( evtByte == 0 ) evtByte = EstimatedEventSize; 00191 00192 assert( (evtByte&3) == 0 ); 00193 00194 uint32_t prePos = m_rfs->tellg(); 00195 m_rfs->seekg( prePos + nIgnore*evtByte); 00196 00197 uint32_t halfEvtWord = evtByte / 8; 00198 uint32_t halfEvtByte = halfEvtWord * 4; 00199 00200 while ( m_rfs->read((char*)m_buffer, halfEvtByte).good() ) { 00201 uint32_t i = 0; 00202 while ( i < halfEvtWord && m_buffer[i] != 0x1234cccc ) { 00203 ++i; 00204 } 00205 if ( i < halfEvtWord ) { 00206 uint32_t curPos = m_rfs->tellg(); 00207 m_rfs->seekg( curPos - (halfEvtWord-i)*4 ); 00208 read_one_event(); 00209 return m_buffer; 00210 } 00211 } 00212 00213 // reached the end of current data file! m_rfs->eof() 00214 m_rfs->clear(); 00215 m_rfs->seekg( -40, std::ios::end ); //sizeof(FileEndRecord) == 40 00216 uint32_t curPos = m_rfs->tellg(); 00217 00218 int nnIgnore = nIgnore - (curPos - prePos) / evtByte; 00219 if ( nnIgnore < 0 ) nnIgnore = 0; 00220 00221 ReachEndOfFile e( currentFile().c_str() ); 00222 return nextFile(e).roughlyNextEvent(nnIgnore, evtByte); 00223 }
uint32_t RawFileReader::runNo | ( | ) | [virtual] |
Implements IRawReader.
Definition at line 224 of file RawFileReader.cxx.
References m_rfs, and raw_ifstream::runNo().
uint32_t RawFileReader::stat | ( | ) | [virtual] |
Implements IRawReader.
Definition at line 239 of file RawFileReader.cxx.
References m_rfs.
00240 { 00241 uint32_t stat = 0; 00242 00243 if ( m_rfs->eof() ) stat |= 1; 00244 if ( m_rfs->fail() ) stat |= 2; 00245 if ( m_rfs->bad() ) stat |= 4; 00246 00247 return stat; 00248 }
uint32_t RawFileReader::tellg | ( | ) |
Definition at line 234 of file RawFileReader.cxx.
References m_rfs.
Referenced by main().
00235 { 00236 return m_rfs->tellg(); 00237 }
uint32_t* RawFileReader::m_buffer [private] |
Definition at line 60 of file RawFileReader.h.
Referenced by currentEvent(), findEventById(), nextEvent(), notSafeNextEvent(), read_one_event(), roughlyNextEvent(), and ~RawFileReader().
uint32_t RawFileReader::m_bufferSize [private] |
EvtIdxHandler* RawFileReader::m_idxHandler [private] |
Definition at line 63 of file RawFileReader.h.
Referenced by findEventById(), nextEvent(), nextFile(), and RawFileReader().
raw_ifstream* RawFileReader::m_rfs [private] |
Definition at line 62 of file RawFileReader.h.
Referenced by currentFile(), findEventById(), nextEvent(), nextFile(), RawFileReader(), read_one_event(), roughlyNextEvent(), runNo(), stat(), and tellg().