CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/L1Trigger/GlobalTrigger/interface/L1GtConditionEvaluation.h

Go to the documentation of this file.
00001 #ifndef GlobalTrigger_L1GtConditionEvaluation_h
00002 #define GlobalTrigger_L1GtConditionEvaluation_h
00003 
00020 // system include files
00021 #include <iostream>
00022 
00023 #include <string>
00024 #include <vector>
00025 
00026 #include <boost/cstdint.hpp>
00027 
00028 // user include files
00029 
00030 //   base class
00031 
00032 //
00033 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapFwd.h"
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 
00036 // forward declarations
00037 
00038 // class interface
00039 class L1GtConditionEvaluation
00040 {
00041 
00042 public:
00043 
00045     L1GtConditionEvaluation()  :
00046     m_condMaxNumberObjects(0),
00047     m_condLastResult(false),
00048     m_verbosity(0) {}
00049 
00050 
00052   virtual ~L1GtConditionEvaluation(){}
00053 
00054 public:
00055 
00058     inline int condMaxNumberObjects() const {
00059         return m_condMaxNumberObjects;
00060     }
00061 
00062     inline void setCondMaxNumberObjects(int condMaxNumberObjectsValue) {
00063         m_condMaxNumberObjects = condMaxNumberObjectsValue;
00064     }
00065 
00067     inline bool condLastResult() const {
00068         return m_condLastResult;
00069     }
00070 
00072     inline void evaluateConditionStoreResult() {
00073         m_condLastResult = evaluateCondition();
00074     }
00075 
00077     virtual const bool evaluateCondition() const = 0;
00078 
00080     virtual std::string getNumericExpression() const {
00081         if (m_condLastResult) {
00082             return "1";
00083         }
00084         else {
00085             return "0";
00086         }
00087     }
00088 
00090     inline CombinationsInCond const & getCombinationsInCond() const {
00091         return m_combinationsInCond;
00092     }
00093 
00094 
00096     virtual void print(std::ostream& myCout) const;
00097 
00098     inline void setVerbosity(const int verbosity) {
00099         m_verbosity = verbosity;
00100     }
00101 
00102 protected:
00103 
00105     inline CombinationsInCond& combinationsInCond() const {
00106         return m_combinationsInCond;
00107     }
00108 
00111     template<class Type1, class Type2> const bool checkThreshold(const Type1& threshold,
00112         const Type2& value, const bool condGEqValue) const;
00113 
00115     template<class Type1> const bool checkBit(const Type1& mask, const unsigned int bitNumber) const;
00116 
00117 protected:
00118 
00121     int m_condMaxNumberObjects;
00122 
00124     bool m_condLastResult;
00125 
00127     mutable CombinationsInCond m_combinationsInCond;
00128 
00130     int m_verbosity;
00131 
00132 };
00133 
00134 // define templated methods
00135 
00136 // check if a value is greater than a threshold or
00137 // greater-or-equal depending on the value of the condGEqValue flag
00138 template<class Type1, class Type2> const bool L1GtConditionEvaluation::checkThreshold(
00139     const Type1& threshold, const Type2& value, const bool condGEqValue) const {
00140 
00141     //if (value > 0) {
00142     //    LogTrace("L1GlobalTrigger") << "  threshold check for condGEqValue = "
00143     //        << condGEqValue << "\n    hex: " << std::hex << "threshold = " << threshold
00144     //        << " value = " << value << "\n    dec: " << std::dec << "threshold = " << threshold
00145     //        << " value = " << value << std::endl;
00146     //}
00147 
00148     if (condGEqValue) {
00149         if (value >= threshold) {
00150 
00151             //LogTrace("L1GlobalTrigger") << "    condGEqValue: value >= threshold"
00152             //    << std::endl;
00153 
00154             return true;
00155         }
00156 
00157         return false;
00158 
00159     }
00160     else {
00161 
00162         if (value == threshold) {
00163 
00164             //LogTrace("L1GlobalTrigger") << "    condGEqValue: value = threshold"
00165             //    << std::endl;
00166 
00167             return true;
00168         }
00169 
00170         return false;
00171     }
00172 }
00173 
00174 // check if a bit with a given number is set in a mask
00175 template<class Type1> const bool L1GtConditionEvaluation::checkBit(const Type1& mask,
00176     const unsigned int bitNumber) const {
00177 
00178     boost::uint64_t oneBit = 1ULL;
00179 
00180     if (bitNumber >= (sizeof(oneBit)*8)) {
00181 
00182         if (m_verbosity) {
00183 
00184             LogTrace("L1GlobalTrigger")
00185                 << "    checkBit " << "\n     Bit number = "
00186                 << bitNumber << " larger than maximum allowed " << sizeof ( oneBit ) * 8
00187                 << std::endl;
00188         }
00189 
00190         return false;
00191     }
00192 
00193     oneBit <<= bitNumber;
00194 
00195     //LogTrace("L1GlobalTrigger") << "    checkBit " << "\n     mask address = " << &mask
00196     //    << std::dec << "\n     dec: " << "mask = " << mask << " oneBit = " << oneBit
00197     //    << " bitNumber = " << bitNumber << std::hex << "\n     hex: " << "mask = " << mask
00198     //    << " oneBit = " << oneBit << " bitNumber = " << bitNumber << std::dec
00199     //    << "\n     mask & oneBit result = " << bool ( mask & oneBit ) << std::endl;
00200 
00201     return (mask & oneBit);
00202 }
00203 
00204 #endif