CMS 3D CMS Logo

StreamerFileReader.cc
Go to the documentation of this file.
12 
13 namespace edm {
14 
17  streamReader_(),
18  eventSkipperByID_(EventSkipperByID::create(pset).release()),
19  initialNumberOfEventsToSkip_(pset.getUntrackedParameter<unsigned int>("skipEvents")),
20  prefetchMBytes_(pset.getUntrackedParameter<unsigned int>("prefetchMBytes")) {
21  InputFileCatalog catalog(pset.getUntrackedParameter<std::vector<std::string> >("fileNames"),
22  pset.getUntrackedParameter<std::string>("overrideCatalog"));
23  streamerNames_ = catalog.fileCatalogItems();
24  reset_();
25  }
26 
28 
30  if (streamerNames_.size() > 1) {
31  streamReader_ = std::make_unique<StreamerInputFile>(streamerNames_, eventSkipperByID(), prefetchMBytes_);
32  } else if (streamerNames_.size() == 1) {
33  streamReader_ = std::make_unique<StreamerInputFile>(streamerNames_.at(0).fileNames()[0],
34  streamerNames_.at(0).logicalFileName(),
37  } else {
38  throw Exception(errors::FileReadError, "StreamerFileReader::StreamerFileReader")
39  << "No fileNames were specified\n";
40  }
41  isFirstFile_ = true;
42  InitMsgView const* header = getHeader();
46  }
47  }
48 
50  EventMsgView const* eview = getNextEvent();
51 
52  if (eview == nullptr) {
53  if (newHeader()) {
54  return Next::kFile;
55  }
56  return Next::kStop;
57  }
58  deserializeEvent(*eview);
59  return Next::kEvent;
60  }
61 
62  void StreamerFileReader::skip(int toSkip) {
63  for (int i = 0; i != toSkip; ++i) {
64  EventMsgView const* evMsg = getNextEvent();
65  if (evMsg == nullptr) {
66  return;
67  }
68  // If the event would have been skipped anyway, don't count it as a skipped event.
69  if (eventSkipperByID_ && eventSkipperByID_->skipIt(evMsg->run(), evMsg->lumi(), evMsg->event())) {
70  --i;
71  }
72  }
73  }
74 
76  if (streamReader_.get() != nullptr)
77  streamReader_->closeStreamerFile();
78  }
79 
81  if (isFirstFile_) {
82  //The file was already opened in the constructor
83  isFirstFile_ = false;
84  return;
85  }
86  streamReader_->openNextFile();
87  // FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
88  // A new file has been opened and we must compare Heraders here !!
89  //Get header/init from reader
90  InitMsgView const* header = getHeader();
92  }
93 
94  bool StreamerFileReader::newHeader() { return streamReader_->newHeader(); }
95 
97  InitMsgView const* header = streamReader_->startMessage();
98 
99  if (header->code() != Header::INIT) { //INIT Msg
100  throw Exception(errors::FileReadError, "StreamerFileReader::readHeader")
101  << "received wrong message type: expected INIT, got " << header->code() << "\n";
102  }
103  return header;
104  }
105 
108  return nullptr;
109  }
110  return streamReader_->currentRecord();
111  }
112 
115  desc.setComment("Reads events from streamer files.");
116  desc.addUntracked<std::vector<std::string> >("fileNames")->setComment("Names of files to be processed.");
117  desc.addUntracked<unsigned int>("skipEvents", 0U)
118  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
119  desc.addUntracked<std::string>("overrideCatalog", std::string());
120  //This next parameter is read in the base class, but its default value depends on the derived class, so it is set here.
121  desc.addUntracked<bool>("inputFileTransitionsEachEvent", false);
122  desc.addUntracked<unsigned int>("prefetchMBytes", 0);
125  descriptions.add("source", desc);
126  }
127 } // namespace edm
static void fillDescription(ParameterSetDescription &description)
def create(alignables, pedeDump, additionalData, outputFile, config)
void genuineCloseFile() override
uint32 lumi() const
Definition: EventMessage.cc:81
uint64 event() const
Definition: EventMessage.cc:76
StreamerFileReader(ParameterSet const &pset, InputSourceDescription const &desc)
std::vector< FileCatalogItem > streamerNames_
void deserializeEvent(EventMsgView const &eventView)
edm::propagate_const< std::unique_ptr< StreamerInputFile > > streamReader_
void skip(int toSkip) override
InitMsgView const * getHeader()
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
void genuineReadFile() override
uint32 run() const
Definition: EventMessage.cc:71
void add(std::string const &label, ParameterSetDescription const &psetDescription)
EventMsgView const * getNextEvent()
static void fillDescription(ParameterSetDescription &desc)
HLT enums.
static void fillDescriptions(ConfigurationDescriptions &descriptions)
std::shared_ptr< EventSkipperByID const > eventSkipperByID() const
void deserializeAndMergeWithRegistry(InitMsgView const &initView, bool subsequent=false)