ATLAS Offline Software
TrigPassFlags.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #pragma once
6 #ifndef TrigSteeringEvent_TrigPassFlags_h
7 #define TrigSteeringEvent_TrigPassFlags_h
8 
9 #include <vector>
10 #include <algorithm>
11 #include <stdexcept>
12 
13 #include "xAODCore/CLASS_DEF.h"
14 // TrigPassFlagsCollection is included at the end (required by Trigger EDM schema)
15 
30 public:
31  TrigPassFlags();
39  TrigPassFlags(const unsigned int size, const unsigned int flagSize, const void *cont=0);
40 
48  void setFlagBit(const unsigned int position, const unsigned int bitPosition, const bool bitValue, const void *cont=0 );
49 
56  void setFlag(const unsigned int position, const std::vector<bool>& flag, const void *cont=0 );
57 
62  bool getFlagBit(const unsigned int position, const unsigned int bitPosition) const;
63 
68  const std::vector<bool>& getFlag(const unsigned int position) const;
69 
73  unsigned int size() const { return m_flagsPerObject.size(); }
74 
78  unsigned int flagSize() const { return m_flagsPerObject[0].size(); }
79 
80 private:
81  friend class TrigPassFlagsCnv_p1;
82 
83  const void *m_container_ptr;
84  std::vector<std::vector<bool> > m_flagsPerObject;
85 };
86 
87 CLASS_DEF( TrigPassFlags , 74395451 , 1 )
88 
89 
90 
94 namespace HLT {
95  template<class CONTAINER>
96  TrigPassFlags* makeTrigPassFlags(const CONTAINER* cont,const unsigned int flagSize) {
97  return new TrigPassFlags(cont->size(), flagSize, (const void*)cont );
98  }
99 
104  template<class T, class CONTAINER>
105  void setFlagBit(TrigPassFlags * flags, const T* obj, const CONTAINER* container, const unsigned int bitPosition, const bool bitValue = true) {
106  typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
107  if ( i != container->end() )
108  flags->setFlagBit(i-container->begin(), bitPosition, bitValue, container);
109  else
110  throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
111  }
112 
113 
120  template<class T, class CONTAINER>
121  void setFlag(TrigPassFlags * flags, const T* obj, const CONTAINER* container, const std::vector<bool>& flag) {
122  typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
123  if ( i != container->end() )
124  flags->setFlag(i-container->begin(), flag, container);
125  else
126  throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
127  }
128 
129 
133  template<class T, class CONTAINER>
134  bool getFlagBit(const TrigPassFlags *flags,const T* obj, const CONTAINER* container, const unsigned int position, const unsigned int bitPosition) {
135  typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
136  if ( i != container->end() )
137  return flags->getFlagBit(i-container->begin(),position, bitPosition);
138  throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
139  }
140 
144  template<class T, class CONTAINER>
145  const std::vector<bool>& getFlag(const TrigPassFlags *flags,const T* obj, const CONTAINER* container, const size_t position) {
146  typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
147  if ( i != container->end() )
148  return flags->getFlag(i-container->begin(),position);
149  throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
150  }
151 
152  template<typename T>
153  std::vector<bool> AsFlag(T flag_t, const size_t size) { // T should be an unsigned type, otherwise this will give a compilation warning
154  if(size>8*sizeof(T)) // check of T has at list 'size' bits
155  throw std::runtime_error("AsFlag(): type T has less bits than required by 'size'");
156  if(flag_t >= ( ((unsigned long long)1)<<size) ) // check of T has at least 'size' bits (with 'size' bits '1<<size' is the lowest number I can not represent.)
157  throw std::runtime_error("AsFlag(): the flag is larger then bits available");
158 
159 
160  std::vector<bool> flag(size);
161  int mask = 0x01;
162  for(size_t idx=0; idx<size; ++idx, mask<<=1)
163  flag[idx] = (flag_t&mask)!=0;
164  return flag;
165  }
166 
167  template<typename T>
168  T FlagAs(const std::vector<bool>& flag) {
169  if(8*sizeof(T)<flag.size()) // check of T has enough bits to represent flag
170  throw std::runtime_error("FlagAs(): the flag size does not fit into the requested type");
171  T v = 0;
172  int mask = 0x01;
173  for(size_t idx=0; idx<flag.size(); ++idx, mask<<=1)
174  if(flag[idx]) v += mask;
175  return v;
176  }
177 
178 } // eof HLT namespace
179 
181 
182 #endif // TrigSteeringEvent_TrigPassFlags_h
183 
184 
185 
186 
TrigPassFlags::setFlagBit
void setFlagBit(const unsigned int position, const unsigned int bitPosition, const bool bitValue, const void *cont=0)
Set bit of the flag at index position.
Definition: TrigPassFlags.cxx:18
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
HLT::makeTrigPassFlags
TrigPassFlags * makeTrigPassFlags(const CONTAINER *cont, const unsigned int flagSize)
Definition: TrigPassFlags.h:96
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
HLT::FlagAs
T FlagAs(const std::vector< bool > &flag)
Definition: TrigPassFlags.h:168
TrigPassFlags::size
unsigned int size() const
gets size of the container object vector
Definition: TrigPassFlags.h:73
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
TrigPassFlags::setFlag
void setFlag(const unsigned int position, const std::vector< bool > &flag, const void *cont=0)
Set the flag at index position.
Definition: TrigPassFlags.cxx:31
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
HLT::getFlagBit
bool getFlagBit(const TrigPassFlags *flags, const T *obj, const CONTAINER *container, const unsigned int position, const unsigned int bitPosition)
Returns the bit 'bitPosition' of the flag at index position.
Definition: TrigPassFlags.h:134
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
lumiFormat.i
int i
Definition: lumiFormat.py:85
master.flag
bool flag
Definition: master.py:29
HLT::setFlag
void setFlag(TrigPassFlags *flags, const T *obj, const CONTAINER *container, const std::vector< bool > &flag)
Set the flag at index position.
Definition: TrigPassFlags.h:121
TrigPassFlags::flagSize
unsigned int flagSize() const
gets size of the flag vector for the object at index
Definition: TrigPassFlags.h:78
HLT::setFlagBit
void setFlagBit(TrigPassFlags *flags, const T *obj, const CONTAINER *container, const unsigned int bitPosition, const bool bitValue=true)
Set bit of the flag at index position for a given TrigPassFlags object.
Definition: TrigPassFlags.h:105
HLT::AsFlag
std::vector< bool > AsFlag(T flag_t, const size_t size)
Definition: TrigPassFlags.h:153
CLASS_DEF.h
File providing the different SG_BASE macros.
python.PyAthena.v
v
Definition: PyAthena.py:154
TrigPassFlagsCollection.h
HLT::getFlag
const std::vector< bool > & getFlag(const TrigPassFlags *flags, const T *obj, const CONTAINER *container, const size_t position)
Returns the flag at index position.
Definition: TrigPassFlags.h:145
CLASS_DEF
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Definition: Control/AthenaKernel/AthenaKernel/CLASS_DEF.h:64
TrigPassFlags
A Flag is an ordered collection of bits (vector<bool>) that can hold additional (boolean) information...
Definition: TrigPassFlags.h:29
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
TrigPassFlags::getFlag
const std::vector< bool > & getFlag(const unsigned int position) const
Returns the flag (vector<bool>) at index position.
Definition: TrigPassFlags.cxx:54
TrigPassFlagsCnv_p1
Definition: TrigPassFlagsCnv_p1.h:28
python.PyAthena.obj
obj
Definition: PyAthena.py:132
TrigPassFlags::TrigPassFlags
TrigPassFlags()
Definition: TrigPassFlags.cxx:8
TrigPassFlags::m_container_ptr
const void * m_container_ptr
Definition: TrigPassFlags.h:83
TrigPassFlags::m_flagsPerObject
std::vector< std::vector< bool > > m_flagsPerObject
list of trainsient n-bit value (STL docu assures that a vector of booleans is efficient)
Definition: TrigPassFlags.h:84
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
TrigPassFlags::getFlagBit
bool getFlagBit(const unsigned int position, const unsigned int bitPosition) const
Returns the bit 'bitPosition' of the flag at index position.
Definition: TrigPassFlags.cxx:44