2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 #include "ByteStreamCnvSvcBase/ByteStreamCnvSvcBase.h"
6 #include "ByteStreamCnvSvcBase/ByteStreamAddress.h"
7 #include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h"
9 #include "GaudiKernel/MsgStream.h"
10 #include "GaudiKernel/StatusCode.h"
11 #include "GaudiKernel/DataObject.h"
12 #include "GaudiKernel/IRegistry.h"
13 #include "GaudiKernel/IToolSvc.h"
15 #include "StoreGate/StoreGateSvc.h"
16 #include "AthenaKernel/CLASS_DEF.h"
19 template< typename TOOL>
20 CollectionByteStreamCnv< TOOL>::CollectionByteStreamCnv(ISvcLocator* svcloc) :
21 Converter(storageType(), classID(), svcloc), m_robDataProvider(0), m_tool(0)
27 template< typename TOOL>
28 const CLID& CollectionByteStreamCnv<TOOL>::classID(){
29 return ClassID_traits<COLLECTION>::ID() ;
32 template< typename TOOL>
33 long CollectionByteStreamCnv<TOOL>::storageType(){
34 return ByteStreamAddress::storageType();
37 template< typename TOOL>
39 CollectionByteStreamCnv<TOOL>::initialize()
41 StatusCode sc = Converter::initialize();
42 if(StatusCode::SUCCESS!=sc)
47 MsgStream log(msgSvc(), "CollectionByteStreamCnv");
49 log << MSG::DEBUG<< " initialize " <<endmsg;
51 // Get ROBDataProvider
52 sc = service("ROBDataProviderSvc", m_robDataProvider);
53 if(sc != StatusCode::SUCCESS ) {
54 log<<MSG::ERROR << " Cant get ROBDataProviderSvc " <<endmsg;
57 Service* svc = dynamic_cast<Service*>(m_robDataProvider);
59 log<<MSG::DEBUG << " connected to RobDataProvider = " << svc->name() <<endmsg;
61 log<<MSG::ERROR << " Cant cast ROBDataProviderSvc to Service " <<endmsg;
66 if(StatusCode::SUCCESS != service("ToolSvc",toolSvc)){
67 log << MSG::ERROR << " Can't get ToolSvc " << endmsg;
68 return StatusCode::FAILURE;
71 std::string toolType = System::typeinfoName(typeid(TOOL)) ;
72 log << MSG::DEBUG <<" Tool Type = "<<toolType<<endmsg;
73 if(StatusCode::SUCCESS != toolSvc->retrieveTool(toolType,m_tool))
75 log << MSG::ERROR << " Can't get ByteStreamTool " << endmsg;
76 return StatusCode::FAILURE;
79 return StatusCode::SUCCESS;
82 template< typename TOOL>
84 CollectionByteStreamCnv<TOOL>::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) {
85 MsgStream log(msgSvc(), "CollectionByteStreamCnv");
87 ByteStreamAddress *pBS_Addr;
88 pBS_Addr = dynamic_cast<ByteStreamAddress*>(pAddr);
90 log << MSG::ERROR << " Can not cast to ByteStreamAddress " << endmsg ;
91 return StatusCode::FAILURE;
94 const std::string nm = *(pBS_Addr->par()) ;
97 log << MSG::DEBUG<<" Creating Objects "<<nm<<endmsg;
100 const std::vector<uint32_t>& vID = pBS_Addr->getRobIDs();
102 IROBDataProviderSvc::VROBFRAG robFrags ;
103 m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID,robFrags);
105 // make ROBData for the Collection Tools.
106 typedef std::vector<ROBData> VROBDATA ;
108 IROBDataProviderSvc::VROBFRAG::const_iterator it = robFrags.begin();
109 IROBDataProviderSvc::VROBFRAG::const_iterator it_e = robFrags.end();
110 for(; it!=it_e;++it){
111 vRobData.push_back(ROBData((*it)));
115 StatusCode sc = m_tool->convert(vRobData, coll, pBS_Addr->ipar() , log );
116 if(sc != StatusCode::SUCCESS) {
117 log << MSG::ERROR<<" Failed to create Objects "<<nm<<endmsg;
121 pObj = SG::asStorable(coll);
125 template< typename TOOL>
127 CollectionByteStreamCnv<TOOL>::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
130 // Fill RawEvent object from DataObject
133 MsgStream log(msgSvc(), "CollectionByteStreamCnv");
135 std::string nm = pObj->registry()->name();
137 ByteStreamAddress* addr = new
138 ByteStreamAddress(classID(),nm,"");
143 log << MSG::ERROR << " THIS METHOD SHOULD NOT BE CALLED "<< endmsg ;
145 StatusCode sc = StatusCode::FAILURE ;