ATLAS Offline Software
RodHeaderByteStreamTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include <algorithm>
7 #include <set>
8 
9 #include "GaudiKernel/IInterface.h"
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/StatusCode.h"
12 
14 
16 #include "L1CaloSrcIdMap.h"
17 #include "L1CaloSubBlock.h"
18 
20 
21 
22 namespace {
23 bool hasEnding(std::string const &fullString, std::string const &ending) {
24  if (fullString.length() >= ending.length()) {
25  return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
26  } else {
27  return false;
28  }
29 }
30 }
31 
32 
33 namespace LVL1BS {
34 
35 // Interface ID
36 
37 static const InterfaceID IID_IRodHeaderByteStreamTool("RodHeaderByteStreamTool", 1, 1);
38 
40 {
41  return IID_IRodHeaderByteStreamTool;
42 }
43 
44 // Constructor
45 
47  const std::string& name,
48  const IInterface* parent)
50  m_robDataProvider("ROBDataProviderSvc", name),
51  m_errorTool("LVL1BS::L1CaloErrorByteStreamTool/L1CaloErrorByteStreamTool")
52 {
53  declareInterface<RodHeaderByteStreamTool>(this);
54 
55  declareProperty("UseSWROD",m_useSWROD = false, "Use SWROD readout instead of legacy (which was removed in 2024)");
56 
57  declareProperty("ErrorTool", m_errorTool,
58  "Tool to collect errors for monitoring");
59  declareProperty("ROBSourceIDs", m_sourceIDsProp,
60  "ROB fragment source identifiers - All except RoIB");
61  declareProperty("ROBSourceIDsPP", m_sourceIDsPPProp,
62  "ROB fragment source identifiers - PP only");
63  declareProperty("ROBSourceIDsCP", m_sourceIDsCPProp,
64  "ROB fragment source identifiers - CP DAQ only");
65  declareProperty("ROBSourceIDsJEP", m_sourceIDsJEPProp,
66  "ROB fragment source identifiers - JEP DAQ only");
67  declareProperty("ROBSourceIDsCPRoI", m_sourceIDsCPRoIProp,
68  "ROB fragment source identifiers - CP RoI only");
69  declareProperty("ROBSourceIDsJEPRoI", m_sourceIDsJEPRoIProp,
70  "ROB fragment source identifiers - JEP RoI only");
71  declareProperty("ROBSourceIDsCPRoIB", m_sourceIDsCPRoIBProp,
72  "ROB fragment source identifiers - CP RoIB only");
73  declareProperty("ROBSourceIDsJEPRoIB", m_sourceIDsJEPRoIBProp,
74  "ROB fragment source identifiers - JEP RoIB only");
75 }
76 
77 // Destructor
78 
80 {
81 }
82 
83 // Initialize
84 
85 
87 {
88  ATH_MSG_INFO( "Initializing " << name() );
89 
91 
92  ATH_CHECK( m_errorTool.retrieve() );
93 
94  return StatusCode::SUCCESS;
95 }
96 
97 // Finalize
98 
100 {
101  return StatusCode::SUCCESS;
102 }
103 
104 // Conversion bytestream to RODHeaders
105 
106 // Conversion bytestream to CMX-CP TOBs
108  const std::string& sgKey,
109  DataVector<LVL1::RODHeader>* const rhCollection) const
110 {
111  const std::vector<uint32_t>& vID(sourceIDs(sgKey));
112  // // get ROB fragments
114  m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags, "RodHeaderByteStreamTool");
115  ATH_MSG_DEBUG("Number of ROB fragments:" << robFrags.size());
116  return convert(robFrags, rhCollection);
117 }
118 
120  const IROBDataProviderSvc::VROBFRAG& robFrags,
121  DataVector<LVL1::RODHeader>* const rhCollection) const
122 {
123  const bool debug = msgLvl(MSG::DEBUG);
124  if (debug) msg(MSG::DEBUG);
125 
126  // Loop over ROB fragments
127 
128  int robCount = 0;
129  std::set<uint32_t> dupCheck;
130  ROBIterator rob = robFrags.begin();
131  ROBIterator robEnd = robFrags.end();
132  for (; rob != robEnd; ++rob) {
133 
134  if (debug) {
135  ++robCount;
136  msg() << "Treating ROB fragment " << robCount << endmsg;
137  }
138 
139  // Skip fragments with ROB status errors
140 
141  uint32_t robid = (*rob)->source_id();
142  if ((*rob)->nstatus() > 0) {
143  ROBPointer robData;
144  (*rob)->status(robData);
145  if (*robData != 0) {
146  m_errorTool->robError(robid, *robData);
147  if (debug) msg() << "ROB status error - skipping fragment" << endmsg;
148  continue;
149  }
150  }
151 
152  // Skip duplicate fragments
153 
154  if (!dupCheck.insert(robid).second) {
156  if (debug) msg() << "Skipping duplicate ROB fragment" << endmsg;
157  continue;
158  }
159 
160  // Unpack ROD header info
161 
162  const uint32_t version = (*rob)->rod_version();
163  const uint32_t sourceId = (*rob)->rod_source_id();
164  const uint32_t run = (*rob)->rod_run_no();
165  const uint32_t lvl1Id = (*rob)->rod_lvl1_id();
166  const uint32_t bcId = (*rob)->rod_bc_id();
167  const uint32_t trigType = (*rob)->rod_lvl1_trigger_type();
168  const uint32_t detType = (*rob)->rod_detev_type();
169  const uint32_t nData = (*rob)->rod_ndata();
170 
171  // Unpack status words
172 
173  std::vector<uint32_t> statusWords;
174  unsigned int nstatus = (*rob)->rod_nstatus();
175  if (nstatus <= 2) {
177  RODPointer statusEnd;
178  (*rob)->rod_status(status);
179  statusEnd = status + nstatus;
180  for (; status != statusEnd; ++status) statusWords.push_back(*status);
181  } else { // Likely corruption
183  continue;
184  }
185 
186  // Save
187 
188  rhCollection->push_back(new LVL1::RODHeader(version, sourceId, run, lvl1Id,
189  bcId, trigType, detType, statusWords, nData));
190  if (debug) {
191  msg() << MSG::hex
192  << "ROD Header version/sourceId/run/lvl1Id/bcId/trigType/detType/nData: "
193  << version << "/" << sourceId << "/" << run << "/" << lvl1Id << "/"
194  << bcId << "/" << trigType << "/" << detType << "/" << nData
195  << endmsg << "ROD Status Words:";
196  std::vector<uint32_t>::const_iterator pos = statusWords.begin();
197  std::vector<uint32_t>::const_iterator pose = statusWords.end();
198  for (; pos != pose; ++pos) msg() << " " << *pos;
199  msg() << MSG::dec << endmsg;
200  }
201  }
202 
203  return StatusCode::SUCCESS;
204 }
205 
206 // Return reference to vector with all possible Source Identifiers
207 
208 const std::vector<uint32_t>& RodHeaderByteStreamTool::sourceIDs(
209  const std::string& sgKey) const
210 {
211  if (isAppended(sgKey, "PP")) {
212  static const std::vector<int> slinksPP { 0, 1, 2, 3 };
213  static const std::vector<uint32_t> sourceIDsPP =
214  makeRobIds(8, 0, slinksPP, 0, eformat::TDAQ_CALO_PREPROC,
216  return sourceIDsPP;
217  }
218 
219  if (isAppended(sgKey, "CP")) {
220  static const std::vector<int> slinksCP { 0, 2 };
221  static const std::vector<uint32_t> sourceIDsCP =
222  makeRobIds(4, 8, slinksCP, 0, eformat::TDAQ_CALO_CLUSTER_PROC_DAQ,
224  return sourceIDsCP;
225  }
226 
227  if (isAppended(sgKey, "CPRoI")) {
228  static const std::vector<int> slinksCPRoI { 0 };
229  static const std::vector<uint32_t> sourceIDsCPRoI =
230  makeRobIds(4, 8, slinksCPRoI, 1, eformat::TDAQ_CALO_CLUSTER_PROC_ROI,
232  return sourceIDsCPRoI;
233  }
234 
235  if (isAppended(sgKey, "JEP")) {
236  static const std::vector<int> slinksJEP { 0, 1, 2, 3 };
237  static const std::vector<uint32_t> sourceIDsJEP =
238  makeRobIds(2, 12, slinksJEP, 0, eformat::TDAQ_CALO_JET_PROC_DAQ,
240  return sourceIDsJEP;
241  }
242 
243  if (isAppended(sgKey, "JEPRoI")) {
244  static const std::vector<int> slinksJEPRoI { 0 };
245  static const std::vector<uint32_t> sourceIDsJEPRoI =
246  makeRobIds(2, 12, slinksJEPRoI, 1, eformat::TDAQ_CALO_JET_PROC_ROI,
248  return sourceIDsJEPRoI;
249  }
250 
251  if (isAppended(sgKey, "CPRoIB")) {
252  static const std::vector<int> slinksCPRoIB { 2 };
253  static const std::vector<uint32_t> sourceIDsCPRoIB =
254  makeRobIds(4, 8, slinksCPRoIB, 1, eformat::TDAQ_CALO_CLUSTER_PROC_ROI,
256  return sourceIDsCPRoIB;
257  }
258 
259  if (isAppended(sgKey, "JEPRoIB")) {
260  static const std::vector<int> slinksJEPRoIB { 2 };
261  static const std::vector<uint32_t> sourceIDsJEPRoIB =
262  makeRobIds(2, 12, slinksJEPRoIB, 1, eformat::TDAQ_CALO_JET_PROC_ROI,
264  return sourceIDsJEPRoIB;
265  }
266 
267  // all
268  static const std::vector<uint32_t> sourceIDs = makeAllRobIds();
269  return sourceIDs;
270 }
271 
272 // Fill vector with ROB IDs for given sub-detector
273 
274 std::vector<uint32_t> RodHeaderByteStreamTool::makeAllRobIds() const
275 {
276  std::vector<uint32_t> robIds;
277 
278  auto append = [&robIds] (const std::vector<uint32_t>& v)
279  { robIds.insert (robIds.end(), v.begin(), v.end()); };
280 
281  append (sourceIDs ("PP"));
282  append (sourceIDs ("CP"));
283  append (sourceIDs ("CPRoI"));
284  append (sourceIDs ("JEP"));
285  append (sourceIDs ("JEPRoI"));
286 
287  // Don't include RoIBs (LVL2) in complete set
288  return robIds;
289 }
290 
291 
292 std::vector<uint32_t> RodHeaderByteStreamTool::makeRobIds(const int numCrates,
293  const int crateOffset,
294  const std::vector<int>& slinks,
295  const int daqOrRoi,
296  const eformat::SubDetector subdet,
297  const std::vector<uint32_t>& prop) const
298 {
299  std::vector<uint32_t> robs;
300 
301  if (!prop.empty()) {
302  robs = prop;
303  }
304  else {
305  for (int crate = 0; crate < numCrates; ++crate) {
306  const int numSlinks = slinks.size();
307  for (int i = 0; i < numSlinks; ++i) {
308  const uint32_t rodId = m_srcIdMap.getRodID(crate + crateOffset,
309  slinks[i], daqOrRoi, subdet);
310  const uint32_t robId = m_srcIdMap.getRobID(rodId);
311  robs.push_back (robId);
312  }
313  }
314  }
315  return robs;
316 }
317 
318 // Return true if StoreGate key ends in given string
319 
320 bool RodHeaderByteStreamTool::isAppended(const std::string& sgKey,
321  const std::string& flag) const
322 {
323 
324  return ::hasEnding(sgKey, flag) || ::hasEnding(sgKey, flag + "Aux.");
325 }
326 
327 } // end namespace
LVL1BS::RodHeaderByteStreamTool::finalize
virtual StatusCode finalize() override
Definition: RodHeaderByteStreamTool.cxx:99
LVL1BS::RodHeaderByteStreamTool::makeAllRobIds
std::vector< uint32_t > makeAllRobIds() const
Fill vector with ROB IDs for given sub-detector.
Definition: RodHeaderByteStreamTool.cxx:274
LVL1BS::RodHeaderByteStreamTool::m_sourceIDsProp
std::vector< uint32_t > m_sourceIDsProp
ROB source IDs.
Definition: RodHeaderByteStreamTool.h:89
LVL1BS::L1CaloSrcIdMap::useSWROD
static void useSWROD(bool in)
Flag to decide if SWROD readout should be used instead of legacy.
Definition: L1CaloSrcIdMap.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LVL1BS::RodHeaderByteStreamTool::RodHeaderByteStreamTool
RodHeaderByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: RodHeaderByteStreamTool.cxx:46
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LVL1BS::L1CaloSubBlock::ERROR_DUPLICATE_ROB
@ ERROR_DUPLICATE_ROB
Definition: L1CaloSubBlock.h:31
LVL1BS::RodHeaderByteStreamTool::m_useSWROD
bool m_useSWROD
Definition: RodHeaderByteStreamTool.h:100
LVL1BS::RodHeaderByteStreamTool::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service for reading bytestream.
Definition: RodHeaderByteStreamTool.h:84
LVL1BS::RodHeaderByteStreamTool::ROBIterator
IROBDataProviderSvc::VROBFRAG::const_iterator ROBIterator
Definition: RodHeaderByteStreamTool.h:68
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
LVL1BS::L1CaloSrcIdMap::getRobID
uint32_t getRobID(uint32_t rod_id) const
Make a ROB Source ID from a ROD source ID.
Definition: L1CaloSrcIdMap.cxx:32
LVL1::RODHeader
ROD Header data and status words.
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/RODHeader.h:17
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
LVL1BS::L1CaloSubBlock::ERROR_ROD_NSTATUS
@ ERROR_ROD_NSTATUS
Definition: L1CaloSubBlock.h:32
LVL1BS::RodHeaderByteStreamTool::m_sourceIDsJEPRoIBProp
std::vector< uint32_t > m_sourceIDsJEPRoIBProp
Definition: RodHeaderByteStreamTool.h:96
LVL1BS::RodHeaderByteStreamTool::m_srcIdMap
const L1CaloSrcIdMap m_srcIdMap
Source ID converter.
Definition: RodHeaderByteStreamTool.h:98
LVL1BS::RodHeaderByteStreamTool::m_errorTool
ToolHandle< LVL1BS::L1CaloErrorByteStreamTool > m_errorTool
Error collection tool.
Definition: RodHeaderByteStreamTool.h:86
RODHeader.h
LVL1BS::RodHeaderByteStreamTool::m_sourceIDsCPRoIBProp
std::vector< uint32_t > m_sourceIDsCPRoIBProp
Definition: RodHeaderByteStreamTool.h:95
LVL1BS::RodHeaderByteStreamTool::~RodHeaderByteStreamTool
virtual ~RodHeaderByteStreamTool()
Definition: RodHeaderByteStreamTool.cxx:79
lumiFormat.i
int i
Definition: lumiFormat.py:85
L1CaloSubBlock.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
python.HLT.CommonSequences.EventBuildingSequences.robs
robs
Definition: EventBuildingSequences.py:401
master.flag
bool flag
Definition: master.py:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LVL1BS::RodHeaderByteStreamTool::m_sourceIDsCPProp
std::vector< uint32_t > m_sourceIDsCPProp
Definition: RodHeaderByteStreamTool.h:91
run
Definition: run.py:1
IROBDataProviderSvc::VROBFRAG
std::vector< const ROBF * > VROBFRAG
Definition: IROBDataProviderSvc.h:27
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
LVL1BS::RodHeaderByteStreamTool::makeRobIds
std::vector< uint32_t > makeRobIds(int numCrates, int crateOffset, const std::vector< int > &slinks, int daqOrRoi, eformat::SubDetector subdet, const std::vector< uint32_t > &prop) const
Definition: RodHeaderByteStreamTool.cxx:292
LVL1BS::RodHeaderByteStreamTool::isAppended
bool isAppended(const std::string &sgKey, const std::string &flag) const
Return true if StoreGate key ends in given string.
Definition: RodHeaderByteStreamTool.cxx:320
bcId
uint16_t bcId(uint32_t data)
Definition: TgcByteStreamData.h:326
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
L1CaloErrorByteStreamTool.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
LVL1BS::RodHeaderByteStreamTool::m_sourceIDsJEPProp
std::vector< uint32_t > m_sourceIDsJEPProp
Definition: RodHeaderByteStreamTool.h:92
python.PyAthena.v
v
Definition: PyAthena.py:154
LVL1BS::RodHeaderByteStreamTool::m_sourceIDsJEPRoIProp
std::vector< uint32_t > m_sourceIDsJEPRoIProp
Definition: RodHeaderByteStreamTool.h:94
get_generator_info.version
version
Definition: get_generator_info.py:33
LVL1BS::RodHeaderByteStreamTool::convert
StatusCode convert(const std::string &name, DataVector< LVL1::RODHeader > *rhCollection) const
Convert ROB fragments to RODHeaders.
Definition: RodHeaderByteStreamTool.cxx:107
LVL1BS::RodHeaderByteStreamTool::RODPointer
OFFLINE_FRAGMENTS_NAMESPACE::PointerType RODPointer
Definition: RodHeaderByteStreamTool.h:70
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LVL1BS
Definition: ZdcModifySlices.h:10
LVL1BS::RodHeaderByteStreamTool::m_sourceIDsCPRoIProp
std::vector< uint32_t > m_sourceIDsCPRoIProp
Definition: RodHeaderByteStreamTool.h:93
LVL1BS::RodHeaderByteStreamTool::ROBPointer
OFFLINE_FRAGMENTS_NAMESPACE::PointerType ROBPointer
Definition: RodHeaderByteStreamTool.h:69
LVL1BS::L1CaloSrcIdMap::getRodID
uint32_t getRodID(int crate, int slink, int daqOrRoi, eformat::SubDetector subdet) const
Make a ROD Source ID.
Definition: L1CaloSrcIdMap.cxx:18
L1CaloSrcIdMap.h
merge.status
status
Definition: merge.py:17
AthAlgTool
Definition: AthAlgTool.h:26
LVL1BS::RodHeaderByteStreamTool::initialize
virtual StatusCode initialize() override
Definition: RodHeaderByteStreamTool.cxx:86
LVL1BS::RodHeaderByteStreamTool::interfaceID
static const InterfaceID & interfaceID()
AlgTool InterfaceID.
Definition: RodHeaderByteStreamTool.cxx:39
LVL1BS::RodHeaderByteStreamTool::sourceIDs
const std::vector< uint32_t > & sourceIDs(const std::string &sgKey) const
Return reference to vector with all possible Source Identifiers.
Definition: RodHeaderByteStreamTool.cxx:208
RodHeaderByteStreamTool.h
LVL1BS::RodHeaderByteStreamTool::m_sourceIDsPPProp
std::vector< uint32_t > m_sourceIDsPPProp
Definition: RodHeaderByteStreamTool.h:90