CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/SiPixelMonitorClient/src/SiPixelDaqInfo.cc

Go to the documentation of this file.
00001 #include "DQM/SiPixelMonitorClient/interface/SiPixelDaqInfo.h"
00002 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00003 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00004 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00005 #include "CondFormats/RunInfo/interface/RunInfo.h"
00006 #include "CondFormats/RunInfo/interface/RunSummary.h"
00007 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00008 
00009 using namespace std;
00010 using namespace edm;
00011 SiPixelDaqInfo::SiPixelDaqInfo(const edm::ParameterSet& ps) {
00012  
00013   FEDRange_.first  = ps.getUntrackedParameter<unsigned int>("MinimumPixelFEDId", 0);
00014   FEDRange_.second = ps.getUntrackedParameter<unsigned int>("MaximumPixelFEDId", 39);
00015   
00016   NumberOfFeds_ =FEDRange_.second -  FEDRange_.first +1;
00017   
00018   NEvents_ = 0;
00019   for(int i=0; i!=40; i++) FEDs_[i] = 0;
00020 
00021 }
00022 
00023 SiPixelDaqInfo::~SiPixelDaqInfo(){}
00024 
00025 void SiPixelDaqInfo::beginLuminosityBlock(const LuminosityBlock& lumiBlock, const  EventSetup& iSetup){}
00026 
00027 
00028 void SiPixelDaqInfo::endLuminosityBlock(const edm::LuminosityBlock&  lumiBlock, const  edm::EventSetup& iSetup){
00029   edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00030   if(0 != iSetup.find( recordKey ) ) {
00031     // cout<<"record key found"<<endl;
00032     //get fed summary information
00033     ESHandle<RunInfo> sumFED;
00034     iSetup.get<RunInfoRcd>().get(sumFED);    
00035     vector<int> FedsInIds= sumFED->m_fed_in;   
00036 
00037     int FedCount=0;
00038     int FedCountBarrel=0;
00039     int FedCountEndcap=0;
00040 
00041     //loop on all active feds
00042     for(unsigned int fedItr=0;fedItr<FedsInIds.size(); ++fedItr) {
00043       int fedID=FedsInIds[fedItr];
00044       //make sure fed id is in allowed range  
00045       //cout<<fedID<<endl;   
00046       if(fedID>=FEDRange_.first && fedID<=FEDRange_.second){
00047         ++FedCount;
00048         if(fedID>=0 && fedID<=31) ++FedCountBarrel;
00049         else if(fedID>=32 && fedID<=39) ++FedCountEndcap;
00050       }
00051     }   
00052     
00053     //Fill active fed fraction ME
00054     if(FedCountBarrel<=32){
00055       FedCountBarrel = 0; FedCountEndcap = 0; FedCount = 0; NumberOfFeds_ = 40;
00056       for(int i=0; i!=40; i++){
00057         if(i<=31 && FEDs_[i]>0) FedCountBarrel++;
00058         if(i>=32 && FEDs_[i]>0) FedCountEndcap++;
00059         if(FEDs_[i]>0) FedCount++;
00060       }
00061     }
00062     if(NumberOfFeds_>0){
00063       //all Pixel:
00064       Fraction_->Fill( FedCount/NumberOfFeds_);
00065       //Barrel:
00066       FractionBarrel_->Fill( FedCountBarrel/32.);
00067       //Endcap:
00068       FractionEndcap_->Fill( FedCountEndcap/8.);
00069     }else{
00070       Fraction_->Fill(-1);
00071       FractionBarrel_->Fill(-1);
00072       FractionEndcap_->Fill(-1);
00073     } 
00074     
00075   }else{      
00076     Fraction_->Fill(-1);               
00077     FractionBarrel_->Fill(-1);
00078     FractionEndcap_->Fill(-1);
00079     return; 
00080   }
00081 }
00082 
00083 void SiPixelDaqInfo::endRun(const edm::Run&  r, const  edm::EventSetup& iSetup){
00084   edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00085   if(0 != iSetup.find( recordKey ) ) {
00086     // cout<<"record key found"<<endl;
00087     //get fed summary information
00088     ESHandle<RunInfo> sumFED;
00089     iSetup.get<RunInfoRcd>().get(sumFED);    
00090     vector<int> FedsInIds= sumFED->m_fed_in;   
00091 
00092     int FedCount=0;
00093     int FedCountBarrel=0;
00094     int FedCountEndcap=0;
00095 
00096     //loop on all active feds
00097     for(unsigned int fedItr=0;fedItr<FedsInIds.size(); ++fedItr) {
00098       int fedID=FedsInIds[fedItr];
00099       //make sure fed id is in allowed range  
00100       //cout<<fedID<<endl;   
00101       if(fedID>=FEDRange_.first && fedID<=FEDRange_.second){
00102         ++FedCount;
00103         if(fedID>=0 && fedID<=31) ++FedCountBarrel;
00104         else if(fedID>=32 && fedID<=39) ++FedCountEndcap;
00105       }
00106     }   
00107 
00108     if(FedCountBarrel>32){
00109       FedCountBarrel = nFEDsBarrel_;
00110       FedCountEndcap = nFEDsEndcap_;
00111       FedCount = FedCountBarrel + FedCountEndcap;
00112       NumberOfFeds_ = 40;
00113     }
00114 
00115     //Fill active fed fraction ME
00116     if(FedCountBarrel<=32){
00117       FedCountBarrel = 0; FedCountEndcap = 0; FedCount = 0; NumberOfFeds_ = 40;
00118       for(int i=0; i!=40; i++){
00119         if(i<=31 && FEDs_[i]>0) FedCountBarrel++;
00120         if(i>=32 && FEDs_[i]>0) FedCountEndcap++;
00121         if(FEDs_[i]>0) FedCount++;
00122       }
00123     }
00124     if(NumberOfFeds_>0){
00125       //all Pixel:
00126       Fraction_->Fill( FedCount/NumberOfFeds_);
00127       //Barrel:
00128       FractionBarrel_->Fill( FedCountBarrel/32.);
00129       //Endcap:
00130       FractionEndcap_->Fill( FedCountEndcap/8.);
00131     }else{
00132       Fraction_->Fill(-1);
00133       FractionBarrel_->Fill(-1);
00134       FractionEndcap_->Fill(-1);
00135     } 
00136     
00137   }else{      
00138     Fraction_->Fill(-1);               
00139     FractionBarrel_->Fill(-1);
00140     FractionEndcap_->Fill(-1);
00141     return; 
00142   }
00143 }
00144 
00145 
00146 void SiPixelDaqInfo::beginJob(){
00147 
00148   dbe_ = 0;
00149   dbe_ = Service<DQMStore>().operator->();
00150   
00151  
00152   dbe_->setCurrentFolder("Pixel/EventInfo");
00153   Fraction_= dbe_->bookFloat("DAQSummary");  
00154   dbe_->setCurrentFolder("Pixel/EventInfo/DAQContents");
00155   FractionBarrel_= dbe_->bookFloat("PixelBarrelFraction");  
00156   FractionEndcap_= dbe_->bookFloat("PixelEndcapFraction");  
00157 }
00158 
00159 
00160 void SiPixelDaqInfo::endJob() {}
00161 
00162 
00163 
00164 void SiPixelDaqInfo::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00165   NEvents_++;  
00166   //cout<<"in SiPixelDaqInfo::analyze now!"<<endl;
00167   if(NEvents_>=1 && NEvents_<=100){
00168     // check if any Pixel FED is in readout:
00169     edm::Handle<FEDRawDataCollection> rawDataHandle;
00170     iEvent.getByLabel("source", rawDataHandle);
00171     if(!rawDataHandle.isValid()){
00172       edm::LogInfo("SiPixelDaqInfo") << "source" << " is empty!";
00173       return;
00174     }
00175     const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
00176     nFEDsBarrel_ = 0; nFEDsEndcap_ = 0;
00177     for(int i = 0; i != 40; i++){
00178       if(rawDataCollection.FEDData(i).size() > 208 ) FEDs_[i]++;
00179     }
00180   }
00181 
00182 }
00183