ATLAS Offline Software
Public Types | Public Member Functions | Protected Attributes | List of all members
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 ()
 
void addToStream (const HitMap &hitMap, bool last=false)
 
std::vector< uint32_t > & getWords ()
 
void addBits64 (const uint64_t value, const uint8_t length)
 
void pushWords32 ()
 
void encodeQCore (const unsigned nCCol, const unsigned nQRow)
 
void encodeEvent ()
 
void streamTag (const uint8_t nStream)
 
void intTag (const uint16_t nEvt)
 
void scanHitMap ()
 
bool hitInQCore (const unsigned CCol, const unsigned QRow)
 
void setHitMap (const HitMap &hitMap)
 
void setEventsPerStream (const unsigned nEventsPerStream=16)
 

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
 
unsigned m_nEventsPerStream {}
 
unsigned m_currCCol {}
 
unsigned m_currQRow {}
 
unsigned m_currEvent {}
 
uint8_t m_currStream {}
 
uint64_t m_currBlock {}
 
uint8_t m_currBit {}
 
std::vector< std::vector< bool > > m_hitQCores
 
std::vector< unsigned > m_lastQRow
 
bool m_plainHitMap {}
 
bool m_dropToT {}
 
HitMap m_hitMap
 

Detailed Description

Definition at line 16 of file ITkPixV2Encoder.h.

Member Typedef Documentation

◆ HitMap

typedef ITkPixLayout<uint16_t> ITkPixEncoder::HitMap
inherited

Definition at line 21 of file ITkPixEncoder.h.

Member Function Documentation

◆ addBits64()

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

Definition at line 23 of file ITkPixEncoder.cxx.

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

◆ addToStream()

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

Definition at line 18 of file ITkPixV2Encoder.cxx.

18  {
19  //This is a high-level interface function that can take care of
20  //adding an event into the current stream, this can be called
21  //easily from the outside, and automatically tags/ends streams
22  //and events based on internal vars only
23 
24  //If this is the first event, start a new stream. Otherwise, add an
25  //internal tag
26  if (m_currEvent == 0){
28  m_currStream++;
29  }
30  else {
32  }
33 
34  //Then add the actual encoded event information
35  setHitMap(hitMap);
36  encodeEvent();
37  m_currEvent++;
38 
39  //If this is the last event in the stream or if we explicitly
40  //want to end the stream (i. e. total number of generated events
41  //is not a multiple of nEventsPerStream), end the stream
42  if (m_currEvent == m_nEventsPerStream || last){
43  endStream();
44  m_currEvent = 0;
45  }
46 
47 }

◆ encodeEvent()

void ITkPixEncoder::encodeEvent ( )
inherited

Definition at line 151 of file ITkPixEncoder.cxx.

151  {
152  //This produces the bits for one event.
153  //First, scan the map and produce helpers
154  scanHitMap();
155 
156  for (unsigned CCol = 0; CCol < m_nCCol; CCol++){
157  //if there are no hits in this CCol, continue
158  if (m_lastQRow[CCol] == 0) continue;
159  //add the 6-bit (CCol + 1) address
160  addBits64(CCol + 1, 6);
161 
162  int previousQRow = -666;
163  for (unsigned QRow = 0; QRow < m_nQRow; QRow++){
164  //if there's no hit in this row, continue
165  if (!m_hitQCores[CCol][QRow]) continue;
166 
167  //add the isLast bit
168  QRow + 1 == m_lastQRow[CCol] ? addBits64(0x1, 1) : addBits64(0x0, 1);
169 
170  //add the isNeighbor bit. If false, add the QRow address as well.
171  if (QRow == (uint)previousQRow + 1){
172  addBits64(0x1, 1);
173  }
174  else {
175  addBits64(0x0, 1);
176  addBits64(QRow, 8);
177  };
178 
179  //add the map and ToT
180  encodeQCore(CCol, QRow);
181 
182  //update the previous QRow
183  previousQRow = QRow;
184  }
185  }
186 }

◆ encodeQCore()

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

Definition at line 78 of file ITkPixEncoder.cxx.

