CMS 3D CMS Logo

EcalDQMonitorTask.cc
Go to the documentation of this file.
2 
4 
7 
11 
16 
18 
21 
22 #include <iomanip>
23 #include <ctime>
24 #include <bitset>
25 #include <sstream>
26 
28  : DQMOneEDAnalyzer<edm::LuminosityBlockCache<ecaldqm::EcalLSCache>>(),
29  ecaldqm::EcalDQMonitor(_ps),
30  schedule_(),
31  skipCollections_(_ps.getUntrackedParameter<std::vector<std::string>>("skipCollections")),
32  allowMissingCollections_(_ps.getUntrackedParameter<bool>("allowMissingCollections")),
33  processedEvents_(0),
34  lastResetTime_(0),
35  resetInterval_(_ps.getUntrackedParameter<double>("resetInterval")) {
37  std::bitset<ecaldqm::nCollections> hasTaskToRun;
39 
41  [&dependencies, &hasTaskToRun, &collector](ecaldqm::DQWorker* worker) {
42  ecaldqm::DQWorkerTask* task(dynamic_cast<ecaldqm::DQWorkerTask*>(worker));
43  if (!task)
44  throw cms::Exception("InvalidConfiguration") << "Non-task DQWorker " << worker->getName() << " passed";
45 
46  task->addDependencies(dependencies);
47  for (unsigned iCol(0); iCol < ecaldqm::nCollections; ++iCol) {
48  if (task->analyze(nullptr, ecaldqm::Collections(iCol))) // "dry run" mode
49  hasTaskToRun.set(iCol);
50  }
51  worker->setTokens(collector);
52  task->setTokens(collector);
53  },
54  "initialization");
55 
56  edm::ParameterSet const& collectionTags(_ps.getParameterSet("collectionTags"));
57 
58  for (unsigned iCol(0); iCol < ecaldqm::nCollections; iCol++) {
59  if (hasTaskToRun[iCol])
61  }
62  if (collectionTags.existsAs<edm::InputTag>("EcalRawData", false))
64 
65  formSchedule(dependencies.formSequence(), collectionTags);
66 
67  if (verbosity_ > 0) {
68  std::stringstream ss;
69  ss << moduleName_ << ": Using collections" << std::endl;
70  for (unsigned iCol(0); iCol < schedule_.size(); iCol++)
71  ss << ecaldqm::collectionName[schedule_[iCol].second] << std::endl;
72  edm::LogInfo("EcalDQM") << ss.str();
73  }
74 
75  edm::ParameterSet const& commonParams(_ps.getUntrackedParameterSet("commonParameters"));
76  if (commonParams.getUntrackedParameter<bool>("onlineMode"))
77  lastResetTime_ = time(nullptr);
78 }
79 
80 /*static*/
84 
85  edm::ParameterSetDescription taskParameters;
88  allWorkers.addNode(
90  desc.addUntracked("workerParameters", allWorkers);
91 
93  collectionTags.addWildcardUntracked<edm::InputTag>("*");
94  desc.add("collectionTags", collectionTags);
95 
96  desc.addUntracked<std::vector<std::string>>("skipCollections", std::vector<std::string>());
97  desc.addUntracked<bool>("allowMissingCollections", true);
98  desc.addUntracked<double>("resetInterval", 0.);
99 
100  _descs.addDefault(desc);
101 }
102 
104  executeOnWorkers_([&_es](ecaldqm::DQWorker* worker) { worker->setSetupObjects(_es); },
105  "ecaldqmGetSetupObjects",
106  "Getting EventSetup Objects");
107 
108  executeOnWorkers_([&_ibooker](ecaldqm::DQWorker* worker) { worker->bookMEs(_ibooker); }, "bookMEs", "Booking MEs");
109 }
110 
112  ecaldqmBeginRun(_run, _es);
113 
114  processedEvents_ = 0;
115 
116  if (lastResetTime_ != 0)
117  lastResetTime_ = time(nullptr);
118 }
119 
121  ecaldqmEndRun(_run, _es);
122 
123  executeOnWorkers_([](ecaldqm::DQWorker* worker) { worker->releaseMEs(); }, "releaseMEs", "releasing histograms");
124 }
125 
126 std::shared_ptr<ecaldqm::EcalLSCache> EcalDQMonitorTask::globalBeginLuminosityBlock(edm::LuminosityBlock const& _lumi,
127  edm::EventSetup const& _es) const {
128  std::shared_ptr<ecaldqm::EcalLSCache> tmpCache = std::make_shared<ecaldqm::EcalLSCache>();
130  [&tmpCache](ecaldqm::DQWorker* worker) { (tmpCache->ByLumiPlotsResetSwitches)[worker->getName()] = true; },
131  "globalBeginLuminosityBlock");
132  if (this->verbosity_ > 2)
133  edm::LogInfo("EcalDQM") << "Set LS cache.";
134 
135  // Reset lhcStatusSet_ to false at the beginning of each LS; when LHC status is set in some event this variable will be set to tru
136  tmpCache->lhcStatusSet_ = false;
137  ecaldqmBeginLuminosityBlock(_lumi, _es);
138  return tmpCache;
139 }
140 
142  ecaldqmEndLuminosityBlock(_lumi, _es);
143 
144  if (lastResetTime_ != 0 && (time(nullptr) - lastResetTime_) / 3600. > resetInterval_) {
145  if (verbosity_ > 0)
146  edm::LogInfo("EcalDQM") << moduleName_ << ": Soft-resetting the histograms";
147  // TODO: soft-reset is no longer supported.
148  lastResetTime_ = time(nullptr);
149  }
150 }
151 
153  if (verbosity_ > 2)
154  edm::LogInfo("EcalDQM") << moduleName_ << "::analyze: Run " << _evt.id().run() << " Lumisection "
155  << _evt.id().luminosityBlock() << " Event " << _evt.id().event() << ": processed "
156  << processedEvents_;
157 
158  if (schedule_.empty())
159  return;
160 
161  std::set<ecaldqm::DQWorker*> enabledTasks;
162 
163  bool eventTypeFiltering(false);
165 
166  if (std::find(skipCollections_.begin(), skipCollections_.end(), "EcalRawData") != skipCollections_.end()) {
167  if (verbosity_ > 2)
168  edm::LogInfo("EcalDQM") << "EcalRawDataCollection is being skipped. No event-type filtering will be applied";
169 
170  } else if (_evt.getByToken(collectionTokens_[ecaldqm::kEcalRawData], dcchsHndl)) {
171  eventTypeFiltering = true;
172  // determine event type (called run type in DCCHeader for some reason) for each FED
173  std::stringstream ss;
174  if (verbosity_ > 2)
175  ss << moduleName_ << ": Event type ";
176 
177  short runType[ecaldqm::nDCC];
178  std::fill_n(runType, ecaldqm::nDCC, -1);
179  for (EcalRawDataCollection::const_iterator dcchItr = dcchsHndl->begin(); dcchItr != dcchsHndl->end(); ++dcchItr) {
180  if (verbosity_ > 2)
181  ss << dcchItr->getRunType() << " ";
182  runType[dcchItr->id() - 1] = dcchItr->getRunType();
183  }
184  if (verbosity_ > 2)
185  edm::LogInfo("EcalDQM") << ss.str();
186 
187  bool processEvent(false);
188 
190  [&enabledTasks, &runType, &processEvent, this](ecaldqm::DQWorker* worker) {
191  if (static_cast<ecaldqm::DQWorkerTask*>(worker)->filterRunType(runType)) {
192  if (this->verbosity_ > 2)
193  edm::LogInfo("EcalDQM") << worker->getName() << " will run on this event";
194  enabledTasks.insert(worker);
195  processEvent = true;
196  }
197  },
198  "filterRunType");
199 
200  if (!processEvent)
201  return;
202  } else {
203  edm::LogWarning("EcalDQM") << "EcalRawDataCollection does not exist. No event-type filtering will be applied";
204  }
205 
206  if (!eventTypeFiltering)
207  executeOnWorkers_([&enabledTasks](ecaldqm::DQWorker* worker) { enabledTasks.insert(worker); }, "");
208 
210 
211  // start event processing
212  auto lumiCache = luminosityBlockCache(_evt.getLuminosityBlock().index());
214  [&_evt, &_es, &enabledTasks, &lumiCache](ecaldqm::DQWorker* worker) {
215  if (enabledTasks.find(worker) != enabledTasks.end()) {
216  if (worker->onlineMode())
217  worker->setTime(time(nullptr));
218  worker->setEventNumber(_evt.id().event());
219  bool ByLumiResetSwitch = (lumiCache->ByLumiPlotsResetSwitches).at(worker->getName());
220  bool lhcStatusSet = lumiCache->lhcStatusSet_;
221  static_cast<ecaldqm::DQWorkerTask*>(worker)->beginEvent(_evt, _es, ByLumiResetSwitch, lhcStatusSet);
222  (lumiCache->ByLumiPlotsResetSwitches)[worker->getName()] = false;
223  lumiCache->lhcStatusSet_ = lhcStatusSet;
224  }
225  },
226  "beginEvent");
227 
228  // run on collections
229  for (unsigned iSch(0); iSch < schedule_.size(); iSch++) {
230  Processor processor(schedule_[iSch].first);
231  (this->*processor)(_evt, schedule_[iSch].second, enabledTasks);
232  }
233 
234  // close event processing
236  [&_evt, &_es, &enabledTasks](ecaldqm::DQWorker* worker) {
237  if (enabledTasks.find(worker) != enabledTasks.end())
238  static_cast<ecaldqm::DQWorkerTask*>(worker)->endEvent(_evt, _es);
239  },
240  "endEvent");
241 
242  if (verbosity_ > 2)
243  edm::LogInfo("EcalDQM") << moduleName_ << "::analyze: Closing Event " << _evt.id().event();
244 }
245 
static void fillDescriptions(edm::ParameterSetDescription &)
Definition: DQWorkerTask.cc:11
std::shared_ptr< ecaldqm::EcalLSCache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
void formSchedule(std::vector< ecaldqm::Collections > const &, edm::ParameterSet const &)
bool onlineMode() const
Definition: DQWorker.h:125
dispatcher processEvent(e, inputTag, standby)
std::string const & getName() const
Definition: DQWorker.h:124
void executeOnWorkers_(FuncOnWorker, std::string const &, std::string const &="", int=1) const
Definition: EcalDQMonitor.h:50
void ecaldqmEndRun(edm::Run const &, edm::EventSetup const &)
ParameterSet const & getParameterSet(std::string const &) const
std::vector< T >::const_iterator const_iterator
edm::EDGetToken collectionTokens_[ecaldqm::nCollections]
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
virtual void releaseMEs()
Definition: DQWorker.cc:90
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
static void fillDescriptions(edm::ParameterSetDescription &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
U second(std::pair< T, U > const &p)
dependencies
Definition: symbols.py:21
void analyze(edm::Event const &, edm::EventSetup const &) override
void setEventNumber(edm::EventNumber_t _e)
Definition: DQWorker.h:122
void addDefault(ParameterSetDescription const &psetDescription)
std::string const collectionName[nCollections]
Definition: Collections.h:59
void(EcalDQMonitorTask::* Processor)(edm::Event const &, ecaldqm::Collections, std::set< ecaldqm::DQWorker *> const &)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void ecaldqmBeginRun(edm::Run const &, edm::EventSetup const &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EventID id() const
Definition: EventBase.h:63
void dqmEndRun(edm::Run const &, edm::EventSetup const &) override
const_iterator begin() const
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:100
virtual void bookMEs(DQMStore::IBooker &)
Definition: DQWorker.cc:96
std::string const moduleName_
Definition: EcalDQMonitor.h:45
const_iterator end() const
void ecaldqmBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const
Log< level::Info, false > LogInfo
RunNumber_t run() const
Definition: EventID.h:38
std::vector< std::pair< Processor, ecaldqm::Collections > > schedule_
static constexpr int nDCC
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
LuminosityBlockIndex index() const
HLT enums.
void setTokens(edm::ConsumesCollector &)
Definition: DQWorker.cc:53
void ecaldqmEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
EcalDQMonitorTask(edm::ParameterSet const &)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void setSetupObjects(edm::EventSetup const &)
Definition: DQWorker.cc:104
Log< level::Warning, false > LogWarning
void setTime(time_t _t)
Definition: DQWorker.h:119
static void fillDescriptions(edm::ConfigurationDescriptions &)
std::vector< std::string > skipCollections_
EventNumber_t event() const
Definition: EventID.h:40
Definition: Run.h:45
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override