ATLAS Offline Software
LeafCnv.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // LeafCnv.cxx
8 // Implementation file for class LeafCnv
9 // Author: S.Binet<binet@cern.ch>
11 
12 // AthenaRootComps includes
13 #include "LeafCnv.h"
14 #include "RootBranchAddress.h"
15 #include "RootDataBucketBranch.h"
16 
17 // STL includes
18 #include <sstream>
19 #include <typeinfo>
20 #include <stdexcept>
21 
22 // framework
23 #include "GaudiKernel/DataObject.h"
24 //#include "GaudiKernel/GenericAddress.h"
25 #include "GaudiKernel/ServiceHandle.h"
26 #include "GaudiKernel/System.h"
29 
30 // ROOT
31 #include "TBranch.h"
33 #include "TLeaf.h"
34 #include "TTree.h"
35 
36 namespace {
37  std::string name_from_clid (const CLID clid)
38  {
39  std::ostringstream o;
40  o << "AthenaRootLeafCnv_" << clid;
41  return o.str();
42  }
43 }
44 
45 namespace Athena {
46 
48 // Public methods:
50 
51 // Constructors
53 LeafCnv::LeafCnv( const CLID& clid,
54  ISvcLocator* pSvcLocator ) :
55  ::Converter( ROOT_StorageType, clid, pSvcLocator ),
56  ::AthMessaging( msgSvc(), name_from_clid(clid) ),
57  m_type()
58 {
59  //
60  // Property declaration
61  //
62  //declareProperty( "Property", m_nProperty );
63 
64 }
65 
66 LeafCnv::LeafCnv( ISvcLocator* pSvcLocator ) :
67  ::Converter ( ROOT_StorageType, CLID_NULL, pSvcLocator ),
68  ::AthMessaging( msgSvc(), name_from_clid(CLID_NULL) ),
69  m_type()
70 {
71  //
72  // Property declaration
73  //
74  //declareProperty( "Property", m_nProperty );
75 
76 }
77 
78 // Destructor
81 {
82  ATH_MSG_DEBUG("Calling destructor");
83 }
84 
85 // Athena Service's Hooks
88 {
89  // configure our MsgStream
90  msg().setLevel( MSG::INFO );
91 
92  ATH_MSG_DEBUG("Initializing LeafCnv...");
93 
94  ATH_MSG_DEBUG("Initializing base class...");
95  if ( ::Converter::initialize().isFailure() ) {
96  ATH_MSG_ERROR("Could not intialize base class !!");
97  return StatusCode::FAILURE;
98  } else {
99  ATH_MSG_VERBOSE("Base class initialized");
100  }
101 
102  // retrieve the dict-loader-svc
103  typedef ServiceHandle<IDictLoaderSvc> IDictLoaderSvc_t;
104  IDictLoaderSvc_t dictSvc("AthDictLoaderSvc",
105  "Athena::LeafCnv");
106  // name_from_clid(objType()));
107  if ( !dictSvc.retrieve().isSuccess() ) {
108  ATH_MSG_ERROR("could not retrieve [" << dictSvc.typeAndName() << "] !");
109  return StatusCode::FAILURE;
110  }
111 
112  RootType ty = dictSvc->load_type(this->objType());
113  ATH_MSG_VERBOSE("loaded dictionary for clid ["
114  << this->objType() << "]: name=["
115  << ty.Name() << "]");
116  m_type = ty;
117 
118  ATH_MSG_DEBUG("converter correctly initialized - clid=[" << objType() << "]");
119  return StatusCode::SUCCESS;
120 }
121 
123 // Const methods:
125 
126 long
128 {
129  return ROOT_StorageType;
130 }
131 
133 // Non-const methods:
135 
139 StatusCode
140 LeafCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
141 {
142  ATH_MSG_DEBUG("::createObj(" << pAddr << ", " << pObj << ")");
143  Athena::RootBranchAddress *rba = dynamic_cast<Athena::RootBranchAddress*>(pAddr);
144  if (!rba) {
145  ATH_MSG_DEBUG(*pAddr->par() << " is NOT a GenericAddress!");
146  return StatusCode::FAILURE;
147  }
148  ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
149  << "/" << rba->par()[1] << "]...");
150  rba->setBranchAddress(m_type);
151  ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
152  << "/" << rba->par()[1] << "]... [done]");
153  Athena::DataBucketBranch *dbb = new DataBucketBranch(rba->clID(), rba->m_type, rba->m_ptr);
154  pObj = dbb;
155  return StatusCode::SUCCESS;
156 }
157 
161 StatusCode
162 LeafCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
163 {
164  ATH_MSG_INFO("::createRep(" << pObj << ", " << pAddr << ")");
165  if (0==pObj) {
166  ATH_MSG_ERROR("::createRep: received null ptr to dobj");
167  return StatusCode::FAILURE;
168  }
169  msg(MSG::INFO) << " -> clid: [" << pObj->clID() << "]" << endmsg
170  << " -> name: [" << pObj->name() << "]" << endmsg;
171 
172  /*
173  Athena::DataBucketBranch *dbb = 0;
174  dbb = dynamic_cast<Athena::DataBucketBranch*>(pObj);
175  if (!dbb) {
176  ATH_MSG_INFO("dataobject at [" << pObj->name() << "] is not"
177  << " a DataBucketBranch ! [clid=" << pObj->clID() << "]");
178  return StatusCode::FAILURE;
179  }
180  */
181 
182  // FIXME:
183  // Athena::RootBranchAddress* addr = new Athena::RootBranchAddress
184  // (ROOT_StorageType,
185  // dbb->clID(),
186  // m_tupleName.value(),
187  // br_name,
188  // (unsigned long)(value_ptr),
189  // (unsigned long)(m_nbrEvts-1));
190 #if 1
191  GenericAddress* addr = new GenericAddress(ROOT_StorageType,
192  pObj->clID(),
193  pObj->name());
194 #else
196  (ROOT_StorageType, id,
197  "foo",//m_tupleName.value(),
198  dbb->name(),
199  (unsigned long)(value_ptr),
200  (unsigned long)(m_nbrEvts-1));
201 #endif
202  pAddr = addr;
203  return StatusCode::SUCCESS;
204 }
205 
206 long
208 {
209  return ROOT_StorageType;
210 }
211 
213 // Const methods:
215 
217 // Non-const methods:
219 
221 // Protected methods:
223 
224 } //> end namespace Athena
RootDataBucketBranch.h
Athena::RootBranchAddress
Definition: RootBranchAddress.h:33
Athena::RootBranchAddress::m_type
RootType m_type
the buffer for the TBranch
Definition: RootBranchAddress.h:88
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LeafCnv.h
DataBucketBase.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
Athena::LeafCnv::storageType
static long storageType()
Definition: LeafCnv.cxx:207
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
Athena::LeafCnv::repSvcType
long repSvcType() const
Definition: LeafCnv.cxx:127
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
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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::RootBranchAddress::setBranchAddress
void setBranchAddress(const RootType &t)
setup the ROOT TTree internal address for the branch.
Definition: RootBranchAddress.cxx:93
Athena::LeafCnv::LeafCnv
LeafCnv(const CLID &clid, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: LeafCnv.cxx:53
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
TScopeAdapter::Name
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition: RootType.cxx:607
Athena::LeafCnv::~LeafCnv
virtual ~LeafCnv()
Destructor:
Definition: LeafCnv.cxx:80
Converter
Definition: Converter.h:27
Athena::LeafCnv::m_type
RootType m_type
the type we can convert
Definition: LeafCnv.h:89
Athena::DataBucketBranch
Definition: RootDataBucketBranch.h:26
RootBranchAddress.h
IDictLoaderSvc.h
Athena::LeafCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Create a transient object from a persistent representation.
Definition: LeafCnv.cxx:140
TBranchElementClang.h
Include TBranchElement.h, suppressing clang warnings.
Athena::LeafCnv::initialize
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition: LeafCnv.cxx:87
Athena::RootBranchAddress::m_ptr
void * m_ptr
Definition: RootBranchAddress.h:89
Athena::LeafCnv::createRep
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Create a persistent representation for a transient object.
Definition: LeafCnv.cxx:162
ServiceHandle< IDictLoaderSvc >
TScopeAdapter
Definition: RootType.h:119