CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDQMonitorTask2.cc
Go to the documentation of this file.
2 
4 
16 
17 #include "TStopwatch.h"
18 
19 void
21 {
22  switch(_collection){
23  case ecaldqm::kSource:
24  collectionTokens_[_collection] = edm::EDGetToken(consumes<FEDRawDataCollection>(_inputTag)); break;
26  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalRawDataCollection>(_inputTag)); break;
28  collectionTokens_[_collection] = edm::EDGetToken(consumes<DetIdCollection>(_inputTag)); break;
30  collectionTokens_[_collection] = edm::EDGetToken(consumes<DetIdCollection>(_inputTag)); break;
32  collectionTokens_[_collection] = edm::EDGetToken(consumes<DetIdCollection>(_inputTag)); break;
34  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalElectronicsIdCollection>(_inputTag)); break;
36  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalElectronicsIdCollection>(_inputTag)); break;
38  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalElectronicsIdCollection>(_inputTag)); break;
40  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalElectronicsIdCollection>(_inputTag)); break;
42  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalElectronicsIdCollection>(_inputTag)); break;
44  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalElectronicsIdCollection>(_inputTag)); break;
45  case ecaldqm::kEBSrFlag:
46  collectionTokens_[_collection] = edm::EDGetToken(consumes<EBSrFlagCollection>(_inputTag)); break;
47  case ecaldqm::kEESrFlag:
48  collectionTokens_[_collection] = edm::EDGetToken(consumes<EESrFlagCollection>(_inputTag)); break;
49  case ecaldqm::kEBDigi:
50  collectionTokens_[_collection] = edm::EDGetToken(consumes<EBDigiCollection>(_inputTag)); break;
51  case ecaldqm::kEEDigi:
52  collectionTokens_[_collection] = edm::EDGetToken(consumes<EEDigiCollection>(_inputTag)); break;
54  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalPnDiodeDigiCollection>(_inputTag)); break;
56  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalTrigPrimDigiCollection>(_inputTag)); break;
58  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalTrigPrimDigiCollection>(_inputTag)); break;
60  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalUncalibratedRecHitCollection>(_inputTag)); break;
62  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalUncalibratedRecHitCollection>(_inputTag)); break;
63  case ecaldqm::kEBRecHit:
64  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalRecHitCollection>(_inputTag)); break;
65  case ecaldqm::kEERecHit:
66  collectionTokens_[_collection] = edm::EDGetToken(consumes<EcalRecHitCollection>(_inputTag)); break;
68  collectionTokens_[_collection] = edm::EDGetToken(consumes<reco::BasicClusterCollection>(_inputTag)); break;
70  collectionTokens_[_collection] = edm::EDGetToken(consumes<reco::BasicClusterCollection>(_inputTag)); break;
72  collectionTokens_[_collection] = edm::EDGetToken(consumes<reco::SuperClusterCollection>(_inputTag)); break;
74  collectionTokens_[_collection] = edm::EDGetToken(consumes<reco::SuperClusterCollection>(_inputTag)); break;
75  default:
76  throw cms::Exception("InvalidConfiguration") << "Undefined collection " << _collection;
77  }
78 }
79 
80 template <class C>
81 void
83 {
84  edm::Handle<C> hndl;
85  if(_evt.getByToken(collectionTokens_[_collection], hndl)){
86 
87  TStopwatch* sw(0);
88  if(evaluateTime_){
89  sw = new TStopwatch;
90  sw->Stop();
91  }
92 
93  ecaldqm::DQWorkerTask* task(0);
94 
95  for(std::vector<ecaldqm::DQWorkerTask *>::iterator wItr(taskLists_[_collection].begin()); wItr != taskLists_[_collection].end(); ++wItr){
96  task = *wItr;
97  if(evaluateTime_) sw->Start();
98  if(enabled_[task]) task->analyze(hndl.product(), _collection);
99  if(evaluateTime_){
100  sw->Stop();
101  taskTimes_[task] += sw->RealTime();
102  }
103  }
104 
105  delete sw;
106  }
107  else if(!allowMissingCollections_)
108  throw cms::Exception("ObjectNotFound") << ecaldqm::collectionName[_collection] << " does not exist";
109 }
110 
111 template <>
112 void
113 EcalDQMonitorTask::runOnCollection<DetIdCollection>(edm::Event const& _evt, ecaldqm::Collections _collection)
114 {
117  if(_evt.getByToken(collectionTokens_[_collection], ebHndl) && _evt.getByToken(collectionTokens_[_collection], eeHndl)){
118  unsigned nEB(ebHndl->size());
119  unsigned nEE(eeHndl->size());
120 
121  if(nEB == 0 && nEE == 0) return;
122 
123  DetIdCollection ids;
124  for(unsigned iId(0); iId < nEB; iId++) ids.push_back(DetId(ebHndl->at(iId)));
125  for(unsigned iId(0); iId < nEE; iId++) ids.push_back(DetId(eeHndl->at(iId)));
126 
127  TStopwatch* sw(0);
128  if(evaluateTime_){
129  sw = new TStopwatch;
130  sw->Stop();
131  }
132 
133  ecaldqm::DQWorkerTask* task(0);
134 
135  for(std::vector<ecaldqm::DQWorkerTask *>::iterator wItr(taskLists_[_collection].begin()); wItr != taskLists_[_collection].end(); ++wItr){
136  task = *wItr;
137  if(evaluateTime_) sw->Start();
138  if(enabled_[task]) task->analyze(const_cast<const DetIdCollection*>(&ids), _collection);
139  if(evaluateTime_){
140  sw->Stop();
141  taskTimes_[task] += sw->RealTime();
142  }
143  }
144 
145  delete sw;
146  }
147  else if(!allowMissingCollections_)
148  throw cms::Exception("ObjectNotFound") << ecaldqm::collectionName[_collection] << " does not exist";
149 }
150 
151 void
152 EcalDQMonitorTask::formSchedule_(std::vector<ecaldqm::Collections> const& _usedCollections, std::multimap<ecaldqm::Collections, ecaldqm::Collections> const& _dependencies)
153 {
154  typedef std::multimap<ecaldqm::Collections, ecaldqm::Collections>::const_iterator mmiter;
155 
156  std::vector<ecaldqm::Collections> preSchedule;
157  std::vector<ecaldqm::Collections>::iterator insertPoint, findPoint;
158 
159  for(std::vector<ecaldqm::Collections>::const_iterator colItr(_usedCollections.begin()); colItr != _usedCollections.end(); ++colItr){
160 
161  bool inserted(true);
162  if((insertPoint = find(preSchedule.begin(), preSchedule.end(), *colItr)) == preSchedule.end()) inserted = false;
163 
164  std::pair<mmiter, mmiter> range(_dependencies.equal_range(*colItr));
165 
166  for(mmiter depItr(range.first); depItr != range.second; ++depItr){
167 
168  if(depItr->second == depItr->first)
169  throw cms::Exception("Fatal") << "Collection " << depItr->second << " depends on itself";
170  if(find(_usedCollections.begin(), _usedCollections.end(), depItr->second) == _usedCollections.end())
171  throw cms::Exception("Fatal") << "Collection " << depItr->first << " depends on Collection " << depItr->second;
172 
173  if((findPoint = find(preSchedule.begin(), preSchedule.end(), depItr->second)) == preSchedule.end())
174  preSchedule.insert(insertPoint, depItr->second);
175  else if(findPoint > insertPoint)
176  throw cms::Exception("InvalidConfiguration") << "Circular dependencies in Collections";
177 
178  }
179 
180  if(!inserted) preSchedule.push_back(*colItr);
181 
182  }
183 
184  for(std::vector<ecaldqm::Collections>::const_iterator colItr(preSchedule.begin()); colItr != preSchedule.end(); ++colItr){
185  std::pair<Processor, ecaldqm::Collections> sch;
186 
187  switch(*colItr){
188  case ecaldqm::kSource:
189  sch.first = &EcalDQMonitorTask::runOnCollection<FEDRawDataCollection>; break;
191  sch.first = &EcalDQMonitorTask::runOnCollection<EcalRawDataCollection>; break;
193  sch.first = &EcalDQMonitorTask::runOnCollection<DetIdCollection>; break;
195  sch.first = &EcalDQMonitorTask::runOnCollection<DetIdCollection>; break;
197  sch.first = &EcalDQMonitorTask::runOnCollection<DetIdCollection>; break;
199  sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
201  sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
203  sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
205  sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
207  sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
209  sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
210  case ecaldqm::kEBSrFlag:
211  sch.first = &EcalDQMonitorTask::runOnCollection<EBSrFlagCollection>; break;
212  case ecaldqm::kEESrFlag:
213  sch.first = &EcalDQMonitorTask::runOnCollection<EESrFlagCollection>; break;
214  case ecaldqm::kEBDigi:
215  sch.first = &EcalDQMonitorTask::runOnCollection<EBDigiCollection>; break;
216  case ecaldqm::kEEDigi:
217  sch.first = &EcalDQMonitorTask::runOnCollection<EEDigiCollection>; break;
219  sch.first = &EcalDQMonitorTask::runOnCollection<EcalPnDiodeDigiCollection>; break;
221  sch.first = &EcalDQMonitorTask::runOnCollection<EcalTrigPrimDigiCollection>; break;
223  sch.first = &EcalDQMonitorTask::runOnCollection<EcalTrigPrimDigiCollection>; break;
225  sch.first = &EcalDQMonitorTask::runOnCollection<EcalUncalibratedRecHitCollection>; break;
227  sch.first = &EcalDQMonitorTask::runOnCollection<EcalUncalibratedRecHitCollection>; break;
228  case ecaldqm::kEBRecHit:
229  sch.first = &EcalDQMonitorTask::runOnCollection<EcalRecHitCollection>; break;
230  case ecaldqm::kEERecHit:
231  sch.first = &EcalDQMonitorTask::runOnCollection<EcalRecHitCollection>; break;
233  sch.first = &EcalDQMonitorTask::runOnCollection<reco::BasicClusterCollection>; break;
235  sch.first = &EcalDQMonitorTask::runOnCollection<reco::BasicClusterCollection>; break;
237  sch.first = &EcalDQMonitorTask::runOnCollection<reco::SuperClusterCollection>; break;
239  sch.first = &EcalDQMonitorTask::runOnCollection<reco::SuperClusterCollection>; break;
240  default:
241  throw cms::Exception("InvalidConfiguration") << "Undefined collection " << *colItr;
242  }
243 
244  sch.second = *colItr;
245 
246  schedule_.push_back(sch);
247  }
248 
249 }
std::map< ecaldqm::DQWorkerTask *, bool > enabled_
void formSchedule_(std::vector< ecaldqm::Collections > const &, std::multimap< ecaldqm::Collections, ecaldqm::Collections > const &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetToken collectionTokens_[ecaldqm::nCollections]
void push_back(T const &t)
Definition: EDCollection.h:67
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::map< ecaldqm::DQWorkerTask *, double > taskTimes_
std::string const collectionName[nCollections]
Definition: Collections.h:39
virtual void analyze(const void *, Collections)
Definition: DQWorkerTask.h:25
void registerCollection(ecaldqm::Collections, edm::InputTag const &)
Definition: DetId.h:18
std::vector< std::pair< Processor, ecaldqm::Collections > > schedule_
std::vector< ecaldqm::DQWorkerTask * > taskLists_[ecaldqm::nCollections]
T const * product() const
Definition: Handle.h:81
#define begin
Definition: vmac.h:30
void runOnCollection(edm::Event const &, ecaldqm::Collections)