ATLAS Offline Software
HLTResultByteStreamCnv.cxx
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 */
6 
9 
10 #include "ByteStreamData/ROBData.h"
14 
15 #include "GaudiKernel/MsgStream.h"
16 #include "GaudiKernel/StatusCode.h"
17 #include "GaudiKernel/DataObject.h"
18 #include "GaudiKernel/IRegistry.h"
19 
21 
22 #include "StoreGate/StoreGateSvc.h"
23 #include "AthenaKernel/CLASS_DEF.h"
24 
25 // Tool
26 #include "GaudiKernel/IToolSvc.h"
27 
28 #include <map>
29 
35  Converter(storageType(), classID(),svcloc),
36  m_log(0),
37  m_tool("HLT::HLTResultByteStreamTool"),
38  m_ByteStreamEventAccess("ByteStreamCnvSvc", "HLTResultByteStreamCnv"),
39  m_robDataProvider("ROBDataProviderSvc", "HLTResultByteStreamCnv")
40 { }
41 
46 {
48 }
49 
51 {
53 }
54 
56 {
57  delete m_log;
58  return StatusCode::SUCCESS;
59 }
60 
61 
66 {
68  if(StatusCode::SUCCESS!=sc)
69  {
70  return sc;
71  }
72 
73  m_log = new MsgStream(msgSvc(), "HLTResultByteStreamCnv");
74 
75  (*m_log) << MSG::DEBUG << "HLTResultByteStreamCnv in initialize() " <<endmsg;
76 
77  //Get ByteStreamCnvSvc
78  if ( m_ByteStreamEventAccess.retrieve().isFailure() ) {
79  (*m_log) << MSG::FATAL << "failed to retrieve ByteStreamEventAccess service: "
80  << m_ByteStreamEventAccess << endmsg;
81  return StatusCode::FAILURE;
82  } else {
83  (*m_log) << MSG::DEBUG << "successfully retrieved ByteStreamEventAccess service: "
84  << m_ByteStreamEventAccess << endmsg;
85  }
86 // if(StatusCode::SUCCESS != service("ByteStreamCnvSvc",m_ByteStreamEventAccess)){
87 // (*m_log) << MSG::ERROR << " Can't get ByteStreamEventAccess interface " << endmsg;
88 // return StatusCode::FAILURE;
89 // }
90 
91 
92 
93  // Retrieve Tool
94  // IToolSvc* toolSvc;
95  // if(StatusCode::SUCCESS != service("ToolSvc",toolSvc)){
96  // (*m_log) << MSG::ERROR << " Can't get ToolSvc " << endmsg;
97  // return StatusCode::FAILURE;
98  // }
99 
100 // std::string toolType = "HLT::HLTResultByteStreamTool" ;
101 // if(StatusCode::SUCCESS !=toolSvc->retrieveTool(toolType,m_tool))
102 // {
103 // (*m_log) << MSG::ERROR << " Can't get ByteStreamTool " << endmsg;
104 // return StatusCode::FAILURE;
105 // }
106  // get the converter tool:
107  if ( m_tool.retrieve().isFailure() ) {
108  (*m_log) << MSG::FATAL << "failed to retrieve converter tool : "
109  << m_tool << endmsg;
110  return StatusCode::FAILURE;
111  } else {
112  (*m_log) << MSG::DEBUG << "successfully retrieved converter tool: "
113  << m_tool << endmsg;
114  }
115 
116 
117  // Get ROBDataProvider
118  if (m_robDataProvider.retrieve().isFailure()) {
119  (*m_log) << MSG::FATAL << "failed to retrieve ROBDataProviderSvc service: "
120  << m_robDataProvider << endmsg;
121  return StatusCode::FAILURE;
122  }
123  (*m_log) << MSG::DEBUG << "successfully retrieved ROBDataProviderSvc service: "
124  << m_robDataProvider << endmsg;
125 
126 // IService* robSvc ;
127 // sc = serviceLocator()->getService("ROBDataProviderSvc", robSvc);
128 // if(sc != StatusCode::SUCCESS ) {
129 // (*m_log)<<MSG::ERROR << " Cant get ROBDataProviderSvc " <<endmsg;
130 
131 // //DBG:
132 // // return sc ;
133 // return StatusCode::SUCCESS;
134 // }
135 
136 // m_robDataProvider = dynamic_cast<IROBDataProviderSvc*> (robSvc);
137 // if(m_robDataProvider == 0 ) {
138 // (*m_log)<<MSG::ERROR<< " Cant cast to ROBDataProviderSvc " <<endmsg;
139 // // return StatusCode::FAILURE ;
140 // }
141 
142  return StatusCode::SUCCESS;
143 }
144 
148 StatusCode HLT::HLTResultByteStreamCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
149 {
150  HLTResult* result = new HLTResult();
151 
152  ByteStreamAddress *pBS_Addr = dynamic_cast<ByteStreamAddress*>(pAddr);
153  if(pBS_Addr==nullptr) {
154  (*m_log) << MSG::ERROR << " Can not cast to ByteStreamAddress " << endmsg ;
155  return StatusCode::FAILURE;
156  }
157 
158  const std::string nm = *(pBS_Addr->par()) ;
159  std::vector<ROBData> vRobData;
160 
161  StatusCode sc = m_tool->convert(*m_robDataProvider, result, nm);
162  if (sc != StatusCode::SUCCESS) {
163  (*m_log) << MSG::ERROR << "Failed to create object " << nm << endmsg;
164  return sc;
165  }
166 
167  pObj = SG::asStorable(result);
168  return sc;
169 }
170 
174 StatusCode HLT::HLTResultByteStreamCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
175 {
176 
177  HLTResult* result = 0;
178  SG::fromStorable(pObj, result);
179 
180  if (!result) {
181  (*m_log) << MSG::ERROR << " Cannot cast to HLTResult " << endmsg ;
182  return StatusCode::FAILURE;
183  }
184 
185  std::string nm = pObj->registry()->name();
186 
187  RawEventWrite* re = m_ByteStreamEventAccess->getRawEvent();
188  // Convert to ByteStream
189  StatusCode sc = m_tool->convert(result, re, nm);
190 
191  if ( pAddr != nullptr ) pAddr->release();
192  ByteStreamAddress* addr = new ByteStreamAddress(classID(), nm, "");
193  pAddr = addr;
194  pAddr->addRef();
195 
196  return sc;
197 
198 }
RawEventWrite
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
Definition: RawEvent.h:39
HLTResultByteStreamTool.h
HLT::HLTResultByteStreamCnv::finalize
virtual StatusCode finalize()
Gaudi finalize.
Definition: HLTResultByteStreamCnv.cxx:55
get_generator_info.result
result
Definition: get_generator_info.py:21
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::fromStorable
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
Definition: StorableConversions.h:180
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
AthenaPoolConverter::storageType
static long storageType()
Definition: AthenaPoolConverter.cxx:156
HLT::HLTResultByteStreamCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
create RDO (HLTResult) from bytestream
Definition: HLTResultByteStreamCnv.cxx:148
SG::asStorable
DataObject * asStorable(T *pObject)
Definition: StorableConversions.h:158
HLTResult.h
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
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
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
HLT::HLTResultByteStreamCnv::storageType
static long storageType()
storageType
Definition: HLTResultByteStreamCnv.cxx:50
ByteStreamAddress.h
HLT::HLTResult
HLT::HLTResult is sumarising result of trigger decision evaluation (online/offline) It contains basic...
Definition: HLTResult.h:57
HLT::HLTResultByteStreamCnv::createRep
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
create bytestream from RDOs (HLTResult)
Definition: HLTResultByteStreamCnv.cxx:174
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
ByteStreamAddress::storageType
static constexpr long storageType()
Definition: ByteStreamAddress.h:51
Converter
Definition: Converter.h:27
HLT::HLTResultByteStreamCnv::classID
static const CLID & classID()
CLID.
Definition: HLTResultByteStreamCnv.cxx:45
HLTResultByteStreamCnv.h
CalibCoolCompareRT.nm
nm
Definition: CalibCoolCompareRT.py:110
re
const boost::regex re(r_e)
DEBUG
#define DEBUG
Definition: page_access.h:11
T_AthenaPoolCustCnv::classID
static const CLID & classID()
ByteStreamCnvSvcBase.h
HLT::HLTResultByteStreamCnv::initialize
virtual StatusCode initialize()
Gaudi initialize.
Definition: HLTResultByteStreamCnv.cxx:65
StoreGateSvc.h
CLASS_DEF.h
macros to associate a CLID to a type
IROBDataProviderSvc.h
HLT::HLTResultByteStreamCnv::HLTResultByteStreamCnv
HLTResultByteStreamCnv(ISvcLocator *svcloc)
std Gaudi converter constructor
Definition: HLTResultByteStreamCnv.cxx:34