CMS 3D CMS Logo

EcalDQMonitorTask.cc
Go to the documentation of this file.
1 #include "../interface/EcalDQMonitorTask.h"
2 
3 #include "../interface/DQWorkerTask.h"
4 
7 
11 
16 
18 
21 
22 #include <iomanip>
23 #include <ctime>
24 #include <bitset>
25 #include <sstream>
26 
28  DQMEDAnalyzer(),
29  ecaldqm::EcalDQMonitor(_ps),
30  schedule_(),
31  allowMissingCollections_(_ps.getUntrackedParameter<bool>("allowMissingCollections")),
32  processedEvents_(0),
33  lastResetTime_(0),
34  resetInterval_(_ps.getUntrackedParameter<double>("resetInterval"))
35 {
37  std::bitset<ecaldqm::nCollections> hasTaskToRun;
39 
40  executeOnWorkers_([&dependencies, &hasTaskToRun, &collector, this](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(0, ecaldqm::Collections(iCol))) // "dry run" mode
48  hasTaskToRun.set(iCol);
49  }
50 
51  task->setTokens(collector);
52  }, "initialization");
53 
54  edm::ParameterSet const& collectionTags(_ps.getUntrackedParameterSet("collectionTags"));
55 
56  for(unsigned iCol(0); iCol < ecaldqm::nCollections; iCol++){
57  if(hasTaskToRun[iCol])
59  }
60  if(collectionTags.existsAs<edm::InputTag>("EcalRawData", false))
62 
63  formSchedule(dependencies.formSequence(), collectionTags);
64 
65  if(verbosity_ > 0){
66  std::stringstream ss;
67  ss << moduleName_ << ": Using collections" << std::endl;
68  for(unsigned iCol(0); iCol < schedule_.size(); iCol++)
69  ss << ecaldqm::collectionName[schedule_[iCol].second] << std::endl;
70  edm::LogInfo("EcalDQM") << ss.str();
71  }
72 
73  edm::ParameterSet const& commonParams(_ps.getUntrackedParameterSet("commonParameters"));
74  if(commonParams.getUntrackedParameter<bool>("onlineMode"))
75  lastResetTime_ = time(0);
76 }
77 
78 /*static*/
79 void
81 {
84 
85  edm::ParameterSetDescription taskParameters;
89  desc.addUntracked("workerParameters", allWorkers);
90 
91  edm::ParameterSetDescription collectionTags;
92  collectionTags.addWildcardUntracked<edm::InputTag>("*");
93  desc.addUntracked("collectionTags", collectionTags);
94 
95  desc.addUntracked<bool>("allowMissingCollections", true);
96  desc.addUntracked<double>("resetInterval", 0.);
97 
98  _descs.addDefault(desc);
99 }
100 
101 void
103 {
105 
106  executeOnWorkers_([&_ibooker](ecaldqm::DQWorker* worker){
107  worker->bookMEs(_ibooker);
108  }, "bookMEs", "Booking MEs");
109 }
110 
111 void
113 {
114  ecaldqmBeginRun(_run, _es);
115 
116  processedEvents_ = 0;
117 
118  if(lastResetTime_ != 0) lastResetTime_ = time(0);
119 }
120 
121 void
123 {
124  if(lastResetTime_ != 0)
126  static_cast<ecaldqm::DQWorkerTask*>(worker)->recoverStats();
127  }, "recoverStats");
128 
129  ecaldqmEndRun(_run, _es);
130 
132  worker->releaseMEs();
133  }, "releaseMEs", "releasing histograms");
134 }
135 
136 void
138 {
139  ecaldqmBeginLuminosityBlock(_lumi, _es);
140 }
141 
142 void
144 {
145  ecaldqmEndLuminosityBlock(_lumi, _es);
146 
147  if(lastResetTime_ != 0 && (time(0) - lastResetTime_) / 3600. > resetInterval_){
148  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << moduleName_ << ": Soft-resetting the histograms";
150  static_cast<ecaldqm::DQWorkerTask*>(worker)->softReset();
151  }, "softReset");
152 
153  lastResetTime_ = time(0);
154  }
155 }
156 
157 void
159 {
160  if(verbosity_ > 2) edm::LogInfo("EcalDQM") << moduleName_ << "::analyze: Run " << _evt.id().run() << " Lumisection " << _evt.id().luminosityBlock() << " Event " << _evt.id().event() << ": processed " << processedEvents_;
161 
162  if(schedule_.size() == 0) return;
163 
164  std::set<ecaldqm::DQWorker*> enabledTasks;
165 
167  if(_evt.getByToken(collectionTokens_[ecaldqm::kEcalRawData], dcchsHndl)){
168  // determine event type (called run type in DCCHeader for some reason) for each FED
169  std::stringstream ss;
170  if(verbosity_ > 2) ss << moduleName_ << ": Event type ";
171 
172  short runType[ecaldqm::nDCC];
173  std::fill_n(runType, ecaldqm::nDCC, -1);
174  for(EcalRawDataCollection::const_iterator dcchItr = dcchsHndl->begin(); dcchItr != dcchsHndl->end(); ++dcchItr){
175  if(verbosity_ > 2) ss << dcchItr->getRunType() << " ";
176  runType[dcchItr->id() - 1] = dcchItr->getRunType();
177  }
178  if(verbosity_ > 2) edm::LogInfo("EcalDQM") << ss.str();
179 
180  bool processEvent(false);
181 
182  executeOnWorkers_([&enabledTasks, &runType, &processEvent, this](ecaldqm::DQWorker* worker){
183  if(static_cast<ecaldqm::DQWorkerTask*>(worker)->filterRunType(runType)){
184  if(this->verbosity_ > 2) edm::LogInfo("EcalDQM") << worker->getName() << " will run on this event";
185  enabledTasks.insert(worker);
186  processEvent = true;
187  }
188  }, "filterRunType");
189 
190  if(!processEvent) return;
191  }
192  else{
193  edm::LogWarning("EcalDQM") << "EcalRawDataCollection does not exist. No event-type filtering will be applied";
194  executeOnWorkers_([&enabledTasks](ecaldqm::DQWorker* worker){
195  enabledTasks.insert(worker);
196  }, "");
197  }
198 
200 
201  // start event processing
202  executeOnWorkers_([&_evt, &_es, &enabledTasks](ecaldqm::DQWorker* worker){
203  if(enabledTasks.find(worker) != enabledTasks.end()){
204  if(worker->onlineMode()) worker->setTime(time(0));
205  worker->setEventNumber(_evt.id().event());
206  static_cast<ecaldqm::DQWorkerTask*>(worker)->beginEvent(_evt, _es);
207  }
208  }, "beginEvent");
209 
210  // run on collections
211  for(unsigned iSch(0); iSch < schedule_.size(); iSch++){
212  Processor processor(schedule_[iSch].first);
213  (this->*processor)(_evt, schedule_[iSch].second, enabledTasks);
214  }
215 
216  // close event processing
217  executeOnWorkers_([&_evt, &_es, &enabledTasks](ecaldqm::DQWorker* worker){
218  if(enabledTasks.find(worker) != enabledTasks.end())
219  static_cast<ecaldqm::DQWorkerTask*>(worker)->endEvent(_evt, _es);
220  }, "endEvent");
221 
222  if(verbosity_ > 2) edm::LogInfo("EcalDQM") << moduleName_ << "::analyze: Closing Event " << _evt.id().event();
223 }
224 
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
void(EcalDQMonitorTask::* Processor)(edm::Event const &, ecaldqm::Collections, std::set< ecaldqm::DQWorker * > const &)
void endRun(edm::Run const &, edm::EventSetup const &) override
static void fillDescriptions(edm::ParameterSetDescription &)
Definition: DQWorkerTask.cc:17
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void formSchedule(std::vector< ecaldqm::Collections > const &, edm::ParameterSet const &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
virtual bool analyze(void const *, Collections)
Definition: DQWorkerTask.h:95
dispatcher processEvent(e, inputTag, standby)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void ecaldqmEndRun(edm::Run const &, edm::EventSetup const &)
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
edm::EDGetToken collectionTokens_[ecaldqm::nCollections]
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
virtual void releaseMEs()
Definition: DQWorker.cc:77
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
void ecaldqmGetSetupObjects(edm::EventSetup const &)
static void fillDescriptions(edm::ParameterSetDescription &)
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
ParameterWildcardBase * addWildcardUntracked(U const &pattern)
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
U second(std::pair< T, U > const &p)
dependencies
Definition: symbols.py:19
void analyze(edm::Event const &, edm::EventSetup const &) override
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
void setEventNumber(edm::EventNumber_t _e)
Definition: DQWorker.h:66
void addDefault(ParameterSetDescription const &psetDescription)
std::string const collectionName[nCollections]
Definition: Collections.h:45
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void ecaldqmBeginRun(edm::Run const &, edm::EventSetup const &)
virtual void addDependencies(DependencySet &)
Definition: DQWorkerTask.h:88
virtual void bookMEs(DQMStore::IBooker &)
Definition: DQWorker.cc:85
std::string const moduleName_
Definition: EcalDQMonitor.h:39
void executeOnWorkers_(FuncOnWorker, std::string const &, std::string const &="", int=1)
Definition: EcalDQMonitor.h:45
bool onlineMode() const
Definition: DQWorker.h:69
const_iterator end() const
std::vector< Collections > formSequence() const
Definition: DQWorkerTask.h:58
std::vector< std::pair< Processor, ecaldqm::Collections > > schedule_
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
void ecaldqmBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
std::string const & getName() const
Definition: DQWorker.h:68
edm::EventID id() const
Definition: EventBase.h:58
void ecaldqmEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
EcalDQMonitorTask(edm::ParameterSet const &)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
virtual void setTokens(edm::ConsumesCollector &)
Definition: DQWorkerTask.h:91
void setTime(time_t _t)
Definition: DQWorker.h:63
void push_back(Dependency const &_d)
Definition: DQWorkerTask.h:50
static void fillDescriptions(edm::ConfigurationDescriptions &)
const_iterator begin() const
Definition: Run.h:42