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 "TgcByteStreamData.h"
8#include "MuonRDO/TgcRdo.h"
9
10#include "GaudiKernel/MsgStream.h"
11
13= default;
14
16= default;
17
18void Muon::TgcByteStream::rdo2ByteStream(const TgcRdo* rdo, ByteStream& bs, MsgStream& log)
19{
20 bool p_debug = (log.level() <= MSG::DEBUG);
21
22 if(p_debug) {
23 log << MSG::DEBUG << "TgcByteStream::rdo2ByteStream" << endmsg;
24 }
25
26 ByteStream headerBS, statusBS, countersBS, dataBS, footerBS;
27 TGC_BYTESTREAM_FRAGMENTCOUNT counters[7] = {
28 {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 8}, {0, 9}
29 };
31
32 if(p_debug) {
33 log << MSG::DEBUG << "Encoding " << rdo->size() << " elements" << endmsg;
34 }
35
36 for (const TgcRawData* raw : *rdo)
37 {
38 switch(raw->type())
39 {
41 ls.hitsRO = 1;
42 counters[1].count++;
43 {
45 roh.channel = raw->channel()-40;
46 roh.sbId = raw->slbId();
47 // revised document : https://twiki.cern.ch/twiki/pub/Main/TgcDocument/ROBformat_V4_0_v2.pdf
48 // (old ver. : http://cern.ch/atlas-tgc/doc/ROBformat.pdf)
49 // Table 7 : SB type, bits 15..13
50 // 0,1: doublet wire, strip
51 // 2,3: triplet wire, strip triplet;
52 // 4 : inner wire and strip
53 // TgcRawData::SlbType is defined in TgcRawData.h
54 // 0: SLB_TYPE_DOUBLET_WIRE,
55 // 1: SLB_TYPE_DOUBLET_STRIP,
56 // 2: SLB_TYPE_TRIPLET_WIRE,
57 // 3: SLB_TYPE_TRIPLET_STRIP,
58 // 4: SLB_TYPE_INNER_WIRE,
59 // 5: SLB_TYPE_INNER_STRIP,
60 // 6: SLB_TYPE_UNKNOWN
61 roh.sbType = raw->slbType();
62
63 // SBLOCs for EIFI are different in online (ByteStream) and offline (RDO).
64 // bug #57051: Wrong numbering of SBLOC for Inner Stations (EI/FI) in 12-fold TGC cablings
65 // ByteStream : slbId = SBLOC + ip*2 (ip=0, 1, 2), SBLOC = 8 or 9 (EI), 0 or 1 (FI)
66 // slbId = 8, 10, 12, 9, 11, 13, 0, 2, 4, 1, 3, 5
67 // RDO : slbId = SBLOC + ip*4 (ip=0, 1, 2), SBLOC = 1 or 3 (EI), 0 or 2 (FI)
68 // slbId = 1, 5, 9, 3, 7, 11, 0, 4, 8, 2, 6, 10
71 if(raw->slbId()%2==0) roh.sbId = raw->slbId() /2;
72 else roh.sbId = (raw->slbId()+15)/2;
73 }
74
75 roh.adj = raw->isAdjacent();
76 roh.ldbId = raw->sswId();
77 roh.bcBitmap = bcBitmap(raw->bcTag());
78 roh.tracklet = raw->tracklet();
79 roh.ok = 1;
80 dataBS.push_back(toBS32(roh));
81 }
82 break;
84 ls.trkRO = 1;
85 counters[2].count++;
86 if(raw->slbType() == TgcRawData::SLB_TYPE_TRIPLET_STRIP)
87 {
89 rot.phi = raw->position();
90 rot.seg = raw->segment();
91 rot.sbId = raw->slbId();
92 rot.ldbId = raw->sswId();
93 rot.bcBitmap = bcBitmap(raw->bcTag());
95 rot.ok = 1;
96 dataBS.push_back(toBS32(rot));
97 }
98 else
99 {
101 rot.rphi = raw->position();
102 rot.subm = raw->subMatrix();
103 rot.seg = raw->segment();
104 rot.delta = raw->delta();
105 rot.sbId = raw->slbId();
106 rot.ldbId = raw->sswId();
107 rot.bcBitmap = bcBitmap(raw->bcTag());
108 // revised document : https://twiki.cern.ch/twiki/pub/Main/TgcDocument/ROBformat_V4_0_v2.pdf
109 // (old ver. : http://cern.ch/atlas-tgc/doc/ROBformat.pdf)
110 // Table 8 : Slave Board type, bits 30..28
111 // 0,1: doublet wire, strip
112 // 2,3: triplet wire, strip triplet;
113 // 4,5: inner wire, strip
114 // TgcRawData::SlbType is defined in TgcRawData.h
115 // 0: SLB_TYPE_DOUBLET_WIRE,
116 // 1: SLB_TYPE_DOUBLET_STRIP,
117 // 2: SLB_TYPE_TRIPLET_WIRE,
118 // 3: SLB_TYPE_TRIPLET_STRIP,
119 // 4: SLB_TYPE_INNER_WIRE,
120 // 5: SLB_TYPE_INNER_STRIP,
121 // 6: SLB_TYPE_UNKNOWN
122 rot.slbType = raw->slbType();
123 rot.ok = 1;
124 dataBS.push_back(toBS32(rot));
125 }
126 break;
128 ls.hipt = 1;
129 counters[5].count++;
130 if(raw->isStrip() == 1 && raw->sector() & 4 ){
132 hpt.inner = raw->inner();
133 //hpt.hipt = raw->isHipt();
134 //hpt.cand = raw->index();
135 //hpt.chip = raw->chip();
136 hpt.sector = raw->sector();
137 //hpt.fwd = raw->isForward();
138 hpt.strip = raw->isStrip();
139 hpt.bcBitmap = bcBitmap(raw->bcTag());
140 dataBS.push_back(toBS32(hpt));
141 }else{
143 hpt.delta = raw->delta();
144 hpt.sub = raw->hsub();
145 hpt.hitId = raw->hitId();
146 hpt.hipt = raw->isHipt();
147 hpt.cand = raw->index();
148 hpt.chip = raw->chip();
149 hpt.sector = raw->sector();
150 hpt.fwd = raw->isForward();
151 hpt.strip = raw->isStrip();
152 hpt.bcBitmap = bcBitmap(raw->bcTag());
153 dataBS.push_back(toBS32(hpt));
154 }
155 break;
157 ls.sl = 1;
158 counters[6].count++;
159 {
161 sl.roi = raw->roi();
162 sl.overlap = raw->isOverlap();
163 sl.veto = raw->isVeto();
164 sl.threshold = raw->threshold();
165 sl.sign = raw->isMuplus();
166 sl.cand = raw->index();
167 sl.sector = raw->sector();
168 sl.fwd = raw->isForward();
169 sl.bcBitmap = bcBitmap(raw->bcTag());
170 sl.cand2plus = raw->cand3plus();
171 dataBS.push_back(toBS32(sl));
172 }
173 break;
174 default:
175 log << MSG::ERROR << "Invalid type " << raw->typeName() << endmsg;
176 break;
177 }
178 }
179
180 statusBS.push_back(toBS32(ls));
181 statusBS.push_back(rdo->orbit());
182
183 for(int iCnt = 0; iCnt < 7; iCnt++)
184 {
185 if(counters[iCnt].count > 0)
186 {
187 countersBS.push_back(toBS32(counters[iCnt]));
188 }
189 }
190
191 bs.clear();
192 bs.insert(bs.end(), countersBS.begin(), countersBS.end());
193 bs.insert(bs.end(), dataBS.begin(), dataBS.end());
194
195 if(p_debug) {
196 log << MSG::DEBUG << "TgcByteStream::rdo2ByteStream done" << endmsg;
197 }
198}
199
200void Muon::TgcByteStream::byteStream2Rdo(const ByteStream& bs, TgcRdo& rdo, uint32_t source_id,
201 MsgStream& log)
202{
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 {
212 if(p_debug) {
213 log << MSG::DEBUG << "Error: input TgcRdo id does not match bytestream id" << endmsg;
214 }
215 return;
216 }
217
218 rdo.setOnlineId(sid.side, sid.rodid);
219
220 TGC_BYTESTREAM_FRAGMENTCOUNT counters[7] = {
221 {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 8}, {0, 9}
222 };
224
225
226 int iBs = 0;
227 for(int iCnt = 0; iCnt < 7; iCnt++)
228 {
229 fromBS32(bs[iBs], counter);
230 if(counter.id == counters[iCnt].id)
231 {
232 counters[iCnt].count = counter.count;
233 iBs++;
234 }
235 }
236
237 for(int iCnt = 0; iCnt < 7; iCnt++)
238 {
239 if(counters[iCnt].count == 0) continue;
240 switch(counters[iCnt].id)
241 {
242 case 1: // Raw data format (SSW format)
243 {
244 if(p_debug) {
245 log << MSG::DEBUG
246 << "fragment" << counters[iCnt].id << " "
247 << counters[iCnt].count << "words" << endmsg;
248 }
249 for(unsigned iFrag = 0; iFrag < counters[iCnt].count; iFrag++)
250 {
251 if(p_debug) {
252 log << MSG::DEBUG
253 << "WORD" << iFrag << ":" << MSG::hex << bs[iBs] << endmsg;
254 }
255 iBs++;
256 }
257 break;
258 }
259
260 case 2: // TgcRawData::TYPE_HIT
261 {
262 if(p_debug) {
263 log << MSG::DEBUG << "fragment"
264 << counters[iCnt].id << " " << counters[iCnt].count
265 << "words" << endmsg;
266 }
268 for(unsigned iFrag = 0; iFrag < counters[iCnt].count; iFrag++)
269 {
270 if(p_debug) {
271 log << MSG::DEBUG <<"WORD" << iFrag << ":" << MSG::hex << bs[iBs] << endmsg;
272 }
273 fromBS32(bs[iBs++], roh);
274
275
276 if(p_debug) {
277 log<< MSG::DEBUG
278 << " rdo.subDetectorId():" << rdo.subDetectorId()
279 << " rdo.rodId():" <<rdo.rodId()
280 << " roh.ldbId:" <<roh.ldbId
281 << " roh.sbId:" <<roh.sbId
282 << " rdo.l1Id():"<<rdo.l1Id()
283 << " rdo.bcId():"<<rdo.bcId()<<endmsg;
284 }
285
286 uint16_t slbId = roh.sbId;
287 // SBLOCs for EIFI are different in online (ByteStream) and offline (RDO).
288 // bug #57051: Wrong numbering of SBLOC for Inner Stations (EI/FI) in 12-fold TGC cablings
289 // ByteStream : slbId = SBLOC + ip*2 (ip=0, 1, 2), SBLOC = 8 or 9 (EI), 0 or 1 (FI)
290 // slbId = 8, 10, 12, 9, 11, 13, 0, 2, 4, 1, 3, 5
291 // RDO : slbId = SBLOC + ip*4 (ip=0, 1, 2), SBLOC = 1 or 3 (EI), 0 or 2 (FI)
292 // slbId = 1, 5, 9, 3, 7, 11, 0, 4, 8, 2, 6, 10
295 if(roh.sbId<8) slbId = roh.sbId *2;
296 else slbId = (roh.sbId-8)*2+1;
297 }
298
299 TgcRawData* raw = new TgcRawData(bcTag(roh.bcBitmap),
300 rdo.subDetectorId(),
301 rdo.rodId(),
302 roh.ldbId,
303 slbId,
304 rdo.l1Id(),
305 rdo.bcId(),
306 // revised document : https://twiki.cern.ch/twiki/pub/Main/TgcDocument/ROBformat_V4_0_v2.pdf
307 // (old ver. : http://cern.ch/atlas-tgc/doc/ROBformat.pdf)
308 // Table 7 : SB type, bits 15..13
309 // 0,1: doublet wire, strip
310 // 2,3: triplet wire, strip triplet;
311 // 4 : inner wire and strip
312 // TgcRawData::SlbType is defined in TgcRawData.h
313 // 0: SLB_TYPE_DOUBLET_WIRE,
314 // 1: SLB_TYPE_DOUBLET_STRIP,
315 // 2: SLB_TYPE_TRIPLET_WIRE,
316 // 3: SLB_TYPE_TRIPLET_STRIP,
317 // 4: SLB_TYPE_INNER_WIRE,
318 // 5: SLB_TYPE_INNER_STRIP,
319 // 6: SLB_TYPE_UNKNOWN
321 (bool)roh.adj,
322 roh.tracklet,
323 roh.channel+40);
324 rdo.push_back(raw);
325 }
326 break;
327 }
328 case 3: // TgcRawData::TYPE_TRACKLET
329 {
330 if(p_debug) {
331 log << MSG::DEBUG << "fragment"
332 << counters[iCnt].id << " " << counters[iCnt].count
333 << "words" << endmsg;
334 }
337 for(unsigned iFrag = 0; iFrag < counters[iCnt].count; iFrag++)
338 {
339 if(p_debug) {
340 log<< MSG::DEBUG << "WORD"
341 << iFrag << ":" << MSG::hex << bs[iBs] << endmsg;
342 }
343 fromBS32(bs[iBs], rostrip);
344
346 {
347 TgcRawData* raw = new TgcRawData(bcTag(rostrip.bcBitmap),
348 rdo.subDetectorId(),
349 rdo.rodId(),
350 rostrip.ldbId,
351 rostrip.sbId,
352 rdo.l1Id(),
353 rdo.bcId(),
355 0,
356 rostrip.seg,
357 rostrip.subc,
358 rostrip.phi);
359 rdo.push_back(raw);
360 }
361 else
362 {
363 fromBS32(bs[iBs], rotrk);
364 TgcRawData* raw = new TgcRawData(bcTag(rotrk.bcBitmap),
365 rdo.subDetectorId(),
366 rdo.rodId(),
367 rotrk.ldbId,
368 rotrk.sbId,
369 rdo.l1Id(),
370 rdo.bcId(),
371 // revised document : https://twiki.cern.ch/twiki/pub/Main/TgcDocument/ROBformat_V4_0_v2.pdf
372 // (old ver. : http://cern.ch/atlas-tgc/doc/ROBformat.pdf)
373 // Table 8 : Slave Board type, bits 30..28
374 // 0,1: doublet wire, strip
375 // 2,3: triplet wire, strip triplet;
376 // 4,5: inner wire, strip
377 // TgcRawData::SlbType is defined in TgcRawData.h
378 // 0: SLB_TYPE_DOUBLET_WIRE,
379 // 1: SLB_TYPE_DOUBLET_STRIP,
380 // 2: SLB_TYPE_TRIPLET_WIRE,
381 // 3: SLB_TYPE_TRIPLET_STRIP,
382 // 4: SLB_TYPE_INNER_WIRE,
383 // 5: SLB_TYPE_INNER_STRIP,
384 // 6: SLB_TYPE_UNKNOWN
386 rotrk.delta,
387 rotrk.seg,
388 0,
389 rotrk.rphi);
390 rdo.push_back(raw);
391 }
392 iBs++;
393 }
394 break;
395 }
396 case 8: // TgcRawData::TYPE_HIPT
397 {
398 if(p_debug) {
399 log << MSG::DEBUG << "fragment"
400 << counters[iCnt].id << " " << counters[iCnt].count
401 << "words" << endmsg;
402 }
405 for(unsigned iFrag = 0; iFrag < counters[iCnt].count; iFrag++)
406 {
407 if(p_debug) {
408 log << MSG::DEBUG << "WORD"
409 << iFrag << ":" << MSG::hex << bs[iBs] << endmsg;
410 }
411 fromBS32(bs[iBs], hptinner);
412 if(hptinner.sector & 4){
413 TgcRawData* raw = new TgcRawData(bcTag(hpt.bcBitmap),
414 rdo.subDetectorId(),
415 rdo.rodId(),
416 rdo.l1Id(),
417 rdo.bcId(),
418 hptinner.strip,
419 0,
420 hptinner.sector,
421 0,
422 0,
423 0,
424 0,
425 0,
426 0,
427 hptinner.inner);
428 rdo.push_back(raw);
429 }else{
430 fromBS32(bs[iBs], hpt);
431 TgcRawData* raw = new TgcRawData(bcTag(hpt.bcBitmap),
432 rdo.subDetectorId(),
433 rdo.rodId(),
434 rdo.l1Id(),
435 rdo.bcId(),
436 hpt.strip,
437 hpt.fwd,
438 hpt.sector,
439 hpt.chip,
440 hpt.cand,
441 hpt.hipt,
442 hpt.hitId,
443 hpt.sub,
444 hpt.delta,
445 0);
446 rdo.push_back(raw);
447 }
448 iBs++;
449 }
450 break;
451 }
452 case 9: // TgcRawData::TYPE_SL
453 {
454 if(p_debug) {
455 log << MSG::DEBUG << "fragment"
456 << counters[iCnt].id << " " << counters[iCnt].count
457 << "words" << endmsg;
458 }
460 for(unsigned iFrag = 0; iFrag < counters[iCnt].count; iFrag++)
461 {
462 if(p_debug) {
463 log << MSG::DEBUG << "WORD"
464 << iFrag << ":" << MSG::hex << bs[iBs] << endmsg;
465 }
466 fromBS32(bs[iBs++], sl);
467
468 TgcRawData* raw = new TgcRawData(bcTag(sl.bcBitmap),
469 rdo.subDetectorId(),
470 rdo.rodId(),
471 rdo.l1Id(),
472 rdo.bcId(),
473 sl.cand2plus,
474 static_cast<bool>(sl.fwd),
475 sl.sector,
476 sl.cand,
477 sl.sign,
478 sl.threshold,
479 sl.overlap,
480 sl.veto,
481 sl.roi);
482 rdo.push_back(raw);
483 }
484 break;
485 }
486 default:
487 if(p_debug) {
488 log << MSG::DEBUG
489 << "Error: TgcByteStream::byteStream2Rdo Unsupported fragment type "
490 << counters[iCnt].id << endmsg;
491 }
492 break;
493 }
494 }
495
496 if(p_debug) {
497 log << MSG::DEBUG << "Decoded " << MSG::dec << rdo.size()
498 << " elements" << endmsg;
499 log << MSG::DEBUG << "TgcByteStream::byteStream2Rdo done" << endmsg;
500 }
501}
#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.