| The Gaudi Framework v32r1 (f65d50dc)

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/RootStatCnv.h"
11 #include "GaudiKernel/IDataManagerSvc.h"
12 #include "GaudiKernel/IRegistry.h"
13 #include "GaudiKernel/NTuple.h"
14 #include "RootCnv/RootDataConnection.h"
15 #include "RootCnv/RootRefs.h"
16 #include "TBranch.h"
17 #include "TROOT.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 // Initialize converter object
28 StatusCode RootStatCnv::initialize() {
29 StatusCode sc = RootConverter::initialize();
30 if ( sc.isSuccess() ) {
31 m_dataMgr = dataProvider();
32 if ( !m_dataMgr ) { return makeError( "Failed to access IDataManagerSvc interface." ); }
33 }
34 m_log.reset( new MsgStream( msgSvc(), System::typeinfoName( typeid( *this ) ) ) );
35 return sc;
36 }
37
38 // Finalize converter object
39 StatusCode RootStatCnv::finalize() {
40 m_log.reset();
41 m_dataMgr.reset();
42 return RootConverter::finalize();
43 }
44
45 // Retrieve the name of the container a given object is placed into
46 const string RootStatCnv::containerName( IRegistry* pReg ) const {
47 const string& path = pReg->identifier();
48 long loc = path.find( '/', 1 );
49 string local = "<local>";
50 // local = "";
51 if ( loc > 0 ) {
52 loc = path.find( '/', ++loc );
53 if ( loc > 0 ) { local += path.substr( loc ); }
54 }
55 // for(size_t i=0; i<local.length();++i)
56 // if ( !isalnum(local[i])) local[i] = '_';
57 return local;
58 }
59
60 // Retrieve the name of the file a given object is placed into
61 const string RootStatCnv::fileName( IRegistry* pReg ) const {
62 string path = topLevel( pReg );
63 DataObject* pObj = nullptr;
64 dataProvider()->retrieveObject( path, pObj );
65 if ( pObj ) {
66 NTuple::File* fptr = dynamic_cast<NTuple::File*>( pObj );
67 if ( fptr ) { return fptr->name(); }
68 }
69 return "";
70 }
71
72 // Retrieve the full path of the file a given object is placed into
73 const string RootStatCnv::topLevel( IRegistry* pReg ) const {
74 if ( pReg ) {
75 string path = pReg->identifier();
76 size_t idx = path.find( '/', 1 );
77 if ( idx != string::npos ) {
78 idx = path.find( '/', idx + 1 );
79 if ( idx != string::npos ) { path = path.substr( 0, idx ); }
80 return path;
81 }
82 }
83 return "";
84 }
85
86 // Helper method to issue error messages.
87 StatusCode RootStatCnv::makeError( const std::string& msg, bool throw_exc ) const {
88 if ( m_log ) {
89 log() << MSG::ERROR << msg << endmsg;
90 } else {
91 MsgStream l( msgSvc(), "RootConverter" );
92 l << MSG::ERROR << msg << endmsg;
93 }
94 if ( throw_exc ) {}
95 return StatusCode::FAILURE;
96 }
97
98 // Save statistics object description.
99 StatusCode RootStatCnv::saveDescription( const string& path, const string& ident, const string& desc, const string& opt,
100 const CLID& clid ) {
101 RootDataConnection* con = nullptr;
102 StatusCode status = m_dbMgr->connectDatabase( path, IDataConnection::UPDATE, &con );
103 if ( status.isSuccess() ) {
104 TClass* cl = gROOT->GetClass( "Gaudi::RootNTupleDescriptor", kTRUE );
105 if ( cl ) {
106 RootNTupleDescriptor* ptr;
107 std::unique_ptr<RootNTupleDescriptor> dsc( ptr = new RootNTupleDescriptor() );
108 TBranch* b = con->getBranch( "##Descriptors", "GaudiStatisticsDescription", cl, ptr, 512, 0 );
109 if ( b ) {
110 dsc->description = desc;
111 dsc->optional = opt;
112 dsc->container = ident;
113 dsc->clid = clid;
114 b->SetAddress( &ptr );
115 int nb = b->Fill();
116 if ( nb > 1 ) {
117 log() << MSG::DEBUG << "Save description for " << ident << endmsg;
118 return StatusCode::SUCCESS;
119 }
120 }
121 return makeError( "Failed to access ROOT branch GaudiStatisticsDescription" );
122 }
123 return makeError( "Failed to access TClass RootNTupleDescriptor" );
124 }
125 return makeError( "Failed to access Tuple file:" + path );
126 }
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Gaudi::RootStatCnv::makeError
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
Definition: RootStatCnv.cpp:87
Gaudi::RootDataConnection::getBranch
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
Definition: RootDataConnection.h:303
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:932
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:73
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298
NTuple.h
Gaudi::RootConverter::m_dbMgr
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:35
Converter::initialize
StatusCode initialize() override
Initialize the converter.
Definition: Converter.cpp:43
MSG::DEBUG
Definition: IMessageSvc.h:15
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Gaudi::RootCnvSvc
Description:
Definition: RootCnvSvc.h:52
std
STL namespace.
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:194
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:61
Gaudi::RootStatCnv::m_dataMgr
SmartIF< IDataManagerSvc > m_dataMgr
Reference to data manager service to manipulate the TES.
Definition: RootStatCnv.h:33
NTuple::File::name
const std::string & name() const
Retrun physical file name.
Definition: NTuple.h:936
std::string
STL class.
Converter::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:95
Converter::finalize
StatusCode finalize() override
Initialize the converter.
Definition: Converter.cpp:50
Gaudi::RootNTupleDescriptor
Description:
Definition: extractEvt.C:98
Gaudi::RootNTupleDescriptor::optional
std::string optional
Optional description.
Definition: extractEvt.C:102
IDataManagerSvc.h
RootRefs.h
Gaudi::RootStatCnv::finalize
StatusCode finalize() override
Finalize converter object.
Definition: RootStatCnv.cpp:39
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::RootStatCnv::log
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:38
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:99
Gaudi::RootNTupleDescriptor::description
std::string description
Description string.
Definition: extractEvt.C:100
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
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
Gaudi::IDataConnection::UPDATE
Definition: IIODataManager.h:39
gaudirun.l
dictionary l
Definition: gaudirun.py:521
Converter::dataProvider
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
Definition: Converter.cpp:68
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
std::unique_ptr
STL class.
Gaudi::RootNTupleDescriptor::container
std::string container
Identifier of description.
Definition: extractEvt.C:104
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MSG::ERROR
Definition: IMessageSvc.h:15
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:86
RootStatCnv.h
Gaudi::RootNTupleDescriptor::clid
unsigned long clid
Class ID of the described object.
Definition: extractEvt.C:106
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:46
Gaudi::RootStatCnv::initialize
StatusCode initialize() override
Initialize converter object.
Definition: RootStatCnv.cpp:28
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:93
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
NTuple::File
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:910
Gaudi::RootConverter
Description: Definition of the ROOT data converter.
Definition: RootConverter.h:32