00001 #pragma once
00002 #ifndef TrigSteeringEvent_TrigPassFlags_h
00003 #define TrigSteeringEvent_TrigPassFlags_h
00004
00005 #include <vector>
00006 #include <algorithm>
00007 #include <stdexcept>
00008
00009 #include "xAODCore/CLASS_DEF.h"
00010
00011
00025 class TrigPassFlags {
00026 public:
00027 TrigPassFlags();
00035 TrigPassFlags(const unsigned int size, const unsigned int flagSize, const void *cont=0);
00036
00044 void setFlagBit(const unsigned int position, const unsigned int bitPosition, const bool bitValue, const void *cont=0 );
00045
00052 void setFlag(const unsigned int position, const std::vector<bool>& flag, const void *cont=0 );
00053
00058 bool getFlagBit(const unsigned int position, const unsigned int bitPosition) const;
00059
00064 const std::vector<bool>& getFlag(const unsigned int position) const;
00065
00069 unsigned int size() const { return m_flagsPerObject.size(); }
00070
00074 unsigned int flagSize() const { return m_flagsPerObject[0].size(); }
00075
00076 private:
00077 friend class TrigPassFlagsCnv_p1;
00078
00079 const void *m_container_ptr;
00080 std::vector<std::vector<bool> > m_flagsPerObject;
00081 };
00082
00083 CLASS_DEF( TrigPassFlags , 74395451 , 1 )
00084
00085
00086
00090 namespace HLT {
00091 template<class CONTAINER>
00092 TrigPassFlags* makeTrigPassFlags(const CONTAINER* cont,const unsigned int flagSize) {
00093 return new TrigPassFlags(cont->size(), flagSize, (const void*)cont );
00094 }
00095
00100 template<class T, class CONTAINER>
00101 void setFlagBit(TrigPassFlags * flags, const T* obj, const CONTAINER* container, const unsigned int bitPosition, const bool bitValue = true) {
00102 typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
00103 if ( i != container->end() )
00104 flags->setFlagBit(i-container->begin(), bitPosition, bitValue, container);
00105 else
00106 throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
00107 }
00108
00109
00116 template<class T, class CONTAINER>
00117 void setFlag(TrigPassFlags * flags, const T* obj, const CONTAINER* container, const std::vector<bool>& flag) {
00118 typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
00119 if ( i != container->end() )
00120 flags->setFlag(i-container->begin(), flag, container);
00121 else
00122 throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
00123 }
00124
00125
00129 template<class T, class CONTAINER>
00130 bool getFlagBit(const TrigPassFlags *flags,const T* obj, const CONTAINER* container, const unsigned int position, const unsigned int bitPosition) {
00131 typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
00132 if ( i != container->end() )
00133 return flags->getFlagBit(i-container->begin(),position, bitPosition);
00134 throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
00135 }
00136
00140 template<class T, class CONTAINER>
00141 const std::vector<bool>& getFlag(const TrigPassFlags *flags,const T* obj, const CONTAINER* container, const size_t position) {
00142 typename CONTAINER::const_iterator i = std::find(container->begin(), container->end(), obj);
00143 if ( i != container->end() )
00144 return flags->getFlag(i-container->begin(),position);
00145 throw std::runtime_error("The CONTAINER passed does not match the CONTAINER that created the TrigPassFlags");
00146 }
00147
00148 template<typename T>
00149 std::vector<bool> AsFlag(T flag_t, const size_t size) {
00150 if(size>8*sizeof(T))
00151 throw std::runtime_error("AsFlag(): type T has less bits than required by 'size'");
00152 if(flag_t >= ( ((unsigned long long)1)<<size) )
00153 throw std::runtime_error("AsFlag(): the flag is larger then bits available");
00154
00155
00156 std::vector<bool> flag(size);
00157 int mask = 0x01;
00158 for(size_t idx=0; idx<size; ++idx, mask<<=1)
00159 flag[idx] = (flag_t&mask)!=0;
00160 return flag;
00161 }
00162
00163 template<typename T>
00164 T FlagAs(const std::vector<bool> flag) {
00165 if(8*sizeof(T)<flag.size())
00166 throw std::runtime_error("FlagAs(): the flag size does not fit into the requested type");
00167 T v = 0;
00168 int mask = 0x01;
00169 for(size_t idx=0; idx<flag.size(); ++idx, mask<<=1)
00170 if(flag[idx]) v += mask;
00171 return v;
00172 }
00173
00174 }
00175
00176 #include "TrigSteeringEvent/TrigPassFlagsCollection.h"
00177
00178 #endif // TrigSteeringEvent_TrigPassFlags_h
00179
00180
00181
00182