The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
RootStatCnv.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11//------------------------------------------------------------------------------
12//
13// Implementation of class : RootStatCnv
14//
15// Author : Markus Frank
16//
17//------------------------------------------------------------------------------
18
19// Include files
22#include <GaudiKernel/NTuple.h>
24#include <RootCnv/RootRefs.h>
25#include <RootCnv/RootStatCnv.h>
26#include <TBranch.h>
27#include <TROOT.h>
28#include <memory>
29
30using namespace std;
31using namespace Gaudi;
32
33// Standard Constructor
34RootStatCnv::RootStatCnv( long typ, const CLID& clid, ISvcLocator* svc, RootCnvSvc* mgr )
35 : RootConverter( typ, clid, svc, mgr ) {}
36
37// Initialize converter object
40 if ( sc.isSuccess() ) {
42 if ( !m_dataMgr ) { return makeError( "Failed to access IDataManagerSvc interface." ); }
43 }
44 m_log.reset( new MsgStream( msgSvc(), System::typeinfoName( typeid( *this ) ) ) );
45 return sc;
46}
47
48// Finalize converter object
50 m_log.reset();
51 m_dataMgr.reset();
53}
54
55// Retrieve the name of the container a given object is placed into
56const string RootStatCnv::containerName( IRegistry* pReg ) const {
57 const string& path = pReg->identifier();
58 long loc = path.find( '/', 1 );
59 string local = "<local>";
60 // local = "";
61 if ( loc > 0 ) {
62 loc = path.find( '/', ++loc );
63 if ( loc > 0 ) { local += path.substr( loc ); }
64 }
65 // for(size_t i=0; i<local.length();++i)
66 // if ( !isalnum(local[i])) local[i] = '_';
67 return local;
68}
69
70// Retrieve the name of the file a given object is placed into
71const string RootStatCnv::fileName( IRegistry* pReg ) const {
72 string path = topLevel( pReg );
73 DataObject* pObj = nullptr;
74 dataProvider()->retrieveObject( path, pObj ).ignore();
75 if ( pObj ) {
76 NTuple::File* fptr = dynamic_cast<NTuple::File*>( pObj );
77 if ( fptr ) { return fptr->name(); }
78 }
79 return "";
80}
81
82// Retrieve the full path of the file a given object is placed into
83const string RootStatCnv::topLevel( IRegistry* pReg ) const {
84 if ( pReg ) {
85 string path = pReg->identifier();
86 size_t idx = path.find( '/', 1 );
87 if ( idx != string::npos ) {
88 idx = path.find( '/', idx + 1 );
89 if ( idx != string::npos ) { path.resize( idx ); }
90 return path;
91 }
92 }
93 return "";
94}
95
96// Helper method to issue error messages.
97StatusCode RootStatCnv::makeError( const std::string& msg, bool throw_exc ) const {
98 if ( m_log ) {
99 log() << MSG::ERROR << msg << endmsg;
100 } else {
101 MsgStream l( msgSvc(), "RootConverter" );
102 l << MSG::ERROR << msg << endmsg;
103 }
104 if ( throw_exc ) {}
105 return StatusCode::FAILURE;
106}
107
108// Save statistics object description.
109StatusCode RootStatCnv::saveDescription( const string& path, const string& ident, const string& desc, const string& opt,
110 const CLID& clid ) {
111 RootDataConnection* con = nullptr;
112 StatusCode status = m_dbMgr->connectDatabase( path, IDataConnection::UPDATE, &con );
113 if ( status.isSuccess() ) {
114 TClass* cl = gROOT->GetClass( "Gaudi::RootNTupleDescriptor", kTRUE );
115 if ( cl ) {
117 std::unique_ptr<RootNTupleDescriptor> dsc( ptr = new RootNTupleDescriptor() );
118 TBranch* b = con->getBranch( "##Descriptors", "GaudiStatisticsDescription", cl, ptr, 512, 0 );
119 if ( b ) {
120 dsc->description = desc;
121 dsc->optional = opt;
122 dsc->container = ident;
123 dsc->clid = clid;
124 b->SetAddress( &ptr );
125 int nb = b->Fill();
126 if ( nb > 1 ) {
127 log() << MSG::DEBUG << "Save description for " << ident << endmsg;
128 return StatusCode::SUCCESS;
129 }
130 }
131 return makeError( "Failed to access ROOT branch GaudiStatisticsDescription" );
132 }
133 return makeError( "Failed to access TClass RootNTupleDescriptor" );
134 }
135 return makeError( "Failed to access Tuple file:" + path );
136}
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
StatusCode initialize() override
Initialize the converter.
Definition Converter.cpp:52
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
Definition Converter.cpp:77
StatusCode finalize() override
Initialize the converter.
Definition Converter.cpp:59
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
Description:
Definition RootCnvSvc.h:61
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
RootConverter(long typ, const CLID &clid, ISvcLocator *svc, RootCnvSvc *mgr)
Initializing Constructor.
Concrete implementation of the IDataConnection interface to access ROOT files.
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
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.
virtual const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
StatusCode initialize() override
Initialize converter object.
StatusCode finalize() override
Finalize converter object.
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
MsgStream & log() const
Helper to use mesage logger.
Definition RootStatCnv.h:47
SmartIF< IDataManagerSvc > m_dataMgr
Reference to data manager service to manipulate the TES.
Definition RootStatCnv.h:42
RootStatCnv(long typ, const CLID &clid, ISvcLocator *svc, RootCnvSvc *mgr)
Initializing Constructor.
virtual const std::string topLevel(IRegistry *pReg) const
Retrieve the full path of the file a given object is placed into.
std::unique_ptr< MsgStream > m_log
Reference to logger object.
Definition RootStatCnv.h:44
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
virtual const id_type & identifier() const =0
Full identifier (or key)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
Small class representing an N tuple file in the transient store.
Definition NTuple.h:915
const std::string & name() const
Retrun physical file name.
Definition NTuple.h:941
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
@ DEBUG
Definition IMessageSvc.h:22
@ ERROR
Definition IMessageSvc.h:22
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:260
STL namespace.