ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetEventCnv
ITkPixelByteStreamCnv
src
ITkPixQCoreEncodingLUT.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef ITKPIXV2QCOREENCODINGLUT_H
6
#define ITKPIXV2QCOREENCODINGLUT_H
7
#include <iostream>
8
#include <cstdint>
9
#include <array>
10
#include <cstddef>
11
#include <algorithm>
12
#include <ranges>
13
14
namespace
ITkPixEncoding
{
15
constexpr
std::size_t
LookUpTableSize
(1<<16);
16
17
18
template
<std::
size_t
Length,
typename
Generator>
19
constexpr
auto
lut
(Generator&& f){
20
using
content_type =
decltype
(f(std::size_t{0}));
21
std::array<content_type, Length> arr;
22
using namespace
std::ranges;
23
auto
rangy = views::iota(std::size_t{0}, Length)
// Generate a sequence
24
| views::transform(std::forward<Generator>(f));
// Transform using our generator
25
copy(rangy, arr.begin());
26
return
arr;
27
}
28
29
constexpr
uint32_t
30
one_bit
(uint32_t v){
31
return
v!=0;
32
}
33
34
// nb. If we use std::array here instead of a C array,
35
// then compilation fails with gcc13 in the dbg build
36
// because the compile-time execution of encode() then takes
37
// too many steps.
38
constexpr
void
prepByte
(uint32_t word, uint32_t b[8]){
39
for
(
int
i = 0 ;i<8;i++) {
40
b[i] = ((word >> (2*i)) & 0x1) << 1 | ((word >> (2*i+1)) & 0x1);
41
}
42
}
43
44
std::array<uint32_t, 8>
prepByte
(uint32_t word)
45
{
46
std::array<uint32_t, 8> b;
47
prepByte
(word, b.data());
48
return
b;
49
}
50
51
52
//QCore encoding function, taken from Matthias Wittgen and Carlos
53
uint32_t
54
constexpr
encode
(uint32_t decoded, uint32_t &encoded) {
55
uint32_t b[8];
56
prepByte
(decoded, b);
57
//
58
uint32_t
S1
= (
one_bit
(b[0] | b[1] | b[2] | b[3]) << 1) |
one_bit
(b[4] | b[5] | b[6] | b[7]);
59
uint32_t S2t = (
one_bit
(b[0] | b[1]) << 1) |
one_bit
(b[2] | b[3]);
60
uint32_t S2b = (
one_bit
(b[4] | b[5]) << 1) |
one_bit
(b[6] | b[7]);
61
uint32_t S3tl = (
one_bit
(b[0]) << 1) |
one_bit
(b[1]);
62
uint32_t S3tr = (
one_bit
(b[2]) << 1) |
one_bit
(b[3]);
63
uint32_t S3bl = (
one_bit
(b[4]) << 1) |
one_bit
(b[5]);
64
uint32_t S3br = (
one_bit
(b[6]) << 1) |
one_bit
(b[7]);
65
66
uint32_t pos = 0;
67
encoded = 0;
68
69
auto
writeTwo = [&](uint32_t src) {
70
if
(src == 0b01) {
71
encoded |= (0b0) << (28 - pos);
72
pos++;
73
}
else
{
74
encoded |= (src & 0x3) << (28 - pos);
75
pos += 2;
76
}
77
};
78
for
(
auto
& val:{
79
S1
, S2t, S3tl, S3tr, b[0], b[1],b[2], b[3],
80
S2b, S3bl, S3br,b[4], b[5], b[6], b[7]
81
})
if
(val) writeTwo(val);
82
return
pos;
83
}
84
85
//Create LUTs - if argument is true, return length LUT, if it's false return the encoded QCore LUT.
86
//It could be prettified / optimized to fill in both LUTs in one go, but happens once per job and takes O(ms)
87
//so no real gain there.
88
inline
auto
create_lut_encode
(
bool
length
=
false
) {
89
//stack use is 262144 bytes in lut
90
//coverity[STACK_USE]
91
std::array<uint32_t, LookUpTableSize>
lut
;
92
lut
[0] = 0;
93
for
(uint32_t i = 1; i < 1 << 16; i++) {
94
uint32_t encoded;
95
uint64_t len =
encode
(i, encoded);
96
lut
[i] =
length
? len : encoded;
97
}
98
return
lut
;
99
}
100
101
//It could be prettified / optimized to fill in both LUTs in one go, but happens once per job and takes O(ms)
102
//so no real gain there.
103
//constexpr complexity exceeds limit (coverity warning)
104
template
<std::
size_t
Length>
105
//coverity[expr_not_constant]
106
constexpr
auto
LutLen
=
lut<Length>
([](uint32_t i){
107
uint32_t encoded;
108
return
encode
(i, encoded);
109
});
110
111
//constexpr complexity exceeds limit
112
template
<std::
size_t
Length>
113
//coverity[expr_not_constant]
114
constexpr
auto
LutBTree
=
lut<Length>
([](uint32_t i){
115
uint32_t encoded;
116
uint64_t len =
encode
(i, encoded);
117
return
encoded >> (30 - len);
118
});
119
120
121
constexpr
std::array<uint32_t, LookUpTableSize >
ITkPixV2QCoreEncodingLUT_Tree
=
LutBTree<LookUpTableSize>
;
122
constexpr
std::array<uint32_t, LookUpTableSize >
ITkPixV2QCoreEncodingLUT_Length
=
LutLen<LookUpTableSize>
;
123
124
}
125
#endif
length
double length(const pvec &v)
Definition
FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
S1
struct TBPatternUnitContext S1
ITkPixEncoding
Definition
ITkPixQCoreEncodingLUT.h:14
ITkPixEncoding::lut
constexpr auto lut(Generator &&f)
Definition
ITkPixQCoreEncodingLUT.h:19
ITkPixEncoding::LutLen
constexpr auto LutLen
Definition
ITkPixQCoreEncodingLUT.h:106
ITkPixEncoding::one_bit
constexpr uint32_t one_bit(uint32_t v)
Definition
ITkPixQCoreEncodingLUT.h:30
ITkPixEncoding::encode
uint32_t constexpr encode(uint32_t decoded, uint32_t &encoded)
Definition
ITkPixQCoreEncodingLUT.h:54
ITkPixEncoding::LutBTree
constexpr auto LutBTree
Definition
ITkPixQCoreEncodingLUT.h:114
ITkPixEncoding::create_lut_encode
auto create_lut_encode(bool length=false)
Definition
ITkPixQCoreEncodingLUT.h:88
ITkPixEncoding::ITkPixV2QCoreEncodingLUT_Length
constexpr std::array< uint32_t, LookUpTableSize > ITkPixV2QCoreEncodingLUT_Length
Definition
ITkPixQCoreEncodingLUT.h:122
ITkPixEncoding::ITkPixV2QCoreEncodingLUT_Tree
constexpr std::array< uint32_t, LookUpTableSize > ITkPixV2QCoreEncodingLUT_Tree
Definition
ITkPixQCoreEncodingLUT.h:121
ITkPixEncoding::prepByte
constexpr void prepByte(uint32_t word, uint32_t b[8])
Definition
ITkPixQCoreEncodingLUT.h:38
ITkPixEncoding::LookUpTableSize
constexpr std::size_t LookUpTableSize(1<< 16)
Generated on
for ATLAS Offline Software by
1.17.0