CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StreamerFileReader.cc
Go to the documentation of this file.
12 
13 namespace edm {
14 
16  : StreamerInputSource(pset, desc),
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.fileCatalogItems();
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>(
33  streamerNames_.at(0).fileNames()[0], streamerNames_.at(0).logicalFileName(), eventSkipperByID());
34  } else {
35  throw Exception(errors::FileReadError, "StreamerFileReader::StreamerFileReader")
36  << "No fileNames were specified\n";
37  }
38  isFirstFile_ = true;
39  InitMsgView const* header = getHeader();
40  deserializeAndMergeWithRegistry(*header, false);
43  }
44  }
45 
47  EventMsgView const* eview = getNextEvent();
48 
49  if (eview == nullptr) {
50  if (newHeader()) {
51  return Next::kFile;
52  }
53  return Next::kStop;
54  }
55  deserializeEvent(*eview);
56  return Next::kEvent;
57  }
58 
59  void StreamerFileReader::skip(int toSkip) {
60  for (int i = 0; i != toSkip; ++i) {
61  EventMsgView const* evMsg = getNextEvent();
62  if (evMsg == nullptr) {
63  return;
64  }
65  // If the event would have been skipped anyway, don't count it as a skipped event.
66  if (eventSkipperByID_ && eventSkipperByID_->skipIt(evMsg->run(), evMsg->lumi(), evMsg->event())) {
67  --i;
68  }
69  }
70  }
71 
73  if (streamReader_.get() != nullptr)
74  streamReader_->closeStreamerFile();
75  }
76 
78  if (isFirstFile_) {
79  //The file was already opened in the constructor
80  isFirstFile_ = false;
81  return;
82  }
83  streamReader_->openNextFile();
84  // FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
85  // A new file has been opened and we must compare Heraders here !!
86  //Get header/init from reader
87  InitMsgView const* header = getHeader();
88  deserializeAndMergeWithRegistry(*header, true);
89  }
90 
91  bool StreamerFileReader::newHeader() { return streamReader_->newHeader(); }
92 
94  InitMsgView const* header = streamReader_->startMessage();
95 
96  if (header->code() != Header::INIT) { //INIT Msg
97  throw Exception(errors::FileReadError, "StreamerFileReader::readHeader")
98  << "received wrong message type: expected INIT, got " << header->code() << "\n";
99  }
100  return header;
101  }
102 
105  return nullptr;
106  }
107  return streamReader_->currentRecord();
108  }
109 
112  desc.setComment("Reads events from streamer files.");
113  desc.addUntracked<std::vector<std::string> >("fileNames")->setComment("Names of files to be processed.");
114  desc.addUntracked<unsigned int>("skipEvents", 0U)
115  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
116  desc.addUntracked<std::string>("overrideCatalog", std::string());
117  //This next parameter is read in the base class, but its default value depends on the derived class, so it is set here.
118  desc.addUntracked<bool>("inputFileTransitionsEachEvent", false);
121  descriptions.add("source", desc);
122  }
123 } // 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)
void genuineCloseFile() 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
std::vector< FileCatalogItem > streamerNames_
void deserializeEvent(EventMsgView const &eventView)
edm::propagate_const< std::unique_ptr< StreamerInputFile > > streamReader_
InitMsgView const * getHeader()
void skip(int toSkip) override
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
void genuineReadFile() override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescription(ParameterSetDescription &desc)
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()
std::vector< FileCatalogItem > const & fileCatalogItems() const