CMS 3D CMS Logo

StreamerInputIndexFile Class Reference

#include <IOPool/Streamer/interface/StreamerInputIndexFile.h>

List of all members.

Public Member Functions

const indexRecIter begin ()
const indexRecIter end ()
bool eof ()
indexRecIter sort ()
const StartIndexRecordstartMessage () const
 StreamerInputIndexFile (const std::vector< std::string > &names)
 StreamerInputIndexFile (const std::string &name)
 Class for doing Index Read Operations.
 ~StreamerInputIndexFile ()

Private Member Functions

int readEventMessage ()
 Reads in Start Message.
void readStartMessage ()

Private Attributes

bool eof_
std::vector< char > eventBuf_
uint64 eventBufPtr_
uint32 eventHeaderSize_
std::vector< char > headerBuf_
std::vector< EventIndexRecord * > indexes_
std::ifstream * ist_
 Reads in next EventIndex Record.
StartIndexRecordstartMsg_


Detailed Description

Definition at line 8 of file StreamerInputIndexFile.h.


Constructor & Destructor Documentation

StreamerInputIndexFile::StreamerInputIndexFile ( const std::string &  name  )  [explicit]

Class for doing Index Read Operations.

Definition at line 21 of file StreamerInputIndexFile.cc.

References lat::endl(), FDEBUG, edm::errors::FileOpenError, ist_, readEventMessage(), and readStartMessage().

00021                                                                    :
00022   ist_(new std::ifstream(name.c_str(), std::ios_base::binary | std::ios_base::in)),
00023   startMsg_(0),
00024   eof_(false),
00025   eventBufPtr_(0),
00026   headerBuf_(1000*1000),
00027   eventBuf_(1000*1000*40),
00028   eventHeaderSize_(0),
00029   indexes_(0)
00030 {
00031 
00032   FDEBUG(10) << "Opening Index file" << std::endl;
00033   if (!ist_->is_open()) {
00034        throw edm::Exception(errors::FileOpenError, "StreamerInputIndexFile::StreamerInputIndexFile")
00035           << "Error Opening Input File: "<< name<< "\n";
00036   } 
00037   readStartMessage();
00038   while (readEventMessage()) {
00039       ;
00040   }
00041   
00042   ist_->close();
00043   delete ist_;
00044 }

StreamerInputIndexFile::StreamerInputIndexFile ( const std::vector< std::string > &  names  )  [explicit]

Definition at line 47 of file StreamerInputIndexFile.cc.

References edm::errors::FileOpenError, i, in, ist_, readEventMessage(), and readStartMessage().

00047                                                                                :
00048   startMsg_(0),
00049   eof_(false),
00050   eventBufPtr_(0),
00051   headerBuf_(1000*1000),
00052   eventBuf_(1000*1000*40),
00053   eventHeaderSize_(0),
00054   indexes_(0)
00055 {
00056    for (unsigned int i=0; i!=names.size(); ++i) 
00057    {
00058      ist_ = new std::ifstream(names.at(i).c_str(), std::ios_base::binary | std::ios_base::in);
00059      if (!ist_->is_open())
00060      {
00061        throw edm::Exception(errors::FileOpenError, "StreamerInputIndexFile::StreamerInputIndexFile")
00062           << "Error Opening Input File: "<< names.at(i) << "\n";
00063      }
00064 
00065        readStartMessage();
00066        while (readEventMessage()) {
00067        ;
00068        }
00069        ist_->close();
00070        delete ist_; 
00071    }
00072 }

StreamerInputIndexFile::~StreamerInputIndexFile (  ) 

Definition at line 12 of file StreamerInputIndexFile.cc.

References end(), it, and startMsg_.

00013 {
00014   delete startMsg_; 
00015 
00016   for(indexRecIter it = this->begin(), itEnd = this->end(); it != itEnd; ++it) {
00017           delete (*it);
00018   }
00019 }


Member Function Documentation

const indexRecIter StreamerInputIndexFile::begin ( void   )  [inline]

Definition at line 21 of file StreamerInputIndexFile.h.

References indexes_.

Referenced by sort().

00021 { return indexes_.begin(); }

const indexRecIter StreamerInputIndexFile::end ( void   )  [inline]

Definition at line 22 of file StreamerInputIndexFile.h.

References indexes_.

Referenced by ~StreamerInputIndexFile().

00022 { return indexes_.end(); }

