CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/EcalPreshowerMonitorModule/src/ESFEDIntegrityTask.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <vector>
00004 
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 
00011 #include "DQMServices/Core/interface/MonitorElement.h"
00012 #include "DQMServices/Core/interface/DQMStore.h"
00013 #include "DQM/EcalPreshowerMonitorModule/interface/ESFEDIntegrityTask.h"
00014 
00015 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00016 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00017 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00018 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00019 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00020 #include "DataFormats/FEDRawData/src/fed_header.h"
00021 #include "DataFormats/EcalRawData/interface/ESDCCHeaderBlock.h"
00022 #include "DataFormats/EcalRawData/interface/ESKCHIPBlock.h"
00023 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00024 
00025 using namespace cms;
00026 using namespace edm;
00027 using namespace std;
00028 
00029 ESFEDIntegrityTask::ESFEDIntegrityTask(const ParameterSet& ps) {
00030 
00031   init_ = false;
00032 
00033   dqmStore_ = Service<DQMStore>().operator->();
00034 
00035   prefixME_      = ps.getUntrackedParameter<string>("prefixME", "");
00036   fedDirName_    = ps.getUntrackedParameter<string>("FEDDirName", "FEDIntegrity");
00037   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00038   mergeRuns_     = ps.getUntrackedParameter<bool>("mergeRuns", false);
00039   debug_         = ps.getUntrackedParameter<bool>("debug", false);
00040 
00041   dccCollections_       = ps.getParameter<InputTag>("ESDCCCollections");
00042   kchipCollections_     = ps.getParameter<InputTag>("ESKChipCollections");
00043   FEDRawDataCollection_ = ps.getParameter<edm::InputTag>("FEDRawDataCollection");
00044 
00045   meESFedsEntries_  = 0;
00046   meESFedsFatal_    = 0;
00047   meESFedsNonFatal_ = 0;
00048   
00049 }
00050 
00051 ESFEDIntegrityTask::~ESFEDIntegrityTask() {
00052 
00053 }
00054 
00055 void ESFEDIntegrityTask::beginJob(void) {
00056 
00057   ievt_ = 0;
00058 
00059   if ( dqmStore_ ) {
00060     dqmStore_->setCurrentFolder(prefixME_ + "/" + fedDirName_);
00061     dqmStore_->rmdir(prefixME_ + "/" + fedDirName_);
00062   }
00063 
00064 }
00065 
00066 void ESFEDIntegrityTask::beginRun(const Run& r, const EventSetup& c) {
00067 
00068   if ( ! mergeRuns_ ) this->reset();
00069 
00070 }
00071 
00072 void ESFEDIntegrityTask::endRun(const Run& r, const EventSetup& c) {
00073 
00074 }
00075 
00076 void ESFEDIntegrityTask::reset(void) {
00077 
00078   if ( meESFedsEntries_ )  meESFedsEntries_->Reset();
00079   if ( meESFedsFatal_ )    meESFedsFatal_->Reset();
00080   if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Reset();
00081 
00082 }
00083 
00084 void ESFEDIntegrityTask::setup(void){
00085 
00086   init_ = true;
00087 
00088   char histo[200];
00089 
00090   if ( dqmStore_ ) {
00091     dqmStore_->setCurrentFolder(prefixME_ + "/" + fedDirName_);
00092 
00093     sprintf(histo, "FEDEntries");
00094     meESFedsEntries_ = dqmStore_->book1D(histo, histo, 56, 520, 576);
00095 
00096     sprintf(histo, "FEDFatal");
00097     meESFedsFatal_ = dqmStore_->book1D(histo, histo, 56, 520, 576);
00098 
00099     sprintf(histo, "FEDNonFatal");
00100     meESFedsNonFatal_ = dqmStore_->book1D(histo, histo, 56, 520, 576);
00101   }
00102 
00103 }
00104 
00105 void ESFEDIntegrityTask::cleanup(void){
00106 
00107   if ( ! init_ ) return;
00108 
00109   if ( dqmStore_ ) {
00110     dqmStore_->setCurrentFolder(prefixME_ + "/" + fedDirName_);
00111 
00112     if ( meESFedsEntries_ ) dqmStore_->removeElement( meESFedsEntries_->getName() );
00113     meESFedsEntries_ = 0;
00114 
00115     if ( meESFedsFatal_ ) dqmStore_->removeElement( meESFedsFatal_->getName() );
00116     meESFedsFatal_ = 0;
00117 
00118     if ( meESFedsNonFatal_ ) dqmStore_->removeElement( meESFedsNonFatal_->getName() );
00119     meESFedsNonFatal_ = 0;
00120 
00121   }
00122 
00123   init_ = false;
00124 
00125 }
00126 
00127 void ESFEDIntegrityTask::endJob(void){
00128 
00129   LogInfo("ESFEDIntegrityTask") << "analyzed " << ievt_ << " events";
00130 
00131   if ( enableCleanup_ ) this->cleanup();
00132 
00133 }
00134 
00135 void ESFEDIntegrityTask::analyze(const Event& e, const EventSetup& c){
00136 
00137   if ( ! init_ ) this->setup();
00138 
00139   ievt_++;
00140 
00141   int gt_L1A = 0, gt_OrbitNumber = 0, gt_BX = 0;
00142   int esDCC_L1A_MostFreqCounts = 0;
00143   int esDCC_BX_MostFreqCounts = 0;
00144   int esDCC_OrbitNumber_MostFreqCounts = 0;
00145   int gtFedDataSize = 0;
00146 
00147   Handle<ESRawDataCollection> dccs;
00148   Handle<FEDRawDataCollection> allFedRawData;
00149 
00150   if ( e.getByLabel(FEDRawDataCollection_, allFedRawData) ) {
00151 
00152     // ES FEDs
00153     for (int esFED=520; esFED<=575; ++esFED) { 
00154 
00155       const FEDRawData& fedData = allFedRawData->FEDData(esFED);
00156       int length = fedData.size()/sizeof(uint64_t);
00157       
00158       if ( length > 0 ) 
00159         if ( meESFedsEntries_ ) meESFedsEntries_->Fill(esFED);
00160     }
00161 
00162     // GT FED data
00163     const FEDRawData& gtFedData = allFedRawData->FEDData(812);
00164      
00165     gtFedDataSize = gtFedData.size()/sizeof(uint64_t);
00166      
00167     if ( gtFedDataSize > 0 ) {
00168        
00169       FEDHeader header(gtFedData.data());
00170        
00171       gt_L1A         = header.lvl1ID();
00172       gt_OrbitNumber = e.orbitNumber();
00173       gt_BX          = e.bunchCrossing();
00174     } else {
00175 
00176       map<int, int> esDCC_L1A_FreqMap;
00177       map<int, int> esDCC_BX_FreqMap;
00178       map<int, int> esDCC_OrbitNumber_FreqMap;
00179 
00180       if ( e.getByLabel(dccCollections_, dccs) ) {
00181         
00182         for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
00183           ESDCCHeaderBlock esdcc = (*dccItr);
00184           
00185           esDCC_L1A_FreqMap[esdcc.getLV1()]++;
00186           esDCC_BX_FreqMap[esdcc.getBX()]++;
00187           esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()]++;
00188           
00189           if (esDCC_L1A_FreqMap[esdcc.getLV1()] > esDCC_L1A_MostFreqCounts) {
00190             esDCC_L1A_MostFreqCounts = esDCC_L1A_FreqMap[esdcc.getLV1()];
00191             gt_L1A = esdcc.getLV1();
00192           } 
00193           
00194           if (esDCC_BX_FreqMap[esdcc.getBX()] > esDCC_BX_MostFreqCounts) {
00195             esDCC_BX_MostFreqCounts = esDCC_BX_FreqMap[esdcc.getBX()];
00196             gt_BX = esdcc.getBX();
00197           } 
00198           
00199           if (esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()] > esDCC_OrbitNumber_MostFreqCounts) {
00200             esDCC_OrbitNumber_MostFreqCounts = esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()];
00201             gt_OrbitNumber = esdcc.getOrbitNumber();
00202           } 
00203           
00204         }
00205       } else {
00206         LogWarning("ESFEDIntegrityTask") << dccCollections_ << " not available";
00207       }
00208 
00209     }
00210 
00211   } else {
00212     LogWarning("ESFEDIntegrityTask") << FEDRawDataCollection_ << " not available";
00213   }
00214 
00215   vector<int> fiberStatus;
00216   if ( e.getByLabel(dccCollections_, dccs) ) {
00217     for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
00218       ESDCCHeaderBlock dcc = (*dccItr);
00219       
00220       if (dcc.getDCCErrors() > 0) {
00221         
00222         if ( meESFedsFatal_ ) meESFedsFatal_->Fill(dcc.fedId());
00223         
00224       } else {
00225         if (debug_) cout<<dcc.fedId()<<" "<<dcc.getOptoRX0()<<" "<<dcc.getOptoRX1()<<" "<<dcc.getOptoRX2()<<endl;
00226         fiberStatus = dcc.getFEChannelStatus();
00227         
00228         if (dcc.getOptoRX0() == 128) {
00229           meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
00230         } else if (dcc.getOptoRX0() == 129) {
00231           for (unsigned int i=0; i<12; ++i) {
00232             if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
00233               if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
00234           }
00235         }
00236         if (dcc.getOptoRX1() == 128) { 
00237           meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
00238         }       else if (dcc.getOptoRX1() == 129) {
00239           for (unsigned int i=12; i<24; ++i) {
00240             if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
00241               if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
00242           }
00243         }
00244         if (dcc.getOptoRX2() == 128) {
00245           meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
00246         } else if (dcc.getOptoRX2() == 129){
00247           for (unsigned int i=24; i<36; ++i) {
00248             if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
00249               if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
00250           }
00251         }
00252       }
00253       
00254       if (dcc.getLV1() != gt_L1A) meESFedsNonFatal_->Fill(dcc.fedId());
00255       //if (dcc.getBX() != gt_BX) meESFedsNonFatal_->Fill(dcc.fedId());
00256       //if (dcc.getOrbitNumber() != gt_OrbitNumber) meESFedsNonFatal_->Fill(dcc.fedId());
00257     }
00258   }
00259 
00260   //for (ESLocalRawDataCollection::const_iterator kItr = kchips->begin(); kItr != kchips->end(); ++kItr) {
00261 
00262   //ESKCHIPBlock kchip = (*kItr);
00263 
00264   //Int_t nErr = 0;
00265   //if (kchip.getFlag1() > 0) nErr++; 
00266   //if (kchip.getFlag2() > 0) nErr++;
00267   //if (kchip.getBC() != kchip.getOptoBC()) nErr++;
00268   //if (kchip.getEC() != kchip.getOptoEC()) nErr++;
00269   //if (nErr>0) meESFedsNonFatal_->Fill(dcc.fedId());
00270   //}
00271 
00272 }
00273 
00274 DEFINE_FWK_MODULE(ESFEDIntegrityTask);