Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "RootCnv/RootRefs.h"
00012 #include "RootCnv/RootStatCnv.h"
00013 #include "RootCnv/RootDataConnection.h"
00014 #include "GaudiKernel/NTuple.h"
00015 #include "GaudiKernel/IRegistry.h"
00016 #include "GaudiKernel/IDataManagerSvc.h"
00017 #include "TROOT.h"
00018 #include "TBranch.h"
00019 #include <memory>
00020
00021 using namespace std;
00022 using namespace Gaudi;
00023
00024
00025 RootStatCnv::RootStatCnv (long typ,const CLID& clid, ISvcLocator* svc, RootCnvSvc* mgr)
00026 : RootConverter(typ, clid, svc, mgr), m_dataMgr(0), m_log(0)
00027 {
00028 }
00029
00030
00031 StatusCode RootStatCnv::initialize() {
00032 StatusCode sc = RootConverter::initialize();
00033 if ( sc.isSuccess() ) {
00034 sc = dataProvider()->queryInterface(IDataManagerSvc::interfaceID(),(void**)&m_dataMgr);
00035 if ( !sc.isSuccess() ) {
00036 return makeError("Failed to access IDataManagerSvc interface.");
00037 }
00038 }
00039 if ( m_log ) delete m_log;
00040 m_log = new MsgStream(msgSvc(),System::typeinfoName(typeid(*this)));
00041 return sc;
00042 }
00043
00044
00045 StatusCode RootStatCnv::finalize() {
00046 if ( m_log ) {
00047 delete m_log;
00048 m_log = 0;
00049 }
00050 if ( m_dataMgr ) {
00051 m_dataMgr->release();
00052 m_dataMgr = 0;
00053 }
00054 return RootConverter::finalize();
00055 }
00056
00057
00058 const string RootStatCnv::containerName(IRegistry* pReg) const {
00059 const string& path = pReg->identifier();
00060 long loc = path.find('/',1);
00061 string local = "<local>";
00062
00063 if ( loc > 0 ) {
00064 loc = path.find('/',++loc);
00065 if ( loc > 0 ) {
00066 local += path.substr(loc,path.length()-loc);
00067 }
00068 }
00069
00070
00071 return local;
00072 }
00073
00074
00075 const string RootStatCnv::fileName(IRegistry* pReg) const {
00076 string path = topLevel(pReg);
00077 DataObject* pObj = 0;
00078 dataProvider()->retrieveObject(path, pObj);
00079 if ( pObj ) {
00080 NTuple::File* fptr = dynamic_cast<NTuple::File*>(pObj);
00081 if ( fptr ) {
00082 return fptr->name();
00083 }
00084 }
00085 return "";
00086 }
00087
00088
00089 const string RootStatCnv::topLevel(IRegistry* pReg) const {
00090 if ( pReg ) {
00091 string path = pReg->identifier();
00092 size_t idx = path.find('/', 1);
00093 if ( idx != string::npos ) {
00094 idx = path.find('/', idx+1);
00095 if ( idx != string::npos ) {
00096 path = path.substr(0, idx);
00097 }
00098 return path;
00099 }
00100 }
00101 return "";
00102 }
00103
00104
00105 StatusCode RootStatCnv::makeError(const std::string& msg, bool throw_exc) const {
00106 if ( m_log ) {
00107 log() << MSG::ERROR << msg << endmsg;
00108 }
00109 else {
00110 MsgStream l(msgSvc(),"RootConverter");
00111 l << MSG::ERROR << msg << endmsg;
00112 }
00113 if ( throw_exc ) {
00114 }
00115 return StatusCode::FAILURE;
00116 }
00117
00118
00119 StatusCode
00120 RootStatCnv::saveDescription(const string& path,
00121 const string& ident,
00122 const string& desc,
00123 const string& opt,
00124 const CLID& clid)
00125 {
00126 RootDataConnection* con = 0;
00127 StatusCode status = m_dbMgr->connectDatabase(path, IDataConnection::UPDATE, &con);
00128 if ( status.isSuccess() ) {
00129 TClass* cl = gROOT->GetClass("Gaudi::RootNTupleDescriptor",kTRUE);
00130 if ( cl ) {
00131 RootNTupleDescriptor* ptr;
00132 auto_ptr<RootNTupleDescriptor> dsc(ptr=new RootNTupleDescriptor());
00133 TBranch* b = con->getBranch("##Descriptors","GaudiStatisticsDescription",cl,ptr);
00134 if ( b ) {
00135 dsc->description = desc;
00136 dsc->optional = opt;
00137 dsc->container = ident;
00138 dsc->clid = clid;
00139 b->SetAddress(&ptr);
00140 int nb = b->Fill();
00141 if ( nb > 1 ) {
00142 log() << MSG::DEBUG << "Save description for " << ident << endmsg;
00143 return StatusCode::SUCCESS;
00144 }
00145 }
00146 return makeError("Failed to access ROOT branch GaudiStatisticsDescription");
00147 }
00148 return makeError("Failed to access TClass RootNTupleDescriptor");
00149 }
00150 return makeError("Failed to access Tuple file:"+path);
00151 }