CMS 3D CMS Logo

ProducerSourceBase.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <cerrno>
5 
18 
19 namespace edm {
20  //used for defaults
21  static unsigned long long const kNanoSecPerSec = 1000000000ULL;
22  static unsigned long long const kAveEventPerSec = 200ULL;
23 
25  InputSourceDescription const& desc, bool realData) :
26  PuttableSourceBase(pset, desc),
27  numberEventsInRun_(pset.getUntrackedParameter<unsigned int>("numberEventsInRun", remainingEvents())),
28  numberEventsInLumi_(pset.getUntrackedParameter<unsigned int>("numberEventsInLuminosityBlock", remainingEvents())),
29  presentTime_(pset.getUntrackedParameter<unsigned long long>("firstTime", 1ULL)), //time in ns
30  origTime_(presentTime_),
31  timeBetweenEvents_(pset.getUntrackedParameter<unsigned long long>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)),
32  eventCreationDelay_(pset.getUntrackedParameter<unsigned int>("eventCreationDelay", 0)),
33  numberEventsInThisRun_(0),
34  numberEventsInThisLumi_(0),
35  zerothEvent_(pset.existsAs<unsigned int>("firstEvent", false) ? pset.getUntrackedParameter<unsigned int>("firstEvent", 1) - 1 :
36  pset.getUntrackedParameter<unsigned long long>("firstEvent", 1) - 1),
37  eventID_(pset.getUntrackedParameter<unsigned int>("firstRun", 1), pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 1), zerothEvent_),
38  origEventID_(eventID_),
39  isRealData_(realData),
40  eType_(EventAuxiliary::Undefined) {
41 
43  // We need to map this string to the EventAuxiliary::ExperimentType enumeration
44  // std::string eType = pset.getUntrackedParameter<std::string>("experimentType", std::string("Any"))),
45  }
46 
48  }
49 
50 
51  std::shared_ptr<RunAuxiliary>
54  resetNewRun();
55  return std::make_shared<RunAuxiliary>(eventID_.run(), ts, Timestamp::invalidTimestamp());
56  }
57 
58  std::shared_ptr<LuminosityBlockAuxiliary>
60  if (processingMode() == Runs) return std::shared_ptr<LuminosityBlockAuxiliary>();
62  resetNewLumi();
63  return std::make_shared<LuminosityBlockAuxiliary>(eventID_.run(), eventID_.luminosityBlock(), ts, Timestamp::invalidTimestamp());
64  }
65 
66  void
70  eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry());
71  Event e(eventPrincipal, moduleDescription(), nullptr);
72  e.setProducer(this,nullptr);
73  produce(e);
74  e.commit_(std::vector<ProductResolverIndex>());
76  }
77 
78  void
80  EventID oldEventID = eventID_;
81  for(; offset < 0; ++offset) {
83  }
84  for(; offset > 0; --offset) {
86  }
87  if(eventID_.run() != oldEventID.run()) {
88  // New Run
89  setNewRun();
90  setNewLumi();
91  }
92  if (eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
93  // New Lumi
94  setNewLumi();
95  }
96  }
97 
98  void
101  // Initialize cannot be called from the constructor, because it is a virtual function
102  // that needs to be invoked from a derived class if the derived class overrides it.
104  }
105 
106  void
108  }
109 
110  void
116  setNewRun();
117  setNewLumi();
118  }
119 
122  if(state() == IsInvalid) {
123  return noFiles() ? IsStop : IsFile;
124  }
125  if (newRun()) {
126  return IsRun;
127  }
128  if (newLumi()) {
129  return IsLumi;
130  }
131  if(eventCached()) {
132  return IsEvent;
133  }
134  EventID oldEventID = eventID_;
136  if (eventCreationDelay_ > 0) {usleep(eventCreationDelay_);}
137  size_t index = fileIndex();
139  if(!another) {
140  return IsStop;
141  }
142  bool newFile = (fileIndex() > index);
143  setEventCached();
144  if(newRun() || eventID_.run() != oldEventID.run()) {
145  // New Run
146  setNewRun();
147  setNewLumi();
148  return newFile ? IsFile : IsRun;
149  }
150  if (processingMode() == Runs) {
151  return newFile ? IsFile : IsRun;
152  }
153  if (processingMode() == RunsAndLumis) {
154  return newFile ? IsFile : IsLumi;
155  }
156  // Same Run
157  if (newLumi() || eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
158  // New Lumi
159  setNewLumi();
160  return newFile ? IsFile : IsLumi;
161  }
162  return newFile ? IsFile : IsEvent;
163  }
164 
165  void
168  // same run
171  // new lumi
172  eventID = eventID.next(eventID.luminosityBlock() + 1);
174  } else {
175  eventID = eventID.next(eventID.luminosityBlock());
177  }
178  } else {
179  // new run
180  eventID = eventID.nextRunFirstEvent(origEventID_.luminosityBlock());
183  }
184  time += timeBetweenEvents_;
185  }
186 
187  void
189  if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
190  // same run
192  eventID = eventID.previous(eventID.luminosityBlock());
193  if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
194  // new lumi
195  eventID = eventID.previous(eventID.luminosityBlock() - 1);
197  } else {
199  }
200  } else {
201  // new run
202  assert(numberEventsInLumi_ != 0);
204  eventID = EventID(numberEventsInRun_, eventID.luminosityBlock(), eventID.run());
207  }
208  time -= timeBetweenEvents_;
209  }
210 
211  bool
213  return false;
214  }
215 
216  size_t
218  return 0UL;
219  }
220 
221  void
223  desc.addOptionalUntracked<unsigned int>("numberEventsInRun")->setComment("Number of events to generate in each run.");
224  desc.addOptionalUntracked<unsigned int>("numberEventsInLuminosityBlock")->setComment("Number of events to generate in each lumi.");
225  desc.addUntracked<unsigned long long>("firstTime", 1)->setComment("Time before first event (ns) (for timestamp).");
226  desc.addUntracked<unsigned long long>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)->setComment("Time between consecutive events (ns) (for timestamp).");
227  desc.addUntracked<unsigned int>("eventCreationDelay", 0)->setComment("Real time delay between generation of consecutive events (ms).");
228 
229  desc.addNode( edm::ParameterDescription<unsigned int>("firstEvent", 1U, false) xor
230  edm::ParameterDescription<unsigned long long>("firstEvent", 1ULL, false))
231  ->setComment("'firstEvent' is an XOR group because it can have type uint32 or uint64, default:1\n"
232  "Event number of first event to generate.");
233 
234  desc.addUntracked<unsigned int>("firstLuminosityBlock", 1)->setComment("Luminosity block number of first lumi to generate.");
235  desc.addUntracked<unsigned int>("firstRun", 1)->setComment("Run number of first run to generate.");
237  }
238 }
239 
RunNumber_t run() const
Definition: EventID.h:39
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:166
void setComment(std::string const &value)
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
static unsigned long long const kNanoSecPerSec
std::shared_ptr< RunAuxiliary > readRunAuxiliary_() override
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
bool newLumi() const
Definition: InputSource.h:366
void readEvent_(EventPrincipal &eventPrincipal) override
unsigned int numberEventsInThisLumi_
#define noexcept
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:244
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
Definition: InputSource.h:337
~ProducerSourceBase() noexcept(false) override
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
ItemType getNextItemType() final
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:209
EventID previous(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:63
EventID next(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:44
virtual size_t fileIndex() const
virtual bool setRunAndEventInfo(EventID &id, TimeValue_t &time, EventAuxiliary::ExperimentType &etype)=0
ProducerSourceBase(ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
bool newRun() const
Definition: InputSource.h:363
void commit_(std::vector< edm::ProductResolverIndex > const &iShouldPut, ParentageID *previousParentageId=0)
Definition: Event.cc:171
static void fillDescription(ParameterSetDescription &desc)
unsigned long long TimeValue_t
Definition: Timestamp.h:28
ItemType state() const
Definition: InputSource.h:341
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:371
void resetEventCached()
Definition: InputSource.h:372
static unsigned long long const kAveEventPerSec
void setProducer(ProducerBase const *iProd, std::vector< BranchID > *previousParentage, std::vector< BranchID > *gotBranchIDsFromAcquire=0)
Definition: Event.cc:66
EventAuxiliary::ExperimentType eType_
unsigned int numberEventsInThisRun_
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
HLT enums.
EventID const & eventID() const
virtual bool noFiles() const
virtual void produce(Event &e)=0
EventID nextRunFirstEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:53
void advanceToNext(EventID &eventID, TimeValue_t &time)
static void fillDescription(ParameterSetDescription &desc)
Definition: InputSource.cc:122
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
ModuleDescription const & moduleDescription() const
Accessor for &#39;module&#39; description.
Definition: InputSource.h:203
void skip(int offset) override
EventID previousRunLastEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:56
void retreatToPrevious(EventID &eventID, TimeValue_t &time)
virtual void initialize(EventID &id, TimeValue_t &time, TimeValue_t &interval)
bool eventCached() const
Definition: InputSource.h:369