CMS 3D CMS Logo

RunHelper.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 #include "RunHelper.h"
4 
7 
8 #include <cassert>
9 
10 namespace edm {
11 
12  std::unique_ptr<RunHelperBase> makeRunHelper(ParameterSet const& pset) {
13  if (pset.exists("setRunNumber")) {
14  RunNumber_t run = pset.getUntrackedParameter<unsigned int>("setRunNumber");
15  if (run != 0U) {
16  return std::make_unique<SetRunHelper>(pset);
17  }
18  }
19  if (pset.exists("setRunNumberForEachLumi")) {
20  std::vector<RunNumber_t> runs = pset.getUntrackedParameter<std::vector<unsigned int>>("setRunNumberForEachLumi");
21  if (!runs.empty()) {
22  return std::make_unique<SetRunForEachLumiHelper>(pset);
23  }
24  }
25  if (pset.exists("firstLuminosityBlockForEachRun")) {
26  if (not pset.getUntrackedParameter<std::vector<LuminosityBlockID>>("firstLuminosityBlockForEachRun").empty()) {
27  return std::make_unique<FirstLuminosityBlockForEachRunHelper>(pset);
28  }
29  }
30  return std::make_unique<DefaultRunHelper>();
31  }
32 
34 
36  assert(lumi == originalLumi);
37  }
38 
40  assert(run == originalRun);
41  }
42 
44 
46  : RunHelperBase(),
47  setRun_(pset.getUntrackedParameter<unsigned int>("setRunNumber")),
48  forcedRunOffset_(0),
49  firstTime_(true) {}
50 
52 
54  if (firstTime_ && setRun_ != 0) {
56  if (forcedRunOffset_ < 0) {
58  << "The value of the 'setRunNumber' parameter must not be\n"
59  << "less than the first run number in the first input file.\n"
60  << "'setRunNumber' was " << setRun_ << ", while the first run was " << firstRun << ".\n";
61  }
62  }
63  firstTime_ = false;
64  }
65 
67  id = RunID(id.run() + forcedRunOffset_);
68  if (id < RunID::firstValidRun())
69  id = RunID::firstValidRun();
70  }
71 
73  id = LuminosityBlockID(id.run() + forcedRunOffset_, id.luminosityBlock());
74  if (RunID(id.run()) < RunID::firstValidRun())
75  id = LuminosityBlockID(RunID::firstValidRun().run(), id.luminosityBlock());
76  }
77 
78  void SetRunHelper::overrideRunNumber(EventID& id, bool isRealData) {
79  if (isRealData) {
80  throw Exception(errors::Configuration, "SetRunHelper::overrideRunNumber()")
81  << "The 'setRunNumber' parameter of PoolSource cannot be used with real data.\n";
82  }
83  id = EventID(id.run() + forcedRunOffset_, id.luminosityBlock(), id.event());
84  if (RunID(id.run()) < RunID::firstValidRun()) {
85  id = EventID(
87  }
88  }
89 
91  assert(run == originalRun + forcedRunOffset_);
92  }
93 
95  : RunHelperBase(),
96  setRunNumberForEachLumi_(pset.getUntrackedParameter<std::vector<unsigned int>>("setRunNumberForEachLumi")),
97  indexOfNextRunNumber_(0),
98  realRunNumber_(0),
99  fakeNewRun_(false),
100  firstTime_(true) {}
101 
103 
105  InputSource::ItemType const& newItemType,
106  RunNumber_t,
108  EventNumber_t) {
109  if (newItemType == InputSource::ItemType::IsRun ||
110  (newItemType == InputSource::ItemType::IsLumi && previousItemType != InputSource::ItemType::IsRun)) {
111  if (firstTime_) {
112  firstTime_ = false;
113  } else {
115  }
117  throw Exception(errors::MismatchedInputFiles, "PoolSource::getNextItemType")
118  << " Parameter 'setRunNumberForEachLumi' has " << setRunNumberForEachLumi_.size() << " entries\n"
119  << "but this job is processing more luminosity blocks than this.\n";
120  }
122  if (run == 0) {
123  throw Exception(errors::Configuration, "PoolSource")
124  << "'setRunNumberForEachLumi' contains an illegal run number of '0'.\n";
125  }
126  bool sameRunNumber = (indexOfNextRunNumber_ != 0U && run == setRunNumberForEachLumi_[indexOfNextRunNumber_ - 1]);
127  if (!sameRunNumber) {
128  fakeNewRun_ = (newItemType != InputSource::ItemType::IsRun);
130  }
131  }
132  return newItemType;
133  }
134 
137  }
138 
140  if (realRunNumber_ != 0 && run != realRunNumber_) {
141  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkForNewRun")
142  << " Parameter 'setRunNumberForEachLumi' can only process a single run.\n"
143  << "but this job is processing more than one run.\n";
144  }
146  }
147 
149 
151  id = LuminosityBlockID(runNumberToUseForThisLumi(), id.luminosityBlock());
152  }
153 
155  if (isRealData) {
156  throw Exception(errors::Configuration, "SetRunForEachLumiHelper::overrideRunNumber()")
157  << "The 'setRunNumberForEachLumi' parameter of PoolSource cannot be used with real data.\n";
158  }
159  id = EventID(runNumberToUseForThisLumi(), id.luminosityBlock(), id.event());
160  }
161 
164  }
165 
167  : lumiToRun_(pset.getUntrackedParameter<std::vector<edm::LuminosityBlockID>>("firstLuminosityBlockForEachRun")),
168  realRunNumber_{0},
169  lastUsedRunNumber_{0},
170  fakeNewRun_{false} {}
171 
173  InputSource::ItemType const& newItemType,
174  RunNumber_t,
176  EventNumber_t) {
177  if (newItemType == InputSource::ItemType::IsLumi && previousItemType != InputSource::ItemType::IsRun) {
178  auto run = findRunFromLumi(iLumi);
179  if (run == 0) {
180  throw Exception(errors::Configuration, "PoolSource")
181  << "'firstLuminosityBlockForEachRun' contains an illegal run number of '0'.\n";
182  }
183  if (lastUsedRunNumber_ != run) {
184  fakeNewRun_ = true;
187  }
188  }
189  return newItemType;
190  }
191 
193 
195  if (realRunNumber_ != 0 && run != realRunNumber_) {
196  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkForNewRun")
197  << " Parameter 'firstLuminosityBlockForEachRun' can only process a single run.\n"
198  << "but this job is processing more than one run.\n";
199  }
202  fakeNewRun_ = false;
203  }
204 
206 
208  id = LuminosityBlockID(runNumberToUseForThisLumi(), id.luminosityBlock());
209  }
210 
212  if (isRealData) {
213  throw Exception(errors::Configuration, "FirstLuminosityBlockForEachRunHelper::overrideRunNumber()")
214  << "The 'firstLuminosityBlockForEachRun' parameter of PoolSource cannot be used with real data.\n";
215  }
216  id = EventID(runNumberToUseForThisLumi(), id.luminosityBlock(), id.event());
217  }
218 
221  }
222 
224  RunNumber_t run = 0;
225  for (auto const& lumiID : lumiToRun_) {
226  if (lumiID.luminosityBlock() > iLumi) {
227  break;
228  }
229  run = lumiID.run();
230  }
231  if (0 == run) {
232  throw Exception(errors::Configuration, "FirstLuminosityBlockForEachRunHelper::findRunFromLumi()")
233  << "The 'firstLuminosityBlockForEachRun' parameter does not have a matching Run number for LuminosityBlock "
234  "number: "
235  << iLumi << ".\n";
236  }
237  return run;
238  }
239 
241  desc.addOptionalNode(ParameterDescription<unsigned int>("setRunNumber", 0U, false) xor
242  ParameterDescription<std::vector<unsigned int>>(
243  "setRunNumberForEachLumi", std::vector<unsigned int>(), false) xor
244  ParameterDescription<std::vector<LuminosityBlockID>>(
245  "firstLuminosityBlockForEachRun", std::vector<LuminosityBlockID>(), false),
246  true)
247  ->setComment(
248  "If 'setRun' is non-zero, change number of first run to this number. Apply same offset to all runs."
249  "If 'setRunNumberForEachLumi' is non-empty, use these as run numbers for each lumi respectively."
250  "If 'firstLuminosityBlockForEachRun' is non-empty, the LuminosityBlock ID is used to determine which Run "
251  "ID to use. The entries must be ascending values of LuminosityBlock ID."
252  "''setRun', 'setRunNumberForEachLumi' and 'firstLuminosityBlockForEachRun' are mutually exclusive and "
253  "allowed only for simulation.");
254  }
255 } // namespace edm
static LuminosityBlockID firstValidLuminosityBlock()
virtual void checkLumiConsistency(LuminosityBlockNumber_t lumi, LuminosityBlockNumber_t origninalLumi) const
Definition: RunHelper.cc:35
void checkRunConsistency(RunNumber_t run, RunNumber_t origninalRun) const override
Definition: RunHelper.cc:162
void setForcedRunOffset(RunNumber_t firstRun) override
Definition: RunHelper.cc:53
void checkForNewRun(RunNumber_t run, LuminosityBlockNumber_t nextLumi) override
Definition: RunHelper.cc:139
static void fillDescription(ParameterSetDescription &desc)
Definition: RunHelper.cc:240
void overrideRunNumber(EventID &event, bool isRealData) override
Definition: RunHelper.cc:78
InputSource::ItemType nextItemType(InputSource::ItemType const &previousItemType, InputSource::ItemType const &newIemType, RunNumber_t, LuminosityBlockNumber_t, EventNumber_t) override
Definition: RunHelper.cc:172
unsigned long long EventNumber_t
static RunID firstValidRun()
Definition: RunID.h:48
assert(be >=bs)
unsigned int LuminosityBlockNumber_t
~SetRunHelper() override
Definition: RunHelper.cc:51
void checkRunConsistency(RunNumber_t run, RunNumber_t origninalRun) const override
Definition: RunHelper.cc:90
SetRunHelper(ParameterSet const &pset)
Definition: RunHelper.cc:45
std::vector< edm::LuminosityBlockID > const lumiToRun_
Definition: RunHelper.h:112
RunNumber_t findRunFromLumi(LuminosityBlockNumber_t) const
Definition: RunHelper.cc:223
void overrideRunNumber(EventID &event, bool isRealData) override
Definition: RunHelper.cc:211
virtual void checkRunConsistency(RunNumber_t run, RunNumber_t origninalRun) const
Definition: RunHelper.cc:39
~DefaultRunHelper() override
Definition: RunHelper.cc:43
std::unique_ptr< RunHelperBase > makeRunHelper(ParameterSet const &pset)
Definition: RunHelper.cc:12
FirstLuminosityBlockForEachRunHelper(ParameterSet const &pset)
Definition: RunHelper.cc:166
SetRunForEachLumiHelper(ParameterSet const &pset)
Definition: RunHelper.cc:94
InputSource::ItemType nextItemType(InputSource::ItemType const &previousItemType, InputSource::ItemType const &newIemType, RunNumber_t, LuminosityBlockNumber_t, EventNumber_t) override
Definition: RunHelper.cc:104
void checkForNewRun(RunNumber_t run, LuminosityBlockNumber_t nextLumi) override
Definition: RunHelper.cc:194
virtual ~RunHelperBase()
Definition: RunHelper.cc:33
~SetRunForEachLumiHelper() override
Definition: RunHelper.cc:102
RunNumber_t runNumberToUseForThisLumi() const override
Definition: RunHelper.cc:192
HLT enums.
RunNumber_t setRun_
Definition: RunHelper.h:60
RunNumber_t runNumberToUseForThisLumi() const override
Definition: RunHelper.cc:135
unsigned int RunNumber_t
void checkRunConsistency(RunNumber_t run, RunNumber_t originalRun) const override
Definition: RunHelper.cc:219
std::vector< RunNumber_t > setRunNumberForEachLumi_
Definition: RunHelper.h:85
void overrideRunNumber(EventID &event, bool isRealData) override
Definition: RunHelper.cc:154