ATLAS Offline Software
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"
18 #include "MuCTPIByteStreamTool.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 
51 
53 
54 }
55 
58 }
59 
64 
65  //
66  // Initialise the base class:
67  //
69 
70  MsgStream log( msgSvc(), "MuCTPIByteStreamCnv" );
71  log << MSG::DEBUG << "MuCTPIByteStreamCnv in initialize() " << endmsg;
72 
73  //
74  // Get ByteStreamCnvSvc:
75  //
76  ATH_CHECK( m_ByteStreamEventAccess.retrieve() );
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 
116 StatusCode 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 
231 StatusCode 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 }
MuCTPIByteStreamCnv.h
CTP_RIO
Definition: CTP_RIO.h:22
RawEventWrite
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
Definition: RawEvent.h:39
MuCTPISrcIdMap::getRobID
uint32_t getRobID(uint32_t rod_id) const
Make a ROB Source ID from a ROD source ID.
Definition: MuCTPISrcIdMap.cxx:17
MuCTPISrcIdMap::getRodID
uint32_t getRodID() const
get a ROD Source ID
Definition: MuCTPISrcIdMap.cxx:12
get_generator_info.result
result
Definition: get_generator_info.py:21
ROBData_T::getROBFragment
const ROBFragment * getROBFragment() const
Return the ROBFragment.
Definition: ROBData.h:184
MuCTPIByteStreamCnv::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service used when reading the BS data.
Definition: MuCTPIByteStreamCnv.h:80
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
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...
initialize
void initialize()
Definition: run_EoverP.cxx:894
ROBData_T
templete data class to wrap ROB fragment for accessing ROD data
Definition: ROBData.h:46
MuCTPIByteStreamCnv::initialize
virtual StatusCode initialize() override
Function connecting to all the needed services/tools.
Definition: MuCTPIByteStreamCnv.cxx:63
skel.it
it
Definition: skel.GENtoEVGEN.py:396
SG::asStorable
DataObject * asStorable(T *pObject)
Definition: StorableConversions.h:158
MuCTPIByteStreamCnv::storageType
static long storageType()
Function needed by the framework.
Definition: MuCTPIByteStreamCnv.cxx:56
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
MuCTPIByteStreamCnv::m_ByteStreamEventAccess
ServiceHandle< IByteStreamEventAccess > m_ByteStreamEventAccess
Service used when writing the BS data.
Definition: MuCTPIByteStreamCnv.h:82
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
MuCTPIByteStreamCnv::classID
static const CLID & classID()
Function needed by the framework.
Definition: MuCTPIByteStreamCnv.cxx:50
RawEvent.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
ByteStreamAddress
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
Definition: ByteStreamAddress.h:28
MuCTPIByteStreamTool.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IROBDataProviderSvc::VROBFRAG
std::vector< const ROBF * > VROBFRAG
Definition: IROBDataProviderSvc.h:27
ByteStreamAddress.h
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
RecCTPByteStreamTool.h
ByteStreamAddress::storageType
static constexpr long storageType()
Definition: ByteStreamAddress.h:51
Converter
Definition: Converter.h:27
MuCTPIByteStreamCnv::m_srcIdMap
MuCTPISrcIdMap m_srcIdMap
Object storing the various IDs of the MuCTPI fragment.
Definition: MuCTPIByteStreamCnv.h:71
CTP_RIO.h
MuCTPIByteStreamCnv::createRep
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr) override
Function creating the MuCTPI ROB fragment from a MuCTPI_RDO object.
Definition: MuCTPIByteStreamCnv.cxx:231
CTPByteStreamTool.h
MuCTPI_RDO.h
CTP_RDO.h
MuCTPI_RDO
Class representing the readout data of the MuCTPI hardware and simulation.
Definition: MuCTPI_RDO.h:41
CTP_RDO
Definition: CTP_RDO.h:20
MuCTPIByteStreamCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
Function creating the MuCTPI_RDO object from a MuCTPI ROB fragment.
Definition: MuCTPIByteStreamCnv.cxx:116
re
const boost::regex re(r_e)
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuCTPIByteStreamCnv::m_tool
ToolHandle< MuCTPIByteStreamTool > m_tool
Tool doing the actual conversion.
Definition: MuCTPIByteStreamCnv.h:69
MuCTPIByteStreamCnv::MuCTPIByteStreamCnv
MuCTPIByteStreamCnv(ISvcLocator *svcloc)
Standard constructor.
Definition: MuCTPIByteStreamCnv.cxx:33