All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RootStatCnv.cpp
Go to the documentation of this file.
1 // $Id: RootStatCnv.cpp,v 1.6 2010-09-27 15:43:53 frankb Exp $
2 //------------------------------------------------------------------------------
3 //
4 // Implementation of class : RootStatCnv
5 //
6 // Author : Markus Frank
7 //
8 //------------------------------------------------------------------------------
9 
10 // Include files
11 #include "RootCnv/RootRefs.h"
12 #include "RootCnv/RootStatCnv.h"
14 #include "GaudiKernel/NTuple.h"
15 #include "GaudiKernel/IRegistry.h"
17 #include "TROOT.h"
18 #include "TBranch.h"
19 #include <memory>
20 
21 using namespace std;
22 using namespace Gaudi;
23 
24 // Standard Constructor
25 RootStatCnv::RootStatCnv (long typ,const CLID& clid, ISvcLocator* svc, RootCnvSvc* mgr)
26 : RootConverter(typ, clid, svc, mgr), m_dataMgr(0), m_log(0)
27 {
28 }
29 
30 // Initialize converter object
33  if ( sc.isSuccess() ) {
34  sc = dataProvider()->queryInterface(IDataManagerSvc::interfaceID(),(void**)&m_dataMgr);
35  if ( !sc.isSuccess() ) {
36  return makeError("Failed to access IDataManagerSvc interface.");
37  }
38  }
39  if ( m_log ) delete m_log;
40  m_log = new MsgStream(msgSvc(),System::typeinfoName(typeid(*this)));
41  return sc;
42 }
43 
44 // Finalize converter object
46  if ( m_log ) {
47  delete m_log;
48  m_log = 0;
49  }
50  if ( m_dataMgr ) {
51  m_dataMgr->release();
52  m_dataMgr = 0;
53  }
54  return RootConverter::finalize();
55 }
56 
57 // Retrieve the name of the container a given object is placed into
58 const string RootStatCnv::containerName(IRegistry* pReg) const {
59  const string& path = pReg->identifier();
60  long loc = path.find('/',1);
61  string local = "<local>";
62  //local = "";
63  if ( loc > 0 ) {
64  loc = path.find('/',++loc);
65  if ( loc > 0 ) {
66  local += path.substr(loc,path.length()-loc);
67  }
68  }
69  //for(size_t i=0; i<local.length();++i)
70  // if ( !isalnum(local[i])) local[i] = '_';
71  return local;
72 }
73 
74 // Retrieve the name of the file a given object is placed into
75 const string RootStatCnv::fileName(IRegistry* pReg) const {
76  string path = topLevel(pReg);
77  DataObject* pObj = 0;
78  dataProvider()->retrieveObject(path, pObj);
79  if ( pObj ) {
80  NTuple::File* fptr = dynamic_cast<NTuple::File*>(pObj);
81  if ( fptr ) {
82  return fptr->name();
83  }
84  }
85  return "";
86 }
87 
88 // Retrieve the full path of the file a given object is placed into
89 const string RootStatCnv::topLevel(IRegistry* pReg) const {
90  if ( pReg ) {
91  string path = pReg->identifier();
92  size_t idx = path.find('/', 1);
93  if ( idx != string::npos ) {
94  idx = path.find('/', idx+1);
95  if ( idx != string::npos ) {
96  path = path.substr(0, idx);
97  }
98  return path;
99  }
100  }
101  return "";
102 }
103 
104 // Helper method to issue error messages.
105 StatusCode RootStatCnv::makeError(const std::string& msg, bool throw_exc) const {
106  if ( m_log ) {
107  log() << MSG::ERROR << msg << endmsg;
108  }
109  else {
110  MsgStream l(msgSvc(),"RootConverter");
111  l << MSG::ERROR << msg << endmsg;
112  }
113  if ( throw_exc ) {
114  }
115  return StatusCode::FAILURE;
116 }
117 
118 // Save statistics object description.
119 StatusCode
121  const string& ident,
122  const string& desc,
123  const string& opt,
124  const CLID& clid)
125 {
126  RootDataConnection* con = 0;
128  if ( status.isSuccess() ) {
129  TClass* cl = gROOT->GetClass("Gaudi::RootNTupleDescriptor",kTRUE);
130  if ( cl ) {
132  auto_ptr<RootNTupleDescriptor> dsc(ptr=new RootNTupleDescriptor());
133  TBranch* b = con->getBranch("##Descriptors","GaudiStatisticsDescription",cl,ptr,512,0);
134  if ( b ) {
135  dsc->description = desc;
136  dsc->optional = opt;
137  dsc->container = ident;
138  dsc->clid = clid;
139  b->SetAddress(&ptr);
140  int nb = b->Fill();
141  if ( nb > 1 ) {
142  log() << MSG::DEBUG << "Save description for " << ident << endmsg;
143  return StatusCode::SUCCESS;
144  }
145  }
146  return makeError("Failed to access ROOT branch GaudiStatisticsDescription");
147  }
148  return makeError("Failed to access TClass RootNTupleDescriptor");
149  }
150  return makeError("Failed to access Tuple file:"+path);
151 }
const std::string & name() const
Retrun physical file name.
Definition: NTuple.h:1122
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:39
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:26
virtual StatusCode finalize()
Initialize the converter.
Definition: Converter.cpp:76
virtual StatusCode finalize()
Finalize converter object.
Definition: RootStatCnv.cpp:45
virtual const std::string topLevel(IRegistry *pReg) const
Retrieve the full path of the file a given object is placed into.
Definition: RootStatCnv.cpp:89
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298
virtual StatusCode initialize()
Initialize the converter.
Definition: Converter.cpp:67
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:37
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:131
Description:
Definition: RootCnvSvc.h:54
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:224
std::string optional
Optional description.
Definition: RootRefs.h:103
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
Definition: RootStatCnv.cpp:75
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:101
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
string opt
print 'Summary: %32s [s] d d steps'%(summary.protocol,summary.type,summary.nevt,len(summary.data),)
Definition: ana.py:116
unsigned int CLID
Class ID definition.
Definition: ClassID.h:9
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
dictionary l
Definition: gaudirun.py:365
virtual SmartIF< IDataProviderSvc > & dataProvider() const
Get Data provider service.
Definition: Converter.cpp:94
virtual unsigned long release()=0
Release Interface instance.
std::string container
Identifier of description.
Definition: RootRefs.h:105
virtual const id_type & identifier() const =0
Full identifier (or key)
unsigned long clid
Class ID of the described object.
Definition: RootRefs.h:107
MsgStream * m_log
Reference to logger object.
Definition: RootStatCnv.h:36
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
virtual StatusCode initialize()
Initialize converter object.
Definition: RootStatCnv.cpp:31
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Definition: RootStatCnv.cpp:58
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
Concrete implementation of the IDataConnection interface to access ROOT files.
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:171
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
IDataManagerSvc * m_dataMgr
Reference to data manager service to manipulate the TES.
Definition: RootStatCnv.h:34
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:1085
Description: Definition of the ROOT data converter.
Definition: RootConverter.h:33