CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMaps.h

Go to the documentation of this file.
00001 #ifndef DataFormats_L1GlobalTrigger_L1GlobalTriggerObjectMaps_h
00002 #define DataFormats_L1GlobalTrigger_L1GlobalTriggerObjectMaps_h
00003 
00021 #include <vector>
00022 
00023 #include "DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h"
00024 #include "DataFormats/Provenance/interface/ParameterSetID.h"
00025 
00026 class L1GlobalTriggerObjectMaps
00027 {
00028 
00029 public:
00030 
00031   L1GlobalTriggerObjectMaps() {}
00032 
00033   ~L1GlobalTriggerObjectMaps() {}
00034 
00035   void swap(L1GlobalTriggerObjectMaps& rh);
00036 
00038   bool algorithmExists(int algorithmBitNumber) const;
00039 
00041   bool algorithmResult(int algorithmBitNumber) const;
00042 
00044   void updateOperandTokenVector(int algorithmBitNumber,
00045                                 std::vector<L1GtLogicParser::OperandToken>& operandTokenVector) const;
00046 
00048   void getAlgorithmBitNumbers(std::vector<int>& algorithmBitNumbers) const;
00049 
00051   unsigned getNumberOfConditions(int algorithmBitNumber) const;
00052 
00053   class ConditionsInAlgorithm;
00054   class CombinationsInCondition;
00055 
00058   ConditionsInAlgorithm getConditionsInAlgorithm(int algorithmBitNumber) const;
00059 
00065   CombinationsInCondition getCombinationsInCondition(int algorithmBitNumber,
00066                                                      unsigned conditionNumber) const;
00067 
00070   edm::ParameterSetID const& namesParameterSetID() const { return m_namesParameterSetID; }
00071 
00072   // the rest are methods used to fill the data
00073   // and should only be used by the producer that
00074   // creates these and puts them into the event.
00075   // There are requirements on ordering and the
00076   // stored indexes that the code that calls these
00077   // functions is expected to carefully take care of.
00078 
00079   void reserveForAlgorithms(unsigned n);
00080   void pushBackAlgorithm(unsigned startIndexOfConditions,
00081                          int algorithmBitNumber,
00082                          bool algorithmResult);
00083 
00084   // This function should be called after filling the data in this object
00085   // using the pushBack* methods.
00086   void consistencyCheck() const;
00087 
00088   void reserveForConditions(unsigned n);
00089   void pushBackCondition(unsigned startIndexOfCombinations,
00090                          unsigned short nObjectsPerCombination,
00091                          bool conditionResult);
00092 
00093   void reserveForObjectIndexes(unsigned n);
00094   void pushBackObjectIndex(unsigned char objectIndex);
00095 
00096   void setNamesParameterSetID(edm::ParameterSetID const& psetID);
00097 
00098   class AlgorithmResult {
00099   public:
00100     AlgorithmResult();
00101     AlgorithmResult(unsigned startIndexOfConditions,
00102                     int algorithmBitNumber,
00103                     bool algorithmResult);
00104     unsigned startIndexOfConditions() const { return m_startIndexOfConditions; }
00105     short algorithmBitNumber() const { return m_algorithmBitNumber; }
00106     bool algorithmResult() const { return m_algorithmResult; }
00107     // The operator is used for searching in the std::vector<AlgorithmResult>
00108     bool operator<(AlgorithmResult const& right) const {
00109       return m_algorithmBitNumber < right.algorithmBitNumber();
00110     }
00111   private:
00112     unsigned m_startIndexOfConditions;
00113     short m_algorithmBitNumber;
00114     bool m_algorithmResult;
00115   };
00116 
00117   class ConditionResult {
00118   public:
00119     ConditionResult();
00120     ConditionResult(unsigned startIndexOfCombinations,
00121                     unsigned short nObjectsPerCombination,
00122                     bool conditionResult);
00123     unsigned startIndexOfCombinations() const { return m_startIndexOfCombinations; }
00124     unsigned short nObjectsPerCombination() const { return m_nObjectsPerCombination; }
00125     bool conditionResult() const { return m_conditionResult; }
00126   private:
00127     unsigned m_startIndexOfCombinations;
00128     unsigned short m_nObjectsPerCombination;
00129     bool m_conditionResult;
00130   };
00131 
00132   class ConditionsInAlgorithm {
00133   public:
00134     ConditionsInAlgorithm(ConditionResult const* conditionResults,
00135                           unsigned nConditions);
00136     unsigned nConditions() const { return m_nConditions; }
00137     bool getConditionResult(unsigned condition) const;
00138 
00139   private:
00140     ConditionResult const* m_conditionResults;
00141     unsigned m_nConditions;
00142   };
00143 
00144   class CombinationsInCondition {
00145   public:
00146     CombinationsInCondition(unsigned char const* startOfObjectIndexes,
00147                             unsigned nCombinations,
00148                             unsigned short nObjectsPerCombination);
00149 
00150     unsigned nCombinations() const { return m_nCombinations; }
00151     unsigned short nObjectsPerCombination() const { return m_nObjectsPerCombination; }
00152     unsigned char getObjectIndex(unsigned combination,
00153                                  unsigned object) const;
00154   private:
00155     unsigned char const* m_startOfObjectIndexes;
00156     unsigned m_nCombinations;
00157     unsigned short m_nObjectsPerCombination;
00158   };
00159 
00160 private:
00161 
00162   void getStartEndIndex(int algorithmBitNumber, unsigned& startIndex, unsigned& endIndex) const;
00163 
00164   // data members
00165   // The vectors are sorted. All three vectors are in algorithmBitNumber
00166   // order. The second two vectors are sorted such that within an algorithm
00167   // the conditions appear in the same order as in the algorithm logical
00168   // expression. And the third is additionally sorted so each combination
00169   // is contiguous and within a combination the order is the same as the
00170   // type specification in the L1 Trigger Menu.
00171   std::vector<AlgorithmResult> m_algorithmResults;
00172   std::vector<ConditionResult> m_conditionResults;
00173   std::vector<unsigned char> m_combinations;
00174   edm::ParameterSetID m_namesParameterSetID;
00175 };
00176 
00177 inline void swap(L1GlobalTriggerObjectMaps& lh, L1GlobalTriggerObjectMaps& rh) {
00178   lh.swap(rh);
00179 }
00180 
00181 #endif