CMS 3D CMS Logo

IDGeneratorSourceBase.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <cerrno>
5 
18 
20 
21 namespace {
22  void checkFirstLumiForRuns(std::vector<edm::LuminosityBlockID> const& iFirstLumis) {
23  if (iFirstLumis.empty())
24  return;
25 
26  auto previous = iFirstLumis[0].luminosityBlock();
27  for (auto it = iFirstLumis.begin() + 1; it != iFirstLumis.end(); ++it) {
28  if (not(it->luminosityBlock() > previous)) {
30  << "Incorrect ordering of LuminosityBlock numbers in parameter 'firstLuminosityBlockForEachRun'";
31  }
32  }
33  }
34 } // namespace
35 namespace edm {
36  //used for defaults
37  static unsigned long long constexpr kNanoSecPerSec = 1000000000ULL;
38  static unsigned long long constexpr kAveEventPerSec = 200ULL;
39 
40  template <typename BASE>
42  InputSourceDescription const& desc,
43  bool realData)
44  : BASE(pset, desc),
45  firstLumiForRuns_(
46  pset.getUntrackedParameter<std::vector<edm::LuminosityBlockID>>("firstLuminosityBlockForEachRun")),
47  numberEventsInRun_(pset.getUntrackedParameter<unsigned int>("numberEventsInRun", BASE::remainingEvents())),
48  numberEventsInLumi_(
49  pset.getUntrackedParameter<unsigned int>("numberEventsInLuminosityBlock", BASE::remainingEvents())),
50  presentTime_(pset.getUntrackedParameter<unsigned long long>("firstTime", 1ULL)), //time in ns
51  origTime_(presentTime_),
52  timeBetweenEvents_(
53  pset.getUntrackedParameter<unsigned long long>("timeBetweenEvents", kNanoSecPerSec / kAveEventPerSec)),
54  eventCreationDelay_(pset.getUntrackedParameter<unsigned int>("eventCreationDelay", 0)),
55  numberEventsInThisRun_(0),
56  numberEventsInThisLumi_(0),
57  zerothEvent_(pset.existsAs<unsigned int>("firstEvent", false)
58  ? pset.getUntrackedParameter<unsigned int>("firstEvent", 1) - 1
59  : pset.getUntrackedParameter<unsigned long long>("firstEvent", 1) - 1),
60  eventID_(pset.getUntrackedParameter<unsigned int>("firstRun", 1),
61  pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 1),
62  zerothEvent_),
63  origEventID_(eventID_),
64  isRealData_(realData),
65  eType_(EventAuxiliary::Undefined) {
66  BASE::setTimestamp(Timestamp(presentTime_));
67  checkFirstLumiForRuns(firstLumiForRuns_);
68  if (not firstLumiForRuns_.empty()) {
69  numberEventsInRun_ = -1;
71  }
72  }
73 
74  template <typename BASE>
76 
77  template <typename BASE>
78  std::shared_ptr<RunAuxiliary> IDGeneratorSourceBase<BASE>::readRunAuxiliary_() {
80  BASE::resetNewRun();
81  return std::make_shared<RunAuxiliary>(eventID_.run(), ts, Timestamp::invalidTimestamp());
82  }
83 
84  template <typename BASE>
85  std::shared_ptr<LuminosityBlockAuxiliary> IDGeneratorSourceBase<BASE>::readLuminosityBlockAuxiliary_() {
86  if (BASE::processingMode() == BASE::Runs)
87  return std::shared_ptr<LuminosityBlockAuxiliary>();
89  BASE::resetNewLumi();
90  return std::make_shared<LuminosityBlockAuxiliary>(
92  }
93 
94  template <typename BASE>
96  EventID oldEventID = eventID_;
97  for (; offset < 0; ++offset) {
99  }
100  for (; offset > 0; --offset) {
102  }
103  if (eventID_.run() != oldEventID.run()) {
104  // New Run
105  BASE::setNewRun();
106  BASE::setNewLumi();
107  }
108  if (eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
109  // New Lumi
110  BASE::setNewLumi();
111  }
112  }
113 
114  template <typename BASE>
116  BASE::beginJob();
117  // Initialize cannot be called from the constructor, because it is a virtual function
118  // that needs to be invoked from a derived class if the derived class overrides it.
120  }
121 
122  template <typename BASE>
124 
125  template <typename BASE>
131  BASE::setNewRun();
132  BASE::setNewLumi();
133  }
134 
135  template <typename BASE>
137  if (BASE::state() == BASE::IsInvalid) {
138  return noFiles() ? BASE::IsStop : BASE::IsFile;
139  }
140  if (BASE::newRun()) {
141  return BASE::IsRun;
142  }
143  if (BASE::newLumi()) {
144  return BASE::IsLumi;
145  }
146  if (BASE::eventCached()) {
147  return BASE::IsEvent;
148  }
149  EventID oldEventID = eventID_;
151  if (eventCreationDelay_ > 0) {
152  usleep(eventCreationDelay_);
153  }
154  size_t index = fileIndex();
156  if (!another) {
157  return BASE::IsStop;
158  }
159  bool newFile = (fileIndex() > index);
160  BASE::setEventCached();
161  if (BASE::newRun() || eventID_.run() != oldEventID.run()) {
162  // New Run
163  BASE::setNewRun();
164  BASE::setNewLumi();
165  return newFile ? BASE::IsFile : BASE::IsRun;
166  }
167  if (BASE::processingMode() == BASE::Runs) {
168  return newFile ? BASE::IsFile : BASE::IsRun;
169  }
170  if (BASE::processingMode() == BASE::RunsAndLumis) {
171  return newFile ? BASE::IsFile : BASE::IsLumi;
172  }
173  // Same Run
174  if (BASE::newLumi() || eventID_.luminosityBlock() != oldEventID.luminosityBlock()) {
175  // New Lumi
176  BASE::setNewLumi();
177  return newFile ? BASE::IsFile : BASE::IsLumi;
178  }
179  return newFile ? BASE::IsFile : BASE::IsEvent;
180  }
181 
182  template <typename BASE>
185  // same run
188  // new lumi
189  eventID = eventID.next(eventID.luminosityBlock() + 1);
191  if (not firstLumiForRuns_.empty()) {
192  auto run = runForLumi(eventID.luminosityBlock());
193  if (run != eventID.run()) {
195  eventID = eventID.nextRunFirstEvent(eventID_.luminosityBlock());
196 
197  eventID = EventID(run, eventID.luminosityBlock(), eventID.event());
198  }
199  }
200  } else {
201  eventID = eventID.next(eventID.luminosityBlock());
203  }
204  } else {
205  // new run
206  eventID = eventID.nextRunFirstEvent(origEventID_.luminosityBlock());
209  }
210  time += timeBetweenEvents_;
211  }
212 
213  template <typename BASE>
215  if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
216  // same run
218  eventID = eventID.previous(eventID.luminosityBlock());
219  if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
220  // new lumi
221  eventID = eventID.previous(eventID.luminosityBlock() - 1);
223 
224  if (not firstLumiForRuns_.empty()) {
225  auto run = runForLumi(eventID.luminosityBlock());
226  if (run != eventID.run()) {
227  eventID = eventID.previousRunLastEvent(eventID_.luminosityBlock());
228 
229  eventID = EventID(run, eventID.luminosityBlock(), eventID.event());
230  }
231  }
232  } else {
234  }
235  } else {
236  // new run
237  assert(numberEventsInLumi_ != 0);
239  eventID = EventID(numberEventsInRun_, eventID.luminosityBlock(), eventID.run());
242  }
243  time -= timeBetweenEvents_;
244  }
245 
246  template <typename BASE>
248  auto it = std::find_if(firstLumiForRuns_.rbegin(), firstLumiForRuns_.rend(), [iLumi](auto const& iV) {
249  return iV.luminosityBlock() <= iLumi;
250  });
251  if (it == firstLumiForRuns_.rend()) {
252  //use first since we are off the end
253  return firstLumiForRuns_[0].run();
254  }
255  return it->run();
256  }
257 
258  template <typename BASE>
260  return false;
261  }
262 
263  template <typename BASE>
265  return 0UL;
266  }
267 
268  template <typename BASE>
270  desc.addOptionalUntracked<unsigned int>("numberEventsInRun")
271  ->setComment("Number of events to generate in each run.");
272  desc.addOptionalUntracked<unsigned int>("numberEventsInLuminosityBlock")
273  ->setComment("Number of events to generate in each lumi.");
274  desc.addUntracked<unsigned long long>("firstTime", 1)->setComment("Time before first event (ns) (for timestamp).");
275  desc.addUntracked<unsigned long long>("timeBetweenEvents", kNanoSecPerSec / kAveEventPerSec)
276  ->setComment("Time between consecutive events (ns) (for timestamp).");
277  desc.addUntracked<unsigned int>("eventCreationDelay", 0)
278  ->setComment("Real time delay between generation of consecutive events (ms).");
279 
280  desc.addNode(edm::ParameterDescription<unsigned int>("firstEvent", 1U, false) xor
281  edm::ParameterDescription<unsigned long long>("firstEvent", 1ULL, false))
282  ->setComment(
283  "'firstEvent' is an XOR group because it can have type uint32 or uint64, default:1\n"
284  "Event number of first event to generate.");
285 
286  desc.addUntracked<unsigned int>("firstLuminosityBlock", 1)
287  ->setComment("Luminosity block number of first lumi to generate.");
288  desc.addUntracked<unsigned int>("firstRun", 1)->setComment("Run number of first run to generate.");
289  desc.addUntracked<std::vector<edm::LuminosityBlockID>>("firstLuminosityBlockForEachRun", {})
290  ->setComment(
291  "When the source makes a new LuminosityBlock, this list is checked to see what Run number should be used. "
292  "The LuminosityBlock numbers are required to be in ascending order.");
293  BASE::fillDescription(desc);
294  }
295 
297  template class IDGeneratorSourceBase<InputSource>;
298 } // namespace edm
RunNumber_t run() const
Definition: EventID.h:38
virtual void initialize(EventID &id, TimeValue_t &time, TimeValue_t &interval)
EventNumber_t event() const
Definition: EventID.h:40
void setComment(std::string const &value)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static Timestamp invalidTimestamp()
Definition: Timestamp.h:82
virtual size_t fileIndex() const
IDGeneratorSourceBase(ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
BASE::ItemType getNextItemType() final
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
unsigned int LuminosityBlockNumber_t
void beginJob()
Definition: Breakpoints.cc:14
EventID previous(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:58
virtual bool setRunAndEventInfo(EventID &id, TimeValue_t &time, EventAuxiliary::ExperimentType &etype)=0
static unsigned long long kAveEventPerSec
EventID next(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:43
EventNumber_t const zerothEvent_
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
~IDGeneratorSourceBase()(false) override
void retreatToPrevious(EventID &eventID, TimeValue_t &time)
EventID const & eventID() const
static unsigned long long kNanoSecPerSec
RunNumber_t runForLumi(LuminosityBlockNumber_t) const
unsigned long long TimeValue_t
Definition: Timestamp.h:28
std::shared_ptr< RunAuxiliary > readRunAuxiliary_() override
#define noexcept
static void fillDescription(ParameterSetDescription &desc)
void advanceToNext(EventID &eventID, TimeValue_t &time)
std::vector< edm::LuminosityBlockID > firstLumiForRuns_
HLT enums.
EventID nextRunFirstEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:50
void skip(int offset) override
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
unsigned int RunNumber_t
EventID previousRunLastEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:51
#define constexpr
EventAuxiliary::ExperimentType eType_