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 <cerrno>
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 
59  void
63  eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry());
64  Event e(eventPrincipal, moduleDescription(), nullptr);
65  produce(e);
66  e.commit_();
68  }
69 
70  void
72  EventID oldEventID = eventID_;
73  for(; offset < 0; ++offset) {
75  }
76  for(; offset > 0; --offset) {
78  }
79  if(eventID_.run() != oldEventID.run()) {
80  // New Run
81  setNewRun();
82  setNewLumi();
83  }
84  if (eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
85  // New Lumi
86  setNewLumi();
87  }
88  }
89 
90  void
92  // initialize cannot be called from the constructor, because it is a virtual function
93  // that needs to be invoked from a derived class if the derived class overrides it.
95  }
96 
97  void
99  }
100 
101  void
103  }
104 
105  void
107  }
108 
109  void
111  }
112 
113  void
115  }
116 
117  void
123  setNewRun();
124  setNewLumi();
125  }
126 
129  if(state() == IsInvalid) {
130  return noFiles() ? IsStop : IsFile;
131  }
132  if (newRun()) {
133  return IsRun;
134  }
135  if (newLumi()) {
136  return IsLumi;
137  }
138  if(eventCached()) {
139  return IsEvent;
140  }
141  EventID oldEventID = eventID_;
143  if (eventCreationDelay_ > 0) {usleep(eventCreationDelay_);}
144  size_t index = fileIndex();
145  bool another = setRunAndEventInfo(eventID_, presentTime_);
146  if(!another) {
147  return IsStop;
148  }
149  bool newFile = (fileIndex() > index);
150  setEventCached();
151  if(newRun() || eventID_.run() != oldEventID.run()) {
152  // New Run
153  setNewRun();
154  setNewLumi();
155  return newFile ? IsFile : IsRun;
156  }
157  if (processingMode() == Runs) {
158  return newFile ? IsFile : IsRun;
159  }
160  if (processingMode() == RunsAndLumis) {
161  return newFile ? IsFile : IsLumi;
162  }
163  // Same Run
164  if (newLumi() || eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
165  // New Lumi
166  setNewLumi();
167  return newFile ? IsFile : IsLumi;
168  }
169  return newFile ? IsFile : IsEvent;
170  }
171 
172  void
175  // same run
178  // new lumi
179  eventID = eventID.next(eventID.luminosityBlock() + 1);
181  } else {
182  eventID = eventID.next(eventID.luminosityBlock());
184  }
185  } else {
186  // new run
187  eventID = eventID.nextRunFirstEvent(origEventID_.luminosityBlock());
190  }
191  time += timeBetweenEvents_;
192  }
193 
194  void
196  if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
197  // same run
199  eventID = eventID.previous(eventID.luminosityBlock());
200  if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
201  // new lumi
202  eventID = eventID.previous(eventID.luminosityBlock() - 1);
204  } else {
206  }
207  } else {
208  // new run
210  eventID = EventID(numberEventsInRun_, eventID.luminosityBlock(), eventID.run());
213  }
214  time -= timeBetweenEvents_;
215  }
216 
217  bool
219  return false;
220  }
221 
222  size_t
224  return 0UL;
225  }
226 
227  void
229  desc.addOptionalUntracked<unsigned int>("numberEventsInRun")->setComment("Number of events to generate in each run.");
230  desc.addOptionalUntracked<unsigned int>("numberEventsInLuminosityBlock")->setComment("Number of events to generate in each lumi.");
231  desc.addUntracked<unsigned long long>("firstTime", 1)->setComment("Time before first event (ns) (for timestamp).");
232  desc.addUntracked<unsigned long long>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)->setComment("Time between consecutive events (ns) (for timestamp).");
233  desc.addUntracked<unsigned int>("eventCreationDelay", 0)->setComment("Real time delay between generation of consecutive events (ms).");
234  desc.addUntracked<unsigned int>("firstEvent", 1)->setComment("Event number of first event to generate.");
235  desc.addUntracked<unsigned int>("firstLuminosityBlock", 1)->setComment("Luminosity block number of first lumi to generate.");
236  desc.addUntracked<unsigned int>("firstRun", 1)->setComment("Run number of first run to generate.");
238  }
239 }
240 
RunNumber_t run() const
Definition: EventID.h:42
ProcessHistoryRegistry const & processHistoryRegistry() const
Const accessor for process history registry.
Definition: InputSource.h:171
static unsigned long long const kNanoSecPerSec
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
virtual boost::shared_ptr< RunAuxiliary > readRunAuxiliary_() override
bool newLumi() const
Definition: InputSource.h:376
virtual void readEvent_(EventPrincipal &eventPrincipal) override
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:253
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
Definition: InputSource.h:345
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:214
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:373
virtual void beginRun(Run &) override
static void fillDescription(ParameterSetDescription &desc)
unsigned int offset(bool)
unsigned long long TimeValue_t
Definition: Timestamp.h:28
virtual void endLuminosityBlock(LuminosityBlock &) override
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
ItemType state() const
Definition: InputSource.h:349
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:381
void resetEventCached()
Definition: InputSource.h:382
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:108
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:132
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
ModuleDescription const & moduleDescription() const
Accessor for &#39;module&#39; description.
Definition: InputSource.h:205
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:41
bool eventCached() const
Definition: InputSource.h:379