CMS 3D CMS Logo

StreamerFileReader.cc
Go to the documentation of this file.
12 
13 #include <cassert>
14 namespace edm::streamer {
15 
18  streamReader_(),
19  eventSkipperByID_(EventSkipperByID::create(pset).release()),
20  initialNumberOfEventsToSkip_(pset.getUntrackedParameter<unsigned int>("skipEvents")),
21  prefetchMBytes_(pset.getUntrackedParameter<unsigned int>("prefetchMBytes")) {
22  InputFileCatalog catalog(pset.getUntrackedParameter<std::vector<std::string> >("fileNames"),
23  pset.getUntrackedParameter<std::string>("overrideCatalog"));
24  streamerNames_ = catalog.fileCatalogItems();
25  reset_();
26  }
27 
29 
31  if (streamerNames_.size() > 1) {
32  streamReader_ = std::make_unique<StreamerInputFile>(streamerNames_, eventSkipperByID(), prefetchMBytes_);
33  } else if (streamerNames_.size() == 1) {
34  streamReader_ = std::make_unique<StreamerInputFile>(streamerNames_.at(0).fileNames()[0],
35  streamerNames_.at(0).logicalFileName(),
38  } else {
39  throw Exception(errors::FileReadError, "StreamerFileReader::StreamerFileReader")
40  << "No fileNames were specified\n";
41  }
42  isFirstFile_ = true;
43  updateMetaData(false);
46  }
47  }
48 
49  void StreamerFileReader::updateMetaData(bool subsequent) {
50  InitMsgView const* header = getHeader();
52  //NOTE: should read first Event to get the meta data and then set 'artificial file'
53  auto eview = getNextEvent();
54 
55  //if no events then file must be empty
56  if (eview == nullptr)
57  return;
58 
59  assert(eview->isEventMetaData());
62  }
63 
65  EventMsgView const* eview = getNextEvent();
66 
67  if (eview == nullptr) {
68  if (newHeader()) {
69  return Next::kFile;
70  }
71  return Next::kStop;
72  }
73  if (eview->isEventMetaData()) {
75  //we lie and say there is a new file since we need to synchronize to update the meta data
76  didArtificialFile_ = true;
78  return Next::kFile;
79  } else {
80  //skip this meta data
81  eview = getNextEvent();
82  if (eview == nullptr) {
83  if (newHeader()) {
84  return Next::kFile;
85  }
86  return Next::kStop;
87  }
88  }
89  }
90  deserializeEvent(*eview);
91  return Next::kEvent;
92  }
93 
94  void StreamerFileReader::skip(int toSkip) {
95  for (int i = 0; i != toSkip; ++i) {
96  EventMsgView const* evMsg = getNextEvent();
97  if (evMsg == nullptr) {
98  return;
99  }
100  // If the event would have been skipped anyway, don't count it as a skipped event.
101  if (eventSkipperByID_ && eventSkipperByID_->skipIt(evMsg->run(), evMsg->lumi(), evMsg->event())) {
102  --i;
103  }
104  }
105  }
106 
108  if (didArtificialFile_) {
109  return;
110  }
111  if (streamReader_.get() != nullptr)
112  streamReader_->closeStreamerFile();
113  }
114 
116  if (isFirstFile_) {
117  //The file was already opened in the constructor
118  isFirstFile_ = false;
119  return;
120  }
121  if (didArtificialFile_) {
122  //update the event meta data
123  didArtificialFile_ = false;
125  return;
126  }
127  streamReader_->openNextFile();
128  // FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
129  // A new file has been opened and we must compare Heraders here !!
130  //Get header/init from reader
131  updateMetaData(true);
132  }
133 
134  bool StreamerFileReader::newHeader() { return streamReader_->newHeader(); }
135 
137  InitMsgView const* header = streamReader_->startMessage();
138 
139  if (header->code() != Header::INIT) { //INIT Msg
140  throw Exception(errors::FileReadError, "StreamerFileReader::readHeader")
141  << "received wrong message type: expected INIT, got " << header->code() << "\n";
142  }
143  return header;
144  }
145 
148  return nullptr;
149  }
150  return streamReader_->currentRecord();
151  }
152 
155  desc.setComment("Reads events from streamer files.");
156  desc.addUntracked<std::vector<std::string> >("fileNames")->setComment("Names of files to be processed.");
157  desc.addUntracked<unsigned int>("skipEvents", 0U)
158  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
159  desc.addUntracked<std::string>("overrideCatalog", std::string());
160  //This next parameter is read in the base class, but its default value depends on the derived class, so it is set here.
161  desc.addUntracked<bool>("inputFileTransitionsEachEvent", false);
162  desc.addUntracked<unsigned int>("prefetchMBytes", 0);
165  descriptions.add("source", desc);
166  }
167 } // namespace edm::streamer
def create(alignables, pedeDump, additionalData, outputFile, config)
void deserializeEventMetaData(EventMsgView const &eventView)
edm::propagate_const< std::unique_ptr< StreamerInputFile > > streamReader_
static void fillDescription(ParameterSetDescription &description)
assert(be >=bs)
void skip(int toSkip) override
void deserializeEvent(EventMsgView const &eventView)
uint32_t eventMetaDataChecksum(EventMsgView const &eventView) const
void deserializeAndMergeWithRegistry(InitMsgView const &initView, bool subsequent=false)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescription(ParameterSetDescription &desc)
StreamerFileReader(ParameterSet const &pset, InputSourceDescription const &desc)
std::shared_ptr< EventSkipperByID const > eventSkipperByID() const
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
std::vector< FileCatalogItem > streamerNames_
static void fillDescriptions(ConfigurationDescriptions &descriptions)