ATLAS Offline Software
Loading...
Searching...
No Matches
NRPC_RawDataProviderTool.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
8
9namespace Muon {
10
11
12NRPC_RawDataProviderTool::NRPC_RawDataProviderTool(const std::string& t, const std::string& n, const IInterface* p) :
13 base_class(t, n, p) {}
14
16
17 // Get ROBDataProviderSvc
18 ATH_CHECK(m_robDataProvider.retrieve());
19 ATH_CHECK(m_idHelperSvc.retrieve());
20
21 ATH_CHECK(m_rdoContainerKey.initialize());
22
23 ATH_CHECK(m_readKey.initialize());
24
25 ATH_MSG_DEBUG("initialize() successful in " << name());
26 return StatusCode::SUCCESS;
27}
28
30 const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs, xAOD::NRPCRDOContainer& nrpcContainer) const {
31 ATH_MSG_VERBOSE("convert(): " << vecRobs.size() << " ROBFragments.");
32
33 for (const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment* frag : vecRobs) {
34 // convert only if data payload is delivered
35 if (frag->rod_ndata() != 0) {
36 ATH_CHECK(fillCollections(*frag, nrpcContainer).ignore() );
37 } else {
38 ATH_MSG_DEBUG(" ROB " << MSG::hex << frag->source_id() << " is delivered with an empty payload" );
39 }
40 }
41
42 return StatusCode::SUCCESS;
43}
44
45StatusCode NRPC_RawDataProviderTool::convert() const // call decoding function using list of all detector ROBId's
46{
47 return convert(Gaudi::Hive::currentContext());
48}
49
51 const EventContext& ctx) const // call decoding function using list of all detector ROBId's
52{
53
54 SG::ReadCondHandle readCdo{m_readKey, ctx};
55 if (!readCdo.isValid()) {
56 ATH_MSG_ERROR("Null pointer to the read conditions object");
57 return StatusCode::FAILURE;
58 }
59 return convert(readCdo->getAllROBId(), ctx);
60}
61
62StatusCode NRPC_RawDataProviderTool::convert(const std::vector<IdentifierHash>& HashVec) const {
63 return convert(HashVec, Gaudi::Hive::currentContext());
64}
65
66StatusCode NRPC_RawDataProviderTool::convert(const std::vector<IdentifierHash>& HashVec, const EventContext& ctx) const {
67 SG::ReadCondHandle readCdo{m_readKey, ctx};
68 if (!readCdo.isValid()) {
69 ATH_MSG_ERROR("Null pointer to the read conditions object");
70 return StatusCode::FAILURE;
71 }
72 return convert(readCdo->getROBId(HashVec, msgStream()), ctx);
73}
74
75StatusCode NRPC_RawDataProviderTool::convert(const std::vector<uint32_t>& robIds) const {
76 return convert(robIds, Gaudi::Hive::currentContext());
77}
78
79StatusCode NRPC_RawDataProviderTool::convert(const std::vector<uint32_t>& robIds, const EventContext& ctx) const {
80 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> vecOfRobf;
81 m_robDataProvider->getROBData(ctx, robIds, vecOfRobf);
82 return convert(vecOfRobf, ctx);
83}
84
85StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs,
86 const std::vector<IdentifierHash>&) const {
87 return convert(vecRobs, Gaudi::Hive::currentContext());
88}
89
90StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs,
91 const std::vector<IdentifierHash>& /*collection*/, const EventContext& ctx) const {
92 return convert(vecRobs, ctx);
93}
94
95StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs) const {
96 return convert(vecRobs, Gaudi::Hive::currentContext());
97}
98
99StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs,
100 const EventContext& ctx) const {
101 ATH_MSG_VERBOSE("convert(): " << vecRobs.size() << " ROBFragments.");
102
103 SG::WriteHandle rdoContainer(m_rdoContainerKey, ctx);
104 ATH_CHECK(rdoContainer.record(std::make_unique<xAOD::NRPCRDOContainer>(), std::make_unique<xAOD::NRPCRDOAuxContainer>()));
105 // use the convert function in the NRPC_RawDataProviderTool class
106 ATH_CHECK(convertIntoContainer(vecRobs, *rdoContainer));
107 return StatusCode::SUCCESS;
108}
109
110
112#define WARNING_WITH_LINE(msg) ATH_MSG_WARNING(__FILE__ << ":" << __LINE__<< " " << msg)
113 try {
114 robFrag.check();
115 } catch (eformat::Issue& ex) {
116 ATH_MSG_VERBOSE(ex.what());
117 return StatusCode::SUCCESS; // error in fragment
118 }
119
120 //uint32_t nstat = robFrag.nstatus();
121 uint32_t version = robFrag.rod_version();
122 uint32_t sourceId = robFrag.source_id();
123 uint32_t rod_sourceId = robFrag.rod_source_id();
124
125 // Unpack sub-detector and board sector from sourceId
126 uint16_t subDetector = sourceId >> 16;
127 uint16_t boardSector = (sourceId & 0x00ffff);
128
129 ATH_MSG_VERBOSE("ROD version: " << MSG::hex << version << MSG::dec << " ROB source ID: " << MSG::hex << sourceId << MSG::dec
130 << " ROD source ID: " << MSG::hex << rod_sourceId << MSG::dec << " Subdetector: " << MSG::hex
131 << subDetector << MSG::dec << " boardSector: " << std::hex
132 << boardSector << std::dec );
133
134
135
136 // get the pointer to the data
137 BS data;
138 robFrag.rod_data(data);
139
140 const unsigned int data_size = robFrag.rod_ndata();
141
142
143 // Loop on words
144 unsigned int idata=0;
145 while (idata<data_size) {
146 if (data[idata]==6 && data[idata+4]==0xa0 && data[idata+5]==0) {
147 ATH_MSG_DEBUG("NRPC: Empty board " << std::hex << data[idata+4] << std::dec << " for " << std::hex << data[idata+1] << std::dec );
148 } else if (data[idata]<6) {
149 WARNING_WITH_LINE("NRPC: Corrupted: Number of words from board " << std::hex << data[idata+4] << std::dec << " is <6 :" << data[idata] );
150 break;
151 } else if ( idata+data[idata] > data_size) {
152 WARNING_WITH_LINE("NRPC: Corrupted number of words from board " << std::hex << data[idata+4] << std::dec << " is too large :" << std::hex << data[idata] << std::dec );
153 break;
154 } else if ( (data[idata+data[idata]-2] & 0x000000ff) != 0xa0) {
155 WARNING_WITH_LINE("NRPC: Missing expected trailer a0" );
156 break;
157 } else {
158
159 // Bit inversion and manipulation needed to decode nominal BCID
160 uint32_t bcid12 = (data[idata+2] & 0xff000000) >> 24;
161 uint32_t bcid34 = (data[idata+2] & 0x00ff0000) >> 8;
162 uint32_t bcid56 = (data[idata+2] & 0x0000ff00) << 8;
163 uint32_t bcid78 = (data[idata+2] & 0x000000ff) << 24;
164 uint32_t bcid_nom = (bcid12 | bcid34 | bcid56 | bcid78) >> 4;
165
166 // Decode data
167 for (unsigned int i=0; i<data[idata]-6; i++) {
168 uint16_t board = (data[idata+4+i] & 0x000000ff) ;
169 uint16_t chan = (data[idata+4+i] & 0x0000ff00) >> 8 ;
170 float tot = ((data[idata+4+i] & 0x007f0000) >> 16)*0.4 ;
171 float time = ((data[idata+4+i] & 0x0f000000) >> 24)*1.6 ;
172 uint32_t bcid_hit = (data[idata+4+i] & 0xf0000000) >> 28 ;
173
174 // Compute the BCID of the hit combining the nominal BCID with the last 4 bits from the hit (bcid_hit)
175 uint32_t bcid_nom_4bits = (bcid_nom & 0x0000000f) ;
176 uint32_t bcid = 0 ;
177 if (bcid_hit >= bcid_nom_4bits) { // The BCID of the hit is subsequent to the nominal
178 bcid = ( (bcid_nom & 0xfffffff0) | bcid_hit );
179 } else {
180 bcid = ( (bcid_nom & 0xfffffff0) | bcid_hit ) + 0x00000010;
181 }
182
183 // Build the RDO
184 xAOD::NRPCRDO* NrpcRdo = rdoIdc.push_back(std::make_unique<xAOD::NRPCRDO>());
185 NrpcRdo->setBcid(bcid);
186 NrpcRdo->setTime(time);
187 NrpcRdo->setSubdetector(subDetector);
188 NrpcRdo->setBoardsector(boardSector);
189 NrpcRdo->setBoard(board);
190 NrpcRdo->setChannel(chan);
191 NrpcRdo->setTimeoverthr(tot);
192 }
193 }
194
195 idata+=data[idata];
196 }
197
198
199 return StatusCode::SUCCESS;
200
201} // end fillCollections
202
203
204
205
206} // namespace Muon
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
#define WARNING_WITH_LINE(msg)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
virtual StatusCode initialize() override
standard Athena-Algorithm method
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
virtual StatusCode fillCollections(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, xAOD::NRPCRDOContainer &rdoIdc) const
SG::WriteHandleKey< xAOD::NRPCRDOContainer > m_rdoContainerKey
OFFLINE_FRAGMENTS_NAMESPACE::PointerType BS
NRPC_RawDataProviderTool(const std::string &, const std::string &, const IInterface *)
SG::ReadCondHandleKey< RpcCablingMap > m_readKey
virtual StatusCode convert(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vecRobs) const override
Convert method - declared in Muon::IMuonRdoToPrepDataTool.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode convert() const override
the new ones
virtual StatusCode convertIntoContainer(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vecRobs, xAOD::NRPCRDOContainer &nrpcContainer) const
Convert method.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void setBoardsector(uint16_t Boardsector)
Set the sector of the board within the subdetector.
void setBoard(uint16_t Board)
Set the number of the TDC channel.
void setTimeoverthr(float Timeoverthr)
Set the time over threshold.
void setSubdetector(uint16_t SubDet)
Set the sub detector.
void setChannel(uint16_t Channel)
Set the fire channel number.
void setTime(float Time)
Set the trigger time [ns].
void setBcid(uint32_t Bcid)
Set the bunch crossing identifier.
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27
NRPCRDO_v1 NRPCRDO
Define the version of the NRPC RDO class.
Definition NRPCRDO.h:13
NRPCRDOContainer_v1 NRPCRDOContainer
Define the version of the NRPC RDO container.