ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetEventCnv
ITkPixelByteStreamCnv
src
ITkPixelDecodingAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
ITkPixelDecodingAlg.h
"
6
#include "
StoreGate/ReadHandle.h
"
7
#include "eformat/ROBFragment.h"
8
9
#define ENABLE_TIMING = true;
10
#ifdef ENABLE_TIMING
11
#define SCOPED_TIMER(name, msg) ITkPixelDecoding::ScopedTimer timer_##__LINE__(name, msg)
12
#else
13
#define SCOPED_TIMER(name, msg)
14
#endif
15
16
17
using namespace
itksw::pix::endec;
18
19
ITkPixelDecodingAlg::ITkPixelDecodingAlg
(
const
std::string& name, ISvcLocator* pSvcLocator) :
20
AthReentrantAlgorithm
(name, pSvcLocator)
21
{
22
23
}
24
25
26
StatusCode
ITkPixelDecodingAlg::initialize
()
27
{
28
ATH_CHECK
(
m_robDataProviderSvc
.retrieve());
29
30
ATH_CHECK
(
m_pixelCablingKey
.initialize());
31
32
ATH_CHECK
(
detStore
()->retrieve(
m_idHelper
,
"PixelID"
));
33
34
ATH_CHECK
(
m_pixelRDOKey
.initialize());
35
36
//this should go into the cabling likely...
37
for
(
size_t
hash = 0; hash <
m_idHelper
->wafer_hash_max(); hash++){
38
m_sourceIDs
.push_back(
m_idHelper
->wafer_id(hash).get_identifier32().get_compact() | 0b00 );
39
m_sourceIDs
.push_back(
m_idHelper
->wafer_id(hash).get_identifier32().get_compact() | 0b10 );
40
m_sourceIDs
.push_back(
m_idHelper
->wafer_id(hash).get_identifier32().get_compact() | 0b01 );
41
m_sourceIDs
.push_back(
m_idHelper
->wafer_id(hash).get_identifier32().get_compact() | 0b11 );
42
}
43
44
return
StatusCode::SUCCESS;
45
}
46
47
StatusCode
ITkPixelDecodingAlg::execute
(
const
EventContext& ctx)
const
48
{
49
//Timing
50
SCOPED_TIMER
(
"ITkPixelDecodingAlg::execute"
,
msg
());
51
52
//Retrieve the ROB IDs from cabling - dummy as of now, happens in initialize()
53
SG::ReadCondHandle<ITkPixelCablingData>
cablingData(
m_pixelCablingKey
, ctx);
54
const
ITkPixelCablingData
* cabling = *cablingData;
55
56
//Instantiate the output. RN using the old pixel RDO, nothing fancier than that
57
std::unique_ptr<PixelRDO_Container> rdoCont = std::make_unique<PixelRDO_Container>(
m_idHelper
->wafer_hash_max());
58
59
//Instantiate the decoder. Doing this once per event is fine and MT-safe
60
//It needs a "callback" that implements methods required by concepts. This is
61
//the drawback of using an external code (by ITk online sw). Each of these methods
62
//is then called at appropriate places in the decoding. The decoder is configured
63
//with data format options. The callback can do whatever with the decoded hits
64
//e. g. print them on the screen or put them in a container as RDOs.
65
DataFormat
fmt
;
66
fmt
.options.en_chip_id =
true
;
67
fmt
.options.en_eos =
true
;
68
PixelCallbacks::RDOCallback
cb(rdoCont.get(),
m_idHelper
,
msg
());
69
DecCore<PixelCallbacks::RDOCallback> core(
fmt
, cb);
70
core.initialize();
71
72
//Invoke ROBDataProviderService, fetch the concerned ROBs.
73
std::vector<const eformat::ROBFragment<const uint32_t*>*> ROBs;
74
m_robDataProviderSvc
->getROBData(ctx,
m_sourceIDs
, ROBs);
75
ATH_MSG_DEBUG
(
"Retrieved "
<< ROBs.size() <<
" fragments"
);
76
77
//We can now loop over the payloads of the ROB fragments retrieved earlier.
78
//There's as of now a little annoyance that the decoder eats 64 bit frames
79
//but the ROBs come in 32 bits. At least they have the same endian polarity.
80
//Nevertheless, we need to rearrange them.
81
std::vector<uint64_t> payload64;
82
std::array<std::vector<uint64_t>, 4> split_streams;
83
84
ATH_MSG_DEBUG
(
"***** ITkPixelDecodingRDOAlg::execute --------- ROBs size"
<< ROBs.size());
85
for
(
const
auto
& ROB : ROBs){
86
const
uint32_t* payload = ROB->rod_data();
87
uint32_t
length
= ROB->rod_ndata();
88
89
ATH_MSG_DEBUG
(
"***** ITkPixelDecodingRDOAlg::execute --------- ROD # data"
<<
length
);
90
91
//Translate the data into 64 bits. We know the length, so we can reserve
92
//the space to avoid reallocation. Since the frames are always 64 bits split
93
//into 32, they'll always be divisible by 2 without modulo.
94
payload64.clear();
95
payload64.resize(
length
/ 2);
96
for
(uint32_t word = 0; word <
length
; word += 2){
97
payload64[word / 2] = ((uint64_t)(payload[word]) << 32) | payload[word + 1];
98
}
99
100
101
//Need to set the correct offline ID for this ROB
102
ITkPixelCabling::ModuleInfo
mi = cabling->offlineModuleInfo(ROB->rob_source_id());
103
cb.
setOfflineID
(mi.
id
.get_identifier32().get_compact());
104
105
//Set transform type
106
cb.
setTransformType
(mi.
transform
);
107
108
//If this is a merged quad, it has all 4 chips in one ROB
109
//In such case we need to decode them separately. Otherwise
110
//It's a 1:1 correspondence
111
112
if
(mi.
type
!=
ITkPixelCabling::ModuleType::MergedQuad
){
113
cb.
setChipID
(0);
114
core.decode(payload64);
115
}
116
else
{
117
//split according to chip ID, which is always in highest bits 1 and 2
118
for
(
auto
&v : split_streams) v.clear();
119
for
(
const
uint64_t& word64: payload64) split_streams[(word64 >> 61) & 0b11].push_back(word64);
120
for
(uint8_t chipID = 0; chipID < 4; chipID++){
121
if
(!split_streams[chipID].
empty
()){
122
cb.
setChipID
(chipID);
123
core.decode(split_streams[chipID]);
124
}
125
}
126
}
127
}
128
129
//The container is filled by now. We can write it to SG
130
SG::WriteHandle<PixelRDO_Container>
pixelRDOContainerHandle(
m_pixelRDOKey
, ctx);
131
ATH_CHECK
(pixelRDOContainerHandle.
record
(std::move(rdoCont)));
132
133
return
StatusCode::SUCCESS;
134
}
135
136
StatusCode
ITkPixelDecodingAlg::finalize
(){
137
return
StatusCode::SUCCESS;
138
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
length
double length(const pvec &v)
Definition
FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
SCOPED_TIMER
#define SCOPED_TIMER(name, msg)
Definition
ITkPixelDecodingAlg.cxx:11
ITkPixelDecodingAlg.h
ReadHandle.h
Handle class for reading from StoreGate.
fmt
const char *const fmt
Definition
TripleGaussCollFit.cxx:84
empty
static const Attributes_t empty
Definition
XmlStreamer.cxx:16
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
AthCommonAlgorithm< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
ITkPixelCablingData
Definition
ITkPixelCablingData.h:105
ITkPixelDecodingAlg::initialize
virtual StatusCode initialize() override
Definition
ITkPixelDecodingAlg.cxx:26
ITkPixelDecodingAlg::m_robDataProviderSvc
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
Definition
ITkPixelDecodingAlg.h:41
ITkPixelDecodingAlg::m_sourceIDs
std::vector< uint32_t > m_sourceIDs
Definition
ITkPixelDecodingAlg.h:47
ITkPixelDecodingAlg::finalize
virtual StatusCode finalize() override
Definition
ITkPixelDecodingAlg.cxx:136
ITkPixelDecodingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
ITkPixelDecodingAlg.cxx:47
ITkPixelDecodingAlg::m_pixelRDOKey
SG::WriteHandleKey< PixelRDO_Container > m_pixelRDOKey
Definition
ITkPixelDecodingAlg.h:45
ITkPixelDecodingAlg::m_idHelper
const PixelID * m_idHelper
Definition
ITkPixelDecodingAlg.h:49
ITkPixelDecodingAlg::m_pixelCablingKey
SG::ReadCondHandleKey< ITkPixelCablingData > m_pixelCablingKey
Definition
ITkPixelDecodingAlg.h:43
ITkPixelDecodingAlg::ITkPixelDecodingAlg
ITkPixelDecodingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
ITkPixelDecodingAlg.cxx:19
PixelCallbacks::RDOCallback
Definition
ITkPixelDecodingAlg.h:71
PixelCallbacks::RDOCallback::setChipID
void setChipID(const uint8_t &chipID)
Definition
ITkPixelDecodingAlg.h:126
PixelCallbacks::RDOCallback::setOfflineID
void setOfflineID(const uint32_t &offlineID)
Definition
ITkPixelDecodingAlg.h:121
PixelCallbacks::RDOCallback::setTransformType
void setTransformType(const ITkPixelCabling::TransformType &transform)
Definition
ITkPixelDecodingAlg.h:131
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ITkPixelCabling::MergedQuad
@ MergedQuad
Definition
ITkPixelCablingData.h:28
ITkPixelCabling::ModuleInfo
Definition
ITkPixelCablingData.h:49
ITkPixelCabling::ModuleInfo::id
ID id
Definition
ITkPixelCablingData.h:50
ITkPixelCabling::ModuleInfo::type
ModuleType type
Definition
ITkPixelCablingData.h:51
ITkPixelCabling::ModuleInfo::transform
TransformType transform
Definition
ITkPixelCablingData.h:52
Generated on
for ATLAS Offline Software by
1.17.0