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 {
14  StreamerInputSource(pset, desc),
15  streamerNames_(pset.getUntrackedParameter<std::vector<std::string> >("fileNames")),
16  streamReader_(),
17  eventSkipperByID_(EventSkipperByID::create(pset).release()),
18  numberOfEventsToSkip_(pset.getUntrackedParameter<unsigned int>("skipEvents")) {
19  InputFileCatalog catalog(pset.getUntrackedParameter<std::vector<std::string> >("fileNames"), pset.getUntrackedParameter<std::string>("overrideCatalog"));
20  streamerNames_ = catalog.fileNames();
21 
22  if (streamerNames_.size() > 1) {
23  streamReader_ = std::auto_ptr<StreamerInputFile>(new StreamerInputFile(streamerNames_, &numberOfEventsToSkip_, eventSkipperByID_));
24  } else if (streamerNames_.size() == 1) {
25  streamReader_ = std::auto_ptr<StreamerInputFile>(new StreamerInputFile(streamerNames_.at(0), &numberOfEventsToSkip_, eventSkipperByID_));
26  } else {
27  throw Exception(errors::FileReadError, "StreamerFileReader::StreamerFileReader")
28  << "No fileNames were specified\n";
29  }
30  InitMsgView const* header = getHeader();
31  deserializeAndMergeWithRegistry(*header, false);
32  }
33 
35  }
36 
39 
40  EventMsgView const* eview = getNextEvent();
41 
42  if (newHeader()) {
43  // FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
44  // A new file has been opened and we must compare Heraders here !!
45  //Get header/init from reader
46  InitMsgView const* header = getHeader();
47  deserializeAndMergeWithRegistry(*header, true);
48  }
49  if (eview == 0) {
50  return 0;
51  }
52  return(deserializeEvent(*eview));
53  }
54 
55  bool
57  return streamReader_->newHeader();
58  }
59 
60  InitMsgView const*
62 
63  InitMsgView const* header = streamReader_->startMessage();
64 
65  if(header->code() != Header::INIT) { //INIT Msg
66  throw Exception(errors::FileReadError, "StreamerFileReader::readHeader")
67  << "received wrong message type: expected INIT, got "
68  << header->code() << "\n";
69  }
70  return header;
71  }
72 
73  EventMsgView const*
75  if (!streamReader_->next()) {
76  return 0;
77  }
78  return streamReader_->currentRecord();
79  }
80 
81  void
84  desc.setComment("Reads events from streamer files.");
85  desc.addUntracked<std::vector<std::string> >("fileNames")
86  ->setComment("Names of files to be processed.");
87  desc.addUntracked<unsigned int>("skipEvents", 0U)
88  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
89  desc.addUntracked<std::string>("overrideCatalog", std::string());
90  //This next parameter is read in the base class, but its default value depends on the derived class, so it is set here.
91  desc.addUntracked<bool>("inputFileTransitionsEachEvent", false);
94  descriptions.add("source", desc);
95  }
96 } //end-of-namespace
97 
T getUntrackedParameter(std::string const &, T const &) const
static void fillDescription(ParameterSetDescription &description)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
StreamerFileReader(ParameterSet const &pset, InputSourceDescription const &desc)
void setComment(std::string const &value)
InitMsgView const * getHeader()
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
std::vector< std::string > streamerNames_
std::vector< std::string > const & fileNames() const
virtual EventPrincipal * read()
void add(std::string const &label, ParameterSetDescription const &psetDescription)
EventPrincipal * deserializeEvent(EventMsgView const &eventView)
static void fillDescription(ParameterSetDescription &desc)
uint32 code() const
Definition: InitMessage.h:66
static void fillDescriptions(ConfigurationDescriptions &descriptions)
std::auto_ptr< StreamerInputFile > streamReader_
void deserializeAndMergeWithRegistry(InitMsgView const &initView, bool subsequent=false)
EventMsgView const * getNextEvent()
SurfaceDeformation * create(int type, const std::vector< double > &params)