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 delete currentEvMsg_; 00012 } 00013 00014 StreamDQMInputFile::StreamDQMInputFile(const std::string& name): 00015 currentEvMsg_(0), 00016 ist_(new ifstream(name.c_str())), 00017 eventBuf_(1000*1000*7) 00018 { 00019 00020 if (!ist_->is_open()) { 00021 throw cms::Exception("StreamDQMInputFile","StreamDQMInputFile") 00022 << "Error Opening Input File: " << name << "\n"; 00023 } 00024 00025 } 00026 00027 bool StreamDQMInputFile::next() 00028 { 00029 if (this->readDQMEventMessage()) { 00030 return true; 00031 } 00032 00033 return false; 00034 } 00035 00036 int StreamDQMInputFile::readDQMEventMessage() { 00037 00038 uint32 last_pos = ist_->tellg(); 00039 uint32 nWant = sizeof(HeaderView); 00040 00041 ist_->read(&eventBuf_[0], nWant); 00042 00043 if (ist_->eof() || static_cast<unsigned int>(ist_->gcount()) < nWant) { 00044 return 0; 00045 } 00046 00047 HeaderView head(&eventBuf_[0]); 00048 uint32 code = head.code(); 00049 if (code != Header::DQM_EVENT) 00050 return 0; 00051 00052 //This includes header 00053 uint32 eventSize = head.size(); 00054 if (eventBuf_.size() < eventSize) eventBuf_.resize(eventSize); 00055 00056 if (eventSize > sizeof(DQMEventMsgView)) { 00057 //Lets read the whole thing again 00058 nWant = eventSize; 00059 ist_->seekg(last_pos, std::ios::beg); 00060 ist_->read(&eventBuf_[0], nWant); 00061 if (ist_->eof() || static_cast<unsigned int>(ist_->gcount()) < nWant) { 00062 return 0; 00063 } 00064 } 00065 00066 if (currentEvMsg_ != NULL) {delete currentEvMsg_;} 00067 currentEvMsg_ = new DQMEventMsgView((void*)&eventBuf_[0]); 00068 uint32 new_len = last_pos + eventSize; 00069 ist_->seekg(new_len, std::ios::beg); 00070 return 1; 00071 } 00072