ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
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. More...
 
StatusCode initialize ()
 Gaudi Service Interface method implementations: More...
 
StatusCode finalize ()
 
StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
 
StatusCode open (const std::string &fname, const std::string &mode)
 Open the file fname with open mode mode More...
 
StatusCode connect (const std::string &fname)
 Connect the file fname to the service. More...
 
StatusCode commitOutput ()
 Commit data and flush buffer. More...
 
StatusCode disconnect (const std::string &fname)
 Disconnect the file fname from the service. More...
 
Athena::RootConnectionconnection (const std::string &fname)
 Get the RootConnection associated with file fname More...
 
virtual ~RootSvc ()
 Destructor. More...
 
MsgStream & msg () const
 
MsgStream & msg (const MSG::Level lvl) const
 
bool msgLvl (const MSG::Level lvl) const
 
RootType getType (const std::type_info &type) const
 Load the type (dictionary) from Root. More...
 
void * readObject (const Token &token, void *&pObj)
 Read object from Root. More...
 
const TokenwriteObject (const Placement &placement, const RootType &type, const void *pObj)
 Write object of a given class to Root. More...
 
void * createObject (const RootType &type) const
 Create an object of a given RootType. More...
 
void destructObject (const RootType &type, void *pObj) const
 Destruct a given object of type RootType. More...
 

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Retrieve interface ID. More...
 

Private Types

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

Private Member Functions

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

Private Attributes

pool::IFileCatalogm_catalog
 
ConnMap_t m_conns
 Map of file name keys and connection values. More...
 
Athena::RootConnectionm_wconn
 
ServiceHandle< ::IDictLoaderSvcm_dictSvc
 ServiceHandle to the dictionary service. More...
 

Friends

class SvcFactory< Athena::RootSvc >
 

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 101 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  ::AthService(name, pSvcLocator),
29  m_catalog(0),
30  m_conns(),
31  m_wconn(0),
32  m_dictSvc("AthDictLoaderSvc", name) {
33 }

◆ ~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 ( )
virtual

Commit data and flush buffer.

Implements IRootSvc.

Definition at line 167 of file RootSvc.cxx.

167  {
168  ATH_MSG_VERBOSE("RootSvc::commitOutput");
169  if (m_wconn == 0) {
170  ATH_MSG_ERROR("Cannot commit without RootConnection.");
171  return StatusCode::FAILURE;
172  }
173  if (!m_wconn->commit().isSuccess()) {
174  ATH_MSG_ERROR("Cannot commit RootConnection.");
175  return StatusCode::FAILURE;
176  }
177  return StatusCode::SUCCESS;
178 }

◆ connect()

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

Connect the file fname to the service.

Implements IRootSvc.

Definition at line 152 of file RootSvc.cxx.

152  {
153  ATH_MSG_VERBOSE("connect(" << fname << ")...");
155  if (conn == 0) {
156  ATH_MSG_ERROR("No open RootConnection for file " << fname);
157  return StatusCode::FAILURE;
158  }
159  if (!conn->connectWrite("recreate").isSuccess()) {
160  ATH_MSG_ERROR("Cannot connect to file " << fname);
161  return StatusCode::FAILURE;
162  }
163  m_wconn = conn;
164  return StatusCode::SUCCESS;
165 }

◆ connection()

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

Get the RootConnection associated with file fname

Returns
NULL if no such file is known to this service

Implements IRootSvc.

Definition at line 200 of file RootSvc.cxx.

200  {
201 // Catalog to get fid...
202  Guid fid = Guid::null();
203  if (m_catalog != 0) {
204  std::string fidString, ftype;
205  m_catalog->lookupFileByPFN(fname, fidString, ftype);
206  if( fidString.empty() ) {
207  m_catalog->registerPFN(fname, "ROOT_All", fidString);
208  }
209  fid.fromString(fidString);
210  }
212  ConnMap_t::const_iterator fitr = m_conns.find(fid);
213  if (fitr != m_conns.end()) {
214  conn = fitr->second;
215  }
216  return conn;
217 }

◆ createObject()

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

Create an object of a given RootType.

Implements IRootSvc.

Definition at line 115 of file RootSvc.cxx.

115  {
116  void* pObj = type.Construct();
117  return pObj;
118 }

