Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ModuleKeyHelper.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3  */
4 #ifndef INDET_MODULEKEYHELPER_H
5 #define INDET_MODULEKEYHELPER_H
6 
7 #include <array>
8 #include <type_traits>
9 
10 namespace InDet {
11  namespace MaskUtils {
16  template<unsigned int bit, unsigned int end, typename T=unsigned int>
17  static consteval T createMask() {
18  if constexpr(bit>31u) {
19  return static_cast<T>(0u);
20  }
21  else if constexpr(bit>=end) {
22  return static_cast<T>(0u);
23  }
24  else {
25  return static_cast<T>(1u<<bit) | createMask<bit+1u,end, T>();
26  }
27  }
28  }
29 
46  template <typename T, unsigned int T_ROW_BITS, unsigned int T_COL_BITS, unsigned int T_CHIP_BITS, unsigned int T_MASK_SEL_BITS, unsigned int T_N_MASKS=3>
47  struct ModuleKeyHelper {
48  static constexpr unsigned int ROW_BITS = T_ROW_BITS;
49  static constexpr unsigned int COL_BITS = T_COL_BITS;
50  static constexpr unsigned int CHIP_BITS = T_CHIP_BITS;
51  static constexpr unsigned int MASK_SEL_BITS = T_MASK_SEL_BITS;
52  static constexpr unsigned int N_MASKS = T_N_MASKS;
53  static constexpr T ROW_SHIFT = 0u;
54  static constexpr T COL_SHIFT = ROW_BITS;
55  static constexpr T CHIP_SHIFT = ROW_BITS + COL_BITS;
56  static constexpr T MASK_SEL_SHIFT = ROW_BITS + COL_BITS + CHIP_BITS;
57  static constexpr T ROW_MASK = MaskUtils::createMask<0, ROW_BITS>();
58  static constexpr T COL_MASK = MaskUtils::createMask<ROW_BITS, ROW_BITS+COL_BITS>();
59  static constexpr T CHIP_MASK = MaskUtils::createMask<ROW_BITS+COL_BITS, ROW_BITS+COL_BITS+CHIP_BITS>();
60  static constexpr T MASK_SEL_MASK = MaskUtils::createMask<ROW_BITS+COL_BITS+CHIP_BITS,ROW_BITS+COL_BITS+CHIP_BITS+MASK_SEL_BITS>();
61  static constexpr unsigned int MASKS_SIZE=N_MASKS;
62  using KEY_TYPE = T;
63 
64  protected:
70  template <unsigned int SHIFT, T MASK>
71  static constexpr T makeKeyPart([[maybe_unused]] T val) {
72  if constexpr(MASK==0) {
73  return T{};
74  }
75  else {
76  assert (((val << SHIFT) & MASK) == (val << SHIFT));
77  return (val << SHIFT);
78  }
79  }
80 
89  static constexpr T makeKey(unsigned int mask_sel, unsigned int chip, unsigned int col, unsigned int row=0u) {
90  return makeKeyPart<MASK_SEL_SHIFT,MASK_SEL_MASK>(mask_sel)
91  | makeKeyPart<CHIP_SHIFT,CHIP_MASK>(chip)
92  | makeKeyPart<COL_SHIFT,COL_MASK>(col)
93  | makeKeyPart<ROW_SHIFT,ROW_MASK>(row);
94  }
95  public:
96 
99  static constexpr T getColumn(T key) { return (key & COL_MASK) >> COL_SHIFT; }
100 
103  static constexpr T getRow(T key) { return (key & ROW_MASK) >> ROW_SHIFT; }
104 
107  static constexpr T getChip(T key) { return (key & CHIP_MASK) >> CHIP_SHIFT; }
108 
111  static constexpr T getMaskIdx(T key) { return (key & MASK_SEL_MASK) >> MASK_SEL_SHIFT; }
112 
115  static constexpr unsigned int nMasks() { return std::max(1u,N_MASKS);}
116 
125  ModuleKeyHelper(std::array<T, N_MASKS> &&masks) requires (N_MASKS>0) : m_masks( masks) {}
126  ModuleKeyHelper() = default;
127 
134  T getMask(T key) const {
135  if constexpr(N_MASKS>0) {
136  unsigned int idx;
137  if constexpr(N_MASKS==1) {
138  idx=0u;
139  }
140  else {
141  idx = getMaskIdx(key);
142  }
143  assert( idx < m_masks.size());
144  return m_masks[idx];
145  }
146  else {
147  return static_cast<T>(1u);
148  }
149  }
150 
160  unsigned int maskedKey([[maybe_unused]] unsigned int mask_idx, unsigned int chip, unsigned int col, unsigned int row=0u) const {
161  if constexpr(N_MASKS>0) {
162  assert( mask_idx < m_masks.size());
163  return (m_masks[mask_idx] & makeKey(0u, chip, col, row)) | makeKey(mask_idx, 0u,0u,0u);
164  }
165  else {
166  return makeKey(0u, chip, col, row);
167  }
168  }
169 
177  unsigned int maskedKey(unsigned int mask_idx, unsigned int key) const {
178  if constexpr(N_MASKS>0) {
179  assert( mask_idx < m_masks.size());
180  return (m_masks[mask_idx] & key) | makeKey(mask_idx, 0u,0u,0u);
181  }
182  else {
183  return key;
184  }
185  }
186 
187 
195  bool isOverlapping(T key_ref, T key_test) const {
196  if constexpr(N_MASKS>0) {
197  unsigned int mask = getMask(key_ref);
198  return (key_ref & mask) == (key_test & mask);
199  }
200  else {
201  return key_ref == key_test;
202  }
203  }
204 
205  protected:
206  struct Empty {};
207  std::conditional< (N_MASKS>0), std::array<T, MASKS_SIZE>, Empty>::type m_masks;
208  };
209 
210 }
211 #endif
InDet::ModuleKeyHelper::MASKS_SIZE
static constexpr unsigned int MASKS_SIZE
Definition: ModuleKeyHelper.h:61
query_example.row
row
Definition: query_example.py:24
InDet::ModuleKeyHelper::getChip
static constexpr T getChip(T key)
Get the column index from a full key.
Definition: ModuleKeyHelper.h:107
InDet::ModuleKeyHelper::ROW_BITS
static constexpr unsigned int ROW_BITS
Definition: ModuleKeyHelper.h:48
InDet::ModuleKeyHelper::ROW_SHIFT
static constexpr T ROW_SHIFT
Definition: ModuleKeyHelper.h:53
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::ModuleKeyHelper::nMasks
static constexpr unsigned int nMasks()
Get the number of possible masks.
Definition: ModuleKeyHelper.h:115
InDet::ModuleKeyHelper< unsigned short, 12, 0, 0, 0, 0 >::KEY_TYPE
unsigned short KEY_TYPE
Definition: ModuleKeyHelper.h:62
InDet::ModuleKeyHelper::MASK_SEL_SHIFT
static constexpr T MASK_SEL_SHIFT
Definition: ModuleKeyHelper.h:56
InDet::ModuleKeyHelper::N_MASKS
static constexpr unsigned int N_MASKS
Definition: ModuleKeyHelper.h:52
InDet::ModuleKeyHelper::COL_BITS
static constexpr unsigned int COL_BITS
Definition: ModuleKeyHelper.h:49
InDet::ModuleKeyHelper::CHIP_BITS
static constexpr unsigned int CHIP_BITS
Definition: ModuleKeyHelper.h:50
requires
requires requires()
This specialization is used for classes deriving from DataObject.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:68
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
InDet::ModuleKeyHelper::CHIP_SHIFT
static constexpr T CHIP_SHIFT
Definition: ModuleKeyHelper.h:55
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
InDet::ModuleKeyHelper::getColumn
static constexpr T getColumn(T key)
Get the column index from a full key.
Definition: ModuleKeyHelper.h:99
InDet::ModuleKeyHelper::ModuleKeyHelper
ModuleKeyHelper()=default
InDet::ModuleKeyHelper::maskedKey
unsigned int maskedKey([[maybe_unused]] unsigned int mask_idx, unsigned int chip, unsigned int col, unsigned int row=0u) const
Create a key for a group defect.
Definition: ModuleKeyHelper.h:160
InDet::ModuleKeyHelper::makeKey
static constexpr T makeKey(unsigned int mask_sel, unsigned int chip, unsigned int col, unsigned int row=0u)
Create a key from mask, chip, column and row indices.
Definition: ModuleKeyHelper.h:89
InDet::ModuleKeyHelper::MASK_SEL_BITS
static constexpr unsigned int MASK_SEL_BITS
Definition: ModuleKeyHelper.h:51
InDet::ModuleKeyHelper::CHIP_MASK
static constexpr T CHIP_MASK
Definition: ModuleKeyHelper.h:59
InDet::ModuleKeyHelper::ModuleKeyHelper
ModuleKeyHelper(std::array< T, N_MASKS > &&masks) requires(N_MASKS >0)
Construct this key helper.
Definition: ModuleKeyHelper.h:125
query_example.col
col
Definition: query_example.py:7
InDet::ModuleKeyHelper::maskedKey
unsigned int maskedKey(unsigned int mask_idx, unsigned int key) const
Turn a single cell (e.g.
Definition: ModuleKeyHelper.h:177
InDet::ModuleKeyHelper::getRow
static constexpr T getRow(T key)
Get the row index from a full key.
Definition: ModuleKeyHelper.h:103
InDet::ModuleKeyHelper::m_masks
std::conditional<(N_MASKS >0), std::array< T, MASKS_SIZE >, Empty >::type m_masks
the masks for this helper.
Definition: ModuleKeyHelper.h:207
InDet::ModuleKeyHelper::Empty
Definition: ModuleKeyHelper.h:206
InDet::ModuleKeyHelper::MASK_SEL_MASK
static constexpr T MASK_SEL_MASK
Definition: ModuleKeyHelper.h:60
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
InDet::ModuleKeyHelper::ROW_MASK
static constexpr T ROW_MASK
Definition: ModuleKeyHelper.h:57
InDet::ModuleKeyHelper::isOverlapping
bool isOverlapping(T key_ref, T key_test) const
Test whether a single cell (e.g.
Definition: ModuleKeyHelper.h:195
InDet::ModuleKeyHelper::getMaskIdx
static constexpr T getMaskIdx(T key)
Get the mask index from a full key.
Definition: ModuleKeyHelper.h:111
InDet::ModuleKeyHelper
Helper class to create keys for defects described by chip, column and row indices,...
Definition: ModuleKeyHelper.h:47
InDet::ModuleKeyHelper::getMask
T getMask(T key) const
Get the mask specified by the full key.
Definition: ModuleKeyHelper.h:134
InDet::ModuleKeyHelper::makeKeyPart
static constexpr T makeKeyPart([[maybe_unused]] T val)
Convenience method to create part of a key.
Definition: ModuleKeyHelper.h:71
RoiUtil::MASK
MASK
Definition: RoiSerialise.cxx:35
InDet::ModuleKeyHelper::COL_MASK
static constexpr T COL_MASK
Definition: ModuleKeyHelper.h:58
InDet::ModuleKeyHelper::COL_SHIFT
static constexpr T COL_SHIFT
Definition: ModuleKeyHelper.h:54
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37