CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQM/L1TMonitor/src/L1TBPTX.cc

Go to the documentation of this file.
00001 #include "DQM/L1TMonitor/interface/L1TBPTX.h"
00002 
00003 #include "DQMServices/Core/interface/DQMStore.h"
00004 
00005 #include "DataFormats/Scalers/interface/LumiScalers.h"
00006 #include "DataFormats/Scalers/interface/Level1TriggerRates.h"
00007 #include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
00008 
00009 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00010 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00011 
00012 #include "DataFormats/Common/interface/ConditionsInEdm.h" // Parameters associated to Run, LS and Event
00013 
00014 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
00015 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00016 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
00017 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00018 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
00019 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsTechTrigRcd.h"
00020 #include "CondFormats/L1TObjects/interface/L1GtMuonTemplate.h"
00021 
00022 // Luminosity Information
00023 //#include "DataFormats/Luminosity/interface/LumiDetails.h"
00024 //#include "DataFormats/Luminosity/interface/LumiSummary.h"
00025 
00026 // L1TMonitor includes
00027 #include "DQM/L1TMonitor/interface/L1TMenuHelper.h"
00028 
00029 #include "TList.h"
00030 
00031 using namespace edm;
00032 using namespace std;
00033 
00034 //-------------------------------------------------------------------------------------
00035 //-------------------------------------------------------------------------------------
00036 L1TBPTX::L1TBPTX(const ParameterSet & pset){
00037 
00038   m_parameters = pset;
00039 
00040   // Mapping parameter input variables
00041   m_scalersSource       = pset.getParameter         <InputTag>("inputTagScalersResults");
00042   m_l1GtDataDaqInputTag = pset.getParameter         <InputTag>("inputTagL1GtDataDaq");
00043   m_l1GtEvmSource       = pset.getParameter         <InputTag>("inputTagtEvmSource");
00044   m_verbose             = pset.getUntrackedParameter<bool>    ("verbose",false);
00045 //  m_refPrescaleSet      = pset.getParameter         <int>     ("refPrescaleSet");
00046 
00047   m_monitorBits = pset.getParameter< vector<ParameterSet> >("MonitorBits");
00048   
00049   for(unsigned i=0; i<m_monitorBits.size(); i++){
00050 
00051     // Algorithms
00052     if(m_monitorBits[i].getParameter<bool>("bitType")){
00053 
00054       int bit    = m_monitorBits[i].getParameter<int>("bitNumber");
00055       int offset = m_monitorBits[i].getParameter<int>("bitOffset");
00056       m_selAlgoBit.push_back( pair<int,int>(bit,offset) );
00057     }
00058     // Tech
00059     else{
00060       int bit    = m_monitorBits[i].getParameter<int>("bitNumber");
00061       int offset = m_monitorBits[i].getParameter<int>("bitOffset");
00062       m_selTechBit.push_back( pair<int,int>(bit,offset) );
00063     }
00064   }
00065 
00066   m_monitorRates = pset.getParameter< vector<ParameterSet> >("MonitorRates");
00067 
00068   if (pset.getUntrackedParameter < bool > ("dqmStore", false)) {
00069     dbe = Service < DQMStore > ().operator->();
00070     dbe->setVerbose(0);
00071   }
00072 
00073 }
00074 
00075 //-------------------------------------------------------------------------------------
00076 //-------------------------------------------------------------------------------------
00077 L1TBPTX::~L1TBPTX(){}
00078 
00079 //-------------------------------------------------------------------------------------
00080 //-------------------------------------------------------------------------------------
00081 void L1TBPTX::beginJob(void){
00082 
00083   if (m_verbose){cout << "[L1TBPTX] Called beginJob." << endl;}
00084 
00085   // get hold of back-end interface
00086   DQMStore *dbe = 0;
00087   dbe = Service < DQMStore > ().operator->();
00088 
00089   if (dbe) {
00090     dbe->setCurrentFolder("L1T/L1TBPTX");
00091     dbe->rmdir("L1T/L1TBPTX");
00092   }
00093 
00094 }
00095 
00096 //-------------------------------------------------------------------------------------
00097 //-------------------------------------------------------------------------------------
00098 void L1TBPTX::endJob(void){
00099 
00100   if (m_verbose){cout << "[L1TBPTX] Called endJob." << endl;}
00101 
00102   if (m_outputFile.size() != 0 && dbe)
00103     dbe->save(m_outputFile);
00104 
00105   return;
00106 
00107 }
00108 
00109 //-------------------------------------------------------------------------------------
00111 //-------------------------------------------------------------------------------------
00112 void L1TBPTX::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
00113 
00114   if (m_verbose){cout << "[L1TBPTX] Called beginRun." << endl;}
00115 
00116   // Initializing variables
00117   int maxNbins = 2501;
00118 
00119   // Reseting run dependent variables
00120   m_lhcFill     = 0;
00121   m_currentLS   = 0;
00122 
00123   // Getting Trigger menu from GT
00124   ESHandle<L1GtTriggerMenu> menuRcd;
00125   iSetup.get<L1GtTriggerMenuRcd>().get(menuRcd);
00126   const L1GtTriggerMenu* menu = menuRcd.product();
00127 
00128   // Filling Alias-Bit Map
00129   for (CItAlgo algo = menu->gtAlgorithmAliasMap().begin(); algo!=menu->gtAlgorithmAliasMap().end(); ++algo){
00130     m_algoBit_Alias[(algo->second).algoBitNumber()] = (algo->second).algoAlias();
00131   }
00132 
00133   for (CItAlgo algo = menu->gtTechnicalTriggerMap().begin(); algo!=menu->gtTechnicalTriggerMap().end(); ++algo){
00134     m_techBit_Alias[(algo->second).algoBitNumber()] = (algo->second).algoName(); 
00135   }
00136 
00137   // Initializing DQM Monitor Elements
00138   dbe->setCurrentFolder("L1T/L1TBPTX");
00139   m_ErrorMonitor = dbe->book1D("ErrorMonitor","ErrorMonitor",7,0,7);
00140   m_ErrorMonitor->setBinLabel(UNKNOWN                      ,"UNKNOWN");
00141   m_ErrorMonitor->setBinLabel(WARNING_DB_CONN_FAILED       ,"WARNING_DB_CONN_FAILED");        // Errors from L1TOMDSHelper
00142   m_ErrorMonitor->setBinLabel(WARNING_DB_QUERY_FAILED      ,"WARNING_DB_QUERY_FAILED");       // Errors from L1TOMDSHelper
00143   m_ErrorMonitor->setBinLabel(WARNING_DB_INCORRECT_NBUNCHES,"WARNING_DB_INCORRECT_NBUNCHES"); // Errors from L1TOMDSHelper
00144   m_ErrorMonitor->setBinLabel(ERROR_UNABLE_RETRIVE_PRODUCT ,"ERROR_UNABLE_RETRIVE_PRODUCT");
00145   m_ErrorMonitor->setBinLabel(ERROR_TRIGGERALIAS_NOTVALID  ,"ERROR_TRIGGERALIAS_NOTVALID");
00146   m_ErrorMonitor->setBinLabel(ERROR_LSBLOCK_NOTVALID       ,"ERROR_LSBLOCK_NOTVALID");
00147 
00148   for(unsigned i=0; i<m_monitorBits.size(); i++){
00149 
00150     bool    isAlgo   = m_monitorBits[i].getParameter<bool>  ("bitType");
00151     TString testName = m_monitorBits[i].getParameter<string>("testName");
00152     int     bit      = m_monitorBits[i].getParameter<int>   ("bitNumber");
00153 
00154     TString meTitle = "";
00155     dbe->setCurrentFolder("L1T/L1TBPTX/Efficiency/");
00156     if(isAlgo){
00157       meTitle="Algo ";meTitle+=bit; meTitle+=" - "; meTitle+=m_algoBit_Alias[bit]; meTitle+=" Efficiency";
00158       m_meAlgoEfficiency[bit] = dbe->book1D(testName,meTitle,maxNbins,-0.5,double(maxNbins)-0.5);
00159       m_meAlgoEfficiency[bit]->setAxisTitle("Lumi Section" ,1);
00160     }
00161     else{
00162       meTitle="Tech "; meTitle+=bit; meTitle+=" - "; meTitle+=m_techBit_Alias[bit]; meTitle+=" Efficiency";
00163       m_meTechEfficiency[bit] = dbe->book1D(testName,meTitle,maxNbins,-0.5,double(maxNbins)-0.5);
00164       m_meTechEfficiency[bit]->setAxisTitle("Lumi Section" ,1);
00165     }
00166     
00167     meTitle = "";
00168     dbe->setCurrentFolder("L1T/L1TBPTX/MissFire/");
00169     if(isAlgo){
00170       meTitle="Algo "; meTitle+=bit; meTitle+=" - "; meTitle+=m_algoBit_Alias[bit]; meTitle+="(1 - Miss Fire Rate)";
00171       m_meAlgoMissFire[bit] = dbe->book1D(testName,meTitle,maxNbins,-0.5,double(maxNbins)-0.5);
00172       m_meAlgoMissFire[bit]->setAxisTitle("Lumi Section"      ,1);
00173       m_meAlgoMissFire[bit]->setAxisTitle("1 - Miss Fire Rate",2);
00174     }
00175     else{
00176       meTitle="Tech "; meTitle+=bit; meTitle+=" - "; meTitle+=m_techBit_Alias[bit]; meTitle+="(1 - Miss Fire Rate)";
00177       m_meTechMissFire[bit] = dbe->book1D(testName,meTitle,maxNbins,-0.5,double(maxNbins)-0.5);
00178       m_meTechMissFire[bit]->setAxisTitle("Lumi Section"      ,1);
00179       m_meTechMissFire[bit]->setAxisTitle("1 - Miss Fire Rate",2);
00180     }
00181   }
00182 
00183   for(unsigned i=0; i<m_monitorRates.size(); i++){
00184    
00185     TString testName = m_monitorRates[i].getParameter<string>("testName");
00186     bool    isAlgo   = m_monitorRates[i].getParameter<bool>  ("bitType");
00187     int     bit      = m_monitorRates[i].getParameter<int>   ("bitNumber");
00188   
00189     pair<bool,int> refME = pair<bool,int>(isAlgo,bit);
00190     
00191     TString meTitle = "";
00192     dbe->setCurrentFolder("L1T/L1TBPTX/Rate/");
00193     if(isAlgo){
00194       meTitle="Algo "+bit; meTitle+=" - "; meTitle+=m_algoBit_Alias[bit]; meTitle+=" Rate";
00195       m_meRate[refME] = dbe->book1D(testName,meTitle,maxNbins,-0.5,double(maxNbins)-0.5);
00196       m_meRate[refME]->setAxisTitle("Lumi Section"           ,1);
00197       m_meRate[refME]->setAxisTitle("Rate (unprescaled) [Hz]",2);
00198     }
00199     else{
00200       meTitle="Tech "+bit; meTitle+=" - "; meTitle+=m_techBit_Alias[bit]; meTitle+=" Rate";
00201       m_meRate[refME] = dbe->book1D(testName,meTitle,maxNbins,-0.5,double(maxNbins)-0.5);
00202       m_meRate[refME]->setAxisTitle("Lumi Section" ,1);
00203       m_meRate[refME]->setAxisTitle("Rate (unprescaled) [Hz]",2);
00204     }   
00205   }
00206     
00207     
00208     
00209   //_____________________________________________________________________
00210   // Getting the prescale columns definition for this run
00211   ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
00212   ESHandle<L1GtPrescaleFactors> l1GtPfTech;
00213 
00214   iSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
00215   iSetup.get<L1GtPrescaleFactorsTechTrigRcd>().get(l1GtPfTech);
00216    
00217   if(l1GtPfAlgo.isValid()){  
00218     const L1GtPrescaleFactors* m_l1GtPfAlgo = l1GtPfAlgo.product();
00219     m_prescaleFactorsAlgoTrig = &(m_l1GtPfAlgo->gtPrescaleFactors());
00220   }else{
00221     //TODO: Some error handling
00222   }
00223   
00224   if(l1GtPfAlgo.isValid()){  
00225     const L1GtPrescaleFactors* m_l1GtPfTech = l1GtPfTech.product();
00226     m_prescaleFactorsTechTrig = &(m_l1GtPfTech->gtPrescaleFactors());
00227   }else{
00228     //TODO: Some error handling
00229   }  
00230   
00231 }
00232 
00233 //_____________________________________________________________________
00234 // Function: beginLuminosityBlock
00235 //_____________________________________________________________________
00236 void L1TBPTX::beginLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
00237 
00238   if (m_verbose){cout << "[L1TBPTX] Called beginLuminosityBlock." << endl;}
00239 
00240   // Updating current LS number
00241   m_currentLS = lumiBlock.id().luminosityBlock();
00242 
00243   // A LS will be valid if BeamMode==STABLE for all events monitored
00244   m_currentLSValid = true;
00245 
00246   for(unsigned i=0; i<m_monitorBits.size(); i++){
00247 
00248     TString triggerName = "";
00249     if(m_monitorBits[i].getParameter<bool>("bitType")){
00250       triggerName = "algo_"+m_monitorBits[i].getParameter<int>("bitNumber");
00251     }else{
00252       triggerName = "tech_"+m_monitorBits[i].getParameter<int>("bitNumber");
00253     }
00254 
00255     m_effNumerator       [triggerName] = 0;
00256     m_effDenominator     [triggerName] = 0;
00257     m_missFireNumerator  [triggerName] = 0;
00258     m_missFireDenominator[triggerName] = 0;
00259 
00260   }
00261 
00262 }
00263 
00264 //_____________________________________________________________________
00265 // Function: endLuminosityBlock
00266 // * Fills LS by LS ration of trigger out of sync
00267 //_____________________________________________________________________
00268 void L1TBPTX::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
00269   
00270   //______________________________________________________________________________
00271   // Monitoring efficiencies
00272   //______________________________________________________________________________  
00273   if(m_verbose){cout << "[L1TBPTX] Called endLuminosityBlock." << endl;}
00274 
00275   // If this LS is valid (i.e. all events recorded with stable beams)
00276   if(m_currentLSValid && m_beamConfig.isValid()){
00277 
00278     for(unsigned i=0; i<m_monitorBits.size(); i++){
00279 
00280       bool    isAlgo   = m_monitorBits[i].getParameter<bool>  ("bitType");
00281       TString testName = m_monitorBits[i].getParameter<string>("testName");
00282       int     bit      = m_monitorBits[i].getParameter<int>   ("bitNumber");
00283 
00284       TString triggerName;
00285       if(isAlgo){triggerName = "algo_"+bit;}
00286       else      {triggerName = "tech_"+bit;}
00287 
00288       double valEff;
00289       double valMiss;
00290       if(m_effDenominator[triggerName]!=0)     {valEff  = (double)m_effNumerator[triggerName]/m_effDenominator[triggerName];}
00291       else                                     {valEff  = 0;}
00292       if(m_missFireDenominator[triggerName]!=0){valMiss = (double)m_missFireNumerator[triggerName]/m_missFireDenominator[triggerName];}
00293       else                                     {valMiss = 0;}
00294 
00295       if(isAlgo){
00296         int bin = m_meAlgoEfficiency[bit]->getTH1()->FindBin(m_currentLS);
00297         m_meAlgoEfficiency[bit]->setBinContent(bin,valEff);
00298         m_meAlgoMissFire[bit]  ->setBinContent(bin,1-valMiss);
00299       }
00300       else{
00301         int bin = m_meTechEfficiency[bit]->getTH1()->FindBin(m_currentLS);
00302         m_meTechEfficiency[bit]->setBinContent(bin,valEff);
00303         m_meTechMissFire[bit]  ->setBinContent(bin,1-valMiss);
00304       }
00305     }
00306   }
00307   
00308   //______________________________________________________________________________
00309   // Monitoring rates
00310   //______________________________________________________________________________  
00311   // We are only interested in monitoring lumisections where the the LHC state is
00312   // RAMP, FLATTOP, SQUEEZE, ADJUST or STABLE since the bunch configuration and 
00313   // therefore the BPTX rate will not change.
00314   
00315   if(m_currentLSValid){
00316   
00317     const vector<int>& currentPFAlgo = (*m_prescaleFactorsAlgoTrig).at(m_currentPrescalesIndex);
00318     const vector<int>& currentPFTech = (*m_prescaleFactorsTechTrig).at(m_currentPrescalesIndex);
00319     
00320     for(unsigned i=0; i<m_monitorRates.size(); i++){
00321    
00322       bool isAlgo = m_monitorRates[i].getParameter<bool>  ("bitType");
00323       int  bit    = m_monitorRates[i].getParameter<int>   ("bitNumber");
00324   
00325       pair<bool,int> refME = pair<bool,int>(isAlgo,bit);
00326     
00327       if(isAlgo){
00328         int    bin      = m_meRate[refME]->getTH1()->FindBin(m_currentGTLS);
00329         int    trigPS   = currentPFAlgo[bit];
00330         double trigRate = (double) trigPS*m_l1Rate[refME];
00331         m_meRate[refME]->setBinContent(bin,trigRate);
00332       
00333       }else{
00334         int    bin      = m_meRate[refME]->getTH1()->FindBin(m_currentGTLS);
00335         int    trigPS   = currentPFTech[bit];
00336         double trigRate = (double) trigPS*m_l1Rate[refME];
00337         m_meRate[refME]->setBinContent(bin,trigRate);
00338       }
00339     }
00340   }
00341 }
00342 
00343 //_____________________________________________________________________
00344 void L1TBPTX::endRun(const edm::Run& run, const edm::EventSetup& iSetup){
00345 
00346   if(m_verbose){cout << "[L1TBPTX] Called endRun." << endl;}
00347 
00348   
00349 }
00350 
00351 //_____________________________________________________________________
00352 void L1TBPTX::analyze(const Event & iEvent, const EventSetup & eventSetup){
00353 
00354   if(m_verbose){cout << "[L1TBPTX] Called analyze." << endl;}
00355 
00356   // We only start analyzing if current LS is still valid
00357   if(m_currentLSValid){
00358 
00359     if(m_verbose){cout << "[L1TBPTX] -> m_currentLSValid=" << m_currentLSValid << endl;}
00360 
00361     // Retriving information from GT
00362     edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvmReadoutRecord;
00363     iEvent.getByLabel(m_l1GtEvmSource, gtEvmReadoutRecord);
00364 
00365     // Determining beam mode and fill number
00366     if(gtEvmReadoutRecord.isValid()){
00367 
00368       const L1GtfeExtWord& gtfeEvmWord = gtEvmReadoutRecord->gtfeWord();
00369       unsigned int lhcBeamMode         = gtfeEvmWord.beamMode();          // Updating beam mode
00370 
00371       if(m_verbose){cout << "[L1TBPTX] Beam mode: "<< lhcBeamMode << endl;}
00372       
00373       if(lhcBeamMode==RAMP || lhcBeamMode==FLATTOP || lhcBeamMode==SQUEEZE || lhcBeamMode==ADJUST || lhcBeamMode==STABLE){
00374         
00375         if(m_lhcFill==0){
00376 
00377           if(m_verbose){cout << "[L1TBPTX] No valid bunch structure yet retrived. Attemptting to retrive..." << endl;}
00378 
00379           m_lhcFill = gtfeEvmWord.lhcFillNumber(); // Getting LHC Fill Number from GT
00380           
00381           getBeamConfOMDS(); // Getting Beam Configuration from OMDS
00382 
00383           // We are between RAMP and STABLE so there should be some colliding bunches
00384           // in the machine. If 0 colliding bunched are found might be due to a delay 
00385           // of the update of the database. So we declare this LS as invalid and try
00386           // again on the next one.
00387           if(m_beamConfig.nCollidingBunches<=0){
00388             m_lhcFill=0;
00389             m_currentLSValid=false;
00390           }
00391         }
00392       }
00393       else{m_currentLSValid=false;}
00394 
00395     }else{
00396       int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
00397       eCount++;
00398       m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT,eCount);
00399     }
00400   }
00401 
00402   //______________________________________________________________________________
00403   // If current LS is valid and Beam Configuration is Valid we analyse this event
00404   //______________________________________________________________________________
00405   if(m_currentLSValid && m_beamConfig.isValid()){
00406 
00407     if(m_verbose){cout << "Current event in valid LS and beam config" << endl;}
00408 
00409     // Getting Final Decision Logic (FDL) Data from GT
00410     edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
00411     iEvent.getByLabel(m_l1GtDataDaqInputTag, gtReadoutRecordData);
00412 
00413     if(gtReadoutRecordData.isValid()){
00414 
00415       const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
00416 
00417       // Getting the index for the fdl data for this event
00418       int eventFDL=0;
00419       for(unsigned int i=0; i<gtFdlVectorData.size(); i++){
00420         if(gtFdlVectorData[i].bxInEvent()==0){eventFDL=i; break;}
00421       }
00422       
00423       m_currentPrescalesIndex = gtFdlVectorData[eventFDL].gtPrescaleFactorIndexAlgo();   
00424       
00425       for(unsigned i=0; i<m_monitorBits.size(); i++){
00426 
00427         TString triggerName = "";
00428         bool isAlgo = m_monitorBits[i].getParameter<bool>("bitType");
00429         int  bit    = m_monitorBits[i].getParameter<int> ("bitNumber");
00430         int  offset = m_monitorBits[i].getParameter<int> ("bitOffset");
00431 
00432         if(isAlgo){triggerName = "algo_"+bit;}
00433         else      {triggerName = "tech_"+bit;}
00434 
00435         int evBxStart = -2;
00436         int evBxEnd   =  2;
00437 
00438         if(offset<0){evBxStart+=-1*offset;}
00439         if(offset>0){evBxEnd  +=-1*offset;}
00440 
00441         for(unsigned a=0; a<gtFdlVectorData.size(); a++){
00442 
00443           int  testBx      = gtFdlVectorData[a].localBxNr()-offset;
00444           bool lhcBxFilled = m_beamConfig.beam1[testBx] && m_beamConfig.beam2[testBx];
00445           bool algoFired   = false;
00446 
00447           if(isAlgo){
00448             if(gtFdlVectorData[a].gtDecisionWord()[bit]){algoFired=true;}
00449 
00450           }
00451           else{
00452             if(gtFdlVectorData[a].gtTechnicalTriggerWord()[bit]){algoFired=true;}
00453           }
00454 
00455           if(lhcBxFilled)             {m_effDenominator[triggerName]++;}
00456           if(lhcBxFilled && algoFired){m_effNumerator  [triggerName]++;}
00457 
00458           if(algoFired)                {m_missFireNumerator[triggerName]++;}
00459           if(algoFired && !lhcBxFilled){m_missFireNumerator[triggerName]++;}
00460 
00461         }
00462       }
00463     }
00464   }
00465 
00466   //______________________________________________________________________________
00467   // Rate calculation
00468   //______________________________________________________________________________
00469   edm::Handle<Level1TriggerScalersCollection> triggerScalers;
00470   iEvent.getByLabel(m_scalersSource,triggerScalers);
00471 
00472   if(triggerScalers.isValid()){
00473     
00474     Level1TriggerScalersCollection::const_iterator itL1TScalers = triggerScalers->begin();
00475     Level1TriggerRates trigRates(*itL1TScalers,iEvent.id().run());
00476     
00477     m_currentGTLS= (*itL1TScalers).lumiSegmentNr();
00478 
00479     for(unsigned i=0; i<m_monitorRates.size(); i++){
00480    
00481       bool isAlgo = m_monitorRates[i].getParameter<bool>("bitType");
00482       int  bit    = m_monitorRates[i].getParameter<int> ("bitNumber");
00483           
00484       pair<bool,int> refTrig = pair<bool,int>(isAlgo,bit);
00485     
00486       if(isAlgo){m_l1Rate[refTrig] = trigRates.gtAlgoCountsRate()[bit];}
00487       else      {m_l1Rate[refTrig] = trigRates.gtTechCountsRate()[bit];}
00488     }
00489   }
00490 
00491 }
00492 
00493 //_____________________________________________________________________
00494 // Method: getBunchStructureOMDS
00495 // Description: Attempt to retrive Beam Configuration from OMDS and if
00496 //              we find error handle it
00497 //_____________________________________________________________________
00498 void L1TBPTX::getBeamConfOMDS(){
00499 
00500   if(m_verbose){cout << "[L1TBPTX] Called getBeamConfOMDS()" << endl;}
00501   
00502   //Getting connection paremeters
00503   string oracleDB   = m_parameters.getParameter<string>("oracleDB");
00504   string pathCondDB = m_parameters.getParameter<string>("pathCondDB");
00505 
00506   // Connecting to OMDS
00507   L1TOMDSHelper myOMDSHelper = L1TOMDSHelper();
00508   int conError;
00509   myOMDSHelper.connect(oracleDB,pathCondDB,conError);
00510 
00511   if(conError == L1TOMDSHelper::NO_ERROR){
00512 
00513     if(m_verbose){cout << "[L1TBPTX] Connected to DB with no error." << endl;}
00514     
00515     int errorRetrive;
00516     m_beamConfig = myOMDSHelper.getBeamConfiguration(m_lhcFill,errorRetrive);
00517     
00518     if(errorRetrive == L1TOMDSHelper::NO_ERROR){
00519       if(m_verbose){
00520         cout << "[L1TBPTX] Retriving LHC Bunch Structure: NO_ERROR" << endl;
00521         cout << "[L1TSync] -> LHC Bunch Structure valid=" << m_beamConfig.m_valid << " nBunches=" << m_beamConfig.nCollidingBunches << endl;
00522       }
00523     }
00524     else if(errorRetrive == L1TOMDSHelper::WARNING_DB_QUERY_FAILED){
00525       if(m_verbose){cout << "[L1TBPTX] Retriving LHC Bunch Structure: WARNING_DB_QUERY_FAILED" << endl;}
00526       
00527       int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_QUERY_FAILED);
00528       eCount++;
00529       m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_QUERY_FAILED,eCount);
00530     }
00531     else if(errorRetrive == L1TOMDSHelper::WARNING_DB_INCORRECT_NBUNCHES){
00532       if(m_verbose){cout << "[L1TBPTX] Retriving LHC Bunch Structure: WARNING_DB_INCORRECT_NBUNCHES" << endl;}
00533       
00534       int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_INCORRECT_NBUNCHES);
00535       eCount++;
00536       m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_INCORRECT_NBUNCHES,eCount);
00537     }    
00538     else{
00539       if(m_verbose){cout << "[L1TBPTX] Retriving LHC Bunch Structure: UNKNOWN" << endl;}
00540       int eCount = m_ErrorMonitor->getTH1()->GetBinContent(UNKNOWN);
00541       eCount++;
00542       m_ErrorMonitor->getTH1()->SetBinContent(UNKNOWN,eCount);
00543     }
00544 
00545   }
00546   else if(conError == L1TOMDSHelper::WARNING_DB_CONN_FAILED){ 
00547     if(m_verbose){cout << "[L1TBPTX] Connection to DB: WARNING_DB_CONN_FAILED" << endl;}
00548     int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_CONN_FAILED);
00549     eCount++;
00550     m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_CONN_FAILED,eCount);
00551   }
00552   else{
00553     if(m_verbose){cout << "[L1TBPTX] Connection to DB: UNKNOWN" << endl;}
00554     int eCount = m_ErrorMonitor->getTH1()->GetBinContent(UNKNOWN);
00555     eCount++;
00556     m_ErrorMonitor->getTH1()->SetBinContent(UNKNOWN,eCount);    
00557   }
00558 }
00559 
00560 //_____________________________________________________________________
00561 // Method: doFractionInSync
00562 // Description: Produce plot with the fraction of in sync trigger for
00563 //              LS blocks with enough statistics.
00564 // Variable: iForce - Forces closing of all blocks and calculation of
00565 //                    the respective fractions
00566 // Variable: iBad   - (Only works with iForce=true) Forces the current
00567 //                    all current blocks to be marked as bad
00568 //_____________________________________________________________________
00569 void L1TBPTX::doFractionInSync(bool iForce,bool iBad){
00570 
00571 }
00572 
00573 
00574 //_____________________________________________________________________
00575 // Method: certifyLSBlock
00576 // Description: Fill the trigger certification plot by blocks
00577 // Variable: iTrigger - Which trigger to certify
00578 // Variable: iInitLs  - Blocks initial LS
00579 // Variable: iEndLs   - Blocks end LS
00580 // Variable: iValue   - Value to be used to fill
00581 //_____________________________________________________________________
00582 void L1TBPTX::certifyLSBlock(string iTrigger, int iInitLs, int iEndLs ,float iValue){
00583 
00584 }
00585 
00586 //define this as a plug-in
00587 DEFINE_FWK_MODULE(L1TBPTX);