Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 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
45 StatusCode RootStatCnv::finalize() {
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
120 RootStatCnv::saveDescription(const string& path,
121  const string& ident,
122  const string& desc,
123  const string& opt,
124  const CLID& clid)
125 {
126  RootDataConnection* con = 0;
127  StatusCode status = m_dbMgr->connectDatabase(path, IDataConnection::UPDATE, &con);
128  if ( status.isSuccess() ) {
129  TClass* cl = gROOT->GetClass("Gaudi::RootNTupleDescriptor",kTRUE);
130  if ( cl ) {
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 }

Generated at Wed Dec 4 2013 14:33:12 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004