Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_L1GlobalTrigger_L1GlobalTriggerObjectMaps_h
0002 #define DataFormats_L1GlobalTrigger_L1GlobalTriggerObjectMaps_h
0003 
0004 /**
0005  * \class L1GlobalTriggerObjectMaps
0006  * 
0007  * 
0008  * Description: map trigger objects to algorithms and conditions.  
0009  *
0010  * Implementation:
0011  *    <TODO: enter implementation details>
0012  *   
0013  * \author: Vasile Mihai Ghete - HEPHY Vienna
0014  * \author: W. David Dagenhart
0015  * 
0016  *
0017  */
0018 
0019 #include <vector>
0020 
0021 #include "DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h"
0022 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0023 
0024 class L1GlobalTriggerObjectMaps {
0025 public:
0026   L1GlobalTriggerObjectMaps() {}
0027 
0028   ~L1GlobalTriggerObjectMaps() {}
0029 
0030   void swap(L1GlobalTriggerObjectMaps& rh);
0031 
0032   /// Returns true if there is an entry for this algorithm bit number
0033   bool algorithmExists(int algorithmBitNumber) const;
0034 
0035   /// Returns whether an algorithm trigger passed or failed
0036   bool algorithmResult(int algorithmBitNumber) const;
0037 
0038   /// Update the condition result in the operandTokenVector.
0039   void updateOperandTokenVector(int algorithmBitNumber,
0040                                 std::vector<L1GtLogicParser::OperandToken>& operandTokenVector) const;
0041 
0042   /// Fills the vector with all the algorithm bit numbers
0043   void getAlgorithmBitNumbers(std::vector<int>& algorithmBitNumbers) const;
0044 
0045   /// Number of conditions associated with an algorithm
0046   unsigned getNumberOfConditions(int algorithmBitNumber) const;
0047 
0048   class ConditionsInAlgorithm;
0049   class CombinationsInCondition;
0050 
0051   /// Return an object which has a function that returns the
0052   /// results of the conditions associated with an algorithm.
0053   ConditionsInAlgorithm getConditionsInAlgorithm(int algorithmBitNumber) const;
0054 
0055   /// Each condition can be satisfied by multiple combinations of L1
0056   /// objects.  The number, order, and type of objects associated with each
0057   /// condition is defined in the L1 Trigger Menu. The following function
0058   /// returns an object which has a function that returns the index into the
0059   /// L1 Object Collections of each object in each combination.
0060   CombinationsInCondition getCombinationsInCondition(int algorithmBitNumber, unsigned conditionNumber) const;
0061 
0062   /// Returns the ID of the ParameterSet containing the algorithm names
0063   /// and condition names.
0064   edm::ParameterSetID const& namesParameterSetID() const { return m_namesParameterSetID; }
0065 
0066   // the rest are methods used to fill the data
0067   // and should only be used by the producer that
0068   // creates these and puts them into the event.
0069   // There are requirements on ordering and the
0070   // stored indexes that the code that calls these
0071   // functions is expected to carefully take care of.
0072 
0073   void reserveForAlgorithms(unsigned n);
0074   void pushBackAlgorithm(unsigned startIndexOfConditions, int algorithmBitNumber, bool algorithmResult);
0075 
0076   // This function should be called after filling the data in this object
0077   // using the pushBack* methods.
0078   void consistencyCheck() const;
0079 
0080   void reserveForConditions(unsigned n);
0081   void pushBackCondition(unsigned startIndexOfCombinations,
0082                          unsigned short nObjectsPerCombination,
0083                          bool conditionResult);
0084 
0085   void reserveForObjectIndexes(unsigned n);
0086   void pushBackObjectIndex(unsigned char objectIndex);
0087 
0088   void setNamesParameterSetID(edm::ParameterSetID const& psetID);
0089 
0090   class AlgorithmResult {
0091   public:
0092     AlgorithmResult();
0093     AlgorithmResult(unsigned startIndexOfConditions, int algorithmBitNumber, bool algorithmResult);
0094     unsigned startIndexOfConditions() const { return m_startIndexOfConditions; }
0095     short algorithmBitNumber() const { return m_algorithmBitNumber; }
0096     bool algorithmResult() const { return m_algorithmResult; }
0097     // The operator is used for searching in the std::vector<AlgorithmResult>
0098     bool operator<(AlgorithmResult const& right) const { return m_algorithmBitNumber < right.algorithmBitNumber(); }
0099 
0100   private:
0101     unsigned m_startIndexOfConditions;
0102     short m_algorithmBitNumber;
0103     bool m_algorithmResult;
0104   };
0105 
0106   class ConditionResult {
0107   public:
0108     ConditionResult();
0109     ConditionResult(unsigned startIndexOfCombinations, unsigned short nObjectsPerCombination, bool conditionResult);
0110     unsigned startIndexOfCombinations() const { return m_startIndexOfCombinations; }
0111     unsigned short nObjectsPerCombination() const { return m_nObjectsPerCombination; }
0112     bool conditionResult() const { return m_conditionResult; }
0113 
0114   private:
0115     unsigned m_startIndexOfCombinations;
0116     unsigned short m_nObjectsPerCombination;
0117     bool m_conditionResult;
0118   };
0119 
0120   class ConditionsInAlgorithm {
0121   public:
0122     ConditionsInAlgorithm(ConditionResult const* conditionResults, unsigned nConditions);
0123     unsigned nConditions() const { return m_nConditions; }
0124     bool getConditionResult(unsigned condition) const;
0125 
0126   private:
0127     ConditionResult const* m_conditionResults;
0128     unsigned m_nConditions;
0129   };
0130 
0131   class CombinationsInCondition {
0132   public:
0133     CombinationsInCondition(unsigned char const* startOfObjectIndexes,
0134                             unsigned nCombinations,
0135                             unsigned short nObjectsPerCombination);
0136 
0137     unsigned nCombinations() const { return m_nCombinations; }
0138     unsigned short nObjectsPerCombination() const { return m_nObjectsPerCombination; }
0139     unsigned char getObjectIndex(unsigned combination, unsigned object) const;
0140 
0141   private:
0142     unsigned char const* m_startOfObjectIndexes;
0143     unsigned m_nCombinations;
0144     unsigned short m_nObjectsPerCombination;
0145   };
0146 
0147 private:
0148   void getStartEndIndex(int algorithmBitNumber, unsigned& startIndex, unsigned& endIndex) const;
0149 
0150   // data members
0151   // The vectors are sorted. All three vectors are in algorithmBitNumber
0152   // order. The second two vectors are sorted such that within an algorithm
0153   // the conditions appear in the same order as in the algorithm logical
0154   // expression. And the third is additionally sorted so each combination
0155   // is contiguous and within a combination the order is the same as the
0156   // type specification in the L1 Trigger Menu.
0157   std::vector<AlgorithmResult> m_algorithmResults;
0158   std::vector<ConditionResult> m_conditionResults;
0159   std::vector<unsigned char> m_combinations;
0160   edm::ParameterSetID m_namesParameterSetID;
0161 };
0162 
0163 inline void swap(L1GlobalTriggerObjectMaps& lh, L1GlobalTriggerObjectMaps& rh) { lh.swap(rh); }
0164 
0165 #endif