ATLAS Offline Software
RootCnvSvc.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 // 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  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 
56 }
57 
59 StatusCode 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 
79  return m_rootSvc->connect(file);
80 }
81 
83 StatusCode RootCnvSvc::commitOutput(const std::string& /*file*/, bool /*do_commit*/) {
84  return m_rootSvc->commitOutput();
85 }
86 
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 
102 StatusCode RootCnvSvc::convertAddress(const IOpaqueAddress* pAddress, std::string& refAddress) {
103  ATH_MSG_VERBOSE("::convertAddress(pAddr = " << pAddress << ", refPaddr = " << refAddress << ")");
104  return StatusCode::FAILURE;
105 }
106 
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 
120 StatusCode RootCnvSvc::updateServiceState(IOpaqueAddress* pAddress) {
121  ATH_MSG_VERBOSE("RootCnvSvc::updateServiceState(paddr = " << pAddress << ")");
122  return StatusCode::FAILURE;
123 }
124 
127 RootType RootCnvSvc::getType(const CLID& clid) const {
128  return m_dictSvc->load_type(clid);
129 }
130 
131 RootType RootCnvSvc::getType(const std::type_info& type) const {
132  return m_dictSvc->load_type(type);
133 }
134 
136 const 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 }
160 
161 IConverter* 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
Athena::RootCnvSvc::m_rootSvc
ServiceHandle< ::IRootSvc > m_rootSvc
ServiceHandle to the root service.
Definition: RootCnvSvc.h:106
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
Placement
This class holds all the necessary information to guide the writing of an object in a physical place.
Definition: Placement.h:19
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:102
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:87
ITPCnvSvc.h
Athena::RootCnvSvc::connectOutput
StatusCode connectOutput(const std::string &file)
Connect the output file to the service.
Definition: RootCnvSvc.cxx:78
Athena::RootCnvSvc::getType
RootType getType(const CLID &clid) const
Definition: RootCnvSvc.cxx:127
RootCnv.h
This file contains the class definition for the Athena::RootCnv class.
Athena::RootCnvSvc::RootCnvSvc
RootCnvSvc()
Default constructor:
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:155
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:120
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:83
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:102
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:136
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:94
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:221
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
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:161
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
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:109
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
AthCnvSvc::initialize
virtual StatusCode initialize() override
Gaudi Service Implementation.
Definition: AthCnvSvc.cxx:104
Athena::RootCnvSvc::m_tpCnvSvc
ServiceHandle< ::ITPCnvSvc > m_tpCnvSvc
ServiceHandle to the T/P conversion service.
Definition: RootCnvSvc.h:104
Athena::RootCnvSvc::finalize
StatusCode finalize()
Definition: RootCnvSvc.cxx:54
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
TScopeAdapter
Definition: RootType.h:119