ATLAS Offline Software
LeafCnv.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 // 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 
122 // StatusCode LeafCnv::finalize()
123 // {
124 // m_msg << MSG::INFO
125 // << "Finalizing " << name() << "..."
126 // << endmsg;
127 
128 // return StatusCode::SUCCESS;
129 // }
130 
131 // Query the interfaces.
132 // Input: riid, Requested interface ID
133 // ppvInterface, Pointer to requested interface
134 // Return: StatusCode indicating SUCCESS or FAILURE.
135 // N.B. Don't forget to release the interface after use!!!
136 // StatusCode
137 // LeafCnv::queryInterface(const InterfaceID& riid, void** ppvInterface)
138 // {
139 // if ( IConverter::interfaceID().versionMatch(riid) ) {
140 // *ppvInterface = dynamic_cast<IConverter*>(this);
141 // } else {
142 // // Interface is not directly available : try out a base class
143 // return ::Service::queryInterface(riid, ppvInterface);
144 // }
145 // addRef();
146 // return StatusCode::SUCCESS;
147 // }
148 
150 // Const methods:
152 
153 long
155 {
156  return ROOT_StorageType;
157 }
158 
160 // Non-const methods:
162 
166 StatusCode
167 LeafCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
168 {
169  ATH_MSG_DEBUG("::createObj(" << pAddr << ", " << pObj << ")");
170  Athena::RootBranchAddress *rba = dynamic_cast<Athena::RootBranchAddress*>(pAddr);
171  if (!rba) {
172  ATH_MSG_DEBUG(*pAddr->par() << " is NOT a GenericAddress!");
173  return StatusCode::FAILURE;
174  }
175  ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
176  << "/" << rba->par()[1] << "]...");
177  rba->setBranchAddress(m_type);
178  ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
179  << "/" << rba->par()[1] << "]... [done]");
180  Athena::DataBucketBranch *dbb = new DataBucketBranch(rba->clID(), rba->m_type, rba->m_ptr);
181  pObj = dbb;
182  return StatusCode::SUCCESS;
183 }
184 
188 StatusCode
189 LeafCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
190 {
191  ATH_MSG_INFO("::createRep(" << pObj << ", " << pAddr << ")");
192  if (0==pObj) {
193  ATH_MSG_ERROR("::createRep: received null ptr to dobj");
194  return StatusCode::FAILURE;
195  }
196  msg(MSG::INFO) << " -> clid: [" << pObj->clID() << "]" << endmsg
197  << " -> name: [" << pObj->name() << "]" << endmsg;
198 
199  /*
200  Athena::DataBucketBranch *dbb = 0;
201  dbb = dynamic_cast<Athena::DataBucketBranch*>(pObj);
202  if (!dbb) {
203  ATH_MSG_INFO("dataobject at [" << pObj->name() << "] is not"
204  << " a DataBucketBranch ! [clid=" << pObj->clID() << "]");
205  return StatusCode::FAILURE;
206  }
207  */
208 
209  // FIXME:
210  // Athena::RootBranchAddress* addr = new Athena::RootBranchAddress
211  // (ROOT_StorageType,
212  // dbb->clID(),
213  // m_tupleName.value(),
214  // br_name,
215  // (unsigned long)(value_ptr),
216  // (unsigned long)(m_nbrEvts-1));
217 #if 1
218  GenericAddress* addr = new GenericAddress(ROOT_StorageType,
219  pObj->clID(),
220  pObj->name());
221 #else
223  (ROOT_StorageType, id,
224  "foo",//m_tupleName.value(),
225  dbb->name(),
226  (unsigned long)(value_ptr),
227  (unsigned long)(m_nbrEvts-1));
228 #endif
229  pAddr = addr;
230  return StatusCode::SUCCESS;
231 }
232 
233 long
235 {
236  return ROOT_StorageType;
237 }
238 
240 // Const methods:
242 
244 // Non-const methods:
246 
248 // Protected methods:
250 
251 } //> 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:234
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:154
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:91
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:167
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:189
ServiceHandle< IDictLoaderSvc >
TScopeAdapter
Definition: RootType.h:119