CMS 3D CMS Logo

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