78  {
79  //produce hit map and ToTs
80  //First, get the top-left pixel in the QCore
81  unsigned col = nCCol * m_nColInCCol;
82  unsigned row = nQRow * m_nRowInQRow;
83 
84  //now loop, store ToTs, and build index of the
85  //compressed hit map in the LUT
86  uint16_t lutIndex = 0x0000;
87  std::vector<uint16_t> tots;
88  tots.reserve(16);
89  int pix = 0;
90  for (unsigned pixRow = row; pixRow < row + m_nRowInQRow; pixRow++){
91  for (unsigned pixCol = col; pixCol < col + m_nColInCCol; pixCol++){
92  if (m_hitMap(pixCol, pixRow)){
93  lutIndex |= 0x1 << pix;
94  tots.push_back(m_hitMap(pixCol, pixRow) - 1);
95  }
96  pix++;
97  }
98  }
99 
100  //now add the binary-tree encoded & compressed map
101  //from the LUT to the stream. If, instead, the plain
102  //hit map is requested, add the index (which is the
103  //plain hit map in fact)
104 
106 
107  //if dropToT is requested, we can return here
108  if (m_dropToT) return;
109 
110  //and add the four-bit ToT information for each hit
111  for (auto& tot : tots){
112  addBits64(tot, 4);
113  }
114 }

◆ endStream()

void ITkPixV2Encoder::endStream ( )

Definition at line 13 of file ITkPixV2Encoder.cxx.

13  {
14  m_currBlock |= (0x1ULL << 63);
15  pushWords32();
16 }

◆ getWords()

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

Definition at line 28 of file ITkPixEncoder.h.

28 {return m_words;}

◆ hitInQCore()

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

Definition at line 116 of file ITkPixEncoder.cxx.

116  {
117  //Was there a hit in this QCore?
118 
119  unsigned col = CCol * m_nColInCCol;
120  unsigned row = QRow * m_nRowInQRow;
121 
122  for (unsigned pixRow = row; pixRow < row + m_nRowInQRow; pixRow++){
123  for (unsigned pixCol = col; pixCol < col + m_nColInCCol; pixCol++){
124  if (m_hitMap(pixCol, pixRow)) return true;
125  }
126  }
127 
128  return false;
129 }

◆ intTag()

void ITkPixEncoder::intTag ( const uint16_t  nEvt)
inherited

Definition at line 193 of file ITkPixEncoder.cxx.

193  {
194  //this adds 11 bits of interal tagging between events.
195  //does the tag always need to start with 111?
196  uint16_t tag = nEvt | (0b111 << 8);
197  addBits64(tag, 11);
198 }

◆ pushWords32()

void ITkPixEncoder::pushWords32 ( )
inherited

Definition at line 66 of file ITkPixEncoder.cxx.

66  {
67  //whenever the current block is ready for output,
68  //split it into two 32-bit words and push them to
69  //the output container. Reset the current bloc/bit
70  uint32_t word1 = m_currBlock >> 32;
71  uint32_t word2 = m_currBlock & 0xFFFFFFFF;
72  m_words.push_back(word1);
73  m_words.push_back(word2);
74  m_currBlock = 0x0ULL;
75  m_currBit = 0;
76 }

◆ scanHitMap()

void ITkPixEncoder::scanHitMap ( )
inherited

Definition at line 131 of file ITkPixEncoder.cxx.

131  {
132  //Fill in a helper map of hit QCores and a vector of last qrow in each ccol
133  m_hitQCores = std::vector<std::vector<bool>>(m_nCCol, std::vector<bool>(m_nQRow, false));
134  m_lastQRow = std::vector<unsigned> (m_nCCol, 0);
135 
136  for (unsigned CCol = 0; CCol < m_nCCol; CCol++){
137  for (unsigned QRow = 0; QRow < m_nQRow; QRow++){
138  //if there's a hit in the qcore, flag the helper map
139  m_hitQCores[CCol][QRow] = hitInQCore(CCol, QRow);
140 
141  //and keep track of the last qrow in each CCol, so that we can
142  //easily set the isLast bit. Numbering starts at 1, in order to
143  //keep the m_lastQRow[CCol] == 0 case denoting "no hit" in the CCol
144  //to save some looping/ifs later on
145  if (m_hitQCores[CCol][QRow]) m_lastQRow[CCol] = QRow + 1;
146  }
147  }
148 
149 }

