12 unsigned int errors=0;
13 constexpr std::array<IndexType,2> axis_offset{1,2};
15 unsigned int n_invalid=0;
17 std::array<std::array<unsigned int,2>,2> n_invalid_halves{};
18 for (
unsigned int element_i=0; element_i<a_split.size(); ++element_i) {
19 bool is_invalid = a_split.at(element_i)==
s_invalid;
20 unsigned int axis0=element_i/2;
21 unsigned int axis1=element_i%2;
22 n_invalid_halves[0][axis0]+=is_invalid;
23 n_invalid_halves[1][axis1]+=is_invalid;
24 if (is_invalid) ++n_invalid;
25 else { good_idx=a_split[element_i]; }
29 for (
unsigned int element_i=0; element_i<a_split.size(); ++element_i) {
30 a_split.at(element_i)=good_idx;
33 else if (n_invalid==2) {
34 unsigned int element_i=std::numeric_limits<unsigned int>::max();
35 for (
unsigned int axis_i=0; axis_i<2; ++axis_i) {
36 for (
unsigned int side_i=0; side_i<2; ++side_i) {
37 if (n_invalid_halves[axis_i][side_i]==2 && n_invalid_halves[axis_i][side_i^1]==0) {
38 element_i=axis_offset[axis_i^1]*side_i;
39 IndexType other_element_i = axis_offset[axis_i^1]*(side_i==1 ? -1 : 1);
40 unsigned int element_end_i=element_i+axis_offset[axis_i]*2;
41 for(; element_i<element_end_i; element_i+=axis_offset[axis_i] ) {
42 a_split[ element_i ] = a_split[ element_i + other_element_i] ;
46 if (element_i != std::numeric_limits<unsigned int>::max())
break;
49 if (element_i == std::numeric_limits<unsigned int>::max()) {
53 else if (n_invalid!=0) {
62 assert( matrix_dim[0]>0 && matrix_dim[1]>0);
67 m_matrixCorner[0]=lower_corner_proxy.position() - lower_corner_proxy.width()*.5;
68 for (
unsigned int axis_i=0; axis_i<2; ++axis_i) {
76 m_matrixCorner[1]=upper_corner_proxy.position() + upper_corner_proxy.width()*.5 ;
77 for (
unsigned int axis_i=0; axis_i<2; ++axis_i) {
82 throw std::logic_error(
"Logic error! Matrix corner positions do not yield valid indices for this matrix!");
88 for (
unsigned int axis_i=0; axis_i<2; ++axis_i) {
89 assert( matrix_dim[axis_i]>0 &&
90 static_cast<unsigned int>(std::abs(matrix_dim[axis_i])) < std::numeric_limits<unsigned int>::max());
91 unsigned int bits_i=0;
92 for (; bits_i<16 && 1u<<bits_i < static_cast<unsigned int>(matrix_dim[axis_i])*3; ++bits_i);
93 tolerance[axis_i]=(1u<<bits_i) * std::numeric_limits<PixelDiodeTree::FloatType>::epsilon();
99 std::stringstream out;
107 out <<
"PixelDiodeTree is inconsistent. Expected identical number of elements but has the following "
108 <<
" container sizes: index-split points : " <<
m_idxSplit.size()
109 <<
" position split points : " <<
m_posSplit.size()
113 <<
" inverted width : " <<
m_diodeParam.m_invWidth.size()
118 out <<
"PixelDiodeTree total width : " <<
m_diodeParam.m_width[0][0] <<
"x" <<
m_diodeParam.m_width[0][1] <<
" mm^2" <<
"\n:";
119 std::vector<std::pair<IndexType,unsigned int> > submatrix_stack;
120 submatrix_stack.push_back(std::make_pair(0u,2u));
121 while (!submatrix_stack.empty()) {
122 auto [submatrix_idx, margin] = submatrix_stack.back();
123 submatrix_stack.pop_back();
124 out << std::setw(margin) <<
' ';
125 if (submatrix_idx < 0) {
127 unsigned int diode_idx=std::abs(submatrix_idx);
130 <<
" attribute " << std::hex <<
m_diodeParam.m_attribute[diode_idx] << std::dec <<
"\n";
134 else if (
static_cast<std::size_t
>(submatrix_idx) >=
m_idxSplit.size()) {
135 out <<
"Invalid sub-matrix index : " << submatrix_idx <<
"\n";
138 out <<
" split at (row,col) " <<
m_idxSplit[submatrix_idx][0] <<
" " <<
m_idxSplit[submatrix_idx][1]
139 <<
" , position (local-x/-y) " <<
m_posSplit[submatrix_idx][0] <<
" " <<
m_posSplit[submatrix_idx][1]
140 <<
" attribute " << std::hex <<
m_attribute[submatrix_idx] << std::dec
141 <<
" sub-matrices (diodes): ";
142 for (
unsigned int split_i=0; split_i<
m_subMatrixIndex[submatrix_idx].size(); ++split_i) {
143 out << (split_i==2 ?
" | " :
" ");
152 for (std::array<IndexType,4>::const_reverse_iterator iter =
m_subMatrixIndex[submatrix_idx].rbegin();
156 submatrix_stack.push_back( std::make_pair( *iter, margin+2));
164 out <<
"PixelDiodeTree with " <<
m_subMatrixIndex.size() <<
" has no diodes." <<
"\n";