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

pool::IFileCatalogm_catalog
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 39 of file RootSvc.h.

Member Typedef Documentation

◆ ConnMap_t

Definition at line 94 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 27 of file RootSvc.cxx.

27 :
28 base_class(name, pSvcLocator),
29 m_catalog(0),
30 m_conns(),
31 m_wconn(0),
32 m_dictSvc("AthDictLoaderSvc", name) {
33}
ConnMap_t m_conns
Map of file name keys and connection values.
Definition RootSvc.h:96
pool::IFileCatalog * m_catalog
Definition RootSvc.h:92
Athena::RootConnection * m_wconn
Definition RootSvc.h:97
ServiceHandle< ::IDictLoaderSvc > m_dictSvc
ServiceHandle to the dictionary service.
Definition RootSvc.h:100

◆ ~RootSvc()

Athena::RootSvc::~RootSvc ( )
virtual

Destructor.

Definition at line 35 of file RootSvc.cxx.

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

◆ 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 156 of file RootSvc.cxx.

156 {
157 ATH_MSG_VERBOSE("RootSvc::commitOutput");
158 if (m_wconn == 0) {
159 ATH_MSG_ERROR("Cannot commit without RootConnection.");
160 return StatusCode::FAILURE;
161 }
162 if (!m_wconn->commit().isSuccess()) {
163 ATH_MSG_ERROR("Cannot commit RootConnection.");
164 return StatusCode::FAILURE;
165 }
166 return StatusCode::SUCCESS;
167}
#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 141 of file RootSvc.cxx.

141 {
142 ATH_MSG_VERBOSE("connect(" << fname << ")...");
143 Athena::RootConnection* conn = this->connection(fname);
144 if (conn == 0) {
145 ATH_MSG_ERROR("No open RootConnection for file " << fname);
146 return StatusCode::FAILURE;
147 }
148 if (!conn->connectWrite("recreate").isSuccess()) {
149 ATH_MSG_ERROR("Cannot connect to file " << fname);
150 return StatusCode::FAILURE;
151 }
152 m_wconn = conn;
153 return StatusCode::SUCCESS;
154}
Athena::RootConnection * connection(const std::string &fname)
Get the RootConnection associated with file fname
Definition RootSvc.cxx:189

◆ 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 189 of file RootSvc.cxx.

189 {
190// Catalog to get fid...
191 Guid fid = Guid::null();
192 if (m_catalog != 0) {
193 std::string fidString, ftype;
194 m_catalog->lookupFileByPFN(fname, fidString, ftype);
195 if( fidString.empty() ) {
196 m_catalog->registerPFN(fname, "ROOT_All", fidString);
197 }
198 fid.fromString(fidString);
199 }
200 Athena::RootConnection* conn = 0;
201 ConnMap_t::const_iterator fitr = m_conns.find(fid);
202 if (fitr != m_conns.end()) {
203 conn = fitr->second;
204 }
205 return conn;
206}
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 104 of file RootSvc.cxx.

104 {
105 void* pObj = type.Construct();
106 return pObj;
107}

◆ destructObject()

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

Destruct a given object of type RootType.

Definition at line 110 of file RootSvc.cxx.

110 {
111}

◆ disconnect()

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

Disconnect the file fname from the service.

Definition at line 170 of file RootSvc.cxx.

170 {
171 ATH_MSG_VERBOSE("disconnect(" << fname << ")...");
172 Athena::RootConnection* conn = this->connection(fname);
173 if (conn == 0) {
174 ATH_MSG_ERROR("No open RootConnection for file " << fname);
175 return StatusCode::FAILURE;
176 }
177 if (!conn->disconnect().isSuccess()) {
178 ATH_MSG_ERROR("Cannot disconnect to file " << fname);
179 return StatusCode::FAILURE;
180 }
181 if (m_wconn == conn) {
182 m_wconn = 0;
183 }
184 return StatusCode::SUCCESS;
185}

◆ finalize()

StatusCode Athena::RootSvc::finalize ( )

Definition at line 61 of file RootSvc.cxx.

61 {
62 for (ConnMap_t::const_iterator itr = m_conns.begin(), iend = m_conns.end(); itr != iend; ++itr) {
63 if (!itr->second->disconnect().isSuccess()) {
64 ATH_MSG_WARNING("Cannot disconnect file = " << itr->first.toString());
65 }
66 }
67 if (m_catalog != 0) {
68 m_catalog->commit();
69 delete m_catalog; m_catalog = 0;
70 }
71 return ::AthService::finalize();
72}
#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 75 of file RootSvc.cxx.

75 {
76 return m_dictSvc->load_type(type);
77}

◆ initialize()

StatusCode Athena::RootSvc::initialize ( )

Gaudi Service Interface method implementations:

Definition at line 42 of file RootSvc.cxx.

42 {
43 ATH_MSG_INFO("Initializing " << name());
44 if (!::AthService::initialize().isSuccess()) {
45 ATH_MSG_FATAL("Cannot initialize ConversionSvc base class.");
46 return StatusCode::FAILURE;
47 }
48 m_catalog = new pool::IFileCatalog;
49 try {
50 m_catalog->setWriteCatalog("xmlcatalog_file:RootFileCatalog.xml"); // FIXME: Make config
51 m_catalog->connect();
52 m_catalog->start();
53 } catch (std::exception& e) {
54 ATH_MSG_FATAL ("Set up Catalog - caught exception: " << e.what());
55 return StatusCode::FAILURE;
56 }
57 ATH_CHECK(m_dictSvc.retrieve());
58 return StatusCode::SUCCESS;
59}
#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 114 of file RootSvc.cxx.

114 {
115// Catalog to get fid...
116 Guid fid = Guid::null();
117 if (m_catalog != 0) {
118 std::string fidString, ftype;
119 m_catalog->lookupFileByPFN(fname, fidString, ftype);
120 if( fidString.empty() ) {
121 m_catalog->registerPFN(fname, "ROOT_All", fidString);
122 }
123 fid.fromString(fidString);
124 }
125 Athena::RootConnection* conn = 0;
126 ConnMap_t::const_iterator fitr = m_conns.find(fid);
127 if (fitr == m_conns.end()) {
128 conn = new Athena::RootConnection(this, fname);
129 m_conns.insert(std::make_pair(fid, conn));
130 } else {
131 conn = fitr->second;
132 }
133 if (conn == 0) {
134 ATH_MSG_ERROR("Cannot get RootConnection for file " << fid.toString());
135 return StatusCode::FAILURE;
136 }
137 return StatusCode::SUCCESS;
138}
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 80 of file RootSvc.cxx.

80 {
81 return 0;
82}

◆ 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 85 of file RootSvc.cxx.

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

Member Data Documentation

◆ m_catalog

pool::IFileCatalog* Athena::RootSvc::m_catalog
private

Definition at line 92 of file RootSvc.h.

◆ m_conns

ConnMap_t Athena::RootSvc::m_conns
private

Map of file name keys and connection values.

Definition at line 96 of file RootSvc.h.

◆ m_dictSvc

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

ServiceHandle to the dictionary service.

Definition at line 100 of file RootSvc.h.

◆ m_wconn

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

Definition at line 97 of file RootSvc.h.


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