ATLAS Offline Software
Loading...
Searching...
No Matches
ITkPixV2Encoder Class Reference

#include <ITkPixV2Encoder.h>

Inheritance diagram for ITkPixV2Encoder:
Collaboration diagram for ITkPixV2Encoder:

Public Types

typedef ITkPixLayout< uint16_t > HitMap

Public Member Functions

void endStream () const
void addToStream (const HitMap &hitMap, bool last=false) const
std::vector< uint32_t > & getWords ()
void addBits64 (const uint64_t value, const uint8_t length) const
void setHitMap (const HitMap &hitMap) const
void setEventsPerStream (const unsigned nEventsPerStream=16)
void setChipID (const uint8_t &chipID)
void clear () const

Protected Member Functions

void pushWords32 () const
void encodeQCore (const unsigned nCCol, const unsigned nQRow) const
void encodeEvent () const
void streamTag (const uint8_t nStream) const
void intTag (const uint16_t nEvt) const
void scanHitMap () const
bool hitInQCore (const unsigned CCol, const unsigned QRow) const

Protected Attributes

unsigned m_nCol {400}
unsigned m_nRow {384}
unsigned m_nCCol {50}
unsigned m_nQRow {192}
unsigned m_nColInCCol {8}
unsigned m_nRowInQRow {2}
std::vector< uint32_t > m_words ATLAS_THREAD_SAFE
unsigned m_currCCol ATLAS_THREAD_SAFE {}
unsigned m_currCCol m_currQRow ATLAS_THREAD_SAFE {}
unsigned m_currCCol m_currQRow m_currEvent ATLAS_THREAD_SAFE {}
uint8_t m_currStream ATLAS_THREAD_SAFE {}
uint64_t m_currBlock ATLAS_THREAD_SAFE {}
uint8_t m_currBit ATLAS_THREAD_SAFE {}
std::vector< std::vector< bool > > m_hitQCores ATLAS_THREAD_SAFE
std::vector< unsigned > m_lastQRow ATLAS_THREAD_SAFE
HitMap m_hitMap ATLAS_THREAD_SAFE
unsigned m_nEventsPerStream
bool m_enableChipID {}
bool m_plainHitMap {}
bool m_dropToT {}
size_t m_bitsPerWord
uint8_t m_chipID = 0b00
std::mutex m_mutex

Detailed Description

Definition at line 22 of file ITkPixV2Encoder.h.

Member Typedef Documentation

◆ HitMap

typedef ITkPixLayout<uint16_t> ITkPixEncoder::HitMap
inherited

Definition at line 25 of file ITkPixEncoder.h.

Member Function Documentation

◆ addBits64()

void ITkPixEncoder::addBits64 ( const uint64_t value,
const uint8_t length ) const
inherited

Definition at line 29 of file ITkPixEncoder.cxx.

29 {
30
31 //only called from mutex-protected function
32
33 //This adds 'length' lowest bits to the current block. If the current
34 //block gets filled, push it to the output and start a new block with
35 //the rest of the bits that didn't make it. Need to keep track of the
36 //remaining space in the current word. Also, we only have 63 bits for
37 //the added data, as the first bit is EoS.
38 //Case 1: there's enough space for the entire information to be added
39 if (length <= (m_bitsPerWord - m_currBit)){
40
41 //The position at which the new bits should be inserted into the block
42 //is (length of the block - 1) - (currently last bit) - (length)
43 //We need to keep the first bit for EoS, hence the -1
44 m_currBlock |= (value << (m_bitsPerWord - m_currBit - length));
45 m_currBit += length;
46 return;
47 }
48
49 //Case 2: there's not enough space, so we put what we can, push the block
50 //to the output, and the rest to a new block
51 else {
52
53 //How much space do we have?
54 uint8_t remainingBits = m_bitsPerWord - m_currBit;
55
56 //Add that many bits
57 m_currBlock |= ((value >> (length - remainingBits)));
58
59 //Push the current block to the output and reset it and the current
60 //bit counter. The block needs to be split in 32-bit halves before the output
62
63 //What are we left with?
64 uint8_t leftoverBits = length - remainingBits;
65
66 //Now we can add the remainder
67 //Make sure that the remainder we're adding is really only the bits we've not yet
68 //added, otherwise there can be a rogue "1" in the EoS bit, which was already added
69 //in the previous block
70 addBits64((value & (0xFFFFFFFFFFFFFFFF >> (64 - leftoverBits))), leftoverBits);
71
72 }
73}
double length(const pvec &v)
void pushWords32() const
size_t m_bitsPerWord
void addBits64(const uint64_t value, const uint8_t length) const

