CMS 3D CMS Logo

ProducerSourceBase.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <cerrno>
5 
18 
19 namespace {
20  void checkFirstLumiForRuns(std::vector<edm::LuminosityBlockID> const& iFirstLumis) {
21  if (iFirstLumis.empty())
22  return;
23 
24  auto previous = iFirstLumis[0].luminosityBlock();
25  for (auto it = iFirstLumis.begin() + 1; it != iFirstLumis.end(); ++it) {
26  if (not(it->luminosityBlock() > previous)) {
28  << "Incorrect ordering of LuminosityBlock numbers in parameter 'firstLuminosityBlockForEachRun'";
29  }
30  }
31  }
32 } // namespace
33 namespace edm {
34  //used for defaults
35  static unsigned long long constexpr kNanoSecPerSec = 1000000000ULL;
36  static unsigned long long constexpr kAveEventPerSec = 200ULL;
37 
39  : PuttableSourceBase(pset, desc),
40  firstLumiForRuns_(
41  pset.getUntrackedParameter<std::vector<edm::LuminosityBlockID>>("firstLuminosityBlockForEachRun")),
42  numberEventsInRun_(pset.getUntrackedParameter<unsigned int>("numberEventsInRun", remainingEvents())),
43  numberEventsInLumi_(
44  pset.getUntrackedParameter<unsigned int>("numberEventsInLuminosityBlock", remainingEvents())),
45  presentTime_(pset.getUntrackedParameter<unsigned long long>("firstTime", 1ULL)), //time in ns
46  origTime_(presentTime_),
47  timeBetweenEvents_(
48  pset.getUntrackedParameter<unsigned long long>("timeBetweenEvents", kNanoSecPerSec / kAveEventPerSec)),
49  eventCreationDelay_(pset.getUntrackedParameter<unsigned int>("eventCreationDelay", 0)),
50  numberEventsInThisRun_(0),
51  numberEventsInThisLumi_(0),
52  zerothEvent_(pset.existsAs<unsigned int>("firstEvent", false)
53  ? pset.getUntrackedParameter<unsigned int>("firstEvent", 1) - 1
54  : pset.getUntrackedParameter<unsigned long long>("firstEvent", 1) - 1),
55  eventID_(pset.getUntrackedParameter<unsigned int>("firstRun", 1),
56  pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 1),
57  zerothEvent_),
58  origEventID_(eventID_),
59  isRealData_(realData),
60  eType_(EventAuxiliary::Undefined) {
62  checkFirstLumiForRuns(firstLumiForRuns_);
63  if (not firstLumiForRuns_.empty()) {
64  numberEventsInRun_ = -1;
66  }
67  }
68 
70 
71  std::shared_ptr<RunAuxiliary> ProducerSourceBase::readRunAuxiliary_() {
73  resetNewRun();
74  return std::make_shared<RunAuxiliary>(eventID_.run(), ts, Timestamp::invalidTimestamp());
75  }
76 
77  std::shared_ptr<LuminosityBlockAuxiliary> ProducerSourceBase::readLuminosityBlockAuxiliary_() {
78  if (processingMode() == Runs)
79  return std::shared_ptr<LuminosityBlockAuxiliary>();
81  resetNewLumi();
82  return std::make_shared<LuminosityBlockAuxiliary>(
84  }
85 
89  eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry());
90  Event e(eventPrincipal, moduleDescription(), nullptr);
91  e.setProducer(this, nullptr);
92  produce(e);
93  e.commit_(std::vector<ProductResolverIndex>());
95  }
96 
98  EventID oldEventID = eventID_;
99  for (; offset < 0; ++offset) {
101  }
102  for (; offset > 0; --offset) {
104  }
105  if (eventID_.run() != oldEventID.run()) {
106  // New Run
107  setNewRun();
108  setNewLumi();
109  }
110  if (eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
111  // New Lumi
112  setNewLumi();
113  }
114  }
115 
118  // Initialize cannot be called from the constructor, because it is a virtual function
119  // that needs to be invoked from a derived class if the derived class overrides it.
121  }
122 
124 
130  setNewRun();
131  setNewLumi();
132  }
133 
135  if (state() == IsInvalid) {
136  return noFiles() ? IsStop : IsFile;
137  }
138  if (newRun()) {
139  return IsRun;
140  }
141  if (newLumi()) {
142  return IsLumi;
143  }
144  if (eventCached()) {
145  return IsEvent;
146  }
147  EventID oldEventID = eventID_;
149  if (eventCreationDelay_ > 0) {
150  usleep(eventCreationDelay_);
151  }
152  size_t index = fileIndex();
154  if (!another) {
155  return IsStop;
156  }
157  bool newFile = (fileIndex() > index);
158  setEventCached();
159  if (newRun() || eventID_.run() != oldEventID.run()) {
160  // New Run
161  setNewRun();
162  setNewLumi();
163  return newFile ? IsFile : IsRun;
164  }
165  if (processingMode() == Runs) {
166  return newFile ? IsFile : IsRun;
167  }
168  if (processingMode() == RunsAndLumis) {
169  return newFile ? IsFile : IsLumi;
170  }
171  // Same Run
172  if (newLumi() || eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
173  // New Lumi
174  setNewLumi();
175  return newFile ? IsFile : IsLumi;
176  }
177  return newFile ? IsFile : IsEvent;
178  }
179 
182  // same run
185  // new lumi
186  eventID = eventID.next(eventID.luminosityBlock() + 1);
188  if (not firstLumiForRuns_.empty()) {
189  auto run = runForLumi(eventID.luminosityBlock());
190  if (run != eventID.run()) {
192  eventID = eventID.nextRunFirstEvent(eventID_.luminosityBlock());
193 
194  eventID = EventID(run, eventID.luminosityBlock(), eventID.event());
195  }
196  }
197  } else {
198  eventID = eventID.next(eventID.luminosityBlock());
200  }
201  } else {
202  // new run
203  eventID = eventID.nextRunFirstEvent(origEventID_.luminosityBlock());
206  }
207  time += timeBetweenEvents_;
208  }
209 
211  if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
212  // same run
214  eventID = eventID.previous(eventID.luminosityBlock());
215  if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
216  // new lumi
217  eventID = eventID.previous(eventID.luminosityBlock() - 1);
219 
220  if (not firstLumiForRuns_.empty()) {
221  auto run = runForLumi(eventID.luminosityBlock());
222  if (run != eventID.run()) {
223  eventID = eventID.previousRunLastEvent(eventID_.luminosityBlock());
224 
225  eventID = EventID(run, eventID.luminosityBlock(), eventID.event());
226  }
227  }
228  } else {
230  }
231  } else {
232  // new run
233  assert(numberEventsInLumi_ != 0);
235  eventID = EventID(numberEventsInRun_, eventID.luminosityBlock(), eventID.run());
238  }
239  time -= timeBetweenEvents_;
240  }
241 
243  auto it = std::find_if(firstLumiForRuns_.rbegin(), firstLumiForRuns_.rend(), [iLumi](auto const& iV) {
244  return iV.luminosityBlock() <= iLumi;
245  });
246  if (it == firstLumiForRuns_.rend()) {
247  //use first since we are off the end
248  return firstLumiForRuns_[0].run();
249  }
250  return it->run();
251  }
252 
253  bool ProducerSourceBase::noFiles() const { return false; }
254 
255  size_t ProducerSourceBase::fileIndex() const { return 0UL; }
256 
258  desc.addOptionalUntracked<unsigned int>("numberEventsInRun")
259  ->setComment("Number of events to generate in each run.");
260  desc.addOptionalUntracked<unsigned int>("numberEventsInLuminosityBlock")
261  ->setComment("Number of events to generate in each lumi.");
262  desc.addUntracked<unsigned long long>("firstTime", 1)->setComment("Time before first event (ns) (for timestamp).");
263  desc.addUntracked<unsigned long long>("timeBetweenEvents", kNanoSecPerSec / kAveEventPerSec)
264  ->setComment("Time between consecutive events (ns) (for timestamp).");
265  desc.addUntracked<unsigned int>("eventCreationDelay", 0)
266  ->setComment("Real time delay between generation of consecutive events (ms).");
267 
268  desc.addNode(edm::ParameterDescription<unsigned int>("firstEvent", 1U, false) xor
269  edm::ParameterDescription<unsigned long long>("firstEvent", 1ULL, false))
270  ->setComment(
271  "'firstEvent' is an XOR group because it can have type uint32 or uint64, default:1\n"
272  "Event number of first event to generate.");
273 
274  desc.addUntracked<unsigned int>("firstLuminosityBlock", 1)
275  ->setComment("Luminosity block number of first lumi to generate.");
276  desc.addUntracked<unsigned int>("firstRun", 1)->setComment("Run number of first run to generate.");
277  desc.addUntracked<std::vector<edm::LuminosityBlockID>>("firstLuminosityBlockForEachRun", {})
278  ->setComment(
279  "When the source makes a new LuminosityBlock, this list is checked to see what Run number should be used. "
280  "The LuminosityBlock numbers are required to be in ascending order.");
282  }
283 } // namespace edm
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:155
void setComment(std::string const &value)
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
std::shared_ptr< RunAuxiliary > readRunAuxiliary_() override
EventNumber_t const zerothEvent_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
bool newLumi() const
Definition: InputSource.h:353
void readEvent_(EventPrincipal &eventPrincipal) override
unsigned int numberEventsInThisLumi_
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:233
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
Definition: InputSource.h:324
RunNumber_t run() const
~ProducerSourceBase() noexcept(false) override
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
ItemType getNextItemType() final
unsigned int LuminosityBlockNumber_t
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:204
EventID previous(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:63
static unsigned long long kAveEventPerSec
EventID next(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:44
std::vector< edm::LuminosityBlockID > firstLumiForRuns_
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:350
void commit_(std::vector< edm::ProductResolverIndex > const &iShouldPut, ParentageID *previousParentageId=0)
Definition: Event.cc:137
static unsigned long long kNanoSecPerSec
static void fillDescription(ParameterSetDescription &desc)
unsigned long long TimeValue_t
Definition: Timestamp.h:28
RunNumber_t runForLumi(LuminosityBlockNumber_t) const
ItemType state() const
Definition: InputSource.h:328
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:358
void resetEventCached()
Definition: InputSource.h:359
#define noexcept
void setProducer(ProducerBase const *iProd, std::vector< BranchID > *previousParentage, std::vector< BranchID > *gotBranchIDsFromAcquire=0)
Definition: Event.cc:55
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:115
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
ModuleDescription const & moduleDescription() const
Accessor for &#39;module&#39; description.
Definition: InputSource.h:198
unsigned int RunNumber_t
void skip(int offset) override
EventID previousRunLastEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:56
void retreatToPrevious(EventID &eventID, TimeValue_t &time)
#define constexpr
virtual void initialize(EventID &id, TimeValue_t &time, TimeValue_t &interval)
bool eventCached() const
Definition: InputSource.h:356