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.
2 
3 #include <algorithm>
4 #include <iomanip>
5 
9 
14 
18 
20 
23 
26 
28  EcalDQMonitor(_ps),
29  ievt_(0),
30  workers_(0),
31  schedule_(),
32  enabled_(),
33  taskTimes_(),
34  evaluateTime_(_ps.getUntrackedParameter<bool>("evaluateTime")),
35  allowMissingCollections_(_ps.getUntrackedParameter<bool>("allowMissingCollections"))
36 {
37  std::vector<std::string> taskNames(_ps.getUntrackedParameter<std::vector<std::string> >("tasks"));
38  edm::ParameterSet const& taskParams(_ps.getUntrackedParameterSet("taskParameters"));
39  edm::ParameterSet const& mePaths(_ps.getUntrackedParameterSet("mePaths"));
40 
41  ecaldqm::WorkerFactory factory(0);
42  std::multimap<ecaldqm::Collections, ecaldqm::Collections> dependencies;
43 
44  for(std::vector<std::string>::iterator tItr(taskNames.begin()); tItr != taskNames.end(); ++tItr){
45  if(!(factory = ecaldqm::SetWorker::findFactory(*tItr))) continue;
46 
47  if(verbosity_ > 0) std::cout << moduleName_ << ": Setting up " << *tItr << std::endl;
48 
49  ecaldqm::DQWorker* worker(factory(taskParams, mePaths.getUntrackedParameterSet(*tItr)));
50  if(worker->getName() != *tItr){
51  delete worker;
52 
53  if(verbosity_ > 0) std::cout << moduleName_ << ": " << *tItr << " could not be configured" << std::endl;
54  continue;
55  }
56  ecaldqm::DQWorkerTask* task(static_cast<ecaldqm::DQWorkerTask*>(worker));
57  task->setVerbosity(verbosity_);
58 
59  workers_.push_back(task);
60 
61  std::vector<std::pair<ecaldqm::Collections, ecaldqm::Collections> > const& dep(task->getDependencies());
62  for(std::vector<std::pair<ecaldqm::Collections, ecaldqm::Collections> >::const_iterator depItr(dep.begin()); depItr != dep.end(); ++depItr)
63  dependencies.insert(*depItr);
64  }
65 
66  edm::ParameterSet const& collectionTags(_ps.getUntrackedParameterSet("collectionTags"));
67 
68  std::vector<ecaldqm::Collections> usedCollections;
69 
70  for(unsigned iCol(0); iCol < ecaldqm::nCollections; iCol++){
71 
73  taskLists_[iCol] = std::vector<ecaldqm::DQWorkerTask*>();
74 
75  bool use(iCol == ecaldqm::kEcalRawData);
76 
77  for(std::vector<ecaldqm::DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
78  if((*wItr)->runsOn(iCol)){
79  taskLists_[iCol].push_back(*wItr);
80  use = true;
81  }
82  }
83  if(use){
84  registerCollection(ecaldqm::Collections(iCol), collectionTags.getUntrackedParameter<edm::InputTag>(ecaldqm::collectionName[iCol]));
85  usedCollections.push_back(ecaldqm::Collections(iCol));
86  }
87 
88  }
89 
90  formSchedule_(usedCollections, dependencies);
91 
92  if(verbosity_ > 0){
93  std::cout << moduleName_ << ": Using collections" << std::endl;
94  for(unsigned iCol(0); iCol < schedule_.size(); iCol++)
95  std::cout << ecaldqm::collectionName[schedule_[iCol].second] << std::endl;
96  std::cout << std::endl;
97  }
98 }
99 
101 {
102  for(std::vector<ecaldqm::DQWorkerTask *>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr)
103  delete *wItr;
104 }
105 
106 /* static */
107 void
109 {
111  desc.setUnknown();
112  _descs.addDefault(desc);
113 }
114 
115 void
117 {
118  // set up ecaldqm::electronicsMap in EcalDQMCommonUtils
120  _es.get<EcalMappingRcd>().get(elecMapHandle);
121  ecaldqm::setElectronicsMap(elecMapHandle.product());
122 
123  // set up ecaldqm::electronicsMap in EcalDQMCommonUtils
125  _es.get<IdealGeometryRecord>().get(ttMapHandle);
126  ecaldqm::setTrigTowerMap(ttMapHandle.product());
127 
128  for(std::vector<ecaldqm::DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
129  ecaldqm::DQWorkerTask* task(*wItr);
130  task->reset();
131  if(task->runsOn(ecaldqm::kRun)) task->beginRun(_run, _es);
132  }
133 
134  if(verbosity_ > 0)
135  std::cout << moduleName_ << ": Starting run " << _run.run() << std::endl;
136 
137  ievt_ = 0;
138  taskTimes_.clear();
139 }
140 
141 void
143 {
144  for(std::vector<ecaldqm::DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
145  ecaldqm::DQWorkerTask* task(*wItr);
146  if(task->runsOn(ecaldqm::kRun)) task->endRun(_run, _es);
147  }
148 
149  if(evaluateTime_){
150  std::stringstream ss;
151 
152  ss << "************** " << moduleName_ << " **************" << std::endl;
153  ss << " Mean time consumption of the modules" << std::endl;
154  ss << "____________________________________" << std::endl;
155  for(std::vector<ecaldqm::DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
156  ecaldqm::DQWorkerTask* task(*wItr);
157  ss << std::setw(20) << std::setfill(' ') << task->getName() << "| " << (taskTimes_[task] / ievt_) << std::endl;
158  }
159  edm::LogInfo("EcalDQM") << ss.str();
160  }
161 }
162 
163 void
165 {
166  for(std::vector<ecaldqm::DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
167  ecaldqm::DQWorkerTask* task(*wItr);
168  if(task->isInitialized() && task->runsOn(ecaldqm::kLumiSection)) task->beginLuminosityBlock(_lumi, _es);
169  }
170 }
171 
172 void
174 {
175  for(std::vector<ecaldqm::DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
176  ecaldqm::DQWorkerTask* task(*wItr);
177  if(task->isInitialized() && task->runsOn(ecaldqm::kLumiSection)) task->endLuminosityBlock(_lumi, _es);
178  }
179 }
180 
181 void
183 {
184  ievt_++;
185 
187  if(!_evt.getByToken(collectionTokens_[ecaldqm::kEcalRawData], dcchsHndl))
188  throw cms::Exception("ObjectNotFound") << "EcalRawDataCollection does not exist";
189 
190  // determine event type (called run type in DCCHeader for some reason) for each FED
191  std::vector<short> runType(54, -1);
192  for(EcalRawDataCollection::const_iterator dcchItr = dcchsHndl->begin(); dcchItr != dcchsHndl->end(); ++dcchItr){
193  runType[dcchItr->id() - 1] = dcchItr->getRunType();
194  }
195 
196  bool atLeastOne(false);
197 
198  ecaldqm::DQWorkerTask* task(0);
199 
200  // set up task modules
201  for(std::vector<ecaldqm::DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
202  task = *wItr;
203 
204  if(task->filterRunType(runType)){
205  enabled_[task] = true;
206 
207  if(!task->isInitialized()){
208  if(verbosity_ > 1) std::cout << moduleName_ << ": Booking MEs for " << task->getName() << std::endl;
209  task->bookMEs();
210  task->setInitialized(true);
211  }
212 
213  task->beginEvent(_evt, _es);
214  atLeastOne = true;
215  }else{
216  enabled_[task] = false;
217  }
218  }
219 
220  if(!atLeastOne) return;
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);
226  }
227 
228  // close event
229  for(std::vector<ecaldqm::DQWorkerTask *>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
230  task = *wItr;
231  if(enabled_[task]) task->endEvent(_evt, _es);
232  }
233 
234 }
T getUntrackedParameter(std::string const &, T const &) const
void(EcalDQMonitorTask::* Processor)(edm::Event const &, ecaldqm::Collections)
std::vector< ecaldqm::DQWorkerTask * > workers_
std::map< ecaldqm::DQWorkerTask *, bool > enabled_
void formSchedule_(std::vector< ecaldqm::Collections > const &, std::multimap< ecaldqm::Collections, ecaldqm::Collections > const &)
void setTrigTowerMap(const EcalTrigTowerConstituentsMap *)
RunNumber_t run() const
Definition: RunBase.h:42
std::string moduleName_
Definition: EcalDQMonitor.h:22
virtual void endEvent(const edm::Event &, const edm::EventSetup &)
Definition: DQWorkerTask.h:18
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
edm::EDGetToken collectionTokens_[ecaldqm::nCollections]
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: DQWorker.h:27
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
void analyze(edm::Event const &, edm::EventSetup const &)
virtual void setVerbosity(int _verbosity)
Definition: DQWorker.h:39
virtual void setInitialized(bool _init)
Definition: DQWorker.h:38
U second(std::pair< T, U > const &p)
void setElectronicsMap(const EcalElectronicsMapping *)
std::map< ecaldqm::DQWorkerTask *, double > taskTimes_
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
void addDefault(ParameterSetDescription const &psetDescription)
std::string const collectionName[nCollections]
Definition: Collections.h:39
virtual void reset()
Definition: DQWorker.cc:55
virtual bool runsOn(unsigned)
Definition: DQWorkerTask.cc:19
virtual std::string const & getName()
Definition: DQWorker.h:36
virtual bool isInitialized()
Definition: DQWorker.h:37
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
Definition: DQWorkerTask.h:17
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
Definition: DQWorker.h:30
virtual void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
Definition: DQWorker.h:31
void registerCollection(ecaldqm::Collections, edm::InputTag const &)
bool first
Definition: L1TdeRCT.cc:79
DQWorker *(* WorkerFactory)(const edm::ParameterSet &, const edm::ParameterSet &)
Definition: DQWorker.h:64
static WorkerFactory findFactory(const std::string &)
Definition: DQWorker.cc:131
virtual bool filterRunType(const std::vector< short > &)
Definition: DQWorkerTask.cc:26
virtual void endRun(const edm::Run &, const edm::EventSetup &)
Definition: DQWorker.h:28
virtual void bookMEs()
Definition: DQWorker.cc:48
std::vector< std::pair< Processor, ecaldqm::Collections > > schedule_
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::vector< ecaldqm::DQWorkerTask * > taskLists_[ecaldqm::nCollections]
virtual const std::vector< std::pair< Collections, Collections > > & getDependencies()
Definition: DQWorkerTask.cc:13
void beginRun(edm::Run const &, edm::EventSetup const &)
EcalDQMonitorTask(edm::ParameterSet const &)
tuple cout
Definition: gather_cfg.py:121
const int verbosity_
Definition: EcalDQMonitor.h:24
void endRun(edm::Run const &, edm::EventSetup const &)
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: Run.h:41