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