Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:51

0001 /**
0002  * \class L1GtTriggerMenuLite
0003  *
0004  *
0005  * Description: L1 trigger menu and masks, lite version not using event setup.
0006  *
0007  * Implementation:
0008  *    This is the lite version of the L1 trigger menu, with trigger masks included,
0009  *    to be used in the environments not having access to event setup. It offers
0010  *    limited access to the full L1 trigger menu which is implemented as event setup
0011  *    (CondFormats/L1TObjects/interface/L1GtTriggerMenu.h). The masks are provided for
0012  *    the physics partition only.
0013  *
0014  *    An EDM product is created and saved in the Run Data, under the assumption that the
0015  *    menu remains the same in a run.
0016  *    The corresponding producer will read the full L1 trigger menu and the trigger masks
0017  *    from event setup, fill the corresponding members and save it as EDM product.
0018  *
0019  * \author: Vasile Mihai Ghete - HEPHY Vienna
0020  *
0021  *
0022  */
0023 
0024 // this class header
0025 #include "DataFormats/L1GlobalTrigger/interface/L1GtTriggerMenuLite.h"
0026 
0027 // system include files
0028 #include <iostream>
0029 #include <iomanip>
0030 
0031 // user include files
0032 
0033 // forward declarations
0034 
0035 // constructor
0036 L1GtTriggerMenuLite::L1GtTriggerMenuLite()
0037     : m_triggerMenuInterface("NULL"),
0038       m_triggerMenuName("NULL"),
0039       m_triggerMenuImplementation("NULL"),
0040       m_scaleDbKey("NULL") {
0041   // empty
0042 }
0043 
0044 L1GtTriggerMenuLite::L1GtTriggerMenuLite(const std::string& triggerMenuNameVal,
0045                                          const L1TriggerMap& algorithmMapVal,
0046                                          const L1TriggerMap& algorithmAliasMapVal,
0047                                          const L1TriggerMap& technicalTriggerMapVal,
0048                                          const std::vector<unsigned int>& triggerMaskAlgoTrigVal,
0049                                          const std::vector<unsigned int>& triggerMaskTechTrigVal,
0050                                          const std::vector<std::vector<int> >& prescaleFactorsAlgoTrigVal,
0051                                          const std::vector<std::vector<int> >& prescaleFactorsTechTrigVal)
0052     : m_triggerMenuInterface("NULL"),
0053       m_triggerMenuName(triggerMenuNameVal),
0054       m_triggerMenuImplementation("NULL"),
0055       m_scaleDbKey("NULL"),
0056       m_algorithmMap(algorithmMapVal),
0057       m_algorithmAliasMap(algorithmAliasMapVal),
0058       m_technicalTriggerMap(technicalTriggerMapVal),
0059       m_triggerMaskAlgoTrig(triggerMaskAlgoTrigVal),
0060       m_triggerMaskTechTrig(triggerMaskTechTrigVal),
0061       m_prescaleFactorsAlgoTrig(prescaleFactorsAlgoTrigVal),
0062       m_prescaleFactorsTechTrig(prescaleFactorsTechTrigVal)
0063 
0064 {
0065   // empty
0066 }
0067 
0068 // copy constructor
0069 L1GtTriggerMenuLite::L1GtTriggerMenuLite(const L1GtTriggerMenuLite& rhs) {
0070   m_triggerMenuInterface = rhs.m_triggerMenuInterface;
0071   m_triggerMenuName = rhs.m_triggerMenuName;
0072   m_triggerMenuImplementation = rhs.m_triggerMenuImplementation;
0073   m_scaleDbKey = rhs.m_scaleDbKey;
0074 
0075   // copy algorithm map
0076   m_algorithmMap = rhs.m_algorithmMap;
0077   m_algorithmAliasMap = rhs.m_algorithmAliasMap;
0078 
0079   // copy technical triggers
0080   // (separate map for technical triggers and physics triggers)
0081   m_technicalTriggerMap = rhs.m_technicalTriggerMap;
0082 
0083   // copy masks
0084   m_triggerMaskAlgoTrig = rhs.m_triggerMaskAlgoTrig;
0085   m_triggerMaskTechTrig = rhs.m_triggerMaskTechTrig;
0086 
0087   // copy prescale factors
0088   m_prescaleFactorsAlgoTrig = rhs.m_prescaleFactorsAlgoTrig;
0089   m_prescaleFactorsTechTrig = rhs.m_prescaleFactorsTechTrig;
0090 }
0091 
0092 // destructor
0093 L1GtTriggerMenuLite::~L1GtTriggerMenuLite() {
0094   m_algorithmMap.clear();
0095   m_algorithmAliasMap.clear();
0096   m_technicalTriggerMap.clear();
0097 }
0098 
0099 // assignment operator
0100 L1GtTriggerMenuLite& L1GtTriggerMenuLite::operator=(const L1GtTriggerMenuLite& rhs) {
0101   if (this != &rhs) {
0102     m_triggerMenuInterface = rhs.m_triggerMenuInterface;
0103     m_triggerMenuName = rhs.m_triggerMenuName;
0104     m_triggerMenuImplementation = rhs.m_triggerMenuImplementation;
0105     m_scaleDbKey = rhs.m_scaleDbKey;
0106 
0107     m_algorithmMap = rhs.m_algorithmMap;
0108     m_algorithmAliasMap = rhs.m_algorithmAliasMap;
0109 
0110     m_technicalTriggerMap = rhs.m_technicalTriggerMap;
0111 
0112     m_triggerMaskAlgoTrig = rhs.m_triggerMaskAlgoTrig;
0113     m_triggerMaskTechTrig = rhs.m_triggerMaskTechTrig;
0114 
0115     m_prescaleFactorsAlgoTrig = rhs.m_prescaleFactorsAlgoTrig;
0116     m_prescaleFactorsTechTrig = rhs.m_prescaleFactorsTechTrig;
0117   }
0118 
0119   // return the object
0120   return *this;
0121 }
0122 
0123 // equal operator
0124 bool L1GtTriggerMenuLite::operator==(const L1GtTriggerMenuLite& rhs) const {
0125   if (m_triggerMenuInterface != rhs.m_triggerMenuInterface) {
0126     return false;
0127   }
0128 
0129   if (m_triggerMenuName != rhs.m_triggerMenuName) {
0130     return false;
0131   }
0132 
0133   if (m_triggerMenuImplementation != rhs.m_triggerMenuImplementation) {
0134     return false;
0135   }
0136 
0137   if (m_scaleDbKey != rhs.m_scaleDbKey) {
0138     return false;
0139   }
0140 
0141   if (m_algorithmMap != rhs.m_algorithmMap) {
0142     return false;
0143   }
0144 
0145   if (m_algorithmAliasMap != rhs.m_algorithmAliasMap) {
0146     return false;
0147   }
0148 
0149   if (m_technicalTriggerMap != rhs.m_technicalTriggerMap) {
0150     return false;
0151   }
0152 
0153   if (m_triggerMaskAlgoTrig != rhs.m_triggerMaskAlgoTrig) {
0154     return false;
0155   }
0156 
0157   if (m_triggerMaskTechTrig != rhs.m_triggerMaskTechTrig) {
0158     return false;
0159   }
0160 
0161   if (m_prescaleFactorsAlgoTrig != rhs.m_prescaleFactorsAlgoTrig) {
0162     return false;
0163   }
0164 
0165   if (m_prescaleFactorsTechTrig != rhs.m_prescaleFactorsTechTrig) {
0166     return false;
0167   }
0168 
0169   // all members identical
0170   return true;
0171 }
0172 
0173 // unequal operator
0174 bool L1GtTriggerMenuLite::operator!=(const L1GtTriggerMenuLite& otherObj) const { return !(otherObj == *this); }
0175 
0176 // merge rule: test on isProductEqual
0177 bool L1GtTriggerMenuLite::isProductEqual(const L1GtTriggerMenuLite& otherObj) const { return (otherObj == *this); }
0178 
0179 // set the trigger menu name
0180 void L1GtTriggerMenuLite::setGtTriggerMenuInterface(const std::string& menuInterface) {
0181   m_triggerMenuInterface = menuInterface;
0182 }
0183 
0184 void L1GtTriggerMenuLite::setGtTriggerMenuName(const std::string& menuName) { m_triggerMenuName = menuName; }
0185 
0186 void L1GtTriggerMenuLite::setGtTriggerMenuImplementation(const std::string& menuImplementation) {
0187   m_triggerMenuImplementation = menuImplementation;
0188 }
0189 
0190 // set menu associated scale key
0191 void L1GtTriggerMenuLite::setGtScaleDbKey(const std::string& scaleKey) { m_scaleDbKey = scaleKey; }
0192 
0193 // set the algorithm map (by algorithm names)
0194 void L1GtTriggerMenuLite::setGtAlgorithmMap(const L1TriggerMap& algoMap) { m_algorithmMap = algoMap; }
0195 
0196 // set the algorithm map (by algorithm aliases)
0197 void L1GtTriggerMenuLite::setGtAlgorithmAliasMap(const L1TriggerMap& algoMap) { m_algorithmAliasMap = algoMap; }
0198 
0199 // set the technical trigger map
0200 void L1GtTriggerMenuLite::setGtTechnicalTriggerMap(const L1TriggerMap& ttMap) { m_technicalTriggerMap = ttMap; }
0201 
0202 // set the trigger mask for physics algorithms
0203 void L1GtTriggerMenuLite::setGtTriggerMaskAlgoTrig(const std::vector<unsigned int>& maskValue) {
0204   m_triggerMaskAlgoTrig = maskValue;
0205 }
0206 
0207 // set the trigger mask for technical triggers
0208 void L1GtTriggerMenuLite::setGtTriggerMaskTechTrig(const std::vector<unsigned int>& maskValue) {
0209   m_triggerMaskTechTrig = maskValue;
0210 }
0211 
0212 // set the prescale factors
0213 void L1GtTriggerMenuLite::setGtPrescaleFactorsAlgoTrig(const std::vector<std::vector<int> >& factorValue) {
0214   m_prescaleFactorsAlgoTrig = factorValue;
0215 }
0216 
0217 void L1GtTriggerMenuLite::setGtPrescaleFactorsTechTrig(const std::vector<std::vector<int> >& factorValue) {
0218   m_prescaleFactorsTechTrig = factorValue;
0219 }
0220 
0221 // print the trigger menu
0222 void L1GtTriggerMenuLite::print(std::ostream& myCout, int& printVerbosity) const {
0223   //
0224 
0225   switch (printVerbosity) {
0226     case 0: {
0227       size_t nrDefinedAlgo = m_algorithmMap.size();
0228       size_t nrDefinedTech = m_technicalTriggerMap.size();
0229 
0230       // header for printing algorithms
0231 
0232       myCout << "\n   ********** L1 Trigger Menu - printing   ********** \n"
0233              << "\nL1 Trigger Menu Interface: " << m_triggerMenuInterface
0234              << "\nL1 Trigger Menu Name:      " << m_triggerMenuName
0235              << "\nL1 Trigger Menu Implementation: " << m_triggerMenuImplementation
0236              << "\nAssociated Scale DB Key: " << m_scaleDbKey << "\n\n"
0237              << "\nL1 Physics Algorithms: " << nrDefinedAlgo << " algorithms defined."
0238              << "\n\n"
0239              << "Bit Number " << std::right << std::setw(35) << "Algorithm Name"
0240              << "  " << std::right << std::setw(35) << "Algorithm Alias"
0241              << "  " << std::right << std::setw(12) << "Trigger Mask";
0242       for (unsigned iSet = 0; iSet < m_prescaleFactorsAlgoTrig.size(); iSet++) {
0243         myCout << std::right << std::setw(10) << "PF Set " << std::right << std::setw(2) << iSet;
0244       }
0245 
0246       myCout << std::endl;
0247 
0248       for (CItL1Trig itTrig = m_algorithmMap.begin(); itTrig != m_algorithmMap.end(); itTrig++) {
0249         const unsigned int bitNumber = itTrig->first;
0250         const std::string& aName = itTrig->second;
0251 
0252         std::string aAlias;
0253         CItL1Trig itAlias = m_algorithmAliasMap.find(bitNumber);
0254         if (itAlias != m_algorithmAliasMap.end()) {
0255           aAlias = itAlias->second;
0256         }
0257 
0258         myCout << std::setw(6) << bitNumber << "     " << std::right << std::setw(35) << aName << "  " << std::right
0259                << std::setw(35) << aAlias << "  " << std::right << std::setw(12) << m_triggerMaskAlgoTrig[bitNumber];
0260         for (unsigned iSet = 0; iSet < m_prescaleFactorsAlgoTrig.size(); iSet++) {
0261           myCout << std::right << std::setw(12) << m_prescaleFactorsAlgoTrig[iSet][bitNumber];
0262         }
0263 
0264         myCout << std::endl;
0265       }
0266 
0267       myCout << "\nL1 Technical Triggers: " << nrDefinedTech << " technical triggers defined."
0268              << "\n\n"
0269              << std::endl;
0270       if (nrDefinedTech) {
0271         myCout << std::right << std::setw(6) << "Bit Number " << std::right << std::setw(45)
0272                << " Technical trigger name "
0273                << "  " << std::right << std::setw(12) << "Trigger Mask";
0274         for (unsigned iSet = 0; iSet < m_prescaleFactorsTechTrig.size(); iSet++) {
0275           myCout << std::right << std::setw(10) << "PF Set " << std::right << std::setw(2) << iSet;
0276         }
0277 
0278         myCout << std::endl;
0279       }
0280 
0281       for (CItL1Trig itTrig = m_technicalTriggerMap.begin(); itTrig != m_technicalTriggerMap.end(); itTrig++) {
0282         unsigned int bitNumber = itTrig->first;
0283         std::string aName = itTrig->second;
0284 
0285         myCout << std::setw(6) << bitNumber << "       " << std::right << std::setw(45) << aName << std::right
0286                << std::setw(12) << m_triggerMaskTechTrig[bitNumber];
0287         for (unsigned iSet = 0; iSet < m_prescaleFactorsTechTrig.size(); iSet++) {
0288           myCout << std::right << std::setw(12) << m_prescaleFactorsTechTrig[iSet][bitNumber];
0289         }
0290 
0291         myCout << std::endl;
0292       }
0293 
0294     } break;
0295     default: {
0296       myCout << "\n   ********** L1 Trigger Menu - printing   ********** \n\n"
0297              << "Verbosity level: " << printVerbosity << " not implemented.\n\n"
0298              << std::endl;
0299     } break;
0300   }
0301 }
0302 
0303 // output stream operator
0304 std::ostream& operator<<(std::ostream& streamRec, const L1GtTriggerMenuLite& result) {
0305   int verbosityLevel = 0;
0306 
0307   result.print(streamRec, verbosityLevel);
0308   return streamRec;
0309 }
0310 
0311 // get the alias for a physics algorithm with a given bit number
0312 const std::string* L1GtTriggerMenuLite::gtAlgorithmAlias(const unsigned int bitNumber, int& errorCode) const {
0313   const std::string* gtAlgorithmAlias = nullptr;
0314 
0315   for (CItL1Trig itTrig = m_algorithmAliasMap.begin(); itTrig != m_algorithmAliasMap.end(); itTrig++) {
0316     if (itTrig->first == bitNumber) {
0317       gtAlgorithmAlias = &(itTrig->second);
0318 
0319       errorCode = 0;
0320       return gtAlgorithmAlias;
0321     }
0322   }
0323 
0324   errorCode = 1;
0325   return gtAlgorithmAlias;
0326 }
0327 
0328 // get the name for a physics algorithm or a technical trigger
0329 // with a given bit number
0330 const std::string* L1GtTriggerMenuLite::gtAlgorithmName(const unsigned int bitNumber, int& errorCode) const {
0331   const std::string* gtAlgorithmName = nullptr;
0332 
0333   for (CItL1Trig itTrig = m_algorithmMap.begin(); itTrig != m_algorithmMap.end(); itTrig++) {
0334     if (itTrig->first == bitNumber) {
0335       gtAlgorithmName = &(itTrig->second);
0336 
0337       errorCode = 0;
0338       return gtAlgorithmName;
0339     }
0340   }
0341 
0342   errorCode = 1;
0343   return gtAlgorithmName;
0344 }
0345 
0346 const std::string* L1GtTriggerMenuLite::gtTechTrigName(const unsigned int bitNumber, int& errorCode) const {
0347   const std::string* gtTechTrigName = nullptr;
0348 
0349   for (CItL1Trig itTrig = m_technicalTriggerMap.begin(); itTrig != m_technicalTriggerMap.end(); itTrig++) {
0350     if (itTrig->first == bitNumber) {
0351       gtTechTrigName = &(itTrig->second);
0352 
0353       errorCode = 0;
0354       return gtTechTrigName;
0355     }
0356   }
0357 
0358   errorCode = 1;
0359   return gtTechTrigName;
0360 }
0361 
0362 // get the bit number for a physics algorithm or a technical trigger
0363 // with a given name or alias
0364 const unsigned int L1GtTriggerMenuLite::gtBitNumber(const std::string& trigName, int& errorCode) const {
0365   unsigned int bitNr = 999;
0366 
0367   //
0368   for (CItL1Trig itTrig = m_algorithmAliasMap.begin(); itTrig != m_algorithmAliasMap.end(); itTrig++) {
0369     if (itTrig->second == trigName) {
0370       bitNr = itTrig->first;
0371 
0372       errorCode = 0;
0373       return bitNr;
0374     }
0375   }
0376 
0377   //
0378   for (CItL1Trig itTrig = m_algorithmMap.begin(); itTrig != m_algorithmMap.end(); itTrig++) {
0379     if (itTrig->second == trigName) {
0380       bitNr = itTrig->first;
0381       errorCode = 0;
0382       return bitNr;
0383     }
0384   }
0385 
0386   //
0387   for (CItL1Trig itTrig = m_technicalTriggerMap.begin(); itTrig != m_technicalTriggerMap.end(); itTrig++) {
0388     if (itTrig->second == trigName) {
0389       bitNr = itTrig->first;
0390       errorCode = 0;
0391       return bitNr;
0392     }
0393   }
0394 
0395   errorCode = 1;
0396   return bitNr;
0397 }
0398 
0399 // get the result for a physics algorithm or a technical trigger with name trigName
0400 // use directly the format of decisionWord (no typedef)
0401 const bool L1GtTriggerMenuLite::gtTriggerResult(const std::string& trigName,
0402                                                 const std::vector<bool>& decWord,
0403                                                 int& errorCode) const {
0404   bool trigResult = false;
0405 
0406   // try first physics algorithm aliases
0407 
0408   for (CItL1Trig itTrig = m_algorithmAliasMap.begin(); itTrig != m_algorithmAliasMap.end(); itTrig++) {
0409     if (itTrig->second == trigName) {
0410       unsigned int bitNumber = itTrig->first;
0411 
0412       if ((bitNumber >= decWord.size())) {
0413         trigResult = false;
0414         errorCode = 10;
0415       } else {
0416         trigResult = decWord[bitNumber];
0417         errorCode = 0;
0418       }
0419 
0420       return trigResult;
0421     }
0422   }
0423 
0424   // ... then physics algorithm names
0425 
0426   for (CItL1Trig itTrig = m_algorithmMap.begin(); itTrig != m_algorithmMap.end(); itTrig++) {
0427     if (itTrig->second == trigName) {
0428       unsigned int bitNumber = itTrig->first;
0429 
0430       if ((bitNumber >= decWord.size())) {
0431         trigResult = false;
0432         errorCode = 10;
0433       } else {
0434         trigResult = decWord[bitNumber];
0435         errorCode = 0;
0436       }
0437 
0438       return trigResult;
0439     }
0440   }
0441 
0442   // ... then technical trigger names
0443 
0444   for (CItL1Trig itTrig = m_technicalTriggerMap.begin(); itTrig != m_technicalTriggerMap.end(); itTrig++) {
0445     if (itTrig->second == trigName) {
0446       unsigned int bitNumber = itTrig->first;
0447 
0448       if ((bitNumber >= decWord.size())) {
0449         trigResult = false;
0450         errorCode = 10;
0451       } else {
0452         trigResult = decWord[bitNumber];
0453         errorCode = 0;
0454       }
0455 
0456       return trigResult;
0457     }
0458   }
0459 
0460   // algorithm or technical trigger not in the menu
0461 
0462   errorCode = 1;
0463   return false;
0464 }