| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

RootStatCnv.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 //
3 // Implementation of class : RootStatCnv
4 //
5 // Author : Markus Frank
6 //
7 //------------------------------------------------------------------------------
8
9 // Include files
10 #include "RootCnv/RootRefs.h"
11 #include "RootCnv/RootStatCnv.h"
12 #include "RootCnv/RootDataConnection.h"
13 #include "GaudiKernel/NTuple.h"
14 #include "GaudiKernel/IRegistry.h"
15 #include "GaudiKernel/IDataManagerSvc.h"
16 #include "TROOT.h"
17 #include "TBranch.h"
18 #include <memory>
19
20 using namespace std;
21 using namespace Gaudi;
22
23 // Standard Constructor
24 RootStatCnv::RootStatCnv (long typ,const CLID& clid, ISvcLocator* svc, RootCnvSvc* mgr)
25 : RootConverter(typ, clid, svc, mgr)
26 {
27 }
28
29 // Initialize converter object
30 StatusCode RootStatCnv::initialize() {
31 StatusCode sc = RootConverter::initialize();
32 if ( sc.isSuccess() ) {
33 m_dataMgr = dataProvider();
34 if ( !m_dataMgr ) {
35 return makeError("Failed to access IDataManagerSvc interface.");
36 }
37 }
38 m_log.reset( new MsgStream(msgSvc(),System::typeinfoName(typeid(*this))) );
39 return sc;
40 }
41
42 // Finalize converter object
43 StatusCode RootStatCnv::finalize() {
44 m_log.reset();
45 m_dataMgr.reset();
46 return RootConverter::finalize();
47 }
48
49 // Retrieve the name of the container a given object is placed into
50 const string RootStatCnv::containerName(IRegistry* pReg) const {
51 const string& path = pReg->identifier();
52 long loc = path.find('/',1);
53 string local = "<local>";
54 //local = "";
55 if ( loc > 0 ) {
56 loc = path.find('/',++loc);
57 if ( loc > 0 ) {
58 local += path.substr(loc);
59 }
60 }
61 //for(size_t i=0; i<local.length();++i)
62 // if ( !isalnum(local[i])) local[i] = '_';
63 return local;
64 }
65
66 // Retrieve the name of the file a given object is placed into
67 const string RootStatCnv::fileName(IRegistry* pReg) const {
68 string path = topLevel(pReg);
69 DataObject* pObj = nullptr;
70 dataProvider()->retrieveObject(path, pObj);
71 if ( pObj ) {
72 NTuple::File* fptr = dynamic_cast<NTuple::File*>(pObj);
73 if ( fptr ) {
74 return fptr->name();
75 }
76 }
77 return "";
78 }
79
80 // Retrieve the full path of the file a given object is placed into
81 const string RootStatCnv::topLevel(IRegistry* pReg) const {
82 if ( pReg ) {
83 string path = pReg->identifier();
84 size_t idx = path.find('/', 1);
85 if ( idx != string::npos ) {
86 idx = path.find('/', idx+1);
87 if ( idx != string::npos ) {
88 path = path.substr(0, idx);
89 }
90 return path;
91 }
92 }
93 return "";
94 }
95
96 // Helper method to issue error messages.
97 StatusCode RootStatCnv::makeError(const std::string& msg, bool throw_exc) const {
98 if ( m_log ) {
99 log() << MSG::ERROR << msg << endmsg;
100 }
101 else {
102 MsgStream l(msgSvc(),"RootConverter");
103 l << MSG::ERROR << msg << endmsg;
104 }
105 if ( throw_exc ) {
106 }
107 return StatusCode::FAILURE;
108 }
109
110 // Save statistics object description.
111 StatusCode
112 RootStatCnv::saveDescription(const string& path,
113 const string& ident,
114 const string& desc,
115 const string& opt,
116 const CLID& clid)
117 {
118 RootDataConnection* con = nullptr;
119 StatusCode status = m_dbMgr->connectDatabase(path, IDataConnection::UPDATE, &con);
120 if ( status.isSuccess() ) {
121 TClass* cl = gROOT->GetClass("Gaudi::RootNTupleDescriptor",kTRUE);
122 if ( cl ) {
123 RootNTupleDescriptor* ptr;
124 std::unique_ptr<RootNTupleDescriptor> dsc(ptr=new RootNTupleDescriptor());
125 TBranch* b = con->getBranch("##Descriptors","GaudiStatisticsDescription",cl,ptr,512,0);
126 if ( b ) {
127 dsc->description = desc;
128 dsc->optional = opt;
129 dsc->container = ident;
130 dsc->clid = clid;
131 b->SetAddress(&ptr);
132 int nb = b->Fill();
133 if ( nb > 1 ) {
134 log() << MSG::DEBUG << "Save description for " << ident << endmsg;
135 return StatusCode::SUCCESS;
136 }
137 }
138 return makeError("Failed to access ROOT branch GaudiStatisticsDescription");
139 }
140 return makeError("Failed to access TClass RootNTupleDescriptor");
141 }
142 return makeError("Failed to access Tuple file:"+path);
143 }
NTuple::File::name
const std::string & name() const
Retrun physical file name.
Definition: NTuple.h:1124
Gaudi::RootStatCnv::log
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:38
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode::SUCCESS
Definition: StatusCode.h:30
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:772
StatusCode::FAILURE
Definition: StatusCode.h:29
Gaudi::RootStatCnv::topLevel
virtual const std::string topLevel(IRegistry *pReg) const
Retrieve the full path of the file a given object is placed into.
Definition: RootStatCnv.cpp:81
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
NTuple.h
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
Gaudi::RootConverter::m_dbMgr
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:36
Converter::initialize
StatusCode initialize() override
Initialize the converter.
Definition: Converter.cpp:65
MSG::DEBUG
Definition: IMessageSvc.h:18
Converter::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:129
Gaudi::RootCnvSvc
Description:
Definition: RootCnvSvc.h:53
std
STL namespace.
Gaudi::RootStatCnv::makeError
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
Definition: RootStatCnv.cpp:97
Gaudi::RootCnvSvc::connectDatabase
StatusCode connectDatabase(const std::string &dataset, int mode, RootDataConnection **con)
Connect the output file to the service with open mode.
Definition: RootCnvSvc.cpp:207
Gaudi::RootStatCnv::m_dataMgr
SmartIF< IDataManagerSvc > m_dataMgr
Reference to data manager service to manipulate the TES.
Definition: RootStatCnv.h:33
std::string
STL class.
Converter::finalize
StatusCode finalize() override
Initialize the converter.
Definition: Converter.cpp:74
Gaudi::RootNTupleDescriptor
Description:
Definition: RootRefs.h:77
Gaudi::RootNTupleDescriptor::optional
std::string optional
Optional description.
Definition: RootRefs.h:81
IDataManagerSvc.h
RootRefs.h
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
Gaudi::RootStatCnv::finalize
StatusCode finalize() override
Finalize converter object.
Definition: RootStatCnv.cpp:43
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Gaudi::RootStatCnv::fileName
virtual const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
Definition: RootStatCnv.cpp:67
Gaudi::RootDataConnection::getBranch
TBranch * getBranch(const std::string &section, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
Definition: RootDataConnection.h:307
Gaudi::RootStatCnv::saveDescription
StatusCode saveDescription(const std::string &path, const std::string &ident, const std::string &desc, const std::string &opt, const CLID &clid)
Save statistics object description.
Definition: RootStatCnv.cpp:112
Gaudi::RootNTupleDescriptor::description
std::string description
Description string.
Definition: RootRefs.h:79
IRegistry.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
RootDataConnection.h
std::unique_ptr::reset
T reset(T...args)
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
Gaudi::IDataConnection::UPDATE
Definition: IIODataManager.h:38
gaudirun.l
dictionary l
Definition: gaudirun.py:421
std::string::find
T find(T...args)
Converter::dataProvider
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
Definition: Converter.cpp:92
std::unique_ptr
STL class.
Gaudi::RootNTupleDescriptor::container
std::string container
Identifier of description.
Definition: RootRefs.h:83
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
MSG::ERROR
Definition: IMessageSvc.h:21
std::string::substr
T substr(T...args)
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
RootStatCnv.h
Gaudi::RootNTupleDescriptor::clid
unsigned long clid
Class ID of the described object.
Definition: RootRefs.h:85
Gaudi::RootStatCnv::m_log
std::unique_ptr< MsgStream > m_log
Reference to logger object.
Definition: RootStatCnv.h:35
Gaudi::RootStatCnv::containerName
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Definition: RootStatCnv.cpp:50
Gaudi::RootStatCnv::initialize
StatusCode initialize() override
Initialize converter object.
Definition: RootStatCnv.cpp:30
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Gaudi::RootDataConnection
Concrete implementation of the IDataConnection interface to access ROOT files.
Definition: RootDataConnection.h:92
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
NTuple::File
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:1088
Gaudi::RootConverter
Description: Definition of the ROOT data converter.
Definition: RootConverter.h:32
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.