Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ModuleIdentifierMatchUtil.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_MODULEIDENTIFIERMATCHUTIL_H
5 #define INDET_MODULEIDENTIFIERMATCHUTIL_H
6 
7 #include "Identifier/Identifier.h"
8 
9 namespace InDet {
10 
11  namespace ModuleIdentifierMatchUtil {
12  namespace detail {
13  template <typename T_ID>
14  concept IdentifierHelperWithSideConecpt = requires(T_ID id_helper, Identifier id) { id_helper.side(id); };
15 
16  // helper to to return the side part of an identifier if available or zero
17  template <class T_ID>
18  inline int getZeroOrSide(const T_ID &id_helper,const Identifier &id) {
19  if constexpr(IdentifierHelperWithSideConecpt<decltype(id_helper)>) {
20  return id_helper.side(id);
21  }
22  else {
23  return 0;
24  }
25  }
26  }
27 
28  // helper templates to detect whether a type has the method columns or cells
29  template <typename T_ModuleDesign>
30  concept HasColumns = requires(T_ModuleDesign design) { design.columns(); };
31  template <typename T_ModuleDesign>
32  concept HasCells = requires(T_ModuleDesign design) { design.cells(); };
33 
34  template <typename T_ModuleDesign>
35  concept ModuleDesignConcept = HasColumns<T_ModuleDesign> || HasCells<T_ModuleDesign>;
36 
37  // Get a unique module type identifier which is either based on the number of
38  // columns (for pixel) or number of cells (or strips; for strips)
39  template <ModuleDesignConcept T_ModuleDesign>
40  int getColumnsOrCells(const T_ModuleDesign &moduleDesign) {
41  if constexpr(HasColumns<T_ModuleDesign>) {
42  return moduleDesign.columns();
43  }
44  else {
45  return moduleDesign.cells();
46  }
47  }
48 
49 
61  kLength=10,
64  kNParts=15
65  };
66 
68 
80  template <bool test_order, typename T>
81  inline bool verifyElementCountAndOrder(const std::vector<std::vector<T> > &arr, std::size_t n_expected, [[maybe_unused]] std::size_t test_n=0) {
82  for (const auto &sub_arr : arr) {
83  if (sub_arr.size() != n_expected) return false;
84  if (test_n%2 != 0 || test_n>=n_expected) return false;
85  if constexpr(test_order) {
86  for (unsigned int i=0; i<test_n; i+=2) {
87  if (sub_arr.at(i)>sub_arr.at(i+1)) return false;
88  }
89  }
90  }
91  return true;
92  }
93 
99  inline bool verifyModulePatternList(const std::vector<std::vector<int> > &arr) {
100  return verifyElementCountAndOrder<true,int>(arr,kNParts, kAllRows);
101  }
102 
106  template <typename T>
107  inline bool verifyElementCount(const std::vector<std::vector<T> > &arr, std::size_t n_expected) {
108  return verifyElementCountAndOrder<false,T>(arr,n_expected, 0);
109  }
110 
116  inline void setModuleData(EModulePatternPart part, int value, std::array< int, kAllRows/2 > &dest) {
117  assert( part%2==0 && static_cast<unsigned int>(part/2)<dest.size());
118  dest[part/2] = value;
119  }
120 
128  template <class T_ID, class T_ModuleDesign>
129  inline void setModuleData(const T_ID &id_helper,
130  const Identifier &identifier,
131  const T_ModuleDesign &module_design,
132  ModuleData_t &module_data) {
133  setModuleData(kBarrelEndcapSelectRange, id_helper.barrel_ec(identifier), module_data);
134  setModuleData(kLayerRange, id_helper.layer_disk(identifier), module_data);
135  setModuleData(kEtaRange, id_helper.eta_module(identifier), module_data);
136  setModuleData(kPhiRange, id_helper.phi_module(identifier), module_data);
137  setModuleData(kColumnStripRange, getColumnsOrCells(module_design), module_data);
138  setModuleData(kLength, static_cast<int>(module_design.length()*1e3), module_data);
139  setModuleData(kSideRange, detail::getZeroOrSide(id_helper,identifier),module_data);
140  }
141 
150  inline void moduleMatches( const std::vector<std::vector<int> > &module_pattern,
151  const ModuleData_t &module_data,
152  std::vector<unsigned int> &module_pattern_idx) {
153  module_pattern_idx.clear();
154  for (unsigned int pattern_i=0u; pattern_i<module_pattern.size(); ++pattern_i) {
155  const std::vector<int> &pattern = module_pattern[pattern_i];
156  unsigned int range_i=0;
157  bool match=true;
158  for (int module_value : module_data) {
159  assert( range_i+1 < pattern.size());
160  if (module_value<pattern[range_i] || module_value>pattern[range_i+1]) {
161  match=false;
162  break;
163  }
164  range_i+=2;
165  }
166  if (match) {
167  module_pattern_idx.push_back(pattern_i);
168  }
169  }
170  }
171 
179  inline bool matchesBothSides(const std::vector<int> &a_module_pattern) {
180  assert( ModuleIdentifierMatchUtil::kSideRange+1 < a_module_pattern.size() );
181  return a_module_pattern[ModuleIdentifierMatchUtil::kSideRange]
182  != a_module_pattern[ModuleIdentifierMatchUtil::kSideRange+1];
183  }
186  inline bool isSideMatching(const std::vector<int> &a_module_pattern, int side) {
187  assert( ModuleIdentifierMatchUtil::kSideRange+1 < a_module_pattern.size() );
188  return side >= a_module_pattern[ModuleIdentifierMatchUtil::kSideRange]
189  && side <= a_module_pattern[ModuleIdentifierMatchUtil::kSideRange+1];
190  }
191 
199  inline bool matchesAllModuleRowsOfSensor(const std::vector<int> &a_module_pattern) {
200  assert(ModuleIdentifierMatchUtil::kAllRows < a_module_pattern.size());
201  return a_module_pattern[ModuleIdentifierMatchUtil::kAllRows] != 0;
202  }
203  }
204 }
205 #endif
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
InDet::ModuleIdentifierMatchUtil::kAllRows
@ kAllRows
Definition: ModuleIdentifierMatchUtil.h:63
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
InDet::ModuleIdentifierMatchUtil::kEtaRange
@ kEtaRange
Definition: ModuleIdentifierMatchUtil.h:58
InDet::ModuleIdentifierMatchUtil::matchesAllModuleRowsOfSensor
bool matchesAllModuleRowsOfSensor(const std::vector< int > &a_module_pattern)
Test whether a pattern matches all module rows of a sensor or just a single row.
Definition: ModuleIdentifierMatchUtil.h:199
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::ModuleIdentifierMatchUtil::kPhiRange
@ kPhiRange
Definition: ModuleIdentifierMatchUtil.h:59
InDet::ModuleIdentifierMatchUtil::EModulePatternPart
EModulePatternPart
The identifier parts used for identifier matching kAllRows denotes the element which contains a flag ...
Definition: ModuleIdentifierMatchUtil.h:55
athena.value
value
Definition: athena.py:124
requires
requires requires()
This specialization is used for classes deriving from DataObject.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:68
detail
Definition: extract_histogram_tag.cxx:14
perfmonmt-printer.dest
dest
Definition: perfmonmt-printer.py:189
InDet::ModuleIdentifierMatchUtil::getColumnsOrCells
int getColumnsOrCells(const T_ModuleDesign &moduleDesign)
Definition: ModuleIdentifierMatchUtil.h:40
xAOD::identifier
identifier
Definition: UncalibratedMeasurement_v1.cxx:15
InDet::ModuleIdentifierMatchUtil::HasCells
concept HasCells
Definition: ModuleIdentifierMatchUtil.h:32
InDet::ModuleIdentifierMatchUtil::verifyElementCount
bool verifyElementCount(const std::vector< std::vector< T > > &arr, std::size_t n_expected)
test whether the 2D vector arr has the expected number of elements.
Definition: ModuleIdentifierMatchUtil.h:107
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
InDet::ModuleIdentifierMatchUtil::ModuleDesignConcept
concept ModuleDesignConcept
Definition: ModuleIdentifierMatchUtil.h:35
InDet::ModuleIdentifierMatchUtil::detail::getZeroOrSide
int getZeroOrSide(const T_ID &id_helper, const Identifier &id)
Definition: ModuleIdentifierMatchUtil.h:18
InDet::ModuleIdentifierMatchUtil::kNParts
@ kNParts
Definition: ModuleIdentifierMatchUtil.h:64
TRT::Hit::side
@ side
Definition: HitInfo.h:83
InDet::ModuleIdentifierMatchUtil::ModuleData_t
std::array< int, ModuleIdentifierMatchUtil::kAllRows/2 > ModuleData_t
Definition: ModuleIdentifierMatchUtil.h:67
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
InDet::ModuleIdentifierMatchUtil::isSideMatching
bool isSideMatching(const std::vector< int > &a_module_pattern, int side)
Test whether the given pattern matches the given side.
Definition: ModuleIdentifierMatchUtil.h:186
lumiFormat.i
int i
Definition: lumiFormat.py:85
InDet::ModuleIdentifierMatchUtil::matchesBothSides
bool matchesBothSides(const std::vector< int > &a_module_pattern)
Test whether the given pattern matches identifiers which refer to either side of a sensor.
Definition: ModuleIdentifierMatchUtil.h:179
InDet::ModuleIdentifierMatchUtil::kSideRange
@ kSideRange
Definition: ModuleIdentifierMatchUtil.h:62
python.LArMinBiasAlgConfig.int
int
Definition: LArMinBiasAlgConfig.py:59
InDet::ModuleIdentifierMatchUtil::kLength
@ kLength
Definition: ModuleIdentifierMatchUtil.h:61
InDet::ModuleIdentifierMatchUtil::verifyModulePatternList
bool verifyModulePatternList(const std::vector< std::vector< int > > &arr)
Verify whether a list of module identifier patterns is consistent.
Definition: ModuleIdentifierMatchUtil.h:99
InDet::ModuleIdentifierMatchUtil::detail::IdentifierHelperWithSideConecpt
concept IdentifierHelperWithSideConecpt
Definition: ModuleIdentifierMatchUtil.h:14
InDet::ModuleIdentifierMatchUtil::verifyElementCountAndOrder
bool verifyElementCountAndOrder(const std::vector< std::vector< T > > &arr, std::size_t n_expected, [[maybe_unused]] std::size_t test_n=0)
Test whether the given 2D vector has the expected number of elements, and correct ordering.
Definition: ModuleIdentifierMatchUtil.h:81
lumiFormat.array
array
Definition: lumiFormat.py:91
InDet::ModuleIdentifierMatchUtil::kBarrelEndcapSelectRange
@ kBarrelEndcapSelectRange
Definition: ModuleIdentifierMatchUtil.h:56
InDet::ModuleIdentifierMatchUtil::kLayerRange
@ kLayerRange
Definition: ModuleIdentifierMatchUtil.h:57
InDet::ModuleIdentifierMatchUtil::moduleMatches
void moduleMatches(const std::vector< std::vector< int > > &module_pattern, const ModuleData_t &module_data, std::vector< unsigned int > &module_pattern_idx)
Test whether an identifier, which is split into various parts, matches some of the given patterns.
Definition: ModuleIdentifierMatchUtil.h:150
InDet::ModuleIdentifierMatchUtil::setModuleData
void setModuleData(EModulePatternPart part, int value, std::array< int, kAllRows/2 > &dest)
Convenience function to set the specified element in the given array.
Definition: ModuleIdentifierMatchUtil.h:116
InDet::ModuleIdentifierMatchUtil::HasColumns
concept HasColumns
Definition: ModuleIdentifierMatchUtil.h:30
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
InDet::ModuleIdentifierMatchUtil::kColumnStripRange
@ kColumnStripRange
Definition: ModuleIdentifierMatchUtil.h:60
Identifier
Definition: IdentifierFieldParser.cxx:14