22 void checkFirstLumiForRuns(std::vector<edm::LuminosityBlockID>
const& iFirstLumis) {
23 if (iFirstLumis.empty())
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'";
40 template <
typename BASE>
47 numberEventsInRun_(
pset.getUntrackedParameter<unsigned
int>(
"numberEventsInRun", BASE::remainingEvents())),
49 pset.getUntrackedParameter<unsigned
int>(
"numberEventsInLuminosityBlock", BASE::remainingEvents())),
50 presentTime_(
pset.getUntrackedParameter<unsigned long long>(
"firstTime", 1ULL)),
51 origTime_(presentTime_),
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),
63 origEventID_(eventID_),
64 isRealData_(realData),
66 BASE::setTimestamp(
Timestamp(presentTime_));
67 checkFirstLumiForRuns(firstLumiForRuns_);
68 if (not firstLumiForRuns_.empty()) {
69 numberEventsInRun_ = -1;
70 eventID_ =
EventID(runForLumi(eventID_.luminosityBlock()), eventID_.luminosityBlock(), zerothEvent_);
74 template <
typename BASE>
77 template <
typename BASE>
81 return std::make_shared<RunAuxiliary>(eventID_.run(), ts, Timestamp::invalidTimestamp());
84 template <
typename BASE>
87 return std::shared_ptr<LuminosityBlockAuxiliary>();
90 return std::make_shared<LuminosityBlockAuxiliary>(
91 eventID_.run(), eventID_.luminosityBlock(), ts, Timestamp::invalidTimestamp());
94 template <
typename BASE>
98 retreatToPrevious(eventID_, presentTime_);
101 advanceToNext(eventID_, presentTime_);
103 if (eventID_.run() != oldEventID.
run()) {
114 template <
typename BASE>
119 initialize(eventID_, presentTime_, timeBetweenEvents_);
122 template <
typename BASE>
125 template <
typename BASE>
127 presentTime_ = origTime_;
128 eventID_ = origEventID_;
129 numberEventsInThisRun_ = 0;
130 numberEventsInThisLumi_ = 0;
135 template <
typename BASE>
138 return noFiles() ? BASE::IsStop : BASE::IsFile;
140 if (BASE::newRun()) {
143 if (BASE::newLumi()) {
146 if (BASE::eventCached()) {
147 return BASE::IsEvent;
150 advanceToNext(eventID_, presentTime_);
151 if (eventCreationDelay_ > 0) {
152 usleep(eventCreationDelay_);
154 size_t index = fileIndex();
155 bool another = setRunAndEventInfo(eventID_, presentTime_, eType_);
159 bool newFile = (fileIndex() >
index);
160 BASE::setEventCached();
161 if (BASE::newRun() || eventID_.run() != oldEventID.
run()) {
165 return newFile ? BASE::IsFile : BASE::IsRun;
168 if (BASE::newLumi() || eventID_.luminosityBlock() != oldEventID.
luminosityBlock()) {
171 return newFile ? BASE::IsFile : BASE::IsLumi;
173 return newFile ? BASE::IsFile : BASE::IsEvent;
176 template <
typename BASE>
178 if (numberEventsInRun_ < 1 || numberEventsInThisRun_ < numberEventsInRun_) {
180 ++numberEventsInThisRun_;
181 if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ < numberEventsInLumi_)) {
184 numberEventsInThisLumi_ = 1;
185 if (not firstLumiForRuns_.empty()) {
187 if (
run != eventID.
run()) {
188 numberEventsInThisRun_ = 1;
196 ++numberEventsInThisLumi_;
201 numberEventsInThisLumi_ = 1;
202 numberEventsInThisRun_ = 1;
204 time += timeBetweenEvents_;
207 template <
typename BASE>
209 if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
211 --numberEventsInThisRun_;
213 if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
216 numberEventsInThisLumi_ = numberEventsInLumi_;
218 if (not firstLumiForRuns_.empty()) {
220 if (
run != eventID.
run()) {
227 --numberEventsInThisLumi_;
231 assert(numberEventsInLumi_ != 0);
232 eventID = eventID.
previousRunLastEvent(origEventID_.luminosityBlock() + numberEventsInRun_ / numberEventsInLumi_);
234 numberEventsInThisLumi_ = numberEventsInLumi_;
235 numberEventsInThisRun_ = numberEventsInRun_;
237 time -= timeBetweenEvents_;
240 template <
typename BASE>
242 auto it = std::find_if(firstLumiForRuns_.rbegin(), firstLumiForRuns_.rend(), [iLumi](
auto const& iV) {
243 return iV.luminosityBlock() <= iLumi;
245 if (it == firstLumiForRuns_.rend()) {
247 return firstLumiForRuns_[0].
run();
252 template <
typename BASE>
257 template <
typename BASE>
262 template <
typename BASE>
264 desc.addOptionalUntracked<
unsigned int>(
"numberEventsInRun")
265 ->setComment(
"Number of events to generate in each run.");
266 desc.addOptionalUntracked<
unsigned int>(
"numberEventsInLuminosityBlock")
267 ->setComment(
"Number of events to generate in each lumi.");
268 desc.addUntracked<
unsigned long long>(
"firstTime", 1)->setComment(
"Time before first event (ns) (for timestamp).");
270 ->setComment(
"Time between consecutive events (ns) (for timestamp).");
271 desc.addUntracked<
unsigned int>(
"eventCreationDelay", 0)
272 ->setComment(
"Real time delay between generation of consecutive events (ms).");
277 "'firstEvent' is an XOR group because it can have type uint32 or uint64, default:1\n"
278 "Event number of first event to generate.");
280 desc.addUntracked<
unsigned int>(
"firstLuminosityBlock", 1)
281 ->setComment(
"Luminosity block number of first lumi to generate.");
282 desc.addUntracked<
unsigned int>(
"firstRun", 1)->setComment(
"Run number of first run to generate.");
283 desc.addUntracked<std::vector<edm::LuminosityBlockID>>(
"firstLuminosityBlockForEachRun", {})
285 "When the source makes a new LuminosityBlock, this list is checked to see what Run number should be used. "
286 "The LuminosityBlock numbers are required to be in ascending order.");
287 BASE::fillDescription(
desc);