CMS 3D CMS Logo

L1TGlobalUtil.h
Go to the documentation of this file.
1 // L1TGlobalUtil: Utility class for parsing the L1 Trigger Menu
2 
3 #ifndef L1TGlobal_L1TGlobalUtil_h
4 #define L1TGlobal_L1TGlobalUtil_h
5 
6 // system include files
7 #include <memory>
8 #include <string_view>
9 
10 #include <vector>
11 
14 
17 
18 // Objects to produce for the output record.
22 
27 
29 
31 
33 
34 // forward declarations
35 
36 // class declaration
37 
38 namespace l1t {
39 
40  // Use this to tell the EventSetup whether it should prefetch
41  // data when processing beginRun or an Event or both. (This
42  // depends on when retrieveL1 and retrieveL1Setup are called)
44 
45  class L1TGlobalUtil {
46  public:
47  // Using this constructor will require InputTags to be specified in the configuration
51 
55 
56  // Using this constructor will cause it to look for valid InputTags in
57  // the following ways in the specified order until they are found.
58  // 1. The configuration
59  // 2. Search all products from the preferred input tags for the required type
60  // 3. Search all products from any other process for the required type
61  template <typename T>
64  T& module,
66 
67  template <typename T>
70  T& module,
72 
73  // Using this constructor will cause it to look for valid InputTags in
74  // the following ways in the specified order until they are found.
75  // 1. The constructor arguments
76  // 2. The configuration
77  // 3. Search all products from the preferred input tags for the required type
78  // 4. Search all products from any other process for the required type
79  template <typename T>
82  T& module,
86 
87  template <typename T>
90  T& module,
94 
96  virtual ~L1TGlobalUtil();
97 
99  bool valid() const;
100 
102  edm::InputTag const& iAlg,
103  edm::InputTag const& iExt,
104  bool readPrescalesFromFile) {
105  L1TGlobalUtilHelper::fillDescription(desc, iAlg, iExt, readPrescalesFromFile);
106  }
107 
108  // OverridePrescalesAndMasks
109  // The ability to override the prescale/mask file will not be part of the permanent interface of this class.
110  // It is provided only until prescales and masks are available as CondFormats...
111  // Most users should simply ignore this method and use the default ctor only!
112  // Will look for prescale csv file in L1Trigger/L1TGlobal/data/Luminosity/startup/<filename>
113  void OverridePrescalesAndMasks(std::string filename, unsigned int psColumn = 1.);
114 
116  void retrieveL1(const edm::Event& iEvent, const edm::EventSetup& evSetup); // using helper
117  void retrieveL1(const edm::Event& iEvent, const edm::EventSetup& evSetup, edm::EDGetToken gtAlgToken);
118  void retrieveL1Setup(const edm::EventSetup& evSetup); // Use this one only during beginRun
119  void retrieveL1Event(const edm::Event& iEvent, const edm::EventSetup& evSetup); // using helper
120  void retrieveL1Event(const edm::Event& iEvent, const edm::EventSetup& evSetup, edm::EDGetToken gtAlgToken);
121 
122  inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; }
123 
124  inline bool getFinalOR() const { return m_finalOR; }
125 
126  // get the trigger bit from the name
127  const bool getAlgBitFromName(const std::string& AlgName, int& bit) const;
128 
129  // get the name from the trigger bit
130  const bool getAlgNameFromBit(int& bit, std::string_view& AlgName) const;
131 
132  // Access results for particular trigger bit
133  const bool getInitialDecisionByBit(int& bit, bool& decision) const;
134  const bool getIntermDecisionByBit(int& bit, bool& decision) const;
135  const bool getFinalDecisionByBit(int& bit, bool& decision) const;
136 
137  // Access Prescale
138  const bool getPrescaleByBit(int& bit, double& prescale) const;
139 
140  // Access Masks:
141  // follows logic of uGT board:
142  // finalDecision[AlgBit]
143  // Final word is after application of prescales.
144  // A prescale = 0 effectively masks out the algorithm in the final decision word
145  //
146  const bool getMaskByBit(int& bit, std::vector<int>& mask) const;
147 
148  // Access results for particular trigger name
149  const bool getInitialDecisionByName(const std::string& algName, bool& decision) const;
150  const bool getIntermDecisionByName(const std::string& algName, bool& decision) const;
151  const bool getFinalDecisionByName(const std::string& algName, bool& decision) const;
152 
153  // Access Prescales
154  const bool getPrescaleByName(const std::string& algName, double& prescale) const;
155 
156  // Access Masks (see note) above
157  const bool getMaskByName(const std::string& algName, std::vector<int>& mask) const;
158 
159  // Some inline commands to return the full vectors
160  inline const std::vector<std::pair<std::string_view, bool>>& decisionsInitial() { return m_decisionsInitial; }
161  inline const std::vector<std::pair<std::string_view, bool>>& decisionsInterm() { return m_decisionsInterm; }
162  inline const std::vector<std::pair<std::string_view, bool>>& decisionsFinal() { return m_decisionsFinal; }
163 
164  // Access all prescales
165  inline const std::vector<std::pair<std::string_view, double>>& prescales() { return m_prescales; }
166 
167  // Access Masks (see note) above
168  inline const std::vector<std::pair<std::string_view, std::vector<int>>>& masks() { return m_masks; }
169 
170  // Menu names
171  inline const std::string& gtTriggerMenuName() const { return m_l1GtMenu->getName(); }
172  inline const std::string& gtTriggerMenuVersion() const { return m_l1GtMenu->getVersion(); }
173  inline const std::string& gtTriggerMenuComment() const { return m_l1GtMenu->getComment(); }
174 
175  // Prescale Column
176  inline unsigned int prescaleColumn() const { return m_PreScaleColumn; }
177  inline unsigned int numberOfPreScaleColumns() const { return m_numberOfPreScaleColumns; }
178 
179  private:
180  L1TGlobalUtil();
181 
182  void retrieveL1Setup(const edm::EventSetup& evSetup, bool isRun);
183  void eventSetupConsumes(edm::ConsumesCollector& iC, UseEventSetupIn useEventSetupIn);
184 
186  void resetDecisionVectors();
187  void resetPrescaleVectors();
188  void resetMaskVectors();
189  void loadPrescalesAndMasks();
190 
191  // trigger menu
193  unsigned long long m_l1GtMenuCacheID;
194 
195  // prescale factors
198  unsigned long long m_l1GtPfAlgoCacheID;
199 
200  // prescales and masks
202 
203  // algorithm maps
204  //const AlgorithmMap* m_algorithmMap;
205  const std::map<std::string, L1TUtmAlgorithm>* m_algorithmMap;
206 
207  // Number of physics triggers
208  unsigned int m_numberPhysTriggers;
209  const unsigned int m_maxNumberPhysTriggers = 512;
210 
211  //file and container for prescale factors
213  unsigned int m_PreScaleColumn;
215 
216  std::vector<std::vector<double>> m_initialPrescaleFactorsAlgoTrig;
217  const std::vector<std::vector<double>>* m_prescaleFactorsAlgoTrig;
218  const std::map<int, std::vector<int>> m_initialTriggerMaskAlgoTrig;
219  const std::map<int, std::vector<int>>* m_triggerMaskAlgoTrig; // vector stores the BX
220 
221  // access to the results block from uGT
223 
224  // final OR
225  bool m_finalOR;
226 
227  // Vectors containing the trigger name and information about that trigger
228  std::vector<std::pair<std::string_view, bool>> m_decisionsInitial;
229  std::vector<std::pair<std::string_view, bool>> m_decisionsInterm;
230  std::vector<std::pair<std::string_view, bool>> m_decisionsFinal;
231  std::vector<std::pair<std::string_view, double>> m_prescales;
232  std::vector<std::pair<std::string_view, std::vector<int>>>
233  m_masks; // vector stores the bx's that are mask for given algo
234 
237 
238  std::unique_ptr<L1TGlobalUtilHelper> m_l1tGlobalUtilHelper;
239 
243 
247  };
248 
249  template <typename T>
252  T& module,
253  UseEventSetupIn useEventSetupIn)
254  : L1TGlobalUtil(pset, iC, module, useEventSetupIn) {}
255 
256  template <typename T>
259  T& module,
260  UseEventSetupIn useEventSetupIn)
261  : L1TGlobalUtil() {
262  m_l1tGlobalUtilHelper = std::make_unique<L1TGlobalUtilHelper>(pset, iC, module);
263  m_readPrescalesFromFile = m_l1tGlobalUtilHelper->readPrescalesFromFile();
264  eventSetupConsumes(iC, useEventSetupIn);
265  }
266 
267  template <typename T>
270  T& module,
273  UseEventSetupIn useEventSetupIn)
274  : L1TGlobalUtil(pset, iC, module, l1tAlgBlkInputTag, l1tExtBlkInputTag, useEventSetupIn) {}
275 
276  template <typename T>
279  T& module,
282  UseEventSetupIn useEventSetupIn)
283  : L1TGlobalUtil() {
285  std::make_unique<L1TGlobalUtilHelper>(pset, iC, module, l1tAlgBlkInputTag, l1tExtBlkInputTag);
286  m_readPrescalesFromFile = m_l1tGlobalUtilHelper->readPrescalesFromFile();
287  eventSetupConsumes(iC, useEventSetupIn);
288  }
289 } // namespace l1t
290 #endif
void setVerbosity(const int verbosity)
std::vector< std::pair< std::string_view, double > > m_prescales
const std::string & getName() const
bool getFinalOR() const
const L1TUtmTriggerMenu * m_l1GtMenu
edm::ESGetToken< L1TGlobalPrescalesVetosFract, L1TGlobalPrescalesVetosFractRcd > m_L1TGlobalPrescalesVetosFractRunToken
const std::string & getComment() const
std::string m_preScaleFileName
const bool getInitialDecisionByBit(int &bit, bool &decision) const
std::vector< std::pair< std::string_view, bool > > m_decisionsInterm
unsigned int prescaleColumn() const
const bool getMaskByName(const std::string &algName, std::vector< int > &mask) const
void retrieveL1Event(const edm::Event &iEvent, const edm::EventSetup &evSetup)
edm::ESGetToken< L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd > m_L1TUtmTriggerMenuRunToken
const bool getAlgBitFromName(const std::string &AlgName, int &bit) const
unsigned long long m_l1GtPfAlgoCacheID
void OverridePrescalesAndMasks(std::string filename, unsigned int psColumn=1.)
const std::vector< std::pair< std::string_view, bool > > & decisionsInitial()
unsigned int m_numberOfPreScaleColumns
const std::vector< std::pair< std::string_view, std::vector< int > > > & masks()
unsigned int m_PreScaleColumn
delete x;
Definition: CaloConfig.h:22
const std::string & gtTriggerMenuName() const
const l1t::PrescalesVetosFractHelper * m_l1GtPrescalesVetoes
std::unique_ptr< L1TGlobalUtilHelper > m_l1tGlobalUtilHelper
void resetDecisionVectors()
clear decision vectors on a menu change
std::vector< std::vector< double > > m_initialPrescaleFactorsAlgoTrig
const std::string & gtTriggerMenuComment() const
unsigned int numberOfPreScaleColumns() const
const bool getIntermDecisionByBit(int &bit, bool &decision) const
const std::map< std::string, L1TUtmAlgorithm > * m_algorithmMap
const std::map< int, std::vector< int > > m_initialTriggerMaskAlgoTrig
std::vector< std::pair< std::string_view, bool > > m_decisionsInitial
int iEvent
Definition: GenABIO.cc:224
const std::map< int, std::vector< int > > * m_triggerMaskAlgoTrig
static void fillDescription(edm::ParameterSetDescription &desc, edm::InputTag const &iAlg, edm::InputTag const &iExt, bool readPrescalesFromFile)
std::vector< std::pair< std::string_view, std::vector< int > > > m_masks
void eventSetupConsumes(edm::ConsumesCollector &iC, UseEventSetupIn useEventSetupIn)
edm::ESGetToken< L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd > m_L1TUtmTriggerMenuEventToken
const bool getFinalDecisionByBit(int &bit, bool &decision) const
const bool getInitialDecisionByName(const std::string &algName, bool &decision) const
const std::vector< std::vector< double > > * m_prescaleFactorsAlgoTrig
const std::string & gtTriggerMenuVersion() const
static void fillDescription(edm::ParameterSetDescription &desc, edm::InputTag const &iAlg, edm::InputTag const &iExt, bool readPrescalesFromFile)
const std::vector< std::pair< std::string_view, bool > > & decisionsInterm()
const int verbosity
const bool getPrescaleByName(const std::string &algName, double &prescale) const
int m_verbosity
verbosity level
unsigned long long m_l1GtMenuCacheID
bool valid() const
check that the L1TGlobalUtil has been properly initialised
const bool getIntermDecisionByName(const std::string &algName, bool &decision) const
const std::vector< std::pair< std::string_view, double > > & prescales()
const bool getAlgNameFromBit(int &bit, std::string_view &AlgName) const
const bool getPrescaleByBit(int &bit, double &prescale) const
edm::Handle< BXVector< GlobalAlgBlk > > m_uGtAlgBlk
const std::string & getVersion() const
const bool getFinalDecisionByName(const std::string &algName, bool &decision) const
const bool getMaskByBit(int &bit, std::vector< int > &mask) const
UseEventSetupIn
Definition: L1TGlobalUtil.h:43
const unsigned int m_maxNumberPhysTriggers
long double T
virtual ~L1TGlobalUtil()
destructor
void retrieveL1Setup(const edm::EventSetup &evSetup)
unsigned int m_numberPhysTriggers
void retrieveL1(const edm::Event &iEvent, const edm::EventSetup &evSetup)
initialize the class (mainly reserve)
edm::ESGetToken< L1TGlobalPrescalesVetosFract, L1TGlobalPrescalesVetosFractRcd > m_L1TGlobalPrescalesVetosFractEventToken
std::vector< std::pair< std::string_view, bool > > m_decisionsFinal
const std::vector< std::pair< std::string_view, bool > > & decisionsFinal()