◆ destructObject()

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

Destruct a given object of type RootType.

Implements IRootSvc.

Definition at line 121 of file RootSvc.cxx.

121  {
122 }

◆ disconnect()

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

Disconnect the file fname from the service.

Implements IRootSvc.

Definition at line 181 of file RootSvc.cxx.

181  {
182  ATH_MSG_VERBOSE("disconnect(" << fname << ")...");
184  if (conn == 0) {
185  ATH_MSG_ERROR("No open RootConnection for file " << fname);
186  return StatusCode::FAILURE;
187  }
188  if (!conn->disconnect().isSuccess()) {
189  ATH_MSG_ERROR("Cannot disconnect to file " << fname);
190  return StatusCode::FAILURE;
191  }
192  if (m_wconn == conn) {
193  m_wconn = 0;
194  }
195  return StatusCode::SUCCESS;
196 }

◆ 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  }
72 }

◆ getType()

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

Load the type (dictionary) from Root.

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

Implements IRootSvc.

Definition at line 86 of file RootSvc.cxx.

86  {
87  return m_dictSvc->load_type(type);
88 }

◆ 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  }
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 }

◆ interfaceID()

static const InterfaceID& Athena::RootSvc::interfaceID ( )
inlinestatic

Retrieve interface ID.

Definition at line 52 of file RootSvc.h.

52  {
53  return ::IRootSvc::interfaceID();
54  }

◆ msg() [1/2]

MsgStream& AthCommonMsg< Service >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24  {
25  return this->msgStream();
26  }

◆ msg() [2/2]

MsgStream& AthCommonMsg< Service >::msg ( const MSG::Level  lvl) const
inlineinherited

Definition at line 27 of file AthCommonMsg.h.

27  {
28  return this->msgStream(lvl);
29  }

◆ msgLvl()

bool AthCommonMsg< Service >::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30  {
31  return this->msgLevel(lvl);
32  }

◆ open()

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

Open the file fname with open mode mode

Implements IRootSvc.

Definition at line 125 of file RootSvc.cxx.

125  {
126 // Catalog to get fid...
127  Guid fid = Guid::null();
128  if (m_catalog != 0) {
129  std::string fidString, ftype;
130  m_catalog->lookupFileByPFN(fname, fidString, ftype);
131  if( fidString.empty() ) {
132  m_catalog->registerPFN(fname, "ROOT_All", fidString);
133  }
134  fid.fromString(fidString);
135  }
137  ConnMap_t::const_iterator fitr = m_conns.find(fid);
138  if (fitr == m_conns.end()) {
139  conn = new Athena::RootConnection(this, fname);
140  m_conns.insert(std::make_pair(fid, conn));
141  } else {
142  conn = fitr->second;
143  }
144  if (conn == 0) {
145  ATH_MSG_ERROR("Cannot get RootConnection for file " << fid.toString());
146  return StatusCode::FAILURE;
147  }
148  return StatusCode::SUCCESS;
149 }

◆ operator=()

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

◆ queryInterface()

StatusCode Athena::RootSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvInterface 
)

Definition at line 74 of file RootSvc.cxx.

74  {
75  if (IRootSvc::interfaceID().versionMatch(riid)) {
76  *ppvInterface = dynamic_cast<IRootSvc*>(this);
77  } else {
78  // Interface is not directly available: try out a base class
79  return ::AthService::queryInterface(riid, ppvInterface);
80  }
81  addRef();
82  return StatusCode::SUCCESS;
83 }

◆ readObject()

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

Read object from Root.

Implements IRootSvc.

Definition at line 91 of file RootSvc.cxx.

91  {
92  return 0;
93 }

◆ writeObject()

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

Write object of a given class to Root.

Implements IRootSvc.

Definition at line 96 of file RootSvc.cxx.

96  {
97  ATH_MSG_VERBOSE("RootSvc::writeObject pObj = " << pObj);
98  if (m_wconn == 0) {
99  ATH_MSG_ERROR("Cannot write without RootConnection for placement " << placement.containerName());
100  return 0;
101  }
102  if (!m_wconn->setContainer(placement.containerName(), type.Name()).isSuccess()) {
103  ATH_MSG_ERROR("Cannot set container [" << placement.containerName() << "]");
104  return 0;
105  }
106  unsigned long ientry = 0;
107  if (!m_wconn->write(pObj, ientry).isSuccess()) {
108  ATH_MSG_ERROR("Cannot write Object to placement [" << placement.containerName() << "]");
109  return 0;
110  }
111  return new Token();
112 }

