CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  evaluateTime_(_ps.getUntrackedParameter<bool>("evaluateTime")),
34  taskTimes_(),
35  lastResetTime_(0),
36  resetInterval_(_ps.getUntrackedParameter<double>("resetInterval"))
37 {
38  ecaldqm::DependencySet dependencies;
39  std::bitset<ecaldqm::nCollections> hasTaskToRun;
41 
42  executeOnWorkers_([&dependencies, &hasTaskToRun, &collector, this](ecaldqm::DQWorker* worker){
43  ecaldqm::DQWorkerTask* task(dynamic_cast<ecaldqm::DQWorkerTask*>(worker));
44  if(!task)
45  throw cms::Exception("InvalidConfiguration") << "Non-task DQWorker " << worker->getName() << " passed";
46 
47  task->addDependencies(dependencies);
48  for(unsigned iCol(0); iCol < ecaldqm::nCollections; ++iCol){
49  if(task->analyze(0, ecaldqm::Collections(iCol))) // "dry run" mode
50  hasTaskToRun.set(iCol);
51  }
52 
53  task->setTokens(collector);
54 
55  taskTimes_[task] = 0.;
56  }, "initialization");
57 
58  edm::ParameterSet const& collectionTags(_ps.getUntrackedParameterSet("collectionTags"));
59 
60  for(unsigned iCol(0); iCol < ecaldqm::nCollections; iCol++){
61  if(hasTaskToRun[iCol])
63  }
64  if(collectionTags.existsAs<edm::InputTag>("EcalRawData", false))
66 
67  formSchedule(dependencies.formSequence(), collectionTags);
68 
69  if(verbosity_ > 0){
70  std::stringstream ss;
71  ss << moduleName_ << ": Using collections" << std::endl;
72  for(unsigned iCol(0); iCol < schedule_.size(); iCol++)
73  ss << ecaldqm::collectionName[schedule_[iCol].second] << std::endl;
74  edm::LogInfo("EcalDQM") << ss.str();
75  }
76 
77  edm::ParameterSet const& commonParams(_ps.getUntrackedParameterSet("commonParameters"));
78  if(commonParams.getUntrackedParameter<bool>("onlineMode"))
79  lastResetTime_ = time(0);
80 }
81 
82 /*static*/
83 void
85 {
88 
89  edm::ParameterSetDescription taskParameters;
93  desc.addUntracked("workerParameters", allWorkers);
94 
95  edm::ParameterSetDescription collectionTags;
96  collectionTags.addWildcardUntracked<edm::InputTag>("*");
97  desc.addUntracked("collectionTags", collectionTags);
98 
99  desc.addUntracked<bool>("allowMissingCollections", true);
100  desc.addUntracked<bool>("evaluateTime", false);
101  desc.addUntracked<double>("resetInterval", 0.);
102 
103  _descs.addDefault(desc);
104 }
105 
106 void
108 {
110  ecaldqmBookHistograms(_ibooker);
111 }
112 
113 void
115 {
116  ecaldqmBeginRun(_run, _es);
117 
118  processedEvents_ = 0;
119 
120  if(lastResetTime_ != 0) lastResetTime_ = time(0);
121 }
122 
123 void
125 {
126  if(lastResetTime_ != 0)
128  static_cast<ecaldqm::DQWorkerTask*>(worker)->recoverStats();
129  }, "recoverStats");
130 
131  ecaldqmEndRun(_run, _es);
132 
134 
135  if(evaluateTime_){
136  std::stringstream ss;
137 
138  ss << "************** " << moduleName_ << " **************" << std::endl;
139  ss << " Mean time consumption of the modules" << std::endl;
140  ss << "____________________________________" << std::endl;
141  executeOnWorkers_([&ss, this](ecaldqm::DQWorker* worker){
142  ss << std::setw(20) << std::setfill(' ') << worker->getName() << "| " << (this->taskTimes_[worker] / this->processedEvents_) << std::endl;
143  }, "print time");
144  edm::LogInfo("EcalDQM") << ss.str();
145  }
146 }
147 
148 void
150 {
151  ecaldqmBeginLuminosityBlock(_lumi, _es);
152 }
153 
154 void
156 {
157  ecaldqmEndLuminosityBlock(_lumi, _es);
158 
159  if(lastResetTime_ != 0 && (time(0) - lastResetTime_) / 3600. > resetInterval_){
160  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << moduleName_ << ": Soft-resetting the histograms";
162  static_cast<ecaldqm::DQWorkerTask*>(worker)->softReset();
163  }, "softReset");
164 
165  lastResetTime_ = time(0);
166  }
167 }
168 
169 void
171 {
172  if(verbosity_ > 2) edm::LogInfo("EcalDQM") << moduleName_ << "::analyze: Run " << _evt.id().run() << " Lumisection " << _evt.id().luminosityBlock() << " Event " << _evt.id().event() << ": processed " << processedEvents_;
173 
174  if(schedule_.size() == 0) return;
175 
176  std::set<ecaldqm::DQWorker*> enabledTasks;
177 
179  if(_evt.getByToken(collectionTokens_[ecaldqm::kEcalRawData], dcchsHndl)){
180  // determine event type (called run type in DCCHeader for some reason) for each FED
181  std::stringstream ss;
182  if(verbosity_ > 2) ss << moduleName_ << ": Event type ";
183 
184  short runType[ecaldqm::nDCC];
185  std::fill_n(runType, ecaldqm::nDCC, -1);
186  for(EcalRawDataCollection::const_iterator dcchItr = dcchsHndl->begin(); dcchItr != dcchsHndl->end(); ++dcchItr){
187  if(verbosity_ > 2) ss << dcchItr->getRunType() << " ";
188  runType[dcchItr->id() - 1] = dcchItr->getRunType();
189  }
190  if(verbosity_ > 2) edm::LogInfo("EcalDQM") << ss.str();
191 
192  bool processEvent(false);
193 
194  executeOnWorkers_([&enabledTasks, &runType, &processEvent, this](ecaldqm::DQWorker* worker){
195  if(static_cast<ecaldqm::DQWorkerTask*>(worker)->filterRunType(runType)){
196  if(this->verbosity_ > 2) edm::LogInfo("EcalDQM") << worker->getName() << " will run on this event";
197  enabledTasks.insert(worker);
198  processEvent = true;
199  }
200  }, "filterRunType");
201 
202  if(!processEvent) return;
203  }
204  else{
205  edm::LogWarning("EcalDQM") << "EcalRawDataCollection does not exist. No event-type filtering will be applied";
206  executeOnWorkers_([&enabledTasks](ecaldqm::DQWorker* worker){
207  enabledTasks.insert(worker);
208  }, "");
209  }
210 
212 
213  // start event processing
214  executeOnWorkers_([&_evt, &_es, &enabledTasks](ecaldqm::DQWorker* worker){
215  if(enabledTasks.find(worker) != enabledTasks.end()){
216  if(worker->onlineMode()) worker->setTime(time(0));
217  worker->setEventNumber(_evt.id().event());
218  static_cast<ecaldqm::DQWorkerTask*>(worker)->beginEvent(_evt, _es);
219  }
220  }, "beginEvent");
221 
222  // run on collections
223  for(unsigned iSch(0); iSch < schedule_.size(); iSch++){
224  Processor processor(schedule_[iSch].first);
225  (this->*processor)(_evt, schedule_[iSch].second, enabledTasks);
226  }
227 
228  // close event processing
229  executeOnWorkers_([&_evt, &_es, &enabledTasks](ecaldqm::DQWorker* worker){
230  if(enabledTasks.find(worker) != enabledTasks.end())
231  static_cast<ecaldqm::DQWorkerTask*>(worker)->endEvent(_evt, _es);
232  }, "endEvent");
233 
234  if(verbosity_ > 2) edm::LogInfo("EcalDQM") << moduleName_ << "::analyze: Closing Event " << _evt.id().event();
235 }
236 
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
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:434
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)
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:43
ParameterWildcardBase * addWildcardUntracked(U const &pattern)
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
U second(std::pair< T, U > const &p)
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:67
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
void(EcalDQMonitorTask::* Processor)(edm::Event const &, ecaldqm::Collections, std::set< ecaldqm::DQWorker * > const &)
bool first
Definition: L1TdeRCT.cc:75
std::string const moduleName_
Definition: EcalDQMonitor.h:40
void executeOnWorkers_(FuncOnWorker, std::string const &, std::string const &="", int=1)
Definition: EcalDQMonitor.h:56
bool onlineMode() const
Definition: DQWorker.h:70
std::vector< Collections > formSequence() const
Definition: DQWorkerTask.h:58
std::vector< std::pair< Processor, ecaldqm::Collections > > schedule_
std::map< ecaldqm::DQWorker *, double > taskTimes_
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:69
edm::EventID id() const
Definition: EventBase.h:56
void ecaldqmBookHistograms(Booker &)
Definition: EcalDQMonitor.h:46
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:64
void push_back(Dependency const &_d)
Definition: DQWorkerTask.h:50
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: Run.h:41