◆ setEventsPerStream()

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

Definition at line 48 of file ITkPixEncoder.h.

48 {m_nEventsPerStream = nEventsPerStream;}

◆ setHitMap()

void ITkPixEncoder::setHitMap ( const HitMap hitMap)
inlineinherited

Definition at line 46 of file ITkPixEncoder.h.

46 {m_hitMap = hitMap;}

◆ streamTag()

void ITkPixEncoder::streamTag ( const uint8_t  nStream)
inherited

Definition at line 188 of file ITkPixEncoder.cxx.

188  {
189  //this adds the 8-bit 'global' stream tag
190  addBits64(nStream, 8);
191 }

Member Data Documentation

◆ m_currBit

uint8_t ITkPixEncoder::m_currBit {}
protectedinherited

Definition at line 61 of file ITkPixEncoder.h.

◆ m_currBlock

uint64_t ITkPixEncoder::m_currBlock {}
protectedinherited

Definition at line 60 of file ITkPixEncoder.h.

◆ m_currCCol

unsigned ITkPixEncoder::m_currCCol {}
protectedinherited

Definition at line 56 of file ITkPixEncoder.h.

◆ m_currEvent

unsigned ITkPixEncoder::m_currEvent {}
protectedinherited

Definition at line 56 of file ITkPixEncoder.h.

◆ m_currQRow

unsigned ITkPixEncoder::m_currQRow {}
protectedinherited

Definition at line 56 of file ITkPixEncoder.h.

◆ m_currStream

uint8_t ITkPixEncoder::m_currStream {}
protectedinherited

Definition at line 57 of file ITkPixEncoder.h.

◆ m_dropToT

bool ITkPixEncoder::m_dropToT {}
protectedinherited

Definition at line 66 of file ITkPixEncoder.h.

◆ m_hitMap

HitMap ITkPixEncoder::m_hitMap
protectedinherited

Definition at line 69 of file ITkPixEncoder.h.

◆ m_hitQCores

std::vector<std::vector<bool> > ITkPixEncoder::m_hitQCores
protectedinherited

Definition at line 62 of file ITkPixEncoder.h.

◆ m_lastQRow

std::vector<unsigned> ITkPixEncoder::m_lastQRow
protectedinherited

Definition at line 63 of file ITkPixEncoder.h.

◆ m_nCCol

unsigned ITkPixEncoder::m_nCCol {50}
protectedinherited

Definition at line 52 of file ITkPixEncoder.h.

◆ m_nCol

unsigned ITkPixEncoder::m_nCol {400}
protectedinherited

Definition at line 52 of file ITkPixEncoder.h.

◆ m_nColInCCol

unsigned ITkPixEncoder::m_nColInCCol {8}
protectedinherited

Definition at line 52 of file ITkPixEncoder.h.

◆ m_nEventsPerStream

unsigned ITkPixEncoder::m_nEventsPerStream {}
protectedinherited

Definition at line 56 of file ITkPixEncoder.h.

◆ m_nQRow

unsigned ITkPixEncoder::m_nQRow {192}
protectedinherited

Definition at line 52 of file ITkPixEncoder.h.

◆ m_nRow

unsigned ITkPixEncoder::m_nRow {384}
protectedinherited

Definition at line 52 of file ITkPixEncoder.h.

◆ m_nRowInQRow

unsigned ITkPixEncoder::m_nRowInQRow {2}
protectedinherited

Definition at line 52 of file ITkPixEncoder.h.

◆ m_plainHitMap

bool ITkPixEncoder::m_plainHitMap {}
protectedinherited

Definition at line 66 of file ITkPixEncoder.h.

◆ m_words

std::vector<uint32_t> ITkPixEncoder::m_words
protectedinherited

Definition at line 55 of file ITkPixEncoder.h.


