CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/EcalBarrelMonitorTasks/src/EBDaqInfoTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBDaqInfoTask.cc
00003  *
00004  * $Date: 2011/08/30 09:30:32 $
00005  * $Revision: 1.12 $
00006  * \author E. Di Marco
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <vector>
00012 
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 
00018 #include "CondFormats/EcalObjects/interface/EcalDAQTowerStatus.h"
00019 #include "CondFormats/DataRecord/interface/EcalDAQTowerStatusRcd.h"
00020 
00021 #include "DQMServices/Core/interface/MonitorElement.h"
00022 #include "DQMServices/Core/interface/DQMStore.h"
00023 
00024 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00025 
00026 #include "DQM/EcalCommon/interface/Numbers.h"
00027 
00028 #include "DQM/EcalBarrelMonitorTasks/interface/EBDaqInfoTask.h"
00029 
00030 EBDaqInfoTask::EBDaqInfoTask(const edm::ParameterSet& ps) {
00031 
00032   dqmStore_ = edm::Service<DQMStore>().operator->();
00033 
00034   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00035 
00036   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00037 
00038   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00039 
00040   meEBDaqFraction_ = 0;
00041   meEBDaqActiveMap_ = 0;
00042   for (int i = 0; i < 36; i++) {
00043     meEBDaqActive_[i] = 0;
00044   }
00045 
00046 }
00047 
00048 EBDaqInfoTask::~EBDaqInfoTask() {
00049 
00050 }
00051 
00052 void EBDaqInfoTask::beginJob(void){
00053 
00054   std::string name;
00055 
00056   if ( dqmStore_ ) {
00057 
00058     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00059 
00060     name = "DAQSummary";
00061     meEBDaqFraction_ = dqmStore_->bookFloat(name);
00062     meEBDaqFraction_->Fill(0.0);
00063 
00064     name = "DAQSummaryMap";
00065     meEBDaqActiveMap_ = dqmStore_->book2D(name, name, 72, 0., 72., 34, 0., 34.);
00066     meEBDaqActiveMap_->setAxisTitle("jphi", 1);
00067     meEBDaqActiveMap_->setAxisTitle("jeta", 2);
00068 
00069     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DAQContents");
00070 
00071     for (int i = 0; i < 36; i++) {
00072       name = "EcalBarrel_" + Numbers::sEB(i+1);
00073       meEBDaqActive_[i] = dqmStore_->bookFloat(name);
00074       meEBDaqActive_[i]->Fill(0.0);
00075     }
00076 
00077   }
00078 
00079 }
00080 
00081 void EBDaqInfoTask::endJob(void) {
00082 
00083   if ( enableCleanup_ ) this->cleanup();
00084 
00085 }
00086 
00087 void EBDaqInfoTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const  edm::EventSetup& iSetup){
00088 
00089   // information is by run, so fill the same for the run and for every lumi section
00090   for ( int iett = 0; iett < 34; iett++ ) {
00091     for ( int iptt = 0; iptt < 72; iptt++ ) {
00092       readyLumi[iptt][iett] = 1;
00093     }
00094   }
00095 
00096 
00097   if ( !iSetup.find( edm::eventsetup::EventSetupRecordKey::makeKey<EcalDAQTowerStatusRcd>() ) ) {
00098     edm::LogWarning("EBDaqInfoTask") << "EcalDAQTowerStatus record not found";
00099     return;
00100   }
00101 
00102   edm::ESHandle<EcalDAQTowerStatus> pDAQStatus;
00103   iSetup.get<EcalDAQTowerStatusRcd>().get(pDAQStatus);
00104     if ( !pDAQStatus.isValid() ) {
00105     edm::LogWarning("EBDaqInfoTask") << "EcalDAQTowerStatus record not valid";
00106     return;
00107   }
00108   const EcalDAQTowerStatus* daqStatus = pDAQStatus.product();
00109 
00110   for(int iz=-1; iz<=1; iz+=2) {
00111     for(int iptt=0 ; iptt<72; iptt++) {
00112       for(int iett=0 ; iett<17; iett++) {
00113         if (EcalTrigTowerDetId::validDetId(iz,EcalBarrel,iett+1,iptt+1 )){
00114 
00115           EcalTrigTowerDetId ebid(iz,EcalBarrel,iett+1,iptt+1);
00116 
00117           uint16_t dbStatus = 0; // 0 = good
00118           EcalDAQTowerStatus::const_iterator daqStatusIt = daqStatus->find( ebid.rawId() );
00119           if ( daqStatusIt != daqStatus->end() ) dbStatus = daqStatusIt->getStatusCode();
00120 
00121           if ( dbStatus > 0 ) {
00122             int ipttEB = iptt;
00123             int iettEB = (iz==-1) ? iett : 17+iett;
00124             readyRun[ipttEB][iettEB] = 0;
00125             readyLumi[ipttEB][iettEB] = 0;
00126           }
00127 
00128         }
00129       }
00130     }
00131   }
00132 
00133 }
00134 
00135 
00136 
00137 void EBDaqInfoTask::endLuminosityBlock(const edm::LuminosityBlock&  lumiBlock, const  edm::EventSetup& iSetup) {
00138 
00139     this->fillMonitorElements(readyLumi);
00140 
00141 }
00142 
00143 void EBDaqInfoTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00144 
00145   if ( ! mergeRuns_ ) this->reset();
00146 
00147   for ( int iett = 0; iett < 34; iett++ ) {
00148     for ( int iptt = 0; iptt < 72; iptt++ ) {
00149       readyRun[iptt][iett] = 1;
00150     }
00151   }
00152 
00153 }
00154 
00155 void EBDaqInfoTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00156 
00157   this->fillMonitorElements(readyRun);
00158 
00159 }
00160 
00161 void EBDaqInfoTask::reset(void) {
00162 
00163   if ( meEBDaqFraction_ ) meEBDaqFraction_->Reset();
00164 
00165   for (int i = 0; i < 36; i++) {
00166     if ( meEBDaqActive_[i] ) meEBDaqActive_[i]->Reset();
00167   }
00168 
00169   if ( meEBDaqActiveMap_ ) meEBDaqActiveMap_->Reset();
00170 
00171 }
00172 
00173 
00174 void EBDaqInfoTask::cleanup(void){
00175 
00176   if ( dqmStore_ ) {
00177 
00178     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00179 
00180     if ( meEBDaqFraction_ ) dqmStore_->removeElement( meEBDaqFraction_->getName() );
00181 
00182     if ( meEBDaqActiveMap_ ) dqmStore_->removeElement( meEBDaqActiveMap_->getName() );
00183 
00184     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DAQContents");
00185 
00186     for (int i = 0; i < 36; i++) {
00187       if ( meEBDaqActive_[i] ) dqmStore_->removeElement( meEBDaqActive_[i]->getName() );
00188     }
00189 
00190   }
00191 
00192 }
00193 
00194 void EBDaqInfoTask::fillMonitorElements(int ready[72][34]) {
00195 
00196   float readySum[36];
00197   for ( int ism = 0; ism < 36; ism++ ) readySum[ism] = 0;
00198   float readySumTot = 0.;
00199 
00200   for ( int iett = 0; iett < 34; iett++ ) {
00201     for ( int iptt = 0; iptt < 72; iptt++ ) {
00202 
00203       if(meEBDaqActiveMap_) meEBDaqActiveMap_->setBinContent( iptt+1, iett+1, ready[iptt][iett] );
00204 
00205       int ism = ( iett<17 ) ? iptt/4 : 18+iptt/4;
00206       if(ready[iptt][iett]) {
00207         readySum[ism]++;
00208         readySumTot++;
00209       }
00210 
00211     }
00212   }
00213 
00214   for ( int ism = 0; ism < 36; ism++ ) {
00215     if( meEBDaqActive_[ism] ) meEBDaqActive_[ism]->Fill( readySum[ism]/68. );
00216   }
00217 
00218   if( meEBDaqFraction_ ) meEBDaqFraction_->Fill(readySumTot/34./72.);
00219 
00220 }
00221 
00222 void EBDaqInfoTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00223 
00224 }