ATLAS Offline Software
Loading...
Searching...
No Matches
TrigPassFlags.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIGSTEERINGEVENT_TRIGPASSFLAGS_H
6#define TRIGSTEERINGEVENT_TRIGPASSFLAGS_H
7
8#include <vector>
9#include <algorithm>
10#include <stdexcept>
11
12#include "xAODCore/CLASS_DEF.h"
13
28public:
37 TrigPassFlags(const unsigned int size, const unsigned int flagSize, const void *cont=0);
38
46 void setFlagBit(const unsigned int position, const unsigned int bitPosition, const bool bitValue, const void *cont=0 );
47
54 void setFlag(const unsigned int position, const std::vector<bool>& flag, const void *cont=0 );
55
60 bool getFlagBit(const unsigned int position, const unsigned int bitPosition) const;
61
66 const std::vector<bool>& getFlag(const unsigned int position) const;
67
71 unsigned int size() const { return m_flagsPerObject.size(); }
72
76 unsigned int flagSize() const { return m_flagsPerObject[0].size(); }
77
78private:
79 friend class TrigPassFlagsCnv_p1;
80
81 const void *m_container_ptr;
82 std::vector<std::vector<bool> > m_flagsPerObject;
83};
84
85CLASS_DEF( TrigPassFlags , 74395451 , 1 )
86
87
88
92namespace HLT {
93 template<class CONTAINER>
94 TrigPassFlags* makeTrigPassFlags(const CONTAINER* cont,const unsigned int flagSize) {
95 return new TrigPassFlags(cont->size(), flagSize, (const void*)cont );
96 }
97
102 template<class T, class CONTAINER>
103 void setFlagBit(TrigPassFlags * flags, const T* obj, const CONTAINER* container, const unsigned int bitPosition, const bool bitValue = true) {
104 typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
105 if ( i != container->end() )
106 flags->setFlagBit(i-container->begin(), bitPosition, bitValue, container);
107 else
108 throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
109 }
110
111
118 template<class T, class CONTAINER>
119 void setFlag(TrigPassFlags * flags, const T* obj, const CONTAINER* container, const std::vector<bool>& flag) {
120 typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
121 if ( i != container->end() )
122 flags->setFlag(i-container->begin(), flag, container);
123 else
124 throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
125 }
126
127
131 template<class T, class CONTAINER>
132 bool getFlagBit(const TrigPassFlags *flags,const T* obj, const CONTAINER* container, const unsigned int position, const unsigned int bitPosition) {
133 typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
134 if ( i != container->end() )
135 return flags->getFlagBit(i-container->begin(),position, bitPosition);
136 throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
137 }
138
142 template<class T, class CONTAINER>
143 const std::vector<bool>& getFlag(const TrigPassFlags *flags,const T* obj, const CONTAINER* container, const size_t position) {
144 typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
145 if ( i != container->end() )
146 return flags->getFlag(i-container->begin(),position);
147 throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
148 }
149
150 template<typename T>
151 std::vector<bool> AsFlag(T flag_t, const size_t size) { // T should be an unsigned type, otherwise this will give a compilation warning
152 if(size>8*sizeof(T)) // check of T has at list 'size' bits
153 throw std::runtime_error("AsFlag(): type T has less bits than required by 'size'");
154 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.)
155 throw std::runtime_error("AsFlag(): the flag is larger then bits available");
156
157
158 std::vector<bool> flag(size);
159 int mask = 0x01;
160 for(size_t idx=0; idx<size; ++idx, mask<<=1)
161 flag[idx] = (flag_t&mask)!=0;
162 return flag;
163 }
164
165 template<typename T>
166 T FlagAs(const std::vector<bool>& flag) {
167 if(8*sizeof(T)<flag.size()) // check of T has enough bits to represent flag
168 throw std::runtime_error("FlagAs(): the flag size does not fit into the requested type");
169 T v = 0;
170 int mask = 0x01;
171 for(size_t idx=0; idx<flag.size(); ++idx, mask<<=1)
172 if(flag[idx]) v += mask;
173 return v;
174 }
175
176} // eof HLT namespace
177
178
179#endif
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
File providing the different SG_BASE macros.
A Flag is an ordered collection of bits (vector<bool>) that can hold additional (boolean) information...
unsigned int flagSize() const
gets size of the flag vector for the object at index
bool getFlagBit(const unsigned int position, const unsigned int bitPosition) const
Returns the bit 'bitPosition' of the flag at index position.
const std::vector< bool > & getFlag(const unsigned int position) const
Returns the flag (vector<bool>) at index position.
std::vector< std::vector< bool > > m_flagsPerObject
list of trainsient n-bit value (STL docu assures that a vector of booleans is efficient)
const void * m_container_ptr
unsigned int size() const
gets size of the container object vector
void setFlag(const unsigned int position, const std::vector< bool > &flag, const void *cont=0)
Set the flag at index position.
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.
friend class TrigPassFlagsCnv_p1
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
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.
const std::vector< bool > & getFlag(const TrigPassFlags *flags, const T *obj, const CONTAINER *container, const size_t position)
Returns the flag at index position.
TrigPassFlags * makeTrigPassFlags(const CONTAINER *cont, const unsigned int flagSize)
void setFlag(TrigPassFlags *flags, const T *obj, const CONTAINER *container, const std::vector< bool > &flag)
Set the flag at index position.
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.
std::vector< bool > AsFlag(T flag_t, const size_t size)
T FlagAs(const std::vector< bool > &flag)