ATLAS Offline Software
TBDataCnv.icc
Go to the documentation of this file.
1 //Dear emacs, this is -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #include "GaudiKernel/MsgStream.h"
8 #include "ByteStreamCnvSvcBase/ByteStreamAddress.h"
9 
10 #include <string>
11 
12 template< class DATATYPE >
13 TBDataCnv<DATATYPE>::TBDataCnv(ISvcLocator* svcloc) :
14  Converter(storageType(), classID(),svcloc),
15  m_tool(nullptr)
16 {
17 }
18 
19 template< class DATATYPE >
20 const CLID& TBDataCnv<DATATYPE>::classID(){
21  return ClassID_traits<DATATYPE>::ID() ;
22 }
23 
24 template< class DATATYPE >
25 long TBDataCnv<DATATYPE>::storageType(){
26  return ByteStreamAddress::storageType() ;
27 }
28 
29 template< class DATATYPE >
30 StatusCode TBDataCnv<DATATYPE>::initialize()
31 {StatusCode sc = Converter::initialize();
32  if (sc!=StatusCode::SUCCESS)
33  return sc;
34  MsgStream logstr(msgSvc(), "TBDataCnv");
35  IToolSvc* toolSvc;
36  sc=service("ToolSvc",toolSvc);
37  if(sc!=StatusCode::SUCCESS)
38  {logstr << MSG::ERROR << " Can't get ToolSvc " << endmsg;
39  return sc;
40  }
41  sc=toolSvc->retrieveTool("TBByteStreamCnvTool",m_tool);
42  if(sc!=StatusCode::SUCCESS)
43  {logstr << MSG::ERROR << " Can't get TBByteStreamCnvTool" << endmsg;
44  return sc;
45  }
46  return StatusCode::SUCCESS;
47 }
48 
49 template< class DATATYPE >
50 StatusCode TBDataCnv<DATATYPE>::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
51 { MsgStream logstr(msgSvc(), "TBDataCnv");
52  ByteStreamAddress *pRE_Addr;
53  pRE_Addr = dynamic_cast<ByteStreamAddress*>(pAddr); //Cast from OpaqueAddress to ByteStreamAddress
54  if (!pRE_Addr)
55  {logstr << MSG::ERROR << "dynamic_cast of IOpaqueAdress to ByteStreamAddress failed!" << endmsg;
56  return StatusCode::FAILURE;
57  }
58  DATATYPE* tbdata = 0;
59  const std::string& key = *(pAddr->par()); // Get key used in the
60  // StoreGateSvc::retrieve function
61  StatusCode sc=m_tool->ReadFragment(tbdata,key);
62  if (sc!=StatusCode::SUCCESS) {
63  delete tbdata;
64  return sc;
65  }
66  pObj = SG::asStorable(tbdata) ;
67  return StatusCode::SUCCESS;
68 }
69 
70 template< class DATATYPE >
71 StatusCode TBDataCnv<DATATYPE>::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
72 {
73  std::string nm = pObj->registry()->name();
74  ByteStreamAddress* addr = new ByteStreamAddress(classID(),nm,"");
75  pAddr = addr;
76 
77  return m_tool->WriteFragment();
78 
79 }