#include <IOPool/Streamer/interface/StreamerInputFile.h>
Public Member Functions | |
const EventMsgView * | currentRecord () const |
Points to File Start Header/Message. | |
const StreamerInputIndexFile * | index () |
Points to current Record. | |
const bool | newHeader () |
Return pointer to current index. | |
bool | next () |
const InitMsgView * | startMessage () const |
Moves the handler to next Event Record. | |
StreamerInputFile (const std::vector< std::string > &names) | |
Multiple Index files for Single Streamer file. | |
StreamerInputFile (const std::string &name, const StreamerInputIndexFile &order) | |
Index file reference is provided. | |
StreamerInputFile (const std::string &name, const std::string &order) | |
Reads a Streamer file and browse it through an index file. | |
StreamerInputFile (const std::string &name) | |
Reads a Streamer file. | |
~StreamerInputFile () | |
Private Member Functions | |
bool | compareHeader () |
Compares current File header with the newly opened file header Returns false in case of miss match. | |
void | logFileAction (const char *msg) |
bool | openNextFile () |
void | openStreamerFile (const std::string &name) |
Test bit if a new header is encountered. | |
IOSize | readBytes (char *buf, IOSize nBytes) |
int | readEventMessage () |
void | readStartMessage () |
Private Attributes | |
EventMsgView * | currentEvMsg_ |
unsigned int | currentFile_ |
Buffer to store Event Data. | |
std::string | currentFileName_ |
True if Multiple Streams are Read. | |
bool | currentFileOpen_ |
uint32 | currProto_ |
uint32 | currRun_ |
bool | endOfFile_ |
std::vector< char > | eventBuf_ |
Buffer to store file Header. | |
std::vector< char > | headerBuf_ |
StreamerInputIndexFile * | index_ |
indexRecIter | indexIter_b |
indexRecIter | indexIter_e |
bool | multiStreams_ |
names of Streamer files | |
bool | newHeader_ |
InitMsgView * | startMsg_ |
boost::shared_ptr< Storage > | storage_ |
std::vector< std::string > | streamerNames_ |
keeps track of which file is in use at the moment | |
bool | useIndex_ |
Definition at line 18 of file StreamerInputFile.h.
StreamerInputFile::StreamerInputFile | ( | const std::string & | name | ) | [explicit] |
Reads a Streamer file.
Definition at line 27 of file StreamerInputFile.cc.
References openStreamerFile(), and readStartMessage().
00027 : 00028 useIndex_(false), 00029 startMsg_(0), 00030 currentEvMsg_(0), 00031 headerBuf_(1000*1000), 00032 eventBuf_(1000*1000*7), 00033 multiStreams_(false), 00034 currentFileName_(), 00035 currentFileOpen_(false), 00036 newHeader_(false), 00037 endOfFile_(false) 00038 { 00039 openStreamerFile(name); 00040 readStartMessage(); 00041 }
StreamerInputFile::StreamerInputFile | ( | const std::string & | name, | |
const std::string & | order | |||
) | [explicit] |
Reads a Streamer file and browse it through an index file.
Index file name provided here
Definition at line 43 of file StreamerInputFile.cc.
References openStreamerFile(), and readStartMessage().
00044 : 00045 useIndex_(true), 00046 index_(new StreamerInputIndexFile(order)), 00047 //indexIter_b(index_->begin()), 00048 indexIter_b(index_->sort()), 00049 indexIter_e(index_->end()), 00050 startMsg_(0), 00051 currentEvMsg_(0), 00052 headerBuf_(1000*1000), 00053 eventBuf_(1000*1000*7), 00054 multiStreams_(false), 00055 currentFileName_(), 00056 currentFileOpen_(false), 00057 newHeader_(false), 00058 endOfFile_(false) 00059 { 00060 openStreamerFile(name); 00061 readStartMessage(); 00062 }
StreamerInputFile::StreamerInputFile | ( | const std::string & | name, | |
const StreamerInputIndexFile & | order | |||
) | [explicit] |
Index file reference is provided.
Definition at line 64 of file StreamerInputFile.cc.
References openStreamerFile(), and readStartMessage().
00065 : 00066 useIndex_(true), 00067 index_((StreamerInputIndexFile*)&order), 00068 //indexIter_b(index_->begin()), 00069 indexIter_b(index_->sort()), 00070 indexIter_e(index_->end()), 00071 startMsg_(0), 00072 currentEvMsg_(0), 00073 headerBuf_(1000*1000), 00074 eventBuf_(1000*1000*7), 00075 multiStreams_(false), 00076 currentFileName_(), 00077 currentFileOpen_(false), 00078 newHeader_(false), 00079 endOfFile_(false) 00080 { 00081 openStreamerFile(name); 00082 readStartMessage(); 00083 }
StreamerInputFile::StreamerInputFile | ( | const std::vector< std::string > & | names | ) | [explicit] |
Multiple Index files for Single Streamer file.
Definition at line 86 of file StreamerInputFile.cc.
References currentFile_, currProto_, currRun_, openStreamerFile(), InitMsgView::protocolVersion(), readStartMessage(), InitMsgView::run(), and startMsg_.
00086 : 00087 useIndex_(false), 00088 startMsg_(0), 00089 currentEvMsg_(0), 00090 headerBuf_(1000*1000), 00091 eventBuf_(1000*1000*7), 00092 currentFile_(0), 00093 streamerNames_(names), 00094 multiStreams_(true), 00095 currentFileName_(), 00096 currentFileOpen_(false), 00097 currRun_(0), 00098 currProto_(0), 00099 newHeader_(false), 00100 endOfFile_(false) 00101 { 00102 openStreamerFile(names.at(0)); 00103 ++currentFile_; 00104 readStartMessage(); 00105 currRun_ = startMsg_->run(); 00106 currProto_ = startMsg_->protocolVersion(); 00107 }
StreamerInputFile::~StreamerInputFile | ( | ) |
Definition at line 16 of file StreamerInputFile.cc.
References currentEvMsg_, currentFileOpen_, logFileAction(), startMsg_, and storage_.
00017 { 00018 if (storage_) { 00019 storage_->close(); 00020 if (currentFileOpen_) logFileAction(" Closed file "); 00021 } 00022 00023 delete startMsg_; 00024 delete currentEvMsg_; 00025 }
bool StreamerInputFile::compareHeader | ( | ) | [private] |
Compares current File header with the newly opened file header Returns false in case of miss match.
Definition at line 261 of file StreamerInputFile.cc.
References currentFile_, currProto_, currRun_, edm::errors::MismatchedInputFiles, newHeader_, InitMsgView::protocolVersion(), readStartMessage(), InitMsgView::run(), startMsg_, and streamerNames_.
Referenced by openNextFile().
00261 { 00262 00263 //Get the new header 00264 readStartMessage(); 00265 00266 //Values from new Header should match up 00267 if (currRun_ != startMsg_->run() || 00268 currProto_ != startMsg_->protocolVersion()) 00269 { 00270 throw edm::Exception(errors::MismatchedInputFiles,"StreamerInputFile::compareHeader") 00271 << "File " << streamerNames_.at(currentFile_) 00272 << "\nhas different run number or protocol version than previous\n"; 00273 00274 return false; 00275 } 00276 newHeader_ = true; 00277 return true; 00278 }
const EventMsgView* StreamerInputFile::currentRecord | ( | ) | const [inline] |
Points to File Start Header/Message.
Definition at line 42 of file StreamerInputFile.h.
References currentEvMsg_.
Referenced by edmtestp::TestFileReader::readEvents().
00042 { return currentEvMsg_; }
const StreamerInputIndexFile * StreamerInputFile::index | ( | ) |
Points to current Record.
Definition at line 142 of file StreamerInputFile.cc.
References index_.
00142 { 00143 return index_; 00144 }
void StreamerInputFile::logFileAction | ( | const char * | msg | ) | [private] |
Definition at line 333 of file StreamerInputFile.cc.
References currentFileName_, edm::FlushMessageLog(), and t.
Referenced by openStreamerFile(), and ~StreamerInputFile().
00333 { 00334 time_t t = time(0); 00335 char ts[] = "dd-Mon-yyyy hh:mm:ss TZN "; 00336 strftime( ts, strlen(ts)+1, "%d-%b-%Y %H:%M:%S %Z", localtime(&t) ); 00337 edm::LogAbsolute("fileAction") << ts << msg << currentFileName_; 00338 edm::FlushMessageLog(); 00339 }
const bool StreamerInputFile::newHeader | ( | ) | [inline] |
Return pointer to current index.
Definition at line 47 of file StreamerInputFile.h.
References newHeader_, and tmp.
00047 { bool tmp=newHeader_; newHeader_=false; return tmp;}
Read the offset of next event from Event Index
Definition at line 198 of file StreamerInputFile.cc.
References ce, endOfFile_, cms::Exception::explainSelf(), edm::errors::FileReadError, EventIndexRecord::getOffset(), indexIter_b, indexIter_e, multiStreams_, openNextFile(), storage_, and useIndex_.
Referenced by edmtestp::TestFileReader::readEvents().
00199 { 00200 if (useIndex_) { 00201 00204 if (indexIter_b != indexIter_e) { 00205 EventIndexRecord* iview = *(indexIter_b); 00206 00207 try { 00208 storage_->position((iview->getOffset()) - 1); 00209 } 00210 catch (cms::Exception& ce) { 00211 throw edm::Exception(errors::FileReadError, "StreamerInputFile::next") 00212 << "Failed reading streamer file in function next\n" 00213 << ce.explainSelf() << "\n"; 00214 } 00215 00216 ++indexIter_b; 00217 } 00218 } 00219 if (this->readEventMessage()) { 00220 return true; 00221 } 00222 00223 if (multiStreams_) { 00224 //Try opening next file 00225 if (openNextFile()) { 00226 endOfFile_ = false; 00227 if (this->readEventMessage()) { 00228 return true; 00229 } 00230 } 00231 } 00232 00233 return false; 00234 }
bool StreamerInputFile::openNextFile | ( | ) | [private] |
Definition at line 236 of file StreamerInputFile.cc.
References compareHeader(), currentFile_, lat::endl(), FDEBUG, NULL, openStreamerFile(), startMsg_, and streamerNames_.
Referenced by next().
00236 { 00237 00238 if (currentFile_ <= streamerNames_.size()-1) 00239 { 00240 00241 FDEBUG(10) << "Opening file " 00242 << streamerNames_.at(currentFile_).c_str() << std::endl; 00243 00244 openStreamerFile(streamerNames_.at(currentFile_)); 00245 00246 // If start message was already there, then compare the 00247 // previous and new headers 00248 if (startMsg_ != NULL) { 00249 FDEBUG(10) << "Comparing Header" << std::endl; 00250 if (!compareHeader()) 00251 { 00252 return false; 00253 } 00254 } 00255 ++currentFile_; 00256 return true; 00257 } 00258 return false; 00259 }
void StreamerInputFile::openStreamerFile | ( | const std::string & | name | ) | [private] |
Test bit if a new header is encountered.
Definition at line 110 of file StreamerInputFile.cc.
References HcalDataFrameFilter_impl::check(), currentFileName_, currentFileOpen_, e, cms::Exception::explainSelf(), edm::errors::FileOpenError, StorageFactory::get(), logFileAction(), IOFlags::OpenRead, size, and storage_.
Referenced by openNextFile(), and StreamerInputFile().
00110 { 00111 00112 if (storage_) { 00113 storage_->close(); 00114 if (currentFileOpen_) logFileAction(" Closed file "); 00115 } 00116 00117 currentFileName_ = name; 00118 currentFileOpen_ = false; 00119 logFileAction(" Initiating request to open file "); 00120 00121 IOOffset size = -1; 00122 if (StorageFactory::get()->check(name.c_str(), &size)) { 00123 try { 00124 storage_.reset(StorageFactory::get()->open(name.c_str(), 00125 IOFlags::OpenRead)); 00126 } 00127 catch (cms::Exception& e) { 00128 throw edm::Exception(errors::FileOpenError,"StreamerInputFile::openStreamerFile") 00129 << "Error Opening Streamer Input File: " << name << "\n" 00130 << e.explainSelf() << "\n"; 00131 } 00132 } 00133 else { 00134 throw edm::Exception(errors::FileOpenError, "StreamerInputFile::openStreamerFile") 00135 << "Error Opening Streamer Input File, file does not exist: " 00136 << name << "\n"; 00137 } 00138 currentFileOpen_ = true; 00139 logFileAction(" Successfully opened file "); 00140 }
Definition at line 146 of file StreamerInputFile.cc.
References ce, cms::Exception::explainSelf(), edm::errors::FileReadError, n, and storage_.
Referenced by readEventMessage(), and readStartMessage().
00147 { 00148 IOSize n; 00149 try { 00150 n = storage_->read(buf, nBytes); 00151 } 00152 catch (cms::Exception& ce) { 00153 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readBytes") 00154 << "Failed reading streamer file in function readBytes\n" 00155 << ce.explainSelf() << "\n"; 00156 } 00157 return n; 00158 }
int StreamerInputFile::readEventMessage | ( | ) | [private] |
Definition at line 281 of file StreamerInputFile.cc.
References code, HeaderView::code(), currentEvMsg_, endOfFile_, Header::EOFRECORD, Header::EVENT, eventBuf_, edm::errors::FileReadError, readBytes(), and HeaderView::size().
00282 { 00283 if (endOfFile_) return 0; 00284 00285 IOSize nWant = sizeof(HeaderView); 00286 IOSize nGot = readBytes(&eventBuf_[0], nWant); 00287 if (nGot != nWant) { 00288 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readEventMessage") 00289 << "Failed reading streamer file, first read in readEventMessage\n" 00290 << "Requested " << nWant << " bytes, read function returned " << nGot << " bytes\n"; 00291 } 00292 00293 HeaderView head(&eventBuf_[0]); 00294 uint32 code = head.code(); 00295 00296 // When we get the EOF record we know we have read all events 00297 // normally and are at the end, return 0 to indicate this 00298 if (code == Header::EOFRECORD) { 00299 endOfFile_ = true; 00300 return 0; 00301 } 00302 00303 // If it is not an event nor EOFRECORD then something is wrong. 00304 if (code != Header::EVENT) { 00305 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readEventMessage") 00306 << "Failed reading streamer file, unknown code in event header\n" 00307 << "code = " << code << "\n"; 00308 } 00309 00310 uint32 eventSize = head.size(); 00311 if (eventBuf_.size() < eventSize) eventBuf_.resize(eventSize); 00312 00313 if (eventSize > sizeof(HeaderView)) { 00314 nWant = eventSize - sizeof(HeaderView); 00315 nGot = readBytes(&eventBuf_[sizeof(HeaderView)], nWant); 00316 if (nGot != nWant) { 00317 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readEventMessage") 00318 << "Failed reading streamer file, second read in readEventMessage\n" 00319 << "Requested " << nWant << " bytes, read function returned " << nGot << " bytes\n"; 00320 } 00321 } 00322 else { 00323 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readEventMessage") 00324 << "Failed reading streamer file, event header size from data too small\n"; 00325 } 00326 00327 delete currentEvMsg_; 00328 currentEvMsg_ = new EventMsgView((void*)&eventBuf_[0]); 00329 00330 return 1; 00331 }
void StreamerInputFile::readStartMessage | ( | ) | [private] |
Not an init message should return
Definition at line 160 of file StreamerInputFile.cc.
References code, HeaderView::code(), edm::errors::FileReadError, headerBuf_, Header::INIT, readBytes(), HeaderView::size(), and startMsg_.
Referenced by compareHeader(), and StreamerInputFile().
00161 { 00162 IOSize nWant = sizeof(HeaderView); 00163 IOSize nGot = readBytes(&headerBuf_[0], nWant); 00164 if (nGot != nWant) { 00165 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readStartMessage") 00166 << "Failed reading streamer file, first read in readStartMessage\n"; 00167 } 00168 00169 HeaderView head(&headerBuf_[0]); 00170 uint32 code = head.code(); 00171 if (code != Header::INIT) 00172 { 00173 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readStartMessage") 00174 << "Expecting an init Message at start of file\n"; 00175 return; 00176 } 00177 00178 uint32 headerSize = head.size(); 00179 if (headerBuf_.size() < headerSize) headerBuf_.resize(headerSize); 00180 00181 if (headerSize > sizeof(HeaderView)) { 00182 nWant = headerSize - sizeof(HeaderView); 00183 nGot = readBytes(&headerBuf_[sizeof(HeaderView)], nWant); 00184 if (nGot != nWant) { 00185 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readStartMessage") 00186 << "Failed reading streamer file, second read in readStartMessage\n"; 00187 } 00188 } 00189 else { 00190 throw edm::Exception(errors::FileReadError, "StreamerInputFile::readStartMessage") 00191 << "Failed reading streamer file, init header size from data too small\n"; 00192 } 00193 00194 delete startMsg_; 00195 startMsg_ = new InitMsgView(&headerBuf_[0]) ; 00196 }
const InitMsgView* StreamerInputFile::startMessage | ( | ) | const [inline] |
Moves the handler to next Event Record.
Definition at line 39 of file StreamerInputFile.h.
References startMsg_.
Referenced by edmtestp::TestFileReader::TestFileReader().
00039 { return startMsg_; }
EventMsgView* StreamerInputFile::currentEvMsg_ [private] |
Definition at line 71 of file StreamerInputFile.h.
Referenced by currentRecord(), readEventMessage(), and ~StreamerInputFile().
unsigned int StreamerInputFile::currentFile_ [private] |
Definition at line 76 of file StreamerInputFile.h.
Referenced by compareHeader(), openNextFile(), and StreamerInputFile().
std::string StreamerInputFile::currentFileName_ [private] |
True if Multiple Streams are Read.
Definition at line 79 of file StreamerInputFile.h.
Referenced by logFileAction(), and openStreamerFile().
bool StreamerInputFile::currentFileOpen_ [private] |
Definition at line 80 of file StreamerInputFile.h.
Referenced by openStreamerFile(), and ~StreamerInputFile().
uint32 StreamerInputFile::currProto_ [private] |
Definition at line 83 of file StreamerInputFile.h.
Referenced by compareHeader(), and StreamerInputFile().
uint32 StreamerInputFile::currRun_ [private] |
Definition at line 82 of file StreamerInputFile.h.
Referenced by compareHeader(), and StreamerInputFile().
bool StreamerInputFile::endOfFile_ [private] |
std::vector<char> StreamerInputFile::eventBuf_ [private] |
Buffer to store file Header.
Definition at line 74 of file StreamerInputFile.h.
Referenced by readEventMessage().
std::vector<char> StreamerInputFile::headerBuf_ [private] |
StreamerInputIndexFile* StreamerInputFile::index_ [private] |
indexRecIter StreamerInputFile::indexIter_b [private] |
indexRecIter StreamerInputFile::indexIter_e [private] |
bool StreamerInputFile::multiStreams_ [private] |
bool StreamerInputFile::newHeader_ [private] |
InitMsgView* StreamerInputFile::startMsg_ [private] |
Definition at line 70 of file StreamerInputFile.h.
Referenced by compareHeader(), openNextFile(), readStartMessage(), startMessage(), StreamerInputFile(), and ~StreamerInputFile().
boost::shared_ptr<Storage> StreamerInputFile::storage_ [private] |
Definition at line 87 of file StreamerInputFile.h.
Referenced by next(), openStreamerFile(), readBytes(), and ~StreamerInputFile().
std::vector<std::string> StreamerInputFile::streamerNames_ [private] |
keeps track of which file is in use at the moment
Definition at line 77 of file StreamerInputFile.h.
Referenced by compareHeader(), and openNextFile().
bool StreamerInputFile::useIndex_ [private] |