ATLAS Offline Software
Loading...
Searching...
No Matches
Athena::RootSvc Class Reference

This class provides the interface to the ROOT software. More...

#include <RootSvc.h>

Inheritance diagram for Athena::RootSvc:
Collaboration diagram for Athena::RootSvc:

Public Member Functions

 RootSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Standard Service Constructor.
StatusCode initialize ()
 Gaudi Service Interface method implementations:
StatusCode finalize ()
StatusCode open (const std::string &fname, const std::string &mode)
 Open the file fname with open mode mode.
StatusCode connect (const std::string &fname)
 Connect the file fname to the service.
StatusCode commitOutput ()
 Commit data and flush buffer.
StatusCode disconnect (const std::string &fname)
 Disconnect the file fname from the service.
Athena::RootConnectionconnection (const std::string &fname)
 Get the RootConnection associated with file fname.
virtual ~RootSvc ()
 Destructor.
RootType getType (const std::type_info &type) const
 Load the type (dictionary) from Root.
void * readObject (const Token &token, void *&pObj)
 Read object from Root.
const TokenwriteObject (const Placement &placement, const RootType &type, const void *pObj)
 Write object of a given class to Root.
void * createObject (const RootType &type) const
 Create an object of a given RootType.
void destructObject (const RootType &type, void *pObj) const
 Destruct a given object of type RootType.

Private Types

typedef std::map< Guid, Athena::RootConnection * > ConnMap_t

Private Member Functions

 RootSvc ()
 Default constructor:
 RootSvc (const RootSvc &)
RootSvcoperator= (const RootSvc &)

Private Attributes

SmartIF< Gaudi::IFileCatalogMgr > m_gCatalogMgr
SmartIF< Gaudi::IFileCatalog > m_gCatalog
ConnMap_t m_conns
 Map of file name keys and connection values.
Athena::RootConnectionm_wconn
ServiceHandle< ::IDictLoaderSvcm_dictSvc
 ServiceHandle to the dictionary service.

Detailed Description

This class provides the interface to the ROOT software.

Definition at line 42 of file RootSvc.h.

Member Typedef Documentation

◆ ConnMap_t

Definition at line 98 of file RootSvc.h.

Constructor & Destructor Documentation

◆ RootSvc() [1/3]

Athena::RootSvc::RootSvc ( const std::string & name,
ISvcLocator * pSvcLocator )

Standard Service Constructor.

Definition at line 24 of file RootSvc.cxx.

24 :
25 base_class(name, pSvcLocator),
26 m_gCatalogMgr(Gaudi::svcLocator()->service<Gaudi::IFileCatalogMgr>( "Gaudi::MultiFileCatalog" )),
28 m_conns(),
29 m_wconn(0),
30 m_dictSvc("AthDictLoaderSvc", name) {
31}
SmartIF< Gaudi::IFileCatalog > m_gCatalog
Definition RootSvc.h:96
ConnMap_t m_conns
Map of file name keys and connection values.
Definition RootSvc.h:100
Athena::RootConnection * m_wconn
Definition RootSvc.h:101
ServiceHandle< ::IDictLoaderSvc > m_dictSvc
ServiceHandle to the dictionary service.
Definition RootSvc.h:104
SmartIF< Gaudi::IFileCatalogMgr > m_gCatalogMgr
Definition RootSvc.h:95

◆ ~RootSvc()

Athena::RootSvc::~RootSvc ( )
virtual

Destructor.

Definition at line 33 of file RootSvc.cxx.

33 {
34 for (ConnMap_t::iterator itr = m_conns.begin(), iend = m_conns.end(); itr != iend; ++itr) {
35 delete itr->second; itr->second = 0;
36 }
37 m_conns.clear();
38}

◆ RootSvc() [2/3]

Athena::RootSvc::RootSvc ( )
private

Default constructor:

◆ RootSvc() [3/3]

Athena::RootSvc::RootSvc ( const RootSvc & )
private

Member Function Documentation

◆ commitOutput()

StatusCode Athena::RootSvc::commitOutput ( )

Commit data and flush buffer.

Definition at line 149 of file RootSvc.cxx.

149 {
150 ATH_MSG_VERBOSE("RootSvc::commitOutput");
151 if (m_wconn == 0) {
152 ATH_MSG_ERROR("Cannot commit without RootConnection.");
153 return StatusCode::FAILURE;
154 }
155 if (!m_wconn->commit().isSuccess()) {
156 ATH_MSG_ERROR("Cannot commit RootConnection.");
157 return StatusCode::FAILURE;
158 }
159 return StatusCode::SUCCESS;
160}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)

