CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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"), pset.getUntrackedParameter<std::string>("overrideCatalog"));
21  streamerNames_ = catalog.fileNames();
22  reset_();
23 
24  }
25 
27  }
28 
29  void
31  if (streamerNames_.size() > 1) {
32  streamReader_ = std::unique_ptr<StreamerInputFile>(new StreamerInputFile(streamerNames_, eventSkipperByID_));
33  } else if (streamerNames_.size() == 1) {
34  streamReader_ = std::unique_ptr<StreamerInputFile>(new StreamerInputFile(streamerNames_.at(0), eventSkipperByID_));
35  } else {
36  throw Exception(errors::FileReadError, "StreamerFileReader::StreamerFileReader")
37  << "No fileNames were specified\n";
38  }
39  InitMsgView const* header = getHeader();
40  deserializeAndMergeWithRegistry(*header, false);
43  }
44  }
45 
46 
48  EventMsgView const* eview = getNextEvent();
49 
50  if (newHeader()) {
51  // FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
52  // A new file has been opened and we must compare Heraders here !!
53  //Get header/init from reader
54  InitMsgView const* header = getHeader();
55  deserializeAndMergeWithRegistry(*header, true);
56  }
57  if (eview == nullptr) {
58  return false;
59  }
60  deserializeEvent(*eview);
61  return true;
62  }
63 
64  void
66  for(int i = 0; i != toSkip; ++i) {
67  EventMsgView const* evMsg = getNextEvent();
68  if(evMsg == nullptr) {
69  return;
70  }
71  // If the event would have been skipped anyway, don't count it as a skipped event.
72  if(eventSkipperByID_ && eventSkipperByID_->skipIt(evMsg->run(), evMsg->lumi(), evMsg->event())) {
73  --i;
74  }
75  }
76  }
77 
78  void
80  if(streamReader_.get() != nullptr) streamReader_->closeStreamerFile();
81  }
82 
83  bool
85  return streamReader_->newHeader();
86  }
87 
88  InitMsgView const*
90 
91  InitMsgView const* header = streamReader_->startMessage();
92 
93  if(header->code() != Header::INIT) { //INIT Msg
94  throw Exception(errors::FileReadError, "StreamerFileReader::readHeader")
95  << "received wrong message type: expected INIT, got "
96  << header->code() << "\n";
97  }
98  return header;
99  }
100 
101  EventMsgView const*
103  if (!streamReader_->next()) {
104  return nullptr;
105  }
106  return streamReader_->currentRecord();
107  }
108 
109  void
112  desc.setComment("Reads events from streamer files.");
113  desc.addUntracked<std::vector<std::string> >("fileNames")
114  ->setComment("Names of files to be processed.");
115  desc.addUntracked<unsigned int>("skipEvents", 0U)
116  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
117  desc.addUntracked<std::string>("overrideCatalog", std::string());
118  //This next parameter is read in the base class, but its default value depends on the derived class, so it is set here.
119  desc.addUntracked<bool>("inputFileTransitionsEachEvent", false);
122  descriptions.add("source", desc);
123  }
124 } //end-of-namespace
125 
T getUntrackedParameter(std::string const &, T const &) const
static void fillDescription(ParameterSetDescription &description)
int i
Definition: DBlmapReader.cc:9
uint32 lumi() const
Definition: EventMessage.cc:85
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual void genuineCloseFile() override
uint32 run() const
Definition: EventMessage.cc:73
StreamerFileReader(ParameterSet const &pset, InputSourceDescription const &desc)
void setComment(std::string const &value)
void deserializeEvent(EventMsgView const &eventView)
InitMsgView const * getHeader()
virtual void skip(int toSkip)
std::vector< std::string > streamerNames_
std::vector< std::string > const & fileNames() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::shared_ptr< EventSkipperByID > eventSkipperByID_
static void fillDescription(ParameterSetDescription &desc)
uint32 code() const
Definition: InitMessage.h:72
static void fillDescriptions(ConfigurationDescriptions &descriptions)
std::unique_ptr< StreamerInputFile > streamReader_
uint64 event() const
Definition: EventMessage.cc:79
void deserializeAndMergeWithRegistry(InitMsgView const &initView, bool subsequent=false)
EventMsgView const * getNextEvent()
SurfaceDeformation * create(int type, const std::vector< double > &params)