ATLAS Offline Software
Loading...
Searching...
No Matches
TgcByteStream.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TgcByteStream.h"
6
7#include "GaudiKernel/MsgStream.h"
8#include "MuonRDO/TgcRdo.h"
9#include "TgcByteStreamData.h"
10
12
14
16 MsgStream& log) {
17 bool p_debug = (log.level() <= MSG::DEBUG);
18
19 if (p_debug) {
20 log << MSG::DEBUG << "TgcByteStream::rdo2ByteStream" << endmsg;
21 }
22
23 ByteStream headerBS, statusBS, countersBS, dataBS, footerBS;
24 TGC_BYTESTREAM_FRAGMENTCOUNT counters[7] = {{0, 1}, {0, 2}, {0, 3}, {0, 4},
25 {0, 5}, {0, 8}, {0, 9}};
27
28 if (p_debug) {
29 log << MSG::DEBUG << "Encoding " << rdo->size() << " elements"
30 << endmsg;
31 }
32
33 for (const TgcRawData* raw : *rdo) {
34 switch (raw->type()) {
36 ls.hitsRO = 1;
37 counters[1].count++;
38 {
40 roh.channel = raw->channel() - 40;
41 roh.sbId = raw->slbId();
42 // revised document :
43 // https://twiki.cern.ch/twiki/pub/Main/TgcDocument/ROBformat_V4_0_v2.pdf
44 // (old ver. : http://cern.ch/atlas-tgc/doc/ROBformat.pdf)
45 // Table 7 : SB type, bits 15..13
46 // 0,1: doublet wire, strip
47 // 2,3: triplet wire, strip triplet;
48 // 4 : inner wire and strip
49 // TgcRawData::SlbType is defined in TgcRawData.h
50 // 0: SLB_TYPE_DOUBLET_WIRE,
51 // 1: SLB_TYPE_DOUBLET_STRIP,
52 // 2: SLB_TYPE_TRIPLET_WIRE,
53 // 3: SLB_TYPE_TRIPLET_STRIP,
54 // 4: SLB_TYPE_INNER_WIRE,
55 // 5: SLB_TYPE_INNER_STRIP,
56 // 6: SLB_TYPE_UNKNOWN
57 roh.sbType = raw->slbType();
58
59 // SBLOCs for EIFI are different in online (ByteStream) and
60 // offline (RDO). bug #57051: Wrong numbering of SBLOC for
61 // Inner Stations (EI/FI) in 12-fold TGC cablings ByteStream
62 // : slbId = SBLOC + ip*2 (ip=0, 1, 2), SBLOC = 8 or 9 (EI),
63 // 0 or 1 (FI)
64 // slbId = 8, 10, 12, 9, 11, 13, 0, 2, 4,
65 // 1, 3, 5
66 // RDO : slbId = SBLOC + ip*4 (ip=0, 1, 2), SBLOC = 1
67 // or 3 (EI), 0 or 2 (FI)
68 // slbId = 1, 5, 9, 3, 7, 11, 0, 4, 8,
69 // 2, 6, 10
72 if (raw->slbId() % 2 == 0) {
73 roh.sbId = raw->slbId() / 2;
74 } else {
75 roh.sbId = (raw->slbId() + 15) / 2;
76 }
77 }
78
79 roh.adj = raw->isAdjacent();
80 roh.ldbId = raw->sswId();
81 roh.bcBitmap = bcBitmap(raw->bcTag());
82 roh.tracklet = raw->tracklet();
83 roh.ok = 1;
84 dataBS.push_back(toBS32(roh));
85 }
86 break;
88 ls.trkRO = 1;
89 counters[2].count++;
90 if (raw->slbType() == TgcRawData::SLB_TYPE_TRIPLET_STRIP) {
92 rot.phi = raw->position();
93 rot.seg = raw->segment();
94 rot.sbId = raw->slbId();
95 rot.ldbId = raw->sswId();
96 rot.bcBitmap = bcBitmap(raw->bcTag());
98 rot.ok = 1;
99 dataBS.push_back(toBS32(rot));
100 } else {
102 rot.rphi = raw->position();
103 rot.subm = raw->subMatrix();
104 rot.seg = raw->segment();
105 rot.delta = raw->delta();
106 rot.sbId = raw->slbId();
107 rot.ldbId = raw->sswId();
108 rot.bcBitmap = bcBitmap(raw->bcTag());
109 // revised document :
110 // https://twiki.cern.ch/twiki/pub/Main/TgcDocument/ROBformat_V4_0_v2.pdf
111 // (old ver. : http://cern.ch/atlas-tgc/doc/ROBformat.pdf)
112 // Table 8 : Slave Board type, bits 30..28
113 // 0,1: doublet wire, strip
114 // 2,3: triplet wire, strip triplet;
115 // 4,5: inner wire, strip
116 // TgcRawData::SlbType is defined in TgcRawData.h
117 // 0: SLB_TYPE_DOUBLET_WIRE,
118 // 1: SLB_TYPE_DOUBLET_STRIP,
119 // 2: SLB_TYPE_TRIPLET_WIRE,
120 // 3: SLB_TYPE_TRIPLET_STRIP,
121 // 4: SLB_TYPE_INNER_WIRE,
122 // 5: SLB_TYPE_INNER_STRIP,
123 // 6: SLB_TYPE_UNKNOWN
124 rot.slbType = raw->slbType();
125 rot.ok = 1;
126 dataBS.push_back(toBS32(rot));
127 }
128 break;
130 ls.hipt = 1;
131 counters[5].count++;
132 if (raw->isStrip() == 1 && raw->sector() & 4) {
134 hpt.inner = raw->inner();
135 // hpt.hipt = raw->isHipt();
136 // hpt.cand = raw->index();
137 // hpt.chip = raw->chip();
138 hpt.sector = raw->sector();
139 // hpt.fwd = raw->isForward();
140 hpt.strip = raw->isStrip();
141 hpt.bcBitmap = bcBitmap(raw->bcTag());
142 dataBS.push_back(toBS32(hpt));
143 } else {
145 hpt.delta = raw->delta();
146 hpt.sub = raw->hsub();
147 hpt.hitId = raw->hitId();
148 hpt.hipt = raw->isHipt();
149 hpt.cand = raw->index();
150 hpt.chip = raw->chip();
151 hpt.sector = raw->sector();
152 hpt.fwd = raw->isForward();
153 hpt.strip = raw->isStrip();
154 hpt.bcBitmap = bcBitmap(raw->bcTag());
155 dataBS.push_back(toBS32(hpt));
156 }
157 break;
159 ls.sl = 1;
160 counters[6].count++;
161 {
163 sl.roi = raw->roi();
164 sl.overlap = raw->isOverlap();
165 sl.veto = raw->isVeto();
166 sl.threshold = raw->threshold();
167 sl.sign = raw->isMuplus();
168 sl.cand = raw->index();
169 sl.sector = raw->sector();
170 sl.fwd = raw->isForward();
171 sl.bcBitmap = bcBitmap(raw->bcTag());
172 sl.cand2plus = raw->cand3plus();
173 dataBS.push_back(toBS32(sl));
174 }
175 break;
176 default:
177 log << MSG::ERROR << "Invalid type " << raw->typeName()
178 << endmsg;
179 break;
180 }
181 }
182
183 statusBS.push_back(toBS32(ls));
184 statusBS.push_back(rdo->orbit());
185
186 for (int iCnt = 0; iCnt < 7; iCnt++) {
187 if (counters[iCnt].count > 0) {
188 countersBS.push_back(toBS32(counters[iCnt]));
189 }
190 }
191
192 bs.clear();
193 bs.insert(bs.end(), countersBS.begin(), countersBS.end());
194 bs.insert(bs.end(), dataBS.begin(), dataBS.end());
195
196 if (p_debug) {
197 log << MSG::DEBUG << "TgcByteStream::rdo2ByteStream done" << endmsg;
198 }
199}
200
202 uint32_t source_id, MsgStream& log) {
203 // Check that we are filling the right collection
204
205 bool p_debug = (log.level() <= MSG::DEBUG);
206
208 fromBS32(source_id, sid);
209
210 if (rdo.identify() != TgcRdo::calculateOnlineId(sid.side, sid.rodid)) {
211 if (p_debug) {
212 log << MSG::DEBUG
213 << "Error: input TgcRdo id does not match bytestream id"
214 << endmsg;
215 }
216 return;
217 }
218
219 rdo.setOnlineId(sid.side, sid.rodid);
220
221 TGC_BYTESTREAM_FRAGMENTCOUNT counters[7] = {{0, 1}, {0, 2}, {0, 3}, {0, 4},
222 {0, 5}, {0, 8}, {0, 9}};
224
225 int iBs = 0;
226 for (int iCnt = 0; iCnt < 7; iCnt++) {
227 fromBS32(bs[iBs], counter);
228 if (counter.id == counters[iCnt].id) {
229 counters[iCnt].count = counter.count;
230 iBs++;
231 }
232 }
233
234 for (int iCnt = 0; iCnt < 7; iCnt++) {
235 if (counters[iCnt].count == 0) {
236 continue;
237 }
238 switch (counters[iCnt].id) {
239 case 1: // Raw data format (SSW format)
240 {
241 if (p_debug) {
242 log << MSG::DEBUG << "fragment" << counters[iCnt].id << " "
243 << counters[iCnt].count << "words" << endmsg;
244 }
245 for (unsigned iFrag = 0; iFrag < counters[iCnt].count;
246 iFrag++) {
247 if (p_debug) {
248 log << MSG::DEBUG << "WORD" << iFrag << ":" << MSG::hex
249 << bs[iBs] << endmsg;
250 }
251 iBs++;
252 }
253 break;
254 }
255
256 case 2: // TgcRawData::TYPE_HIT
257 {
258 if (p_debug) {
259 log << MSG::DEBUG << "fragment" << counters[iCnt].id << " "
260 << counters[iCnt].count << "words" << endmsg;
261 }
263 for (unsigned iFrag = 0; iFrag < counters[iCnt].count;
264 iFrag++) {
265 if (p_debug) {
266 log << MSG::DEBUG << "WORD" << iFrag << ":" << MSG::hex
267 << bs[iBs] << endmsg;
268 }
269 fromBS32(bs[iBs++], roh);
270
271 if (p_debug) {
272 log << MSG::DEBUG
273 << " rdo.subDetectorId():" << rdo.subDetectorId()
274 << " rdo.rodId():" << rdo.rodId()
275 << " roh.ldbId:" << roh.ldbId
276 << " roh.sbId:" << roh.sbId
277 << " rdo.l1Id():" << rdo.l1Id()
278 << " rdo.bcId():" << rdo.bcId() << endmsg;
279 }
280
281 uint16_t slbId = roh.sbId;
282 // SBLOCs for EIFI are different in online (ByteStream) and
283 // offline (RDO). bug #57051: Wrong numbering of SBLOC for
284 // Inner Stations (EI/FI) in 12-fold TGC cablings ByteStream
285 // : slbId = SBLOC + ip*2 (ip=0, 1, 2), SBLOC = 8 or 9 (EI),
286 // 0 or 1 (FI)
287 // slbId = 8, 10, 12, 9, 11, 13, 0, 2, 4,
288 // 1, 3, 5
289 // RDO : slbId = SBLOC + ip*4 (ip=0, 1, 2), SBLOC = 1
290 // or 3 (EI), 0 or 2 (FI)
291 // slbId = 1, 5, 9, 3, 7, 11, 0, 4, 8,
292 // 2, 6, 10
295 if (roh.sbId < 8) {
296 slbId = roh.sbId * 2;
297 } else {
298 slbId = (roh.sbId - 8) * 2 + 1;
299 }
300 }
301
302 TgcRawData* raw = new TgcRawData(
303 bcTag(roh.bcBitmap), rdo.subDetectorId(), rdo.rodId(),
304 roh.ldbId, slbId, rdo.l1Id(), rdo.bcId(),
305 // revised document :
306 // https://twiki.cern.ch/twiki/pub/Main/TgcDocument/ROBformat_V4_0_v2.pdf
307 // (old ver. :
308 // http://cern.ch/atlas-tgc/doc/ROBformat.pdf) Table 7 :
309 // SB type, bits 15..13 0,1: doublet wire, strip 2,3:
310 // triplet wire, strip triplet; 4 : inner wire and
311 // strip TgcRawData::SlbType is defined in TgcRawData.h
312 // 0: SLB_TYPE_DOUBLET_WIRE,
313 // 1: SLB_TYPE_DOUBLET_STRIP,
314 // 2: SLB_TYPE_TRIPLET_WIRE,
315 // 3: SLB_TYPE_TRIPLET_STRIP,
316 // 4: SLB_TYPE_INNER_WIRE,
317 // 5: SLB_TYPE_INNER_STRIP,
318 // 6: SLB_TYPE_UNKNOWN
319 (TgcRawData::SlbType)roh.sbType, (bool)roh.adj,
320 roh.tracklet, roh.channel + 40);
321 rdo.push_back(raw);
322 }
323 break;
324 }
325 case 3: // TgcRawData::TYPE_TRACKLET
326 {
327 if (p_debug) {
328 log << MSG::DEBUG << "fragment" << counters[iCnt].id << " "
329 << counters[iCnt].count << "words" << endmsg;
330 }
333 for (unsigned iFrag = 0; iFrag < counters[iCnt].count;
334 iFrag++) {
335 if (p_debug) {
336 log << MSG::DEBUG << "WORD" << iFrag << ":" << MSG::hex
337 << bs[iBs] << endmsg;
338 }
339 fromBS32(bs[iBs], rostrip);
340
342 TgcRawData* raw = new TgcRawData(
343 bcTag(rostrip.bcBitmap), rdo.subDetectorId(),
344 rdo.rodId(), rostrip.ldbId, rostrip.sbId,
345 rdo.l1Id(), rdo.bcId(),
347 rostrip.subc, rostrip.phi);
348 rdo.push_back(raw);
349 } else {
350 fromBS32(bs[iBs], rotrk);
351 TgcRawData* raw = new TgcRawData(
352 bcTag(rotrk.bcBitmap), rdo.subDetectorId(),
353 rdo.rodId(), rotrk.ldbId, rotrk.sbId, rdo.l1Id(),
354 rdo.bcId(),
355 // revised document :
356 // https://twiki.cern.ch/twiki/pub/Main/TgcDocument/ROBformat_V4_0_v2.pdf
357 // (old ver. :
358 // http://cern.ch/atlas-tgc/doc/ROBformat.pdf) Table
359 // 8 : Slave Board type, bits 30..28 0,1: doublet
360 // wire, strip 2,3: triplet wire, strip triplet;
361 // 4,5: inner wire, strip
362 // TgcRawData::SlbType is defined in TgcRawData.h
363 // 0: SLB_TYPE_DOUBLET_WIRE,
364 // 1: SLB_TYPE_DOUBLET_STRIP,
365 // 2: SLB_TYPE_TRIPLET_WIRE,
366 // 3: SLB_TYPE_TRIPLET_STRIP,
367 // 4: SLB_TYPE_INNER_WIRE,
368 // 5: SLB_TYPE_INNER_STRIP,
369 // 6: SLB_TYPE_UNKNOWN
370 (TgcRawData::SlbType)rotrk.slbType, rotrk.delta,
371 rotrk.seg, 0, rotrk.rphi);
372 rdo.push_back(raw);
373 }
374 iBs++;
375 }
376 break;
377 }
378 case 8: // TgcRawData::TYPE_HIPT
379 {
380 if (p_debug) {
381 log << MSG::DEBUG << "fragment" << counters[iCnt].id << " "
382 << counters[iCnt].count << "words" << endmsg;
383 }
386 for (unsigned iFrag = 0; iFrag < counters[iCnt].count;
387 iFrag++) {
388 if (p_debug) {
389 log << MSG::DEBUG << "WORD" << iFrag << ":" << MSG::hex
390 << bs[iBs] << endmsg;
391 }
392 fromBS32(bs[iBs], hptinner);
393 if (hptinner.sector & 4) {
394 TgcRawData* raw = new TgcRawData(
395 bcTag(hpt.bcBitmap), rdo.subDetectorId(),
396 rdo.rodId(), rdo.l1Id(), rdo.bcId(), hptinner.strip,
397 0, hptinner.sector, 0, 0, 0, 0, 0, 0,
398 hptinner.inner);
399 rdo.push_back(raw);
400 } else {
401 fromBS32(bs[iBs], hpt);
402 TgcRawData* raw = new TgcRawData(
403 bcTag(hpt.bcBitmap), rdo.subDetectorId(),
404 rdo.rodId(), rdo.l1Id(), rdo.bcId(), hpt.strip,
405 hpt.fwd, hpt.sector, hpt.chip, hpt.cand, hpt.hipt,
406 hpt.hitId, hpt.sub, hpt.delta, 0);
407 rdo.push_back(raw);
408 }
409 iBs++;
410 }
411 break;
412 }
413 case 9: // TgcRawData::TYPE_SL
414 {
415 if (p_debug) {
416 log << MSG::DEBUG << "fragment" << counters[iCnt].id << " "
417 << counters[iCnt].count << "words" << endmsg;
418 }
420 for (unsigned iFrag = 0; iFrag < counters[iCnt].count;
421 iFrag++) {
422 if (p_debug) {
423 log << MSG::DEBUG << "WORD" << iFrag << ":" << MSG::hex
424 << bs[iBs] << endmsg;
425 }
426 fromBS32(bs[iBs++], sl);
427
428 TgcRawData* raw = new TgcRawData(
429 bcTag(sl.bcBitmap), rdo.subDetectorId(), rdo.rodId(),
430 rdo.l1Id(), rdo.bcId(), sl.cand2plus,
431 static_cast<bool>(sl.fwd), sl.sector, sl.cand, sl.sign,
432 sl.threshold, sl.overlap, sl.veto, sl.roi);
433 rdo.push_back(raw);
434 }
435 break;
436 }
437 default:
438 if (p_debug) {
439 log << MSG::DEBUG
440 << "Error: TgcByteStream::byteStream2Rdo Unsupported "
441 "fragment type "
442 << counters[iCnt].id << endmsg;
443 }
444 break;
445 }
446 }
447
448 if (p_debug) {
449 log << MSG::DEBUG << "Decoded " << MSG::dec << rdo.size() << " elements"
450 << endmsg;
451 log << MSG::DEBUG << "TgcByteStream::byteStream2Rdo done" << endmsg;
452 }
453}
#define endmsg
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current TgcRawData
unsigned bcBitmap(uint16_t bcTag)
uint32_t toBS32(T &data)
void fromBS32(uint32_t data, T &s)
unsigned bcTag(unsigned bcBitMap)
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.
std::vector< uint32_t > ByteStream
static void byteStream2Rdo(const ByteStream &bs, TgcRdo &rdo, uint32_t source_id, MsgStream &log)
Convert ByteStream to RDO.
TgcByteStream()
Constructor.
~TgcByteStream()
Destructor.
static void rdo2ByteStream(const TgcRdo *rdo, ByteStream &bs, MsgStream &log)
Convert RDO to ByteStream.
An unit object of TGC ROD output.
Definition TgcRawData.h:23
@ SLB_TYPE_INNER_WIRE
Definition TgcRawData.h:36
@ SLB_TYPE_TRIPLET_STRIP
Definition TgcRawData.h:35
@ SLB_TYPE_INNER_STRIP
Definition TgcRawData.h:37
uint16_t rodId() const
Definition TgcRdo.h:138
uint16_t l1Id() const
Definition TgcRdo.h:150
void setOnlineId(uint16_t subDetectorId, uint16_t rodId)
Definition TgcRdo.cxx:37
uint32_t orbit() const
Definition TgcRdo.h:206
uint16_t subDetectorId() const
Definition TgcRdo.h:134
static uint16_t calculateOnlineId(uint16_t subDetectorId, uint16_t rodId)
Definition TgcRdo.cxx:60
uint16_t identify() const
Definition TgcRdo.h:107
uint16_t bcId() const
Definition TgcRdo.h:146
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
The struct for fragment count in ByteStream.
The struct for Inner trigger bits in ByteStream.
The struct for HiPt in ByteStream.
The struct for local status in ByteStream.
The struct for hit in ByteStream.
The struct for tracklet in ByteStream.
The struct for triplet strip in ByteStream.
The struct for SL in ByteStream.
The struct for source ID in ByteStream.