ATLAS Offline Software
CollectionByteStreamCnv.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ByteStreamCnvSvcBase/ByteStreamCnvSvcBase.h"
6 #include "ByteStreamCnvSvcBase/ByteStreamAddress.h"
7 #include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h"
8 
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"
14 
15 #include "StoreGate/StoreGateSvc.h"
16 #include "AthenaKernel/CLASS_DEF.h"
17 #include <algorithm>
18 
19 template< typename TOOL>
20 CollectionByteStreamCnv< TOOL>::CollectionByteStreamCnv(ISvcLocator* svcloc) :
21  Converter(storageType(), classID(), svcloc), m_robDataProvider(0), m_tool(0)
22 {
23 
24 
25 }
26 
27 template< typename TOOL>
28 const CLID& CollectionByteStreamCnv<TOOL>::classID(){
29  return ClassID_traits<COLLECTION>::ID() ;
30 }
31 
32 template< typename TOOL>
33 long CollectionByteStreamCnv<TOOL>::storageType(){
34  return ByteStreamAddress::storageType();
35 }
36 
37 template< typename TOOL>
38 StatusCode
39 CollectionByteStreamCnv<TOOL>::initialize()
40 {
41  StatusCode sc = Converter::initialize();
42  if(StatusCode::SUCCESS!=sc)
43  {
44  return sc;
45  }
46 
47  MsgStream log(msgSvc(), "CollectionByteStreamCnv");
48 
49  log << MSG::DEBUG<< " initialize " <<endmsg;
50 
51  // Get ROBDataProvider
52  sc = service("ROBDataProviderSvc", m_robDataProvider);
53  if(sc != StatusCode::SUCCESS ) {
54  log<<MSG::ERROR << " Cant get ROBDataProviderSvc " <<endmsg;
55  return sc ;
56  } else {
57  Service* svc = dynamic_cast<Service*>(m_robDataProvider);
58  if (svc != 0) {
59  log<<MSG::DEBUG << " connected to RobDataProvider = " << svc->name() <<endmsg;
60  } else {
61  log<<MSG::ERROR << " Cant cast ROBDataProviderSvc to Service " <<endmsg;
62  }
63  }
64 
65  IToolSvc* toolSvc;
66  if(StatusCode::SUCCESS != service("ToolSvc",toolSvc)){
67  log << MSG::ERROR << " Can't get ToolSvc " << endmsg;
68  return StatusCode::FAILURE;
69  }
70 
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))
74  {
75  log << MSG::ERROR << " Can't get ByteStreamTool " << endmsg;
76  return StatusCode::FAILURE;
77  }
78 
79  return StatusCode::SUCCESS;
80 }
81 
82 template< typename TOOL>
83 StatusCode
84 CollectionByteStreamCnv<TOOL>::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) {
85  MsgStream log(msgSvc(), "CollectionByteStreamCnv");
86 
87  ByteStreamAddress *pBS_Addr;
88  pBS_Addr = dynamic_cast<ByteStreamAddress*>(pAddr);
89  if(!pBS_Addr) {
90  log << MSG::ERROR << " Can not cast to ByteStreamAddress " << endmsg ;
91  return StatusCode::FAILURE;
92  }
93 
94  const std::string nm = *(pBS_Addr->par()) ;
95 
96 #ifndef NDEBUG
97  log << MSG::DEBUG<<" Creating Objects "<<nm<<endmsg;
98 #endif
99 
100  const std::vector<uint32_t>& vID = pBS_Addr->getRobIDs();
101 
102  IROBDataProviderSvc::VROBFRAG robFrags ;
103  m_robDataProvider->getROBData(vID,robFrags);
104 
105  // make ROBData for the Collection Tools.
106  typedef std::vector<ROBData> VROBDATA ;
107  VROBDATA 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)));
112  }
113 
114  COLLECTION* coll ;
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;
118  return sc;
119  }
120 
121  pObj = SG::asStorable(coll);
122  return sc;
123 }
124 
125 template< typename TOOL>
126 StatusCode
127 CollectionByteStreamCnv<TOOL>::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
128 {
129  //
130  // Fill RawEvent object from DataObject
131  //
132 
133  MsgStream log(msgSvc(), "CollectionByteStreamCnv");
134 
135  std::string nm = pObj->registry()->name();
136 
137  ByteStreamAddress* addr = new
138  ByteStreamAddress(classID(),nm,"");
139 
140  pAddr = addr;
141 
142 
143  log << MSG::ERROR << " THIS METHOD SHOULD NOT BE CALLED "<< endmsg ;
144 
145  StatusCode sc = StatusCode::FAILURE ;
146  return sc;
147 }
148 
149