ATLAS Offline Software
TBDataCnv.icc
Go to the documentation of this file.
1 //Dear emacs, this is -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2024 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  SmartIF<IToolSvc> toolSvc{service("ToolSvc")};
36  ATH_CHECK( toolSvc.isValid() );
37 
38  ATH_CHECK( toolSvc->retrieveTool("TBByteStreamCnvTool",m_tool) );
39 
40  return StatusCode::SUCCESS;
41 }
42 
43 template< class DATATYPE >
44 StatusCode TBDataCnv<DATATYPE>::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
45 { MsgStream logstr(msgSvc(), "TBDataCnv");
46  ByteStreamAddress *pRE_Addr;
47  pRE_Addr = dynamic_cast<ByteStreamAddress*>(pAddr); //Cast from OpaqueAddress to ByteStreamAddress
48  if (!pRE_Addr)
49  {logstr << MSG::ERROR << "dynamic_cast of IOpaqueAdress to ByteStreamAddress failed!" << endmsg;
50  return StatusCode::FAILURE;
51  }
52  DATATYPE* tbdata = 0;
53  const std::string& key = *(pAddr->par()); // Get key used in the
54  // StoreGateSvc::retrieve function
55  StatusCode sc=m_tool->ReadFragment(tbdata,key);
56  if (sc!=StatusCode::SUCCESS) {
57  delete tbdata;
58  return sc;
59  }
60  pObj = SG::asStorable(tbdata) ;
61  return StatusCode::SUCCESS;
62 }
63 
64 template< class DATATYPE >
65 StatusCode TBDataCnv<DATATYPE>::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
66 {
67  std::string nm = pObj->registry()->name();
68  ByteStreamAddress* addr = new ByteStreamAddress(classID(),nm,"");
69  pAddr = addr;
70 
71  return m_tool->WriteFragment();
72 
73 }