ATLAS Offline Software
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 
9 namespace Muon {
10 
11 
12 NRPC_RawDataProviderTool::NRPC_RawDataProviderTool(const std::string& t, const std::string& n, const IInterface* p) :
13  base_class(t, n, p) {
14  declareInterface<Muon::IMuonRawDataProviderTool>(this);
15 
16 }
17 
19 
20  // Get ROBDataProviderSvc
21  ATH_CHECK(m_robDataProvider.retrieve());
22  ATH_CHECK(m_idHelperSvc.retrieve());
23 
24  ATH_CHECK(m_rdoContainerKey.initialize());
25 
27 
28  ATH_MSG_DEBUG("initialize() successful in " << name());
29  return StatusCode::SUCCESS;
30 }
31 
33  const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs, xAOD::NRPCRDOContainer& nrpcContainer) const {
34  ATH_MSG_VERBOSE("convert(): " << vecRobs.size() << " ROBFragments.");
35 
36  for (const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment* frag : vecRobs) {
37  // convert only if data payload is delivered
38  if (frag->rod_ndata() != 0) {
39  ATH_CHECK(fillCollections(*frag, nrpcContainer).ignore() );
40  } else {
41  ATH_MSG_DEBUG(" ROB " << MSG::hex << frag->source_id() << " is delivered with an empty payload" );
42  }
43  }
44 
45  return StatusCode::SUCCESS;
46 }
47 
48 StatusCode NRPC_RawDataProviderTool::convert() const // call decoding function using list of all detector ROBId's
49 {
50  return convert(Gaudi::Hive::currentContext());
51 }
52 
54  const EventContext& ctx) const // call decoding function using list of all detector ROBId's
55 {
56 
57  SG::ReadCondHandle<MuonNRPC_CablingMap> readHandle{m_readKey, ctx};
58  const MuonNRPC_CablingMap* readCdo{*readHandle};
59  if (!readCdo) {
60  ATH_MSG_ERROR("Null pointer to the read conditions object");
61  return StatusCode::FAILURE;
62  }
63 
64  const std::vector<uint32_t>& robIds=readCdo->getAllROBId();
65 
66  return convert(robIds, ctx);
67 }
68 
69 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<IdentifierHash>& HashVec) const {
70  return convert(HashVec, Gaudi::Hive::currentContext());
71 }
72 
73 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<IdentifierHash>& HashVec, const EventContext& ctx) const {
75  const MuonNRPC_CablingMap* readCdo{*readHandle};
76  if (!readCdo) {
77  ATH_MSG_ERROR("Null pointer to the read conditions object");
78  return StatusCode::FAILURE;
79  }
80  return convert(readCdo->getROBId(HashVec, msgStream()), ctx);
81 }
82 
83 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<uint32_t>& robIds) const {
84  return convert(robIds, Gaudi::Hive::currentContext());
85 }
86 
87 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<uint32_t>& robIds, const EventContext& ctx) const {
88  std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> vecOfRobf;
89  m_robDataProvider->getROBData(ctx, robIds, vecOfRobf);
90  return convert(vecOfRobf, ctx);
91 }
92 
93 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs,
94  const std::vector<IdentifierHash>&) const {
95  return convert(vecRobs, Gaudi::Hive::currentContext());
96 }
97 
98 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs,
99  const std::vector<IdentifierHash>& /*collection*/, const EventContext& ctx) const {
100  return convert(vecRobs, ctx);
101 }
102 
103 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs) const {
104  return convert(vecRobs, Gaudi::Hive::currentContext());
105 }
106 
107 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs,
108  const EventContext& ctx) const {
109  ATH_MSG_VERBOSE("convert(): " << vecRobs.size() << " ROBFragments.");
110 
112  ATH_CHECK(rdoContainerHandle.record(std::make_unique<xAOD::NRPCRDOContainer>(), std::make_unique<xAOD::NRPCRDOAuxContainer>()));
113  xAOD::NRPCRDOContainer* rdoContainer = rdoContainerHandle.ptr();
114 
115  // use the convert function in the NRPC_RawDataProviderTool class
116  ATH_CHECK(convertIntoContainer(vecRobs, *rdoContainer));
117 
118  return StatusCode::SUCCESS;
119 }
120 
121 
123 #define WARNING_WITH_LINE(msg) ATH_MSG_WARNING(__FILE__ << ":" << __LINE__<< " " << msg)
124  try {
125  robFrag.check();
126  } catch (eformat::Issue& ex) {
127  ATH_MSG_VERBOSE(ex.what());
128  return StatusCode::SUCCESS; // error in fragment
129  }
130 
131  //uint32_t nstat = robFrag.nstatus();
132  uint32_t version = robFrag.rod_version();
133  uint32_t sourceId = robFrag.source_id();
134  uint32_t rod_sourceId = robFrag.rod_source_id();
135 
136  // Unpack sub-detector and tdc sector from sourceId
137  uint16_t subDetector = sourceId >> 16;
138  uint16_t tdcSector = (sourceId & 0x00ffff);
139 
140  ATH_MSG_VERBOSE("ROD version: " << MSG::hex << version << MSG::dec << " ROB source ID: " << MSG::hex << sourceId << MSG::dec
141  << " ROD source ID: " << MSG::hex << rod_sourceId << MSG::dec << " Subdetector: " << MSG::hex
142  << subDetector << MSG::dec << " tdcSector: " << std::hex
143  << tdcSector << std::dec );
144 
145 
146 
147  // get the pointer to the data
148  BS data;
149  robFrag.rod_data(data);
150 
151  const unsigned int data_size = robFrag.rod_ndata();
152 
153 
154  // Loop on words
155  unsigned int idata=0;
156  while (idata<data_size) {
157  if (data[idata]==6 && data[idata+4]==0xa0 && data[idata+5]==0) {
158  ATH_MSG_DEBUG("NRPC: Empty tdc " << std::hex << data[idata+4] << std::dec << " for " << std::hex << data[idata+1] << std::dec );
159  } else if (data[idata]<6) {
160  WARNING_WITH_LINE("NRPC: Corrupted: Number of words from tdc " << std::hex << data[idata+4] << std::dec << " is <6 :" << data[idata] );
161  break;
162  } else if ( (data[idata+data[idata]-2] & 0x000000ff) != 0xa0) {
163  WARNING_WITH_LINE("NRPC: Missing expected trailer a0" );
164  break;
165  } else {
166 
167  // Bit inversion and manipulation needed to decode nominal BCID
168  uint32_t bcid12 = (data[idata+2] & 0xff000000) >> 24;
169  uint32_t bcid34 = (data[idata+2] & 0x00ff0000) >> 8;
170  uint32_t bcid56 = (data[idata+2] & 0x0000ff00) << 8;
171  uint32_t bcid78 = (data[idata+2] & 0x000000ff) << 24;
172  uint32_t bcid_nom = (bcid12 | bcid34 | bcid56 | bcid78) >> 4;
173 
174  // Decode data
175  for (unsigned int i=0; i<data[idata]-6; i++) {
176  uint16_t tdc = (data[idata+4] & 0x000000ff) ;
177  uint16_t chan = (data[idata+4] & 0x0000ff00) >> 8 ;
178  float tot = ((data[idata+4] & 0x00ff0000) >> 16)*0.4 ;
179  float time = ((data[idata+4] & 0x0f000000) >> 24)*1.6 ;
180  uint32_t bcid_hit = (data[idata+4] & 0xf0000000) >> 28 ;
181 
182  // Compute the BCID of the hit combining the nominal BCID with the last 4 bits from the hit (bcid_hit)
183  uint32_t bcid_nom_4bits = (bcid_nom & 0x0000000f) ;
184  uint32_t bcid = 0 ;
185  if (bcid_hit >= bcid_nom_4bits) { // The BCID of the hit is subsequent to the nominal
186  bcid = ( (bcid_nom & 0xfffffff0) | bcid_hit );
187  } else {
188  bcid = ( (bcid_nom & 0xfffffff0) | bcid_hit ) + 0x00000010;
189  }
190 
191  // Build the RDO
192  xAOD::NRPCRDO* NrpcRdo = new xAOD::NRPCRDO();
193  rdoIdc.push_back(NrpcRdo);
194  NrpcRdo->setBcid(bcid);
195  NrpcRdo->setTime(time);
196  NrpcRdo->setSubdetector(subDetector);
197  NrpcRdo->setTdcsector(tdcSector);
198  NrpcRdo->setTdc(tdc);
199  NrpcRdo->setChannel(chan);
200  NrpcRdo->setTimeoverthr(tot);
201 
202  }
203  }
204 
205  idata+=data[idata];
206  }
207 
208 
209  return StatusCode::SUCCESS;
210 
211 } // end fillCollections
212 
213 
214 
215 
216 } // namespace Muon
xAOD::NRPCRDO_v1::setTdcsector
void setTdcsector(uint16_t Tdcsector)
Set the sector of the tdc within the subdetector.
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
Issue
Configuration Issue
Definition: PscIssues.h:31
Muon::NRPC_RawDataProviderTool::m_readKey
SG::ReadCondHandleKey< MuonNRPC_CablingMap > m_readKey
Definition: NRPC_RawDataProviderTool.h:106
Muon::NRPC_RawDataProviderTool::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Definition: NRPC_RawDataProviderTool.h:104
NRPC_RawDataProviderTool.h
xAOD::NRPCRDO_v1
Definition: NRPCRDO_v1.h:14
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
MuonNRPC_CablingMap
Definition: MuonNRPC_CablingMap.h:21
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:45
Muon::NRPC_RawDataProviderTool::fillCollections
virtual StatusCode fillCollections(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, xAOD::NRPCRDOContainer &rdoIdc) const
Definition: NRPC_RawDataProviderTool.cxx:122
xAOD::NRPCRDO_v1::setChannel
void setChannel(uint16_t Channel)
Set the fire channel number.
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
xAOD::NRPCRDO_v1::setSubdetector
void setSubdetector(uint16_t SubDet)
Set the sub detector.
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Muon::NRPC_RawDataProviderTool::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: NRPC_RawDataProviderTool.cxx:18
xAOD::NRPCRDO_v1::setBcid
void setBcid(uint32_t Bcid)
Set the bunch crossing identifier.
Muon::NRPC_RawDataProviderTool::m_rdoContainerKey
SG::WriteHandleKey< xAOD::NRPCRDOContainer > m_rdoContainerKey
Definition: NRPC_RawDataProviderTool.h:99
xAOD::NRPCRDO_v1::setTdc
void setTdc(uint16_t Tdc)
Set the number of the TDC channel.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
LB_AnalMapSplitter.tot
tot
Definition: LB_AnalMapSplitter.py:46
Muon::NRPC_RawDataProviderTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: NRPC_RawDataProviderTool.h:101
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Muon::NRPC_RawDataProviderTool::convert
virtual StatusCode convert() const override
the new ones
Definition: NRPC_RawDataProviderTool.cxx:48
NRPCRDOAuxContainer.h
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
TMVAToMVAUtils::convert
std::unique_ptr< MVAUtils::BDT > convert(TMVA::MethodBDT *bdt, bool isRegression=true, bool useYesNoLeaf=false)
Definition: TMVAToMVAUtils.h:114
Muon::NRPC_RawDataProviderTool::convertIntoContainer
virtual StatusCode convertIntoContainer(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vecRobs, xAOD::NRPCRDOContainer &nrpcContainer) const
Convert method.
Definition: NRPC_RawDataProviderTool.cxx:32
xAOD::NRPCRDO
NRPCRDO_v1 NRPCRDO
Define the version of the NRPC RDO class.
Definition: NRPCRDO.h:13
get_generator_info.version
version
Definition: get_generator_info.py:33
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
WARNING_WITH_LINE
#define WARNING_WITH_LINE(msg)
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Muon::NRPC_RawDataProviderTool::BS
OFFLINE_FRAGMENTS_NAMESPACE::PointerType BS
Definition: NRPC_RawDataProviderTool.h:97
xAOD::NRPCRDO_v1::setTime
void setTime(float Time)
Set the trigger time [ns].
Muon::NRPC_RawDataProviderTool::NRPC_RawDataProviderTool
NRPC_RawDataProviderTool(const std::string &, const std::string &, const IInterface *)
Definition: NRPC_RawDataProviderTool.cxx:12
xAOD::NRPCRDO_v1::setTimeoverthr
void setTimeoverthr(float Timeoverthr)
Set the time over threshold.