CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQM/TrigXMonitor/src/HLTSeedL1LogicScalers.cc

Go to the documentation of this file.
00001 
00002 // $Id: HLTSeedL1LogicScalers.cc,v 1.9 2010/10/13 13:47:23 eulisse Exp $
00003 
00004 #include "DQM/TrigXMonitor/interface/HLTSeedL1LogicScalers.h"
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00009 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00010 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00011 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00012 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00013 
00014 
00015 
00016 using namespace edm;
00017 using namespace std;
00018 using namespace trigger;
00019 
00020 //
00021 // constants, enums and typedefs
00022 //
00023 
00024 //
00025 // static data member definitions
00026 //
00027 
00028 //
00029 // constructors and destructor
00030 //
00031 HLTSeedL1LogicScalers::HLTSeedL1LogicScalers(const edm::ParameterSet& iConfig)
00032 
00033 {
00034    //now do what ever initialization is needed
00035   LogDebug("HLTSeedL1LogicScalers") << "constructor" ;
00036 
00037   // get untracked parameters
00039   fL1BeforeMask = iConfig.getParameter<bool>("l1BeforeMask");
00040   fProcessname  = iConfig.getParameter<std::string>("processname");
00041 
00042   // input tag for GT DAQ product
00043   fL1GtDaqReadoutRecordInputTag  = iConfig.getParameter<edm::InputTag>("L1GtDaqReadoutRecordInputTag");
00044 
00045   // input tag for GT lite product
00046   fL1GtRecordInputTag = iConfig.getParameter<edm::InputTag>("L1GtRecordInputTag");
00047 
00048   // get untracked parameters
00050   fDQMFolder    = iConfig.getUntrackedParameter("DQMFolder", string("HLT/HLTSeedL1LogicScalers/HLT_LogicL1"));
00051   fMonitorPaths = iConfig.getUntrackedParameter<std::vector<std::string > >("monitorPaths");
00052 
00053   fDbe = Service < DQMStore > ().operator->();
00054 
00055   if ( ! fDbe ) {
00056     LogInfo("HLTSeedL1LogicScalers") << "unable to get DQMStore service?";
00057   }
00058   else {
00059     fDbe->setCurrentFolder(fDQMFolder);
00060   }
00061   
00062 }
00063 
00064 
00065 HLTSeedL1LogicScalers::~HLTSeedL1LogicScalers()
00066 {
00067 }
00068 
00069 void
00070 HLTSeedL1LogicScalers::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00071 {
00072 
00073   LogDebug("HLTSeedL1LogicScalers") << "HLTSeedL1LogicScalers::analyze  event " ;
00074 
00075   // before accessing any result from L1GtUtils, one must retrieve and cache
00076   // the L1 trigger event setup
00077   // add this call in the analyze / produce / filter method of your
00078   // analyzer / producer / filter
00079 
00080   m_l1GtUtils.retrieveL1EventSetup(iSetup);
00081 
00082   // loop over maps of ME-L1Algos
00083   for (unsigned int i=0;i<fMapMEL1Algos.size();i++) {
00084 
00085     MonitorElement* me = fMapMEL1Algos[i].first;
00086     LogTrace("HLTSeedL1LogicScalers") << "ME = " << me->getName() << endl;
00087     
00088     const vector<string>& l1Algos = fMapMEL1Algos[i].second;
00089 
00090     // word to bit-pack decisions of l1Algos
00091     unsigned int myL1Word = 0;
00092 
00093     // loop over l1Algos 
00094     for (unsigned int j=0;j<l1Algos.size();j++) {
00095 
00096       // check if this l1Algo passed
00097       bool l1Pass = analyzeL1GtUtils(iEvent, iSetup, l1Algos[j]);
00098       LogTrace("HLTSeedL1LogicScalers") << "l1Algo = " << l1Algos[j] << "  l1Pass = " <<  l1Pass << endl;
00099       if(l1Pass) {
00100         
00101         // bit-wise pack
00102         myL1Word |= (1<<j);
00103 
00104       }
00105 /*
00106 */
00107 
00108     } 
00109 
00110     me->Fill(myL1Word);
00111 
00112   } // end for i maps
00113 
00114 }
00115 
00116 
00117 
00118 void 
00119 HLTSeedL1LogicScalers::beginRun(const edm::Run& run, const edm::EventSetup& iSetup)
00120 {
00121 
00122   // Get configuration of HLT menu used in this run
00123   LogTrace("HLTSeedL1LogicScalers") << "beginRun, run " << run.id();
00124   fDbe->setCurrentFolder(fDQMFolder);
00125   
00126   // HLT config does not change within runs!
00127 
00128   bool changed = false;
00129  
00130   if (!fHLTConfig.init(run, iSetup, fProcessname, changed)) {
00131 
00132     LogDebug("HLTSeedL1LogicScalers") << "HLTConfigProvider failed to initialize.";
00133     return;
00134 
00135     // check if trigger name in (new) config
00136     //  cout << "Available TriggerNames are: " << endl;
00137     //  fHLTConfig.dump("Triggers");
00138 
00139   }
00140 
00141   const unsigned int n(fHLTConfig.size());
00142 
00143   for (unsigned int j=0; j!=n; ++j) {
00144   
00145     LogTrace("HLTSeedL1LogicScalers") << "HLTConfig path " << fHLTConfig.triggerName(j) << endl;
00146 
00147   }
00148 
00149   // book histos for L1 logic of specificified HLT paths
00150   LogTrace("HLTSeedL1LogicScalers") << "size of vector of paths to monitor = " << fMonitorPaths.size() << endl;
00151   for (unsigned int iPath=0;iPath<fMonitorPaths.size();iPath++) {
00152 
00153     string monPath = fMonitorPaths[iPath];
00154     LogTrace("HLTSeedL1LogicScalers") << "monPath = " << monPath << endl;
00155 
00156     string folderName = fDQMFolder + "/" + monPath;
00157     fDbe->setCurrentFolder(folderName);
00158     
00159     // do nothing if monPath is not in the HLT menu
00160     if(fHLTConfig.triggerIndex(monPath) == fHLTConfig.size()) continue;
00161     // get L1SeedLogicalExpression of this path
00162     vector<pair<bool,string> > hltL1GTSeed = fHLTConfig.hltL1GTSeeds(monPath);
00163     LogTrace("HLTSeedL1LogicScalers") << endl << "size of vector of GTSeedL1LogicalExpression = " << hltL1GTSeed.size() << endl;
00164 
00165     // each GT Seed of each path contains l1Algos
00166     for (unsigned int iSeed=0;iSeed<hltL1GTSeed.size();iSeed++) {
00167 
00168       LogTrace("HLTSeedL1LogicScalers") << "  TechBit_flag = " << hltL1GTSeed[iSeed].first << "  GTSeedL1LogicalExpression = " << hltL1GTSeed[iSeed].second << endl;;
00169 
00170       istringstream totalSString( hltL1GTSeed[iSeed].second );
00171       string temp_string;
00172 
00173       vector<string> l1Algos;
00174 
00175       // only if not TechBit flag
00176       while(! hltL1GTSeed[iSeed].first) {
00177 
00178         totalSString >> temp_string;
00179 
00180         if(! l1Algos.empty()) {
00181           
00182           if(temp_string.compare(l1Algos.back()) == 0) break;
00183 
00184         }
00185         if(temp_string != "OR" && temp_string != "AND" && temp_string != "NOT" && temp_string != "(" && temp_string != ")" && temp_string != ""){
00186 
00187           l1Algos.push_back(temp_string);
00188 
00189         }
00190       }
00191 
00192       int nL1Algo = l1Algos.size();
00193 
00194       // put an upper limit on the size of l1Algos
00195       if(nL1Algo > 32) {
00196 
00197         LogWarning("HLTSeedL1LogicScalers") << "  number of l1 Algos grater than 32. Using only the first 32." << endl ;
00198         l1Algos.resize(32);
00199 
00200       }
00201       int nBins = 1 << nL1Algo;
00202 
00203       for (unsigned int k=0;k< l1Algos.size();k++) {
00204 
00205         LogTrace("HLTSeedL1LogicScalers") << "  l1 Algo = " << l1Algos[k] << endl;
00206 
00207 
00208       } // end for k
00209 
00210       //char title[100];
00211       //char name[100];
00212 
00213       std::stringstream title;
00214       std::stringstream name;
00215 
00216       name << monPath << "_Seed_" << iSeed << "_L1BitLogic";
00217       title << monPath << "  BitPacked L1Algos of GTSeed " << iSeed << ": '" << hltL1GTSeed[iSeed].second << "'";
00218 
00219       //sprintf(name,"%s_Seed_%d_L1BitLogic",monPath.c_str(),iSeed);
00220       //sprintf(title,"%s BitPacked L1Algos of GTSeed %d: '%s'",monPath.c_str(), iSeed, hltL1GTSeed[iSeed].second.c_str());
00221 
00222       LogTrace("HLTSeedL1LogicScalers") << "  MonitorElement name = " << name << endl;
00223       LogTrace("HLTSeedL1LogicScalers") << "  MonitorElement title = " << title << endl;
00224       LogTrace("HLTSeedL1LogicScalers") << "  MonitorElement nBins = " << nBins << endl << endl;
00225 
00226       MonitorElement* me = fDbe->book1D(name.str().c_str(), title.str().c_str(), nBins,0,nBins);
00227       me->setAxisTitle("bit-packed word L1 Algorithms");
00228       fMonitorPathsME.push_back(me);
00229 
00230       // pair of 1D hisotgram and vector of l1Algos
00231       //pair<MonitorElement*, vector<string> > pairMEL1Algo;
00232       //pairMEL1Algo.first = me;
00233       //pairMEL1Algo.second = l1Algos;
00234       //fMapMEL1Algos.push_back(pairMEL1Algo);
00235       fMapMEL1Algos.push_back(make_pair(me, l1Algos));
00236 
00237    } // end for Seeds
00238 
00239 
00240 
00241   } // end for monitoring paths
00242 
00243 }
00244 
00245 void 
00246 HLTSeedL1LogicScalers::beginJob()
00247 {
00248 }
00249 
00250 // ------------ method called once each job just after ending the event loop  ------------
00251 void 
00252 HLTSeedL1LogicScalers::endJob() {
00253 }
00254 
00255 bool HLTSeedL1LogicScalers::analyzeL1GtUtils(const edm::Event& iEvent, const edm::EventSetup& evSetup, const string & l1AlgoName)
00256 {
00257 
00258   LogTrace("HLTSeedL1LogicScalers") << "analyzeL1GtUtils..." << endl;
00259 
00260     // access L1 trigger results using public methods from L1GtUtils
00261     // always check on error code returned by that method
00262 
00263     int iErrorCode = -1;
00264 
00265     
00266     LogTrace("HLTSeedL1LogicScalers") << "l1AlgoName = " << l1AlgoName << endl;
00267 
00268     bool decisionAlgTechTrig = false;
00269 
00270     // check flag L1BeforeMask
00271     if (fL1BeforeMask) {
00272       
00273       decisionAlgTechTrig = m_l1GtUtils.decisionBeforeMask(iEvent, fL1GtRecordInputTag, fL1GtDaqReadoutRecordInputTag, l1AlgoName, iErrorCode);
00274 
00275     } 
00276     else {
00277 
00278      decisionAlgTechTrig = m_l1GtUtils.decisionAfterMask(iEvent, fL1GtRecordInputTag, fL1GtDaqReadoutRecordInputTag, l1AlgoName, iErrorCode);
00279 
00280     }
00281 
00282     LogTrace("HLTSeedL1LogicScalers") << "bool L1BeforeMask = " << fL1BeforeMask << "  decisionAlgTechTrig = " << decisionAlgTechTrig << endl;
00283 
00284     if (iErrorCode == 0) {
00285  
00286       return decisionAlgTechTrig; 
00287 
00288     } else if (iErrorCode == 1) {
00289         
00290       // algorithm / technical trigger  does not exist in the L1 menu
00291       LogWarning("HLTSeedL1LogicScalers") << "L1 algorithm " << l1AlgoName << " not in L1 menu, but HLTConfigProvider found it in L1SeedsLogicalExpression of at least one HLT path of the HLT menu." << endl;
00292       return false;
00293 
00294     } else {
00295 
00296       // error - see error code
00297       // do whatever needed
00298       return false;
00299 
00300     }
00301 
00302     return false;
00303 
00304 }
00305 
00306 bool HLTSeedL1LogicScalers::analyzeL1GtRecord(const edm::Event& iEvent, const edm::EventSetup& evSetup, string l1AlgoName)
00307 {
00308   LogTrace("HLTSeedL1LogicScalers") << "analyzeL1GtRecord.. " << endl;
00309 /*
00310   edm::Handle<L1GtTriggerMenu> menuRcd;
00311   evSetup.get<L1GtTriggerMenuRcd>().get(menuRcd) ;
00312   const L1GtTriggerMenu* menu = menuRcd.product();
00313 
00314   edm::Handle< L1GlobalTriggerReadoutRecord > gtReadoutRecord;
00315   iEvent.getByLabel( edm::InputTag("gtDigis"), gtReadoutRecord);
00316   const  DecisionWord& gtDecisionWordBeforeMask = = gtReadoutRecord->decisionWord();
00317 
00318   // test if the algorithm name is in the menu
00319   
00320   const AlgorithmMap& algorithmMap = menu->gtAlgorithmMap();
00321   CItAlgo itAlgo = algorithmMap.find(l1AlgoName);
00322   if (itAlgo != algorithmAliasMap.end()) {
00323       bool l1Result = menu->gtAlgorithmResult( l1AlgoName, gtDecisionWordBeforeMask);
00324       return l1Result;
00325   } else {
00326       // algorithm not in the L1 menu - do whatever needed
00327       return false;
00328   }
00329 */
00330  return false;
00331 
00332 }