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 
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 
45 StatusCode 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 
62 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<IdentifierHash>& HashVec) const {
63  return convert(HashVec, Gaudi::Hive::currentContext());
64 }
65 
66 StatusCode 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 
75 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<uint32_t>& robIds) const {
76  return convert(robIds, Gaudi::Hive::currentContext());
77 }
78 
79 StatusCode 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 
85 StatusCode 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 
90 StatusCode 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 
95 StatusCode NRPC_RawDataProviderTool::convert(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs) const {
96  return convert(vecRobs, Gaudi::Hive::currentContext());
97 }
98 
99 StatusCode 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 tdc sector from sourceId
126  uint16_t subDetector = sourceId >> 16;
127  uint16_t tdcSector = (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 << " tdcSector: " << std::hex
132  << tdcSector << 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 tdc " << 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 tdc " << std::hex << data[idata+4] << std::dec << " is <6 :" << data[idata] );
150  break;
151  } else if ( (data[idata+data[idata]-2] & 0x000000ff) != 0xa0) {
152  WARNING_WITH_LINE("NRPC: Missing expected trailer a0" );
153  break;
154  } else {
155 
156  // Bit inversion and manipulation needed to decode nominal BCID
157  uint32_t bcid12 = (data[idata+2] & 0xff000000) >> 24;
158  uint32_t bcid34 = (data[idata+2] & 0x00ff0000) >> 8;
159  uint32_t bcid56 = (data[idata+2] & 0x0000ff00) << 8;
160  uint32_t bcid78 = (data[idata+2] & 0x000000ff) << 24;
161  uint32_t bcid_nom = (bcid12 | bcid34 | bcid56 | bcid78) >> 4;
162 
163  // Decode data
164  for (unsigned int i=0; i<data[idata]-6; i++) {
165  uint16_t tdc = (data[idata+4] & 0x000000ff) ;
166  uint16_t chan = (data[idata+4] & 0x0000ff00) >> 8 ;
167  float tot = ((data[idata+4] & 0x00ff0000) >> 16)*0.4 ;
168  float time = ((data[idata+4] & 0x0f000000) >> 24)*1.6 ;
169  uint32_t bcid_hit = (data[idata+4] & 0xf0000000) >> 28 ;
170 
171  // Compute the BCID of the hit combining the nominal BCID with the last 4 bits from the hit (bcid_hit)
172  uint32_t bcid_nom_4bits = (bcid_nom & 0x0000000f) ;
173  uint32_t bcid = 0 ;
174  if (bcid_hit >= bcid_nom_4bits) { // The BCID of the hit is subsequent to the nominal
175  bcid = ( (bcid_nom & 0xfffffff0) | bcid_hit );
176  } else {
177  bcid = ( (bcid_nom & 0xfffffff0) | bcid_hit ) + 0x00000010;
178  }
179 
180  // Build the RDO
181  xAOD::NRPCRDO* NrpcRdo = rdoIdc.push_back(std::make_unique<xAOD::NRPCRDO>());
182  NrpcRdo->setBcid(bcid);
183  NrpcRdo->setTime(time);
184  NrpcRdo->setSubdetector(subDetector);
185  NrpcRdo->setTdcsector(tdcSector);
186  NrpcRdo->setTdc(tdc);
187  NrpcRdo->setChannel(chan);
188  NrpcRdo->setTimeoverthr(tot);
189  }
190  }
191 
192  idata+=data[idata];
193  }
194 
195 
196  return StatusCode::SUCCESS;
197 
198 } // end fillCollections
199 
200 
201 
202 
203 } // 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_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
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
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:111
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:93
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
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:15
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:794
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:228
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Muon::NRPC_RawDataProviderTool::convert
virtual StatusCode convert() const override
the new ones
Definition: NRPC_RawDataProviderTool.cxx:45
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:29
Muon::NRPC_RawDataProviderTool::m_readKey
SG::ReadCondHandleKey< RpcCablingMap > m_readKey
Definition: NRPC_RawDataProviderTool.h:106
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.