23 void checkFirstLumiForRuns(std::vector<edm::LuminosityBlockID>
const& iFirstLumis) {
24 if (iFirstLumis.empty())
27 auto previous = iFirstLumis[0].luminosityBlock();
28 for (
auto it = iFirstLumis.begin() + 1;
it != iFirstLumis.end(); ++
it) {
31 <<
"Incorrect ordering of LuminosityBlock numbers in parameter 'firstLuminosityBlockForEachRun'";
41 template <
typename BASE>
48 numberEventsInRun_(
pset.getUntrackedParameter<unsigned
int>(
"numberEventsInRun", BASE::remainingEvents())),
50 pset.getUntrackedParameter<unsigned
int>(
"numberEventsInLuminosityBlock", BASE::remainingEvents())),
51 presentTime_(
pset.getUntrackedParameter<unsigned long long>(
"firstTime", 1ULL)),
52 origTime_(presentTime_),
55 eventCreationDelay_(
pset.getUntrackedParameter<unsigned
int>(
"eventCreationDelay", 0)),
56 numberEventsInThisRun_(0),
57 numberEventsInThisLumi_(0),
58 zerothEvent_(
pset.existsAs<unsigned
int>(
"firstEvent",
false)
59 ?
pset.getUntrackedParameter<unsigned
int>(
"firstEvent", 1) - 1
60 :
pset.getUntrackedParameter<unsigned long long>(
"firstEvent", 1) - 1),
61 eventID_(
pset.getUntrackedParameter<unsigned
int>(
"firstRun", 1),
62 pset.getUntrackedParameter<unsigned
int>(
"firstLuminosityBlock", 1),
64 origEventID_(eventID_),
65 isRealData_(realData),
67 BASE::setTimestamp(
Timestamp(presentTime_));
68 checkFirstLumiForRuns(firstLumiForRuns_);
69 if (not firstLumiForRuns_.empty()) {
70 numberEventsInRun_ = -1;
71 eventID_ =
EventID(runForLumi(eventID_.luminosityBlock()), eventID_.luminosityBlock(), zerothEvent_);
75 template <
typename BASE>
78 template <
typename BASE>
82 return std::make_shared<RunAuxiliary>(eventID_.run(), ts, Timestamp::invalidTimestamp());
85 template <
typename BASE>
88 return std::shared_ptr<LuminosityBlockAuxiliary>();
91 return std::make_shared<LuminosityBlockAuxiliary>(
92 eventID_.run(), eventID_.luminosityBlock(), ts, Timestamp::invalidTimestamp());
95 template <
typename BASE>
99 retreatToPrevious(eventID_, presentTime_);
102 advanceToNext(eventID_, presentTime_);
104 if (eventID_.run() != oldEventID.
run()) {
115 template <
typename BASE>
120 initialize(eventID_, presentTime_, timeBetweenEvents_);
123 template <
typename BASE>
126 template <
typename BASE>
128 presentTime_ = origTime_;
129 eventID_ = origEventID_;
130 numberEventsInThisRun_ = 0;
131 numberEventsInThisLumi_ = 0;
136 template <
typename BASE>
139 return noFiles() ? BASE::ItemType::IsStop : BASE::ItemType::IsFile;
141 if (BASE::newRun()) {
142 return BASE::ItemType::IsRun;
144 if (BASE::newLumi()) {
145 return BASE::ItemType::IsLumi;
147 if (BASE::eventCached()) {
148 return BASE::ItemType::IsEvent;
151 advanceToNext(eventID_, presentTime_);
152 if (eventCreationDelay_ > 0) {
153 std::this_thread::sleep_for(std::chrono::microseconds(eventCreationDelay_));
155 size_t index = fileIndex();
156 bool another = setRunAndEventInfo(eventID_, presentTime_, eType_);
158 return BASE::ItemType::IsStop;
160 bool newFile = (fileIndex() >
index);
161 BASE::setEventCached();
162 if (BASE::newRun() || eventID_.run() != oldEventID.
run()) {
166 return newFile ? BASE::ItemType::IsFile : BASE::ItemType::IsRun;
169 if (BASE::newLumi() || eventID_.luminosityBlock() != oldEventID.
luminosityBlock()) {
172 return newFile ? BASE::ItemType::IsFile : BASE::ItemType::IsLumi;
174 return newFile ? BASE::ItemType::IsFile : BASE::ItemType::IsEvent;
177 template <
typename BASE>
179 if (numberEventsInRun_ < 1 || numberEventsInThisRun_ < numberEventsInRun_) {
181 ++numberEventsInThisRun_;
182 if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ < numberEventsInLumi_)) {
185 numberEventsInThisLumi_ = 1;
186 if (not firstLumiForRuns_.empty()) {
188 if (
run != eventID.
run()) {
189 numberEventsInThisRun_ = 1;
197 ++numberEventsInThisLumi_;
202 numberEventsInThisLumi_ = 1;
203 numberEventsInThisRun_ = 1;
205 time += timeBetweenEvents_;
208 template <
typename BASE>
210 if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
212 --numberEventsInThisRun_;
214 if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
217 numberEventsInThisLumi_ = numberEventsInLumi_;
219 if (not firstLumiForRuns_.empty()) {
221 if (
run != eventID.
run()) {
228 --numberEventsInThisLumi_;
232 assert(numberEventsInLumi_ != 0);
233 eventID = eventID.
previousRunLastEvent(origEventID_.luminosityBlock() + numberEventsInRun_ / numberEventsInLumi_);
235 numberEventsInThisLumi_ = numberEventsInLumi_;
236 numberEventsInThisRun_ = numberEventsInRun_;
238 time -= timeBetweenEvents_;
241 template <
typename BASE>
243 auto it = std::find_if(firstLumiForRuns_.rbegin(), firstLumiForRuns_.rend(), [
iLumi](
auto const& iV) {
244 return iV.luminosityBlock() <=
iLumi;
246 if (
it == firstLumiForRuns_.rend()) {
248 return firstLumiForRuns_[0].run();
253 template <
typename BASE>
258 template <
typename BASE>
263 template <
typename BASE>
265 desc.addOptionalUntracked<
unsigned int>(
"numberEventsInRun")
266 ->setComment(
"Number of events to generate in each run.");
267 desc.addOptionalUntracked<
unsigned int>(
"numberEventsInLuminosityBlock")
268 ->setComment(
"Number of events to generate in each lumi.");
269 desc.addUntracked<
unsigned long long>(
"firstTime", 1)->setComment(
"Time before first event (ns) (for timestamp).");
271 ->setComment(
"Time between consecutive events (ns) (for timestamp).");
272 desc.addUntracked<
unsigned int>(
"eventCreationDelay", 0)
273 ->setComment(
"Real time delay between generation of consecutive events (ms).");
278 "'firstEvent' is an XOR group because it can have type uint32 or uint64, default:1\n" 279 "Event number of first event to generate.");
281 desc.addUntracked<
unsigned int>(
"firstLuminosityBlock", 1)
282 ->setComment(
"Luminosity block number of first lumi to generate.");
283 desc.addUntracked<
unsigned int>(
"firstRun", 1)->setComment(
"Run number of first run to generate.");
284 desc.addUntracked<std::vector<edm::LuminosityBlockID>>(
"firstLuminosityBlockForEachRun", {})
286 "When the source makes a new LuminosityBlock, this list is checked to see what Run number should be used. " 287 "The LuminosityBlock numbers are required to be in ascending order.");
288 BASE::fillDescription(
desc);
static unsigned long long constexpr kAveEventPerSec
EventID next(LuminosityBlockNumber_t const &lumi) const
static AlgebraicMatrix initialize()
IDGeneratorSourceBase(ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
unsigned int LuminosityBlockNumber_t
LuminosityBlockNumber_t luminosityBlock() const
EventID previous(LuminosityBlockNumber_t const &lumi) const
unsigned long long TimeValue_t
EventID nextRunFirstEvent(LuminosityBlockNumber_t const &lumi) const
EventID previousRunLastEvent(LuminosityBlockNumber_t const &lumi) const
static unsigned long long constexpr kNanoSecPerSec
EventNumber_t event() const