CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DQM/EcalCommon/src/EcalDQMonitorTask.cc

Go to the documentation of this file.
00001 #include "DQM/EcalCommon/interface/EcalDQMonitorTask.h"
00002 
00003 #include <algorithm>
00004 #include <iomanip>
00005 
00006 #include "DQM/EcalCommon/interface/DQWorkerTask.h"
00007 #include "DQM/EcalCommon/interface/MESet.h"
00008 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
00009 
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Framework/interface/Run.h"
00013 #include "FWCore/Framework/interface/Event.h"
00014 
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00017 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00018 
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 
00021 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00022 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00023 
00024 #include "DataFormats/Common/interface/Handle.h"
00025 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00026 
00027 using namespace ecaldqm;
00028 
00029 EcalDQMonitorTask::EcalDQMonitorTask(const edm::ParameterSet &_ps) :
00030   EcalDQMonitor(_ps),
00031   ievt_(0),
00032   workers_(0),
00033   schedule_(),
00034   enabled_(),
00035   taskTimes_(),
00036   evaluateTime_(_ps.getUntrackedParameter<bool>("evaluateTime")),
00037   allowMissingCollections_(_ps.getUntrackedParameter<bool>("allowMissingCollections"))
00038 {
00039   using namespace std;
00040 
00041   vector<string> taskNames(_ps.getUntrackedParameter<vector<string> >("tasks"));
00042   const edm::ParameterSet& taskParams(_ps.getUntrackedParameterSet("taskParameters"));
00043   const edm::ParameterSet& mePaths(_ps.getUntrackedParameterSet("mePaths"));
00044 
00045   WorkerFactory factory(0);
00046   std::multimap<Collections, Collections> dependencies;
00047 
00048   for(vector<string>::iterator tItr(taskNames.begin()); tItr != taskNames.end(); ++tItr){
00049     if (!(factory = SetWorker::findFactory(*tItr))) continue;
00050 
00051     if(verbosity_ > 0) cout << moduleName_ << ": Setting up " << *tItr << endl;
00052 
00053     DQWorker* worker(factory(taskParams, mePaths.getUntrackedParameterSet(*tItr)));
00054     if(worker->getName() != *tItr){
00055       delete worker;
00056 
00057       if(verbosity_ > 0) cout << moduleName_ << ": " << *tItr << " could not be configured" << endl; 
00058       continue;
00059     }
00060     DQWorkerTask* task(static_cast<DQWorkerTask*>(worker));
00061     task->setVerbosity(verbosity_);
00062 
00063     workers_.push_back(task);
00064 
00065     const std::vector<std::pair<Collections, Collections> >& dep(task->getDependencies());
00066     for(std::vector<std::pair<Collections, Collections> >::const_iterator depItr(dep.begin()); depItr != dep.end(); ++depItr)
00067       dependencies.insert(*depItr);
00068   }
00069 
00070   const edm::ParameterSet& collectionTags(_ps.getUntrackedParameterSet("collectionTags"));
00071 
00072   std::vector<Collections> usedCollections;
00073 
00074   for(unsigned iCol(0); iCol < nCollections; iCol++){
00075 
00076     collectionTags_[iCol] = edm::InputTag();
00077     taskLists_[iCol] = vector<DQWorkerTask*>();
00078 
00079     bool use(iCol == kEcalRawData);
00080 
00081     for(vector<DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
00082       if((*wItr)->runsOn(iCol)){
00083         taskLists_[iCol].push_back(*wItr);
00084         use = true;
00085       }
00086     }
00087     if(use){
00088       collectionTags_[iCol] = collectionTags.getUntrackedParameter<edm::InputTag>(collectionName[iCol]);
00089       usedCollections.push_back(Collections(iCol));
00090     }
00091 
00092   }
00093 
00094   formSchedule_(usedCollections, dependencies);
00095 
00096   if(verbosity_ > 0){
00097     cout << moduleName_ << ": Using collections" << endl;
00098     for(unsigned iCol(0); iCol < schedule_.size(); iCol++)
00099       cout << collectionName[schedule_[iCol].second] << endl;
00100     cout << endl;
00101   }
00102 }
00103 
00104 EcalDQMonitorTask::~EcalDQMonitorTask()
00105 {
00106   for(std::vector<DQWorkerTask *>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr)
00107     delete *wItr;
00108 }
00109 
00110 /* static */
00111 void
00112 EcalDQMonitorTask::fillDescriptions(edm::ConfigurationDescriptions &_descs)
00113 {
00114   edm::ParameterSetDescription desc;
00115   desc.setUnknown();
00116   _descs.addDefault(desc);
00117 }
00118 
00119 void
00120 EcalDQMonitorTask::beginRun(const edm::Run &_run, const edm::EventSetup &_es)
00121 {
00122   // set up ecaldqm::electronicsMap in EcalDQMCommonUtils
00123   edm::ESHandle<EcalElectronicsMapping> elecMapHandle;
00124   _es.get<EcalMappingRcd>().get(elecMapHandle);
00125   setElectronicsMap(elecMapHandle.product());
00126 
00127   // set up ecaldqm::electronicsMap in EcalDQMCommonUtils
00128   edm::ESHandle<EcalTrigTowerConstituentsMap> ttMapHandle;
00129   _es.get<IdealGeometryRecord>().get(ttMapHandle);
00130   setTrigTowerMap(ttMapHandle.product());
00131 
00132   for(std::vector<DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
00133     DQWorkerTask* task(*wItr);
00134     task->reset();
00135     if(task->runsOn(kRun)) task->beginRun(_run, _es);
00136   }
00137 
00138   if(verbosity_ > 0)
00139     std::cout << moduleName_ << ": Starting run " << _run.run() << std::endl;
00140 
00141   ievt_ = 0;
00142   taskTimes_.clear();
00143 }
00144 
00145 void
00146 EcalDQMonitorTask::endRun(const edm::Run &_run, const edm::EventSetup &_es)
00147 {
00148   using namespace std;
00149 
00150   for(vector<DQWorkerTask *>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
00151     DQWorkerTask* task(*wItr);
00152     if(task->runsOn(kRun)) task->endRun(_run, _es);
00153   }
00154 
00155   if(evaluateTime_){
00156     stringstream ss;
00157 
00158     ss << "************** " << moduleName_ << " **************" << endl;
00159     ss << "      Mean time consumption of the modules" << endl;
00160     ss << "____________________________________" << endl;
00161     for(std::vector<DQWorkerTask *>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
00162       DQWorkerTask* task(*wItr);
00163       ss << setw(20) << setfill(' ') << task->getName() << "|   " << (taskTimes_[task] / ievt_) << endl;
00164     }
00165     edm::LogInfo("EcalDQM") << ss.str();
00166   }
00167 }
00168 
00169 void
00170 EcalDQMonitorTask::beginLuminosityBlock(const edm::LuminosityBlock &_lumi, const edm::EventSetup &_es)
00171 {
00172   for(std::vector<DQWorkerTask *>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
00173     DQWorkerTask* task(*wItr);
00174     if(task->isInitialized() && task->runsOn(kLumiSection)) task->beginLuminosityBlock(_lumi, _es);
00175   }
00176 }
00177 
00178 void
00179 EcalDQMonitorTask::endLuminosityBlock(const edm::LuminosityBlock &_lumi, const edm::EventSetup &_es)
00180 {
00181   for(std::vector<DQWorkerTask *>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
00182     DQWorkerTask* task(*wItr);
00183     if(task->isInitialized() && task->runsOn(kLumiSection)) task->endLuminosityBlock(_lumi, _es);
00184   }
00185 }
00186 
00187 void
00188 EcalDQMonitorTask::analyze(const edm::Event &_evt, const edm::EventSetup &_es)
00189 {
00190   using namespace std;
00191   using namespace ecaldqm;
00192 
00193   ievt_++;
00194 
00195   edm::Handle<EcalRawDataCollection> dcchsHndl;
00196   if(!_evt.getByLabel(collectionTags_[kEcalRawData], dcchsHndl))
00197     throw cms::Exception("ObjectNotFound") << "EcalRawDataCollection with InputTag " << collectionTags_[kEcalRawData] << " does not exist";
00198  
00199   // determine event type (called run type in DCCHeader for some reason) for each FED
00200   std::vector<short> runType(54, -1);
00201   for(EcalRawDataCollection::const_iterator dcchItr = dcchsHndl->begin(); dcchItr != dcchsHndl->end(); ++dcchItr){
00202     runType[dcchItr->id() - 1] = dcchItr->getRunType();
00203   }
00204 
00205   bool atLeastOne(false);
00206 
00207   DQWorkerTask *task(0);
00208 
00209   // set up task modules
00210   for(vector<DQWorkerTask*>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
00211     task = *wItr;
00212 
00213     if(task->filterRunType(runType)){
00214       enabled_[task] = true;
00215 
00216       if(!task->isInitialized()){
00217         if(verbosity_ > 1) cout << moduleName_ << ": Booking MEs for " << task->getName() << endl;
00218         task->bookMEs();
00219         task->setInitialized(true);
00220       }
00221 
00222       task->beginEvent(_evt, _es);
00223       atLeastOne = true;
00224     }else{
00225       enabled_[task] = false;
00226     }
00227   }
00228 
00229   if(!atLeastOne) return;
00230 
00231   // run on collections
00232   for(unsigned iSch(0); iSch < schedule_.size(); iSch++){
00233     Processor processor(schedule_[iSch].first);
00234     (this->*processor)(_evt, schedule_[iSch].second);
00235   }
00236 
00237   // close event
00238   for(vector<DQWorkerTask *>::iterator wItr(workers_.begin()); wItr != workers_.end(); ++wItr){
00239     task = *wItr;
00240     if(enabled_[task]) task->endEvent(_evt, _es);
00241   }
00242 
00243 }