Friends And Related Function Documentation

◆ SvcFactory< Athena::RootSvc >

friend class SvcFactory< Athena::RootSvc >
friend

Definition at line 1 of file RootSvc.h.

Member Data Documentation

◆ m_catalog

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

Definition at line 99 of file RootSvc.h.

◆ m_conns

ConnMap_t Athena::RootSvc::m_conns
private

Map of file name keys and connection values.

Definition at line 103 of file RootSvc.h.

◆ m_dictSvc

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

ServiceHandle to the dictionary service.

Definition at line 107 of file RootSvc.h.

◆ m_wconn

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

Definition at line 104 of file RootSvc.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AthService::AthService
AthService()
Athena::RootConnection
This class provides the implementation of Athena::RootConnection class, similar to Gaudi IDataConnect...
Definition: RootConnection.h:36
Guid::null
static const Guid & null()
NULL-Guid: static class method.
Definition: Guid.cxx:18
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
checkCorrelInHIST.conn
conn
Definition: checkCorrelInHIST.py:25
Athena::RootSvc::m_dictSvc
ServiceHandle< ::IDictLoaderSvc > m_dictSvc
ServiceHandle to the dictionary service.
Definition: RootSvc.h:107
pool::IFileCatalog::lookupFileByPFN
void lookupFileByPFN(const std::string &pfn, std::string &fid, std::string &tech) const
Get FID and filetype for a given PFN.
Placement::containerName
const std::string & containerName() const
Access container name.
Definition: Placement.h:32
Athena::RootSvc::m_catalog
pool::IFileCatalog * m_catalog
Definition: RootSvc.h:99
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Athena::RootSvc::m_conns
ConnMap_t m_conns
Map of file name keys and connection values.
Definition: RootSvc.h:103
pool::IFileCatalog::registerPFN
void registerPFN(const std::string &pfn, const std::string &ftype, std::string &fid)
Register PFN, assign new FID if not given.
initialize
void initialize()
Definition: run_EoverP.cxx:894
Athena::RootConnection::commit
StatusCode commit()
Commit data stream to ROOT.
Definition: RootConnection.cxx:96
Guid::toString
const std::string toString() const
Automatic conversion to string representation.
Definition: Guid.cxx:58
pool::IFileCatalog::commit
void commit()
Save catalog to file.
Definition: IFileCatalog.h:49
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
Athena::RootConnection::write
StatusCode write(const void *data, unsigned long &len)
Write root byte buffer to output stream.
Definition: RootConnection.cxx:130
pool::IFileCatalog
Definition: IFileCatalog.h:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IRootSvc::interfaceID
static const InterfaceID & interfaceID()
Retrieve interface ID.
Definition: IRootSvc.h:37
Athena::RootSvc::m_wconn
Athena::RootConnection * m_wconn
Definition: RootSvc.h:104
pool::IFileCatalog::start
void start()
redirect to init() for Gaudi FC
Definition: IFileCatalog.h:45
calibdata.exception
exception
Definition: calibdata.py:496
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
pool::IFileCatalog::setWriteCatalog
void setWriteCatalog(const std::string &connect)
Access to the (first) writable file catalog.
Athena::RootSvc::connection
Athena::RootConnection * connection(const std::string &fname)
Get the RootConnection associated with file fname
Definition: RootSvc.cxx:200
pool::IFileCatalog::connect
void connect()
Definition: IFileCatalog.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
Guid
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition: Guid.h:20
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Guid::fromString
const Guid & fromString(const std::string &s)
Automatic conversion from string representation.
Definition: Guid.cxx:65
Athena::RootConnection::setContainer
StatusCode setContainer(const std::string &container, const std::string &type)
Set the container name and type, creating TTree and TBranch as needed.
Definition: RootConnection.cxx:148
IRootSvc
This class provides the interface to the ROOT software.
Definition: IRootSvc.h:32