◆ connect()

StatusCode Athena::RootSvc::connect ( const std::string & fname)

Connect the file fname to the service.

Definition at line 134 of file RootSvc.cxx.

134 {
135 ATH_MSG_VERBOSE("connect(" << fname << ")...");
136 Athena::RootConnection* conn = this->connection(fname);
137 if (conn == 0) {
138 ATH_MSG_ERROR("No open RootConnection for file " << fname);
139 return StatusCode::FAILURE;
140 }
141 if (!conn->connectWrite("recreate").isSuccess()) {
142 ATH_MSG_ERROR("Cannot connect to file " << fname);
143 return StatusCode::FAILURE;
144 }
145 m_wconn = conn;
146 return StatusCode::SUCCESS;
147}
Athena::RootConnection * connection(const std::string &fname)
Get the RootConnection associated with file fname.
Definition RootSvc.cxx:182

◆ connection()

Athena::RootConnection * Athena::RootSvc::connection ( const std::string & fname)

Get the RootConnection associated with file fname.

Returns
NULL if no such file is known to this service

Definition at line 182 of file RootSvc.cxx.

182 {
183// Catalog to get fid...
184 Guid fid = Guid::null();
185 std::string fidString;
186 fidString = m_gCatalog->lookupPFN(fname);
187 if( fidString.empty() ) {
188 fidString = m_gCatalog->createFID();
189 m_gCatalog->registerPFN(fidString, fname, "ROOT_All");
190 }
191 fid.fromString(fidString);
192 Athena::RootConnection* conn = 0;
193 ConnMap_t::const_iterator fitr = m_conns.find(fid);
194 if (fitr != m_conns.end()) {
195 conn = fitr->second;
196 }
197 return conn;
198}
constexpr void fromString(std::string_view s)
Automatic conversion from string representation.
Definition Guid.h:143
static const Guid & null() noexcept
NULL-Guid: static class method.
Definition Guid.cxx:14

◆ createObject()

void * Athena::RootSvc::createObject ( const RootType & type) const

Create an object of a given RootType.

Definition at line 98 of file RootSvc.cxx.

98 {
99 void* pObj = type.Construct();
100 return pObj;
101}

◆ destructObject()

void Athena::RootSvc::destructObject ( const RootType & type,
void * pObj ) const

Destruct a given object of type RootType.

Definition at line 104 of file RootSvc.cxx.

104 {
105}

◆ disconnect()

StatusCode Athena::RootSvc::disconnect ( const std::string & fname)

Disconnect the file fname from the service.

Definition at line 163 of file RootSvc.cxx.

163 {
164 ATH_MSG_VERBOSE("disconnect(" << fname << ")...");
165 Athena::RootConnection* conn = this->connection(fname);
166 if (conn == 0) {
167 ATH_MSG_ERROR("No open RootConnection for file " << fname);
168 return StatusCode::FAILURE;
169 }
170 if (!conn->disconnect().isSuccess()) {
171 ATH_MSG_ERROR("Cannot disconnect to file " << fname);
172 return StatusCode::FAILURE;
173 }
174 if (m_wconn == conn) {
175 m_wconn = 0;
176 }
177 return StatusCode::SUCCESS;
178}

◆ finalize()

StatusCode Athena::RootSvc::finalize ( )

Definition at line 58 of file RootSvc.cxx.

58 {
59 for (ConnMap_t::const_iterator itr = m_conns.begin(), iend = m_conns.end(); itr != iend; ++itr) {
60 if (!itr->second->disconnect().isSuccess()) {
61 ATH_MSG_WARNING("Cannot disconnect file = " << itr->first.toString());
62 }
63 }
64 m_gCatalog->commit();
65 return ::AthService::finalize();
66}
#define ATH_MSG_WARNING(x)

◆ getType()

RootType Athena::RootSvc::getType ( const std::type_info & type) const

Load the type (dictionary) from Root.

RootType-base interface Load the type (dictionary) from Root.

Definition at line 69 of file RootSvc.cxx.

69 {
70 return m_dictSvc->load_type(type);
71}

◆ initialize()

StatusCode Athena::RootSvc::initialize ( )

Gaudi Service Interface method implementations:

Definition at line 40 of file RootSvc.cxx.

