ATLAS Offline Software
L1TopoByteStreamTool.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 #include <exception>
6 #include <bitset>
7 
8 // Gaudi/Athena include(s):
10 
11 // Trigger include(s):
12 #include "L1TopoRDO/L1TopoRDO.h"
14 #include "L1TopoRDO/ModuleID.h"
15 #include "L1TopoRDO/Helpers.h"
16 
17 // Local include(s):
18 #include "L1TopoByteStreamTool.h"
19 
21 static const InterfaceID IID_IL1TopoByteStreamTool("L1TopoByteStreamTool", 1,
22  0);
23 
28 const InterfaceID& L1TopoByteStreamTool::interfaceID() {
29  return IID_IL1TopoByteStreamTool;
30 }
31 
37  const std::string& name,
38  const IInterface* parent)
40  m_srcIdMap(0),
41  m_robDataProvider("ROBDataProviderSvc", "L1TopoByteStreamTool") {
42  declareInterface<L1TopoByteStreamTool>(this);
43  declareProperty("ROBSourceIDs", m_sourceIDs,
44  "ROB fragment source identifiers - overrides decodeDAQROBs "
45  "and decodeROIROBs");
47  "decodeDAQROBs", m_doDAQROBs = true,
48  "add standard DAQ ROBs to list of ROBs to decode; default true");
50  "decodeROIROBs", m_doROIROBs = false,
51  "add standard ROI ROBs to list of ROBs to decode; default false");
52 }
53 
58 
64  m_srcIdMap = new L1TopoSrcIdMap();
66  if (!m_sourceIDs.empty()) {
68  "ROBSourceIDs property is set: this overrides decodeDAQROBs and "
69  "decodeROIROBs");
70  } else {
72  }
75  ATH_MSG_DEBUG("using sourceIDs " << std::hex << std::showbase << m_sourceIDs
76  << std::dec << std::noshowbase);
77 
78  CHECK(m_robDataProvider.retrieve());
79  return AlgTool::initialize();
80 }
81 
86  delete m_srcIdMap;
87  return AlgTool::finalize();
88 }
89 
100 const std::vector<uint32_t>& L1TopoByteStreamTool::sourceIDs() {
101  if (m_sourceIDs.empty()) {
102  // iterate over link numbers: 0 is DAQ link, 1 is ROIB, 2 for New ROIB
103  for (unsigned int slink : {0, 1, 2}) {
104  unsigned int roiOrDaq = 0;
105  if (slink > 0) { // 0 means DAQ-type link, 1 means ROI-type link
106  roiOrDaq = 1;
107  }
108  if (roiOrDaq == 0 && !m_doDAQROBs) {
109  continue; // skip DAQ ROBs
110  } else if (roiOrDaq == 1 && !m_doROIROBs) {
111  continue; // skip ROI ROBs
112  }
113  for (unsigned int module :
114  {0, 1}) { // could be upgraded to 3 modules eventually?
115  const uint32_t moduleId =
116  L1Topo::ModuleID(slink, module, roiOrDaq).id();
117  eformat::helper::SourceIdentifier sourceId(eformat::TDAQ_CALO_TOPO_PROC, moduleId);
118 
119  m_sourceIDs.push_back(sourceId.code());
120  }
121  }
122  }
123  return m_sourceIDs;
124 }
125 
131  RawEventWrite* re) const{
132  ATH_MSG_DEBUG("executing convert() from RDO to ROBFragment");
133 
134  // Create Event Assembler
136 
137  // Reset lumi-block number to 1
138  fea.setDetEvtType(1);
139  // Set L1Apos to center of readout window
140  // uint16_t minorVersion = ( result->getNumberOfBunches() - 1u ) / 2u;
141  // minorVersion &= ctpVersion.getL1APositionMask();
142  // minorVersion <<= ctpVersion.getL1APositionShift();
143  uint16_t minorVersion = 0;
144  fea.setRodMinorVersion(minorVersion);
145 
147 
148  // Source ID of L1Topo
149  // NB needs to change to using list of modules - as it is, it will just
150  // produce one with an unconventional ID of 0x91000000.
151  const uint32_t rodId = m_srcIdMap->getRodID();
152  ATH_MSG_DEBUG(" ROD ID:" << MSG::hex << rodId);
153  ATH_MSG_DEBUG(" ROD IDs:" << MSG::hex << m_sourceIDs << " NOT YET IMPLEMENTED");
154 
155  // get the ROD data container to be filled
156  theROD = fea.getRodData(rodId);
157 
158  ATH_MSG_VERBOSE(" Dumping L1Topo data words:");
159  // fill Data Words
160  const std::vector<uint32_t>& vDataWords = result->getDataWords();
161  std::vector<uint32_t>::const_iterator it = vDataWords.begin();
162  std::vector<uint32_t>::const_iterator end = vDataWords.end();
163  for (; it != end; ++it) {
164  theROD->push_back(*it);
165  ATH_MSG_VERBOSE(" 0x" << MSG::hex << std::setw(8) << (*it));
166  }
167 
168  // Now fill full event
169  ATH_MSG_DEBUG("Now filling the event with the L1Topo fragment");
170  fea.fill(re, msg());
171 
172  return StatusCode::SUCCESS;
173 }
174 
175 StatusCode L1TopoByteStreamTool::convert(const std::string& sgKey,
176  L1TopoRDOCollection* result) const {
177  //
178  // Get the ROB fragment:
179  //
181  m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), m_sourceIDs, robFrags);
182 
183  if (robFrags.size() == 0) {
184  ATH_MSG_WARNING("No ROB fragments found");
185  return StatusCode::SUCCESS;
186  }
187 
188  for (auto it : robFrags) {
189  L1TopoRDO* rdo = nullptr;
190  StatusCode sc = convert(ROBData(it).getROBFragment(), rdo);
191  if (sc.isFailure()) {
192  ATH_MSG_ERROR(" Failed to create Objects: " << sgKey);
193  return sc;
194  } else {
195  result->push_back(rdo); // append a copy of the pointer to the
196  // collection, i.e. takes ownership of the new
197  // L1TopoRDO.
198  }
199  }
200  return StatusCode::SUCCESS;
201 }
202 
207 // change to VROBFRAG and use IROBDataProviderSvc::VROBFRAG::const_iterator to
208 // loop over them
210  ATH_MSG_DEBUG("executing convert() from ROBFragment to RDO");
211 
212  uint32_t rodId = rob->rob_source_id();
213 
214  ATH_MSG_DEBUG("expected ROD sub-detector ID: " << MSG::hex << m_sourceIDs
215  << " ID found: " << MSG::hex
216  << rodId << MSG::dec);
217 
218  bool idMatch = false;
219  for (auto id : m_sourceIDs) {
220  if (rodId == id) {
221  idMatch = true;
222  }
223  }
224  if (idMatch) {
225  // Need to check S-link trailer for errors - this would be propagated to
226  // status word, see below.
227  // First use ROB & ROD error check methods
228  bool error_rob(false);
229  bool error_rod(false);
230  try {
231  if (rob->check_rob()) {
232  ATH_MSG_VERBOSE("ROB fragment checked ok");
233  }
234  } catch (std::exception const& ex) {
235  ATH_MSG_WARNING("ROB fragment not valid: " << ex.what());
236  error_rob = true;
237  }
238  try {
239  if (rob->check_rod()) {
240  ATH_MSG_VERBOSE("ROD fragment checked ok");
241  }
242  } catch (std::exception const& ex) {
243  ATH_MSG_WARNING("ROD fragment not valid: " << ex.what());
244  error_rod = true;
245  }
246 
247  // Print some header info
249  MSG::hex << " \n"
250  << " rod_version 0x" << rob->rod_version() << " \n"
251  << " rod_run_no 0x" << MSG::dec
252  << rob->rod_run_no() << " \n"
253  << " rod_lvl1_id 0x" << MSG::hex
254  << rob->rod_lvl1_id() << " \n"
255  << " rod_bc_id 0x" << rob->rod_bc_id() << " \n"
256  << " rod_lvl1_trigger_type 0x" << rob->rod_lvl1_trigger_type()
257  << " \n"
258  << " nchildren 0x" << rob->nchildren() << " \n"
259  << MSG::dec);
260 
261  // print and check status words
262  OFFLINE_FRAGMENTS_NAMESPACE::PointerType it_status = rob->rod_status();
263  const uint32_t nstatus = rob->rod_nstatus();
264  ATH_MSG_VERBOSE("Number of status words: " << nstatus);
265  std::vector<uint32_t> vStatusWords;
266  vStatusWords.reserve(nstatus);
267  ATH_MSG_VERBOSE("Dumping ROD status words:");
268  for (uint32_t i = 0; i < nstatus; ++i, ++it_status) {
269  vStatusWords.push_back(static_cast<uint32_t>(*it_status));
270  ATH_MSG_VERBOSE(" 0x" << MSG::hex << std::setfill('0') << std::setw(8)
271  << *it_status << MSG::dec);
272  }
273  // for definition of first status word see:
274  // - bits 00-15: https://edms.cern.ch/document/445840/5.0a section 5.8
275  // - bits 16-31: bits 16-31:
276  // https://twiki.cern.ch/twiki/bin/viewauth/Atlas/ROBINFragmentErrors
277  // Can do something more specific eventually.
278  bool error_status(false);
279  if (vStatusWords.size() == 0) {
280  ATH_MSG_WARNING("ROD has no status word");
281  }
282  if (vStatusWords.size() > 0 && vStatusWords.at(0) != 0) {
283  ATH_MSG_WARNING("Non-zero first status word, payload may not be valid");
284  error_status = true;
285  }
286 
287  // print and interpret data words and save them for RDO
288  OFFLINE_FRAGMENTS_NAMESPACE::PointerType it_data = rob->rod_data();
289  const uint32_t ndata = rob->rod_ndata();
290  ATH_MSG_VERBOSE("Number of data words: " << ndata);
291 
292  ATH_MSG_VERBOSE("Dumping L1Topo data words:");
293  std::vector<uint32_t> vDataWords;
294  vDataWords.reserve(ndata);
295  for (uint32_t i = 0; i < ndata; ++i, ++it_data) {
296  vDataWords.push_back(static_cast<uint32_t>(*it_data));
297  ATH_MSG_VERBOSE(" 0x" << MSG::hex << std::setfill('0') << std::setw(8)
298  << *it_data << MSG::dec);
299  }
300 
301  // create L1Topo RDO
302  result = new L1TopoRDO();
303  result->setDataWords(std::move(vDataWords));
304  result->setStatusWords(std::move(vStatusWords));
305  if (error_status) {
307  }
308  if (error_rob) {
309  result->setError(L1Topo::Error::ROB_ERROR);
310  }
311  if (error_rod) {
312  result->setError(L1Topo::Error::ROD_ERROR);
313  }
314  result->setSourceID(rodId);
315 
316  return StatusCode::SUCCESS;
317  }
318 
319  ATH_MSG_ERROR("Wrong ROD ID found in the L1Topo ROB fragment!");
320  return StatusCode::FAILURE;
321 }
L1TopoRDO
The class that represents the raw data received from an L1Topo board.
Definition: L1TopoRDO.h:29
RawEventWrite
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
Definition: RawEvent.h:39
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
L1TopoByteStreamTool::m_sourceIDs
std::vector< uint32_t > m_sourceIDs
Source IDs of L1Topo RODs.
Definition: L1TopoByteStreamTool.h:69
get_generator_info.result
result
Definition: get_generator_info.py:21
L1TopoRDO.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ModuleID.h
FullEventAssembler
Template class for assembling a full atlas raw event from subfragments.
Definition: FullEventAssembler.h:40
L1TopoByteStreamTool::m_doROIROBs
BooleanProperty m_doROIROBs
Definition: L1TopoByteStreamTool.h:72
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
ROBData
ROBData_T< OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment, OFFLINE_FRAGMENTS_NAMESPACE::PointerType > ROBData
Definition: ROBData.h:225
ROBData.h
Defines the ROB data entity. The ROB data is an abstract entity that is used to discase the raw event...
L1TopoSrcIdMap
This class provides conversion between Lower level Source ID to higher level source ID for L1Topo Byt...
Definition: L1TopoSrcIdMap.h:17
initialize
void initialize()
Definition: run_EoverP.cxx:894
L1TopoByteStreamTool::finalize
virtual StatusCode finalize()
Function to finalise the tool.
Definition: L1TopoByteStreamTool.cxx:85
skel.it
it
Definition: skel.GENtoEVGEN.py:396
L1TopoByteStreamTool::interfaceID
static const InterfaceID & interfaceID()
AlgTool InterfaceID.
Definition: L1TopoByteStreamTool.cxx:28
L1TopoByteStreamTool::~L1TopoByteStreamTool
virtual ~L1TopoByteStreamTool()
Default destructor.
Definition: L1TopoByteStreamTool.cxx:57
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
python.PyAthena.module
module
Definition: PyAthena.py:131
OFFLINE_FRAGMENTS_NAMESPACE::PointerType
const DataType * PointerType
Definition: RawEvent.h:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
lumiFormat.i
int i
Definition: lumiFormat.py:85
L1TopoByteStreamTool::m_srcIdMap
L1TopoSrcIdMap * m_srcIdMap
Object to generate and convert between the various IDs of the L1Topo fragment.
Definition: L1TopoByteStreamTool.h:67
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
L1TopoByteStreamTool::convert
StatusCode convert(const std::string &sgKey, L1TopoRDOCollection *result) const
Convert ROBFragment to L1TopoRDO.
Definition: L1TopoByteStreamTool.cxx:175
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
calibdata.exception
exception
Definition: calibdata.py:496
L1TopoRDOCollection.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
IROBDataProviderSvc::VROBFRAG
std::vector< const ROBF * > VROBFRAG
Definition: IROBDataProviderSvc.h:27
L1Topo::Error::ROD_ERROR
@ ROD_ERROR
L1Topo::Error::SLINK_STATUS_ERROR
@ SLINK_STATUS_ERROR
L1TopoByteStreamTool::sourceIDs
const std::vector< uint32_t > & sourceIDs()
return list of L1Topo ROD source IDs to use, defaults to DAQ ROD IDs
Definition: L1TopoByteStreamTool.cxx:100
L1TopoByteStreamTool::m_doDAQROBs
BooleanProperty m_doDAQROBs
Definition: L1TopoByteStreamTool.h:71
L1TopoByteStreamTool::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service for reading bytestream.
Definition: L1TopoByteStreamTool.h:76
L1TopoRDOCollection
Container of L1TopoRDOs (standard Athena boilerplate)
Definition: L1TopoRDOCollection.h:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
L1TopoByteStreamTool::L1TopoByteStreamTool
L1TopoByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Default constructor.
Definition: L1TopoByteStreamTool.cxx:36
L1TopoByteStreamTool::initialize
virtual StatusCode initialize()
Function to initialise the tool.
Definition: L1TopoByteStreamTool.cxx:63
L1Topo::ModuleID
Represents the L1Topo module ID, with decoder and encoder.
Definition: ModuleID.h:28
FullEventAssembler::setRodMinorVersion
void setRodMinorVersion(uint16_t m)
change the ROD minor version
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
L1Topo::Error::ROB_ERROR
@ ROB_ERROR
re
const boost::regex re(r_e)
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
L1TopoSrcIdMap::getRodID
uint32_t getRodID() const
get a ROD Source ID (deprecated)
Definition: L1TopoSrcIdMap.cxx:22
FullEventAssembler::RODDATA
std::vector< uint32_t > RODDATA
ROD data as a vector of unsigned int.
Definition: FullEventAssembler.h:54
AthAlgTool
Definition: AthAlgTool.h:26
L1Topo::ModuleID::id
uint16_t id() const
access method
Definition: ModuleID.cxx:41
FullEventAssembler::getRodData
RODDATA * getRodData(uint32_t id)
get a block of ROD data
Helpers.h
FullEventAssembler::setDetEvtType
void setDetEvtType(uint32_t m)
change Detector Event Type
FullEventAssembler::fill
void fill(RawEventWrite *re, MsgStream &log)
Fill the FullEventFragment with all the ROD data stored in this.
L1TopoByteStreamTool.h