CMS 3D CMS Logo

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.existsAs<unsigned int>("firstEvent", false) ? pset.getUntrackedParameter<unsigned int>("firstEvent", 1) - 1 :
31  pset.getUntrackedParameter<unsigned long long>("firstEvent", 1) - 1),
32  eventID_(pset.getUntrackedParameter<unsigned int>("firstRun", 1), pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 1), zerothEvent_),
33  origEventID_(eventID_),
34  isRealData_(realData),
35  eType_(EventAuxiliary::Undefined) {
36 
38  // We need to map this string to the EventAuxiliary::ExperimentType enumeration
39  // std::string eType = pset.getUntrackedParameter<std::string>("experimentType", std::string("Any"))),
40  }
41 
43  }
44 
45  std::shared_ptr<RunAuxiliary>
48  resetNewRun();
49  return std::make_shared<RunAuxiliary>(eventID_.run(), ts, Timestamp::invalidTimestamp());
50  }
51 
52  std::shared_ptr<LuminosityBlockAuxiliary>
54  if (processingMode() == Runs) return std::shared_ptr<LuminosityBlockAuxiliary>();
56  resetNewLumi();
57  return std::make_shared<LuminosityBlockAuxiliary>(eventID_.run(), eventID_.luminosityBlock(), ts, Timestamp::invalidTimestamp());
58  }
59 
60  void
64  eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry());
65  Event e(eventPrincipal, moduleDescription(), nullptr);
66  produce(e);
67  e.commit_(std::vector<ProductResolverIndex>());
69  }
70 
71  void
73  EventID oldEventID = eventID_;
74  for(; offset < 0; ++offset) {
76  }
77  for(; offset > 0; --offset) {
79  }
80  if(eventID_.run() != oldEventID.run()) {
81  // New Run
82  setNewRun();
83  setNewLumi();
84  }
85  if (eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
86  // New Lumi
87  setNewLumi();
88  }
89  }
90 
91  void
93  // initialize cannot be called from the constructor, because it is a virtual function
94  // that needs to be invoked from a derived class if the derived class overrides it.
96  }
97 
98  void
100  }
101 
102  void
104  }
105 
106  void
108  }
109 
110  void
112  }
113 
114  void
116  }
117 
118  void
124  setNewRun();
125  setNewLumi();
126  }
127 
130  if(state() == IsInvalid) {
131  return noFiles() ? IsStop : IsFile;
132  }
133  if (newRun()) {
134  return IsRun;
135  }
136  if (newLumi()) {
137  return IsLumi;
138  }
139  if(eventCached()) {
140  return IsEvent;
141  }
142  EventID oldEventID = eventID_;
144  if (eventCreationDelay_ > 0) {usleep(eventCreationDelay_);}
145  size_t index = fileIndex();
147  if(!another) {
148  return IsStop;
149  }
150  bool newFile = (fileIndex() > index);
151  setEventCached();
152  if(newRun() || eventID_.run() != oldEventID.run()) {
153  // New Run
154  setNewRun();
155  setNewLumi();
156  return newFile ? IsFile : IsRun;
157  }
158  if (processingMode() == Runs) {
159  return newFile ? IsFile : IsRun;
160  }
161  if (processingMode() == RunsAndLumis) {
162  return newFile ? IsFile : IsLumi;
163  }
164  // Same Run
165  if (newLumi() || eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
166  // New Lumi
167  setNewLumi();
168  return newFile ? IsFile : IsLumi;
169  }
170  return newFile ? IsFile : IsEvent;
171  }
172 
173  void
176  // same run
179  // new lumi
180  eventID = eventID.next(eventID.luminosityBlock() + 1);
182  } else {
183  eventID = eventID.next(eventID.luminosityBlock());
185  }
186  } else {
187  // new run
188  eventID = eventID.nextRunFirstEvent(origEventID_.luminosityBlock());
191  }
192  time += timeBetweenEvents_;
193  }
194 
195  void
197  if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
198  // same run
200  eventID = eventID.previous(eventID.luminosityBlock());
201  if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
202  // new lumi
203  eventID = eventID.previous(eventID.luminosityBlock() - 1);
205  } else {
207  }
208  } else {
209  // new run
210  assert(numberEventsInLumi_ != 0);
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 
237  desc.addNode( edm::ParameterDescription<unsigned int>("firstEvent", 1U, false) xor
238  edm::ParameterDescription<unsigned long long>("firstEvent", 1ULL, false))
239  ->setComment("'firstEvent' is an XOR group because it can have type uint32 or uint64, default:1\n"
240  "Event number of first event to generate.");
241 
242  desc.addUntracked<unsigned int>("firstLuminosityBlock", 1)->setComment("Luminosity block number of first lumi to generate.");
243  desc.addUntracked<unsigned int>("firstRun", 1)->setComment("Run number of first run to generate.");
245  }
246 }
247 
RunNumber_t run() const
Definition: EventID.h:39
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:176
void setComment(std::string const &value)
virtual std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
static unsigned long long const kNanoSecPerSec
virtual 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:383
virtual void readEvent_(EventPrincipal &eventPrincipal) override
virtual void beginLuminosityBlock(LuminosityBlock &) override
virtual ~ProducerSourceBase() noexcept(false)
unsigned int numberEventsInThisLumi_
#define noexcept
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:258
void commit_(std::vector< edm::ProductResolverIndex > const &iShouldPut, std::vector< BranchID > *previousParentage=0, ParentageID *previousParentageId=0)
Definition: Event.cc:123
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
Definition: InputSource.h:354
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:219
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
virtual void endRun(Run &) override
ProducerSourceBase(ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
virtual void beginJob() override
bool newRun() const
Definition: InputSource.h:380
virtual void beginRun(Run &) override
static void fillDescription(ParameterSetDescription &desc)
unsigned long long TimeValue_t
Definition: Timestamp.h:28
virtual void endLuminosityBlock(LuminosityBlock &) override
virtual ItemType getNextItemType() override final
ItemType state() const
Definition: InputSource.h:358
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:388
void resetEventCached()
Definition: InputSource.h:389
static unsigned long long const kAveEventPerSec
virtual void rewind_() override
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:127
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
ModuleDescription const & moduleDescription() const
Accessor for &#39;module&#39; description.
Definition: InputSource.h:213
virtual 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)
Definition: Run.h:42
bool eventCached() const
Definition: InputSource.h:386