bool StreamerInputIndexFile::eof ( void   )  [inline]

Definition at line 19 of file StreamerInputIndexFile.h.

References eof_.

00019 {return eof_; }

int StreamerInputIndexFile::readEventMessage (  )  [private]

Reads in Start Message.

Not an event message should return

Definition at line 123 of file StreamerInputIndexFile.cc.

References code, HeaderView::code(), lat::endl(), eof_, Header::EVENT, eventBuf_, eventBufPtr_, eventHeaderSize_, Exception, FDEBUG, edm::errors::FileReadError, indexes_, ist_, EventIndexRecord::makeEvent(), and EventIndexRecord::makeOffset().

Referenced by StreamerInputIndexFile().

00123                                               {
00124   std::streampos last_pos = ist_->tellg();
00125   uint32 bufPtr = eventBufPtr_;
00126   //uint32 bufPtr = eventBufPtr_+1;
00127 
00128   //ist_->clear();
00129   if (eventBuf_.size() < bufPtr + sizeof(HeaderView)) {
00130     throw edm::Exception(errors::FileReadError, "StreamerInputFile::readEventMessage")
00131       << "eventBuf array is about to overflow, just before first read.\n";
00132   }
00133   ist_->read((char*)&eventBuf_[bufPtr], sizeof(HeaderView));
00134 
00135   if (ist_->eof() || static_cast<unsigned int>(ist_->gcount()) < sizeof(HeaderView))
00136   {      
00137         eof_ = true;
00138         return 0;
00139   }
00140 
00141   HeaderView head_(&eventBuf_[bufPtr]);
00142   uint32 code = head_.code();
00143 
00144   if (code != Header::EVENT) 
00145      {
00146      FDEBUG(10) << "Not an event Message "<< std::endl;
00147      return 0;
00148      }
00149 
00150   //Bring the pointer at last position, start of event msg
00151   //ist_->clear();
00152   ist_->seekg(last_pos);
00153   
00154   if (eventBuf_.size() < bufPtr + eventHeaderSize_ + sizeof(uint64)) {
00155     throw cms::Exception("readEventMessage","StreamerInputFile")
00156       << "eventBuf array is about to overflow, just before second read.\n";
00157   }
00158   ist_->read((char*)&eventBuf_[bufPtr], eventHeaderSize_+sizeof(uint64));
00159   if (ist_->eof()) {
00160      eof_= true;
00161      return 0;
00162   }
00163 
00164   EventIndexRecord* currentEvMsg = new EventIndexRecord();
00165   //EventIndexRecord currentEvMsg;
00166   currentEvMsg->makeEvent((void*)&eventBuf_[bufPtr]);
00167 
00168   uint32 offset_loc = bufPtr + eventHeaderSize_;
00169    
00170   currentEvMsg->makeOffset(&eventBuf_[offset_loc]);
00171 
00172   indexes_.push_back(currentEvMsg);
00173 
00174   //This Brings the pointer to end of this Event Msg.
00175   std::streamoff new_len = eventHeaderSize_ + sizeof(uint64); 
00176 
00177   //How many bytes have read so far
00178   eventBufPtr_ +=  eventHeaderSize_ + sizeof(uint64);
00179 
00180   //This should be the proper position of the file pointer
00181   ist_->seekg(last_pos + new_len);
00182   return 1;
00183 }

void StreamerInputIndexFile::readStartMessage (  )  [private]

Definition at line 74 of file StreamerInputIndexFile.cc.

References code, HeaderView::code(), eventHeaderSize_, edm::errors::FileReadError, StartIndexRecord::getInit(), headerBuf_, Header::INIT, ist_, StartIndexRecord::makeHeader(), StartIndexRecord::makeInit(), HeaderView::size(), and startMsg_.

Referenced by StreamerInputIndexFile().

