ATLAS Offline Software
Loading...
Searching...
No Matches
RootCnvSvc.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
7// RootCnvSvc.cxx
8// Implementation file for class Athena::RootCnvSvc
9// Author: Peter van Gemmeren <gemmeren@anl.gov>
10// Author: S.Binet<binet@cern.ch>
12
13// AthenaRootComps includes
14#include "RootCnvSvc.h"
15#include "RootCnv.h"
16#include "RootSvc.h"
17
18// fwk includes
19#include "GaudiKernel/DataObject.h"
20#include "GaudiKernel/GenericAddress.h"
25
26// AthenaRootKernel includes
28
29namespace Athena {
30
31RootCnvSvc::RootCnvSvc(const std::string& name, ISvcLocator* pSvcLocator) :
32 base_class(name, pSvcLocator, ROOT_StorageType),
33 m_dictSvc("AthDictLoaderSvc", name),
34 m_tpCnvSvc("AthTPCnvSvc", name),
35 m_rootSvc("Athena::RootSvc/AthenaRootSvc", name),
36 m_treeName("CollectionTree") {
37}
38
40 ATH_MSG_INFO("Initializing " << name());
41 if (!::AthCnvSvc::initialize().isSuccess()) {
42 ATH_MSG_FATAL("Cannot initialize ConversionSvc base class.");
43 return StatusCode::FAILURE;
44 }
45 // Get the Dictionary service
46 ATH_CHECK(m_dictSvc.retrieve());
47 // Get the T/P conversion service
48 ATH_CHECK(m_tpCnvSvc.retrieve());
49 // Get the Root service
50 ATH_CHECK(m_rootSvc.retrieve());
51 return StatusCode::SUCCESS;
52}
53
55 return ::AthCnvSvc::finalize();
56}
57
59StatusCode RootCnvSvc::connectOutput(const std::string& file, const std::string& mode) {
60 std::string fileName = file;
61 std::string::size_type inx1 = file.find('(');
62 if (inx1 != std::string::npos) {
63 std::string::size_type inx2 = file.find(')');
64 if (inx2 == std::string::npos || inx2 != file.size() - 1) {
65 return StatusCode::FAILURE;
66 }
67 m_treeName = fileName.substr(inx1 + 1, inx2 - inx1 - 1);
68 fileName.resize(inx1);//already checked that inx1!=npos
69 }
70 if (!m_rootSvc->open(fileName, mode).isSuccess()) {
71 ATH_MSG_ERROR("Could not open-recreate file [" << file << "]");
72 return StatusCode::FAILURE;
73 }
74 return this->connectOutput(fileName);
75}
76
78StatusCode RootCnvSvc::connectOutput(const std::string& file) {
79 return m_rootSvc->connect(file);
80}
81
83StatusCode RootCnvSvc::commitOutput(const std::string& /*file*/, bool /*do_commit*/) {
84 return m_rootSvc->commitOutput();
85}
86
87StatusCode RootCnvSvc::createAddress(long svc_type,
88 const CLID& clid,
89 const std::string* par,
90 const unsigned long* ip,
91 IOpaqueAddress*& refpAddress) {
92 ATH_MSG_VERBOSE("RootCnvSvc::createAddress("
93 << "svc_type=" << svc_type << ", "
94 << "clid=" << clid << ", "
95 << "par=" << par[0] << ", " << par[1] << " "
96 << "ip=" << ip[0] << ", " << ip[1] << " "
97 << "refpaddr=" << refpAddress << ")");
98 refpAddress = new GenericAddress(ROOT_StorageType, clid, par[0], par[1], ip[0], ip[1]);
99 return StatusCode::SUCCESS;
100}
101
102StatusCode RootCnvSvc::convertAddress(const IOpaqueAddress* pAddress, std::string& refAddress) {
103 ATH_MSG_VERBOSE("::convertAddress(pAddr = " << pAddress << ", refPaddr = " << refAddress << ")");
104 return StatusCode::FAILURE;
105}
106
107StatusCode RootCnvSvc::createAddress(long svc_type,
108 const CLID& clid,
109 const std::string& refAddress,
110 IOpaqueAddress*& refpAddress) {
111 ATH_MSG_VERBOSE("RootCnvSvc::createAddress("
112 << "svc_type=" << svc_type << ", "
113 << "clid=" << clid << ", "
114 << "refaddr=" << refAddress << ", "
115 << "refpaddr=" << refpAddress << ")");
116
117 return StatusCode::FAILURE;
118}
119
120StatusCode RootCnvSvc::updateServiceState(IOpaqueAddress* pAddress) {
121 ATH_MSG_VERBOSE("RootCnvSvc::updateServiceState(paddr = " << pAddress << ")");
122 return StatusCode::FAILURE;
123}
124
128 return m_dictSvc->load_type(clid);
129}
130
131RootType RootCnvSvc::getType(const std::type_info& type) const {
132 return m_dictSvc->load_type(type);
133}
134
136const Token* RootCnvSvc::writeObject(const std::string& key,
137 const RootType& typeDesc,
138 const void* pObj,
139 ITPCnvBase* tpConverter) {
140 const Token* token = 0;
141 Placement placement;
142 placement.setContainerName(m_treeName + "(" + key + ")");
143 placement.setTechnology(ROOT_StorageType);
144 if (tpConverter == 0) {
145 token = m_rootSvc->writeObject(placement, typeDesc, pObj);
146 } else {
147 void* pers = m_rootSvc->createObject(typeDesc);
148 tpConverter->transToPersUntyped(pObj, pers, this->msg());
149 token = m_rootSvc->writeObject(placement, typeDesc, pers);
150 m_rootSvc->destructObject(typeDesc, pers); pers = 0;
151 }
152 return token;
153}
154
156 ATH_MSG_VERBOSE("RootCnvSvc::getTPConverter clid = " << clid);
157 return m_tpCnvSvc->t2p_cnv(clid);
158}
159
160
161IConverter* RootCnvSvc::createConverter(long typ, const CLID& clid, const ICnvFactory* fac) {
162 ATH_MSG_VERBOSE("createConverter typ = " << typ << ", clid = " << clid);
163 if (typ == ROOT_StorageType) {
164 return new Athena::RootCnv(clid, serviceLocator().get());
165 }
166 return ::AthCnvSvc::createConverter(typ, clid, fac);
167}
168
169} //> end namespace Athena
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
uint32_t CLID
The Class ID type.
This file contains the class definition for the IRootSvc interface class.
This file contains the class definition for the Placement class (migrated from POOL).
This file contains the class definition for the Athena::RootCnv class.
This file contains the class definition for the RootSvc class.
TTypeAdapter RootType
Definition RootType.h:211
virtual StatusCode initialize() override
Gaudi Service Implementation.
ServiceHandle< ::ITPCnvSvc > m_tpCnvSvc
ServiceHandle to the T/P conversion service.
Definition RootCnvSvc.h:104
ITPCnvBase * getTPConverter(const CLID &clid) const
Get T/P converter for a transient class.
IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new converter using factory.
RootCnvSvc()
Default constructor:
StatusCode commitOutput(const std::string &output, bool do_commit)
Commit pending output.
StatusCode updateServiceState(IOpaqueAddress *pAddress)
Update state of the service.
StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
Create a Generic address using explicit arguments to identify a single object.
StatusCode finalize()
ServiceHandle< ::IDictLoaderSvc > m_dictSvc
ServiceHandle to the dictionary service.
Definition RootCnvSvc.h:102
StatusCode connectOutput(const std::string &file)
Connect the output file to the service.
ServiceHandle< ::IRootSvc > m_rootSvc
ServiceHandle to the root service.
Definition RootCnvSvc.h:106
std::string m_treeName
ROOT TTree name.
Definition RootCnvSvc.h:109
RootType getType(const CLID &clid) const
const Token * writeObject(const std::string &key, const RootType &typeDesc, const void *pObj, ITPCnvBase *tpConverter=0)
Write object of a given class to Root, using optional T/P converter.
StatusCode initialize()
Gaudi Service Interface method implementations:
StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress)
Convert an address to string form.
This class provides the abstract converter to translate an object to/from its persistent ROOT represe...
Definition RootCnv.h:37
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &msg)=0
Convert transient object representation to persistent.
This class holds all the necessary information to guide the writing of an object in a physical place.
Definition Placement.h:19
Placement & setContainerName(const std::string &containerName)
Set container name.
Definition Placement.h:34
Placement & setTechnology(int technology)
Set technology type.
Definition Placement.h:38
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:21
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
MsgStream & msg
Definition testRead.cxx:32
TFile * file