CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/IOPool/Streamer/src/StreamDQMInputFile.cc

Go to the documentation of this file.
00001 #include "IOPool/Streamer/interface/StreamDQMInputFile.h"
00002 #include "IOPool/Streamer/interface/MsgTools.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 //#include "FWCore/Utilities/interface/DebugMacros.h"
00005 
00006 using namespace edm;
00007 
00008 StreamDQMInputFile::~StreamDQMInputFile()
00009 {
00010   //ist_->close();
00011 }
00012 
00013 StreamDQMInputFile::StreamDQMInputFile(const std::string& name):
00014   currentEvMsg_(),
00015   ist_(new ifstream(name.c_str())),
00016   eventBuf_(1000*1000*7)
00017 {
00018 
00019   if (!ist_->is_open()) {
00020       throw cms::Exception("StreamDQMInputFile","StreamDQMInputFile")
00021         << "Error Opening Input File: " << name << "\n";
00022   }
00023 
00024 }
00025 
00026 bool StreamDQMInputFile::next()  
00027 {
00028   if (this->readDQMEventMessage()) {
00029        return true;
00030   }
00031 
00032   return false;
00033 }
00034 
00035 int StreamDQMInputFile::readDQMEventMessage() {
00036 
00037   uint32 last_pos = ist_->tellg();
00038   uint32 nWant = sizeof(HeaderView);
00039 
00040   ist_->read(&eventBuf_[0], nWant);
00041 
00042   if (ist_->eof() || static_cast<unsigned int>(ist_->gcount()) < nWant) {
00043         return 0;
00044   }  
00045 
00046   HeaderView head(&eventBuf_[0]);
00047   uint32 code = head.code();
00048   if (code != Header::DQM_EVENT)
00049     return 0;
00050 
00051   //This includes header
00052   uint32 eventSize = head.size();
00053   if (eventBuf_.size() < eventSize) eventBuf_.resize(eventSize);
00054 
00055   if (eventSize > sizeof(DQMEventMsgView)) {
00056     //Lets read the whole thing again
00057     nWant = eventSize;
00058     ist_->seekg(last_pos, std::ios::beg);
00059     ist_->read(&eventBuf_[0], nWant);
00060     if (ist_->eof() || static_cast<unsigned int>(ist_->gcount()) < nWant) {
00061         return 0;
00062     }
00063   }
00064 
00065   currentEvMsg_.reset(new DQMEventMsgView((void*)&eventBuf_[0]));
00066   uint32 new_len = last_pos + eventSize; 
00067   ist_->seekg(new_len, std::ios::beg);
00068   return 1;
00069 }
00070