◆ addToStream()

void ITkPixV2Encoder::addToStream ( const HitMap & hitMap,
bool last = false ) const

Definition at line 21 of file ITkPixV2Encoder.cxx.

21 {
22
23 //All operation on the class mutables (except m_words()) is done here
24 //in a serialized sequence ensuring thread safety. The individual functions
25 //called here are not accessible from the outside.
26
27 //This is a high-level interface function that can take care of
28 //adding an event into the current stream, this can be called
29 //easily from the outside, and automatically tags/ends streams
30 //and events based on internal vars only
31
32 //If this is the first event, start a new stream. Otherwise, add an
33 //internal tag
34 std::lock_guard<std::mutex> lock(m_mutex);
35
36 if (m_currEvent == 0){
37 streamTag(m_currStream);
38 m_currStream++;
39 }
40 else {
41 intTag(m_currEvent);
42 }
43
44 //Then add the actual encoded event information
45 setHitMap(hitMap);
47 m_currEvent++;
48
49 //If this is the last event in the stream or if we explicitly
50 //want to end the stream (i. e. total number of generated events
51 //is not a multiple of nEventsPerStream), end the stream
52 if (m_currEvent == m_nEventsPerStream || last){
53 endStream();
54 m_currEvent = 0;
55 }
56
57}
void encodeEvent() const
std::mutex m_mutex
void streamTag(const uint8_t nStream) const
unsigned m_nEventsPerStream
void setHitMap(const HitMap &hitMap) const
void intTag(const uint16_t nEvt) const
void endStream() const

◆ clear()

void ITkPixEncoder::clear ( ) const
inherited

Definition at line 231 of file ITkPixEncoder.cxx.

231 {
232 std::lock_guard<std::mutex> lock(m_mutex);
233 m_words.clear();
234}

◆ encodeEvent()

void ITkPixEncoder::encodeEvent ( ) const
protectedinherited

Definition at line 170 of file ITkPixEncoder.cxx.

170 {
171
172 //only called from mutex-protected function
173
174 //This produces the bits for one event.
175 //First, scan the map and produce helpers
176 scanHitMap();
177
178 for (unsigned CCol = 0; CCol < m_nCCol; CCol++){
179 //if there are no hits in this CCol, continue
180 if (m_lastQRow[CCol] == 0) continue;
181 //add the 6-bit (CCol + 1) address
182 addBits64(CCol + 1, 6);
183
184 unsigned previousQRow = std::numeric_limits<unsigned>::max();
185 for (unsigned QRow = 0; QRow < m_nQRow; QRow++){
186 //if there's no hit in this row, continue
187 if (!m_hitQCores[CCol][QRow]) continue;
188
189 //add the isLast bit
190 QRow + 1 == m_lastQRow[CCol] ? addBits64(0x1, 1) : addBits64(0x0, 1);
191
192 //add the isNeighbor bit. If false, add the QRow address as well.
193 if (previousQRow != std::numeric_limits<unsigned>::max() && QRow == previousQRow + 1) {
194 addBits64(0x1, 1);
195 } else {
196 addBits64(0x0, 1);
197 addBits64(QRow, 8);
198 };
199
200 //add the map and ToT
201 encodeQCore(CCol, QRow);
202
203 //update the previous QRow
204 previousQRow = QRow;
205 }
206 }
207}
void encodeQCore(const unsigned nCCol, const unsigned nQRow) const
void scanHitMap() const
unsigned m_nQRow
unsigned m_nCCol

◆ encodeQCore()

void ITkPixEncoder::encodeQCore ( const unsigned nCCol,
const unsigned nQRow ) const
protectedinherited

Definition at line 92 of file ITkPixEncoder.cxx.

