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  allowMissingCollections_(_ps.getUntrackedParameter<bool>("allowMissingCollections")),
32  processedEvents_(0),
33  lastResetTime_(0),
34  resetInterval_(_ps.getUntrackedParameter<double>("resetInterval")) {
36  std::bitset<ecaldqm::nCollections> hasTaskToRun;
38 
40  [&dependencies, &hasTaskToRun, &collector](ecaldqm::DQWorker* worker) {
41  ecaldqm::DQWorkerTask* task(dynamic_cast<ecaldqm::DQWorkerTask*>(worker));
42  if (!task)
43  throw cms::Exception("InvalidConfiguration") << "Non-task DQWorker " << worker->getName() << " passed";
44 
45  task->addDependencies(dependencies);
46  for (unsigned iCol(0); iCol < ecaldqm::nCollections; ++iCol) {
47  if (task->analyze(nullptr, ecaldqm::Collections(iCol))) // "dry run" mode
48  hasTaskToRun.set(iCol);
49  }
50  worker->setTokens(collector);
51  task->setTokens(collector);
52  },
53  "initialization");
54 
55  edm::ParameterSet const& collectionTags(_ps.getParameterSet("collectionTags"));
56 
57  for (unsigned iCol(0); iCol < ecaldqm::nCollections; iCol++) {
58  if (hasTaskToRun[iCol])
60  }
61  if (collectionTags.existsAs<edm::InputTag>("EcalRawData", false))
63 
64  formSchedule(dependencies.formSequence(), collectionTags);
65 
66  if (verbosity_ > 0) {
67  std::stringstream ss;
68  ss << moduleName_ << ": Using collections" << std::endl;
69  for (unsigned iCol(0); iCol < schedule_.size(); iCol++)
70  ss << ecaldqm::collectionName[schedule_[iCol].second] << std::endl;
71  edm::LogInfo("EcalDQM") << ss.str();
72  }
73 
74  edm::ParameterSet const& commonParams(_ps.getUntrackedParameterSet("commonParameters"));
75  if (commonParams.getUntrackedParameter<bool>("onlineMode"))
76  lastResetTime_ = time(nullptr);
77 }
78 
79 /*static*/
83 
84  edm::ParameterSetDescription taskParameters;
87  allWorkers.addNode(
89  desc.addUntracked("workerParameters", allWorkers);
90 
92  collectionTags.addWildcardUntracked<edm::InputTag>("*");
93  desc.add("collectionTags", collectionTags);
94 
95  desc.addUntracked<bool>("allowMissingCollections", true);
96  desc.addUntracked<double>("resetInterval", 0.);
97 
98  _descs.addDefault(desc);
99 }
100 
102  executeOnWorkers_([&_es](ecaldqm::DQWorker* worker) { worker->setSetupObjects(_es); },
103  "ecaldqmGetSetupObjects",
104  "Getting EventSetup Objects");
105 
106  executeOnWorkers_([&_ibooker](ecaldqm::DQWorker* worker) { worker->bookMEs(_ibooker); }, "bookMEs", "Booking MEs");
107 }
108 
110  ecaldqmBeginRun(_run, _es);
111 
112  processedEvents_ = 0;
113 
114  if (lastResetTime_ != 0)
115  lastResetTime_ = time(nullptr);
116 }
117 
119  ecaldqmEndRun(_run, _es);
120 
121  executeOnWorkers_([](ecaldqm::DQWorker* worker) { worker->releaseMEs(); }, "releaseMEs", "releasing histograms");
122 }
123 
124 std::shared_ptr<ecaldqm::EcalLSCache> EcalDQMonitorTask::globalBeginLuminosityBlock(edm::LuminosityBlock const& _lumi,
125  edm::EventSetup const& _es) const {
126  std::shared_ptr<ecaldqm::EcalLSCache> tmpCache = std::make_shared<ecaldqm::EcalLSCache>();
128  [&tmpCache](ecaldqm::DQWorker* worker) { (tmpCache->ByLumiPlotsResetSwitches)[worker->getName()] = true; },
129  "globalBeginLuminosityBlock");
130  if (this->verbosity_ > 2)
131  edm::LogInfo("EcalDQM") << "Set LS cache.";
132 
133  // 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
134  tmpCache->lhcStatusSet_ = false;
135  ecaldqmBeginLuminosityBlock(_lumi, _es);
136  return tmpCache;
137 }
138 
140  ecaldqmEndLuminosityBlock(_lumi, _es);
141 
142  if (lastResetTime_ != 0 && (time(nullptr) - lastResetTime_) / 3600. > resetInterval_) {
143  if (verbosity_ > 0)
144  edm::LogInfo("EcalDQM") << moduleName_ << ": Soft-resetting the histograms";
145  // TODO: soft-reset is no longer supported.
146  lastResetTime_ = time(nullptr);
147  }
148 }
149 
151  if (verbosity_ > 2)
152  edm::LogInfo("EcalDQM") << moduleName_ << "::analyze: Run " << _evt.id().run() << " Lumisection "
153  << _evt.id().luminosityBlock() << " Event " << _evt.id().event() << ": processed "
154  << processedEvents_;
155 
156  if (schedule_.empty())
157  return;
158 
159  std::set<ecaldqm::DQWorker*> enabledTasks;
160 
162  if (_evt.getByToken(collectionTokens_[ecaldqm::kEcalRawData], dcchsHndl)) {
163  // determine event type (called run type in DCCHeader for some reason) for each FED
164  std::stringstream ss;
165  if (verbosity_ > 2)
166  ss << moduleName_ << ": Event type ";
167 
168  short runType[ecaldqm::nDCC];
169  std::fill_n(runType, ecaldqm::nDCC, -1);
170  for (EcalRawDataCollection::const_iterator dcchItr = dcchsHndl->begin(); dcchItr != dcchsHndl->end(); ++dcchItr) {
171  if (verbosity_ > 2)
172  ss << dcchItr->getRunType() << " ";
173  runType[dcchItr->id() - 1] = dcchItr->getRunType();
174  }
175  if (verbosity_ > 2)
176  edm::LogInfo("EcalDQM") << ss.str();
177 
178  bool processEvent(false);
179 
181  [&enabledTasks, &runType, &processEvent, this](ecaldqm::DQWorker* worker) {
182  if (static_cast<ecaldqm::DQWorkerTask*>(worker)->filterRunType(runType)) {
183  if (this->verbosity_ > 2)
184  edm::LogInfo("EcalDQM") << worker->getName() << " will run on this event";
185  enabledTasks.insert(worker);
186  processEvent = true;
187  }
188  },
189  "filterRunType");
190 
191  if (!processEvent)
192  return;
193  } else {
194  edm::LogWarning("EcalDQM") << "EcalRawDataCollection does not exist. No event-type filtering will be applied";
195  executeOnWorkers_([&enabledTasks](ecaldqm::DQWorker* worker) { enabledTasks.insert(worker); }, "");
196  }
197 
199 
200  // start event processing
201  auto lumiCache = luminosityBlockCache(_evt.getLuminosityBlock().index());
203  [&_evt, &_es, &enabledTasks, &lumiCache](ecaldqm::DQWorker* worker) {
204  if (enabledTasks.find(worker) != enabledTasks.end()) {
205  if (worker->onlineMode())
206  worker->setTime(time(nullptr));
207  worker->setEventNumber(_evt.id().event());
208  bool ByLumiResetSwitch = (lumiCache->ByLumiPlotsResetSwitches).at(worker->getName());
209  bool lhcStatusSet = lumiCache->lhcStatusSet_;
210  static_cast<ecaldqm::DQWorkerTask*>(worker)->beginEvent(_evt, _es, ByLumiResetSwitch, lhcStatusSet);
211  (lumiCache->ByLumiPlotsResetSwitches)[worker->getName()] = false;
212  lumiCache->lhcStatusSet_ = lhcStatusSet;
213  }
214  },
215  "beginEvent");
216 
217  // run on collections
218  for (unsigned iSch(0); iSch < schedule_.size(); iSch++) {
219  Processor processor(schedule_[iSch].first);
220  (this->*processor)(_evt, schedule_[iSch].second, enabledTasks);
221  }
222 
223  // close event processing
225  [&_evt, &_es, &enabledTasks](ecaldqm::DQWorker* worker) {
226  if (enabledTasks.find(worker) != enabledTasks.end())
227  static_cast<ecaldqm::DQWorkerTask*>(worker)->endEvent(_evt, _es);
228  },
229  "endEvent");
230 
231  if (verbosity_ > 2)
232  edm::LogInfo("EcalDQM") << moduleName_ << "::analyze: Closing Event " << _evt.id().event();
233 }
234 
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:536
static void fillDescriptions(edm::ParameterSetDescription &)
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_
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 &)
EventNumber_t event() const
Definition: EventID.h:40
Definition: Run.h:45
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override