The documentation for this class was generated from the following files:
ITkPixEncoding::ITkPixV2QCoreEncodingLUT_Length
constexpr std::array< uint32_t, LookUpTableSize > ITkPixV2QCoreEncodingLUT_Length
Definition: ITkPixQCoreEncodingLUT.h:116
ITkPixEncoder::streamTag
void streamTag(const uint8_t nStream)
Definition: ITkPixEncoder.cxx:188
query_example.row
row
Definition: query_example.py:24
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
ITkPixEncoder::m_lastQRow
std::vector< unsigned > m_lastQRow
Definition: ITkPixEncoder.h:63
ITkPixEncoder::m_currStream
uint8_t m_currStream
Definition: ITkPixEncoder.h:57
xAOD::word1
word1
Definition: eFexEMRoI_v1.cxx:82
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
ITkPixEncoder::m_hitMap
HitMap m_hitMap
Definition: ITkPixEncoder.h:69
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
athena.value
value
Definition: athena.py:122
ITkPixEncoder::m_hitQCores
std::vector< std::vector< bool > > m_hitQCores
Definition: ITkPixEncoder.h:62
ITkPixEncoding
Definition: ITkPixQCoreEncodingLUT.h:14
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
ITkPixEncoder::m_dropToT
bool m_dropToT
Definition: ITkPixEncoder.h:66
ITkPixEncoder::m_nRowInQRow
unsigned m_nRowInQRow
Definition: ITkPixEncoder.h:52
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
ITkPixEncoder::m_words
std::vector< uint32_t > m_words
Definition: ITkPixEncoder.h:55
ITkPixEncoder::m_nEventsPerStream
unsigned m_nEventsPerStream
Definition: ITkPixEncoder.h:56
ITkPixEncoder::m_nColInCCol
unsigned m_nColInCCol
Definition: ITkPixEncoder.h:52
ITkPixV2Encoder::endStream
void endStream()
Definition: ITkPixV2Encoder.cxx:13
ITkPixEncoder::hitInQCore
bool hitInQCore(const unsigned CCol, const unsigned QRow)
Definition: ITkPixEncoder.cxx:116
ITkPixEncoder::intTag
void intTag(const uint16_t nEvt)
Definition: ITkPixEncoder.cxx:193
ITkPixEncoder::m_currEvent
unsigned m_currEvent
Definition: ITkPixEncoder.h:56
ITkPixEncoder::m_plainHitMap
bool m_plainHitMap
Definition: ITkPixEncoder.h:66
ITkPixEncoder::m_currBit
uint8_t m_currBit
Definition: ITkPixEncoder.h:61
LB_AnalMapSplitter.tot
tot
Definition: LB_AnalMapSplitter.py:46
ITkPixEncoder::setHitMap
void setHitMap(const HitMap &hitMap)
Definition: ITkPixEncoder.h:46
ITkPixEncoder::m_nCCol
unsigned m_nCCol
Definition: ITkPixEncoder.h:52
ITkPixEncoder::pushWords32
void pushWords32()
Definition: ITkPixEncoder.cxx:66
ITkPixEncoder::m_currBlock
uint64_t m_currBlock
Definition: ITkPixEncoder.h:60
query_example.col
col
Definition: query_example.py:7
ITkPixEncoder::encodeQCore
void encodeQCore(const unsigned nCCol, const unsigned nQRow)
Definition: ITkPixEncoder.cxx:78
ITkPixEncoder::addBits64
void addBits64(const uint64_t value, const uint8_t length)
Definition: ITkPixEncoder.cxx:23
ITkPixEncoder::encodeEvent
void encodeEvent()
Definition: ITkPixEncoder.cxx:151
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
ITkPixEncoder::m_nQRow
unsigned m_nQRow
Definition: ITkPixEncoder.h:52
pix
Definition: PixelMapping.cxx:16
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
ITkPixEncoder::scanHitMap
void scanHitMap()
Definition: ITkPixEncoder.cxx:131
ITkPixEncoding::ITkPixV2QCoreEncodingLUT_Tree
constexpr std::array< uint32_t, LookUpTableSize > ITkPixV2QCoreEncodingLUT_Tree
Definition: ITkPixQCoreEncodingLUT.h:115