Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:59

0001 #ifndef GlobalTrigger_L1GtConditionEvaluation_h
0002 #define GlobalTrigger_L1GtConditionEvaluation_h
0003 
0004 /**
0005  * \class L1GtConditionEvaluation
0006  *
0007  *
0008  * Description: Base class for evaluation of the L1 Global Trigger object
0009  * templates.
0010  *
0011  * Implementation:
0012  *    <TODO: enter implementation details>
0013  *
0014  * \author: Vasile Mihai Ghete   - HEPHY Vienna
0015  *
0016  *
0017  */
0018 
0019 // system include files
0020 #include <iostream>
0021 
0022 #include <string>
0023 #include <vector>
0024 
0025 // user include files
0026 
0027 //   base class
0028 
0029 //
0030 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapFwd.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include <cstdint>
0033 
0034 // forward declarations
0035 
0036 // class interface
0037 class L1GtConditionEvaluation {
0038 public:
0039   /// constructor
0040   L1GtConditionEvaluation() : m_condMaxNumberObjects(0), m_condLastResult(false), m_verbosity(0) {}
0041 
0042   /// destructor
0043   virtual ~L1GtConditionEvaluation() {}
0044 
0045 public:
0046   /// get / set the maximum number of objects received for the
0047   /// evaluation of the condition
0048   inline int condMaxNumberObjects() const { return m_condMaxNumberObjects; }
0049 
0050   inline void setCondMaxNumberObjects(int condMaxNumberObjectsValue) {
0051     m_condMaxNumberObjects = condMaxNumberObjectsValue;
0052   }
0053 
0054   /// get the latest result for the condition
0055   inline bool condLastResult() const { return m_condLastResult; }
0056 
0057   /// call evaluateCondition and save last result
0058   inline void evaluateConditionStoreResult() { m_condLastResult = evaluateCondition(); }
0059 
0060   /// the core function to check if the condition matches
0061   virtual const bool evaluateCondition() const = 0;
0062 
0063   /// get numeric expression
0064   virtual std::string getNumericExpression() const {
0065     if (m_condLastResult) {
0066       return "1";
0067     } else {
0068       return "0";
0069     }
0070   }
0071 
0072   /// get all the object combinations evaluated to true in the condition
0073   inline CombinationsInCond const &getCombinationsInCond() const { return m_combinationsInCond; }
0074 
0075   /// print condition
0076   virtual void print(std::ostream &myCout) const;
0077 
0078   inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; }
0079 
0080 protected:
0081   /// get all the object combinations (to fill it...)
0082   inline CombinationsInCond &combinationsInCond() const { return m_combinationsInCond; }
0083 
0084   /// check if a value is greater than a threshold or
0085   /// greater-or-equal depending on the value of the condGEqValue flag
0086   template <class Type1, class Type2>
0087   const bool checkThreshold(const Type1 &threshold, const Type2 &value, const bool condGEqValue) const;
0088 
0089   /// check if a bit with a given number is set in a mask
0090   template <class Type1>
0091   const bool checkBit(const Type1 &mask, const unsigned int bitNumber) const;
0092 
0093 protected:
0094   /// maximum number of objects received for the evaluation of the condition
0095   /// usually retrieved from event setup
0096   int m_condMaxNumberObjects;
0097 
0098   /// the last result of evaluateCondition()
0099   bool m_condLastResult;
0100 
0101   /// store all the object combinations evaluated to true in the condition
0102   mutable CombinationsInCond m_combinationsInCond;
0103 
0104   /// verbosity level
0105   int m_verbosity;
0106 };
0107 
0108 // define templated methods
0109 
0110 // check if a value is greater than a threshold or
0111 // greater-or-equal depending on the value of the condGEqValue flag
0112 template <class Type1, class Type2>
0113 const bool L1GtConditionEvaluation::checkThreshold(const Type1 &threshold,
0114                                                    const Type2 &value,
0115                                                    const bool condGEqValue) const {
0116   // if (value > 0) {
0117   //    LogTrace("L1GlobalTrigger") << "  threshold check for condGEqValue = "
0118   //        << condGEqValue << "\n    hex: " << std::hex << "threshold = " <<
0119   //        threshold
0120   //        << " value = " << value << "\n    dec: " << std::dec << "threshold =
0121   //        " << threshold
0122   //        << " value = " << value << std::endl;
0123   //}
0124 
0125   if (condGEqValue) {
0126     if (value >= threshold) {
0127       // LogTrace("L1GlobalTrigger") << "    condGEqValue: value >= threshold"
0128       //    << std::endl;
0129 
0130       return true;
0131     }
0132 
0133     return false;
0134 
0135   } else {
0136     if (value == threshold) {
0137       // LogTrace("L1GlobalTrigger") << "    condGEqValue: value = threshold"
0138       //    << std::endl;
0139 
0140       return true;
0141     }
0142 
0143     return false;
0144   }
0145 }
0146 
0147 // check if a bit with a given number is set in a mask
0148 template <class Type1>
0149 const bool L1GtConditionEvaluation::checkBit(const Type1 &mask, const unsigned int bitNumber) const {
0150   uint64_t oneBit = 1ULL;
0151 
0152   if (bitNumber >= (sizeof(oneBit) * 8)) {
0153     if (m_verbosity) {
0154       LogTrace("L1GlobalTrigger") << "    checkBit "
0155                                   << "\n     Bit number = " << bitNumber << " larger than maximum allowed "
0156                                   << sizeof(oneBit) * 8 << std::endl;
0157     }
0158 
0159     return false;
0160   }
0161 
0162   oneBit <<= bitNumber;
0163 
0164   // LogTrace("L1GlobalTrigger") << "    checkBit " << "\n     mask address = "
0165   // << &mask
0166   //    << std::dec << "\n     dec: " << "mask = " << mask << " oneBit = " <<
0167   //    oneBit
0168   //    << " bitNumber = " << bitNumber << std::hex << "\n     hex: " << "mask =
0169   //    " << mask
0170   //    << " oneBit = " << oneBit << " bitNumber = " << bitNumber << std::dec
0171   //    << "\n     mask & oneBit result = " << bool ( mask & oneBit ) <<
0172   //    std::endl;
0173 
0174   return (mask & oneBit);
0175 }
0176 
0177 #endif