ATLAS Offline Software
RootCnv.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // RootCnv.cxx
8 // Implementation file for class Athena::RootCnv
9 // Author: Peter van Gemmeren <gemmeren@anl.gov>
10 // Author: S.Binet<binet@cern.ch>
12 
13 // AthenaRootComps includes
14 #include "RootCnv.h"
15 
16 // AthenaRootKernel includes
19 
20 // stl includes
21 #include <string>
22 
23 // fwk includes
24 #include "GaudiKernel/DataObject.h"
25 #include "GaudiKernel/IOpaqueAddress.h"
26 #include "GaudiKernel/IRegistry.h"
32 
33 
34 namespace {
35  std::string name_from_clid(const CLID clid) {
36  std::ostringstream o;
37  o << "AthenaRootCnv_" << clid;
38  return o.str();
39  }
40 }
41 
42 namespace Athena {
43 
44 RootCnv::RootCnv(const CLID& id, ISvcLocator* pSvcLocator) : ::Converter(ROOT_StorageType, id, pSvcLocator),
45  ::AthMessaging((pSvcLocator != 0 ? msgSvc() : 0), ::name_from_clid(id)),
46  m_cnvSvc("Athena::RootCnvSvc/AthenaRootCnvSvc", ::name_from_clid(id)),
47  m_ttype(),
48  m_ptype(),
49  m_tpcnv(0) {
50 }
51 
52 RootCnv::RootCnv(ISvcLocator* pSvcLocator) : ::Converter(ROOT_StorageType, CLID_NULL, pSvcLocator),
53  ::AthMessaging( msgSvc(), ::name_from_clid(CLID_NULL)),
54  m_cnvSvc("Athena::RootCnvSvc/AthenaRootCnvSvc", ::name_from_clid(CLID_NULL)),
55  m_ttype(),
56  m_ptype(),
57  m_tpcnv(0) {
58 }
59 
61 }
62 
64  if (!::Converter::initialize().isSuccess()) {
65  ATH_MSG_FATAL("Cannot initialize Converter base class.");
66  return StatusCode::FAILURE;
67  }
68  // Get the AthenaRootCnvSvc
69  ATH_CHECK(m_cnvSvc.retrieve());
70  CLID clid = this->objType();
71  m_tpcnv = m_cnvSvc->getTPConverter(clid);
72  if (!m_ttype) {
73  m_ttype = m_cnvSvc->getType(clid);
74  }
75  if (!m_ptype) {
76  if (m_tpcnv == 0) {
77  // only warn if not a builtin
78  if (!m_ttype.IsFundamental()) {
79  ATH_MSG_INFO("Cannot get T/P converter, will write transient type [" << m_ttype.Name() << ", clid = " << clid << "]");
80  }
81  m_ptype = m_cnvSvc->getType(clid);
82  } else {
83  m_ptype = m_cnvSvc->getType(m_tpcnv->persistentTInfo());
84  }
85  if (!m_ptype) {
86  ATH_MSG_ERROR("Cannot get RootType for DataObject.");
87  return StatusCode::FAILURE;
88  }
89  }
90  return StatusCode::SUCCESS;
91 }
92 
95 }
96 
97 long RootCnv::repSvcType() const {
98  return ROOT_StorageType;
99 }
100 
102  return ROOT_StorageType;
103 }
104 
105 StatusCode RootCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) {
106  ATH_MSG_DEBUG("createObj(" << pAddr << ", " << pObj << ")");
107  /*
108  Athena::RootBranchAddress* rba = dynamic_cast<Athena::RootBranchAddress*>(pAddr);
109  if (!rba) {
110  ATH_MSG_DEBUG(*pAddr->par() << " is NOT a GenericAddress!");
111  return StatusCode::FAILURE;
112  }
113  ATH_MSG_DEBUG("loading branch: [" << rba->par()[0] << "/" << rba->par()[1] << "]...");
114  rba->setBranchAddress(m_type);
115  ATH_MSG_DEBUG("loading branch: [" << rba->par()[0] << "/" << rba->par()[1] << "]... [done]");
116  Athena::DataBucketBranch* dbb = new DataBucketBranch(rba->clID(), rba->m_ptr);
117  pObj = dbb;
118  return StatusCode::SUCCESS;
119  */
120  return StatusCode::FAILURE;
121 }
122 
123 StatusCode RootCnv::fillObjRefs(IOpaqueAddress* pAddr, DataObject* pObj) {
124  ATH_MSG_VERBOSE("fillObjRefs(pAddr = " << pAddr << ", " << "pObj = " << pObj << ")...");
125  return StatusCode::FAILURE;
126 }
127 
128 StatusCode RootCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr) {
129  ATH_MSG_VERBOSE("createRep pObj = " << pObj);
130  pAddr = 0;
131  if (pObj == 0) {
132  ATH_MSG_ERROR("createRep called without DataObject.");
133  return StatusCode::FAILURE;
134  }
135  CLID clid = pObj->clID();
136  IRegistry* pR = pObj->registry();
137  if (pR == 0) {
138  ATH_MSG_ERROR("createRep no registry for DataObject.");
139  return StatusCode::FAILURE;
140  }
141  std::string p[2] = { "", pR->identifier() };
142  unsigned long ip[2] = { 0, 0 };
143  void* trans = SG::fromStorable(pObj, clid);
144  ATH_MSG_DEBUG("writing [" << objType() << "/" << p[1] << "]");
145  ATH_MSG_DEBUG("p-type: [" << m_ptype.Name() << "]");
146  std::unique_ptr<const Token> token (m_cnvSvc->writeObject(p[1], m_ptype, trans, m_tpcnv));
147  if (token == 0 || !m_cnvSvc->createAddress(this->repSvcType(), clid, p, ip, pAddr).isSuccess()) {
148  ATH_MSG_ERROR("problem creating opaque address");
149  return StatusCode::FAILURE;
150  }
151  ATH_MSG_DEBUG("writing [" << objType() << "/" << p[1] << "] [done], entry = " << ip[0]);
152  return StatusCode::SUCCESS;
153 }
154 
155 StatusCode RootCnv::fillRepRefs(IOpaqueAddress* pAddr, DataObject* pObj) {
156  ATH_MSG_VERBOSE("fillRepRefs(pAddr = " << pAddr << ", " << "pObj = " << pObj << ")...");
157  return StatusCode::FAILURE;
158 }
159 
160 } //< end namespace Athena
Athena::RootCnv::initialize
virtual StatusCode initialize()
Gaudi Service Interface method implementations:
Definition: RootCnv.cxx:63
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Athena::RootCnv::m_ttype
RootType m_ttype
transient type
Definition: RootCnv.h:93
AthCheckMacros.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::fromStorable
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
Definition: StorableConversions.h:167
StorableConversions.h
convert to and from a SG storable
initialize
void initialize()
Definition: run_EoverP.cxx:894
RootCnv.h
This file contains the class definition for the Athena::RootCnv class.
Athena::RootCnv::~RootCnv
virtual ~RootCnv()
Destructor.
Definition: RootCnv.cxx:60
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ITPCnvBase.h
Athena::RootCnv::m_cnvSvc
ServiceHandle< ::IAthenaRootCnvSvc > m_cnvSvc
ServiceHandle to the conversion service.
Definition: RootCnv.h:89
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
Athena::RootCnv::fillObjRefs
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Resolve the references of the created transient object.
Definition: RootCnv.cxx:123
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Athena::RootCnv::createRep
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Create a ROOT persistent representation for a transient object.
Definition: RootCnv.cxx:128
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
TScopeAdapter::Name
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition: RootType.cxx:607
Athena::RootCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Create a transient object from a ROOT persistent representation.
Definition: RootCnv.cxx:105
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
Converter
Definition: Converter.h:27
Athena::RootCnv::m_ptype
RootType m_ptype
persistent type
Definition: RootCnv.h:96
TScopeAdapter::IsFundamental
Bool_t IsFundamental() const
Definition: RootType.cxx:726
Athena::RootCnv::repSvcType
long repSvcType() const
Retrieve the class type of the data store the converter uses.
Definition: RootCnv.cxx:97
IRootSvc.h
This file contains the class definition for the IRootSvc interface class.
ITPCnvBase::persistentTInfo
virtual const std::type_info & persistentTInfo() const =0
return C++ type id of the persistent class this converter is for
Athena::RootCnv::storageType
static long storageType()
Definition: RootCnv.cxx:101
IAthenaRootCnvSvc.h
This file contains the class definition for the IAthenaRootCnvSvc interface class.
Placement.h
This file contains the class definition for the Placement class (migrated from POOL).
Athena::RootCnv::finalize
virtual StatusCode finalize()
Definition: RootCnv.cxx:93
Athena::RootCnv::m_tpcnv
ITPCnvBase * m_tpcnv
Definition: RootCnv.h:98
Token.h
This file contains the class definition for the Token class (migrated from POOL).
Athena::RootCnv::RootCnv
RootCnv()
Default constructor:
Athena::RootCnv::fillRepRefs
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Resolve the references of the created transient object.
Definition: RootCnv.cxx:155