40 {
41 ATH_MSG_INFO("Initializing " << name());
42 if (!::AthService::initialize().isSuccess()) {
43 ATH_MSG_FATAL("Cannot initialize ConversionSvc base class.");
44 return StatusCode::FAILURE;
45 }
46 try {
47 m_gCatalogMgr->addCatalog("xmlcatalog_file:RootFileCatalog.xml");
48 m_gCatalogMgr->setWriteCatalog(m_gCatalogMgr->findCatalog("file:RootFileCatalog.xml", true));
49 m_gCatalog->init();
50 } catch (std::exception& e) {
51 ATH_MSG_FATAL ("Set up Catalog - caught exception: " << e.what());
52 return StatusCode::FAILURE;
53 }
54 ATH_CHECK(m_dictSvc.retrieve());
55 return StatusCode::SUCCESS;
56}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)

◆ open()

StatusCode Athena::RootSvc::open ( const std::string & fname,
const std::string & mode )

Open the file fname with open mode mode.

Definition at line 108 of file RootSvc.cxx.

108 {
109// Catalog to get fid...
110 Guid fid = Guid::null();
111 std::string fidString;
112 fidString = m_gCatalog->lookupPFN(fname);
113 if( fidString.empty() ) {
114 fidString = m_gCatalog->createFID();
115 m_gCatalog->registerPFN(fidString, fname, "ROOT_All");
116 }
117 fid.fromString(fidString);
118 Athena::RootConnection* conn = 0;
119 ConnMap_t::const_iterator fitr = m_conns.find(fid);
120 if (fitr == m_conns.end()) {
121 conn = new Athena::RootConnection(this, fname);
122 m_conns.insert(std::make_pair(fid, conn));
123 } else {
124 conn = fitr->second;
125 }
126 if (conn == 0) {
127 ATH_MSG_ERROR("Cannot get RootConnection for file " << fid.toString());
128 return StatusCode::FAILURE;
129 }
130 return StatusCode::SUCCESS;
131}
constexpr void toString(std::span< char, StrLen > buf, bool uppercase=true) const noexcept
Automatic conversion to string representation.

◆ operator=()

RootSvc & Athena::RootSvc::operator= ( const RootSvc & )
private

◆ readObject()

void * Athena::RootSvc::readObject ( const Token & token,
void *& pObj )

Read object from Root.

Definition at line 74 of file RootSvc.cxx.

74 {
75 return 0;
76}

◆ writeObject()

const Token * Athena::RootSvc::writeObject ( const Placement & placement,
const RootType & type,
const void * pObj )

Write object of a given class to Root.

Definition at line 79 of file RootSvc.cxx.

79 {
80 ATH_MSG_VERBOSE("RootSvc::writeObject pObj = " << pObj);
81 if (m_wconn == 0) {
82 ATH_MSG_ERROR("Cannot write without RootConnection for placement " << placement.containerName());
83 return 0;
84 }
85 if (!m_wconn->setContainer(placement.containerName(), type.Name()).isSuccess()) {
86 ATH_MSG_ERROR("Cannot set container [" << placement.containerName() << "]");
87 return 0;
88 }
89 unsigned long ientry = 0;
90 if (!m_wconn->write(pObj, ientry).isSuccess()) {
91 ATH_MSG_ERROR("Cannot write Object to placement [" << placement.containerName() << "]");
92 return 0;
93 }
94 return new Token();
95}
const std::string & containerName() const
Access container name.
Definition Placement.h:33

Member Data Documentation

◆ m_conns

ConnMap_t Athena::RootSvc::m_conns
private

Map of file name keys and connection values.

Definition at line 100 of file RootSvc.h.

◆ m_dictSvc

ServiceHandle< ::IDictLoaderSvc> Athena::RootSvc::m_dictSvc
private

ServiceHandle to the dictionary service.

Definition at line 104 of file RootSvc.h.

◆ m_gCatalog

SmartIF<Gaudi::IFileCatalog> Athena::RootSvc::m_gCatalog
private

Definition at line 96 of file RootSvc.h.

◆ m_gCatalogMgr

SmartIF<Gaudi::IFileCatalogMgr> Athena::RootSvc::m_gCatalogMgr
private

Definition at line 95 of file RootSvc.h.

◆ m_wconn

Athena::RootConnection* Athena::RootSvc::m_wconn
private

Definition at line 101 of file RootSvc.h.


The documentation for this class was generated from the following files: