CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/L1Trigger/GlobalTriggerAnalyzer/src/L1GtUtils.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
00019 
00020 // system include files
00021 #include <iomanip>
00022 
00023 // user include files
00024 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00025 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00026 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerRecord.h"
00027 
00028 #include "FWCore/Framework/interface/ESHandle.h"
00029 
00030 #include "CondFormats/L1TObjects/interface/L1GtStableParameters.h"
00031 #include "CondFormats/DataRecord/interface/L1GtStableParametersRcd.h"
00032 
00033 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
00034 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
00035 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsTechTrigRcd.h"
00036 
00037 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00038 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00039 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00040 
00041 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskVetoAlgoTrigRcd.h"
00042 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskVetoTechTrigRcd.h"
00043 
00044 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00045 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00046 
00047 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00048 
00049 // constructor(s)
00050 L1GtUtils::L1GtUtils() :
00051 
00052     m_l1GtStableParCacheID(0ULL), m_numberAlgorithmTriggers(0),
00053 
00054     m_numberTechnicalTriggers(0),
00055 
00056     m_l1GtPfAlgoCacheID(0ULL), m_l1GtPfTechCacheID(0ULL),
00057 
00058     m_l1GtTmAlgoCacheID(0ULL), m_l1GtTmTechCacheID(0ULL),
00059 
00060     m_l1GtTmVetoAlgoCacheID(0ULL), m_l1GtTmVetoTechCacheID(0ULL),
00061 
00062     m_l1GtMenuCacheID(0ULL),
00063 
00064     m_l1EventSetupValid(false),
00065 
00066     m_l1GtMenuLiteValid(false),
00067 
00068     m_beginRunCache(false),
00069 
00070     m_runIDCache(0),
00071 
00072     m_provRunIDCache(0),
00073     
00074     m_physicsDaqPartition(0),
00075 
00076     m_retrieveL1EventSetup(false),
00077 
00078     m_retrieveL1GtTriggerMenuLite(false)
00079 
00080     {
00081 
00082     // empty
00083 }
00084 
00085 // destructor
00086 L1GtUtils::~L1GtUtils() {
00087 
00088     // empty
00089 
00090 }
00091 
00092 const std::string L1GtUtils::triggerCategory(
00093         const TriggerCategory& trigCategory) const {
00094 
00095     switch (trigCategory) {
00096         case AlgorithmTrigger: {
00097             return "Algorithm Trigger";
00098         }
00099             break;
00100         case TechnicalTrigger: {
00101             return "Technical Trigger";
00102         }
00103 
00104             break;
00105         default: {
00106             return EmptyString;
00107         }
00108             break;
00109     }
00110 }
00111 
00112 
00113 void L1GtUtils::retrieveL1EventSetup(const edm::EventSetup& evSetup) {
00114 
00115     //
00116     m_retrieveL1EventSetup = true;
00117 
00118     m_l1EventSetupValid = true;
00119     // FIXME test for each record if valid; if not set m_l1EventSetupValid = false;
00120 
00121     // get / update the stable parameters from the EventSetup
00122     // local cache & check on cacheIdentifier
00123 
00124     unsigned long long l1GtStableParCacheID =
00125             evSetup.get<L1GtStableParametersRcd>().cacheIdentifier();
00126 
00127     if (m_l1GtStableParCacheID != l1GtStableParCacheID) {
00128 
00129         edm::ESHandle<L1GtStableParameters> l1GtStablePar;
00130         evSetup.get<L1GtStableParametersRcd>().get(l1GtStablePar);
00131         m_l1GtStablePar = l1GtStablePar.product();
00132 
00133         // number of algorithm triggers
00134         m_numberAlgorithmTriggers = m_l1GtStablePar->gtNumberPhysTriggers();
00135 
00136         // number of technical triggers
00137         m_numberTechnicalTriggers =
00138                 m_l1GtStablePar->gtNumberTechnicalTriggers();
00139 
00140         int maxNumberTrigger = std::max(m_numberAlgorithmTriggers,
00141                 m_numberTechnicalTriggers);
00142 
00143         m_triggerMaskSet.reserve(maxNumberTrigger);
00144         m_prescaleFactorSet.reserve(maxNumberTrigger);
00145 
00146         //
00147         m_l1GtStableParCacheID = l1GtStableParCacheID;
00148 
00149     }
00150 
00151     // get / update the prescale factors from the EventSetup
00152     // local cache & check on cacheIdentifier
00153 
00154     unsigned long long l1GtPfAlgoCacheID =
00155             evSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().cacheIdentifier();
00156 
00157     if (m_l1GtPfAlgoCacheID != l1GtPfAlgoCacheID) {
00158 
00159         edm::ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
00160         evSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
00161         m_l1GtPfAlgo = l1GtPfAlgo.product();
00162 
00163         m_prescaleFactorsAlgoTrig = &(m_l1GtPfAlgo->gtPrescaleFactors());
00164 
00165         m_l1GtPfAlgoCacheID = l1GtPfAlgoCacheID;
00166 
00167     }
00168 
00169     unsigned long long l1GtPfTechCacheID = evSetup.get<
00170             L1GtPrescaleFactorsTechTrigRcd>().cacheIdentifier();
00171 
00172     if (m_l1GtPfTechCacheID != l1GtPfTechCacheID) {
00173 
00174         edm::ESHandle<L1GtPrescaleFactors> l1GtPfTech;
00175         evSetup.get<L1GtPrescaleFactorsTechTrigRcd>().get(l1GtPfTech);
00176         m_l1GtPfTech = l1GtPfTech.product();
00177 
00178         m_prescaleFactorsTechTrig = &(m_l1GtPfTech->gtPrescaleFactors());
00179 
00180         m_l1GtPfTechCacheID = l1GtPfTechCacheID;
00181 
00182     }
00183 
00184     // get / update the trigger mask from the EventSetup
00185     // local cache & check on cacheIdentifier
00186 
00187     unsigned long long l1GtTmAlgoCacheID =
00188             evSetup.get<L1GtTriggerMaskAlgoTrigRcd>().cacheIdentifier();
00189 
00190     if (m_l1GtTmAlgoCacheID != l1GtTmAlgoCacheID) {
00191 
00192         edm::ESHandle<L1GtTriggerMask> l1GtTmAlgo;
00193         evSetup.get<L1GtTriggerMaskAlgoTrigRcd>().get(l1GtTmAlgo);
00194         m_l1GtTmAlgo = l1GtTmAlgo.product();
00195 
00196         m_triggerMaskAlgoTrig = &(m_l1GtTmAlgo->gtTriggerMask());
00197 
00198         m_l1GtTmAlgoCacheID = l1GtTmAlgoCacheID;
00199 
00200     }
00201 
00202     unsigned long long l1GtTmTechCacheID =
00203             evSetup.get<L1GtTriggerMaskTechTrigRcd>().cacheIdentifier();
00204 
00205     if (m_l1GtTmTechCacheID != l1GtTmTechCacheID) {
00206 
00207         edm::ESHandle<L1GtTriggerMask> l1GtTmTech;
00208         evSetup.get<L1GtTriggerMaskTechTrigRcd>().get(l1GtTmTech);
00209         m_l1GtTmTech = l1GtTmTech.product();
00210 
00211         m_triggerMaskTechTrig = &(m_l1GtTmTech->gtTriggerMask());
00212 
00213         m_l1GtTmTechCacheID = l1GtTmTechCacheID;
00214 
00215     }
00216 
00217     unsigned long long l1GtTmVetoAlgoCacheID =
00218             evSetup.get<L1GtTriggerMaskVetoAlgoTrigRcd>().cacheIdentifier();
00219 
00220     if (m_l1GtTmVetoAlgoCacheID != l1GtTmVetoAlgoCacheID) {
00221 
00222         edm::ESHandle<L1GtTriggerMask> l1GtTmVetoAlgo;
00223         evSetup.get<L1GtTriggerMaskVetoAlgoTrigRcd>().get(l1GtTmVetoAlgo);
00224         m_l1GtTmVetoAlgo = l1GtTmVetoAlgo.product();
00225 
00226         m_triggerMaskVetoAlgoTrig = &(m_l1GtTmVetoAlgo->gtTriggerMask());
00227 
00228         m_l1GtTmVetoAlgoCacheID = l1GtTmVetoAlgoCacheID;
00229 
00230     }
00231 
00232     unsigned long long l1GtTmVetoTechCacheID =
00233             evSetup.get<L1GtTriggerMaskVetoTechTrigRcd>().cacheIdentifier();
00234 
00235     if (m_l1GtTmVetoTechCacheID != l1GtTmVetoTechCacheID) {
00236 
00237         edm::ESHandle<L1GtTriggerMask> l1GtTmVetoTech;
00238         evSetup.get<L1GtTriggerMaskVetoTechTrigRcd>().get(l1GtTmVetoTech);
00239         m_l1GtTmVetoTech = l1GtTmVetoTech.product();
00240 
00241         m_triggerMaskVetoTechTrig = &(m_l1GtTmVetoTech->gtTriggerMask());
00242 
00243         m_l1GtTmVetoTechCacheID = l1GtTmVetoTechCacheID;
00244 
00245     }
00246 
00247     // get / update the trigger menu from the EventSetup
00248     // local cache & check on cacheIdentifier
00249 
00250     unsigned long long l1GtMenuCacheID =
00251             evSetup.get<L1GtTriggerMenuRcd>().cacheIdentifier();
00252 
00253     if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
00254 
00255         edm::ESHandle<L1GtTriggerMenu> l1GtMenu;
00256         evSetup.get<L1GtTriggerMenuRcd>().get(l1GtMenu);
00257         m_l1GtMenu = l1GtMenu.product();
00258 
00259         m_algorithmMap = &(m_l1GtMenu->gtAlgorithmMap());
00260         m_algorithmAliasMap = &(m_l1GtMenu->gtAlgorithmAliasMap());
00261 
00262         m_technicalTriggerMap = &(m_l1GtMenu->gtTechnicalTriggerMap());
00263 
00264         m_l1GtMenuCacheID = l1GtMenuCacheID;
00265 
00266     }
00267 
00268 }
00269 
00270 
00271 void L1GtUtils::retrieveL1GtTriggerMenuLite(const edm::Run& iRun,
00272         const edm::InputTag& l1GtMenuLiteInputTag) {
00273 
00274     //
00275     m_retrieveL1GtTriggerMenuLite = true;
00276 
00277     // get L1GtTriggerMenuLite
00278     edm::Handle<L1GtTriggerMenuLite> l1GtMenuLite;
00279     iRun.getByLabel(l1GtMenuLiteInputTag, l1GtMenuLite);
00280 
00281     if (!l1GtMenuLite.isValid()) {
00282 
00283         LogDebug("L1GtUtils") << "\nL1GtTriggerMenuLite with \n  "
00284                 << l1GtMenuLiteInputTag
00285                 << "\nrequested in configuration, but not found in the event."
00286                 << std::endl;
00287 
00288         m_l1GtMenuLiteValid = false;
00289     } else {
00290         m_l1GtMenuLite = l1GtMenuLite.product();
00291         m_l1GtMenuLiteValid = true;
00292 
00293         LogDebug("L1GtUtils") << "\nL1GtTriggerMenuLite with \n  "
00294                 << l1GtMenuLiteInputTag << "\nretrieved for run "
00295                 << iRun.runAuxiliary().run() << std::endl;
00296 
00297         m_algorithmMapLite = &(m_l1GtMenuLite->gtAlgorithmMap());
00298         m_algorithmAliasMapLite = &(m_l1GtMenuLite->gtAlgorithmAliasMap());
00299         m_technicalTriggerMapLite = &(m_l1GtMenuLite->gtTechnicalTriggerMap());
00300 
00301         m_triggerMaskAlgoTrigLite = &(m_l1GtMenuLite->gtTriggerMaskAlgoTrig());
00302         m_triggerMaskTechTrigLite = &(m_l1GtMenuLite->gtTriggerMaskTechTrig());
00303 
00304         m_prescaleFactorsAlgoTrigLite
00305                 = &(m_l1GtMenuLite->gtPrescaleFactorsAlgoTrig());
00306         m_prescaleFactorsTechTrigLite
00307                 = &(m_l1GtMenuLite->gtPrescaleFactorsTechTrig());
00308 
00309     }
00310 
00311 }
00312 
00313 void L1GtUtils::getL1GtRunCache(const edm::Run& iRun,
00314         const edm::EventSetup& evSetup, const bool useL1EventSetup,
00315         const bool useL1GtTriggerMenuLite, const edm::InputTag& l1GtTmLInputTag) {
00316 
00317     // first call will turn this to true: the quantities which can be cached in
00318     // beginRun will not be cached then in analyze
00319     m_beginRunCache = true;
00320 
00321     // if requested, retrieve and cache L1 event setup
00322     // keep the caching based on cacheIdentifier() for each record
00323     if (useL1EventSetup) {
00324         retrieveL1EventSetup(evSetup);
00325     }
00326 
00327     // cached per run
00328 
00329     // if requested, retrieve and cache the L1GtTriggerMenuLite
00330     // L1GtTriggerMenuLite is defined per run and produced in prompt reco by L1Reco
00331     // and put in the Run section
00332     if (useL1GtTriggerMenuLite) {
00333         retrieveL1GtTriggerMenuLite(iRun, l1GtTmLInputTag);
00334     }
00335 
00336 }
00337 
00338 
00339 void L1GtUtils::getL1GtRunCache(const edm::Run& iRun,
00340         const edm::EventSetup& evSetup, bool useL1EventSetup,
00341         bool useL1GtTriggerMenuLite) {
00342 
00343     if (useL1GtTriggerMenuLite) {
00344         getL1GtTriggerMenuLiteInputTag(iRun, m_provL1GtTriggerMenuLiteInputTag);
00345 
00346     }
00347 
00348     getL1GtRunCache(iRun, evSetup, useL1EventSetup, useL1GtTriggerMenuLite,
00349             m_provL1GtTriggerMenuLiteInputTag);
00350 
00351 }
00352 
00353 
00354 
00355 void L1GtUtils::getL1GtRunCache(const edm::Event& iEvent,
00356         const edm::EventSetup& evSetup, const bool useL1EventSetup,
00357         const bool useL1GtTriggerMenuLite, const edm::InputTag& l1GtTmLInputTag) {
00358 
00359     // if there was no retrieval and caching in beginRun, do it here
00360     if (!m_beginRunCache) {
00361 
00362         // if requested, retrieve and cache L1 event setup
00363         // keep the caching based on cacheIdentifier() for each record
00364         if (useL1EventSetup) {
00365             retrieveL1EventSetup(evSetup);
00366         }
00367     }
00368 
00369     // cached per run
00370 
00371     const edm::Run& iRun = iEvent.getRun();
00372     edm::RunID runID = iRun.runAuxiliary().id();
00373 
00374     if (runID != m_runIDCache) {
00375 
00376         if (!m_beginRunCache) {
00377             // if requested, retrieve and cache the L1GtTriggerMenuLite
00378             // L1GtTriggerMenuLite is defined per run and produced in prompt reco by L1Reco
00379             // and put in the Run section
00380             if (useL1GtTriggerMenuLite) {
00381                 retrieveL1GtTriggerMenuLite(iRun, l1GtTmLInputTag);
00382             }
00383         }
00384 
00385         // find from provenance and cache the input tags for L1GlobalTriggerRecord and
00386         // L1GlobalTriggerReadoutRecord
00387         getL1GtRecordInputTag(iEvent, m_provL1GtRecordInputTag,
00388                 m_provL1GtReadoutRecordInputTag);
00389 
00390         //
00391         m_runIDCache = runID;
00392 
00393     }
00394 
00395 }
00396 
00397 
00398 void L1GtUtils::getL1GtRunCache(const edm::Event& iEvent,
00399         const edm::EventSetup& evSetup, const bool useL1EventSetup,
00400         const bool useL1GtTriggerMenuLite) {
00401 
00402     // if the input tag for L1GtTriggerMenuLite was not found in beginRun, do it here
00403     if (!m_beginRunCache) {
00404 
00405         const edm::Run& iRun = iEvent.getRun();
00406         edm::RunID runID = iRun.runAuxiliary().id();
00407 
00408         if (runID != m_provRunIDCache) {
00409 
00410             if (useL1GtTriggerMenuLite) {
00411 
00412                 getL1GtTriggerMenuLiteInputTag(iRun,
00413                         m_provL1GtTriggerMenuLiteInputTag);
00414             }
00415 
00416             //
00417             m_provRunIDCache = runID;
00418         }
00419 
00420     }
00421 
00422     // call now the general method for getL1GtRunCache
00423     getL1GtRunCache(iEvent, evSetup, useL1EventSetup, useL1GtTriggerMenuLite,
00424             m_provL1GtTriggerMenuLiteInputTag);
00425 
00426 }
00427 
00428 
00429 void L1GtUtils::getL1GtRecordInputTag(const edm::Event& iEvent,
00430         edm::InputTag& l1GtRecordInputTag,
00431         edm::InputTag& l1GtReadoutRecordInputTag) const {
00432 
00433     typedef std::vector<edm::Provenance const*> Provenances;
00434     Provenances provenances;
00435     std::string friendlyName;
00436     std::string modLabel;
00437     std::string instanceName;
00438     std::string processName;
00439 
00440     bool foundL1GtRecord = false;
00441     bool foundL1GtReadoutRecord = false;
00442 
00443     LogDebug("L1GtUtils") << "\nTry to get AllProvenance for event "
00444             << iEvent.id().event() << std::endl;
00445 
00446     iEvent.getAllProvenance(provenances);
00447 
00448     LogTrace("L1GtUtils") << "\n" << "Event contains " << provenances.size()
00449             << " product" << (provenances.size() == 1 ? "" : "s")
00450             << " with friendlyClassName, moduleLabel, productInstanceName and processName:\n"
00451             << std::endl;
00452 
00453     for (Provenances::iterator itProv = provenances.begin(), itProvEnd =
00454             provenances.end(); itProv != itProvEnd; ++itProv) {
00455 
00456         friendlyName = (*itProv)->friendlyClassName();
00457         modLabel = (*itProv)->moduleLabel();
00458         instanceName = (*itProv)->productInstanceName();
00459         processName = (*itProv)->processName();
00460 
00461         LogTrace("L1GtUtils") << friendlyName << "\t \"" << modLabel
00462                 << "\" \t \"" << instanceName << "\" \t \"" << processName
00463                 << "\"" << std::endl;
00464 
00465         if (friendlyName == "L1GlobalTriggerRecord") {
00466             l1GtRecordInputTag = edm::InputTag(modLabel, instanceName,
00467                     processName);
00468             foundL1GtRecord = true;
00469         } else if (friendlyName == "L1GlobalTriggerReadoutRecord") {
00470 
00471             l1GtReadoutRecordInputTag = edm::InputTag(modLabel, instanceName,
00472                     processName);
00473             foundL1GtReadoutRecord = true;
00474         }
00475     }
00476 
00477     // if not found, return empty input tags
00478     if (!foundL1GtRecord) {
00479         l1GtRecordInputTag = edm::InputTag();
00480     } else {
00481         LogTrace("L1GtUtils")
00482                 << "\nL1GlobalTriggerRecord found in the event with \n  "
00483                 << l1GtRecordInputTag << std::endl;
00484     }
00485 
00486     if (!foundL1GtReadoutRecord) {
00487         l1GtReadoutRecordInputTag = edm::InputTag();
00488     } else {
00489         LogTrace("L1GtUtils")
00490                 << "\nL1GlobalTriggerReadoutRecord found in the event with \n  "
00491                 << l1GtReadoutRecordInputTag << std::endl;
00492     }
00493 
00494 }
00495 
00496 void L1GtUtils::getL1GtTriggerMenuLiteInputTag(const edm::Run& iRun,
00497         edm::InputTag& l1GtTriggerMenuLiteInputTag) const {
00498 
00499     typedef std::vector<edm::Provenance const*> Provenances;
00500     Provenances provenances;
00501     std::string friendlyName;
00502     std::string modLabel;
00503     std::string instanceName;
00504     std::string processName;
00505 
00506     bool foundL1GtTriggerMenuLite = false;
00507 
00508     LogDebug("L1GtUtils") << "\nTry to get AllProvenance for run "
00509             << iRun.runAuxiliary().run() << std::endl;
00510 
00511     iRun.getAllProvenance(provenances);
00512 
00513     LogTrace("L1GtUtils") << "\n" << "Run contains " << provenances.size()
00514             << " product" << (provenances.size() == 1 ? "" : "s")
00515             << " with friendlyClassName, moduleLabel, productInstanceName and processName:\n"
00516             << std::endl;
00517 
00518     for (Provenances::iterator itProv = provenances.begin(), itProvEnd =
00519             provenances.end(); itProv != itProvEnd; ++itProv) {
00520 
00521         friendlyName = (*itProv)->friendlyClassName();
00522         modLabel = (*itProv)->moduleLabel();
00523         instanceName = (*itProv)->productInstanceName();
00524         processName = (*itProv)->processName();
00525 
00526         LogTrace("L1GtUtils") << friendlyName << "\t \"" << modLabel
00527                 << "\" \t \"" << instanceName << "\" \t \"" << processName
00528                 << "\"" << std::endl;
00529 
00530         if (friendlyName == "L1GtTriggerMenuLite") {
00531             l1GtTriggerMenuLiteInputTag = edm::InputTag(modLabel, instanceName,
00532                     processName);
00533             foundL1GtTriggerMenuLite = true;
00534         }
00535 
00536     }
00537 
00538     if (!foundL1GtTriggerMenuLite) {
00539         l1GtTriggerMenuLiteInputTag = edm::InputTag();
00540         LogTrace("L1GtUtils") << "\nL1GtTriggerMenuLite not found in Run"
00541                 << std::endl;
00542     } else {
00543         LogTrace("L1GtUtils") << "\nL1GtTriggerMenuLite found in Run with \n  "
00544                 << l1GtTriggerMenuLiteInputTag << std::endl;
00545     }
00546 
00547 }
00548 
00549 
00550 const bool L1GtUtils::l1AlgoTechTrigBitNumber(
00551         const std::string& nameAlgoTechTrig, TriggerCategory& trigCategory,
00552         int& bitNumber) const {
00553 
00554     trigCategory = AlgorithmTrigger;
00555     bitNumber = -1;
00556 
00557     if (m_retrieveL1GtTriggerMenuLite) {
00558         if (m_l1GtMenuLiteValid) {
00559 
00560             // test if the name is an algorithm alias
00561             for (L1GtTriggerMenuLite::CItL1Trig itTrig =
00562                     m_algorithmAliasMapLite->begin(); itTrig
00563                     != m_algorithmAliasMapLite->end(); itTrig++) {
00564 
00565                 if (itTrig->second == nameAlgoTechTrig) {
00566 
00567                     trigCategory = AlgorithmTrigger;
00568                     bitNumber = itTrig->first;
00569 
00570                     return true;
00571                 }
00572             }
00573 
00574             // test if the name is an algorithm name
00575             for (L1GtTriggerMenuLite::CItL1Trig itTrig =
00576                     m_algorithmMapLite->begin(); itTrig
00577                     != m_algorithmMapLite->end(); itTrig++) {
00578 
00579                 if (itTrig->second == nameAlgoTechTrig) {
00580 
00581                     trigCategory = AlgorithmTrigger;
00582                     bitNumber = itTrig->first;
00583 
00584                     return true;
00585                 }
00586             }
00587 
00588             // test if the name is a technical trigger
00589             for (L1GtTriggerMenuLite::CItL1Trig itTrig =
00590                     m_technicalTriggerMapLite->begin(); itTrig
00591                     != m_technicalTriggerMapLite->end(); itTrig++) {
00592 
00593                 if (itTrig->second == nameAlgoTechTrig) {
00594 
00595                     trigCategory = TechnicalTrigger;
00596                     bitNumber = itTrig->first;
00597 
00598                     return true;
00599                 }
00600             }
00601 
00602         } else if (m_retrieveL1EventSetup) {
00603 
00604             // test if the name is an algorithm alias
00605             CItAlgo itAlgo = m_algorithmAliasMap->find(nameAlgoTechTrig);
00606             if (itAlgo != m_algorithmAliasMap->end()) {
00607                 trigCategory = AlgorithmTrigger;
00608                 bitNumber = (itAlgo->second).algoBitNumber();
00609 
00610                 return true;
00611             }
00612 
00613             // test if the name is an algorithm name
00614             itAlgo = m_algorithmMap->find(nameAlgoTechTrig);
00615             if (itAlgo != m_algorithmMap->end()) {
00616                 trigCategory = AlgorithmTrigger;
00617                 bitNumber = (itAlgo->second).algoBitNumber();
00618 
00619                 return true;
00620             }
00621 
00622             // test if the name is a technical trigger
00623             itAlgo = m_technicalTriggerMap->find(nameAlgoTechTrig);
00624             if (itAlgo != m_technicalTriggerMap->end()) {
00625                 trigCategory = TechnicalTrigger;
00626                 bitNumber = (itAlgo->second).algoBitNumber();
00627 
00628                 return true;
00629             }
00630 
00631         } else {
00632             // only L1GtTriggerMenuLite requested, but it is not valid
00633             return false;
00634 
00635         }
00636     } else if (m_retrieveL1EventSetup) {
00637 
00638         // test if the name is an algorithm alias
00639         CItAlgo itAlgo = m_algorithmAliasMap->find(nameAlgoTechTrig);
00640         if (itAlgo != m_algorithmAliasMap->end()) {
00641             trigCategory = AlgorithmTrigger;
00642             bitNumber = (itAlgo->second).algoBitNumber();
00643 
00644             return true;
00645         }
00646 
00647         // test if the name is an algorithm name
00648         itAlgo = m_algorithmMap->find(nameAlgoTechTrig);
00649         if (itAlgo != m_algorithmMap->end()) {
00650             trigCategory = AlgorithmTrigger;
00651             bitNumber = (itAlgo->second).algoBitNumber();
00652 
00653             return true;
00654         }
00655 
00656         // test if the name is a technical trigger
00657         itAlgo = m_technicalTriggerMap->find(nameAlgoTechTrig);
00658         if (itAlgo != m_technicalTriggerMap->end()) {
00659             trigCategory = TechnicalTrigger;
00660             bitNumber = (itAlgo->second).algoBitNumber();
00661 
00662             return true;
00663         }
00664 
00665     } else {
00666         // L1 trigger configuration not retrieved
00667         return false;
00668 
00669     }
00670 
00671     // all possibilities already tested, so it should not arrive here
00672     return false;
00673 
00674 
00675 }
00676 
00677 const bool L1GtUtils::l1TriggerNameFromBit(const int& bitNumber,
00678         const TriggerCategory& trigCategory, std::string& aliasL1Trigger,
00679         std::string& nameL1Trigger) const {
00680 
00681     aliasL1Trigger.clear();
00682     nameL1Trigger.clear();
00683 
00684     if (m_retrieveL1GtTriggerMenuLite) {
00685         if (m_l1GtMenuLiteValid) {
00686 
00687             // for an algorithm trigger
00688             if (trigCategory == AlgorithmTrigger) {
00689 
00690                 bool trigAliasFound = false;
00691                 bool trigNameFound = false;
00692 
00693                 for (L1GtTriggerMenuLite::CItL1Trig itTrig =
00694                         m_algorithmAliasMapLite->begin();
00695                         itTrig != m_algorithmAliasMapLite->end(); itTrig++) {
00696 
00697                     if (static_cast<int>(itTrig->first) == bitNumber) {
00698                         aliasL1Trigger = itTrig->second;
00699                         trigAliasFound = true;
00700                         break;
00701                     }
00702                 }
00703 
00704                 for (L1GtTriggerMenuLite::CItL1Trig itTrig =
00705                         m_algorithmMapLite->begin();
00706                         itTrig != m_algorithmMapLite->end(); itTrig++) {
00707 
00708                     if (static_cast<int>(itTrig->first) == bitNumber) {
00709                         nameL1Trigger = itTrig->second;
00710                         trigNameFound = true;
00711                         break;
00712                     }
00713                 }
00714 
00715                 if (!(trigAliasFound && trigNameFound)) {
00716                     return false;
00717                 }
00718 
00719                 return true;
00720 
00721             } else if (trigCategory == TechnicalTrigger) {
00722 
00723                 // for a technical trigger   
00724 
00725                 bool trigNameFound = false;
00726 
00727                 for (L1GtTriggerMenuLite::CItL1Trig itTrig =
00728                         m_technicalTriggerMapLite->begin();
00729                         itTrig != m_technicalTriggerMapLite->end(); itTrig++) {
00730 
00731                     if (static_cast<int>(itTrig->first) == bitNumber) {
00732                         nameL1Trigger = itTrig->second;
00733 
00734                         // technically, no alias is defined for technical triggers
00735                         // users use mainly aliases, so just return the name here
00736                         aliasL1Trigger = itTrig->second;
00737 
00738                         trigNameFound = true;
00739                         break;
00740                     }
00741                 }
00742 
00743                 if (!(trigNameFound)) {
00744                     return false;
00745                 }
00746 
00747                 return true;
00748 
00749             } else {
00750 
00751                 // non-existing trigger category...
00752                 return false;
00753             }
00754 
00755         } else if (m_retrieveL1EventSetup) {
00756 
00757             // for an algorithm trigger
00758             if (trigCategory == AlgorithmTrigger) {
00759 
00760                 bool trigAliasFound = false;
00761 
00762                 for (CItAlgo itTrig = m_algorithmAliasMap->begin();
00763                         itTrig != m_algorithmAliasMap->end(); itTrig++) {
00764 
00765                     if ((itTrig->second).algoBitNumber() == bitNumber) {
00766                         aliasL1Trigger = itTrig->first;
00767                         // get the name here, avoiding a loop on m_algorithmMap
00768                         nameL1Trigger = (itTrig->second).algoName();
00769 
00770                         trigAliasFound = true;
00771                         break;
00772                     }
00773                 }
00774 
00775                 if (!(trigAliasFound)) {
00776                     return false;
00777                 }
00778 
00779                 return true;
00780 
00781             } else if (trigCategory == TechnicalTrigger) {
00782 
00783                 // for a technical trigger   
00784 
00785                 bool trigNameFound = false;
00786 
00787                 for (CItAlgo itTrig = m_technicalTriggerMap->begin();
00788                         itTrig != m_technicalTriggerMap->end(); itTrig++) {
00789 
00790                     if ((itTrig->second).algoBitNumber() == bitNumber) {
00791                         nameL1Trigger = (itTrig->second).algoName();
00792                         // technically, no alias is defined for technical triggers
00793                         // users use mainly aliases, so just return the name here
00794                         aliasL1Trigger = nameL1Trigger;
00795 
00796                         trigNameFound = true;
00797                         break;
00798                     }
00799                 }
00800 
00801                 if (!(trigNameFound)) {
00802                     return false;
00803                 }
00804 
00805                 return true;
00806 
00807             } else {
00808 
00809                 // non-existing trigger category...
00810                 return false;
00811             }
00812 
00813         } else {
00814             // only L1GtTriggerMenuLite requested, but it is not valid
00815             return false;
00816 
00817         }
00818     } else if (m_retrieveL1EventSetup) {
00819 
00820         // for an algorithm trigger
00821         if (trigCategory == AlgorithmTrigger) {
00822 
00823             bool trigAliasFound = false;
00824 
00825             for (CItAlgo itTrig = m_algorithmAliasMap->begin();
00826                     itTrig != m_algorithmAliasMap->end(); itTrig++) {
00827 
00828                 if ((itTrig->second).algoBitNumber() == bitNumber) {
00829                     aliasL1Trigger = itTrig->first;
00830                     // get the name here, avoiding a loop on m_algorithmMap
00831                     nameL1Trigger = (itTrig->second).algoName();
00832 
00833                     trigAliasFound = true;
00834                     break;
00835                 }
00836             }
00837 
00838             if (!(trigAliasFound)) {
00839                 return false;
00840             }
00841 
00842             return true;
00843 
00844         } else if (trigCategory == TechnicalTrigger) {
00845 
00846             // for a technical trigger   
00847 
00848             bool trigNameFound = false;
00849 
00850             for (CItAlgo itTrig = m_technicalTriggerMap->begin();
00851                     itTrig != m_technicalTriggerMap->end(); itTrig++) {
00852 
00853                 if ((itTrig->second).algoBitNumber() == bitNumber) {
00854                     nameL1Trigger = (itTrig->second).algoName();
00855                     // technically, no alias is defined for technical triggers
00856                     // users use mainly aliases, so just return the name here
00857                     aliasL1Trigger = itTrig->first;
00858 
00859                     trigNameFound = true;
00860                     break;
00861                 }
00862             }
00863 
00864             if (!(trigNameFound)) {
00865                 return false;
00866             }
00867 
00868             return true;
00869 
00870         } else {
00871 
00872             // non-existing trigger category...
00873             return false;
00874         }
00875 
00876     } else {
00877         // L1 trigger configuration not retrieved
00878         return false;
00879 
00880     }
00881 
00882     // all possibilities already tested, so it should not arrive here
00883     return false;
00884 
00885 }
00886 
00887 const int L1GtUtils::l1Results(const edm::Event& iEvent,
00888         const edm::InputTag& l1GtRecordInputTag,
00889         const edm::InputTag& l1GtReadoutRecordInputTag,
00890         const std::string& nameAlgoTechTrig, bool& decisionBeforeMask,
00891         bool& decisionAfterMask, int& prescaleFactor, int& triggerMask) const {
00892 
00893     // initial values for returned results
00894     decisionBeforeMask = false;
00895     decisionAfterMask = false;
00896     prescaleFactor = -1;
00897     triggerMask = -1;
00898 
00899     // initialize error code and L1 configuration code
00900     int iError = 0;
00901     int l1ConfCode = 0;
00902 
00903     // check if L1 configuration is available
00904 
00905     if (!availableL1Configuration(iError, l1ConfCode)) {
00906         return iError;
00907     }
00908 
00909     // at this point, a valid L1 configuration is available, so the if/else if/else
00910     // can be simplified
00911 
00912     // if the given name is not an algorithm trigger alias, an algorithm trigger name
00913     // or a technical trigger in the current menu, return with error code 1
00914 
00915     TriggerCategory trigCategory = AlgorithmTrigger;
00916     int bitNumber = -1;
00917 
00918 
00919     if (!l1AlgoTechTrigBitNumber(nameAlgoTechTrig, trigCategory, bitNumber)) {
00920 
00921         iError = l1ConfCode + 1;
00922 
00923         if (m_retrieveL1GtTriggerMenuLite) {
00924             if (m_l1GtMenuLiteValid) {
00925 
00926                 LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n  "
00927                         << nameAlgoTechTrig
00928                         << "\not found in the trigger menu \n  "
00929                         << m_l1GtMenuLite->gtTriggerMenuImplementation()
00930                         << "\nretrieved from L1GtTriggerMenuLite" << std::endl;
00931 
00932             } else {
00933 
00934                 // fall through: L1 trigger configuration from event setup
00935                 LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n  "
00936                         << nameAlgoTechTrig
00937                         << "\not found in the trigger menu \n  "
00938                         << m_l1GtMenu->gtTriggerMenuImplementation()
00939                         << "\nretrieved from Event Setup" << std::endl;
00940 
00941             }
00942 
00943         } else {
00944             // L1 trigger configuration from event setup only
00945             LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n  "
00946                     << nameAlgoTechTrig
00947                     << "\not found in the trigger menu \n  "
00948                     << m_l1GtMenu->gtTriggerMenuImplementation()
00949                     << "\nretrieved from Event Setup" << std::endl;
00950 
00951         }
00952 
00953         return iError;
00954 
00955     }
00956 
00957     // check here if a positive bit number was retrieved
00958     // exit in case of negative bit number, before retrieving L1 GT products, saving time
00959 
00960     if (bitNumber < 0) {
00961 
00962         iError = l1ConfCode + 2;
00963 
00964         if (m_retrieveL1GtTriggerMenuLite) {
00965             if (m_l1GtMenuLiteValid) {
00966                 LogDebug("L1GtUtils") << "\nNegative bit number for "
00967                         << triggerCategory(trigCategory) << "\n  "
00968                         << nameAlgoTechTrig << "\nfrom menu \n  "
00969                         << m_l1GtMenuLite->gtTriggerMenuImplementation()
00970                         << "\nretrieved from L1GtTriggerMenuLite" << std::endl;
00971 
00972             } else {
00973                 // fall through: L1 trigger configuration from event setup
00974                 LogDebug("L1GtUtils") << "\nNegative bit number for "
00975                         << triggerCategory(trigCategory) << "\n  "
00976                         << nameAlgoTechTrig << "\nfrom menu \n  "
00977                         << m_l1GtMenu->gtTriggerMenuImplementation()
00978                         << "\nretrieved from Event Setup" << std::endl;
00979 
00980             }
00981 
00982         } else {
00983             // L1 trigger configuration from event setup only
00984             LogDebug("L1GtUtils") << "\nNegative bit number for "
00985                     << triggerCategory(trigCategory) << "\n  "
00986                     << nameAlgoTechTrig << "\nfrom menu \n  "
00987                     << m_l1GtMenu->gtTriggerMenuImplementation()
00988                     << "\nretrieved from Event Setup" << std::endl;
00989 
00990         }
00991 
00992         return iError;
00993     }
00994 
00995 
00996     // retrieve L1GlobalTriggerRecord and 1GlobalTriggerReadoutRecord product
00997     // intermediate error code for the records
00998     // the module returns an error code only if both the lite and the readout record are missing
00999 
01000     int iErrorRecord = 0;
01001 
01002     bool validRecord = false;
01003     bool gtReadoutRecordValid = false;
01004 
01005     edm::Handle<L1GlobalTriggerRecord> gtRecord;
01006     iEvent.getByLabel(l1GtRecordInputTag, gtRecord);
01007 
01008     if (gtRecord.isValid()) {
01009 
01010         validRecord = true;
01011 
01012     } else {
01013 
01014         iErrorRecord = 10;
01015         LogDebug("L1GtUtils") << "\nL1GlobalTriggerRecord with \n  "
01016                 << l1GtRecordInputTag << "\nnot found in the event."
01017                 << std::endl;
01018     }
01019 
01020     edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecord;
01021     iEvent.getByLabel(l1GtReadoutRecordInputTag, gtReadoutRecord);
01022 
01023     if (gtReadoutRecord.isValid()) {
01024 
01025         gtReadoutRecordValid = true;
01026         validRecord = true;
01027 
01028     } else {
01029 
01030         iErrorRecord = iErrorRecord + 100;
01031         LogDebug("L1GtUtils") << "\nL1GlobalTriggerReadoutRecord with \n  "
01032                 << l1GtReadoutRecordInputTag << "\nnot found in the event."
01033                 << std::endl;
01034 
01035     }
01036 
01037     // get the prescale factor index from
01038     //  L1GlobalTriggerReadoutRecord if valid
01039     //  if not, from L1GlobalTriggerRecord if valid
01040     //  else return an error
01041 
01042 
01043     int pfIndexTechTrig = -1;
01044     int pfIndexAlgoTrig = -1;
01045 
01046     if (validRecord) {
01047         if (gtReadoutRecordValid) {
01048 
01049             pfIndexTechTrig
01050                     = (gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexTech();
01051             pfIndexAlgoTrig
01052                     = (gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexAlgo();
01053 
01054         } else {
01055 
01056             pfIndexTechTrig
01057                     = static_cast<int> (gtRecord->gtPrescaleFactorIndexTech());
01058             pfIndexAlgoTrig
01059                     = static_cast<int> (gtRecord->gtPrescaleFactorIndexAlgo());
01060 
01061         }
01062 
01063     } else {
01064 
01065         LogDebug("L1GtUtils") << "\nError: "
01066                 << "\nNo valid L1GlobalTriggerRecord with \n  "
01067                 << l1GtRecordInputTag << "\nfound in the event."
01068                 << "\nNo valid L1GlobalTriggerReadoutRecord with \n  "
01069                 << l1GtReadoutRecordInputTag << "\nfound in the event."
01070                 << std::endl;
01071 
01072         iError = l1ConfCode + iErrorRecord;
01073         return iError;
01074 
01075     }
01076 
01077     // depending on trigger category (algorithm trigger or technical trigger)
01078     // get the correct quantities
01079 
01080     // number of sets of prescale factors
01081     // index of prescale factor set retrieved from data
01082     // pointer to the actual prescale factor set
01083     // pointer to the set of trigger masks
01084 
01085     size_t pfSetsSize = 0;
01086     int pfIndex = -1;
01087     const std::vector<int>* prescaleFactorsSubset = 0;
01088     const std::vector<unsigned int>* triggerMasksSet = 0;
01089 
01090     switch (trigCategory) {
01091         case AlgorithmTrigger: {
01092             if (m_retrieveL1GtTriggerMenuLite) {
01093                 if (m_l1GtMenuLiteValid) {
01094                     pfSetsSize = m_prescaleFactorsAlgoTrigLite->size();
01095                     triggerMasksSet = m_triggerMaskAlgoTrigLite;
01096 
01097                 } else {
01098                     // fall through: L1 trigger configuration from event setup
01099                     pfSetsSize = m_prescaleFactorsAlgoTrig->size();
01100                     triggerMasksSet = m_triggerMaskAlgoTrig;
01101 
01102                 }
01103 
01104             } else {
01105                 // L1 trigger configuration from event setup only
01106                 pfSetsSize = m_prescaleFactorsAlgoTrig->size();
01107                 triggerMasksSet = m_triggerMaskAlgoTrig;
01108 
01109             }
01110 
01111             pfIndex = pfIndexAlgoTrig;
01112 
01113         }
01114             break;
01115         case TechnicalTrigger: {
01116             if (m_retrieveL1GtTriggerMenuLite) {
01117                 if (m_l1GtMenuLiteValid) {
01118                     pfSetsSize = m_prescaleFactorsTechTrigLite->size();
01119                     triggerMasksSet = m_triggerMaskTechTrigLite;
01120 
01121                 } else {
01122                     // fall through: L1 trigger configuration from event setup
01123                     pfSetsSize = m_prescaleFactorsTechTrig->size();
01124                     triggerMasksSet = m_triggerMaskTechTrig;
01125 
01126                 }
01127 
01128             } else {
01129                 // L1 trigger configuration from event setup only
01130                 pfSetsSize = m_prescaleFactorsTechTrig->size();
01131                 triggerMasksSet = m_triggerMaskTechTrig;
01132 
01133             }
01134 
01135             pfIndex = pfIndexTechTrig;
01136 
01137         }
01138             break;
01139         default: {
01140             // should not be the case
01141             iError = l1ConfCode + iErrorRecord + 3;
01142             return iError;
01143 
01144         }
01145             break;
01146     }
01147 
01148 
01149     // test prescale factor set index correctness, then retrieve the actual set of prescale factors
01150 
01151     if (pfIndex < 0) {
01152 
01153         iError = l1ConfCode + iErrorRecord + 1000;
01154         LogDebug("L1GtUtils")
01155                 << "\nError: index of prescale factor set retrieved from the data \n"
01156                 << "less than zero."
01157                 << "\n  Value of index retrieved from data = " << pfIndex
01158                 << std::endl;
01159 
01160         return iError;
01161 
01162     } else if (pfIndex >= (static_cast<int>(pfSetsSize))) {
01163         iError = l1ConfCode + iErrorRecord + 2000;
01164         LogDebug("L1GtUtils")
01165                 << "\nError: index of prescale factor set retrieved from the data \n"
01166                 << "greater than the size of the vector of prescale factor sets."
01167                 << "\n  Value of index retrieved from data = " << pfIndex
01168                 << "\n  Vector size = " << pfSetsSize << std::endl;
01169 
01170         return iError;
01171 
01172     } else {
01173         switch (trigCategory) {
01174             case AlgorithmTrigger: {
01175                 if (m_retrieveL1GtTriggerMenuLite) {
01176                     if (m_l1GtMenuLiteValid) {
01177                         prescaleFactorsSubset
01178                                 = &((*m_prescaleFactorsAlgoTrigLite).at(pfIndex));
01179 
01180                     } else {
01181                         // fall through: L1 trigger configuration from event setup
01182                         prescaleFactorsSubset
01183                                 = &((*m_prescaleFactorsAlgoTrig).at(pfIndex));
01184 
01185                     }
01186 
01187                 } else {
01188                     // L1 trigger configuration from event setup only
01189                     prescaleFactorsSubset
01190                             = &((*m_prescaleFactorsAlgoTrig).at(pfIndex));
01191 
01192                 }
01193 
01194             }
01195                 break;
01196             case TechnicalTrigger: {
01197                 if (m_retrieveL1GtTriggerMenuLite) {
01198                     if (m_l1GtMenuLiteValid) {
01199                         prescaleFactorsSubset
01200                                 = &((*m_prescaleFactorsTechTrigLite).at(pfIndex));
01201 
01202                     } else {
01203                         // fall through: L1 trigger configuration from event setup
01204                         prescaleFactorsSubset
01205                                 = &((*m_prescaleFactorsTechTrig).at(pfIndex));
01206 
01207                     }
01208 
01209                 } else {
01210                     // L1 trigger configuration from event setup only
01211                     prescaleFactorsSubset
01212                             = &((*m_prescaleFactorsTechTrig).at(pfIndex));
01213 
01214                 }
01215 
01216             }
01217                 break;
01218             default: {
01219                 // do nothing - it was tested before, with return
01220 
01221             }
01222                 break;
01223         }
01224 
01225     }
01226 
01227 
01228     // algorithm result before applying the trigger masks
01229     // the bit number is positive (tested previously)
01230 
01231     switch (trigCategory) {
01232         case AlgorithmTrigger: {
01233             if (gtReadoutRecordValid) {
01234                 const DecisionWord& decWord = gtReadoutRecord->decisionWord();
01235                 decisionBeforeMask = trigResult(decWord, bitNumber,
01236                         nameAlgoTechTrig, trigCategory, iError);
01237                 if (iError) {
01238                     return (iError + l1ConfCode + iErrorRecord);
01239                 }
01240 
01241             } else {
01242 
01243                 const DecisionWord& decWord =
01244                         gtRecord->decisionWordBeforeMask();
01245                 decisionBeforeMask = trigResult(decWord, bitNumber,
01246                         nameAlgoTechTrig, trigCategory, iError);
01247                 if (iError) {
01248                     return (iError + l1ConfCode + iErrorRecord);
01249                 }
01250 
01251             }
01252 
01253         }
01254             break;
01255         case TechnicalTrigger: {
01256             if (gtReadoutRecordValid) {
01257                 const DecisionWord& decWord =
01258                         gtReadoutRecord->technicalTriggerWord();
01259                 decisionBeforeMask = trigResult(decWord, bitNumber,
01260                         nameAlgoTechTrig, trigCategory, iError);
01261                 if (iError) {
01262                     return (iError + l1ConfCode + iErrorRecord);
01263                 }
01264 
01265             } else {
01266 
01267                 const DecisionWord& decWord =
01268                         gtRecord->technicalTriggerWordBeforeMask();
01269                 decisionBeforeMask = trigResult(decWord, bitNumber,
01270                         nameAlgoTechTrig, trigCategory, iError);
01271                 if (iError) {
01272                     return (iError + l1ConfCode + iErrorRecord);
01273                 }
01274 
01275             }
01276 
01277         }
01278             break;
01279         default: {
01280             // do nothing - it was tested before, with return
01281 
01282         }
01283             break;
01284     }
01285 
01286     // prescale factor
01287     // the bit number is positive (tested previously)
01288 
01289     if (bitNumber < (static_cast<int> (prescaleFactorsSubset->size()))) {
01290         prescaleFactor = (*prescaleFactorsSubset)[bitNumber];
01291     } else {
01292         iError = l1ConfCode + iErrorRecord + 4000;
01293         LogDebug("L1GtUtils") << "\nError: bit number " << bitNumber
01294                 << " retrieved for " << triggerCategory(trigCategory) << "\n  "
01295                 << nameAlgoTechTrig
01296                 << "\ngreater than size of actual L1 GT prescale factor set: "
01297                 << prescaleFactorsSubset->size()
01298                 << "\nError: Inconsistent L1 trigger configuration!"
01299                 << std::endl;
01300 
01301         return iError;
01302     }
01303 
01304     // trigger mask and trigger result after applying the trigger masks
01305 
01306     if (bitNumber < (static_cast<int> ((*triggerMasksSet).size()))) {
01307 
01308         if (m_retrieveL1GtTriggerMenuLite) {
01309             if (m_l1GtMenuLiteValid) {
01310                 triggerMask = (*triggerMasksSet)[bitNumber];
01311 
01312             } else {
01313                 // fall through: L1 trigger configuration from event setup
01314                 // masks in event setup are for all partitions
01315                 triggerMask = ((*triggerMasksSet)[bitNumber]) & (1
01316                         << m_physicsDaqPartition);
01317 
01318             }
01319 
01320         } else {
01321             // L1 trigger configuration from event setup only
01322             // masks in event setup are for all partitions
01323             triggerMask = ((*triggerMasksSet)[bitNumber]) & (1
01324                     << m_physicsDaqPartition);
01325 
01326         }
01327 
01328 
01329     } else {
01330         iError = l1ConfCode + iErrorRecord + 5000;
01331         LogDebug("L1GtUtils") << "\nError: bit number " << bitNumber
01332                 << " retrieved for " << triggerCategory(trigCategory) << "\n  "
01333                 << nameAlgoTechTrig
01334                 << "\ngreater than size of L1 GT trigger mask set: "
01335                 << (*triggerMasksSet).size()
01336                 << "\nError: Inconsistent L1 trigger configuration!"
01337                 << std::endl;
01338 
01339         return iError;
01340 
01341     }
01342 
01343     decisionAfterMask = decisionBeforeMask;
01344 
01345     if (triggerMask) {
01346         decisionAfterMask = false;
01347     }
01348 
01349     return iError;
01350 
01351 }
01352 
01353 
01354 const int L1GtUtils::l1Results(const edm::Event& iEvent,
01355         const std::string& nameAlgoTechTrig, bool& decisionBeforeMask,
01356         bool& decisionAfterMask, int& prescaleFactor, int& triggerMask) const {
01357 
01358     // initial values for returned results
01359     decisionBeforeMask = false;
01360     decisionAfterMask = false;
01361     prescaleFactor = -1;
01362     triggerMask = -1;
01363 
01364     int l1ErrorCode = 0;
01365 
01366     l1ErrorCode = l1Results(iEvent, m_provL1GtRecordInputTag,
01367             m_provL1GtReadoutRecordInputTag, nameAlgoTechTrig, decisionBeforeMask,
01368             decisionAfterMask, prescaleFactor, triggerMask);
01369 
01370     return l1ErrorCode;
01371 
01372 }
01373 
01374 //
01375 
01376 const bool L1GtUtils::decisionBeforeMask(const edm::Event& iEvent,
01377         const edm::InputTag& l1GtRecordInputTag,
01378         const edm::InputTag& l1GtReadoutRecordInputTag,
01379         const std::string& nameAlgoTechTrig, int& errorCode) const {
01380 
01381     // initial values
01382     bool decisionBeforeMask = false;
01383     bool decisionAfterMask = false;
01384     int prescaleFactor = -1;
01385     int triggerMask = -1;
01386 
01387     errorCode = l1Results(iEvent, l1GtRecordInputTag,
01388             l1GtReadoutRecordInputTag, nameAlgoTechTrig, decisionBeforeMask,
01389             decisionAfterMask, prescaleFactor, triggerMask);
01390 
01391     return decisionBeforeMask;
01392 
01393 }
01394 
01395 const bool L1GtUtils::decisionBeforeMask(const edm::Event& iEvent,
01396         const std::string& nameAlgoTechTrig, int& errorCode) const {
01397 
01398     // initial values
01399     bool decisionBeforeMask = false;
01400     bool decisionAfterMask = false;
01401     int prescaleFactor = -1;
01402     int triggerMask = -1;
01403 
01404     errorCode = l1Results(iEvent, nameAlgoTechTrig, decisionBeforeMask,
01405             decisionAfterMask, prescaleFactor, triggerMask);
01406 
01407     return decisionBeforeMask;
01408 
01409 }
01410 
01411 //
01412 
01413 const bool L1GtUtils::decisionAfterMask(const edm::Event& iEvent,
01414         const edm::InputTag& l1GtRecordInputTag,
01415         const edm::InputTag& l1GtReadoutRecordInputTag,
01416         const std::string& nameAlgoTechTrig, int& errorCode) const {
01417 
01418     // initial values
01419     bool decisionBeforeMask = false;
01420     bool decisionAfterMask = false;
01421     int prescaleFactor = -1;
01422     int triggerMask = -1;
01423 
01424     errorCode = l1Results(iEvent, l1GtRecordInputTag,
01425             l1GtReadoutRecordInputTag, nameAlgoTechTrig, decisionBeforeMask,
01426             decisionAfterMask, prescaleFactor, triggerMask);
01427 
01428     return decisionAfterMask;
01429 
01430 }
01431 
01432 const bool L1GtUtils::decisionAfterMask(const edm::Event& iEvent,
01433         const std::string& nameAlgoTechTrig, int& errorCode) const {
01434 
01435     // initial values
01436     bool decisionBeforeMask = false;
01437     bool decisionAfterMask = false;
01438     int prescaleFactor = -1;
01439     int triggerMask = -1;
01440 
01441     errorCode = l1Results(iEvent, nameAlgoTechTrig, decisionBeforeMask,
01442             decisionAfterMask, prescaleFactor, triggerMask);
01443 
01444     return decisionAfterMask;
01445 
01446 }
01447 
01448 //
01449 
01450 const bool L1GtUtils::decision(const edm::Event& iEvent,
01451         const edm::InputTag& l1GtRecordInputTag,
01452         const edm::InputTag& l1GtReadoutRecordInputTag,
01453         const std::string& nameAlgoTechTrig, int& errorCode) const {
01454 
01455     // initial values
01456     bool decisionBeforeMask = false;
01457     bool decisionAfterMask = false;
01458     int prescaleFactor = -1;
01459     int triggerMask = -1;
01460 
01461     errorCode = l1Results(iEvent, l1GtRecordInputTag,
01462             l1GtReadoutRecordInputTag, nameAlgoTechTrig, decisionBeforeMask,
01463             decisionAfterMask, prescaleFactor, triggerMask);
01464 
01465     return decisionAfterMask;
01466 
01467 }
01468 
01469 const bool L1GtUtils::decision(const edm::Event& iEvent,
01470         const std::string& nameAlgoTechTrig, int& errorCode) const {
01471 
01472     // initial values
01473     bool decisionBeforeMask = false;
01474     bool decisionAfterMask = false;
01475     int prescaleFactor = -1;
01476     int triggerMask = -1;
01477 
01478     errorCode = l1Results(iEvent, nameAlgoTechTrig, decisionBeforeMask,
01479             decisionAfterMask, prescaleFactor, triggerMask);
01480 
01481     return decisionAfterMask;
01482 
01483 }
01484 
01485 //
01486 
01487 const int L1GtUtils::prescaleFactor(const edm::Event& iEvent,
01488         const edm::InputTag& l1GtRecordInputTag,
01489         const edm::InputTag& l1GtReadoutRecordInputTag,
01490         const std::string& nameAlgoTechTrig, int& errorCode) const {
01491 
01492     // initial values
01493     bool decisionBeforeMask = false;
01494     bool decisionAfterMask = false;
01495     int prescaleFactor = -1;
01496     int triggerMask = -1;
01497 
01498     errorCode = l1Results(iEvent, l1GtRecordInputTag,
01499             l1GtReadoutRecordInputTag, nameAlgoTechTrig, decisionBeforeMask,
01500             decisionAfterMask, prescaleFactor, triggerMask);
01501 
01502     return prescaleFactor;
01503 
01504 }
01505 
01506 const int L1GtUtils::prescaleFactor(const edm::Event& iEvent,
01507         const std::string& nameAlgoTechTrig, int& errorCode) const {
01508 
01509     // initial values
01510     bool decisionBeforeMask = false;
01511     bool decisionAfterMask = false;
01512     int prescaleFactor = -1;
01513     int triggerMask = -1;
01514 
01515     errorCode = l1Results(iEvent, nameAlgoTechTrig, decisionBeforeMask,
01516             decisionAfterMask, prescaleFactor, triggerMask);
01517 
01518     return prescaleFactor;
01519 
01520 }
01521 
01522 const int L1GtUtils::triggerMask(const edm::Event& iEvent,
01523         const edm::InputTag& l1GtRecordInputTag,
01524         const edm::InputTag& l1GtReadoutRecordInputTag,
01525         const std::string& nameAlgoTechTrig, int& errorCode) const {
01526 
01527     // initial values
01528     bool decisionBeforeMask = false;
01529     bool decisionAfterMask = false;
01530     int prescaleFactor = -1;
01531     int triggerMask = -1;
01532 
01533     errorCode = l1Results(iEvent, l1GtRecordInputTag,
01534             l1GtReadoutRecordInputTag, nameAlgoTechTrig, decisionBeforeMask,
01535             decisionAfterMask, prescaleFactor, triggerMask);
01536 
01537     return triggerMask;
01538 
01539 }
01540 
01541 const int L1GtUtils::triggerMask(const edm::Event& iEvent,
01542         const std::string& nameAlgoTechTrig, int& errorCode) const {
01543 
01544     // initial values
01545     bool decisionBeforeMask = false;
01546     bool decisionAfterMask = false;
01547     int prescaleFactor = -1;
01548     int triggerMask = -1;
01549 
01550     errorCode = l1Results(iEvent, nameAlgoTechTrig, decisionBeforeMask,
01551             decisionAfterMask, prescaleFactor, triggerMask);
01552 
01553     return triggerMask;
01554 
01555 }
01556 
01557 const int L1GtUtils::triggerMask(const std::string& nameAlgoTechTrig,
01558         int& errorCode) const {
01559 
01560     // initial values for returned results
01561     int triggerMaskValue = -1;
01562 
01563     // initialize error code and L1 configuration code
01564     int iError = 0;
01565     int l1ConfCode = 0;
01566 
01567     // check if L1 configuration is available
01568 
01569     if (!availableL1Configuration(iError, l1ConfCode)) {
01570         errorCode = iError;
01571         return triggerMaskValue;
01572     }
01573 
01574     // at this point, a valid L1 configuration is available, so the if/else if/else
01575     // can be simplified
01576 
01577     // if the given name is not an algorithm trigger alias, an algorithm trigger name
01578     // or a technical trigger in the current menu, return with error code 1
01579 
01580     TriggerCategory trigCategory = AlgorithmTrigger;
01581     int bitNumber = -1;
01582 
01583     if (!l1AlgoTechTrigBitNumber(nameAlgoTechTrig, trigCategory, bitNumber)) {
01584 
01585         iError = l1ConfCode + 1;
01586 
01587         if (m_retrieveL1GtTriggerMenuLite) {
01588             if (m_l1GtMenuLiteValid) {
01589 
01590                 LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n  "
01591                         << nameAlgoTechTrig
01592                         << "\not found in the trigger menu \n  "
01593                         << m_l1GtMenuLite->gtTriggerMenuImplementation()
01594                         << "\nretrieved from L1GtTriggerMenuLite" << std::endl;
01595 
01596             } else {
01597 
01598                 // fall through: L1 trigger configuration from event setup
01599                 LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n  "
01600                         << nameAlgoTechTrig
01601                         << "\not found in the trigger menu \n  "
01602                         << m_l1GtMenu->gtTriggerMenuImplementation()
01603                         << "\nretrieved from Event Setup" << std::endl;
01604 
01605             }
01606 
01607         } else {
01608             // L1 trigger configuration from event setup only
01609             LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n  "
01610                     << nameAlgoTechTrig
01611                     << "\not found in the trigger menu \n  "
01612                     << m_l1GtMenu->gtTriggerMenuImplementation()
01613                     << "\nretrieved from Event Setup" << std::endl;
01614 
01615         }
01616 
01617         errorCode = iError;
01618         return triggerMaskValue;
01619 
01620     }
01621 
01622     // check here if a positive bit number was retrieved
01623     // exit in case of negative bit number, before retrieving L1 GT products, saving time
01624 
01625     if (bitNumber < 0) {
01626 
01627         iError = l1ConfCode + 2;
01628 
01629         if (m_retrieveL1GtTriggerMenuLite) {
01630             if (m_l1GtMenuLiteValid) {
01631                 LogDebug("L1GtUtils") << "\nNegative bit number for "
01632                         << triggerCategory(trigCategory) << "\n  "
01633                         << nameAlgoTechTrig << "\nfrom menu \n  "
01634                         << m_l1GtMenuLite->gtTriggerMenuImplementation()
01635                         << "\nretrieved from L1GtTriggerMenuLite" << std::endl;
01636 
01637             } else {
01638                 // fall through: L1 trigger configuration from event setup
01639                 LogDebug("L1GtUtils") << "\nNegative bit number for "
01640                         << triggerCategory(trigCategory) << "\n  "
01641                         << nameAlgoTechTrig << "\nfrom menu \n  "
01642                         << m_l1GtMenu->gtTriggerMenuImplementation()
01643                         << "\nretrieved from Event Setup" << std::endl;
01644 
01645             }
01646 
01647         } else {
01648             // L1 trigger configuration from event setup only
01649             LogDebug("L1GtUtils") << "\nNegative bit number for "
01650                     << triggerCategory(trigCategory) << "\n  "
01651                     << nameAlgoTechTrig << "\nfrom menu \n  "
01652                     << m_l1GtMenu->gtTriggerMenuImplementation()
01653                     << "\nretrieved from Event Setup" << std::endl;
01654 
01655         }
01656 
01657         errorCode = iError;
01658         return triggerMaskValue;
01659     }
01660 
01661     // depending on trigger category (algorithm trigger or technical trigger)
01662     // get the correct quantities
01663 
01664     // pointer to the set of trigger masks
01665 
01666     const std::vector<unsigned int>* triggerMasksSet = 0;
01667 
01668     switch (trigCategory) {
01669         case AlgorithmTrigger: {
01670             if (m_retrieveL1GtTriggerMenuLite) {
01671                 if (m_l1GtMenuLiteValid) {
01672                     triggerMasksSet = m_triggerMaskAlgoTrigLite;
01673 
01674                 } else {
01675                     // fall through: L1 trigger configuration from event setup
01676                     triggerMasksSet = m_triggerMaskAlgoTrig;
01677 
01678                 }
01679 
01680             } else {
01681                 // L1 trigger configuration from event setup only
01682                 triggerMasksSet = m_triggerMaskAlgoTrig;
01683 
01684             }
01685 
01686         }
01687             break;
01688         case TechnicalTrigger: {
01689             if (m_retrieveL1GtTriggerMenuLite) {
01690                 if (m_l1GtMenuLiteValid) {
01691                     triggerMasksSet = m_triggerMaskTechTrigLite;
01692 
01693                 } else {
01694                     // fall through: L1 trigger configuration from event setup
01695                     triggerMasksSet = m_triggerMaskTechTrig;
01696 
01697                 }
01698 
01699             } else {
01700                 // L1 trigger configuration from event setup only
01701                 triggerMasksSet = m_triggerMaskTechTrig;
01702 
01703             }
01704 
01705         }
01706             break;
01707         default: {
01708             // should not be the case
01709             iError = l1ConfCode + 3;
01710 
01711             errorCode = iError;
01712             return triggerMaskValue;
01713 
01714         }
01715             break;
01716     }
01717 
01718     // trigger mask
01719 
01720     if (bitNumber < (static_cast<int> ((*triggerMasksSet).size()))) {
01721 
01722         if (m_retrieveL1GtTriggerMenuLite) {
01723             if (m_l1GtMenuLiteValid) {
01724                 triggerMaskValue = (*triggerMasksSet)[bitNumber];
01725 
01726             } else {
01727                 // fall through: L1 trigger configuration from event setup
01728                 // masks in event setup are for all partitions
01729                 triggerMaskValue = ((*triggerMasksSet)[bitNumber]) & (1
01730                         << m_physicsDaqPartition);
01731 
01732             }
01733 
01734         } else {
01735             // L1 trigger configuration from event setup only
01736             // masks in event setup are for all partitions
01737             triggerMaskValue = ((*triggerMasksSet)[bitNumber]) & (1
01738                     << m_physicsDaqPartition);
01739 
01740         }
01741 
01742     } else {
01743         iError = l1ConfCode + 5000;
01744         LogDebug("L1GtUtils") << "\nError: bit number " << bitNumber
01745                 << " retrieved for " << triggerCategory(trigCategory) << "\n  "
01746                 << nameAlgoTechTrig
01747                 << "\ngreater than size of L1 GT trigger mask set: "
01748                 << (*triggerMasksSet).size()
01749                 << "\nError: Inconsistent L1 trigger configuration!"
01750                 << std::endl;
01751 
01752         errorCode = iError;
01753         return triggerMaskValue;
01754 
01755     }
01756 
01757     errorCode = iError;
01758     return triggerMaskValue;
01759 
01760 }
01761 
01762 const int L1GtUtils::prescaleFactorSetIndex(const edm::Event& iEvent,
01763         const edm::InputTag& l1GtRecordInputTag,
01764         const edm::InputTag& l1GtReadoutRecordInputTag,
01765         const TriggerCategory& trigCategory, int& errorCode) const {
01766 
01767     // initialize the index to a negative value
01768     int pfIndex = -1;
01769 
01770     // initialize error code and L1 configuration code
01771     int iError = 0;
01772     int l1ConfCode = 0;
01773 
01774     // check if L1 configuration is available
01775 
01776     if (!availableL1Configuration(iError, l1ConfCode)) {
01777         errorCode = iError;
01778         return pfIndex;
01779     }
01780 
01781     // at this point, a valid L1 configuration is available, so the if/else if/else
01782     // can be simplified
01783 
01784     // retrieve L1GlobalTriggerRecord and 1GlobalTriggerReadoutRecord product
01785     // intermediate error code for the records
01786     // the module returns an error code only if both the lite and the readout record are missing
01787 
01788     int iErrorRecord = 0;
01789 
01790     bool validRecord = false;
01791     bool gtReadoutRecordValid = false;
01792 
01793     edm::Handle<L1GlobalTriggerRecord> gtRecord;
01794     iEvent.getByLabel(l1GtRecordInputTag, gtRecord);
01795 
01796     if (gtRecord.isValid()) {
01797 
01798         validRecord = true;
01799 
01800     } else {
01801 
01802         iErrorRecord = 10;
01803         LogDebug("L1GtUtils") << "\nL1GlobalTriggerRecord with \n  "
01804                 << l1GtRecordInputTag << "\nnot found in the event."
01805                 << std::endl;
01806     }
01807 
01808     edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecord;
01809     iEvent.getByLabel(l1GtReadoutRecordInputTag, gtReadoutRecord);
01810 
01811     if (gtReadoutRecord.isValid()) {
01812 
01813         gtReadoutRecordValid = true;
01814         validRecord = true;
01815 
01816     } else {
01817 
01818         iErrorRecord = iErrorRecord + 100;
01819         LogDebug("L1GtUtils") << "\nL1GlobalTriggerReadoutRecord with \n  "
01820                 << l1GtReadoutRecordInputTag << "\nnot found in the event."
01821                 << std::endl;
01822 
01823     }
01824 
01825     // get the prescale factor index from
01826     //  L1GlobalTriggerReadoutRecord if valid
01827     //  if not, from L1GlobalTriggerRecord if valid
01828     //  else return an error
01829 
01830 
01831     int pfIndexTechTrig = -1;
01832     int pfIndexAlgoTrig = -1;
01833 
01834     if (validRecord) {
01835         if (gtReadoutRecordValid) {
01836 
01837             pfIndexTechTrig
01838                     = (gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexTech();
01839             pfIndexAlgoTrig
01840                     = (gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexAlgo();
01841 
01842         } else {
01843 
01844             pfIndexTechTrig
01845                     = static_cast<int> (gtRecord->gtPrescaleFactorIndexTech());
01846             pfIndexAlgoTrig
01847                     = static_cast<int> (gtRecord->gtPrescaleFactorIndexAlgo());
01848 
01849         }
01850 
01851     } else {
01852 
01853         LogDebug("L1GtUtils") << "\nError: "
01854                 << "\nNo valid L1GlobalTriggerRecord with \n  "
01855                 << l1GtRecordInputTag << "\nfound in the event."
01856                 << "\nNo valid L1GlobalTriggerReadoutRecord with \n  "
01857                 << l1GtReadoutRecordInputTag << "\nfound in the event."
01858                 << std::endl;
01859 
01860         iError = l1ConfCode + iErrorRecord;
01861 
01862         errorCode = iError;
01863         return pfIndex;
01864 
01865     }
01866 
01867     // depending on trigger category (algorithm trigger or technical trigger)
01868     // get the correct quantities
01869 
01870     // number of sets of prescale factors
01871     // index of prescale factor set retrieved from data
01872     // pointer to the actual prescale factor set
01873     // pointer to the set of trigger masks
01874 
01875     size_t pfSetsSize = 0;
01876 
01877     switch (trigCategory) {
01878         case AlgorithmTrigger: {
01879             if (m_retrieveL1GtTriggerMenuLite) {
01880                 if (m_l1GtMenuLiteValid) {
01881                     pfSetsSize = m_prescaleFactorsAlgoTrigLite->size();
01882 
01883                 } else {
01884                     // fall through: L1 trigger configuration from event setup
01885                     pfSetsSize = m_prescaleFactorsAlgoTrig->size();
01886 
01887                 }
01888 
01889             } else {
01890                 // L1 trigger configuration from event setup only
01891                 pfSetsSize = m_prescaleFactorsAlgoTrig->size();
01892 
01893             }
01894 
01895             pfIndex = pfIndexAlgoTrig;
01896 
01897         }
01898             break;
01899         case TechnicalTrigger: {
01900             if (m_retrieveL1GtTriggerMenuLite) {
01901                 if (m_l1GtMenuLiteValid) {
01902                     pfSetsSize = m_prescaleFactorsTechTrigLite->size();
01903 
01904                 } else {
01905                     // fall through: L1 trigger configuration from event setup
01906                     pfSetsSize = m_prescaleFactorsTechTrig->size();
01907 
01908                 }
01909 
01910             } else {
01911                 // L1 trigger configuration from event setup only
01912                 pfSetsSize = m_prescaleFactorsTechTrig->size();
01913 
01914             }
01915 
01916             pfIndex = pfIndexTechTrig;
01917 
01918         }
01919             break;
01920         default: {
01921             // should not be the case
01922             iError = l1ConfCode + iErrorRecord + 3;
01923             return iError;
01924 
01925         }
01926             break;
01927     }
01928 
01929 
01930     // test prescale factor set index correctness, then retrieve the actual set of prescale factors
01931 
01932     if (pfIndex < 0) {
01933 
01934         iError = l1ConfCode + iErrorRecord + 1000;
01935         LogDebug("L1GtUtils")
01936                 << "\nError: index of prescale factor set retrieved from the data \n"
01937                 << "less than zero."
01938                 << "\n  Value of index retrieved from data = " << pfIndex
01939                 << std::endl;
01940 
01941         errorCode = iError;
01942         return pfIndex;
01943 
01944     } else if (pfIndex >= (static_cast<int>(pfSetsSize))) {
01945         iError = l1ConfCode + iErrorRecord + 2000;
01946         LogDebug("L1GtUtils")
01947                 << "\nError: index of prescale factor set retrieved from the data \n"
01948                 << "greater than the size of the vector of prescale factor sets."
01949                 << "\n  Value of index retrieved from data = " << pfIndex
01950                 << "\n  Vector size = " << pfSetsSize << std::endl;
01951 
01952         errorCode = iError;
01953         return pfIndex;
01954 
01955     } else {
01956 
01957         errorCode = iError;
01958         return pfIndex;
01959     }
01960 
01961     errorCode = iError;
01962     return pfIndex;
01963 
01964 }
01965 
01966 
01967 const int L1GtUtils::prescaleFactorSetIndex(const edm::Event& iEvent,
01968         const TriggerCategory& trigCategory, int& errorCode) const {
01969 
01970     // initialize error code and return value
01971     int iError = 0;
01972     int pfIndex = -1;
01973 
01974     pfIndex = prescaleFactorSetIndex(iEvent, m_provL1GtRecordInputTag,
01975             m_provL1GtReadoutRecordInputTag, trigCategory, iError);
01976 
01977     // return the error code and the index value
01978     // if the  error code is 0, the index returned is -1
01979     errorCode = iError;
01980     return pfIndex;
01981 
01982 }
01983 
01984 
01985 
01986 const std::vector<int>& L1GtUtils::prescaleFactorSet(const edm::Event& iEvent,
01987         const edm::InputTag& l1GtRecordInputTag,
01988         const edm::InputTag& l1GtReadoutRecordInputTag,
01989         const TriggerCategory& trigCategory, int& errorCode) {
01990 
01991     // clear the vector before filling it
01992     m_prescaleFactorSet.clear();
01993 
01994     // initialize error code
01995     int iError = 0;
01996 
01997     const int pfIndex = prescaleFactorSetIndex(iEvent, l1GtRecordInputTag,
01998             l1GtReadoutRecordInputTag, trigCategory, iError);
01999 
02000     if (iError == 0) {
02001 
02002         switch (trigCategory) {
02003             case AlgorithmTrigger: {
02004                 if (m_retrieveL1GtTriggerMenuLite) {
02005                     if (m_l1GtMenuLiteValid) {
02006                         m_prescaleFactorSet
02007                                 = (*m_prescaleFactorsAlgoTrigLite).at(pfIndex);
02008 
02009                     } else {
02010                         // fall through: L1 trigger configuration from event setup
02011                         m_prescaleFactorSet = (*m_prescaleFactorsAlgoTrig).at(
02012                                 pfIndex);
02013 
02014                     }
02015 
02016                 } else {
02017                     // L1 trigger configuration from event setup only
02018                     m_prescaleFactorSet = (*m_prescaleFactorsAlgoTrig).at(
02019                             pfIndex);
02020 
02021                 }
02022 
02023             }
02024                 break;
02025             case TechnicalTrigger: {
02026                 if (m_retrieveL1GtTriggerMenuLite) {
02027                     if (m_l1GtMenuLiteValid) {
02028                         m_prescaleFactorSet
02029                                 = (*m_prescaleFactorsTechTrigLite).at(pfIndex);
02030 
02031                     } else {
02032                         // fall through: L1 trigger configuration from event setup
02033                         m_prescaleFactorSet = (*m_prescaleFactorsTechTrig).at(
02034                                 pfIndex);
02035 
02036                     }
02037 
02038                 } else {
02039                     // L1 trigger configuration from event setup only
02040                     m_prescaleFactorSet = (*m_prescaleFactorsTechTrig).at(
02041                             pfIndex);
02042 
02043                 }
02044 
02045             }
02046                 break;
02047             default: {
02048                 // do nothing - it was tested before, with return
02049 
02050             }
02051                 break;
02052         }
02053 
02054     }
02055 
02056     errorCode = iError;
02057     return m_prescaleFactorSet;
02058 
02059 }
02060 
02061 const std::vector<int>& L1GtUtils::prescaleFactorSet(const edm::Event& iEvent,
02062         const TriggerCategory& trigCategory, int& errorCode) {
02063 
02064     // clear the vector before filling it
02065     m_prescaleFactorSet.clear();
02066 
02067     // initialize error code
02068     int iError = 0;
02069 
02070     m_prescaleFactorSet = prescaleFactorSet(iEvent, m_provL1GtRecordInputTag,
02071             m_provL1GtReadoutRecordInputTag, trigCategory, iError);
02072 
02073     errorCode = iError;
02074     return m_prescaleFactorSet;
02075 
02076 }
02077 
02078 
02079 
02080 
02081 const std::vector<unsigned int>& L1GtUtils::triggerMaskSet(
02082         const TriggerCategory& trigCategory, int& errorCode) {
02083 
02084     // clear the vector before filling it
02085     m_triggerMaskSet.clear();
02086 
02087     // initialize error code and L1 configuration code
02088     int iError = 0;
02089     int l1ConfCode = 0;
02090 
02091     // check if L1 configuration is available
02092 
02093     if (!availableL1Configuration(iError, l1ConfCode)) {
02094         errorCode = iError;
02095         return m_triggerMaskSet;
02096     }
02097 
02098     // at this point, a valid L1 configuration is available, so the if/else if/else
02099     // can be simplified
02100 
02101 
02102     // depending on trigger category (algorithm trigger or technical trigger)
02103     // get the correct quantities
02104 
02105     // pointer to the set of trigger masks
02106 
02107     switch (trigCategory) {
02108         case AlgorithmTrigger: {
02109             if (m_retrieveL1GtTriggerMenuLite) {
02110                 // L1GtTriggerMenuLite has masks for physics partition only
02111                 // avoid copy to m_triggerMaskSet, return directly m_triggerMaskAlgoTrigLite
02112                if (m_l1GtMenuLiteValid) {
02113                     errorCode = iError;
02114                     return (*m_triggerMaskAlgoTrigLite);
02115 
02116                 } else {
02117                     // fall through: L1 trigger configuration from event setup
02118                     for (unsigned i = 0; i < m_triggerMaskAlgoTrig->size(); i++) {
02119                         m_triggerMaskSet.push_back(
02120                                 ((*m_triggerMaskAlgoTrig)[i]) & (1
02121                                         << m_physicsDaqPartition));
02122                     }
02123 
02124                 }
02125 
02126             } else {
02127                 // L1 trigger configuration from event setup only
02128                 for (unsigned i = 0; i < m_triggerMaskAlgoTrig->size(); i++) {
02129                     m_triggerMaskSet.push_back(((*m_triggerMaskAlgoTrig)[i])
02130                             & (1 << m_physicsDaqPartition));
02131                 }
02132 
02133             }
02134         }
02135             break;
02136         case TechnicalTrigger: {
02137             if (m_retrieveL1GtTriggerMenuLite) {
02138                 if (m_l1GtMenuLiteValid) {
02139                     errorCode = iError;
02140                     return (*m_triggerMaskTechTrigLite);
02141 
02142                 } else {
02143                     // fall through: L1 trigger configuration from event setup
02144                     for (unsigned i = 0; i < m_triggerMaskTechTrig->size(); i++) {
02145                         m_triggerMaskSet.push_back(
02146                                 ((*m_triggerMaskTechTrig)[i]) & (1
02147                                         << m_physicsDaqPartition));
02148                     }
02149 
02150                 }
02151 
02152             } else {
02153                 // L1 trigger configuration from event setup only
02154                 for (unsigned i = 0; i < m_triggerMaskTechTrig->size(); i++) {
02155                     m_triggerMaskSet.push_back(((*m_triggerMaskTechTrig)[i])
02156                             & (1 << m_physicsDaqPartition));
02157                 }
02158 
02159             }
02160         }
02161             break;
02162         default: {
02163             // should not be the case
02164             iError = l1ConfCode + 3;
02165 
02166             errorCode = iError;
02167             return m_triggerMaskSet;
02168 
02169         }
02170             break;
02171     }
02172 
02173     errorCode = iError;
02174     return m_triggerMaskSet;
02175 
02176 }
02177 
02178 
02179 
02180 const std::string& L1GtUtils::l1TriggerMenu() const {
02181 
02182     if (m_retrieveL1GtTriggerMenuLite) {
02183         if (m_l1GtMenuLiteValid) {
02184             return m_l1GtMenuLite->gtTriggerMenuName();
02185 
02186         } else if (m_retrieveL1EventSetup) {
02187             return m_l1GtMenu->gtTriggerMenuName();
02188 
02189         } else {
02190             // only L1GtTriggerMenuLite requested, but it is not valid
02191             return EmptyString;
02192 
02193         }
02194     } else if (m_retrieveL1EventSetup) {
02195         return m_l1GtMenu->gtTriggerMenuName();
02196 
02197     } else {
02198         // L1 trigger configuration not retrieved
02199         return EmptyString;
02200 
02201     }
02202 
02203 }
02204 
02205 const std::string& L1GtUtils::l1TriggerMenuImplementation() const {
02206 
02207     if (m_retrieveL1GtTriggerMenuLite) {
02208         if (m_l1GtMenuLiteValid) {
02209             return m_l1GtMenuLite->gtTriggerMenuImplementation();
02210 
02211         } else if (m_retrieveL1EventSetup) {
02212             return m_l1GtMenu->gtTriggerMenuImplementation();
02213 
02214         } else {
02215             // only L1GtTriggerMenuLite requested, but it is not valid
02216             return EmptyString;
02217 
02218         }
02219     } else if (m_retrieveL1EventSetup) {
02220         return m_l1GtMenu->gtTriggerMenuImplementation();
02221 
02222     } else {
02223         // L1 trigger configuration not retrieved
02224         return EmptyString;
02225 
02226     }
02227 
02228 }
02229 
02230 const L1GtTriggerMenu* L1GtUtils::ptrL1TriggerMenuEventSetup(int& errorCode) {
02231 
02232     // initialize error code and return value
02233     int iError = 0;
02234     int l1ConfCode = 0;
02235 
02236     // check if L1 configuration is available
02237 
02238     if (!availableL1Configuration(iError, l1ConfCode)) {
02239         errorCode = iError;
02240         return 0;
02241     }
02242 
02243     if (m_retrieveL1EventSetup) {
02244         errorCode = iError;
02245         return m_l1GtMenu;
02246     } else {
02247         iError = l1ConfCode;
02248 
02249         errorCode = iError;
02250         return 0;
02251 
02252     }
02253 
02254     errorCode = iError;
02255     return m_l1GtMenu;
02256 }
02257 
02258 const L1GtTriggerMenuLite* L1GtUtils::ptrL1GtTriggerMenuLite(int& errorCode) {
02259 
02260     // initialize error code and return value
02261     int iError = 0;
02262     int l1ConfCode = 0;
02263 
02264     // check if L1 configuration is available
02265 
02266     if (!availableL1Configuration(iError, l1ConfCode)) {
02267         errorCode = iError;
02268         return 0;
02269     }
02270 
02271     if (m_retrieveL1GtTriggerMenuLite) {
02272         if (m_l1GtMenuLiteValid) {
02273 
02274             errorCode = iError;
02275             return m_l1GtMenuLite;
02276 
02277         } else {
02278             iError = l1ConfCode;
02279 
02280             errorCode = iError;
02281             return 0;
02282         }
02283     } else {
02284         iError = l1ConfCode;
02285 
02286         errorCode = iError;
02287         return 0;
02288     }
02289 
02290     errorCode = iError;
02291     return m_l1GtMenuLite;
02292 
02293 }
02294 
02295 const bool L1GtUtils::availableL1Configuration(int& errorCode, int& l1ConfCode) const {
02296 
02297     if (m_retrieveL1GtTriggerMenuLite) {
02298         if (!m_retrieveL1EventSetup) {
02299             LogDebug("L1GtUtils")
02300                     << "\nRetrieve L1 trigger configuration from L1GtTriggerMenuLite only.\n"
02301                     << std::endl;
02302             l1ConfCode = 0;
02303         } else {
02304             LogDebug("L1GtUtils")
02305                     << "\nFall through: retrieve L1 trigger configuration from L1GtTriggerMenuLite."
02306                     << "\nIf L1GtTriggerMenuLite not valid, try to retrieve from event setup.\n"
02307                     << std::endl;
02308             l1ConfCode = 100000;
02309         }
02310 
02311         if (m_l1GtMenuLiteValid) {
02312             LogDebug("L1GtUtils")
02313                     << "\nRetrieve L1 trigger configuration from L1GtTriggerMenuLite, valid product.\n"
02314                     << std::endl;
02315             l1ConfCode = l1ConfCode  + 10000;
02316             errorCode = 0;
02317 
02318             return true;
02319 
02320         } else if (m_retrieveL1EventSetup) {
02321             if (m_l1EventSetupValid) {
02322                 LogDebug("L1GtUtils")
02323                         << "\nFall through: retrieve L1 trigger configuration from event setup."
02324                         << "\nFirst option was L1GtTriggerMenuLite - but product is not valid.\n"
02325                         << std::endl;
02326                 l1ConfCode = l1ConfCode  + 20000;
02327                 errorCode = 0;
02328 
02329                 return true;
02330 
02331             } else {
02332                 LogDebug("L1GtUtils")
02333                         << "\nFall through: L1GtTriggerMenuLite not valid, event setup not valid.\n"
02334                         << std::endl;
02335                 l1ConfCode = l1ConfCode  + L1GtNotValidError;
02336                 errorCode = l1ConfCode;
02337 
02338                 return false;
02339 
02340 
02341             }
02342 
02343         } else {
02344             LogDebug("L1GtUtils")
02345                     << "\nError: L1 trigger configuration requested from L1GtTriggerMenuLite only"
02346                     << "\nbut L1GtTriggerMenuLite is not valid.\n" << std::endl;
02347             l1ConfCode = l1ConfCode  + L1GtNotValidError;
02348             errorCode = l1ConfCode;
02349 
02350             return false;
02351 
02352         }
02353     } else if (m_retrieveL1EventSetup) {
02354 
02355         LogDebug("L1GtUtils")
02356                 << "\nRetrieve L1 trigger configuration from event setup."
02357                 << "\nL1GtTriggerMenuLite product was not requested.\n"
02358                 << std::endl;
02359         l1ConfCode = 200000;
02360 
02361         if (m_l1EventSetupValid) {
02362             LogDebug("L1GtUtils")
02363                     << "\nRetrieve L1 trigger configuration from event setup only."
02364                     << "\nValid L1 trigger event setup.\n"
02365                     << std::endl;
02366             l1ConfCode = l1ConfCode  + 10000;
02367             errorCode = 0;
02368 
02369             return true;
02370 
02371         } else {
02372             LogDebug("L1GtUtils")
02373                     << "\nRetrieve L1 trigger configuration from event setup only."
02374                     << "\nNo valid L1 trigger event setup.\n"
02375                     << std::endl;
02376             l1ConfCode = l1ConfCode  + L1GtNotValidError;
02377             errorCode = l1ConfCode;
02378 
02379             return false;
02380 
02381 
02382         }
02383 
02384     } else {
02385         LogDebug("L1GtUtils")
02386                 << "\nError: no L1 trigger configuration requested to be retrieved."
02387                 << "\nMust call before getL1GtRunCache in beginRun and analyze.\n"
02388                 << std::endl;
02389         l1ConfCode = 300000;
02390         errorCode = l1ConfCode;
02391 
02392         return false;
02393 
02394     }
02395 }
02396 
02397 // private methods
02398 
02399 const bool L1GtUtils::trigResult(const DecisionWord& decWord,
02400         const int bitNumber, const std::string& nameAlgoTechTrig,
02401         const TriggerCategory& trigCategory, int& errorCode) const {
02402 
02403     bool trigRes = false;
02404     errorCode = 0;
02405 
02406     if (bitNumber < (static_cast<int> (decWord.size()))) {
02407         trigRes = decWord[bitNumber];
02408     } else {
02409         errorCode = 3000;
02410         LogDebug("L1GtUtils") << "\nError: bit number " << bitNumber
02411                 << " retrieved for " << triggerCategory(trigCategory) << "\n  "
02412                 << nameAlgoTechTrig
02413                 << "\ngreater than size of L1 GT decision word: "
02414                 << decWord.size()
02415                 << "\nError: Inconsistent L1 trigger configuration!"
02416                 << std::endl;
02417     }
02418 
02419     return trigRes;
02420 }
02421 
02422 L1GtUtils::LogicalExpressionL1Results::LogicalExpressionL1Results(
02423         const std::string& expression, L1GtUtils& l1GtUtils) :
02424 
02425         m_logicalExpression(expression),
02426 
02427         m_l1GtUtils(l1GtUtils),
02428 
02429         m_l1GtRecordInputTag(edm::InputTag()),
02430 
02431         m_l1GtReadoutRecordInputTag(edm::InputTag()),
02432 
02433         m_l1ConfCode(-1),
02434 
02435         m_validL1Configuration(false),
02436 
02437         m_validLogicalExpression(false),
02438 
02439         m_l1GtInputTagsFromProv(true),
02440 
02441         m_l1ResultsAlreadyCalled(false),
02442 
02443         m_expL1TriggersSize(0),
02444 
02445         m_expBitsTechTrigger(false) {
02446 
02447     initialize();
02448 }
02449 
02450 L1GtUtils::LogicalExpressionL1Results::LogicalExpressionL1Results(
02451         const std::string& expression, L1GtUtils& l1GtUtils,
02452         const edm::InputTag& l1GtRecordInputTag,
02453         const edm::InputTag& l1GtReadoutRecordInputTag) :
02454 
02455         m_logicalExpression(expression),
02456 
02457         m_l1GtUtils(l1GtUtils),
02458 
02459         m_l1GtRecordInputTag(l1GtRecordInputTag),
02460 
02461         m_l1GtReadoutRecordInputTag(l1GtReadoutRecordInputTag),
02462 
02463         m_l1ConfCode(-1),
02464 
02465         m_validL1Configuration(false),
02466 
02467         m_validLogicalExpression(false),
02468 
02469         m_l1GtInputTagsFromProv(false),
02470 
02471         m_l1ResultsAlreadyCalled(false),
02472 
02473         m_expL1TriggersSize(0),
02474 
02475         m_expBitsTechTrigger(false) {
02476 
02477     initialize();
02478 }
02479 
02480 // destructor
02481 L1GtUtils::LogicalExpressionL1Results::~LogicalExpressionL1Results() {
02482 
02483     // empty
02484 
02485 }
02486 
02487 bool L1GtUtils::LogicalExpressionL1Results::initialize() {
02488 
02489     // get the vector of triggers corresponding to the logical expression
02490     // check also the logical expression - add/remove spaces if needed
02491 
02492     try {
02493 
02494         L1GtLogicParser m_l1AlgoLogicParser = L1GtLogicParser(
02495                 m_logicalExpression);
02496 
02497         // list of L1 triggers from the logical expression
02498         m_expL1Triggers = m_l1AlgoLogicParser.operandTokenVector();
02499         m_expL1TriggersSize = m_expL1Triggers.size();
02500 
02501         m_validLogicalExpression = true;
02502 
02503     } catch (cms::Exception & ex) {
02504         m_validLogicalExpression = false;
02505 
02506         edm::LogWarning("L1GtUtils") << ex;
02507         edm::LogWarning("L1GtUtils") << ex.what();
02508         edm::LogWarning("L1GtUtils") << ex.explainSelf();
02509     }
02510 
02511     // try to convert the string representing each L1 trigger to bit number,
02512     //   to check if the logical expression is constructed from bit numbers
02513     // trade-off: cache it here, irrespective of the expression
02514     //   when the conversion fails (normally for the first seed, 
02515     //   if not expression of technical trigger bits), stop and 
02516     //   set m_expBitsTechTrigger to false
02517 
02518     m_expBitsTechTrigger = true;
02519 
02520     for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
02521         const std::string& bitString = (m_expL1Triggers[iTrig]).tokenName;
02522         std::istringstream bitStream(bitString);
02523         int bitInt;
02524 
02525         if ((bitStream >> bitInt).fail()) {
02526 
02527             m_expBitsTechTrigger = false;
02528 
02529             break;
02530         }
02531 
02532         (m_expL1Triggers[iTrig]).tokenNumber = bitInt;
02533 
02534     }
02535 
02536     // resize and fill 
02537     m_decisionsBeforeMask.resize(m_expL1TriggersSize);
02538     m_decisionsAfterMask.resize(m_expL1TriggersSize);
02539     m_prescaleFactors.resize(m_expL1TriggersSize);
02540     m_triggerMasks.resize(m_expL1TriggersSize);
02541     m_errorCodes.resize(m_expL1TriggersSize);
02542     m_expTriggerCategory.resize(m_expL1TriggersSize);
02543     m_expTriggerInMenu.resize(m_expL1TriggersSize);
02544 
02545     LogDebug("L1GtUtils") << std::endl;
02546     LogTrace("L1GtUtils") << "\nLogical expression\n  " << m_logicalExpression
02547             << "\n has " << m_expL1TriggersSize << " L1 triggers" << std::endl;
02548     for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
02549 
02550         const std::string& trigNameOrAlias = (m_expL1Triggers[iTrig]).tokenName;
02551         LogTrace("L1GtUtils") << "  " << trigNameOrAlias << std::endl;
02552 
02553         (m_decisionsBeforeMask[iTrig]).first = trigNameOrAlias;
02554         (m_decisionsBeforeMask[iTrig]).second = false;
02555 
02556         (m_decisionsAfterMask[iTrig]).first = trigNameOrAlias;
02557         (m_decisionsAfterMask[iTrig]).second = false;
02558 
02559         (m_prescaleFactors[iTrig]).first = trigNameOrAlias;
02560         (m_prescaleFactors[iTrig]).second = -1;
02561 
02562         (m_triggerMasks[iTrig]).first = trigNameOrAlias;
02563         (m_triggerMasks[iTrig]).second = -1;
02564 
02565         (m_errorCodes[iTrig]).first = trigNameOrAlias;
02566         (m_errorCodes[iTrig]).second = -1;
02567 
02568         m_expTriggerCategory[iTrig] = L1GtUtils::AlgorithmTrigger;
02569 
02570         m_expTriggerInMenu[iTrig] = false;
02571 
02572     }
02573     LogTrace("L1GtUtils") << std::endl;
02574 
02575     return true;
02576 
02577 }
02578 
02579 
02580 const int L1GtUtils::LogicalExpressionL1Results::logicalExpressionRunUpdate(
02581         const edm::Run& iRun, const edm::EventSetup& evSetup,
02582         const std::string& logicExpression) {
02583 
02584     // initialize error code
02585     int errorCode = 0;
02586 
02587     // logical expression has changed - one must re-initialize all quantities related to the logical expression
02588     // and clear the vectors
02589 
02590     m_logicalExpression = logicExpression;
02591     m_validLogicalExpression = false;
02592 
02593     m_l1ResultsAlreadyCalled = false;
02594 
02595     m_expL1TriggersSize = 0;
02596     m_expBitsTechTrigger = false;
02597     
02598     // 
02599     m_decisionsBeforeMask.clear();
02600     m_decisionsAfterMask.clear();
02601     m_prescaleFactors.clear();
02602     m_triggerMasks.clear();
02603     m_errorCodes.clear();
02604     m_expTriggerCategory.clear();
02605     m_expTriggerInMenu.clear();
02606 
02607 
02608     initialize();
02609 
02610     //
02611     errorCode = logicalExpressionRunUpdate(iRun, evSetup);
02612 
02613     return errorCode;
02614 
02615 }
02616 
02617 
02618 const int L1GtUtils::LogicalExpressionL1Results::logicalExpressionRunUpdate(
02619         const edm::Run& iRun, const edm::EventSetup& evSetup) {
02620 
02621     // check first that a valid L1 configuration was retrieved, 
02622     // to prevent also calls before the L1 configuration retrieval
02623 
02624     // initialize error code and L1 configuration code
02625     int errorCode = 0;
02626     int l1ConfCode = 0;
02627 
02628     if (!(m_l1GtUtils.availableL1Configuration(errorCode, l1ConfCode))) {
02629 
02630         m_validL1Configuration = false;
02631         return errorCode;
02632     } else {
02633 
02634         m_validL1Configuration = true;
02635         m_l1ConfCode = l1ConfCode;
02636     }
02637 
02638     // check if the trigger (name of alias) from the logical expression are in the menu, 
02639     // if names are used, set tokenNumber to the corresponding bit number
02640     // if technical trigger bits, set tokenName to the corresponding technical trigger name, if 
02641     //   a technical trigger exists on that bit
02642     // for each trigger, set also the trigger category
02643 
02644     // initialization 
02645     L1GtUtils::TriggerCategory trigCategory = L1GtUtils::AlgorithmTrigger;
02646     int bitNumber = -1;
02647 
02648     for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
02649 
02650         trigCategory = L1GtUtils::AlgorithmTrigger;
02651         bitNumber = -1;
02652         const std::string& trigNameOrAlias = (m_expL1Triggers[iTrig]).tokenName;
02653 
02654         if (!m_expBitsTechTrigger) {
02655             const bool triggerInMenu = m_l1GtUtils.l1AlgoTechTrigBitNumber(
02656                     trigNameOrAlias, trigCategory, bitNumber);
02657 
02658             (m_expL1Triggers[iTrig]).tokenNumber = bitNumber;
02659             m_expTriggerCategory[iTrig] = trigCategory;
02660             m_expTriggerInMenu[iTrig] = triggerInMenu;
02661 
02662         } else {
02663 
02664             std::string aliasL1Trigger;
02665             std::string nameL1Trigger;
02666 
02667             trigCategory = L1GtUtils::TechnicalTrigger;
02668             bitNumber = (m_expL1Triggers[iTrig]).tokenNumber;
02669 
02670             const bool triggerInMenu = m_l1GtUtils.l1TriggerNameFromBit(
02671                     bitNumber, trigCategory, aliasL1Trigger, nameL1Trigger);
02672 
02673             if (!triggerInMenu) {
02674                 aliasL1Trigger = "Technical_trigger_bit_"
02675                         + (m_expL1Triggers[iTrig]).tokenName + "_empty";
02676             }
02677 
02678             (m_expL1Triggers[iTrig]).tokenName = aliasL1Trigger;
02679             m_expTriggerCategory[iTrig] = trigCategory;
02680             m_expTriggerInMenu[iTrig] = triggerInMenu;
02681 
02682             // put the names of the technical triggers in the returned quantities
02683 
02684             (m_decisionsBeforeMask[iTrig]).first = aliasL1Trigger;
02685             (m_decisionsAfterMask[iTrig]).first = aliasL1Trigger;
02686             (m_prescaleFactors[iTrig]).first = aliasL1Trigger;
02687             (m_triggerMasks[iTrig]).first = aliasL1Trigger;
02688             (m_errorCodes[iTrig]).first = aliasL1Trigger;
02689 
02690         }
02691     }
02692 
02693     return errorCode;
02694 
02695 }
02696 
02697 const std::vector<std::pair<std::string, bool> >& L1GtUtils::LogicalExpressionL1Results::decisionsBeforeMask() {
02698 
02699     // throw an exception if the result is not computed once per event - user usage error
02700     if (!m_l1ResultsAlreadyCalled) {
02701         throw cms::Exception("FailModule") << "\nUsage error: "
02702                 << "\n  Method 'errorCodes' must be called in the event loop before attempting to use this method.\n"
02703                 << std::endl;
02704     }
02705 
02706     return m_decisionsBeforeMask;
02707 
02708 }
02709 
02710 const std::vector<std::pair<std::string, bool> >& L1GtUtils::LogicalExpressionL1Results::decisionsAfterMask() {
02711 
02712     // throw an exception if the result is not computed once per event - user usage error
02713     if (!m_l1ResultsAlreadyCalled) {
02714         throw cms::Exception("FailModule") << "\nUsage error: "
02715                 << "\n  Method 'errorCodes' must be called in the event loop before attempting to use this method.\n"
02716                 << std::endl;
02717     }
02718 
02719     return m_decisionsAfterMask;
02720 
02721 }
02722 
02723 const std::vector<std::pair<std::string, int> >& L1GtUtils::LogicalExpressionL1Results::prescaleFactors() {
02724 
02725     // throw an exception if the result is not computed once per event - user usage error
02726     if (!m_l1ResultsAlreadyCalled) {
02727         throw cms::Exception("FailModule") << "\nUsage error: "
02728                 << "\n  Method 'errorCodes' must be called in the event loop before attempting to use this method.\n"
02729                 << std::endl;
02730     }
02731 
02732     return m_prescaleFactors;
02733 
02734 }
02735 
02736 const std::vector<std::pair<std::string, int> >& L1GtUtils::LogicalExpressionL1Results::triggerMasks() {
02737 
02738     // throw an exception if the result is not computed once per event - user usage error
02739     if (!m_l1ResultsAlreadyCalled) {
02740         throw cms::Exception("FailModule") << "\nUsage error: "
02741                 << "\n  Method 'errorCodes' must be called in the event loop before attempting to use this method.\n"
02742                 << std::endl;
02743     }
02744 
02745     return m_triggerMasks;
02746 
02747 }
02748 
02749 const std::vector<std::pair<std::string, int> >& L1GtUtils::LogicalExpressionL1Results::errorCodes(
02750         const edm::Event& iEvent) {
02751 
02752     m_l1ResultsAlreadyCalled = false;
02753 
02754     // if not a valid L1 configuration, reset all quantities and return
02755     if (!m_validL1Configuration) {
02756         reset(m_decisionsBeforeMask);
02757         reset(m_decisionsAfterMask);
02758         reset(m_prescaleFactors);
02759         reset(m_triggerMasks);
02760         reset(m_errorCodes);
02761 
02762         m_l1ResultsAlreadyCalled = true;
02763         return m_errorCodes;
02764 
02765     }
02766 
02767     if (m_l1GtInputTagsFromProv) {
02768 
02769         l1Results(iEvent, m_l1GtUtils.provL1GtRecordInputTag(),
02770                 m_l1GtUtils.provL1GtReadoutRecordInputTag());
02771 
02772     } else {
02773 
02774         l1Results(iEvent, m_l1GtRecordInputTag, m_l1GtReadoutRecordInputTag);
02775     }
02776 
02777     m_l1ResultsAlreadyCalled = true;
02778 
02779     return m_errorCodes;
02780 
02781 }
02782 
02783 void L1GtUtils::LogicalExpressionL1Results::reset(
02784         std::vector<std::pair<std::string, bool> > pairVector) const {
02785 
02786     for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
02787         (pairVector[iTrig]).second = false;
02788     }
02789 }
02790 
02791 void L1GtUtils::LogicalExpressionL1Results::reset(
02792         std::vector<std::pair<std::string, int> > pairVector) const {
02793 
02794     for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
02795         (pairVector[iTrig]).second = -1;
02796     }
02797 }
02798 
02799 void L1GtUtils::LogicalExpressionL1Results::l1Results(const edm::Event& iEvent,
02800         const edm::InputTag& l1GtRecordInputTag,
02801         const edm::InputTag& l1GtReadoutRecordInputTag) {
02802 
02803     // reset the vectors before filling them
02804     reset(m_decisionsBeforeMask);
02805     reset(m_decisionsAfterMask);
02806     reset(m_prescaleFactors);
02807     reset(m_triggerMasks);
02808     reset(m_errorCodes);
02809 
02810     // initialization of actual values for each trigger
02811     bool decisionBeforeMaskValue = false;
02812     bool decisionAfterMaskValue = false;
02813     int prescaleFactorValue = -1;
02814     int triggerMaskValue = -1;
02815     int errorCode = -1;
02816 
02817     LogDebug("L1GtUtils") << std::endl;
02818     LogTrace("L1GtUtils") << "\nLogical expression\n  " << m_logicalExpression
02819             << std::endl;
02820 
02821     // for each trigger, if it is in the L1 menu, get the prescale factor and trigger mask
02822 
02823     for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
02824 
02825         const std::string& trigNameOrAlias = (m_expL1Triggers[iTrig]).tokenName;
02826 
02827         if (m_expTriggerInMenu[iTrig]) {
02828             errorCode = m_l1GtUtils.l1Results(iEvent, l1GtRecordInputTag,
02829                     l1GtReadoutRecordInputTag, trigNameOrAlias,
02830                     decisionBeforeMaskValue, decisionAfterMaskValue,
02831                     prescaleFactorValue, triggerMaskValue);
02832 
02833             if (errorCode != 0) {
02834 
02835                 // error while retrieving the results
02836                 //    for this trigger: set prescale factor to -1, trigger mask to -1
02837 
02838                 decisionBeforeMaskValue = false;
02839                 decisionAfterMaskValue = false;
02840                 prescaleFactorValue = -1;
02841                 triggerMaskValue = -1;
02842 
02843             }
02844 
02845         } else {
02846             // no trigger name or trigger alias in the menu, no bits: 
02847             //    for this trigger: set prescale factor to -1, set the error code
02848 
02849             decisionBeforeMaskValue = false;
02850             decisionAfterMaskValue = false;
02851             prescaleFactorValue = -1;
02852             triggerMaskValue = -1;
02853             errorCode = m_l1ConfCode + 1;
02854 
02855         }
02856 
02857         LogTrace("L1GtUtils") << "\n" << trigNameOrAlias << ":" << std::endl;
02858 
02859         (m_decisionsBeforeMask[iTrig]).second = decisionBeforeMaskValue;
02860         LogTrace("L1GtUtils") << "    decision before mask = "
02861                 << decisionBeforeMaskValue << std::endl;
02862 
02863         (m_decisionsAfterMask[iTrig]).second = decisionAfterMaskValue;
02864         LogTrace("L1GtUtils") << "    decision after mask  = "
02865                 << decisionAfterMaskValue << std::endl;
02866 
02867         (m_prescaleFactors[iTrig]).second = prescaleFactorValue;
02868         LogTrace("L1GtUtils") << "    prescale factor      = "
02869                 << prescaleFactorValue << std::endl;
02870 
02871         (m_triggerMasks[iTrig]).second = triggerMaskValue;
02872         LogTrace("L1GtUtils") << "    trigger mask         = "
02873                 << triggerMaskValue << std::endl;
02874 
02875         (m_errorCodes[iTrig]).second = errorCode;
02876         LogTrace("L1GtUtils") << "    error code           = " << errorCode
02877                 << std::endl;
02878 
02879     }
02880 
02881     LogDebug("L1GtUtils") << std::endl;
02882 
02883 }
02884 
02885 const std::string L1GtUtils::EmptyString = "";
02886 const int L1GtUtils::L1GtNotValidError = 99999;
02887