ATLAS Offline Software
RootCnvSvc.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 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"
23 #include "AthenaKernel/ITPCnvSvc.h"
25 
26 // AthenaRootKernel includes
28 
29 namespace Athena {
30 
31 RootCnvSvc::RootCnvSvc(const std::string& name, ISvcLocator* pSvcLocator) :
32  ::AthCnvSvc(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 
56 }
57 
58 StatusCode RootCnvSvc::queryInterface(const InterfaceID& riid, void** ppvInterface) {
59  if (IAthenaRootCnvSvc::interfaceID().versionMatch(riid)) {
60  *ppvInterface = dynamic_cast<IAthenaRootCnvSvc*>(this);
61  } else {
62  // Interface is not directly available: try out a base class
63  return ::AthCnvSvc::queryInterface(riid, ppvInterface);
64  }
65  addRef();
66  return StatusCode::SUCCESS;
67 }
68 
70 StatusCode RootCnvSvc::connectOutput(const std::string& file, const std::string& mode) {
71  std::string fileName = file;
72  std::string::size_type inx1 = file.find('(');
73  if (inx1 != std::string::npos) {
74  std::string::size_type inx2 = file.find(')');
75  if (inx2 == std::string::npos || inx2 != file.size() - 1) {
76  return StatusCode::FAILURE;
77  }
78  m_treeName = fileName.substr(inx1 + 1, inx2 - inx1 - 1);
79  fileName.resize(inx1);//already checked that inx1!=npos
80  }
81  if (!m_rootSvc->open(fileName, mode).isSuccess()) {
82  ATH_MSG_ERROR("Could not open-recreate file [" << file << "]");
83  return StatusCode::FAILURE;
84  }
85  return this->connectOutput(fileName);
86 }
87 
90  return m_rootSvc->connect(file);
91 }
92 
94 StatusCode RootCnvSvc::commitOutput(const std::string& /*file*/, bool /*do_commit*/) {
95  return m_rootSvc->commitOutput();
96 }
97 
99  const CLID& clid,
100  const std::string* par,
101  const unsigned long* ip,
102  IOpaqueAddress*& refpAddress) {
103  ATH_MSG_VERBOSE("RootCnvSvc::createAddress("
104  << "svc_type=" << svc_type << ", "
105  << "clid=" << clid << ", "
106  << "par=" << par[0] << ", " << par[1] << " "
107  << "ip=" << ip[0] << ", " << ip[1] << " "
108  << "refpaddr=" << refpAddress << ")");
109  refpAddress = new GenericAddress(ROOT_StorageType, clid, par[0], par[1], ip[0], ip[1]);
110  return StatusCode::SUCCESS;
111 }
112 
113 StatusCode RootCnvSvc::convertAddress(const IOpaqueAddress* pAddress, std::string& refAddress) {
114  ATH_MSG_VERBOSE("::convertAddress(pAddr = " << pAddress << ", refPaddr = " << refAddress << ")");
115  return StatusCode::FAILURE;
116 }
117 
119  const CLID& clid,
120  const std::string& refAddress,
121  IOpaqueAddress*& refpAddress) {
122  ATH_MSG_VERBOSE("RootCnvSvc::createAddress("
123  << "svc_type=" << svc_type << ", "
124  << "clid=" << clid << ", "
125  << "refaddr=" << refAddress << ", "
126  << "refpaddr=" << refpAddress << ")");
127 
128  return StatusCode::FAILURE;
129 }
130 
131 StatusCode RootCnvSvc::updateServiceState(IOpaqueAddress* pAddress) {
132  ATH_MSG_VERBOSE("RootCnvSvc::updateServiceState(paddr = " << pAddress << ")");
133  return StatusCode::FAILURE;
134 }
135 
138 RootType RootCnvSvc::getType(const CLID& clid) const {
139  return m_dictSvc->load_type(clid);
140 }
141 
142 RootType RootCnvSvc::getType(const std::type_info& type) const {
143  return m_dictSvc->load_type(type);
144 }
145 
147 const Token* RootCnvSvc::writeObject(const std::string& key,
148  const RootType& typeDesc,
149  const void* pObj,
150  ITPCnvBase* tpConverter) {
151  const Token* token = 0;
152  Placement placement;
153  placement.setContainerName(m_treeName + "(" + key + ")");
154  placement.setTechnology(ROOT_StorageType);
155  if (tpConverter == 0) {
156  token = m_rootSvc->writeObject(placement, typeDesc, pObj);
157  } else {
158  void* pers = m_rootSvc->createObject(typeDesc);
159  tpConverter->transToPersUntyped(pObj, pers, this->msg());
160  token = m_rootSvc->writeObject(placement, typeDesc, pers);
161  m_rootSvc->destructObject(typeDesc, pers); pers = 0;
162  }
163  return token;
164 }
165 
167  ATH_MSG_VERBOSE("RootCnvSvc::getTPConverter clid = " << clid);
168  return m_tpCnvSvc->t2p_cnv(clid);
169 }
171 
172 IConverter* RootCnvSvc::createConverter(long typ, const CLID& clid, const ICnvFactory* fac) {
173  ATH_MSG_VERBOSE("createConverter typ = " << typ << ", clid = " << clid);
174  if (typ == ROOT_StorageType) {
175  return new Athena::RootCnv(clid, serviceLocator().get());
176  }
177  return ::AthCnvSvc::createConverter(typ, clid, fac);
178 }
179 
180 } //> end namespace Athena
Athena::RootCnvSvc::m_rootSvc
ServiceHandle< ::IRootSvc > m_rootSvc
ServiceHandle to the root service.
Definition: RootCnvSvc.h:107
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Placement
This class holds all the necessary information to guide the writing of an object in a physical place.
Definition: Placement.h:19
IAthenaRootCnvSvc
This class provides the interface between Athena and RootSvc.
Definition: IAthenaRootCnvSvc.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Athena::RootCnvSvc::m_dictSvc
ServiceHandle< ::IDictLoaderSvc > m_dictSvc
ServiceHandle to the dictionary service.
Definition: RootCnvSvc.h:103
Athena::RootCnvSvc::createAddress
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.
Definition: RootCnvSvc.cxx:98
ITPCnvSvc.h
IAthenaRootCnvSvc::interfaceID
static const InterfaceID & interfaceID()
Retrieve interface ID.
Definition: IAthenaRootCnvSvc.h:35
Athena::RootCnvSvc::connectOutput
StatusCode connectOutput(const std::string &file)
Connect the output file to the service.
Definition: RootCnvSvc.cxx:89
Athena::RootCnvSvc::getType
RootType getType(const CLID &clid) const
Definition: RootCnvSvc.cxx:138
RootCnv.h
This file contains the class definition for the Athena::RootCnv class.
Athena::RootCnvSvc::RootCnvSvc
RootCnvSvc()
Default constructor:
AthCnvSvc::initialize
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition: AthCnvSvc.cxx:111
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ITPCnvBase.h
Athena::RootCnvSvc::getTPConverter
ITPCnvBase * getTPConverter(const CLID &clid) const
Get T/P converter for a transient class.
Definition: RootCnvSvc.cxx:166
Placement::setContainerName
Placement & setContainerName(const std::string &containerName)
Set container name.
Definition: Placement.h:34
Athena::RootCnvSvc::updateServiceState
StatusCode updateServiceState(IOpaqueAddress *pAddress)
Update state of the service.
Definition: RootCnvSvc.cxx:131
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
ITPCnvBase::transToPersUntyped
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &msg)=0
Convert transient object representation to persistent.
Athena::RootCnvSvc::commitOutput
StatusCode commitOutput(const std::string &output, bool do_commit)
Commit pending output.
Definition: RootCnvSvc.cxx:94
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
Athena::RootCnvSvc::convertAddress
StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress)
Convert an address to string form.
Definition: RootCnvSvc.cxx:113
Athena::RootCnvSvc::writeObject
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.
Definition: RootCnvSvc.cxx:147
file
TFile * file
Definition: tile_monitor.h:29
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
RootSvc.h
This file contains the class definition for the RootSvc class.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Preparation.mode
mode
Definition: Preparation.py:95
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
Athena::RootCnvSvc::queryInterface
StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Definition: RootCnvSvc.cxx:58
ITPCnvBase
Definition: ITPCnvBase.h:24
Athena::RootCnvSvc::createConverter
IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new converter using factory.
Definition: RootCnvSvc.cxx:172
Athena::RootCnvSvc::initialize
StatusCode initialize()
Gaudi Service Interface method implementations:
Definition: RootCnvSvc.cxx:39
IDictLoaderSvc.h
IRootSvc.h
This file contains the class definition for the IRootSvc interface class.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Placement::setTechnology
Placement & setTechnology(int technology)
Set technology type.
Definition: Placement.h:38
AthCommonMsg< Service >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
Athena::RootCnvSvc::m_treeName
std::string m_treeName
ROOT TTree name.
Definition: RootCnvSvc.h:110
Athena::RootCnv
This class provides the abstract converter to translate an object to/from its persistent ROOT represe...
Definition: RootCnv.h:37
Placement.h
This file contains the class definition for the Placement class (migrated from POOL).
RootCnvSvc.h
Athena::RootCnvSvc::m_tpCnvSvc
ServiceHandle< ::ITPCnvSvc > m_tpCnvSvc
ServiceHandle to the T/P conversion service.
Definition: RootCnvSvc.h:105
Athena::RootCnvSvc::finalize
StatusCode finalize()
Definition: RootCnvSvc.cxx:54
AthCnvSvc
Definition: AthCnvSvc.h:67
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
TScopeAdapter
Definition: RootType.h:119