ATLAS Offline Software
FPGADataFormatAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 #include "AthenaKernel/Chrono.h"
7 #include <fstream>
8 
10 {
13 
14  ATH_CHECK(m_FPGADataFormatTool.retrieve());
15  ATH_CHECK(m_testVectorTool.retrieve());
17  ATH_CHECK(m_xAODClusterMaker.retrieve());
18  ATH_CHECK(m_xAODSpacePointMaker.retrieve());
19 
20  ATH_CHECK(m_chronoSvc.retrieve());
21 
22  return StatusCode::SUCCESS;
23 }
24 
25 StatusCode FPGADataFormatAlg::execute(const EventContext &ctx) const
26 {
27  auto pixelRDOHandle = SG::makeHandle(m_pixelRDOKey, ctx);
28  auto stripRDOHandle = SG::makeHandle(m_stripRDOKey, ctx);
29 
30  std::vector<uint64_t> outputData;
31 
32  std::vector<IdentifierHash> listOfPixelIds;
33  std::vector<IdentifierHash> listOfStripIds;
34 
35  ATH_CHECK(m_FPGADataFormatTool->convertPixelHitsToFPGADataFormat(*pixelRDOHandle, outputData, listOfPixelIds, ctx));
36 
37  // Report the output
38  ATH_MSG_DEBUG("ITK pixel encoded data");
39  int line = 0;
40  for (const auto &var : outputData)
41  {
42  ATH_MSG_DEBUG("Line: " << line << " data: " << std::hex << var);
43  line++;
44  }
45 
46  outputData.clear();
47 
48  {
49  Athena::Chrono chrono("ConvertStripHitsToFPGADataFormat", m_chronoSvc.get());
50  ATH_CHECK(m_FPGADataFormatTool->convertStripHitsToFPGADataFormat(*stripRDOHandle, outputData, listOfStripIds, ctx));
51  }
52 
53  // Report the output
54  ATH_MSG_DEBUG("ITK Strip encoded data");
55  line = 0;
56  for (const auto &var : outputData)
57  {
58  ATH_MSG_DEBUG("Line: " << line << " data: " << std::hex << var);
59  line++;
60  }
61 
62  // To make the xAOD, we need the aux data
63  std::unique_ptr<EFTrackingTransient::Metadata> metadata =
64  std::make_unique<EFTrackingTransient::Metadata>();
67 
68  // Starting from here validate the conversion tool
69  // First read in the test vector
70  // Check if the path is set
71  // If the path is set, read in the test vector and call the decode function
72  EFTrackingFPGAIntegration::TVHolder pixelEDMTV("PixelEDM");
73  if (m_pixelEDMRefTVPath.empty())
74  {
75  ATH_MSG_DEBUG("The path to the pixel EDM reference test vector is not set, skipping");
76  }
77  else
78  {
79  ATH_CHECK(m_testVectorTool->prepareTV(m_pixelEDMRefTVPath, pixelEDMTV.refTV));
80  {
81  Athena::Chrono chrono("DecodePixelEDM", m_chronoSvc.get());
82  ATH_CHECK(m_outputConversionTool->decodePixelEDM(pixelEDMTV.refTV, metadata.get(), pcAux));
83  }
84  }
85 
86  EFTrackingFPGAIntegration::TVHolder stripEDMTV("StripEDM");
87  if (m_stripEDMRefTVPath.empty())
88  {
89  ATH_MSG_DEBUG("The path to the strip EDM reference test vector is not set, skipping");
90  }
91  else
92  {
93  ATH_CHECK(m_testVectorTool->prepareTV(m_stripEDMRefTVPath, stripEDMTV.refTV));
94  {
95  Athena::Chrono chrono("DecodeStripEDM", m_chronoSvc.get());
96  ATH_CHECK(m_outputConversionTool->decodeStripEDM(stripEDMTV.refTV, metadata.get(), scAux));
97  }
98  }
99 
100  EFTrackingFPGAIntegration::TVHolder spacePointTV("SpacePoint");
101  if (m_spacePointRefTVPath.empty())
102  {
103  ATH_MSG_DEBUG("The path to the space point reference test vector is not set, skipping");
104  }
105  else
106  {
107  ATH_CHECK(m_testVectorTool->prepareTV(m_spacePointRefTVPath, spacePointTV.refTV));
108 
109  {
110  Athena::Chrono chrono("DecodeSpacePoints", m_chronoSvc.get());
111  ATH_CHECK(m_outputConversionTool->decodeSpacePoints(spacePointTV.refTV, metadata.get()));
112  }
113  }
114 
115  // Print event summary
116  if (msgLvl(MSG::DEBUG))
117  {
118  ATH_MSG_DEBUG("===================Event Summary====================");
119  ATH_MSG_DEBUG("Metadata: ");
120 
121  ATH_MSG_DEBUG("\tnumOfPixelClusters: " << metadata->numOfPixelClusters);
122  ATH_MSG_DEBUG("\tpcRdoIndexSize: " << metadata->pcRdoIndexSize);
123  ATH_MSG_DEBUG("Pixel Cluster RDO Index: ");
124  for (unsigned int i = 0; i < metadata->pcRdoIndexSize; i++)
125  {
126  ATH_MSG_DEBUG("\tCluster [" << i << "] has " << metadata->pcRdoIndex[i] << " RDOs");
127  }
128 
129  // print the pixel cluster rdo list
130  ATH_MSG_DEBUG("Pixel Cluster RDO List: ");
131  for (const auto &rdo : pcAux.rdoList)
132  {
133  ATH_MSG_DEBUG("\t" << rdo);
134  }
135 
136  ATH_MSG_DEBUG("\tnumOfStripClusters: " << metadata->numOfStripClusters);
137  ATH_MSG_DEBUG("\tscRdoIndexSize: " << metadata->scRdoIndexSize);
138  ATH_MSG_DEBUG("Strip Cluster RDO Index: ");
139  for (unsigned int i = 0; i < metadata->scRdoIndexSize; i++)
140  {
141  ATH_MSG_DEBUG("\tCluster [" << i << "] has " << metadata->scRdoIndex[i] << " RDOs");
142  }
143 
144  // print the strip cluster rdo list
145  ATH_MSG_DEBUG("Strip Cluster RDO List: ");
146  for (const auto &rdo : scAux.rdoList)
147  {
148  ATH_MSG_DEBUG("\t" << rdo);
149  }
150 
151  // print pcAux
152  ATH_MSG_DEBUG("Pixel Cluster Aux: ");
153  for (unsigned int i = 0; i < metadata->numOfPixelClusters; i++)
154  {
155  ATH_MSG_DEBUG("===");
156  ATH_MSG_DEBUG("\tCluster [" << i << "] has id: " << pcAux.id[i]);
157  ATH_MSG_DEBUG("\tCluster [" << i << "] has idHash: " << pcAux.idHash[i]);
158  ATH_MSG_DEBUG("\tCluster [" << i << "] has localPosition x: " << pcAux.localPosition[2 * i]);
159  ATH_MSG_DEBUG("\tCluster [" << i << "] has localPosition y: " << pcAux.localPosition[2 * i + 1]);
160  ATH_MSG_DEBUG("\tCluster [" << i << "] has localCovariance xx: " << pcAux.localCovariance[2 * i]);
161  ATH_MSG_DEBUG("\tCluster [" << i << "] has localCovariance yy: " << pcAux.localCovariance[2 * i + 1]);
162  ATH_MSG_DEBUG("\tCluster [" << i << "] has globalPosition x: " << pcAux.globalPosition[3 * i]);
163  ATH_MSG_DEBUG("\tCluster [" << i << "] has globalPosition y: " << pcAux.globalPosition[3 * i + 1]);
164  ATH_MSG_DEBUG("\tCluster [" << i << "] has globalPosition z: " << pcAux.globalPosition[3 * i + 2]);
165  ATH_MSG_DEBUG("\tCluster [" << i << "] has channelsInPhi: " << pcAux.channelsInPhi[i]);
166  ATH_MSG_DEBUG("\tCluster [" << i << "] has totalToT: " << pcAux.totalToT[i]);
167  }
168 
169  // print scAux
170  ATH_MSG_DEBUG("Strip Cluster Aux: ");
171  for (unsigned int i = 0; i < metadata->numOfStripClusters; i++)
172  {
173  ATH_MSG_DEBUG("===");
174  ATH_MSG_DEBUG("\tCluster [" << i << "] has id: " << scAux.id[i]);
175  ATH_MSG_DEBUG("\tCluster [" << i << "] has idHash: " << scAux.idHash[i]);
176  ATH_MSG_DEBUG("\tCluster [" << i << "] has localPosition x: " << scAux.localPosition[i]);
177  ATH_MSG_DEBUG("\tCluster [" << i << "] has localCovariance xx: " << scAux.localCovariance[i]);
178  ATH_MSG_DEBUG("\tCluster [" << i << "] has globalPosition x: " << scAux.globalPosition[3 * i]);
179  ATH_MSG_DEBUG("\tCluster [" << i << "] has globalPosition y: " << scAux.globalPosition[3 * i + 1]);
180  ATH_MSG_DEBUG("\tCluster [" << i << "] has globalPosition z: " << scAux.globalPosition[3 * i + 2]);
181  ATH_MSG_DEBUG("\tCluster [" << i << "] has channelsInPhi: " << scAux.channelsInPhi[i]);
182  }
183  ATH_MSG_DEBUG("===================End of Event Summary====================");
184  }
185 
186  // Make the xAOD
187  {
188  Athena::Chrono chrono("MakePixelContainers", m_chronoSvc.get());
189  ATH_CHECK(m_xAODClusterMaker->makePixelClusterContainer(pcAux, metadata.get(), ctx));
190  }
191 
192  {
193  Athena::Chrono chrono("MakeStripContainers", m_chronoSvc.get());
194  ATH_CHECK(m_xAODClusterMaker->makeStripClusterContainer(scAux, metadata.get(), ctx));
195  }
196 
197  return StatusCode::SUCCESS;
198 }
EFTrackingFPGAIntegration::TVHolder::refTV
std::vector< uint64_t > refTV
Definition: TestVectorTool.h:34
FPGADataFormatAlg::m_stripRDOKey
SG::ReadHandleKey< SCT_RDO_Container > m_stripRDOKey
Definition: FPGADataFormatAlg.h:43
EFTrackingTransient::PixelClusterAuxInput::localPosition
std::vector< float > localPosition
Definition: EFTrackingTransient.h:229
beamspotnt.var
var
Definition: bin/beamspotnt.py:1393
EFTrackingTransient::PixelClusterAuxInput
The PixelClusterAuxInput struct is used to simplify the creaction of the xAOD::PixelClusterContainer.
Definition: EFTrackingTransient.h:226
EFTrackingTransient::StripClusterAuxInput::globalPosition
std::vector< float > globalPosition
Definition: EFTrackingTransient.h:216
FPGADataFormatAlg::m_xAODSpacePointMaker
ToolHandle< xAODSpacePointMaker > m_xAODSpacePointMaker
Definition: FPGADataFormatAlg.h:64
FPGADataFormatAlg::m_xAODClusterMaker
ToolHandle< xAODClusterMaker > m_xAODClusterMaker
Definition: FPGADataFormatAlg.h:63
FPGADataFormatAlg::m_chronoSvc
ServiceHandle< IChronoStatSvc > m_chronoSvc
Definition: FPGADataFormatAlg.h:67
EFTrackingTransient::StripClusterAuxInput::localCovariance
std::vector< float > localCovariance
Definition: EFTrackingTransient.h:213
FPGADataFormatAlg::m_pixelEDMRefTVPath
Gaudi::Property< std::string > m_pixelEDMRefTVPath
Pixel L2G reference test vector.
Definition: FPGADataFormatAlg.h:46
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Chrono.h
Exception-safe IChronoSvc caller.
dq_defect_bulk_create_defects.line
line
Definition: dq_defect_bulk_create_defects.py:27
EFTrackingTransient::StripClusterAuxInput::rdoList
std::vector< unsigned long long > rdoList
Definition: EFTrackingTransient.h:217
FPGADataFormatAlg::m_testVectorTool
ToolHandle< TestVectorTool > m_testVectorTool
Definition: FPGADataFormatAlg.h:57
python.checkMetadata.metadata
metadata
Definition: checkMetadata.py:175
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
FPGADataFormatAlg::m_pixelRDOKey
SG::ReadHandleKey< PixelRDO_Container > m_pixelRDOKey
Definition: FPGADataFormatAlg.h:42
Athena::Chrono
Exception-safe IChronoSvc caller.
Definition: Chrono.h:50
EFTrackingTransient::PixelClusterAuxInput::rdoList
std::vector< unsigned long long > rdoList
Definition: EFTrackingTransient.h:232
lumiFormat.i
int i
Definition: lumiFormat.py:85
FPGADataFormatAlg::initialize
virtual StatusCode initialize() override
Definition: FPGADataFormatAlg.cxx:9
EFTrackingTransient::PixelClusterAuxInput::localCovariance
std::vector< float > localCovariance
Definition: EFTrackingTransient.h:230
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
EFTrackingTransient::StripClusterAuxInput::idHash
std::vector< unsigned int > idHash
Definition: EFTrackingTransient.h:214
FPGADataFormatAlg::m_FPGADataFormatTool
ToolHandle< FPGADataFormatTool > m_FPGADataFormatTool
Definition: FPGADataFormatAlg.h:54
EFTrackingTransient::PixelClusterAuxInput::totalToT
std::vector< int > totalToT
Definition: EFTrackingTransient.h:237
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EFTrackingFPGAIntegration::TVHolder
Definition: TestVectorTool.h:29
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
FPGADataFormatAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Performs the data convertsion.
Definition: FPGADataFormatAlg.cxx:25
EFTrackingTransient::PixelClusterAuxInput::idHash
std::vector< unsigned int > idHash
Definition: EFTrackingTransient.h:228
FPGADataFormatAlg.h
EFTrackingTransient::StripClusterAuxInput
The StripClusterAuxInput struct is used to simplify the creaction of the xAOD::StripClusterContainer.
Definition: EFTrackingTransient.h:211
EFTrackingTransient::StripClusterAuxInput::localPosition
std::vector< float > localPosition
Definition: EFTrackingTransient.h:212
EFTrackingTransient::PixelClusterAuxInput::channelsInPhi
std::vector< int > channelsInPhi
Definition: EFTrackingTransient.h:233
FPGADataFormatAlg::m_outputConversionTool
ToolHandle< OutputConversionTool > m_outputConversionTool
Definition: FPGADataFormatAlg.h:60
EFTrackingTransient::PixelClusterAuxInput::id
std::vector< long unsigned int > id
Definition: EFTrackingTransient.h:227
EFTrackingTransient::PixelClusterAuxInput::globalPosition
std::vector< float > globalPosition
Definition: EFTrackingTransient.h:231
DEBUG
#define DEBUG
Definition: page_access.h:11
EFTrackingTransient::StripClusterAuxInput::id
std::vector< long unsigned int > id
Definition: EFTrackingTransient.h:215
EFTrackingTransient::StripClusterAuxInput::channelsInPhi
std::vector< int > channelsInPhi
Definition: EFTrackingTransient.h:218
FPGADataFormatAlg::m_stripEDMRefTVPath
Gaudi::Property< std::string > m_stripEDMRefTVPath
Strip L2G reference test vector.
Definition: FPGADataFormatAlg.h:48
FPGADataFormatAlg::m_spacePointRefTVPath
Gaudi::Property< std::string > m_spacePointRefTVPath
Space point reference test vector.
Definition: FPGADataFormatAlg.h:50