92 {
93
94 //only called from mutex-protected function
95
96 //produce hit map and ToTs
97 //First, get the top-left pixel in the QCore
98 unsigned col = nCCol * m_nColInCCol;
99 unsigned row = nQRow * m_nRowInQRow;
100
101 //now loop, store ToTs, and build index of the
102 //compressed hit map in the LUT
103 uint16_t lutIndex = 0x0000;
104 std::vector<uint16_t> tots;
105 tots.reserve(16);
106 int pix = 0;
107 for (unsigned pixRow = row; pixRow < row + m_nRowInQRow; pixRow++){
108 for (unsigned pixCol = col; pixCol < col + m_nColInCCol; pixCol++){
109 if (m_hitMap(pixCol, pixRow)){
110 lutIndex |= 0x1 << pix;
111 tots.push_back(m_hitMap(pixCol, pixRow) - 1);
112 }
113 pix++;
114 }
115 }
116
117 //now add the binary-tree encoded & compressed map
118 //from the LUT to the stream. If, instead, the plain
119 //hit map is requested, add the index (which is the
120 //plain hit map in fact)
121 m_plainHitMap ? addBits64(lutIndex, 16) : addBits64(ITkPixEncoding::ITkPixV2QCoreEncodingLUT_Tree[lutIndex], ITkPixEncoding::ITkPixV2QCoreEncodingLUT_Length[lutIndex]);
122
123 //if dropToT is requested, we can return here
124 if (m_dropToT) return;
125
126 //and add the four-bit ToT information for each hit
127 for (auto& tot : tots){
128 addBits64(tot, 4);
129 }
130}
unsigned m_nRowInQRow
unsigned m_nColInCCol
constexpr std::array< uint32_t, LookUpTableSize > ITkPixV2QCoreEncodingLUT_Length
constexpr std::array< uint32_t, LookUpTableSize > ITkPixV2QCoreEncodingLUT_Tree
row
Appending html table to final .html summary file.
setWord1 uint16_t

◆ endStream()

void ITkPixV2Encoder::endStream ( ) const

Definition at line 15 of file ITkPixV2Encoder.cxx.

15 {
16 //only called from mutex-protected function
17 m_currBlock |= (0x1ULL << 63);
19}

◆ getWords()

std::vector< uint32_t > & ITkPixEncoder::getWords ( )
inlineinherited

Definition at line 32 of file ITkPixEncoder.h.

32{return m_words;}

◆ hitInQCore()

bool ITkPixEncoder::hitInQCore ( const unsigned CCol,
const unsigned QRow ) const
protectedinherited

Definition at line 132 of file ITkPixEncoder.cxx.

132 {
133 //Was there a hit in this QCore?
134
135 unsigned col = CCol * m_nColInCCol;
136 unsigned row = QRow * m_nRowInQRow;
137
138 for (unsigned pixRow = row; pixRow < row + m_nRowInQRow; pixRow++){
139 for (unsigned pixCol = col; pixCol < col + m_nColInCCol; pixCol++){
140 if (m_hitMap(pixCol, pixRow)) return true;
141 }
142 }
143
144 return false;
145}

◆ intTag()

void ITkPixEncoder::intTag ( const uint16_t nEvt) const
protectedinherited

Definition at line 217 of file ITkPixEncoder.cxx.

217 {
218
219 //only called from mutex-protected function
220
221 //this adds 11 bits of interal tagging between events.
222 //does the tag always need to start with 111?
223 uint16_t tag = nEvt | (0b111 << 8);
224 addBits64(tag, 11);
225}

◆ pushWords32()

void ITkPixEncoder::pushWords32 ( ) const
protectedinherited

Definition at line 75 of file ITkPixEncoder.cxx.

75 {
76 //whenever the current block is ready for output,
77 //split it into two 32-bit words and push them to
78 //the output container. Reset the current bloc/bit
79
80 //only called from mutex-protected function
81 if (m_enableChipID){
82 m_currBlock |= ((0x0ULL | m_chipID) << 61);
83 }
84 uint32_t word1 = m_currBlock >> 32;
85 uint32_t word2 = m_currBlock & 0xFFFFFFFF;
86 m_words.push_back(word1);
87 m_words.push_back(word2);
88 m_currBlock = 0x0ULL;
89 m_currBit = 0;
90}
setEventNumber uint32_t

