CMS 3D CMS Logo

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