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