2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
5 #ifndef TRIGT1RESULTBYTESTREAM_ROIBRESULTBYTESTREAMCNV_ICC
6 #define TRIGT1RESULTBYTESTREAM_ROIBRESULTBYTESTREAMCNV_ICC
9 #include "TrigT1Result/RoIBResult.h"
12 #include "ByteStreamCnvSvcBase/ByteStreamAddress.h"
13 #include "ByteStreamData/RawEvent.h"
14 #include "AthenaKernel/StorableConversions.h"
17 #include "GaudiKernel/ConcurrencyFlags.h"
20 * The constructor sets up all the ToolHandle and ServiceHandle objects and initialises the
21 * base class in the correct way.
23 template< class ROBF >
24 RoIBResultByteStreamCnv< ROBF >::RoIBResultByteStreamCnv( ISvcLocator* svcloc )
25 : Converter( storageType(), classID(), svcloc ),
26 AthMessaging( msgSvc(), "RoIBResultByteStreamCnv" ),
27 m_tool( "RoIBResultByteStreamTool/RoIBResultBSEncoderTool" ),
28 m_ByteStreamCnvSvc( "ByteStreamCnvSvc", "RoIBResultByteStreamCnv" ),
29 m_robDataProviderSvc( "ROBDataProviderSvc", "RoIBResultByteStreamCnv" ) {
34 * Function telling the framework the Class ID of the object that this converter
35 * is for (RoIBResult).
37 template< class ROBF >
38 const CLID& RoIBResultByteStreamCnv< ROBF >::classID(){
39 return ClassID_traits< ROIB::RoIBResult >::ID();
42 template< class ROBF >
43 long RoIBResultByteStreamCnv< ROBF >::storageType() {
44 return ByteStreamAddress::storageType();
48 * Init method gets all necessary services etc.
50 template< class ROBF >
51 StatusCode RoIBResultByteStreamCnv< ROBF >::initialize() {
53 // Initialise the base class:
55 ATH_CHECK( Converter::initialize() );
56 ATH_MSG_DEBUG("In initialize()");
59 // Get ByteStreamCnvSvc:
61 ATH_CHECK( m_ByteStreamCnvSvc.retrieve() );
62 ATH_MSG_DEBUG("Connected to ByteStreamCnvSvc");
65 // Get ROBDataProviderSvc:
67 ATH_CHECK( m_robDataProviderSvc.retrieve() );
68 ATH_MSG_DEBUG("Connected to ROBDataProviderSvc");
71 // Get RoIBResultByteStreamTool:
73 ATH_CHECK( m_tool.retrieve() );
74 ATH_MSG_DEBUG("Connected to RoIBResultByteStreamTool");
77 // Flag if running in AthenaMT
79 m_isMT = (Gaudi::Concurrency::ConcurrencyFlags::numThreads() + Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents()) > 0;
80 if (m_isMT) ATH_MSG_DEBUG("Detected running in AthenaMT");
81 else ATH_MSG_DEBUG("Detected running in legacy Athena");
83 return StatusCode::SUCCESS;
87 * This function creates the RoIBResult object from the BS data. It collects all the
88 * ROB fragments coming from the RoI Builder and gives them to RoIBResultByteStreamTool
91 template< class ROBF >
92 StatusCode RoIBResultByteStreamCnv< ROBF >::createObj( IOpaqueAddress* /*pAddr*/, DataObject*& /*pObj*/ ) {
93 ATH_MSG_ERROR("Misconfiguration! Decoding ROIB::RoIBResult from ByteStream using a Converter is deprecated. "
94 << "Use the L1TriggerByteStreamDecoderAlg configured with RoIBResultByteStreamTool instead.");
95 return StatusCode::FAILURE;
99 * This function receives an RoIBResult object as input, and adds all the ROB fragments
100 * of the RoI Builder to the current raw event using the IByteStreamEventAccess
103 template< class ROBF >
104 StatusCode RoIBResultByteStreamCnv< ROBF >::createRep( DataObject* pObj, IOpaqueAddress*& pAddr ) {
105 ATH_MSG_DEBUG("createRep() called");
107 // Create a ByteStreamAddress for RoIBResult
108 ROIB::RoIBResult* result;
109 if( ! SG::fromStorable( pObj, result ) ) {
110 ATH_MSG_ERROR("Failed to convert DataObject to RoIBResult");
111 return StatusCode::FAILURE;
114 if ( pAddr != nullptr ) pAddr->release();
115 ByteStreamAddress* bsAddr = new ByteStreamAddress( classID(), pObj->registry()->name(), "" );
116 pAddr = static_cast<IOpaqueAddress*>(bsAddr);
119 // Retrieve the raw event pointer
120 RawEventWrite* re = m_ByteStreamCnvSvc->getRawEvent();
122 ATH_MSG_ERROR("Failed to obtain a pointer to RawEventWrite");
123 return StatusCode::FAILURE;
125 ATH_MSG_VERBOSE("Obtained RawEventWrite pointer = " << re);
127 // Use the IL1TriggerByteStreamTool interface of the tool to convert RoIBResult to ByteStream.
128 // NOTE: the pObj passed as input to this function is actually not passed to the tool. Instead,
129 // the tool retrieves the RoIBResult from event store using a ReadHandle which ensures correct
130 // data dependencies and integration with other uses of the same interface.
131 std::vector<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment*> vrobf;
132 ATH_CHECK(m_tool->convertToBS(vrobf, Gaudi::Hive::currentContext())); // TODO: find a way to avoid ThreadLocalContext
133 ATH_MSG_DEBUG("Created " << vrobf.size() << " ROB Fragments");
134 for (OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment* rob : vrobf) {
135 // Set LVL1 Trigger Type from the full event
136 rob->rod_lvl1_type(re->lvl1_trigger_type());
137 // Set LVL1 ID from the full event
138 rob->rod_lvl1_id(re->lvl1_id());
139 // Add the ROBFragment to the full event
141 ATH_MSG_DEBUG("Added ROB fragment " << MSG::hex << rob->source_id() << MSG::dec << " to the output raw event");
144 return StatusCode::SUCCESS;
148 #endif // TRIGT1RESULTBYTESTREAM_ROIBRESULTBYTESTREAMCNV_ICC