ATLAS Offline Software
MuCTPIPhase1ByteStreamAlgo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 
12 //also inspired by Rafal's word decoding code from:
13 //https://gitlab.cern.ch/atlas/athena/blob/release/22.0.91/Trigger/TrigT1/TrigT1ResultByteStream/src/MuonRoIByteStreamTool.cxx
14 
19 MuCTPIPhase1ByteStreamAlgo::MuCTPIPhase1ByteStreamAlgo( const std::string& name, ISvcLocator* svcLoc )
20  : AthReentrantAlgorithm( name, svcLoc) {}
21 
23 {
24  ATH_MSG_DEBUG("Initialising " << name());
25 
26  ATH_CHECK( m_MuCTPI_Phase1_RDOKey.initialize(/*m_processMuctpi=*/true) );
27 
28  //needed to enable the decoding of eta and phi
29  ATH_MSG_INFO("--- ENABLING THE DECODING");
30  const std::string barrelFileName = PathResolverFindCalibFile( m_barrelRoIFile );
31  ATH_MSG_INFO("--- - CHECK BARREL FILE NAME" << barrelFileName);
32  const std::string ecfFileName = PathResolverFindCalibFile( m_ecfRoIFile );
33  ATH_MSG_INFO("--- - CHECK ECF FILE NAME" << ecfFileName);
34  const std::string side0LUTFileName = PathResolverFindCalibFile( m_side0LUTFile );
35  ATH_MSG_INFO("--- - CHECK SIDE0 LUT FILE NAME" << side0LUTFileName);
36  const std::string side1LUTFileName = PathResolverFindCalibFile( m_side1LUTFile );
37  ATH_MSG_INFO("--- - INFO SIDE1 LUT FILE NAME" << side1LUTFileName);
38 
39  CHECK( m_l1topoLUT.initializeLUT(barrelFileName,
40  ecfFileName,
41  side0LUTFileName,
42  side1LUTFileName) );
43 
44  //return here while looking for fix for this
45  return StatusCode::SUCCESS;
46 
47  //this didn't work yet locally (offline). Waiting for feedback and should cleanup or reinclude soon.
48  //not critical; can run without it.
105 }
106 
107 StatusCode MuCTPIPhase1ByteStreamAlgo::execute(const EventContext& eventContext) const {
108  ATH_MSG_DEBUG("Executing " << name());
109 
110  // Retrieve the BS data for all tools in one request to parallelise DCM->ROS network requests
112  std::vector<uint32_t> robID = { m_robId };// Source ID of MIROD
113  //get rob fragment(s)
114  m_robDataProviderSvc->getROBData(eventContext, robID, vrobf, name());
115  //should only receive exactly 1 fragment; make sure:
116  if(vrobf.size()!=1)
117  {
118  ATH_MSG_ERROR("Wrong number of MUCTPI fragment in event: vrobf.size()="<<vrobf.size());
119  return StatusCode::FAILURE;
120  }
121 
122  //make the conversion, i.e. make the RDO, record it
124  ATH_CHECK(convert(vrobf[0],outputHandle));
125  return StatusCode::SUCCESS;
126 }
127 
133 
134  ATH_MSG_DEBUG("executing convert() from ROBFragment to RDO");
135  // check ROD source ID
136  const uint32_t rodId = rob->rod_source_id();
137  // check BC ID
138  const uint32_t bcId = rob->rod_bc_id();
139 
140  ATH_MSG_DEBUG(" expected ROD sub-detector ID: " << std::hex << m_robId << " ID found: " << std::hex << rodId << std::dec);
141 
142  if( rodId != m_robId ) {
143  ATH_MSG_ERROR("Wrong ROD ID found in the MuCTPI ROB fragment!");
144  return StatusCode::FAILURE;
145  }
146 
147  ATH_MSG_VERBOSE(" ROD Header BCID " << bcId << ", dumping MuCTPI words:");
148 
149  const uint32_t* it_data;
150  rob->rod_data( it_data );
151  const uint32_t ndata = rob->rod_ndata();
152  ATH_MSG_DEBUG("MUCTPI DQ DEBUG: number of ROB data words: " << std::dec << ndata);
153 
154  //slices
155  std::vector< LVL1::MuCTPIBits::Slice > slices;
157  bool firstSlice=true;
158  std::vector<size_t> errorBits;
159  uint64_t sliceMultiplicity=0;//grouping the 3 multiplicity words, to be processed at the end of the slice
160 
161  for( uint32_t iWord = 0; iWord < ndata; ++iWord, ++it_data ) {
162 
163  //for each word, get it, find type, and add in Slice struct.
164  uint32_t word = static_cast< uint32_t >( *it_data );
165  ATH_MSG_DEBUG("MUCTPI raw word " << iWord << ": 0x" << std::hex << word << std::dec);
167 
168  switch (wordType) {
170 
171  ATH_MSG_DEBUG(" MUCTPI DQ DEBUG: Timeslice found: "<< std::hex << word);
172 
173  //add previous slice if any
174  if(!firstSlice)
175  {
176  ATH_MSG_DEBUG(" MUCTPI DQ DEBUG: new timeslice found (pushing)");
177  slices.push_back(slice);
178  }
179  else
180  firstSlice=false;
181 
182  //make new slice (to be improved, since "new" will give pointer)
184  slice = s;
185 
186  const auto header = LVL1::MuCTPIBits::timesliceHeader(word);
187  ATH_MSG_DEBUG("This is a timeslice header word with BCID=" << header.bcid
188  << ", NTOB=" << header.tobCount << ", NCAND=" << header.candCount);
189  slice.bcid = header.bcid;
190  slice.nCand = header.candCount;
191  slice.nTOB = header.tobCount;
192  break;
193  }
196  ATH_MSG_DEBUG("This is a multiplicity word #" << tmNum);
197 
198  if(m_muctpi_Nbits.size()==32)
199  {
200  //fill mult word into temp container until 3rd word is found
201  if(tmNum==1)
202  sliceMultiplicity |= ( (uint64_t)LVL1::MuCTPIBits::maskedWord(word,LVL1::MuCTPIBits::RUN3_MULTIPLICITY_PART1_SHIFT, LVL1::MuCTPIBits::RUN3_MULTIPLICITY_PART1_MASK) ) << LVL1::MuCTPIBits::RUN3_MULTIPLICITY_ENC_PART1_SHIFT;
203  else if(tmNum==2)
204  sliceMultiplicity |= ( (uint64_t)LVL1::MuCTPIBits::maskedWord(word,LVL1::MuCTPIBits::RUN3_MULTIPLICITY_PART2_SHIFT, LVL1::MuCTPIBits::RUN3_MULTIPLICITY_PART2_MASK) ) << LVL1::MuCTPIBits::RUN3_MULTIPLICITY_ENC_PART2_SHIFT;
205  else if(tmNum==3)
206  sliceMultiplicity |= ( (uint64_t)LVL1::MuCTPIBits::maskedWord(word,LVL1::MuCTPIBits::RUN3_MULTIPLICITY_PART3_SHIFT, LVL1::MuCTPIBits::RUN3_MULTIPLICITY_PART3_MASK) ) << LVL1::MuCTPIBits::RUN3_MULTIPLICITY_ENC_PART3_SHIFT;
207 
208  //flags from third word
209  //AND: process multiplicity for the slice!!!
210  if(tmNum==3)
211  {
212  slice.mlt.nswMon = LVL1::MuCTPIBits::maskedWord(word,LVL1::MuCTPIBits::RUN3_NSW_MONITORING_TRIGGER_SHIFT, LVL1::MuCTPIBits::RUN3_NSW_MONITORING_TRIGGER_MASK);
213  slice.mlt.candOverflow = LVL1::MuCTPIBits::maskedWord(word,LVL1::MuCTPIBits::RUN3_MULTIPLICITY_OVERFLOW_SHIFT, LVL1::MuCTPIBits::RUN3_MULTIPLICITY_OVERFLOW_MASK);
214  slice.mlt.bits = sliceMultiplicity;
215 
216  //process the long mult word into 32 mlt thr counters
217  for(uint iThr=0;iThr<m_muctpi_Nbits.size();iThr++)
218  {
219  uint thismask=0;
220  if(m_muctpi_Nbits[iThr]==1)
221  thismask=0x1;
222  else if(m_muctpi_Nbits[iThr]==2)
223  thismask=0x3;
224  else if(m_muctpi_Nbits[iThr]==3)
225  thismask=0x7;
226 
227  //keep only the part of the 64bit word corresponding to the nbits value
228  slice.mlt.cnt.push_back( sliceMultiplicity & thismask);
229  //"throw away" the part of the 64bit word that we just used
230  sliceMultiplicity >>= m_muctpi_Nbits[iThr];
231  }
232 
233  sliceMultiplicity=0;//cleaning just in case..
234  }
235 
236  }
237  else
238  {
239  //if nbits size !=32, then it's not set
240  //for now, ignore, and can fill the histos with the Mult bits, as they come
241  //without decoding
242  //=>suppress this warning
243  //ATH_MSG_WARNING("MUCTPI DQ DEBUG: skipping Mult processing, no nbits defined");
244 
245  //todo: add code + histos for Mult bits
246  }
247 
248  break;
249  }
251  ATH_MSG_DEBUG("This is a RoI candidate word");
252 
253  LVL1::MuCTPIBits::Candidate thiscand(word);
254 
255  // We calculate eta/phi coordinates for each candidate with the
256  // full resolution available.
258  {
259  thiscand.eta = m_l1topoLUT.getCoordinates(thiscand.side, thiscand.subsystem, thiscand.num, thiscand.roi).eta;
260  thiscand.phi = m_l1topoLUT.getCoordinates(thiscand.side, thiscand.subsystem, thiscand.num, thiscand.roi).phi;
261  thiscand.mappedPt = LVL1::MuCTPIBits::RPCtoTGC_pt_map[thiscand.pt - 1];
262  }
263  else if(thiscand.type == LVL1::MuCTPIBits::SubsysID::Endcap)
264  {
265  thiscand.eta = m_l1topoLUT.getCoordinates(thiscand.side, thiscand.subsystem, thiscand.num, thiscand.roi).eta;
266  thiscand.phi = m_l1topoLUT.getCoordinates(thiscand.side, thiscand.subsystem, thiscand.num, thiscand.roi).phi;
267  }
268  else if(thiscand.type == LVL1::MuCTPIBits::SubsysID::Forward)
269  {
270  thiscand.eta = m_l1topoLUT.getCoordinates(thiscand.side, thiscand.subsystem, thiscand.num, thiscand.roi).eta;
271  thiscand.phi = m_l1topoLUT.getCoordinates(thiscand.side, thiscand.subsystem, thiscand.num, thiscand.roi).phi;
272  }
273  slice.cand.push_back(thiscand);
274  break;
275  }
277  ATH_MSG_DEBUG("This is a Topo TOB word "<< std::hex << word);
278  LVL1::MuCTPIBits::TopoTOB thistob(word);
279 
280  if(thistob.det == 0) // BA
281  {
282  thistob.roi = m_l1topoLUT.getBarrelROI(thistob.side, thistob.sec, thistob.barrel_eta_lookup, thistob.barrel_phi_lookup);
283  thistob.etaDecoded = m_l1topoLUT.getCoordinates(thistob.side, thistob.subsystem, thistob.sec, thistob.roi).eta;
284  thistob.phiDecoded = m_l1topoLUT.getCoordinates(thistob.side, thistob.subsystem, thistob.sec, thistob.roi).phi;
285  }
286  else // FW or EC
287  {
288  // FW and EC have the ROI initialized in the constructor of the Topo word, because it is encoded in eta_raw and phi_raw
289  thistob.etaDecoded = m_l1topoLUT.getCoordinates(thistob.side, thistob.subsystem, thistob.sec, thistob.roi).eta;
290  thistob.phiDecoded = m_l1topoLUT.getCoordinates(thistob.side, thistob.subsystem, thistob.sec, thistob.roi).phi;
291  }
292  slice.tob.push_back(thistob);
293  break;
294  }
296  ATH_MSG_DEBUG("This is a status word"<< std::hex << word);
298  if (!errorBits.empty()) {
299  ATH_MSG_DEBUG("MUCTPI ROD data flagged with errors. The data status word is 0x" << std::hex << word << std::dec);
300  for (size_t bit : errorBits) {
301  ATH_MSG_DEBUG("Error bit " << bit << ": " << LVL1::MuCTPIBits::DataStatusWordErrors.at(bit));
302  }
303  }
304  break;
305  }
306  default: {
307  ATH_MSG_ERROR("The MUCTPI word 0x" << std::hex << word << std::dec << " does not match any known word type");
308  return StatusCode::FAILURE;
309  }//default
310  }//switch
311  }//for each word
312 
313  //add last timeslice in vector, since there is no end-slice flag
314  ATH_MSG_DEBUG(" MUCTPI DQ DEBUG: out of words (pushing last slice)");
315  slices.push_back( slice );
316 
317  // create MuCTPI RDO
318  ATH_CHECK(outputHandle.record(
319  std::make_unique<MuCTPI_Phase1_RDO>(std::move(slices), std::move(errorBits))
320  ));
321  return StatusCode::SUCCESS;
322 }
LVL1::MuCTPIBits::WordType
WordType
Definition: HelpersPhase1.h:16
MuCTPIPhase1ByteStreamAlgo::m_l1topoLUT
LVL1MUCTPIPHASE1::L1TopoLUT m_l1topoLUT
Helper members.
Definition: MuCTPIPhase1ByteStreamAlgo.h:70
LVL1::MuCTPIBits::TopoTOB::etaDecoded
float etaDecoded
Definition: HelpersPhase1.h:318
LVL1::MuCTPIBits::TopoTOB::barrel_phi_lookup
uint32_t barrel_phi_lookup
Definition: HelpersPhase1.h:314
LVL1::MuCTPIBits::WordType::Candidate
@ Candidate
MuCTPI_Phase1_RDO.h
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
LVL1MUCTPIPHASE1::L1TopoLUT::getBarrelROI
unsigned short getBarrelROI(unsigned short side, unsigned short sector, unsigned short ieta, unsigned short iphi) const
Definition: L1TopoLUT.cxx:232
LVL1::MuCTPIBits::getDataStatusWordErrors
std::vector< size_t > getDataStatusWordErrors(uint32_t word)
Decode the data status word (returns a vector of bit indices for the errors set - empty if no errors)
Definition: HelpersPhase1.h:186
LVL1::MuCTPIBits::getWordType
constexpr WordType getWordType(uint32_t word)
Determine the type of a MUCTPI ROD word.
Definition: HelpersPhase1.h:64
header
Definition: hcg.cxx:526
LVL1::MuCTPIBits::TopoTOB::barrel_eta_lookup
uint32_t barrel_eta_lookup
Definition: HelpersPhase1.h:313
MuCTPIPhase1ByteStreamAlgo::MuCTPIPhase1ByteStreamAlgo
MuCTPIPhase1ByteStreamAlgo(const std::string &name, ISvcLocator *svcLoc)
Default constructor.
Definition: MuCTPIPhase1ByteStreamAlgo.cxx:19
LVL1::MuCTPIBits::maskedWord
constexpr uint32_t maskedWord(uint32_t word, uint32_t shift, uint32_t mask)
Extract sub-word from 32-bit word by applying a shift and a mask.
Definition: HelpersPhase1.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LVL1::MuCTPIBits::Candidate::roi
uint32_t roi
Definition: HelpersPhase1.h:222
MuCTPIPhase1ByteStreamAlgo.h
LVL1::MuCTPIBits::Candidate::type
SubsysID type
Definition: HelpersPhase1.h:217
LVL1::MuCTPIBits::Candidate::eta
float eta
Definition: HelpersPhase1.h:224
LVL1::MuCTPIBits::TopoTOB::side
bool side
Definition: HelpersPhase1.h:308
MuCTPIPhase1ByteStreamAlgo::m_robId
Gaudi::Property< uint32_t > m_robId
Object storing the various IDs of the MuCTPI fragment.
Definition: MuCTPIPhase1ByteStreamAlgo.h:50
LVL1::MuCTPIBits::TopoTOB::subsystem
uint32_t subsystem
Definition: HelpersPhase1.h:317
LVL1::MuCTPIBits::Candidate::subsystem
uint32_t subsystem
Definition: HelpersPhase1.h:223
MuCTPIPhase1ByteStreamAlgo::m_ecfRoIFile
const std::string m_ecfRoIFile
Definition: MuCTPIPhase1ByteStreamAlgo.h:65
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
LVL1::MuCTPIBits::Candidate::phi
float phi
Definition: HelpersPhase1.h:225
LVL1::MuCTPIBits::Candidate::side
bool side
Definition: HelpersPhase1.h:216
LVL1::MuCTPIBits::WordType::Topo
@ Topo
MuCTPIPhase1ByteStreamAlgo::m_side1LUTFile
const std::string m_side1LUTFile
Definition: MuCTPIPhase1ByteStreamAlgo.h:67
LVL1::MuCTPIBits::SubsysID::Endcap
@ Endcap
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LVL1::MuCTPIBits::multiplicityWordNumber
constexpr uint32_t multiplicityWordNumber(uint32_t word)
Decode the index of the multitpicity word, which is 1, 2, or 3.
Definition: HelpersPhase1.h:154
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuCTPIPhase1ByteStreamAlgo::convert
StatusCode convert(const IROBDataProviderSvc::ROBF *rob, SG::WriteHandle< MuCTPI_Phase1_RDO > &outputHandle) const
Convert ROBFragment to MuCTPI_RDO.
Definition: MuCTPIPhase1ByteStreamAlgo.cxx:132
perfmonmt-refit.slice
slice
Definition: perfmonmt-refit.py:52
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
LVL1MUCTPIPHASE1::L1TopoLUT::getCoordinates
L1TopoCoordinates getCoordinates(const unsigned short &side, const unsigned short &subsystem, const unsigned short &sectorID, const unsigned short &roi) const
Definition: L1TopoLUT.cxx:218
LVL1::MuCTPIBits::SubsysID::Forward
@ Forward
LVL1::MuCTPIBits::Candidate::pt
uint32_t pt
Definition: HelpersPhase1.h:219
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
LVL1::MuCTPIBits::TopoTOB::phiDecoded
float phiDecoded
Definition: HelpersPhase1.h:319
MuCTPIPhase1ByteStreamAlgo::m_side0LUTFile
const std::string m_side0LUTFile
Definition: MuCTPIPhase1ByteStreamAlgo.h:66
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
LVL1::MuCTPIBits::Candidate
Definition: HelpersPhase1.h:215
IROBDataProviderSvc::VROBFRAG
std::vector< const ROBF * > VROBFRAG
Definition: IROBDataProviderSvc.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
LVL1::MuCTPIBits::timesliceHeader
constexpr auto timesliceHeader(uint32_t word)
Decode timeslice word.
Definition: HelpersPhase1.h:81
LVL1::MuCTPIBits::TopoTOB::det
uint32_t det
Definition: HelpersPhase1.h:315
bcId
uint16_t bcId(uint32_t data)
Definition: TgcByteStreamData.h:329
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MuCTPI_Bits.h
LVL1::MuCTPIBits::TopoTOB
Definition: HelpersPhase1.h:307
MuCTPIPhase1ByteStreamAlgo::execute
virtual StatusCode execute(const EventContext &eventContext) const override
Definition: MuCTPIPhase1ByteStreamAlgo.cxx:107
LVL1::MuCTPIBits::WordType::Multiplicity
@ Multiplicity
LVL1::MuCTPIBits::Candidate::mappedPt
uint32_t mappedPt
Definition: HelpersPhase1.h:221
LVL1MUCTPIPHASE1::L1TopoCoordinates::eta
double eta
Definition: L1TopoLUT.h:30
MuCTPIPhase1ByteStreamAlgo::m_barrelRoIFile
const std::string m_barrelRoIFile
Definition: MuCTPIPhase1ByteStreamAlgo.h:64
LVL1::MuCTPIBits::WordType::Status
@ Status
MuCTPIPhase1ByteStreamAlgo::initialize
virtual StatusCode initialize() override
Definition: MuCTPIPhase1ByteStreamAlgo.cxx:22
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
MuCTPIPhase1ByteStreamAlgo::m_robDataProviderSvc
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
ROBDataProvider service handle.
Definition: MuCTPIPhase1ByteStreamAlgo.h:53
LVL1::MuCTPIBits::Slice
Definition: HelpersPhase1.h:384
LVL1MUCTPIPHASE1::L1TopoCoordinates::phi
double phi
Definition: L1TopoLUT.h:31
LVL1MUCTPIPHASE1::L1TopoLUT::initializeLUT
bool initializeLUT(const std::string &barrelFileName, const std::string &ecfFileName, const std::string &side0LUTFileName, const std::string &side1LUTFileName)
Definition: L1TopoLUT.cxx:101
LVL1::MuCTPIBits::RPCtoTGC_pt_map
const uint32_t RPCtoTGC_pt_map[6]
Definition: HelpersPhase1.h:20
LVL1::MuCTPIBits::Candidate::num
uint32_t num
Definition: HelpersPhase1.h:218
MuCTPIPhase1ByteStreamAlgo::m_muctpi_Nbits
std::vector< uint32_t > m_muctpi_Nbits
Definition: MuCTPIPhase1ByteStreamAlgo.h:57
MuCTPIPhase1ByteStreamAlgo::m_MuCTPI_Phase1_RDOKey
SG::WriteHandleKey< MuCTPI_Phase1_RDO > m_MuCTPI_Phase1_RDOKey
Definition: MuCTPIPhase1ByteStreamAlgo.h:55
LVL1::MuCTPIBits::WordType::Timeslice
@ Timeslice
HelpersPhase1.h
LVL1::MuCTPIBits::SubsysID::Barrel
@ Barrel
LVL1::MuCTPIBits::TopoTOB::sec
uint32_t sec
Definition: HelpersPhase1.h:316
keylayer_zslicemap.slices
slices
Definition: keylayer_zslicemap.py:112
LVL1::MuCTPIBits::TopoTOB::roi
uint32_t roi
Definition: HelpersPhase1.h:312