CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProducerSourceBase.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <errno.h>
5 
13 
14 namespace edm {
15  //used for defaults
16  static unsigned long long const kNanoSecPerSec = 1000000000ULL;
17  static unsigned long long const kAveEventPerSec = 200ULL;
18 
20  InputSourceDescription const& desc, bool realData) :
21  InputSource(pset, desc),
22  numberEventsInRun_(pset.getUntrackedParameter<unsigned int>("numberEventsInRun", remainingEvents())),
23  numberEventsInLumi_(pset.getUntrackedParameter<unsigned int>("numberEventsInLuminosityBlock", remainingEvents())),
24  presentTime_(pset.getUntrackedParameter<unsigned long long>("firstTime", 1ULL)), //time in ns
25  origTime_(presentTime_),
26  timeBetweenEvents_(pset.getUntrackedParameter<unsigned long long>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)),
27  eventCreationDelay_(pset.getUntrackedParameter<unsigned int>("eventCreationDelay", 0)),
28  numberEventsInThisRun_(0),
29  numberEventsInThisLumi_(0),
30  zerothEvent_(pset.getUntrackedParameter<unsigned int>("firstEvent", 1) - 1),
31  eventID_(pset.getUntrackedParameter<unsigned int>("firstRun", 1), pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 1), zerothEvent_),
32  origEventID_(eventID_),
33  isRealData_(realData),
34  eType_(EventAuxiliary::Undefined) {
35 
37  // We need to map this string to the EventAuxiliary::ExperimentType enumeration
38  // std::string eType = pset.getUntrackedParameter<std::string>("experimentType", std::string("Any"))),
39  }
40 
42  }
43 
44  boost::shared_ptr<RunAuxiliary>
47  resetNewRun();
48  return boost::shared_ptr<RunAuxiliary>(new RunAuxiliary(eventID_.run(), ts, Timestamp::invalidTimestamp()));
49  }
50 
51  boost::shared_ptr<LuminosityBlockAuxiliary>
53  if (processingMode() == Runs) return boost::shared_ptr<LuminosityBlockAuxiliary>();
55  resetNewLumi();
56  return boost::shared_ptr<LuminosityBlockAuxiliary>(new LuminosityBlockAuxiliary(eventID_.run(), eventID_.luminosityBlock(), ts, Timestamp::invalidTimestamp()));
57  }
58 
62  EventSourceSentry sentry(*this);
64  eventPrincipal.fillEventPrincipal(aux);
65  Event e(eventPrincipal, moduleDescription());
66  produce(e);
67  e.commit_();
69  return &eventPrincipal;
70  }
71 
72  void
74  EventID oldEventID = eventID_;
75  for(; offset < 0; ++offset) {
77  }
78  for(; offset > 0; --offset) {
80  }
81  if(eventID_.run() != oldEventID.run()) {
82  // New Run
83  setNewRun();
84  setNewLumi();
85  }
86  if (eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
87  // New Lumi
88  setNewLumi();
89  }
90  }
91 
92  void
94  // initialize cannot be called from the constructor, because it is a virtual function
95  // that needs to be invoked from a derived class if the derived class overrides it.
97  }
98 
99  void
101  }
102 
103  void
105  }
106 
107  void
109  }
110 
111  void
113  }
114 
115  void
117  }
118 
119  void
125  setNewRun();
126  setNewLumi();
127  }
128 
131  if(state() == IsInvalid) {
132  return noFiles() ? IsStop : IsFile;
133  }
134  if (newRun()) {
135  return IsRun;
136  }
137  if (newLumi()) {
138  return IsLumi;
139  }
140  if(eventCached()) {
141  return IsEvent;
142  }
143  EventID oldEventID = eventID_;
145  if (eventCreationDelay_ > 0) {usleep(eventCreationDelay_);}
146  size_t index = fileIndex();
147  bool another = setRunAndEventInfo(eventID_, presentTime_);
148  if(!another) {
149  return IsStop;
150  }
151  bool newFile = (fileIndex() > index);
152  setEventCached();
153  if(eventID_.run() != oldEventID.run()) {
154  // New Run
155  setNewRun();
156  setNewLumi();
157  return newFile ? IsFile : IsRun;
158  }
159  if (processingMode() == Runs) {
160  return newFile ? IsFile : IsRun;
161  }
162  if (processingMode() == RunsAndLumis) {
163  return newFile ? IsFile : IsLumi;
164  }
165  // Same Run
166  if (eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
167  // New Lumi
168  setNewLumi();
169  return newFile ? IsFile : IsLumi;
170  }
171  return newFile ? IsFile : IsEvent;
172  }
173 
174  void
177  // same run
180  // new lumi
181  eventID = eventID.next(eventID.luminosityBlock() + 1);
183  } else {
184  eventID = eventID.next(eventID.luminosityBlock());
186  }
187  } else {
188  // new run
189  eventID = eventID.nextRunFirstEvent(origEventID_.luminosityBlock());
192  }
193  time += timeBetweenEvents_;
194  }
195 
196  void
198  if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
199  // same run
201  eventID = eventID.previous(eventID.luminosityBlock());
202  if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
203  // new lumi
204  eventID = eventID.previous(eventID.luminosityBlock() - 1);
206  } else {
208  }
209  } else {
210  // new run
212  eventID = EventID(numberEventsInRun_, eventID.luminosityBlock(), eventID.run());
215  }
216  time -= timeBetweenEvents_;
217  }
218 
219  bool
221  return false;
222  }
223 
224  size_t
226  return 0UL;
227  }
228 
229  void
231  desc.addOptionalUntracked<unsigned int>("numberEventsInRun")->setComment("Number of events to generate in each run.");
232  desc.addOptionalUntracked<unsigned int>("numberEventsInLuminosityBlock")->setComment("Number of events to generate in each lumi.");
233  desc.addUntracked<unsigned long long>("firstTime", 1)->setComment("Time before first event (ns) (for timestamp).");
234  desc.addUntracked<unsigned long long>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)->setComment("Time between consecutive events (ns) (for timestamp).");
235  desc.addUntracked<unsigned int>("eventCreationDelay", 0)->setComment("Real time delay between generation of consecutive events (ms).");
236  desc.addUntracked<unsigned int>("firstEvent", 1)->setComment("Event number of first event to generate.");
237  desc.addUntracked<unsigned int>("firstLuminosityBlock", 1)->setComment("Luminosity block number of first lumi to generate.");
238  desc.addUntracked<unsigned int>("firstRun", 1)->setComment("Run number of first run to generate.");
240  }
241 }
242 
RunNumber_t run() const
Definition: EventID.h:42
void fillEventPrincipal(EventAuxiliary const &aux, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), DelayedReader *reader=0)
static unsigned long long const kNanoSecPerSec
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual boost::shared_ptr< RunAuxiliary > readRunAuxiliary_() override
bool newLumi() const
Definition: InputSource.h:344
virtual boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
virtual void beginLuminosityBlock(LuminosityBlock &) override
unsigned int numberEventsInThisLumi_
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:238
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
Definition: InputSource.h:314
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:199
EventID previous(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:66
EventID next(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:47
virtual size_t fileIndex() const
virtual void endRun(Run &) override
ProducerSourceBase(ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
virtual void beginJob() override
bool newRun() const
Definition: InputSource.h:341
virtual void beginRun(Run &) override
static void fillDescription(ParameterSetDescription &desc)
unsigned int offset(bool)
unsigned long long TimeValue_t
Definition: Timestamp.h:27
virtual void endLuminosityBlock(LuminosityBlock &) override
ItemType state() const
Definition: InputSource.h:317
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:349
void resetEventCached()
Definition: InputSource.h:350
virtual EventPrincipal * readEvent_(EventPrincipal &eventPrincipal) override
static Timestamp const & invalidTimestamp()
Definition: Timestamp.cc:83
static unsigned long long const kAveEventPerSec
virtual void rewind_() override
EventAuxiliary::ExperimentType eType_
virtual bool setRunAndEventInfo(EventID &id, TimeValue_t &time)=0
void commit_(std::vector< BranchID > *previousParentage=0, ParentageID *previousParentageId=0)
Definition: Event.cc:111
unsigned int numberEventsInThisRun_
virtual bool noFiles() const
virtual void produce(Event &e)=0
EventID nextRunFirstEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:56
void advanceToNext(EventID &eventID, TimeValue_t &time)
static void fillDescription(ParameterSetDescription &desc)
Definition: InputSource.cc:134
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
ModuleDescription const & moduleDescription() const
Accessor for &#39;module&#39; description.
Definition: InputSource.h:190
virtual ItemType getNextItemType() override
virtual void skip(int offset) override
EventID previousRunLastEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:59
void retreatToPrevious(EventID &eventID, TimeValue_t &time)
virtual void initialize(EventID &id, TimeValue_t &time, TimeValue_t &interval)
Definition: Run.h:36
bool eventCached() const
Definition: InputSource.h:347