00074                                               {
00075   //Read magic+reserved fileds at the start of file 
00076   //ist_->clear();
00077   ist_->read((char*)&headerBuf_[0], sizeof(StartIndexRecordHeader));
00078   if (ist_->eof() || static_cast<unsigned int>(ist_->gcount()) < sizeof(StartIndexRecordHeader)) {
00079         return;
00080    }  
00081   //Read Header from the start of init message to find the size
00082   ist_->read((char*)&headerBuf_[sizeof(StartIndexRecordHeader)], sizeof(HeaderView));
00083   if (ist_->eof() || static_cast<unsigned int>(ist_->gcount()) < sizeof(HeaderView))
00084   {
00085         throw edm::Exception(errors::FileReadError, "StreamerInputFile::readStartMessage")
00086               << "Empty file encountered\n";
00087   }
00088 
00089   HeaderView head(&headerBuf_[sizeof(StartIndexRecordHeader)]);
00090   uint32 code = head.code();
00091   if (code != Header::INIT) // ** Not an init message should return ****** /
00092   {
00093     throw edm::Exception(errors::FileReadError, "StreamerInputFile::readStartMessage")
00094               << "Expecting an init Message at start of file\n";
00095     return;
00096   }
00097   uint32 headerSize = head.size();
00098   //Bring the pointer at start of Start Message (Starts after file header magic+reserved)
00099   ist_->seekg(sizeof(StartIndexRecordHeader), std::ios::beg);
00100   if (headerBuf_.size() < (sizeof(StartIndexRecordHeader) + headerSize))
00101     headerBuf_.resize(sizeof(StartIndexRecordHeader) + headerSize);
00102   ist_->read((char*)&headerBuf_[sizeof(StartIndexRecordHeader)], headerSize);
00103  
00104   delete startMsg_;
00105    
00106   startMsg_ = new StartIndexRecord();
00107   startMsg_->makeHeader(&headerBuf_[0]);
00108   //Init msg lies just after StartIndexRecordHeader
00109   startMsg_->makeInit(&headerBuf_[sizeof(StartIndexRecordHeader)]);
00110    
00111   //   As the size of index record is unknown as of yet the 
00112   //   ist_ can over run, so it may have reached EOF
00113   //   it needs to be reset, before its positioned correctly.
00114 
00115   ist_->clear();
00116   //Bring ist_ at the end of record
00117   headerSize = (startMsg_->getInit())->headerSize(); 
00118   ist_->seekg(sizeof(StartIndexRecordHeader)+headerSize, std::ios::beg);
00119 
00120   eventHeaderSize_ = (startMsg_->getInit())->eventHeaderSize();
00121 }

indexRecIter StreamerInputIndexFile::sort (  ) 

Definition at line 203 of file StreamerInputIndexFile.cc.

References begin(), header_event_sorter(), header_run_sorter(), and edm::sort_all().

00203                                           {
00204   //Run sorting is required ?? 
00205   sort_all(*this, header_run_sorter);
00206   sort_all(*this, header_event_sorter);
00207   return this->begin();
00208 }

const StartIndexRecord* StreamerInputIndexFile::startMessage (  )  const [inline]

Definition at line 17 of file StreamerInputIndexFile.h.

References startMsg_.

00017 { return startMsg_; }


Member Data Documentation

bool StreamerInputIndexFile::eof_ [private]

Definition at line 34 of file StreamerInputIndexFile.h.

Referenced by eof(), and readEventMessage().

std::vector<char> StreamerInputIndexFile::eventBuf_ [private]

Definition at line 39 of file StreamerInputIndexFile.h.

Referenced by readEventMessage().

uint64 StreamerInputIndexFile::eventBufPtr_ [private]

Definition at line 36 of file StreamerInputIndexFile.h.

Referenced by readEventMessage().

uint32 StreamerInputIndexFile::eventHeaderSize_ [private]

Definition at line 40 of file StreamerInputIndexFile.h.

Referenced by readEventMessage(), and readStartMessage().

std::vector<char> StreamerInputIndexFile::headerBuf_ [private]

Definition at line 38 of file StreamerInputIndexFile.h.

Referenced by readStartMessage().

std::vector<EventIndexRecord*> StreamerInputIndexFile::indexes_ [private]

Definition at line 42 of file StreamerInputIndexFile.h.

Referenced by begin(), end(), and readEventMessage().

std::ifstream* StreamerInputIndexFile::ist_ [private]

Reads in next EventIndex Record.

Definition at line 30 of file StreamerInputIndexFile.h.

Referenced by readEventMessage(), readStartMessage(), and StreamerInputIndexFile().

StartIndexRecord* StreamerInputIndexFile::startMsg_ [private]

Definition at line 32 of file StreamerInputIndexFile.h.

Referenced by readStartMessage(), startMessage(), and ~StreamerInputIndexFile().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:32:55 2009 for CMSSW by  doxygen 1.5.4