CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/L1TriggerConfig/L1GtConfigProducers/src/L1GtTriggerMenuTester.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtTriggerMenuTester.h"
00019 
00020 // system include files
00021 #include <iomanip>
00022 #include <boost/algorithm/string/erase.hpp>
00023 
00024 // user include files
00025 //   base class
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 
00031 #include "FWCore/Framework/interface/EventSetup.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 
00034 #include "CondFormats/L1TObjects/interface/L1GtStableParameters.h"
00035 #include "CondFormats/DataRecord/interface/L1GtStableParametersRcd.h"
00036 
00037 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00038 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00039 
00040 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
00041 
00042 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
00043 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsTechTrigRcd.h"
00044 
00045 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00046 
00047 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00048 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00049 
00050 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskVetoAlgoTrigRcd.h"
00051 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskVetoTechTrigRcd.h"
00052 
00053 #include "DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h"
00054 
00055 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00056 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00057 
00058 // forward declarations
00059 
00060 // constructor(s)
00061 L1GtTriggerMenuTester::L1GtTriggerMenuTester(const edm::ParameterSet& parSet) :
00062             m_overwriteHtmlFile(parSet.getParameter<bool> ("OverwriteHtmlFile")),
00063             m_htmlFile(parSet.getParameter<std::string> ("HtmlFile")),
00064             m_useHltMenu(parSet.getParameter<bool> ("UseHltMenu")),
00065             m_hltProcessName(parSet.getParameter<std::string> ("HltProcessName")),
00066             m_noThrowIncompatibleMenu(
00067                     parSet.getParameter<bool> ("NoThrowIncompatibleMenu")),
00068             m_printPfsRates(parSet.getParameter<bool> ("PrintPfsRates")),
00069             m_indexPfSet(parSet.getParameter<int> ("IndexPfSet")),
00070             m_numberAlgorithmTriggers(0), m_numberTechnicalTriggers(0) {
00071 
00072     // empty
00073 
00074 }
00075 
00076 // destructor
00077 L1GtTriggerMenuTester::~L1GtTriggerMenuTester() {
00078     // empty
00079 }
00080 
00081 // begin job
00082 void L1GtTriggerMenuTester::beginJob() {
00083 
00084 }
00085 
00086 // begin run
00087 void L1GtTriggerMenuTester::beginRun(const edm::Run& iRun,
00088         const edm::EventSetup& evSetup) {
00089 
00090     // retrieve L1 trigger configuration
00091     retrieveL1EventSetup(evSetup);
00092 
00093     // print with various level of verbosity
00094 
00095     // define an output stream to print into
00096     // it can then be directed to whatever log level is desired
00097     std::ostringstream myCout;
00098 
00099     int printVerbosity = 0;
00100     m_l1GtMenu->print(myCout, printVerbosity);
00101     myCout << std::flush << std::endl;
00102 
00103     printVerbosity = 1;
00104     m_l1GtMenu->print(myCout, printVerbosity);
00105     myCout << std::flush << std::endl;
00106 
00107     printVerbosity = 2;
00108     m_l1GtMenu->print(myCout, printVerbosity);
00109     myCout << std::flush << std::endl;
00110 
00111     // redirect myCout to edm::LogVerbatim TODO - parameter to choose the log
00112     edm::LogVerbatim("L1GtTriggerMenuTester") << myCout.str() << std::endl;
00113 
00114     // prepare L1 - HLT
00115     if (m_useHltMenu) {
00116         associateL1SeedsHltPath(iRun, evSetup);
00117 
00118         if (m_noThrowIncompatibleMenu) {
00119             edm::LogVerbatim("L1GtTriggerMenuTester")
00120                     << "\n List of algorithm triggers used as L1 seeds but not in L1 menu"
00121                     << std::endl;
00122 
00123             for (std::vector<std::string>::const_iterator strIter =
00124                     m_algoTriggerSeedNotInL1Menu.begin(); strIter
00125                     != m_algoTriggerSeedNotInL1Menu.end(); ++strIter) {
00126 
00127                 edm::LogVerbatim("L1GtTriggerMenuTester") << "   "
00128                         << (*strIter) << std::endl;
00129             }
00130 
00131         }
00132     }
00133 
00134     // print in wiki format
00135     printWiki();
00136 
00137 }
00138 
00139 // begin luminosity block
00140 void L1GtTriggerMenuTester::beginLuminosityBlock(const edm::LuminosityBlock& iLumiBlock,
00141         const edm::EventSetup& evSetup) {
00142 
00143 }
00144 
00145 // loop over events
00146 void L1GtTriggerMenuTester::analyze(const edm::Event& iEvent,
00147         const edm::EventSetup& evSetup) {
00148 
00149     // empty
00150 
00151 }
00152 
00153 // end luminosity block
00154 void L1GtTriggerMenuTester::endLuminosityBlock(const edm::LuminosityBlock& iLumiBlock,
00155         const edm::EventSetup& evSetup) {
00156 
00157 }
00158 
00159 // end run
00160 void L1GtTriggerMenuTester::endRun(const edm::Run&, const edm::EventSetup& evSetup) {
00161 
00162 }
00163 
00164 // end job
00165 void L1GtTriggerMenuTester::endJob() {
00166 
00167 }
00168 
00169 void L1GtTriggerMenuTester::retrieveL1EventSetup(const edm::EventSetup& evSetup) {
00170 
00171     // get / update the stable parameters from the EventSetup
00172 
00173     edm::ESHandle<L1GtStableParameters> l1GtStablePar;
00174     evSetup.get<L1GtStableParametersRcd> ().get(l1GtStablePar);
00175     m_l1GtStablePar = l1GtStablePar.product();
00176 
00177     // number of algorithm triggers
00178     m_numberAlgorithmTriggers = m_l1GtStablePar->gtNumberPhysTriggers();
00179 
00180     // number of technical triggers
00181     m_numberTechnicalTriggers = m_l1GtStablePar->gtNumberTechnicalTriggers();
00182 
00183 //    int maxNumberTrigger = std::max(m_numberAlgorithmTriggers,
00184 //            m_numberTechnicalTriggers);
00185 
00186 //    m_triggerMaskSet.reserve(maxNumberTrigger);
00187 //    m_prescaleFactorSet.reserve(maxNumberTrigger);
00188 
00189     // get / update the prescale factors from the EventSetup
00190 
00191 
00192     edm::ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
00193     evSetup.get<L1GtPrescaleFactorsAlgoTrigRcd> ().get(l1GtPfAlgo);
00194     m_l1GtPfAlgo = l1GtPfAlgo.product();
00195 
00196     m_prescaleFactorsAlgoTrig = &(m_l1GtPfAlgo->gtPrescaleFactors());
00197 
00198     edm::ESHandle<L1GtPrescaleFactors> l1GtPfTech;
00199     evSetup.get<L1GtPrescaleFactorsTechTrigRcd> ().get(l1GtPfTech);
00200     m_l1GtPfTech = l1GtPfTech.product();
00201 
00202     m_prescaleFactorsTechTrig = &(m_l1GtPfTech->gtPrescaleFactors());
00203 
00204     // get / update the trigger mask from the EventSetup
00205 
00206     edm::ESHandle<L1GtTriggerMask> l1GtTmAlgo;
00207     evSetup.get<L1GtTriggerMaskAlgoTrigRcd> ().get(l1GtTmAlgo);
00208     m_l1GtTmAlgo = l1GtTmAlgo.product();
00209 
00210     m_triggerMaskAlgoTrig = &(m_l1GtTmAlgo->gtTriggerMask());
00211 
00212     edm::ESHandle<L1GtTriggerMask> l1GtTmTech;
00213     evSetup.get<L1GtTriggerMaskTechTrigRcd> ().get(l1GtTmTech);
00214     m_l1GtTmTech = l1GtTmTech.product();
00215 
00216     m_triggerMaskTechTrig = &(m_l1GtTmTech->gtTriggerMask());
00217 
00218     edm::ESHandle<L1GtTriggerMask> l1GtTmVetoAlgo;
00219     evSetup.get<L1GtTriggerMaskVetoAlgoTrigRcd> ().get(l1GtTmVetoAlgo);
00220     m_l1GtTmVetoAlgo = l1GtTmVetoAlgo.product();
00221 
00222     m_triggerMaskVetoAlgoTrig = &(m_l1GtTmVetoAlgo->gtTriggerMask());
00223 
00224     edm::ESHandle<L1GtTriggerMask> l1GtTmVetoTech;
00225     evSetup.get<L1GtTriggerMaskVetoTechTrigRcd> ().get(l1GtTmVetoTech);
00226     m_l1GtTmVetoTech = l1GtTmVetoTech.product();
00227 
00228     m_triggerMaskVetoTechTrig = &(m_l1GtTmVetoTech->gtTriggerMask());
00229 
00230     // get / update the trigger menu from the EventSetup
00231 
00232     edm::ESHandle<L1GtTriggerMenu> l1GtMenu;
00233     evSetup.get<L1GtTriggerMenuRcd> ().get(l1GtMenu);
00234     m_l1GtMenu = l1GtMenu.product();
00235     (const_cast<L1GtTriggerMenu*> (m_l1GtMenu))->buildGtConditionMap();
00236 
00237     m_algorithmMap = &(m_l1GtMenu->gtAlgorithmMap());
00238     m_algorithmAliasMap = &(m_l1GtMenu->gtAlgorithmAliasMap());
00239 
00240     m_technicalTriggerMap = &(m_l1GtMenu->gtTechnicalTriggerMap());
00241 
00242 }
00243 
00244 void L1GtTriggerMenuTester::associateL1SeedsHltPath(const edm::Run& iRun,
00245         const edm::EventSetup& evSetup) {
00246 
00247     bool hltChanged = true;
00248 
00249     if (m_hltConfig.init(iRun, evSetup, m_hltProcessName, hltChanged)) {
00250 
00251         // if init returns TRUE, initialization has succeeded!
00252         if (hltChanged) {
00253 
00254             // HLT configuration has actually changed wrt the previous run
00255             m_hltTableName = m_hltConfig.tableName();
00256 
00257             edm::LogVerbatim("L1GtTriggerMenuTester")
00258                     << "\nHLT ConfDB menu name: \n   " << m_hltTableName
00259                     << std::endl;
00260 
00261             // loop over trigger paths, get the HLTLevel1GTSeed logical expression, and add the path to
00262             // each L1 trigger
00263 
00264             m_hltPathsForL1AlgorithmTrigger.resize(m_numberAlgorithmTriggers);
00265             m_hltPathsForL1TechnicalTrigger.resize(m_numberTechnicalTriggers);
00266 
00267             m_algoTriggerSeedNotInL1Menu.reserve(m_numberAlgorithmTriggers);
00268             m_techTriggerSeedNotInL1Menu.reserve(m_numberTechnicalTriggers);
00269 
00270             for (unsigned int iHlt = 0; iHlt < m_hltConfig.size(); ++iHlt) {
00271 
00272                 const std::string& hltPathName = m_hltConfig.triggerName(iHlt);
00273 
00274                 const std::vector<std::pair<bool, std::string> >& hltL1Seed =
00275                         m_hltConfig.hltL1GTSeeds(hltPathName);
00276 
00277                 unsigned int numberHltL1GTSeeds = hltL1Seed.size();
00278 
00279                 edm::LogVerbatim("L1GtTriggerMenuTester") << "\nPath: "
00280                         << hltPathName << " :    <== " << numberHltL1GTSeeds
00281                         << " HLTLevel1GTSeed module(s)" << std::endl;
00282 
00283                 for (unsigned int iSeedModule = 0; iSeedModule
00284                         < numberHltL1GTSeeds; ++iSeedModule) {
00285 
00286                     // one needs a non-const logical expression... TODO check why
00287                     std::string m_l1SeedsLogicalExpression =
00288                             (hltL1Seed[iSeedModule]).second;
00289 
00290                     edm::LogVerbatim("L1GtTriggerMenuTester") << "      '"
00291                             << m_l1SeedsLogicalExpression << "'";
00292 
00293                     // parse logical expression
00294 
00295                     if (m_l1SeedsLogicalExpression != "L1GlobalDecision") {
00296 
00297                         // check also the logical expression - add/remove spaces if needed
00298                         L1GtLogicParser m_l1AlgoLogicParser = L1GtLogicParser(
00299                                 m_l1SeedsLogicalExpression);
00300 
00301                         // list of required algorithms for seeding
00302                         std::vector<L1GtLogicParser::OperandToken>
00303                                 m_l1AlgoSeeds =
00304                                         m_l1AlgoLogicParser.expressionSeedsOperandList();
00305                         size_t l1AlgoSeedsSize = m_l1AlgoSeeds.size();
00306 
00307                         edm::LogVerbatim("L1GtTriggerMenuTester")
00308                                 << " :    <== " << l1AlgoSeedsSize
00309                                 << " L1 seeds" << std::endl;
00310 
00311                         // for each algorithm trigger, check if it is in the L1 menu, get the bit number
00312                         // and add path to the vector of strings for that bit number
00313 
00314                         for (size_t i = 0; i < l1AlgoSeedsSize; ++i) {
00315 
00316                             const std::string& trigNameOrAlias =
00317                                     (m_l1AlgoSeeds[i]).tokenName;
00318 
00319                             CItAlgo itAlgo = m_algorithmAliasMap->find(
00320                                     trigNameOrAlias);
00321                             if (itAlgo != m_algorithmAliasMap->end()) {
00322 
00323                                 int bitNr = (itAlgo->second).algoBitNumber();
00324 
00325                                 (m_hltPathsForL1AlgorithmTrigger.at(bitNr)).push_back(
00326                                         hltPathName);
00327 
00328                                 edm::LogVerbatim("L1GtTriggerMenuTester")
00329                                         << "         " << trigNameOrAlias
00330                                         << " bit " << bitNr << std::endl;
00331 
00332                             } else {
00333 
00334                                 if (m_noThrowIncompatibleMenu) {
00335                                     edm::LogVerbatim("L1GtTriggerMenuTester")
00336                                             << "         " << trigNameOrAlias
00337                                             << " trigger not in L1 menu "
00338                                             << m_l1GtMenu->gtTriggerMenuName()
00339                                             << std::endl;
00340 
00341                                     m_algoTriggerSeedNotInL1Menu.push_back(
00342                                             trigNameOrAlias);
00343 
00344                                 } else {
00345                                     throw cms::Exception("FailModule")
00346                                             << "\nAlgorithm  "
00347                                             << trigNameOrAlias
00348                                             << ", requested as seed by a HLT path, not found in the L1 trigger menu\n   "
00349                                             << m_l1GtMenu->gtTriggerMenuName()
00350                                             << "\nIncompatible L1 and HLT menus.\n"
00351                                             << std::endl;
00352 
00353                                 }
00354                             }
00355                         }
00356 
00357                     }
00358                 }
00359 
00360             }
00361         }
00362     } else {
00363         // if init returns FALSE, initialization has NOT succeeded, which indicates a problem
00364         // with the file and/or code and needs to be investigated!
00365         edm::LogError("MyAnalyzer")
00366                 << " HLT config extraction failure with process name "
00367                 << m_hltProcessName;
00368     }
00369 
00370 }
00371 
00372 // printing template for a trigger group
00373 void L1GtTriggerMenuTester::printTriggerGroup(const std::string& trigGroupName,
00374         const std::map<std::string, const L1GtAlgorithm*>& trigGroup,
00375         const bool compactPrint, const bool printPfsRates) {
00376 
00377     // FIXME get values - either read from a specific L1 menu file, or from
00378     std::string lumiVal1 = "5.0E33";
00379     std::string lumiVal2 = "7.0E33";
00380     std::string trigComment;
00381 
00382     int trigPfVal1 = 0;
00383     int trigPfVal2 = 0;
00384 
00385     int trigRateVal1 = 0;
00386     int trigRateVal2 = 0;
00387 
00388     // cumulative list of L1 triggers not used as seed by HLT
00389     std::vector < std::string > algoTriggerNotSeed;
00390     algoTriggerNotSeed.reserve(m_numberAlgorithmTriggers);
00391 
00392     std::vector < std::string > techTriggerNotSeed;
00393     techTriggerNotSeed.reserve(m_numberTechnicalTriggers);
00394 
00395     // force a page break before each group
00396     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00397             << "<p style=\"page-break-before: always\">&nbsp;</p>";
00398 
00399     edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "\n---++++ "
00400             << trigGroupName << "\n" << std::endl;
00401 
00402     if (compactPrint) {
00403         edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00404                 << "|  *Trigger Name*  |  *Trigger Alias*  |  *Bit*  |  *Comments*  |"
00405                 << std::endl;
00406 
00407     } else {
00408 
00409         if (printPfsRates) {
00410             edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00411                     << "|  *Trigger Name*  |  *Trigger Alias*  |  *Bit*  |  *Luminosity*  ||||  *Seed for !HLT path(s)*  |  *Comments*  |"
00412                     << std::endl;
00413 
00414             edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "|^|^|^|  *"
00415                     << lumiVal1 << "*  ||  *" << lumiVal2
00416                     << "*  ||  **  |  **  |" << std::endl;
00417 
00418             edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00419                     << "|^|^|^|  *PF*  |  *Rate*  |  *PF*  |  *Rate*  |  ** |  **  |"
00420                     << std::endl;
00421 
00422         } else {
00423 
00424             edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00425                     << "|  *Trigger Name*  |  *Trigger Alias*  |  *Bit*  |  *Seed for !HLT path(s)*  |"
00426                     << std::endl;
00427         }
00428 
00429     }
00430 
00431     for (CItAlgoP itAlgo = trigGroup.begin(); itAlgo != trigGroup.end(); itAlgo++) {
00432 
00433         const std::string& aName = (itAlgo->second)->algoName();
00434         const std::string& aAlias = (itAlgo->second)->algoAlias();
00435         const int& bitNumber = (itAlgo->second)->algoBitNumber();
00436 
00437 
00438         // concatenate in a string, to simplify the next print instruction
00439         std::string seedsHlt;
00440         if (m_useHltMenu) {
00441             const std::vector<std::string> & hltPaths =
00442                     m_hltPathsForL1AlgorithmTrigger.at(bitNumber);
00443 
00444             if (hltPaths.size() < 1) {
00445                 algoTriggerNotSeed.push_back(aAlias);
00446                 seedsHlt
00447                         = "<font color = \"red\">Not used as seed by any !HLT path</font>";
00448             } else {
00449 
00450                 for (std::vector<std::string>::const_iterator strIter =
00451                         hltPaths.begin(); strIter != hltPaths.end(); ++strIter) {
00452 
00453                     seedsHlt = seedsHlt + (*strIter) + "<BR>";
00454                 }
00455             }
00456 
00457         }
00458 
00459         if (compactPrint) {
00460             edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "|" << std::left
00461                     << "[[" << (m_htmlFile + "#" + aName) << "][ " << aName
00462                     << "]] " << "  |" << aAlias << "  |  " << bitNumber << "| |"
00463                     << std::endl;
00464 
00465         } else {
00466 
00467             if (printPfsRates) {
00468                 edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "|"
00469                         << std::left << "[[" << (m_htmlFile + "#" + aName)
00470                         << "][ " << aName << "]] " << "  |" << aAlias
00471                         << "  |  " << bitNumber << "|  "
00472                         << ((trigPfVal1 != 0) ? trigPfVal1 : 0) << "  |  "
00473                         << ((trigRateVal1 != 0) ? trigRateVal1 : 0) << "  |  "
00474                         << ((trigPfVal2 != 0) ? trigPfVal2 : 0) << "  |  "
00475                         << ((trigRateVal2 != 0) ? trigRateVal2 : 0) << "  |  "
00476                         << seedsHlt << "  |  " << trigComment << "  |"
00477                         << std::endl;
00478 
00479             } else {
00480 
00481                 edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "|"
00482                         << std::left << "[[" << (m_htmlFile + "#" + aName)
00483                         << "][ " << aName << "]] " << "  |" << aAlias
00484                         << "  |  " << bitNumber << "|" << seedsHlt << "  |  "
00485                         << std::endl;
00486             }
00487 
00488         }
00489 
00490     }
00491 
00492     edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "\n" << trigGroupName
00493             << ": " << (trigGroup.size()) << " bits defined." << std::endl;
00494 
00495     if (m_useHltMenu && (!compactPrint)) {
00496         edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00497                 << "\n Algorithm triggers from " << trigGroupName
00498                 << " not used as seeds by !HLT:" << std::endl;
00499 
00500         if (algoTriggerNotSeed.size() != 0) {
00501             for (std::vector<std::string>::const_iterator strIter =
00502                     algoTriggerNotSeed.begin(); strIter
00503                     != algoTriggerNotSeed.end(); ++strIter) {
00504 
00505                 edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "   * "
00506                         << (*strIter) << std::endl;
00507             }
00508 
00509         } else {
00510             edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "   * none"
00511                     << std::endl;
00512         }
00513     }
00514 
00515 }
00516 
00518 void L1GtTriggerMenuTester::printWiki() {
00519 
00520     //
00521     // print menu, prescale factors and trigger mask in wiki format
00522     //
00523 
00524     // L1 GT prescale factors for algorithm triggers
00525 
00526     std::vector<int> prescaleFactorsAlgoTrig = m_prescaleFactorsAlgoTrig->at(
00527             m_indexPfSet);
00528 
00529     // L1 GT prescale factors for technical triggers
00530 
00531     std::vector<int> prescaleFactorsTechTrig = m_prescaleFactorsTechTrig->at(
00532             m_indexPfSet);
00533 
00534     // use another map <int, L1GtAlgorithm> to get the menu sorted after bit number
00535     // both algorithm and bit numbers are unique
00536     typedef std::map<int, const L1GtAlgorithm*>::const_iterator CItBit;
00537 
00538     //    algorithm triggers
00539 
00540     std::map<int, const L1GtAlgorithm*> algoBitToAlgo;
00541 
00542     std::map<std::string, const L1GtAlgorithm*> jetAlgoTrig;
00543     std::map<std::string, const L1GtAlgorithm*> egammaAlgoTrig;
00544     std::map<std::string, const L1GtAlgorithm*> esumAlgoTrig;
00545     std::map<std::string, const L1GtAlgorithm*> muonAlgoTrig;
00546     std::map<std::string, const L1GtAlgorithm*> crossAlgoTrig;
00547     std::map<std::string, const L1GtAlgorithm*> bkgdAlgoTrig;
00548 
00549     int algoTrigNumber = 0;
00550     int freeAlgoTrigNumber = 0;
00551 
00552     int jetAlgoTrigNumber = 0;
00553     int egammaAlgoTrigNumber = 0;
00554     int esumAlgoTrigNumber = 0;
00555     int muonAlgoTrigNumber = 0;
00556     int crossAlgoTrigNumber = 0;
00557     int bkgdAlgoTrigNumber = 0;
00558 
00559     for (CItAlgo itAlgo = m_algorithmMap->begin(); itAlgo
00560             != m_algorithmMap->end(); itAlgo++) {
00561 
00562         const int bitNumber = (itAlgo->second).algoBitNumber();
00563         const std::string& algName = (itAlgo->second).algoName();
00564 
00565         algoBitToAlgo[bitNumber] = &(itAlgo->second);
00566 
00567         algoTrigNumber++;
00568 
00569         // per category
00570 
00571         const ConditionMap& conditionMap = (m_l1GtMenu->gtConditionMap()).at(
00572                 (itAlgo->second).algoChipNumber());
00573 
00574         const std::vector<L1GtLogicParser::TokenRPN>& rpnVector =
00575                 (itAlgo->second).algoRpnVector();
00576         const L1GtLogicParser::OperationType condOperand =
00577                 L1GtLogicParser::OP_OPERAND;
00578 
00579         std::list<L1GtObject> listObjects;
00580 
00581         for (size_t i = 0; i < rpnVector.size(); ++i) {
00582 
00583             if ((rpnVector[i]).operation == condOperand) {
00584 
00585                 const std::string& cndName = (rpnVector[i]).operand;
00586 
00587                 // search the condition in the condition list
00588 
00589                 bool foundCond = false;
00590 
00591                 CItCond itCond = conditionMap.find(cndName);
00592                 if (itCond != conditionMap.end()) {
00593                     foundCond = true;
00594 
00595                     // loop through object types and add them to the list
00596 
00597                     const std::vector<L1GtObject>& objType =
00598                             (itCond->second)->objectType();
00599 
00600                     for (std::vector<L1GtObject>::const_iterator itObject =
00601                             objType.begin(); itObject != objType.end(); itObject++) {
00602                         listObjects.push_back(*itObject);
00603 
00604                         edm::LogVerbatim("L1GtTriggerMenuTester")
00605                                 << (*itObject) << std::endl;
00606                     }
00607 
00608                     // FIXME for XML parser, add GtExternal to objType correctly
00609                     if ((itCond->second)->condCategory() == CondExternal) {
00610                         listObjects.push_back(GtExternal);
00611                     }
00612 
00613                 }
00614 
00615                 if (!foundCond) {
00616 
00617                     // it should never be happen, all conditions are in the maps
00618                     throw cms::Exception("FailModule") << "\nCondition "
00619                             << cndName << " not found in the condition map"
00620                             << " for chip number "
00621                             << ((itAlgo->second).algoChipNumber()) << std::endl;
00622                 }
00623 
00624             }
00625 
00626         }
00627 
00628         // eliminate duplicates
00629         listObjects.sort();
00630         listObjects.unique();
00631 
00632         // add the algorithm to the corresponding group
00633 
00634         bool jetGroup = false;
00635         bool egammaGroup = false;
00636         bool esumGroup = false;
00637         bool muonGroup = false;
00638         bool crossGroup = false;
00639         bool bkgdGroup = false;
00640 
00641         for (std::list<L1GtObject>::const_iterator itObj = listObjects.begin(); itObj
00642                 != listObjects.end(); ++itObj) {
00643 
00644             switch (*itObj) {
00645                 case Mu: {
00646                     muonGroup = true;
00647                 }
00648 
00649                     break;
00650                 case NoIsoEG: {
00651                     egammaGroup = true;
00652                 }
00653 
00654                     break;
00655                 case IsoEG: {
00656                     egammaGroup = true;
00657                 }
00658 
00659                     break;
00660                 case CenJet: {
00661                     jetGroup = true;
00662                 }
00663 
00664                     break;
00665                 case ForJet: {
00666                     jetGroup = true;
00667                 }
00668 
00669                     break;
00670                 case TauJet: {
00671                     jetGroup = true;
00672                 }
00673 
00674                     break;
00675                 case ETM: {
00676                     esumGroup = true;
00677 
00678                 }
00679 
00680                     break;
00681                 case ETT: {
00682                     esumGroup = true;
00683 
00684                 }
00685 
00686                     break;
00687                 case HTT: {
00688                     esumGroup = true;
00689 
00690                 }
00691 
00692                     break;
00693                 case HTM: {
00694                     esumGroup = true;
00695 
00696                 }
00697 
00698                     break;
00699                 case JetCounts: {
00700                     // do nothing - not available
00701                 }
00702 
00703                     break;
00704                 case HfBitCounts: {
00705                     bkgdGroup = true;
00706                 }
00707 
00708                     break;
00709                 case HfRingEtSums: {
00710                     bkgdGroup = true;
00711                 }
00712 
00713                     break;
00714                 case GtExternal: {
00715                     bkgdGroup = true;
00716                 }
00717 
00718                     break;
00719                 case TechTrig:
00720                 case Castor:
00721                 case BPTX:
00722                 default: {
00723                     // should not arrive here
00724 
00725                     edm::LogVerbatim("L1GtTriggerMenuTester")
00726                             << "\n      Unknown object of type " << *itObj
00727                             << std::endl;
00728                 }
00729                     break;
00730             }
00731 
00732         }
00733 
00734         int sumGroup = jetGroup + egammaGroup + esumGroup + muonGroup
00735                 + crossGroup + bkgdGroup;
00736 
00737         if (sumGroup > 1) {
00738             crossAlgoTrig[algName] = &(itAlgo->second);
00739         } else {
00740 
00741             if (jetGroup) {
00742                 jetAlgoTrig[algName] = &(itAlgo->second);
00743 
00744             } else if (egammaGroup) {
00745                 egammaAlgoTrig[algName] = &(itAlgo->second);
00746 
00747             } else if (esumGroup && (listObjects.size() > 1)) {
00748                 crossAlgoTrig[algName] = &(itAlgo->second);
00749 
00750             } else if (esumGroup) {
00751                 esumAlgoTrig[algName] = &(itAlgo->second);
00752 
00753             } else if (muonGroup) {
00754                 muonAlgoTrig[algName] = &(itAlgo->second);
00755 
00756             } else if (bkgdGroup) {
00757                 bkgdAlgoTrig[algName] = &(itAlgo->second);
00758 
00759             } else {
00760                 // do nothing
00761             }
00762 
00763         }
00764 
00765         edm::LogVerbatim("L1GtTriggerMenuTester") << algName << " sum: "
00766                 << sumGroup << " size: " << listObjects.size() << std::endl;
00767 
00768     }
00769 
00770     freeAlgoTrigNumber = m_numberAlgorithmTriggers - algoTrigNumber;
00771 
00772     jetAlgoTrigNumber = jetAlgoTrig.size();
00773     egammaAlgoTrigNumber = egammaAlgoTrig.size();
00774     esumAlgoTrigNumber = esumAlgoTrig.size();
00775     muonAlgoTrigNumber = muonAlgoTrig.size();
00776     crossAlgoTrigNumber = crossAlgoTrig.size();
00777     bkgdAlgoTrigNumber = bkgdAlgoTrig.size();
00778 
00779     //    technical triggers
00780     std::map<int, const L1GtAlgorithm*> techBitToAlgo;
00781 
00782     int techTrigNumber = 0;
00783     int freeTechTrigNumber = 0;
00784 
00785     for (CItAlgo itAlgo = m_technicalTriggerMap->begin(); itAlgo
00786             != m_technicalTriggerMap->end(); itAlgo++) {
00787 
00788         int bitNumber = (itAlgo->second).algoBitNumber();
00789         techBitToAlgo[bitNumber] = &(itAlgo->second);
00790 
00791         techTrigNumber++;
00792     }
00793 
00794     freeTechTrigNumber = m_numberTechnicalTriggers - techTrigNumber;
00795 
00796     // name of the attached HTML file
00797     if (!m_overwriteHtmlFile) {
00798         std::string menuName = m_l1GtMenu->gtTriggerMenuImplementation();
00799 
00800         // replace "/" with "_"
00801         std::replace(menuName.begin(), menuName.end(), '/', '_');
00802         m_htmlFile = "%ATTACHURL%/" + menuName + ".html";
00803     } else {
00804         m_htmlFile = "%ATTACHURL%/" + m_htmlFile;
00805     }
00806 
00807     // header for printing algorithms
00808 
00809     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00810             << "\n   ********** L1 Trigger Menu - printing in wiki format  ********** \n\n"
00811             << "\n---+++ L1 menu identification\n"
00812             << "\n|L1 Trigger Menu Interface: |!"
00813             << m_l1GtMenu->gtTriggerMenuInterface() << " |"
00814             << "\n|L1 Trigger Menu Name: |!" << m_l1GtMenu->gtTriggerMenuName()
00815             << " |" << "\n|L1 Trigger Menu Implementation: |!"
00816             << m_l1GtMenu->gtTriggerMenuImplementation() << " |"
00817             << "\n|Associated L1 scale DB key: |!"
00818             << m_l1GtMenu->gtScaleDbKey() << " |" << "\n\n" << std::flush
00819             << std::endl;
00820 
00821     // Overview page
00822     edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "\n---+++ Summary\n"
00823             << std::endl;
00824     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00825             << "   * Number of algorithm triggers: " << algoTrigNumber
00826             << " defined, 128 possible." << std::endl;
00827     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00828             << "   * Number of technical triggers: " << techTrigNumber
00829             << " defined,  64 possible.<BR><BR>" << std::endl;
00830 
00831     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00832             << "   * Number of free bits for algorithm triggers: "
00833             << freeAlgoTrigNumber << std::endl;
00834     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00835             << "   * Number of free bits for technical triggers: "
00836             << freeTechTrigNumber << "<BR>" << std::endl;
00837 
00838     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00839             << "\nNumber of algorithm triggers per trigger group\n"
00840             << std::endl;
00841     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00842             << "    | *Trigger group* | *Number of bits used*|" << std::endl;
00843     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00844             << "    | Jet algorithm triggers: |  " << jetAlgoTrigNumber << "|"
00845             << std::endl;
00846     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00847             << "    | EGamma algorithm triggers: |  " << egammaAlgoTrigNumber
00848             << "|" << std::endl;
00849     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00850             << "    | Energy sum algorithm triggers: |  " << esumAlgoTrigNumber
00851             << "|" << std::endl;
00852     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00853             << "    | Muon algorithm triggers: |  " << muonAlgoTrigNumber
00854             << "|" << std::endl;
00855     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00856             << "    | Cross algorithm triggers: |  " << crossAlgoTrigNumber
00857             << "|" << std::endl;
00858     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00859             << "    | Background algorithm triggers: |  " << bkgdAlgoTrigNumber
00860             << "|" << std::endl;
00861 
00862     // force a page break
00863     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00864             << "<p style=\"page-break-before: always\">&nbsp;</p>";
00865 
00866     // compact print - without HLT path
00867     bool compactPrint = true;
00868 
00869     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00870             << "\n---+++ List of algorithm triggers sorted by trigger groups\n"
00871             << std::endl;
00872 
00873     // Jet algorithm triggers
00874     printTriggerGroup("Jet algorithm triggers", jetAlgoTrig, compactPrint,
00875             m_printPfsRates);
00876 
00877     // EGamma algorithm triggers
00878     printTriggerGroup("EGamma algorithm triggers", egammaAlgoTrig,
00879             compactPrint, m_printPfsRates);
00880 
00881     // Energy sum algorithm triggers
00882     printTriggerGroup("Energy sum algorithm triggers", esumAlgoTrig,
00883             compactPrint, m_printPfsRates);
00884 
00885     // Muon algorithm triggers
00886     printTriggerGroup("Muon algorithm triggers", muonAlgoTrig, compactPrint,
00887             m_printPfsRates);
00888 
00889     // Cross algorithm triggers
00890     printTriggerGroup("Cross algorithm triggers", crossAlgoTrig, compactPrint,
00891             m_printPfsRates);
00892 
00893     // Background algorithm triggers
00894     printTriggerGroup("Background algorithm triggers", bkgdAlgoTrig,
00895             compactPrint, m_printPfsRates);
00896 
00897     // force a page break
00898     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00899             << "<p style=\"page-break-before: always\">&nbsp;</p>";
00900 
00901     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00902             << "\n---+++ List of algorithm triggers sorted by bits\n"
00903             << std::endl;
00904 
00905     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00906             << "| *Algorithm* | *Alias* | *Bit number* |" << std::endl;
00907 
00908     for (CItBit itBit = algoBitToAlgo.begin(); itBit != algoBitToAlgo.end(); itBit++) {
00909 
00910         int bitNumber = itBit->first;
00911         std::string aName = (itBit->second)->algoName();
00912         std::string aAlias = (itBit->second)->algoAlias();
00913 
00914         edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "|" << std::left
00915                 << "[[" << (m_htmlFile + "#" + aName) << "][ " << aName
00916                 << "]] " << "  |" << aAlias << "  |  " << bitNumber << "| |"
00917                 << std::endl;
00918 
00919     }
00920 
00921     // force a page break
00922     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00923             << "<p style=\"page-break-before: always\">&nbsp;</p>";
00924     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00925             << "\n---+++ List of technical triggers\n" << std::endl;
00926 
00927     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00928             << "| *Technical trigger* | *Bit number* |" << std::endl;
00929 
00930     for (CItBit itBit = techBitToAlgo.begin(); itBit != techBitToAlgo.end(); itBit++) {
00931 
00932         int bitNumber = itBit->first;
00933         std::string aName = (itBit->second)->algoName();
00934         std::string aAlias = (itBit->second)->algoAlias();
00935 
00936         edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << "|!" << std::left
00937                 << aName << "  |  " << std::right << bitNumber << " |"
00938                 << std::endl;
00939     }
00940 
00941     // force a page break
00942     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00943             << "<p style=\"page-break-before: always\">&nbsp;</p>";
00944 
00945     // compact print false: with HLT path association, if the parameter m_useHltMenu is true
00946     // otherwise, we have no association computed
00947 
00948     if (m_useHltMenu) {
00949         compactPrint = false;
00950     } else {
00951         return;
00952     }
00953 
00954     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00955             << "\n---+++ List of algorithm triggers sorted by trigger groups, including !HLT path association \n"
00956             << std::endl;
00957 
00958     edm::LogVerbatim("L1GtTriggerMenuTesterWiki")
00959             << "\n The following !HLT menu was used to associate the !HLT path to the L1 algorithm triggers:\n    "
00960             << std::endl;
00961     edm::LogVerbatim("L1GtTriggerMenuTesterWiki") << m_hltTableName
00962             << std::endl;
00963 
00964     // Jet algorithm triggers
00965     printTriggerGroup("Jet algorithm triggers", jetAlgoTrig, compactPrint,
00966             m_printPfsRates);
00967 
00968     // EGamma algorithm triggers
00969     printTriggerGroup("EGamma algorithm triggers", egammaAlgoTrig,
00970             compactPrint, m_printPfsRates);
00971 
00972     // Energy sum algorithm triggers
00973     printTriggerGroup("Energy sum algorithm triggers", esumAlgoTrig,
00974             compactPrint, m_printPfsRates);
00975 
00976     // Muon algorithm triggers
00977     printTriggerGroup("Muon algorithm triggers", muonAlgoTrig, compactPrint,
00978             m_printPfsRates);
00979 
00980     // Cross algorithm triggers
00981     printTriggerGroup("Cross algorithm triggers", crossAlgoTrig, compactPrint,
00982             m_printPfsRates);
00983 
00984     // Background algorithm triggers
00985     printTriggerGroup("Background algorithm triggers", bkgdAlgoTrig,
00986             compactPrint, m_printPfsRates);
00987 
00988 }