The Gaudi Framework  master (37c0b60a)
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
21 #include <GaudiKernel/IRegistry.h>
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 
30 using namespace std;
31 using namespace Gaudi;
32 
33 // Standard Constructor
34 RootStatCnv::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();
52  return RootConverter::finalize();
53 }
54 
55 // Retrieve the name of the container a given object is placed into
56 const 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
71 const 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
83 const 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.
97 StatusCode 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.
109 StatusCode RootStatCnv::saveDescription( const string& path, const string& ident, const string& desc, const string& opt,
110  const CLID& clid ) {
111  RootDataConnection* con = nullptr;
113  if ( status.isSuccess() ) {
114  TClass* cl = gROOT->GetClass( "Gaudi::RootNTupleDescriptor", kTRUE );
115  if ( cl ) {
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 }
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
Converter::dataProvider
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
Definition: Converter.cpp:78
Gaudi::RootNTupleDescriptor::optional
std::string optional
Optional description.
Definition: RootRefs.h:91
NTuple::File
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:923
std::string
STL class.
Gaudi::RootNTupleDescriptor::clid
unsigned long clid
Class ID of the described object.
Definition: RootRefs.h:95
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
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:210
Gaudi::RootConverter::m_dbMgr
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:45
Gaudi::RootCnvSvc
Definition: RootCnvSvc.h:62
Gaudi::RootNTupleDescriptor
Definition: RootRefs.h:87
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
ISvcLocator
Definition: ISvcLocator.h:46
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
IRegistry
Definition: IRegistry.h:32
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:315
RootDataConnection.h
std::unique_ptr::reset
T reset(T... args)
Gaudi::RootConverter
Definition: RootConverter.h:42
Gaudi::RootDataConnection
Definition: RootDataConnection.h:112
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:56
StatusCode
Definition: StatusCode.h:65
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:109
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::RootStatCnv::m_log
std::unique_ptr< MsgStream > m_log
Reference to logger object.
Definition: RootStatCnv.h:45
Gaudi::IDataConnection::UPDATE
@ UPDATE
Definition: IIODataManager.h:49
Gaudi::RootNTupleDescriptor::description
std::string description
Description string.
Definition: RootRefs.h:89
NTuple.h
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
IRegistry.h
MsgStream
Definition: MsgStream.h:33
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Gaudi::RootStatCnv::finalize
StatusCode finalize() override
Finalize converter object.
Definition: RootStatCnv.cpp:49
Gaudi::RootStatCnv::log
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:48
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
RootRefs.h
gaudirun.l
dictionary l
Definition: gaudirun.py:583
NTuple::File::name
const std::string & name() const
Retrun physical file name.
Definition: NTuple.h:949
std
STL namespace.
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:83
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
Gaudi::RootStatCnv::m_dataMgr
SmartIF< IDataManagerSvc > m_dataMgr
Reference to data manager service to manipulate the TES.
Definition: RootStatCnv.h:43
RootStatCnv.h
DataObject
Definition: DataObject.h:36
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
GaudiConfig2.semantics.ident
ident
Definition: semantics.py:198
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:71
Converter::initialize
StatusCode initialize() override
Initialize the converter.
Definition: Converter.cpp:53
Converter::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:105
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::RootNTupleDescriptor::container
std::string container
Identifier of description.
Definition: RootRefs.h:93
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:326
std::unique_ptr
STL class.
Gaudi::RootStatCnv::initialize
StatusCode initialize() override
Initialize converter object.
Definition: RootStatCnv.cpp:38
IDataManagerSvc.h
Converter::finalize
StatusCode finalize() override
Initialize the converter.
Definition: Converter.cpp:60