ATLAS Offline Software
Loading...
Searching...
No Matches
RpcByteStreamDecoder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7namespace {
8 constexpr unsigned int const rpcRawHitWordLength = 7;
9}
10
12 MsgStream* log) :
13 m_bytestream(p_bytestream), m_cabling(readCdo), m_rpcIdHelper(rpcId) {
14 m_rpcpads = new std::vector<RpcPad*>;
15 m_log = log;
16 if (m_log) {
17 m_debug = m_log->level() <= MSG::DEBUG;
18 m_verbose = m_log->level() <= MSG::VERBOSE;
19 } else {
20 m_debug = false;
21 m_verbose = false;
22 }
23}
24
26 if (m_rpcpads != nullptr) {
27 delete m_rpcpads;
28 m_rpcpads = nullptr;
29 }
30}
31
33 if (m_debug && m_log) *m_log << MSG::DEBUG << "Start decoding" << endmsg;
34
35 PAD_Readout padReadout = m_bytestream->pad_readout();
36
37 // Iterate on the readout PADS and decode them
38 for (PAD_Readout::iterator it = padReadout.begin(); it != padReadout.end(); ++it) {
39 PADreadout pad = (*it).second;
40 RpcPad* newpad = decodePad(pad);
41
42 // Push back the decoded pad in the vector
43 m_rpcpads->push_back(newpad);
44 }
45
46 if (m_debug && m_log) *m_log << MSG::DEBUG << "Number of decoded Pads : " << m_rpcpads->size() << endmsg;
47
48 return StatusCode::SUCCESS;
49}
50
51// Decode a pad and return a pointer to a RpcPad RDO
53 if (m_debug && m_log) *m_log << MSG::DEBUG << "Decoding a new RpcPad" << endmsg;
54
55 // Identifier elements
56 int name = 0;
57 int eta = 0;
58 int phi = 0;
59 int doublet_r = 0;
60 int doublet_z = 0;
61 int doublet_phi = 0;
62 int gas_gap = 0;
63 int measures_phi = 0;
64 int strip = 0;
65
66 PadReadOut* readout = pad.give_pad_readout();
67
68 // Retrieve PAD sector and PAD ID
69 int sector = pad.sector();
70 int pad_id = pad.PAD();
71 // Compute side and logic sector
72 int side = (sector < 32) ? 0 : 1;
73 int logic_sector = sector % 32;
74 // Compute the key to retrieve the offline id from the map (as from LVL1 sim.)
75 int key = side * 10000 + logic_sector * 100 + pad_id;
76
77 if (m_debug && m_log) *m_log << MSG::DEBUG << "Pad: Side " << side << " Sector logic" << logic_sector << " Id " << pad_id << endmsg;
78
79 // Retrieve the identifier elements from the map
80 const RpcCablingCondData::RDOmap& pad_map = m_cabling->give_RDOs();
81 auto foundPair = pad_map.find(key);
82 if (foundPair == pad_map.end()) return nullptr;
83 RDOindex index = foundPair->second;
84
85 index.offline_indexes(name, eta, phi, doublet_r, doublet_z, doublet_phi, gas_gap, measures_phi, strip);
86
87 // Build the pad offline identifier
88 bool valid{false};
89 Identifier id = m_rpcIdHelper->padID(name, eta, phi, doublet_r, doublet_z, doublet_phi, valid);
90
91 if (m_log && !valid) {
92 *m_log << MSG::ERROR << "Invalid pad offline indices " << endmsg;
93 *m_log << MSG::ERROR << "Name : " << name << endmsg;
94 *m_log << MSG::ERROR << "Eta " << eta << " Phi " << phi << endmsg;
95 *m_log << MSG::ERROR << "Doublet r " << doublet_r << " Doublet_z " << doublet_z << " Doublet_phi " << doublet_phi << endmsg;
96 *m_log << MSG::ERROR << "Gas gap " << gas_gap << " Measures_phi " << measures_phi << " Strip " << strip << endmsg;
97 }
98
99 // Retrieve Pad status and error code from Pad header and footer
100 PadReadOutStructure pad_header = readout->getHeader();
101 PadReadOutStructure pad_footer = readout->getFooter();
102 // Check the data format
103 // cppcheck-suppress assertWithSideEffect
104 assert(pad_header.isHeader());
105 // cppcheck-suppress assertWithSideEffect
106 assert(pad_footer.isFooter());
107
108 unsigned int hashId = index.hash();
109 unsigned int onlineId = pad_id;
110 // unsigned int status = pad_header.status();
111 unsigned int status = 0;
112 unsigned int errorCode = pad_footer.errorCode();
113
114 // Construct the new Pad
115 RpcPad* rpc_pad = new RpcPad(id, hashId, onlineId, status, errorCode, sector);
116
117 // Iterate on the matrices and decode them
118 for (int i = 0; i < readout->numberOfCMROFragments(); ++i) {
119 MatrixReadOut* matrix = pad.matrices_readout(i);
120 RpcCoinMatrix* coinMatrix = decodeMatrix(matrix, id);
121 // Add the matrix to the pad
122 rpc_pad->push_back(coinMatrix);
123 }
124
125 if (m_debug && m_log) *m_log << MSG::DEBUG << "Number of matrices in Pad : " << rpc_pad->size() << endmsg;
126
127 return rpc_pad;
128}
129
130// Function decoding a coincidence matrix
132 if (m_debug && m_log) *m_log << MSG::DEBUG << "Decoding a new RpcCoinMatrix" << endmsg;
133
134 // Matrix Header and SubHeader
135 MatrixReadOutStructure matrix_header = matrix->getHeader();
136 MatrixReadOutStructure matrix_subheader = matrix->getSubHeader();
137 MatrixReadOutStructure matrix_footer = matrix->getFooter();
138 // Check the data structure
139 // cppcheck-suppress assertWithSideEffect
140 assert(matrix_header.isHeader());
141 // cppcheck-suppress assertWithSideEffect
142 assert(matrix_subheader.isSubHeader());
143 // cppcheck-suppress assertWithSideEffect
144 assert(matrix_footer.isFooter());
145
146 // Create the coincidence matrix
147 RpcCoinMatrix* coinMatrix =
148 new RpcCoinMatrix(id, matrix_header.cmid(), matrix_footer.crc(), matrix_header.fel1id(), matrix_subheader.febcid());
149
150 // Iterate on fired channels and decode them
152 for (int j = 0; j < matrix->numberOfBodyWords(); ++j) {
153 cm_hit = matrix->getCMAHit(j);
154 // cppcheck-suppress assertWithSideEffect
155 assert(cm_hit.isBody());
156 RpcFiredChannel* firedChannel = nullptr;
157
158 if (cm_hit.ijk() < rpcRawHitWordLength) {
159 firedChannel = new RpcFiredChannel(cm_hit.bcid(), cm_hit.time(), cm_hit.ijk(), cm_hit.channel());
160 } else if (cm_hit.ijk() == rpcRawHitWordLength) {
161 firedChannel = new RpcFiredChannel(cm_hit.bcid(), cm_hit.time(), cm_hit.ijk(), cm_hit.threshold(), cm_hit.overlap());
162 }
163
164 coinMatrix->push_back(firedChannel);
165 }
166
167 if (m_debug && m_log) *m_log << MSG::DEBUG << "Number of Fired Channels in Matrix : " << coinMatrix->size() << endmsg;
168 return coinMatrix;
169}
170
171// Printout the RDOs for testing
173 std::cout << "Printing out RPC RDO's : " << std::endl;
174 std::cout << "Number of Pads in event : " << m_rpcpads->size() << std::endl;
175 std::vector<RpcPad*>::const_iterator pad_it;
176 int ipad = 1;
177 // Iterate on pads
178 for (pad_it = m_rpcpads->begin(); pad_it != m_rpcpads->end(); ++pad_it, ++ipad) {
179 std::cout << "Pad number " << ipad << " Identifier : " << std::endl;
180 (*pad_it)->identify().show();
181 std::cout << std::endl;
182 std::cout << "Number of Matrices in Pad : " << (*pad_it)->size() << std::endl;
183 // Iterate on the pad's coincidence matrices
185 int imat = 1;
186 for (mat_it = (*pad_it)->begin(); mat_it != (*pad_it)->end(); ++mat_it, ++imat) {
187 std::cout << "Matrix number " << imat << std::endl;
188 std::cout << "Number of fired channels: " << (*mat_it)->size() << std::endl;
190 int ichan = 1;
191 // Printout the fired channels
192 for (chan_it = (*mat_it)->begin(); chan_it != (*mat_it)->end(); ++chan_it, ++ichan) {
193 std::cout << "Fired Channel " << ichan << " :: bcid " << (*chan_it)->bcid() << " ijk " << (*chan_it)->ijk()
194 << " channel " << (*chan_it)->channel() << std::endl;
195 }
196 }
197 }
198}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define endmsg
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current RpcCoinMatrix
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current RpcPad
std::map< int, PADreadout, std::less< int > > PAD_Readout
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
PadReadOut * give_pad_readout(void)
MatrixReadOut * matrices_readout(int) const
int sector(void) const
Definition PADreadout.h:40
int PAD(void) const
Definition PADreadout.h:41
PadReadOutStructure getFooter()
PadReadOutStructure getHeader()
ubit16 numberOfCMROFragments()
Definition PadReadOut.h:30
RpcCoinMatrix * decodeMatrix(MatrixReadOut *matrix, Identifier &id)
const RpcCablingCondData * m_cabling
RpcPad * decodePad(PADreadout &pad)
const RpcIdHelper * m_rpcIdHelper
std::vector< RpcPad * > * m_rpcpads
RpcByteStreamDecoder(const RPCbytestream *p_bytestream, const RpcCablingCondData *readCdo, const RpcIdHelper *rpcId, MsgStream *log=nullptr)
const RPCbytestream * m_bytestream
std::map< int, RDOindex, std::less< int > > RDOmap
Definition index.py:1