◆ scanHitMap()

void ITkPixEncoder::scanHitMap ( ) const
protectedinherited

Definition at line 147 of file ITkPixEncoder.cxx.

147 {
148
149 //only called from mutex-protected function
150
151 //Fill in a helper map of hit QCores and a vector of last qrow in each ccol
152 m_hitQCores = std::vector<std::vector<bool>>(m_nCCol, std::vector<bool>(m_nQRow, false));
153 m_lastQRow = std::vector<unsigned> (m_nCCol, 0);
154
155 for (unsigned CCol = 0; CCol < m_nCCol; CCol++){
156 for (unsigned QRow = 0; QRow < m_nQRow; QRow++){
157 //if there's a hit in the qcore, flag the helper map
158 m_hitQCores[CCol][QRow] = hitInQCore(CCol, QRow);
159
160 //and keep track of the last qrow in each CCol, so that we can
161 //easily set the isLast bit. Numbering starts at 1, in order to
162 //keep the m_lastQRow[CCol] == 0 case denoting "no hit" in the CCol
163 //to save some looping/ifs later on
164 if (m_hitQCores[CCol][QRow]) m_lastQRow[CCol] = QRow + 1;
165 }
166 }
167
168}
bool hitInQCore(const unsigned CCol, const unsigned QRow) const

◆ setChipID()

void ITkPixEncoder::setChipID ( const uint8_t & chipID)
inherited

Definition at line 227 of file ITkPixEncoder.cxx.

227 {
228 m_chipID = chipID;
229}

◆ setEventsPerStream()

void ITkPixEncoder::setEventsPerStream ( const unsigned nEventsPerStream = 16)
inlineinherited

Definition at line 38 of file ITkPixEncoder.h.

38{m_nEventsPerStream = nEventsPerStream;}

◆ setHitMap()

void ITkPixEncoder::setHitMap ( const HitMap & hitMap) const
inlineinherited

Definition at line 36 of file ITkPixEncoder.h.

36{m_hitMap = hitMap;}

◆ streamTag()

void ITkPixEncoder::streamTag ( const uint8_t nStream) const
protectedinherited

Definition at line 209 of file ITkPixEncoder.cxx.

209 {
210
211 //only called from mutex-protected function
212
213 //this adds the 8-bit 'global' stream tag
214 addBits64(nStream, 8);
215}

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/10]

std::vector<uint32_t> m_words ITkPixEncoder::ATLAS_THREAD_SAFE
mutableprotectedinherited

Definition at line 65 of file ITkPixEncoder.h.

◆ ATLAS_THREAD_SAFE [2/10]

unsigned m_currCCol ITkPixEncoder::ATLAS_THREAD_SAFE {}
mutableprotectedinherited

Definition at line 67 of file ITkPixEncoder.h.

67{}, m_currQRow ATLAS_THREAD_SAFE {}, m_currEvent ATLAS_THREAD_SAFE {};//
std::vector< uint32_t > m_words ATLAS_THREAD_SAFE

◆ ATLAS_THREAD_SAFE [3/10]

unsigned m_currCCol m_currQRow ITkPixEncoder::ATLAS_THREAD_SAFE {}
protectedinherited

Definition at line 67 of file ITkPixEncoder.h.

67{}, m_currQRow ATLAS_THREAD_SAFE {}, m_currEvent ATLAS_THREAD_SAFE {};//

◆ ATLAS_THREAD_SAFE [4/10]

unsigned m_currCCol m_currQRow m_currEvent ITkPixEncoder::ATLAS_THREAD_SAFE {}
protectedinherited

Definition at line 67 of file ITkPixEncoder.h.

67{}, m_currQRow ATLAS_THREAD_SAFE {}, m_currEvent ATLAS_THREAD_SAFE {};//

◆ ATLAS_THREAD_SAFE [5/10]

uint8_t m_currStream ITkPixEncoder::ATLAS_THREAD_SAFE {}
mutableprotectedinherited

Definition at line 68 of file ITkPixEncoder.h.

68{};

◆ ATLAS_THREAD_SAFE [6/10]

uint64_t m_currBlock ITkPixEncoder::ATLAS_THREAD_SAFE {}
mutableprotectedinherited

