ATLAS Offline Software
L1TriggerResultByteStreamCnv.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 // Trigger includes
8 
9 // Athena includes
14 
15 // Gaudi includes
16 #include "GaudiKernel/IRegistry.h"
17 #include "GaudiKernel/ThreadLocalContext.h"
18 
19 // TDAQ includes
20 #include "eformat/Issue.h"
21 #include "eformat/SourceIdentifier.h"
22 
24 
25 // =============================================================================
26 // Standard constructor
27 // =============================================================================
29  Converter(storageType(), classID(), svcLoc),
30  AthMessaging(msgSvc(), "L1TriggerResultByteStreamCnv") {}
31 
32 // =============================================================================
33 // Standard destructor
34 // =============================================================================
36 
37 // =============================================================================
38 // Implementation of Converter::initialize
39 // =============================================================================
41  ATH_MSG_VERBOSE("start of " << __FUNCTION__);
43 
44  // Check one property of the encoder tool to determine if the tool is configured in the job
45  const bool doMuon = not serviceLocator()->getOptsSvc().get("ToolSvc.L1MuonBSEncoderTool.ROBIDs").empty();
46  ATH_MSG_DEBUG("MUCTPI BS encoding is " << (doMuon ? "enabled" : "disabled"));
47  ATH_CHECK(m_muonEncoderTool.retrieve(EnableTool(doMuon)));
48 
49  const bool doMuonDaq = not serviceLocator()->getOptsSvc().get("ToolSvc.L1MuonBSEncoderToolDAQ.ROBIDs").empty();
50  ATH_MSG_DEBUG("MUCTPI DAQ ROB encoding is " << (doMuonDaq ? "enabled" : "disabled"));
51  ATH_CHECK(m_muonEncoderToolDaq.retrieve(EnableTool(doMuonDaq)));
52 
53  ATH_MSG_VERBOSE("end of " << __FUNCTION__);
54  return StatusCode::SUCCESS;
55 }
56 
57 // =============================================================================
58 // Implementation of Converter::finalize
59 // =============================================================================
61  ATH_MSG_VERBOSE("start of " << __FUNCTION__);
62  if (m_ByteStreamEventAccess.release().isFailure())
63  ATH_MSG_WARNING("Failed to release service " << m_ByteStreamEventAccess.typeAndName());
64  if (m_muonEncoderTool.isEnabled() && m_muonEncoderTool.release().isFailure())
65  ATH_MSG_WARNING("Failed to release tool " << m_muonEncoderTool.typeAndName());
66  if (m_muonEncoderToolDaq.isEnabled() && m_muonEncoderToolDaq.release().isFailure())
67  ATH_MSG_WARNING("Failed to release tool " << m_muonEncoderToolDaq.typeAndName());
68  ATH_MSG_VERBOSE("end of " << __FUNCTION__);
69  return StatusCode::SUCCESS;
70 }
71 
72 // =============================================================================
73 // Implementation of Converter::createObj
74 // =============================================================================
75 StatusCode L1TriggerResultByteStreamCnv::createObj(IOpaqueAddress* /*pAddr*/, DataObject*& /*pObj*/) {
76  ATH_MSG_ERROR("L1TriggerResult cannot be created directly from ByteStream!"
77  << " Use the L1TriggerResultMaker algorithm instead");
78  return StatusCode::FAILURE;
79 }
80 
81 // =============================================================================
82 // Implementation of Converter::createRep
83 // =============================================================================
84 StatusCode L1TriggerResultByteStreamCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr) {
85  ATH_MSG_VERBOSE("start of " << __FUNCTION__);
86 
87  // Cast the DataObject to L1TriggerResult
88  xAOD::TrigCompositeContainer* l1TriggerResult = nullptr;
89  bool castSuccessful = SG::fromStorable(pObj, l1TriggerResult);
90  if (!castSuccessful || !l1TriggerResult) {
91  ATH_MSG_ERROR("Failed to convert DataObject to xAOD::TrigCompositeContainer for L1TriggerResult");
92  return StatusCode::FAILURE;
93  }
94 
95  // Obtain the RawEventWrite (aka eformat::write::FullEventFragment) pointer
96  RawEventWrite* re = m_ByteStreamEventAccess->getRawEvent();
97  if (!re) {
98  ATH_MSG_ERROR("Failed to obtain a pointer to RawEventWrite");
99  return StatusCode::FAILURE;
100  }
101  ATH_MSG_VERBOSE("Obtained RawEventWrite pointer = " << re);
102 
103  // CTP encoding should come here when implemented and update full event header (L1 trigger bits)
104  // in addition to encoding the corresponding ROBFragment.
105  // The xAOD CTP result object holding the bits will be obtained here via ElementLink from l1TriggerResult
106 
107  // MuonRoI encoding
108  for (ToolHandle<IL1TriggerByteStreamTool>& tool : {std::reference_wrapper(m_muonEncoderTool), std::reference_wrapper(m_muonEncoderToolDaq)}) {
109  if (not tool.isEnabled()) {continue;}
110  std::vector<WROBF*> muon_robs;
111  ATH_CHECK(tool->convertToBS(muon_robs, Gaudi::Hive::currentContext())); // TODO: find a way to avoid ThreadLocalContext
112  ATH_MSG_DEBUG(tool.name() << " created " << muon_robs.size() << " L1Muon ROB Fragments");
113  for (WROBF* rob : muon_robs) {
114  printRob(*rob);
115  // Set LVL1 Trigger Type from the full event
116  rob->rod_lvl1_type(re->lvl1_trigger_type());
117  // Set LVL1 ID from the full event
118  rob->rod_lvl1_id(re->lvl1_id());
119  // Add the ROBFragment to the full event
120  re->append(rob);
121  ATH_MSG_DEBUG("Added ROB fragment 0x" << MSG::hex << rob->source_id() << MSG::dec << " to the output raw event");
122  }
123  }
124 
125  // Placeholder for other systems: L1Topo, L1Calo
126 
127  // Create a ByteStreamAddress for L1TriggerResult
128  if ( pAddr != nullptr ) pAddr->release();
129  ByteStreamAddress* bsAddr = new ByteStreamAddress(classID(), pObj->registry()->name(), "");
130  pAddr = static_cast<IOpaqueAddress*>(bsAddr);
131  pAddr->addRef();
132 
133  ATH_MSG_VERBOSE("end of " << __FUNCTION__);
134  return StatusCode::SUCCESS;
135 }
136 
137 // =============================================================================
138 // Debug print helper
139 // =============================================================================
141  if (not msgLvl(MSG::DEBUG)) {return;}
142  const uint32_t ndata = rob.rod_ndata();
143  const uint32_t* data = rob.rod_data();
144  ATH_MSG_DEBUG("This ROB has " << ndata << " data words");
145  for (uint32_t i=0; i<ndata; ++i, ++data) {
146  ATH_MSG_DEBUG("--- 0x" << MSG::hex << *data << MSG::dec);
147  }
148 }
149 
150 // =============================================================================
151 // CLID / storageType
152 // =============================================================================
155 }
156 
159 }
RawEventWrite
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
Definition: RawEvent.h:39
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
AthCheckMacros.h
L1TriggerResultByteStreamCnv::finalize
virtual StatusCode finalize() override
Definition: L1TriggerResultByteStreamCnv.cxx:60
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::fromStorable
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
Definition: StorableConversions.h:180
StorableConversions.h
convert to and from a SG storable
python.ZdcRecConfig.doMuon
doMuon
Definition: ZdcRecConfig.py:331
L1TriggerResultByteStreamCnv::printRob
void printRob(const OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment &rob) const
Helper method for debug printouts.
Definition: L1TriggerResultByteStreamCnv.cxx:140
L1TriggerResultByteStreamCnv::~L1TriggerResultByteStreamCnv
virtual ~L1TriggerResultByteStreamCnv()
Standard destructor.
Definition: L1TriggerResultByteStreamCnv.cxx:35
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
L1TriggerResultByteStreamCnv::m_ByteStreamEventAccess
ServiceHandle< IByteStreamEventAccess > m_ByteStreamEventAccess
Helper to obtain the RawEvent pointer.
Definition: L1TriggerResultByteStreamCnv.h:52
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthMessaging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Test the output level.
Definition: AthMessaging.h:151
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:92
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
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
L1TriggerResultByteStreamCnv::classID
static const CLID & classID()
CLID of the class of the L1TriggerResult converted by this converter (xAOD::TrigCompositeContainer)
Definition: L1TriggerResultByteStreamCnv.cxx:153
ByteStreamAddress
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
Definition: ByteStreamAddress.h:28
L1TriggerResultByteStreamCnv::initialize
virtual StatusCode initialize() override
Definition: L1TriggerResultByteStreamCnv.cxx:40
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ByteStreamAddress.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
TrigCompositeContainer.h
L1TriggerResultByteStreamCnv::storageType
static long storageType()
Storage type used by this converter.
Definition: L1TriggerResultByteStreamCnv.cxx:157
ByteStreamAddress::storageType
static constexpr long storageType()
Definition: ByteStreamAddress.h:51
L1TriggerResultByteStreamCnv.h
Converter
Definition: Converter.h:27
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
L1TriggerResultByteStreamCnv::m_muonEncoderToolDaq
ToolHandle< IL1TriggerByteStreamTool > m_muonEncoderToolDaq
Definition: L1TriggerResultByteStreamCnv.h:57
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment
eformat::write::ROBFragment ROBFragment
Definition: RawEvent.h:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
WROBF
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment WROBF
Definition: eFexByteStreamTool.cxx:27
re
const boost::regex re(r_e)
DEBUG
#define DEBUG
Definition: page_access.h:11
L1TriggerResultByteStreamCnv::createRep
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr) override
Create ByteStream from xAOD (L1TriggerResult)
Definition: L1TriggerResultByteStreamCnv.cxx:84
L1TriggerResultByteStreamCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
Create xAOD (L1TriggerResult) from ByteStream.
Definition: L1TriggerResultByteStreamCnv.cxx:75
L1TriggerResultByteStreamCnv::m_muonEncoderTool
ToolHandle< IL1TriggerByteStreamTool > m_muonEncoderTool
Encoder tools for L1Muon RoIs (one writing RoIB ROB, one writing DAQ ROB)
Definition: L1TriggerResultByteStreamCnv.h:56
L1TriggerResultByteStreamCnv::L1TriggerResultByteStreamCnv
L1TriggerResultByteStreamCnv(ISvcLocator *svcLoc)
Standard constructor.
Definition: L1TriggerResultByteStreamCnv.cxx:28