CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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; 
00142   // int gt_OrbitNumber = 0, gt_BX = 0;
00143   int esDCC_L1A_MostFreqCounts = 0;
00144   int esDCC_BX_MostFreqCounts = 0;
00145   int esDCC_OrbitNumber_MostFreqCounts = 0;
00146   int gtFedDataSize = 0;
00147 
00148   Handle<ESRawDataCollection> dccs;
00149   Handle<FEDRawDataCollection> allFedRawData;
00150 
00151   if ( e.getByLabel(FEDRawDataCollection_, allFedRawData) ) {
00152 
00153     // ES FEDs
00154     for (int esFED=520; esFED<=575; ++esFED) { 
00155 
00156       const FEDRawData& fedData = allFedRawData->FEDData(esFED);
00157       int length = fedData.size()/sizeof(uint64_t);
00158       
00159       if ( length > 0 ) 
00160         if ( meESFedsEntries_ ) meESFedsEntries_->Fill(esFED);
00161     }
00162 
00163     // GT FED data
00164     const FEDRawData& gtFedData = allFedRawData->FEDData(812);
00165      
00166     gtFedDataSize = gtFedData.size()/sizeof(uint64_t);
00167      
00168     if ( gtFedDataSize > 0 ) {
00169        
00170       FEDHeader header(gtFedData.data());
00171        
00172       gt_L1A         = header.lvl1ID();
00173       //gt_OrbitNumber = e.orbitNumber();
00174       //gt_BX          = e.bunchCrossing();
00175     } else {
00176 
00177       map<int, int> esDCC_L1A_FreqMap;
00178       map<int, int> esDCC_BX_FreqMap;
00179       map<int, int> esDCC_OrbitNumber_FreqMap;
00180 
00181       if ( e.getByLabel(dccCollections_, dccs) ) {
00182         
00183         for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
00184           ESDCCHeaderBlock esdcc = (*dccItr);
00185           
00186           esDCC_L1A_FreqMap[esdcc.getLV1()]++;
00187           esDCC_BX_FreqMap[esdcc.getBX()]++;
00188           esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()]++;
00189           
00190           if (esDCC_L1A_FreqMap[esdcc.getLV1()] > esDCC_L1A_MostFreqCounts) {
00191             esDCC_L1A_MostFreqCounts = esDCC_L1A_FreqMap[esdcc.getLV1()];
00192             gt_L1A = esdcc.getLV1();
00193           } 
00194           
00195           if (esDCC_BX_FreqMap[esdcc.getBX()] > esDCC_BX_MostFreqCounts) {
00196             esDCC_BX_MostFreqCounts = esDCC_BX_FreqMap[esdcc.getBX()];
00197             //gt_BX = esdcc.getBX();
00198           } 
00199           
00200           if (esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()] > esDCC_OrbitNumber_MostFreqCounts) {
00201             esDCC_OrbitNumber_MostFreqCounts = esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()];
00202             //gt_OrbitNumber = esdcc.getOrbitNumber();
00203           } 
00204           
00205         }
00206       } else {
00207         LogWarning("ESFEDIntegrityTask") << dccCollections_ << " not available";
00208       }
00209 
00210     }
00211 
00212   } else {
00213     LogWarning("ESFEDIntegrityTask") << FEDRawDataCollection_ << " not available";
00214   }
00215 
00216   vector<int> fiberStatus;
00217   if ( e.getByLabel(dccCollections_, dccs) ) {
00218     for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
00219       ESDCCHeaderBlock dcc = (*dccItr);
00220       
00221       if (dcc.getDCCErrors() > 0) {
00222         
00223         if ( meESFedsFatal_ ) meESFedsFatal_->Fill(dcc.fedId());
00224         
00225       } else {
00226         if (debug_) cout<<dcc.fedId()<<" "<<dcc.getOptoRX0()<<" "<<dcc.getOptoRX1()<<" "<<dcc.getOptoRX2()<<endl;
00227         fiberStatus = dcc.getFEChannelStatus();
00228         
00229         if (dcc.getOptoRX0() == 128) {
00230           meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
00231         } else if (dcc.getOptoRX0() == 129) {
00232           for (unsigned int i=0; i<12; ++i) {
00233             if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
00234               if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
00235           }
00236         }
00237         if (dcc.getOptoRX1() == 128) { 
00238           meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
00239         }       else if (dcc.getOptoRX1() == 129) {
00240           for (unsigned int i=12; i<24; ++i) {
00241             if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
00242               if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
00243           }
00244         }
00245         if (dcc.getOptoRX2() == 128) {
00246           meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
00247         } else if (dcc.getOptoRX2() == 129){
00248           for (unsigned int i=24; i<36; ++i) {
00249             if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
00250               if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
00251           }
00252         }
00253       }
00254       
00255       if (dcc.getLV1() != gt_L1A) meESFedsNonFatal_->Fill(dcc.fedId());
00256       //if (dcc.getBX() != gt_BX) meESFedsNonFatal_->Fill(dcc.fedId());
00257       //if (dcc.getOrbitNumber() != gt_OrbitNumber) meESFedsNonFatal_->Fill(dcc.fedId());
00258     }
00259   }
00260 
00261   //for (ESLocalRawDataCollection::const_iterator kItr = kchips->begin(); kItr != kchips->end(); ++kItr) {
00262 
00263   //ESKCHIPBlock kchip = (*kItr);
00264 
00265   //Int_t nErr = 0;
00266   //if (kchip.getFlag1() > 0) nErr++; 
00267   //if (kchip.getFlag2() > 0) nErr++;
00268   //if (kchip.getBC() != kchip.getOptoBC()) nErr++;
00269   //if (kchip.getEC() != kchip.getOptoEC()) nErr++;
00270   //if (nErr>0) meESFedsNonFatal_->Fill(dcc.fedId());
00271   //}
00272 
00273 }
00274 
00275 DEFINE_FWK_MODULE(ESFEDIntegrityTask);