Definition at line 71 of file ITkPixEncoder.h.

71{};

◆ ATLAS_THREAD_SAFE [7/10]

uint8_t m_currBit ITkPixEncoder::ATLAS_THREAD_SAFE {}
mutableprotectedinherited

Definition at line 72 of file ITkPixEncoder.h.

72{};

◆ ATLAS_THREAD_SAFE [8/10]

std::vector<std::vector<bool> > m_hitQCores ITkPixEncoder::ATLAS_THREAD_SAFE
mutableprotectedinherited

Definition at line 73 of file ITkPixEncoder.h.

◆ ATLAS_THREAD_SAFE [9/10]

std::vector<unsigned> m_lastQRow ITkPixEncoder::ATLAS_THREAD_SAFE
mutableprotectedinherited

Definition at line 74 of file ITkPixEncoder.h.

◆ ATLAS_THREAD_SAFE [10/10]

HitMap m_hitMap ITkPixEncoder::ATLAS_THREAD_SAFE
mutableprotectedinherited

Definition at line 82 of file ITkPixEncoder.h.

◆ m_bitsPerWord

size_t ITkPixEncoder::m_bitsPerWord
protectedinherited

Definition at line 78 of file ITkPixEncoder.h.

◆ m_chipID

uint8_t ITkPixEncoder::m_chipID = 0b00
protectedinherited

Definition at line 79 of file ITkPixEncoder.h.

◆ m_dropToT

bool ITkPixEncoder::m_dropToT {}
protectedinherited

Definition at line 77 of file ITkPixEncoder.h.

◆ m_enableChipID

bool ITkPixEncoder::m_enableChipID {}
protectedinherited

Definition at line 77 of file ITkPixEncoder.h.

◆ m_mutex

std::mutex ITkPixEncoder::m_mutex
mutableprotectedinherited

Definition at line 84 of file ITkPixEncoder.h.

◆ m_nCCol

unsigned ITkPixEncoder::m_nCCol {50}
protectedinherited

Definition at line 62 of file ITkPixEncoder.h.

62{400}, m_nRow{384}, m_nCCol{50}, m_nQRow{192}, m_nColInCCol{8}, m_nRowInQRow{2};
unsigned m_nRow

◆ m_nCol

unsigned ITkPixEncoder::m_nCol {400}
protectedinherited

Definition at line 62 of file ITkPixEncoder.h.

62{400}, m_nRow{384}, m_nCCol{50}, m_nQRow{192}, m_nColInCCol{8}, m_nRowInQRow{2};

◆ m_nColInCCol

unsigned ITkPixEncoder::m_nColInCCol {8}
protectedinherited

Definition at line 62 of file ITkPixEncoder.h.

62{400}, m_nRow{384}, m_nCCol{50}, m_nQRow{192}, m_nColInCCol{8}, m_nRowInQRow{2};

◆ m_nEventsPerStream

unsigned ITkPixEncoder::m_nEventsPerStream
protectedinherited

Definition at line 66 of file ITkPixEncoder.h.

◆ m_nQRow

unsigned ITkPixEncoder::m_nQRow {192}
protectedinherited

Definition at line 62 of file ITkPixEncoder.h.

62{400}, m_nRow{384}, m_nCCol{50}, m_nQRow{192}, m_nColInCCol{8}, m_nRowInQRow{2};

◆ m_nRow

unsigned ITkPixEncoder::m_nRow {384}
protectedinherited

Definition at line 62 of file ITkPixEncoder.h.

62{400}, m_nRow{384}, m_nCCol{50}, m_nQRow{192}, m_nColInCCol{8}, m_nRowInQRow{2};

◆ m_nRowInQRow

unsigned ITkPixEncoder::m_nRowInQRow {2}
protectedinherited

Definition at line 62 of file ITkPixEncoder.h.

62{400}, m_nRow{384}, m_nCCol{50}, m_nQRow{192}, m_nColInCCol{8}, m_nRowInQRow{2};

◆ m_plainHitMap

bool ITkPixEncoder::m_plainHitMap {}
protectedinherited

Definition at line 77 of file ITkPixEncoder.h.


The documentation for this class was generated from the following files: