ATLAS Offline Software
Loading...
Searching...
No Matches
ITkPixelCnvTool.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*
6* Author: Ondra Kovanda, ondrej.kovanda at cern.ch
7* Date: 03/2025
8* Description: Top-level tool to be called from BS converter or algorithm
9*/
10
11#include "ITkPixelCnvTool.h"
16
17
18
19
20ITkPixelCnvTool::ITkPixelCnvTool(const std::string& type,const std::string& name,const IInterface* parent)
21 : AthAlgTool(type, name, parent)
22{}
23
28
29 //Initialize the sub-tools
30 ATH_CHECK(m_hitSortingTool.retrieve());
31
32 ATH_CHECK(m_encodingTool.retrieve());
33
34 ATH_CHECK(m_pixelCablingKey.initialize());
35
36 if (not m_dataRateMonTool.empty())
37 ATH_CHECK(m_dataRateMonTool.retrieve());
38
39 return StatusCode::SUCCESS;
40
41}
42
47template<class ContainerType>
48StatusCode ITkPixelCnvTool::convertToByteStream(const ContainerType* cont) const {
49
50 //Get the cabling
52 const ITkPixelCablingData* cabling = *cablingData;
53
54 //Get the full event assembler from ByteStreamCnvSvcBase
55 //SrcIdMap translates lower lvl IDs into higher lvl, e. g. ROD -> ROB, ROB -> ROS, ROS -> Det
57 ATH_CHECK(m_byteStreamCnvSvc->getFullEventAssembler(fea, "ITkPixelRawCont"));
58
59 fea->setDetEvtType(0x0);
60 fea->setLvl1TriggerType(0x0);
61
62 //Expose the buffer to be filled with the encoded data
63 //Other BS converters use FullEventAssembler<SrcIdMap>::RODDATA,
64 //which is just a typedef for std::vector<uint32_t>. Why the extra
65 //layer of renaming?
66 std::vector<uint32_t>* rod;
67
68 //sort the RDO hits based on the FE
69 const std::map<ITkPixelOnlineId, ITkPixLayout<uint16_t>> EventHitMaps = m_hitSortingTool->sortRDOHits(cont, cabling);
70
71 int nRODs = 0;
72
73 for (const auto& [onlineID, hitMap] : EventHitMaps){
74
75 //make a copy of the onlineID
76 uint32_t onID = (uint32_t)onlineID;
77
78 //Encode the FE hits
79 std::vector<uint32_t> encodedStream = m_encodingTool->encodeFE(hitMap, onID & 0x3);
80
81 //Is this a merged quad? If so, collapse the chip ID in the online identifier to 00
82 //we can get the information from cabling's online -> modlue Info map.
83 ITkPixelCabling::ModuleInfo mi = cabling->offlineModuleInfo((onID >> 2) << 2);
84 if (mi.type == ITkPixelCabling::ModuleType::MergedQuad) onID = (onID >> 2) << 2;
85
86 // passing information to the monitoring tool if initialised
87 if (not m_dataRateMonTool.empty()) {
88 m_dataRateMonTool->fill(mi.id.get_identifier32().get_compact(), encodedStream, hitMap);
89 }
90
91 //At this point, the ROD identifier will be labelled with lowest two bits 00 for single
92 //chips, chip 00 in unmerged quads and for entire merged quads, and with
93 //the rest up to 0x3 for the remaining 3 chips in unmerged quads. The higher bits are
94 //the online 'base'. We need this because of the unmerged quads, where one
95 //offline entity maps on 4 online entities.
96
97
98 //Create ROD and insert the payload
99 rod = fea->getRodData(onID);
100 if (rod->size() == 0) nRODs++;
101 rod->insert(rod->end(), encodedStream.begin(), encodedStream.end());
102
103 }
104 std::cout << "nRODs = " << nRODs << "\n";
105
106 return StatusCode::SUCCESS;
107}
108
#define ATH_CHECK
Evaluate an expression and check for errors.
InDetRawDataContainer< InDetRawDataCollection< ITkPixelRDORawData > > ITkPixelRDO_Container
InDetRawDataContainer< InDetRawDataCollection< PixelRDORawData > > PixelRDO_Container
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Template class for assembling a full atlas raw event from subfragments.
void setLvl1TriggerType(uint8_t m)
change LVL1 Trigger Type
void setDetEvtType(uint32_t m)
change Detector Event Type
RODDATA * getRodData(uint32_t id)
get a block of ROD data
ITkPixelCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
SG::ReadCondHandleKey< ITkPixelCablingData > m_pixelCablingKey
StatusCode convertToByteStream(const ContainerType *cont) const
Take ITkPixelRDO_Container or PixelRDO_Container and translate it to bytestream.
virtual StatusCode initialize() override
Retrieve helper tools.
ServiceHandle< IByteStreamCnvSvc > m_byteStreamCnvSvc
ToolHandle< ITkPixelEncodingTool > m_encodingTool
ToolHandle< ITkPixelHitSortingTool > m_hitSortingTool
ToolHandle< ITkPixelDataRateMonTool > m_dataRateMonTool