4#ifndef INDET_MODULEIDENTIFIERMATCHUTIL_H
5#define INDET_MODULEIDENTIFIERMATCHUTIL_H
7#include "Identifier/Identifier.h"
13 template <
typename T_ID>
20 return id_helper.side(
id);
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(); };
34 template <
typename T_ModuleDesign>
39 template <ModuleDesignConcept T_ModuleDesign>
42 return moduleDesign.columns();
45 return moduleDesign.cells();
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)) {
88 if (sub_arr.at(i+1)!=-2 || (sub_arr.at(i)!=0 && sub_arr.at(i)!=1)) {
110 template <
typename T>
121 assert( part%2==0 &&
static_cast<unsigned int>(part/2)<dest.size());
122 dest[part/2] = value;
132 template <
class T_ID,
class T_ModuleDesign>
135 const T_ModuleDesign &module_design,
154 inline void moduleMatches(
const std::vector<std::vector<int> > &module_pattern,
156 std::vector<unsigned int> &module_pattern_idx) {
157 module_pattern_idx.clear();
158 for (
unsigned int pattern_i=0u; pattern_i<module_pattern.size(); ++pattern_i) {
159 const std::vector<int> &pattern = module_pattern[pattern_i];
160 unsigned int range_i=0;
162 for (
int module_value : module_data) {
163 assert( range_i+1 < pattern.size());
164 if (module_value<pattern[range_i] || module_value>pattern[range_i+1]) {
166 if (pattern[range_i+1]>=pattern[range_i] || pattern[range_i+1]!=-2 || (module_value & 1) != (pattern[range_i] & 1)) {
174 module_pattern_idx.push_back(pattern_i);
bool match(std::string s1, std::string s2)
match the individual directories of two strings
int getZeroOrSide(const T_ID &id_helper, const Identifier &id)
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.
std::array< int, ModuleIdentifierMatchUtil::kAllRows/2 > ModuleData_t
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.
bool matchesBothSides(const std::vector< int > &a_module_pattern)
Test whether the given pattern matches identifiers which refer to either side of a sensor.
EModulePatternPart
The identifier parts used for identifier matching kAllRows denotes the element which contains a flag ...
@ kBarrelEndcapSelectRange
bool verifyModulePatternList(const std::vector< std::vector< int > > &arr)
Verify whether a list of module identifier patterns is consistent.
int getColumnsOrCells(const T_ModuleDesign &moduleDesign)
bool verifyElementCountAndOrder(const std::vector< std::vector< T > > &arr, std::size_t n_expected, std::size_t test_n=0)
Test whether the given 2D vector has the expected number of elements, and correct ordering.
void setModuleData(EModulePatternPart part, int value, std::array< int, kAllRows/2 > &dest)
Convenience function to set the specified element in the given array.
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.
bool isSideMatching(const std::vector< int > &a_module_pattern, int side)
Test whether the given pattern matches the given side.