ATLAS Offline Software
Loading...
Searching...
No Matches
MuCTPIByteStreamCnv.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// Gaudi/Athena include(s):
10
12
13// Trigger include(s):
15
16// Local include(s):
17#include "MuCTPIByteStreamCnv.h"
19
20// Hack for early data, where CTP and MuCTPI were plugged into the
21// same ROS PC
22#ifdef CTP_MUCTPI_HAVE_SAME_ROS
23# include "CTPByteStreamTool.h"
24# include "RecCTPByteStreamTool.h"
25# include "TrigT1Result/CTP_RDO.h"
26# include "TrigT1Result/CTP_RIO.h"
27#endif
28
34 : Converter( storageType(), classID(), svcloc ),
35 m_tool( "MuCTPIByteStreamTool" ),
36#ifdef CTP_MUCTPI_HAVE_SAME_ROS
37 m_ctp_tool( "CTPByteStreamTool" ),
38 m_ctp_rec_tool( "RecCTPByteStreamTool" ),
39 m_storeGate( "StoreGateSvc", "MuCTPIByteStreamCnv" ),
40#endif
41 m_robDataProvider( "ROBDataProviderSvc", "MuCTPIByteStreamCnv" ),
42 m_ByteStreamEventAccess( "ByteStreamCnvSvc", "MuCTPIByteStreamCnv" ) {
43
44}
45
55
59
64
65 //
66 // Initialise the base class:
67 //
68 ATH_CHECK( Converter::initialize() );
69
70 MsgStream log( msgSvc(), "MuCTPIByteStreamCnv" );
71 log << MSG::DEBUG << "MuCTPIByteStreamCnv in initialize() " << endmsg;
72
73 //
74 // Get ByteStreamCnvSvc:
75 //
77
78 //
79 // Get MuCTPIByteStreamTool:
80 //
81 ATH_CHECK( m_tool.retrieve() );
82 log << MSG::DEBUG << "Connected to MuCTPIByteStreamTool" << endmsg;
83
84#ifdef CTP_MUCTPI_HAVE_SAME_ROS
85 //
86 // Get CTPByteStreamTool:
87 //
88 ATH_CHECK( m_ctp_tool.retrieve() );
89 log << MSG::DEBUG << "Connected to CTPByteStreamTool" << endmsg;
90
91 //
92 // Get RecCTPByteStreamTool:
93 //
94 ATH_CHECK( m_ctp_rec_tool.retrieve() );
95 log << MSG::DEBUG << "Connected to RecCTPByteStreamTool" << endmsg;
96#endif
97
98 //
99 // Get ROBDataProvider:
100 //
101 if( m_robDataProvider.retrieve().isFailure() ) {
102 log << MSG::WARNING << "Can't get ROBDataProviderSvc" << endmsg;
103 // return is disabled for Write BS which does not requre ROBDataProviderSvc
104 } else {
105 log << MSG::DEBUG << "Connected to ROBDataProviderSvc" << endmsg;
106 }
107
108 return StatusCode::SUCCESS;
109}
110
116StatusCode MuCTPIByteStreamCnv::createObj( IOpaqueAddress* pAddr, DataObject*& pObj ) {
117
118 MsgStream log( msgSvc(), "MuCTPIByteStreamCnv" );
119 log << MSG::DEBUG << "createObj() called" << endmsg;
120
121 ByteStreamAddress *pBS_Addr;
122 pBS_Addr = dynamic_cast< ByteStreamAddress* >( pAddr );
123 if ( !pBS_Addr ) {
124 log << MSG::ERROR << " Can not cast to ByteStreamAddress " << endmsg ;
125 return StatusCode::FAILURE;
126 }
127
128 log << MSG::DEBUG << " Creating Objects " << *( pBS_Addr->par() ) << endmsg;
129
130 //
131 // Get SourceID:
132 //
133 const uint32_t robId = m_srcIdMap.getRobID( m_srcIdMap.getRodID() );
134
135 log << MSG::DEBUG << " expected ROB sub-detector ID: " << std::hex
136 << robId << std::dec << endmsg;
137
138 std::vector< uint32_t > vID;
139 vID.push_back( robId );
140
141 //
142 // Get ROB fragment:
143 //
145 m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags );
146
147 //
148 // Size check:
149 //
150 if( robFrags.size() == 0 ) {
151
152 // This is a hack - for some time CTP and MUCTPI were plugged in
153 // the same ROB of the same ROS PC ...
154 // 0x76000b : MUCTPI
155 // 0x76000a : CTP
156 // Note that the MUCTPI ROBID must come first, cos further down we
157 // just use the first element of robFrags to create the RDO
158 vID[0] = ( robId | 0x00000b );
159#ifdef CTP_MUCTPI_HAVE_SAME_ROS
160 vID.push_back( robId | 0x00000a );
161#endif
162 m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags );
163
164 if( robFrags.size() == 0 ) {
165 // yet another temporary hack!!! - for some time the ROB ID was 0!
166 vID[0] = 0x00000b;
167#ifdef CTP_MUCTPI_HAVE_SAME_ROS
168 vID[1] = 0x00000a;
169#endif
170 m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags );
171
172 if( robFrags.size() == 0 ) {
173 log << MSG::WARNING << "No MuCTPI ROB fragments found!" << endmsg;
174
176 pObj = SG::asStorable( result );
177 return StatusCode::SUCCESS;
178 }
179 }
180 }
181
182 IROBDataProviderSvc::VROBFRAG::const_iterator it = robFrags.begin();
183 MuCTPI_RDO* result = 0;
184 StatusCode sc = m_tool->convert( ROBData( *it ).getROBFragment(), result );
185 if( sc.isFailure() ) {
186 log << MSG::ERROR << " Failed to create Objects: " << *( pBS_Addr->par() ) << endmsg;
187 if (result!=0){
188 delete result;
189 result=0;
190 }
191 return sc;
192 }
193 pObj = SG::asStorable( result ) ;
194
195#ifdef CTP_MUCTPI_HAVE_SAME_ROS
196 // If CTP and MuCTPI send to the same ROS, the MuCTPI ROS, we get
197 // the CTP fragment in the MuCTPI ROS fragment. In order to be able
198 // to produce a CTP_RDO, we call the CTP ByteStream AlgTool from
199 // here whenever we think we have a CTP fragment.
200
201 if( robFrags.size() > 1 ) {
202
203 ++it;
204 if( it != robFrags.end() ) {
205
206 CTP_RDO* ctp_result = 0;
207 CTP_RIO* ctp_rio_result = 0;
208
209 ATH_CHECK( m_ctp_tool->convert( ROBData( *it ).getROBFragment(), ctp_result ) );
210
211 SG::asStorable( ctp_result ) ;
212 ATH_CHECK( m_storeGate->record( ctp_result, "CTP_RDO" ) );
213
214 ATH_CHECK( m_ctp_rec_tool->convert( ROBData( *it ).getROBFragment(), ctp_rio_result, log ) );
215
216 SG::asStorable( ctp_rio_result ) ;
217 ATH_CHECK( m_storeGate->record( ctp_rio_result, "CTP_RIO" ) );
218 }
219
220 }
221#endif
222
223 return sc;
224}
225
231StatusCode MuCTPIByteStreamCnv::createRep( DataObject* pObj, IOpaqueAddress*& pAddr ) {
232
233 MsgStream log( msgSvc(), "MuCTPIByteStreamCnv" );
234 log << MSG::DEBUG << "createRep() called" << endmsg;
235
236 RawEventWrite* re = m_ByteStreamEventAccess->getRawEvent();
237
239 if( ! SG::fromStorable( pObj, result ) ) {
240 log << MSG::ERROR << " Cannot cast to MuCTPI_RDO" << endmsg;
241 return StatusCode::FAILURE;
242 }
243
244 ByteStreamAddress* addr = new ByteStreamAddress( classID(), pObj->registry()->name(), "" );
245
246 pAddr = addr;
247
248 // Convert to ByteStream
249 return m_tool->convert( result, re );
250}
const boost::regex re(r_e)
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
uint32_t CLID
The Class ID type.
static Double_t sc
Defines the ROB data entity. The ROB data is an abstract entity that is used to decouple the raw even...
ROBData_T< OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment, OFFLINE_FRAGMENTS_NAMESPACE::PointerType > ROBData
Definition ROBData.h:225
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
Definition RawEvent.h:39
convert to and from a SG storable
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
static constexpr long storageType()
std::vector< const ROBF * > VROBFRAG
ServiceHandle< IByteStreamEventAccess > m_ByteStreamEventAccess
Service used when writing the BS data.
static const CLID & classID()
Function needed by the framework.
ToolHandle< MuCTPIByteStreamTool > m_tool
Tool doing the actual conversion.
MuCTPIByteStreamCnv(ISvcLocator *svcloc)
Standard constructor.
MuCTPISrcIdMap m_srcIdMap
Object storing the various IDs of the MuCTPI fragment.
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
Function creating the MuCTPI_RDO object from a MuCTPI ROB fragment.
virtual StatusCode initialize() override
Function connecting to all the needed services/tools.
static long storageType()
Function needed by the framework.
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service used when reading the BS data.
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr) override
Function creating the MuCTPI ROB fragment from a MuCTPI_RDO object.
Class representing the readout data of the MuCTPI hardware and simulation.
Definition MuCTPI_RDO.h:41
const ROBFragment * getROBFragment() const
Return the ROBFragment.
Definition ROBData.h:184
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)