ATLAS Offline Software
Loading...
Searching...
No Matches
ZdcByteStreamReadV1V2Tool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ===========================================================================
6// Includes
7// ===========================================================================
8// STD:
9// ===========================================================================
10#include <stdexcept>
11#include <bitset>
12#include <iomanip>
13// ===========================================================================
14
15#include "eformat/SourceIdentifier.h"
18
19// PAS all adapted from L1Calo, since they hide all of their headers in "src"{!!}
25#include "ZdcByteStream/ZdcL1CaloSubBlock.h" // Only for error codes
28
31
33
34// ===========================================================================
35
36
37
38
39namespace {
40 constexpr int slink2ppmChannel[64] =
41 {0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60,
42 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63,
43 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61,
44 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62 };
45
46 uint32_t bitFieldSize(uint32_t word, uint8_t offset, uint8_t size) {
47 return (word >> offset) & ((1U << size) - 1);
48 }
49
50 uint32_t coolId(uint8_t crate, uint8_t module, uint8_t channel) {
51 const uint8_t pin = channel % 16;
52 const uint8_t asic = channel / 16;
53 return (crate << 24) | (1 << 20) | (module << 16) | (pin << 8) | asic;
54 }
55
56 int16_t pedCorrection(uint16_t twoBytePedCor) {
57 return twoBytePedCor > 511? (twoBytePedCor - 1024): twoBytePedCor;
58 }
59
60#if 0
61 std::string noAuxSuffix(const std::string& name) {
62 if ((name.size() > 4) && (name.substr(name.size()-4, 4) == "Aux.")) {
63 return name.substr(0, name.size() - 4);
64 }
65 return name;
66 }
67#endif
68}
69// namespace removed since I was not planning on putting everything into the LVL1BS namespace (yet)
70// ===========================================================================
71//namespace LVL1BS {
72// ===========================================================================
73// Constructor
75 "ZdcByteStreamxAODReadTool"*/) :
76 AsgTool(name) {
77 declareInterface<ZdcByteStreamReadV1V2Tool>(this);
78}
79
80// ===========================================================================
81// Initialize
82
83
85
86 m_srcIdMap = new ZdcSrcIdMap();
87 CHECK(m_errorTool.retrieve());
88 //CHECK(m_ppmMaps.retrieve());
89 CHECK(m_robDataProvider.retrieve());
90
91 const ZdcID* zdcID = nullptr;
92 if (detStore()->retrieve( zdcID ).isFailure() ) {
93 msg(MSG::ERROR) << "execute: Could not retrieve ZdcID object from the detector store" << endmsg;
94 return StatusCode::FAILURE;
95 }
96 else {
97 msg(MSG::DEBUG) << "execute: retrieved ZdcID" << endmsg;
98 }
99 m_zdcID = zdcID;
100
102
103 return StatusCode::SUCCESS;
104}
105// ===========================================================================
106// Finalize
107
109 delete m_srcIdMap;
110
111 return StatusCode::SUCCESS;
112}
113
114// Conversion bytestream to trigger towers
116 const IROBDataProviderSvc::VROBFRAG& robFrags,
117 xAOD::TriggerTowerContainer* const ttCollection) const
118{
119 State state;
120 state.m_subDetectorID = eformat::FORWARD_ZDC;
121 state.m_triggerTowers = ttCollection;
122
123 ROBIterator rob = robFrags.begin();
124 ROBIterator robEnd = robFrags.end();
125
126 for (; rob != robEnd; ++rob) {
127 StatusCode sc = processRobFragment_(state, rob, RequestType::PPM);
128 if (!sc.isSuccess()) {
129
130 }
131 }
132 return StatusCode::SUCCESS;
133}
134
135// Conversion bytestream to trigger towers and then to ZDC digits
137 const IROBDataProviderSvc::VROBFRAG& robFrags,
138 ZdcDigitsCollection* zdcCollection) const
139{
140
143 ttCollection->setStore(aux);
144
145 ATH_MSG_DEBUG("Getting TT collection!");
146 StatusCode sc = convert(robFrags,ttCollection);
147
148 ATH_MSG_DEBUG("Got it!");
149
150 if (sc != StatusCode::SUCCESS) {
151 ATH_MSG_DEBUG("ZDC TT Conversion failed");
152 return sc;
153 }
154
155 ATH_MSG_DEBUG("convertTT2ZD");
156 //convertTT2ZD 'new-s' and returns a bare ptr for ZdcDigitsCollection...
157 //return by value or a unique_ptr would be safer
158 ZdcDigitsCollection* zc = convertTT2ZD(ttCollection);
159 ATH_MSG_DEBUG("convertedTT2ZD! Now copying");
160 (*zdcCollection) = (*zc);
161 //...so zc should be deleted
162 delete zc;
163 ATH_MSG_DEBUG("Copied!");
164
165 return StatusCode::SUCCESS;
166}
167
169 xAOD::TriggerTowerContainer* const ttCollection) const {
170 //return convert(LVL1::TrigT1CaloDefs::xAODTriggerTowerLocation, ttCollection);
171 return convert("ZdcTriggerTowerContainer", ttCollection);
172}
173
174StatusCode ZdcByteStreamReadV1V2Tool::convert(const std::string& sgKey,
175 xAOD::TriggerTowerContainer* const ttCollection) const {
176
177 //std::cout << "convert " << sgKey << std::endl;
178
179 const std::vector<uint32_t>& vID(ppmSourceIDs(sgKey));
180
181 // // get ROB fragments
183 m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags, "ZdcByteStreamxAODReadTool");
184 ATH_MSG_DEBUG("Number of ROB fragments:" << robFrags.size());
185
186 CHECK(convert(robFrags, ttCollection));
187 return StatusCode::SUCCESS;
188}
189
190// ===========================================================================
192 State& state,
193 const ROBIterator& robIter, const RequestType& /*requestedType*/) const {
194
195 auto rob = **robIter;
196
198 "Treating ROB fragment source id #" << MSG::hex << rob.rob_source_id());
199
200
201 state.m_rodSourceId = rob.rod_source_id();
202 state.m_robSourceId = rob.source_id();
203 const auto sourceID = (state.m_rodSourceId >> 16) & 0xff;
204 const auto rodCrate = ZdcSrcIdMap::crate(state.m_rodSourceId);
205 const auto rodSlink = ZdcSrcIdMap::slink(state.m_rodSourceId);
206 // -------------------------------------------------------------------------
207 // Check Rob status
208 if (rob.nstatus() > 0) {
209 ROBPointer robData;
210 rob.status(robData);
211 if (*robData != 0) {
212 ATH_MSG_WARNING("ROB status error - skipping fragment");
213 m_errorTool->robError(state.m_rodSourceId, *robData);
214 return StatusCode::FAILURE;
215 }
216 }
217 // -------------------------------------------------------------------------
218 RODPointer payloadBeg;
219 RODPointer payloadEnd;
220 RODPointer payload;
221
222 rob.rod_data(payloadBeg);
223 payloadEnd = payloadBeg + rob.rod_ndata();
224 payload = payloadBeg;
225 // -------------------------------------------------------------------------
226 if (payload == payloadEnd) {
227 ATH_MSG_DEBUG("ROB fragment empty");
228 return StatusCode::FAILURE;
229 }
230 // -------------------------------------------------------------------------
231
232
233 uint16_t rodVer = rob.rod_version() & 0xffff;
234 state.m_verCode = ((rodVer & 0xfff) << 4) | 1;
235 uint32_t rodRunNumber = rob.rod_run_no() & 0xffffff;
236
237
238 if (sourceID != state.m_subDetectorID) {
239 ATH_MSG_ERROR("Wrong subdetector source id for requested objects: " << state.m_rodSourceId);
240 return StatusCode::FAILURE;
241 }
242
243 ATH_MSG_DEBUG("Treating crate " << rodCrate << " slink " << rodSlink);
244
245 state.m_caloUserHeader = ZdcCaloUserHeader(*payload);
246 if (!state.m_caloUserHeader.isValid()) {
247 ATH_MSG_ERROR("Invalid or missing user header");
248 return StatusCode::FAILURE;
249 }
250
252 "Run number: " << MSG::dec << rodRunNumber << endmsg
253 << "Version code: 0x" << MSG::hex << int(state.m_verCode) << MSG::dec
254 << endmsg << "LUT triggered slice offset: "
255 << int(state.m_caloUserHeader.lut()) << endmsg
256 << "FADC triggered slice offset: " << int(state.m_caloUserHeader.ppFadc())
257 << endmsg << "FADC baseline lower bound: "
258 << int(state.m_caloUserHeader.ppLowerBound()));
259
260 int indata = 0;
261 uint8_t blockType = 0;
262 int subBlock = 0;
263
264 for (; payload != payloadEnd; ++payload) {
265 if (ZdcCaloUserHeader::isValid(*payload) && (subBlock == 0)) {
266
267 } else if (ZdcSubBlockHeader::isSubBlockHeader(*payload)) {
268 indata = 0;
269 CHECK(processPpmBlock_(state));
270
271 state.m_ppLuts.clear();
272 state.m_ppFadcs.clear();
273 state.m_ppBlock.clear();
274
275 blockType = (*payload >> 28) & 0xf;
276
277 if ((blockType & 0xd) == 0xc) {
278 state.m_subBlockHeader = ZdcSubBlockHeader(*payload);
280 "SubBlock version #" << int(state.m_subBlockHeader.version())
281 << " format #" << int(state.m_subBlockHeader.format())
282 << " seqNum (compVer) #" << int(state.m_subBlockHeader.seqNum())
283 << " nslice1 #" << int(state.m_subBlockHeader.nSlice1())
284 << " nslice2 #" << int(state.m_subBlockHeader.nSlice2())
285 );
286 subBlock = blockType & 0xe;
287 } else if (blockType == (subBlock | 1)) {
288 //m_subBlockStatus = ZdcSubBlockStatus(*payload);
289 subBlock = 0;
290 }
291 } else {
292 switch(state.m_subDetectorID){
293 case eformat::TDAQ_CALO_PREPROC:
294 CHECK(processPpmWord_(state, *payload, indata));
295 break;
296 case eformat::FORWARD_ZDC:
297 CHECK(processPpmWord_(state, *payload, indata));
298 break;
299 default:
300 break;
301 }
302 indata++;
303 }
304 }
305 CHECK(processPpmBlock_(state));
306 return StatusCode::SUCCESS;
307}
308
310 uint32_t word,
311 int indata) const {
312 if ( (state.m_subBlockHeader.format() == 0)
313 || (state.m_subBlockHeader.format() >= 2)
314 || (state.m_verCode >= 0x41)) {
315 state.m_ppBlock.push_back(word);
316 } else if ((state.m_verCode == 0x21) || (state.m_verCode == 0x31)) {
317 return processPpmStandardR3V1_(state, word, indata);
318 } else {
319 ATH_MSG_ERROR("Unsupported PPM version:format ("
320 << state.m_verCode << ":" << state.m_subBlockHeader.format()
321 <<") combination");
322 return StatusCode::FAILURE;
323 }
324 return StatusCode::SUCCESS;
325}
326
327
329 if (!state.m_ppBlock.empty()) {
330 if (state.m_subBlockHeader.format() == 0) {
331 StatusCode sc = processPpmNeutral_(state);
332 state.m_ppBlock.clear();
333 CHECK(sc);
334 return sc;
335 }
336
337 if (state.m_verCode == 0x31) {
338 StatusCode sc = processPpmCompressedR3V1_(state);
339 state.m_ppBlock.clear();
340 CHECK(sc);
341 return sc;
342 }
343
344 if (state.m_verCode == 0x41 || state.m_verCode == 0x42) {
345 StatusCode sc = processPpmBlockR4V1_(state);
346 state.m_ppBlock.clear();
347 CHECK(sc);
348 return sc;
349 }
350 }
351
352 if (!state.m_ppLuts.empty()) {
353 if (state.m_verCode == 0x21 || state.m_verCode == 0x31) {
354 StatusCode sc = processPpmBlockR3V1_(state);
355 state.m_ppLuts.clear();
356 state.m_ppFadcs.clear();
357 CHECK(sc);
358 return sc;
359 }
360 ATH_MSG_ERROR("Unknown PPM subheader format '"
361 << int(state.m_subBlockHeader.format())
362 << "' for rob version '"
363 << MSG::hex << int(state.m_verCode)
364 << MSG::dec << "'" );
365 return StatusCode::FAILURE;
366 }
367 return StatusCode::SUCCESS;
368}
369
371 uint8_t numLut = state.m_subBlockHeader.nSlice1();
372 uint8_t numFadc = state.m_subBlockHeader.nSlice2();
373 uint8_t totSlice = 3 * numLut + numFadc;
374
375 uint8_t channel = 0;
376 for ( int asic = 0 ; asic < 4 ; ++asic ) {
377 for ( int mcm = 0 ; mcm < 16 ; ++mcm ) {
378 // ----------------------------------------------------------------------
379 std::vector<uint32_t> rotated(totSlice);
380
381 for ( uint8_t slice = 0 ; slice < totSlice ; ++slice ) {
382 for ( uint8_t bit = 0 ; bit < 11 ; ++bit ) {
383 if ( state.m_ppBlock[slice * 11 + asic * (11 * totSlice) + bit + 1] & (1 << mcm))
384 rotated[slice] |= (1 << bit);
385 }
386 }
387
388 bool nonZeroData = false;
389 for (uint8_t slice = 0; slice < numLut; ++slice) {
390 if (rotated[slice]
391 || rotated[slice + numLut]
392 || rotated[slice + 2 * numLut + numFadc]) { // CP, JET
393 nonZeroData = true;
394 break;
395 }
396 }
397
398 std::vector<uint8_t> lcpVal;
399 std::vector<uint8_t> lcpBcidVec;
400 std::vector<uint8_t> ljeVal;
401 std::vector<uint8_t> ljeSat80Vec;
402 std::vector<int16_t> pedCor;
403 std::vector<uint8_t> pedEn;
404
405 std::vector<uint16_t> adcVal;
406 std::vector<uint8_t> adcExt;
407
408 if (nonZeroData) {
409 for (uint8_t slice = 0; slice < numLut; ++slice) {
410 lcpVal.push_back(rotated[slice] & 0xff);
411 ljeVal.push_back(rotated[slice + numLut] & 0xff);
412 pedCor.push_back(::pedCorrection(rotated[slice + 2 * numLut + numFadc] & 0x3ff));
413
414 lcpBcidVec.push_back((rotated[slice] >> 8) & 0x7);
415 ljeSat80Vec.push_back((rotated[slice + numLut] >> 8) & 0x7);
416 pedEn.push_back((rotated[slice + 2 * numLut + numFadc] >> 10) & 0x1);
417 }
418 }
419
420 for (uint8_t slice = 0; slice < numFadc; ++slice) {
421 if (rotated[slice + numLut]) { // CP, JET
422 nonZeroData = true;
423 break;
424 }
425 }
426
427 if (nonZeroData) {
428 for (uint8_t slice = 0; slice < numFadc; ++ slice) {
429 adcVal.push_back(rotated[slice + 2 * numLut] & 0x3ff);
430 adcExt.push_back((rotated[slice + 2 * numLut] >> 10 & 0x1) & 0x3ff);
431 }
432 }
433
435 state,
436 state.m_subBlockHeader.crate(),
437 state.m_subBlockHeader.module(),
438 channel,
439 lcpVal,
440 lcpBcidVec,
441 ljeVal,
442 ljeSat80Vec, adcVal,
443 adcExt,
444 pedCor,
445 pedEn));
446 // ---------------------------------------------------------------------
447 channel++;
448 }
449 }
450 return StatusCode::SUCCESS;
451}
452
454 uint8_t chan = 0;
455 BitReader br (state.m_ppBlock);
456 try{
457 while (chan < 64) {
458 uint8_t present = 1;
459 if (state.m_subBlockHeader.format() == 3) {
460 present = br.getField (1);
461 }
462
463 if (present == 1) {
464 uint8_t lutVal = 0;
465 uint8_t fmt = 6;
466 uint8_t lutSat=0;
467 uint8_t lutExt=0;
468 uint8_t lutPeak=0;
469
470 std::vector<uint16_t> adcVal = {0 , 0, 0, 0, 0};
471 std::vector<uint8_t> adcExt = {0 , 0, 0, 0, 0};
472
473 uint8_t minHeader = br.getField (4);
474 uint8_t minIndex = minHeader % 5;
475 if (minHeader < 15) { // Formats 0-5
476 if (minHeader < 10) { // Formats 0-1
477 fmt = minHeader / 5;
478 } else { // Formats 2-5
479 fmt = 2 + br.getField (2);
480 uint8_t haveLut = br.getField (1);
481 if (fmt == 2) {
482 if (haveLut == 1) {
483 lutVal = br.getField (3);
484 lutPeak = 1; // Even if LutVal==0 it seems
485 }
486 } else {
487 uint8_t haveExt = br.getField (1);
488 if (haveLut == 1) {
489 lutVal = br.getField (8);
490 lutExt = br.getField (1);
491 lutSat = br.getField (1);
492 lutPeak = br.getField (1);
493 }
494
495 if (haveExt == 1){
496 for(uint8_t i = 0; i < 5; ++i) {
497 adcExt[i] = br.getField (1);
498 }
499 } else {
500 adcExt[2] = lutExt;
501 }
502 }
503 }
504 adcVal = getPpmAdcSamplesR3_(state, br, fmt, minIndex);
505 } else {
506 uint8_t haveAdc = br.getField (1);
507 if (haveAdc == 1) {
508 uint16_t val = br.getField (10);
509 for(uint8_t i = 0; i < 5; ++i) {
510 adcVal[i] = val;
511 }
512 }
513 }
514 // Add Trigger Tower
515 //std::vector<uint8_t> luts = {lutVal};
517 state,
518 state.m_subBlockHeader.crate(),
519 state.m_subBlockHeader.module(),
520 chan,
521 std::vector<uint8_t> {lutVal},
522 std::vector<uint8_t> {uint8_t(lutExt | (lutSat << 1) | (lutPeak << 2))},
523 adcVal,
524 adcExt
525 ));
526 }
527 chan++;
528 }
529 }catch (const std::out_of_range& ex) {
530 ATH_MSG_WARNING("Excess Data in Sub-block");
532 }
533 return StatusCode::SUCCESS;
534}
535
537 State& state,
538 BitReader& br, uint8_t format, uint8_t minIndex) const {
539
540 std::vector<uint16_t> adc = {0, 0, 0, 0, 0};
541 uint8_t minAdc = 0;
542
543 for(uint8_t i = 0; i <5; ++i) {
544 uint8_t longField = 0;
545 uint8_t numBits = 0;
546 if (format > 2) {
547 longField = br.getField (1);
548 numBits = longField == 0? 4: (format * 2);
549 } else {
550 numBits = i == 0? 4: (format + 2);
551 }
552
553 if (i == 0) {
554 minAdc = br.getField (numBits);
555 if (longField == 0) {
556 minAdc += state.m_caloUserHeader.ppLowerBound();
557 }
558 } else {
559 adc[i] = minAdc + br.getField (numBits);
560 }
561 }
562
563 if (minIndex == 0) {
564 adc[0] = minAdc;
565 } else {
566 adc[0] = adc[minIndex];
567 adc[minIndex] = minAdc;
568 }
569 return adc;
570}
571
572
573
575 uint32_t word,
576 int inData) const {
577 StatusCode sc;
578 if (state.m_subBlockHeader.seqNum() == 63) { // Error block
579 ATH_MSG_DEBUG("Error PPM subblock");
580 //TODO: errorTool
581 } else {
582 const uint8_t numAdc = state.m_subBlockHeader.nSlice2();
583 const uint8_t numLut = state.m_subBlockHeader.nSlice1();
584 const uint8_t nTotal = numAdc + numLut;
585 const uint8_t wordsPerBlock = 8; // 16 towers (4 MCMs) / 2 per word
586 const uint8_t iBlk = inData / wordsPerBlock;
587 uint8_t iChan = state.m_subBlockHeader.seqNum() + 2 * (inData % wordsPerBlock);
588
589 if (iBlk < numLut) { // First all LUT values
590 for(uint8_t i = 0; i < 2; ++i) {
591 uint16_t subword = (word >> 16 * i) & 0x7ff;
592 state.m_ppLuts[iChan].push_back(subword);
593 iChan++;
594 }
595 } else if (iBlk < nTotal) { // Next all FADC values
596 for(uint8_t i = 0; i < 2; ++i) {
597 uint16_t subword = (word >> (16 * i)) & 0x7ff;
598 state.m_ppFadcs[iChan].push_back(subword);
599 iChan++;
600 }
601
602 } else{
603 ATH_MSG_WARNING("Error decoding Ppm word (run1)");
604 sc = StatusCode::FAILURE;
605 }
606
607 }
608 return sc;
609}
610
612 if (state.m_subBlockHeader.format() == 1) {
614 return StatusCode::SUCCESS;
615 } else if (state.m_subBlockHeader.format() >= 2) {
616 // TODO: convert compressed
618 return StatusCode::SUCCESS;
619 }
620 return StatusCode::FAILURE;
621}
622
624 BitReader br (state.m_ppBlock);
625
626 uint8_t numAdc = state.m_subBlockHeader.nSlice2();
627 uint8_t numLut = state.m_subBlockHeader.nSlice1();
628 int16_t pedCorBase = -20;
629
630
631 // for(size_t i = 0; i < state.m_ppBlock.size(); ++i) {
632 // std::bitset<32> x(state.m_ppBlock[i]);
633 // std::cout << i << " " << x << std::endl;
634 // }
635
636 try{
637 for(uint8_t chan = 0; chan < 64; ++chan) {
638 uint8_t present = 1;
639
640 std::vector<uint8_t> haveLut(numLut, 0);
641 std::vector<uint8_t> lcpVal(numLut, 0);
642
643 std::vector<uint8_t> lcpExt(numLut, 0);
644 std::vector<uint8_t> lcpSat(numLut, 0);
645 std::vector<uint8_t> lcpPeak(numLut, 0);
646 std::vector<uint8_t> lcpBcidVec(numLut, 0);
647
648 std::vector<uint8_t> ljeVal(numLut, 0);
649
650 std::vector<uint8_t> ljeLow(numLut, 0);
651 std::vector<uint8_t> ljeHigh(numLut, 0);
652 std::vector<uint8_t> ljeRes(numLut, 0);
653 std::vector<uint8_t> ljeSat80Vec(numLut, 0);
654
655 std::vector<uint16_t> adcVal(numAdc, 0);
656 std::vector<uint8_t> adcExt(numAdc, 0);
657 std::vector<int16_t> pedCor(numLut, 0);
658 std::vector<uint8_t> pedEn(numLut, 0);
659
660 int8_t encoding = -1;
661 int8_t minIndex = -1;
662
663 if (state.m_subBlockHeader.format() == 3) {
664 present = br.getField (1);
665 }
666 if (present == 1) {
667 interpretPpmHeaderR4V1_(br, numAdc, encoding, minIndex);
668 CHECK((encoding != -1) && (minIndex != -1));
669 // First get the LIT related quantities
670 if (encoding < 3) {
671 // Get the peal finder bits
672 for(uint i=0; i < numLut; ++i) {
673 lcpPeak[i] = br.getField (1);
674 }
675 // Get Sat80 low bits
676 if (encoding > 0) {
677 for (uint8_t i = 0; i < numLut; ++i) {
678 ljeLow[i] = br.getField (1);
679 }
680 }
681 // Get LutCP and LutJEP values (these are
682 // only present if the peak finder is set).
683 if (encoding == 2) {
684 for (uint8_t i = 0; i < numLut; ++i) {
685 if (lcpPeak[i] == 1) {
686 lcpVal[i] = br.getField (4);
687 }
688 }
689 for(uint8_t i = 0; i < numLut; ++i) {
690 if (lcpPeak[i] == 1){
691 ljeVal[i] = br.getField (3);
692 }
693 }
694 }
695 } else if (encoding < 6) {
696 // Get LUT presence flag for each LUT slice.
697 for(uint8_t i = 0; i < numLut; ++i){
698 haveLut[i] = br.getField (1);
699 }
700
701 // Get external BCID bits (if block is present).
702 uint8_t haveExt = br.getField (1);
703
704 if (haveExt == 1) {
705 for (uint8_t i = 0; i < numAdc; ++i) {
706 adcExt[i] = br.getField (1);
707 }
708 }
709
710 for(uint8_t i = 0; i < numLut; ++i){
711 if (haveLut[i] == 1) {
712 lcpVal[i] = br.getField (8);
713 lcpExt[i] = br.getField (1);
714 lcpSat[i] = br.getField (1);
715 lcpPeak[i] = br.getField (1);
716 }
717 }
718 // Get JEP LUT values and corresponding bits.
719 for(uint8_t i = 0; i < numLut; ++i){
720 if (haveLut[i] == 1) {
721 ljeVal[i] = br.getField (8);
722 ljeLow[i] = br.getField (1);
723 ljeHigh[i] = br.getField (1);
724 ljeRes[i] = br.getField (1);
725 }
726 }
727
728 }
729
730 }
731
732 if (minIndex < 0)
733 return StatusCode::FAILURE;
734
735 // Next get the ADC related quantities (all encodings).
736 adcVal = getPpmAdcSamplesR4_(state, br, encoding, minIndex);
737 // Finally get the pedestal correction.
738 if ((encoding < 3) || (encoding == 6)) {
739 for (uint8_t i = 0; i < numLut; ++i)
740 {
741 pedCor[i] = br.getField (6) + pedCorBase;
742 if (state.m_subBlockHeader.compVer() > 0) {
743 pedEn[i] = 1;
744 }
745 }
746 } else {
747 // At the moment there is an enabled bit for every LUT slice
748 // (even though its really a global flag).
749 // The correction values is a twos complement signed value.
750 for (uint8_t i = 0; i < numLut; ++i)
751 {
752 uint16_t val = br.getField (10);
753 pedCor[i] = ::pedCorrection(val);
754 pedEn[i] = br.getField (1);
755 }
756 }
757
758 for(uint8_t i=0; i < numLut; ++i){
759 lcpBcidVec[i] = uint8_t((lcpPeak[i] << 2) | (lcpSat[i] << 1) | lcpExt[i]);
760 ljeSat80Vec[i] = uint8_t((ljeRes[i] << 2) | (ljeHigh[i] << 1) | ljeLow[i]);
761 }
763 chan, lcpVal, lcpBcidVec, ljeVal, ljeSat80Vec, adcVal, adcExt, pedCor,
764 pedEn));
765 }
766 } catch (const std::out_of_range& ex) {
767 ATH_MSG_WARNING("Excess Data in Sub-block");
769 }
770 return StatusCode::SUCCESS;
771
772}
773
775 uint8_t numAdc,
776 int8_t& encoding, int8_t& minIndex) const {
777 uint8_t minHeader = 0;
778
779 if (numAdc == 5) {
780 minHeader = br.getField (4);
781 //ATH_MSG_DEBUG("SASHA: minHeader=" << int(minHeader));
782 minIndex = minHeader % 5;
783 if (minHeader < 15){ // Encodings 0-5
784 if (minHeader < 10) {
785 encoding = minHeader / 5;
786 } else {
787 encoding = 2 + br.getField (2);
788 }
789 } else {
790 encoding = 6;
791 }
792 } else {
793 uint8_t numBits = 0;
794 if (numAdc ==3 ) {
795 numBits = 2;
796 } else if (numAdc == 7) {
797 numBits = 3;
798 } else if (numAdc < 16) {
799 numBits = 4;
800 }
801
802 if (numBits > 0) {
803 uint8_t fieldSize = 1 << numBits;
804 minHeader = br.getField (numBits);
805 uint8_t encValue = fieldSize - 1;
806 if (minHeader == encValue) { // Encoding 6
807 encoding = 6;
808 minIndex = 0;
809 } else {
810 minHeader += br.getField (2) << numBits;
811 minIndex = minHeader % fieldSize;
812 encValue = 3 * fieldSize;
813
814 if (minHeader < encValue) { // Encodings 0-2
815 encoding = minHeader / fieldSize;
816 } else {
817 encoding = 3 + br.getField (2);
818 }
819 }
820 }
821 }
822}
823
825 State& state,
826 BitReader& br, uint8_t encoding, uint8_t minIndex) const {
827 uint8_t numAdc = state.m_subBlockHeader.nSlice2();
828
829 if (encoding == 6) {
830 uint16_t val = br.getField (6);
831 return std::vector<uint16_t>(numAdc, val);
832 } else if ( encoding < 3) {
833 std::vector<uint16_t> adc(numAdc, 0);
834 uint16_t minAdc = br.getField (5) + state.m_caloUserHeader.ppLowerBound();
835 adc[minIndex] = minAdc;
836 for(uint8_t i = 1; i < numAdc; ++i) {
837 adc[i == minIndex? 0: i] = br.getField (encoding + 2) + minAdc;
838 }
839 return adc;
840 } else {
841 std::vector<uint16_t> adc(numAdc, 0);
842 uint16_t minAdc = br.getField (1)
843 ? br.getField (encoding * 2)
844 : (br.getField (5) +
846
847 adc[minIndex] = minAdc;
848 for (uint8_t i = 1; i < numAdc; ++i) {
849 adc[minIndex == i? 0: i] = br.getField (
850 br.getField (1)? encoding * 2: 4
851 ) + minAdc;
852 }
853 return adc;
854 }
855}
856
858 if (state.m_subBlockHeader.format() == 1) {
860 return StatusCode::SUCCESS;
861 } else if (state.m_subBlockHeader.format() >= 2) {
862 // TODO: convert compressed
863 return StatusCode::FAILURE;
864 }
865 return StatusCode::FAILURE;
866}
867
869
870 //std::cout << "Here I am in processPpmStandardR4V1_" << std::endl;
871 uint8_t numAdc = state.m_subBlockHeader.nSlice2();
872 uint8_t numLut = state.m_subBlockHeader.nSlice1();
873 uint8_t crate = state.m_subBlockHeader.crate();
874 uint8_t module = state.m_subBlockHeader.module();
875
876
877 BitReader br (state.m_ppBlock);
878
879 for (uint8_t chan = 0; chan < 64; ++chan) {
880 //for (uint8_t k = 0; k < 4; ++k) {
881 std::vector<uint8_t> lcpVal;
882 std::vector<uint8_t> lcpBcidVec;
883
884 std::vector<uint8_t> ljeVal;
885 std::vector<uint8_t> ljeSat80Vec;
886
887
888
889 std::vector<uint16_t> adcVal;
890 std::vector<uint8_t> adcExt;
891 std::vector<int16_t> pedCor;
892 std::vector<uint8_t> pedEn;
893 try {
894 for (int i = 0; i < numLut; ++i) {
895 lcpVal.push_back(br.getField (8));
896 lcpBcidVec.push_back(br.getField (3));
897 }
898
899 for (int i = 0; i < numLut; ++i) {
900 ljeVal.push_back(br.getField (8));
901 ljeSat80Vec.push_back(br.getField (3));
902 }
903
904 for (int i = 0; i < numAdc; ++i) {
905 adcVal.push_back(br.getField (10));
906 adcExt.push_back(br.getField (1));
907 }
908
909 for (int i = 0; i < numLut; ++i) {
910 uint16_t pc = br.getField (10);
911 pedCor.push_back(pedCorrection(pc));
912 pedEn.push_back(br.getField (1));
913 }
914 } catch (const std::out_of_range& ex) {
915 ATH_MSG_WARNING("Excess Data in Sub-block");
917 }
918 CHECK(
919 addTriggerTowerV2_(state, crate, module, chan, lcpVal, lcpBcidVec,
920 ljeVal, ljeSat80Vec, adcVal, adcExt, pedCor, pedEn));
921 }
922
923 return StatusCode::SUCCESS;
924}
925
927 for(const auto& lut : state.m_ppLuts) {
929 state,
930 state.m_subBlockHeader.crate(),
931 state.m_subBlockHeader.module(),
932 lut.first,
933 lut.second,
934 state.m_ppFadcs[lut.first]));
935 }
936 return StatusCode::SUCCESS;
937}
938
940 State& state,
941 uint8_t crate,
942 uint8_t module,
943 uint8_t channel,
944 const std::vector<uint8_t>& lcpVal,
945 const std::vector<uint8_t>& lcpBcidVec,
946 const std::vector<uint8_t>& ljeVal,
947 const std::vector<uint8_t>& ljeSat80Vec,
948 const std::vector<uint16_t>& adcVal,
949 const std::vector<uint8_t>& adcExt,
950 const std::vector<int16_t>& pedCor,
951 const std::vector<uint8_t>& pedEn) const {
952
953 //int layer = 0;
954 int error = 0;
955 double eta = 0.;
956 double phi = 0.;
957
958 bool isNotSpare = false; // PAS - just to minimize changing code
959 // PAS - not using L1Calo PPMMap
960 /*
961 bool isNotSpare = m_ppmMaps->mapping(crate, module, channel, eta, phi, layer);
962 if (!isNotSpare && !m_ppmIsRetSpare && !m_ppmIsRetMuon){
963 return StatusCode::SUCCESS;
964 }
965 */
966
967 if (!isNotSpare) {
968 const int pin = channel % 16;
969 const int asic = channel / 16;
970 eta = 16 * crate + module;
971 phi = 4 * pin + asic;
972 }
973
974 uint32_t coolId = ::coolId(crate, module, channel);
975 CHECK(state.m_coolIds.count(coolId) == 0);
976 state.m_coolIds.insert(coolId);
977
979 //std::cout << ZdcToString(*tt) << std::endl;
980
981 state.m_triggerTowers->push_back(tt);
982 // tt->initialize(
983 // const uint_least32_t& coolId,
984 // const uint_least8_t& layer,
985 // const float& eta,
986 // const float& phi,
987 // const std::vector<uint_least8_t>& lut_cp,
988 // const std::vector<uint_least8_t>& lut_jep,
989 // const std::vector<int_least16_t>& correction,
990 // const std::vector<uint_least8_t>& correctionEnabled,
991 // const std::vector<uint_least8_t>& bcidVec,
992 // const std::vector<uint_least16_t>& adc,
993 // const std::vector<uint_least8_t>& bcidExt,
994 // const std::vector<uint_least8_t>& sat80,
995 // const uint_least16_t& error,
996 // const uint_least8_t& peak,
997 // const uint_least8_t& adcPeak
998 // );
999 tt->initialize(coolId, eta, phi, lcpVal, ljeVal, pedCor, pedEn,
1000 lcpBcidVec, adcVal, adcExt, ljeSat80Vec, error, state.m_caloUserHeader.lut(),
1001 state.m_caloUserHeader.ppFadc());
1002 return StatusCode::SUCCESS;
1003}
1004
1006 State& state,
1007 uint8_t crate,
1008 uint8_t module,
1009 uint8_t channel,
1010 const std::vector<uint8_t>& luts,
1011 const std::vector<uint8_t>& lcpBcidVec,
1012 const std::vector<uint16_t>& fadc,
1013 const std::vector<uint8_t>& bcidExt
1014 ) const {
1015
1016 std::vector<uint8_t> ljeSat80Vec;
1017
1018 std::vector<int16_t> pedCor;
1019 std::vector<uint8_t> pedEn;
1020
1021 CHECK(addTriggerTowerV2_(state, crate, module, channel, luts, lcpBcidVec,
1022 luts , ljeSat80Vec, fadc, bcidExt, pedCor, pedEn)
1023 );
1024
1025 return StatusCode::SUCCESS;
1026}
1027
1029 State& state,
1030 uint8_t crate,
1031 uint8_t module,
1032 uint8_t channel,
1033 const std::vector<uint16_t>& luts,
1034 const std::vector<uint16_t>& fadc
1035 ) const {
1036
1037 std::vector<uint8_t> lcpVal;
1038 std::vector<uint8_t> lcpBcidVec;
1039
1040 std::vector<uint16_t> adcVal;
1041 std::vector<uint8_t> adcExt;
1042
1043 for(auto lut: luts) {
1044 lcpVal.push_back(BitField::get<uint8_t>(lut, 0, 8));
1045 lcpBcidVec.push_back(BitField::get<uint8_t>(lut, 8, 3));
1046 }
1047
1048 for(auto f: fadc) {
1049 adcExt.push_back(BitField::get<uint8_t>(f, 0, 1));
1050 adcVal.push_back(BitField::get<uint16_t>(f, 1, 10));
1051 }
1052
1053 CHECK(addTriggerTowerV1_(state, crate, module, channel, lcpVal, lcpBcidVec,
1054 adcVal, adcExt));
1055
1056 return StatusCode::SUCCESS;
1057}
1058
1060{
1061 const int crates = 8;
1062 m_ppmSourceIDs.clear();
1063 m_ppmSourceIDsSpare.clear();
1064 m_ppmSourceIDsMuon.clear();
1065
1066 for (int crate = 0; crate < crates; ++crate) {
1067 for (int slink = 0; slink < m_srcIdMap->maxSlinks(); ++slink) {
1068 //const uint32_t rodId = m_srcIdMap->getRodID(crate, slink, 0,
1069 // eformat::TDAQ_CALO_PREPROC);
1070 const uint32_t rodId = m_srcIdMap->getRodID(crate, slink, 0,
1071 eformat::FORWARD_ZDC);
1072 const uint32_t robId = m_srcIdMap->getRobID(rodId);
1073 m_ppmSourceIDs.push_back(robId);
1074 //std::cout << "robId=" << std::hex << robId << std::dec << std::endl;
1075 if (crate > 1 && crate < 6) {
1076 m_ppmSourceIDsSpare.push_back(robId);
1077 if (crate < 4 && slink == 0) {
1078 m_ppmSourceIDsMuon.push_back(robId);
1079 }
1080 }
1081 }
1082 }
1083}
1084
1085// Return reference to vector with all possible Source Identifiers
1086
1087const std::vector<uint32_t>& ZdcByteStreamReadV1V2Tool::ppmSourceIDs(
1088 const std::string& sgKey) const
1089{
1090 if (sgKey.find("Muon") != std::string::npos) {
1091 return m_ppmSourceIDsMuon;
1092 }
1093 else if (sgKey.find("Spare") != std::string::npos) {
1094 return m_ppmSourceIDsSpare;
1095 }
1096
1097 return m_ppmSourceIDs;
1098}
1099
1100
1101
1103 (const uint8_t numBits)
1104{
1105 if ((m_ppPointer + numBits) <= m_ppMaxBit) {
1106 uint32_t iWord = m_ppPointer / 31;
1107 uint8_t iBit = m_ppPointer % 31;
1108 m_ppPointer += numBits;
1109
1110 uint32_t result;
1111 if ((iBit + numBits) <= 31) {
1112 result = ::bitFieldSize(m_ppBlock[iWord], iBit, numBits);
1113 } else {
1114 uint8_t nb1 = 31 - iBit;
1115 uint8_t nb2 = numBits - nb1;
1116 uint32_t field1 = ::bitFieldSize(m_ppBlock[iWord], iBit, nb1);
1117 uint32_t field2 = ::bitFieldSize(m_ppBlock[iWord + 1], 0, nb2);
1118 result = field1 | (field2 << nb1);
1119 }
1120
1121 return result;
1122 }
1123
1124 throw std::out_of_range("Requested too much bits from ppm block");
1125}
1126
1128{
1129 typedef std::map<uint32_t,ZdcDigits*> hashmapType;
1130 hashmapType digits_map;
1131 Identifier chan_id;
1132
1133 for (const xAOD::TriggerTower* tt : *ttCollection)
1134 {
1135 uint32_t coolId = tt->coolId();
1136 uint32_t pin = (coolId>>8) & 0xf;
1137 uint32_t asic = coolId & 0xf;
1138 uint32_t slinkChannel = asic*16 + pin;
1139 uint32_t ppmChannel = slink2ppmChannel[slinkChannel];
1140
1141 uint32_t module = (coolId>>16) & 0xf;
1142
1143 ATH_MSG_DEBUG( "--> ZCS: " << ZdcCablingService::getInstance() << " mod=" << module << " slinkC=" << slinkChannel << " ppmC=" << ppmChannel );
1144 chan_id = ZdcCablingService::getInstance()->h2s_channel_id(module, ppmChannel);
1145
1146 const uint32_t chan_hash = chan_id.get_identifier32().get_compact();
1147 int gain = ZdcCablingService::getInstance()->hwid2gain(module,ppmChannel);
1148 int delay = ZdcCablingService::getInstance()->hwid2delay(module,ppmChannel);
1149
1150 ATH_MSG_DEBUG("Trying to find chan_hash " << chan_hash << " g" << gain << "d" << delay);
1151
1152 hashmapType::iterator iter = digits_map.find(chan_hash);
1153 if (iter == digits_map.end())
1154 {
1155 ATH_MSG_DEBUG("new channel for " << chan_id);
1156 digits_map.insert(std::pair<uint32_t,ZdcDigits*>(chan_hash,new ZdcDigits(chan_id)));
1157 iter = digits_map.find(chan_hash);
1158 }
1159 if (iter != digits_map.end())
1160 {
1161 ATH_MSG_DEBUG("new auxdata for " << chan_id);
1162 if (gain==0&&delay==0) (*iter).second->set_digits_gain0_delay0( tt->adc() );
1163 if (gain==1&&delay==0) (*iter).second->set_digits_gain1_delay0( tt->adc() );
1164 if (gain==0&&delay==1) (*iter).second->set_digits_gain0_delay1( tt->adc() );
1165 if (gain==1&&delay==1) (*iter).second->set_digits_gain1_delay1( tt->adc() );
1166 }
1167
1168 }
1169
1170 ZdcDigitsCollection* zdcCollection = new ZdcDigitsCollection();
1171
1172 hashmapType::iterator iter = digits_map.begin();
1173 hashmapType::iterator iter_end = digits_map.end();
1174
1175 while (iter != iter_end)
1176 {
1177 /*
1178 Identifier id = ((*iter).second)->identify();
1179 std::cout
1180 << "side=" << m_zdcID->side(id)
1181 << " mod=" << m_zdcID->module(id)
1182 << " type=" << m_zdcID->type(id)
1183 << " chan=" << m_zdcID->channel(id)
1184 << std::endl;
1185 ((*iter).second)->print();
1186 */
1187 zdcCollection->push_back((*iter).second);
1188 ++iter;
1189 }
1190
1191 return zdcCollection;
1192}
1193
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define endmsg
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define CHECK(...)
Evaluate an expression and check for errors.
double delay(std::size_t d)
unsigned int uint
static Double_t sc
size_t size() const
Number of registered mappings.
const char *const fmt
const int slink2ppmChannel[64]
const ServiceHandle< StoreGateSvc > & detStore() const
T get(const uint32_t &word) const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
std::vector< const ROBF * > VROBFRAG
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
const std::vector< uint32_t > & m_ppBlock
OFFLINE_FRAGMENTS_NAMESPACE::PointerType RODPointer
ZdcDigitsCollection * convertTT2ZD(xAOD::TriggerTowerContainer *const ttCollection) const
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
StatusCode processPpmStandardR4V1_(State &state) const
void interpretPpmHeaderR4V1_(BitReader &br, uint8_t numAdc, int8_t &encoding, int8_t &minIndex) const
StatusCode processPpmWord_(State &state, uint32_t word, int indata) const
std::vector< uint32_t > m_ppmSourceIDs
StatusCode addTriggerTowerV2_(State &state, uint8_t crate, uint8_t module, uint8_t channel, const std::vector< uint8_t > &lcpVal, const std::vector< uint8_t > &lcpBcidVec, const std::vector< uint8_t > &ljeVal, const std::vector< uint8_t > &ljeSat80Vec, const std::vector< uint16_t > &adcVal, const std::vector< uint8_t > &adcExt, const std::vector< int16_t > &pedCor, const std::vector< uint8_t > &pedEn) const
StatusCode processPpmBlockR3V1_(State &state) const
IROBDataProviderSvc::VROBFRAG::const_iterator ROBIterator
StatusCode processPpmCompressedR3V1_(State &state) const
StatusCode processPpmCompressedR4V1_(State &state) const
std::vector< uint32_t > m_ppmSourceIDsMuon
StatusCode convert(const IROBDataProviderSvc::VROBFRAG &robFrags, xAOD::TriggerTowerContainer *const ttCollection) const
Convert ROB fragments to trigger towers.
ZdcByteStreamReadV1V2Tool(const std::string &name)
StatusCode processPpmStandardR3V1_(State &state) const
OFFLINE_FRAGMENTS_NAMESPACE::PointerType ROBPointer
std::vector< uint16_t > getPpmAdcSamplesR4_(State &state, BitReader &br, uint8_t encoding, uint8_t minIndex) const
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service for reading bytestream.
StatusCode processPpmBlockR4V1_(State &state) const
StatusCode addTriggerTowerV1_(State &state, uint8_t crate, uint8_t module, uint8_t channel, const std::vector< uint16_t > &luts, const std::vector< uint16_t > &fadc) const
std::vector< uint32_t > m_ppmSourceIDsSpare
StatusCode processPpmNeutral_(State &state) const
StatusCode processRobFragment_(State &state, const ROBIterator &robFrag, const RequestType &requestedType) const
StatusCode processPpmBlock_(State &state) const
const std::vector< uint32_t > & ppmSourceIDs(const std::string &sgKey) const
Return reference to vector with all possible Source Identifiers.
std::vector< uint16_t > getPpmAdcSamplesR3_(State &state, BitReader &br, uint8_t format, uint8_t minIndex) const
ToolHandle< ZdcL1CaloErrorByteStreamTool > m_errorTool
int hwid2gain(int crate, int channel) const
static const ZdcCablingService * getInstance()
get pointer to service instance
int hwid2delay(int crate, int channel) const
Identifier h2s_channel_id(int crate, int channel) const
L1Calo User Header class.
uint8_t ppFadc() const
uint8_t ppLowerBound() const
Definition ZdcID.h:25
This class provides conversion between Lower level Source ID to higher level source ID for L1Calo Byt...
Definition ZdcSrcIdMap.h:24
static int crate(uint32_t code)
moduleID -> crate
static int slink(uint32_t code)
moduleID -> slink
L1Calo User Header class.
uint8_t crate() const
uint8_t nSlice2() const
bool isSubBlockHeader() const
uint8_t compVer() const
uint8_t format() const
uint8_t version() const
uint8_t seqNum() const
uint8_t module() const
uint8_t nSlice1() const
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
TriggerTowerContainer_v2 TriggerTowerContainer
Define the latest version of the TriggerTower container.
setScaleOne setStatusOne setSaturated int16_t
TriggerTower_v2 TriggerTower
Define the latest version of the TriggerTower class.
TriggerTowerAuxContainer_v2 TriggerTowerAuxContainer
Define the latest version of the TriggerTower auxiliary container.
setEventNumber uint32_t
std::map< uint8_t, std::vector< uint16_t > > m_ppFadcs
xAOD::TriggerTowerContainer * m_triggerTowers
std::map< uint8_t, std::vector< uint16_t > > m_ppLuts
MsgStream & msg
Definition testRead.cxx:32