CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/EcalCommon/src/EcalDQMonitorTask2.cc

Go to the documentation of this file.
00001 #include "DQM/EcalCommon/interface/EcalDQMonitorTask.h"
00002 
00003 #include "DQM/EcalCommon/interface/DQWorkerTask.h"
00004 
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 #include "DataFormats/Common/interface/Handle.h"
00008 #include "DataFormats/DetId/interface/DetIdCollection.h"
00009 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00010 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00011 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00012 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00013 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00014 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00015 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00016 
00017 #include "TStopwatch.h"
00018 
00019 using namespace ecaldqm;
00020 
00021 template <class C>
00022 void
00023 EcalDQMonitorTask::runOnCollection(const edm::Event& _evt, Collections _colName)
00024 {
00025   edm::Handle<C> hndl;
00026   if(_evt.getByLabel(collectionTags_[_colName], hndl)){
00027 
00028     TStopwatch* sw(0);
00029     if(evaluateTime_){
00030       sw = new TStopwatch;
00031       sw->Stop();
00032     }
00033 
00034     DQWorkerTask* task(0);
00035 
00036     for(std::vector<DQWorkerTask *>::iterator wItr(taskLists_[_colName].begin()); wItr != taskLists_[_colName].end(); ++wItr){
00037       task = *wItr;
00038       if(evaluateTime_) sw->Start();
00039       if(enabled_[task]) task->analyze(hndl.product(), _colName);
00040       if(evaluateTime_){
00041         sw->Stop();
00042         taskTimes_[task] += sw->RealTime();
00043       }
00044     }
00045 
00046     delete sw;
00047   }
00048   else if(!allowMissingCollections_)
00049     throw cms::Exception("ObjectNotFound") << "Collection with InputTag " << collectionTags_[_colName] << " does not exist";
00050 }
00051 
00052 template <>
00053 void
00054 EcalDQMonitorTask::runOnCollection<DetIdCollection>(const edm::Event& _evt, Collections _colName)
00055 {
00056   edm::Handle<EBDetIdCollection> ebHndl;
00057   edm::Handle<EEDetIdCollection> eeHndl;
00058   if(_evt.getByLabel(collectionTags_[_colName], ebHndl) && _evt.getByLabel(collectionTags_[_colName], eeHndl)){
00059     unsigned nEB(ebHndl->size());
00060     unsigned nEE(eeHndl->size());
00061 
00062     if(nEB == 0 && nEE == 0) return;
00063 
00064     DetIdCollection ids;
00065     for(unsigned iId(0); iId < nEB; iId++) ids.push_back(DetId(ebHndl->at(iId)));
00066     for(unsigned iId(0); iId < nEE; iId++) ids.push_back(DetId(eeHndl->at(iId)));
00067 
00068     TStopwatch* sw(0);
00069     if(evaluateTime_){
00070       sw = new TStopwatch;
00071       sw->Stop();
00072     }
00073 
00074     DQWorkerTask* task(0);
00075 
00076     for(std::vector<DQWorkerTask *>::iterator wItr(taskLists_[_colName].begin()); wItr != taskLists_[_colName].end(); ++wItr){
00077       task = *wItr;
00078       if(evaluateTime_) sw->Start();
00079       if(enabled_[task]) task->analyze(const_cast<const DetIdCollection*>(&ids), _colName);
00080       if(evaluateTime_){
00081         sw->Stop();
00082         taskTimes_[task] += sw->RealTime();
00083       }
00084     }
00085 
00086     delete sw;
00087   }
00088   else if(!allowMissingCollections_)
00089     throw cms::Exception("ObjectNotFound") << "DetIdCollection with InputTag " << collectionTags_[_colName] << " does not exist";
00090 }
00091 
00092 void
00093 EcalDQMonitorTask::formSchedule_(const std::vector<Collections>& _usedCollections, const std::multimap<Collections, Collections>& _dependencies)
00094 {
00095   using namespace std;
00096   typedef multimap<Collections, Collections>::const_iterator mmiter;
00097 
00098   vector<Collections> preSchedule;
00099   vector<Collections>::iterator insertPoint, findPoint;
00100 
00101   for(vector<Collections>::const_iterator colItr(_usedCollections.begin()); colItr != _usedCollections.end(); ++colItr){
00102 
00103     bool inserted(true);
00104     if((insertPoint = find(preSchedule.begin(), preSchedule.end(), *colItr)) == preSchedule.end()) inserted = false;
00105 
00106     pair<mmiter, mmiter> range(_dependencies.equal_range(*colItr));
00107 
00108     for(mmiter depItr(range.first); depItr != range.second; ++depItr){
00109 
00110       if(depItr->second == depItr->first)
00111         throw cms::Exception("Fatal") << "Collection " << depItr->second << " depends on itself";
00112       if(find(_usedCollections.begin(), _usedCollections.end(), depItr->second) == _usedCollections.end())
00113         throw cms::Exception("Fatal") << "Collection " << depItr->first << " depends on Collection " << depItr->second;
00114 
00115       if((findPoint = find(preSchedule.begin(), preSchedule.end(), depItr->second)) == preSchedule.end())
00116         preSchedule.insert(insertPoint, depItr->second);
00117       else if(findPoint > insertPoint)
00118         throw cms::Exception("InvalidConfiguration") << "Circular dependencies in Collections";
00119 
00120     }
00121 
00122     if(!inserted) preSchedule.push_back(*colItr);
00123 
00124   }
00125 
00126   for(vector<Collections>::const_iterator colItr(preSchedule.begin()); colItr != preSchedule.end(); ++colItr){
00127     std::pair<Processor, Collections> sch;
00128 
00129     switch(*colItr){
00130     case kSource:
00131       sch.first = &EcalDQMonitorTask::runOnCollection<FEDRawDataCollection>; break;
00132     case kEcalRawData:
00133       sch.first = &EcalDQMonitorTask::runOnCollection<EcalRawDataCollection>; break;
00134     case kGainErrors:
00135       sch.first = &EcalDQMonitorTask::runOnCollection<DetIdCollection>; break;
00136     case kChIdErrors:
00137       sch.first = &EcalDQMonitorTask::runOnCollection<DetIdCollection>; break;
00138     case kGainSwitchErrors:
00139       sch.first = &EcalDQMonitorTask::runOnCollection<DetIdCollection>; break;
00140     case kTowerIdErrors:
00141       sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
00142     case kBlockSizeErrors:
00143       sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
00144     case kMEMTowerIdErrors:
00145       sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
00146     case kMEMBlockSizeErrors:
00147       sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
00148     case kMEMChIdErrors:
00149       sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
00150     case kMEMGainErrors:
00151       sch.first = &EcalDQMonitorTask::runOnCollection<EcalElectronicsIdCollection>; break;
00152     case kEBSrFlag:
00153       sch.first = &EcalDQMonitorTask::runOnCollection<EBSrFlagCollection>; break;
00154     case kEESrFlag:
00155       sch.first = &EcalDQMonitorTask::runOnCollection<EESrFlagCollection>; break;
00156     case kEBDigi:
00157       sch.first = &EcalDQMonitorTask::runOnCollection<EBDigiCollection>; break;
00158     case kEEDigi:
00159       sch.first = &EcalDQMonitorTask::runOnCollection<EEDigiCollection>; break;
00160     case kPnDiodeDigi:
00161       sch.first = &EcalDQMonitorTask::runOnCollection<EcalPnDiodeDigiCollection>; break;
00162     case kTrigPrimDigi:
00163       sch.first = &EcalDQMonitorTask::runOnCollection<EcalTrigPrimDigiCollection>; break;
00164     case kTrigPrimEmulDigi:
00165       sch.first = &EcalDQMonitorTask::runOnCollection<EcalTrigPrimDigiCollection>; break;
00166     case kEBUncalibRecHit:
00167       sch.first = &EcalDQMonitorTask::runOnCollection<EcalUncalibratedRecHitCollection>; break;
00168     case kEEUncalibRecHit:
00169       sch.first = &EcalDQMonitorTask::runOnCollection<EcalUncalibratedRecHitCollection>; break;
00170     case kEBRecHit:
00171       sch.first = &EcalDQMonitorTask::runOnCollection<EcalRecHitCollection>; break;
00172     case kEERecHit:
00173       sch.first = &EcalDQMonitorTask::runOnCollection<EcalRecHitCollection>; break;
00174     case kEBBasicCluster:
00175       sch.first = &EcalDQMonitorTask::runOnCollection<reco::BasicClusterCollection>; break;
00176     case kEEBasicCluster:
00177       sch.first = &EcalDQMonitorTask::runOnCollection<reco::BasicClusterCollection>; break;
00178     case kEBSuperCluster:
00179       sch.first = &EcalDQMonitorTask::runOnCollection<reco::SuperClusterCollection>; break;
00180     case kEESuperCluster:
00181       sch.first = &EcalDQMonitorTask::runOnCollection<reco::SuperClusterCollection>; break;
00182     default:
00183       throw cms::Exception("InvalidConfiguration") << "Undefined collection " << *colItr;
00184     }
00185 
00186     sch.second = *colItr;
00187 
00188     schedule_.push_back(sch);
00189   }
00190 
00191 }