![]() |
|
|
Generated: 18 Jul 2008 |
00001 // $Id: PoolDbStatCnv.cpp,v 1.5 2006/11/30 14:50:45 mato Exp $ 00002 //------------------------------------------------------------------------------ 00003 // 00004 // Implementation of class : PoolDbStatCnv 00005 // 00006 // Author : Markus Frank 00007 // 00008 //------------------------------------------------------------------------------ 00009 00010 // Include files 00011 #include "GaudiPoolDb/PoolDbStatCnv.h" 00012 #include "GaudiPoolDb/IPoolDbMgr.h" 00013 #include "GaudiPoolDb/PoolDbNTupleDescriptor.h" 00014 00015 #include "GaudiKernel/NTuple.h" 00016 #include "GaudiKernel/IRegistry.h" 00017 #include "GaudiKernel/IDataProviderSvc.h" 00018 #include "GaudiKernel/CnvFactory.h" 00019 #include "StorageSvc/DbReflex.h" 00020 #include "StorageSvc/DbTypeInfo.h" 00021 #include "StorageSvc/DbObjectCallBack.h" 00022 00023 // Standard Constructor 00024 PoolDbStatCnv::PoolDbStatCnv (long typ, 00025 const CLID& clid, 00026 ISvcLocator* svc) 00027 : PoolDbBaseCnv(typ, clid, svc) 00028 { 00029 } 00030 00031 // Retrieve the name of the container a given object is placed into 00032 const std::string PoolDbStatCnv::containerName(IRegistry* pReg) const { 00033 const std::string& path = pReg->identifier(); 00034 long loc = path.find('/',1); 00035 std::string local = "<local>"; 00036 if ( loc > 0 ) { 00037 loc = path.find('/',++loc); 00038 if ( loc > 0 ) { 00039 local += path.substr(loc,path.length()-loc); 00040 } 00041 } 00042 return local; 00043 } 00044 00045 const std::string PoolDbStatCnv::fileName(IRegistry* pReg) const { 00046 std::string path = topLevel(pReg); 00047 DataObject* pObj = 0; 00048 dataProvider()->retrieveObject(path, pObj); 00049 if ( pObj ) { 00050 NTuple::File* fptr = dynamic_cast<NTuple::File*>(pObj); 00051 if ( fptr ) { 00052 return fptr->name(); 00053 } 00054 } 00055 return ""; 00056 } 00057 00059 const std::string PoolDbStatCnv::topLevel(IRegistry* pReg) const 00060 { 00061 if ( pReg ) { 00062 std::string path = pReg->identifier(); 00063 size_t idx = path.find('/', 1); 00064 if ( idx != std::string::npos ) { 00065 idx = path.find('/', idx+1); 00066 if ( idx != std::string::npos ) { 00067 path = path.substr(0, idx); 00068 } 00069 return path; 00070 } 00071 } 00072 return ""; 00073 } 00074 00075 StatusCode PoolDbStatCnv::saveDescription(const std::string& path, 00076 const std::string& ident, 00077 const std::string& desc, 00078 const std::string& opt, 00079 const pool::Guid& guid, 00080 const CLID& clid, 00081 const std::string& openMode) 00082 { 00083 ROOT::Reflex::Type cl = pool::DbReflex::forTypeInfo(typeid(PoolDbNTupleDescriptor)); 00084 const pool::DbTypeInfo* info = pool::DbTypeInfo::create(cl.Name(ROOT::Reflex::SCOPED)); 00085 if ( info ) { 00086 StatusCode status = m_dbMgr->connectOutput(path, openMode); 00087 if ( status.isSuccess() ) { 00088 std::auto_ptr<PoolDbNTupleDescriptor> dsc(new PoolDbNTupleDescriptor()); 00089 dsc->description = desc; 00090 dsc->optional = opt; 00091 dsc->container = ident; 00092 dsc->guid = guid.toString(); 00093 dsc->clid = clid; 00094 pool::DataCallBack* call=new pool::DbObjectCallBack(cl); 00095 call->setShape(info); 00096 call->setObject(dsc.release()); 00097 status = m_dbMgr->markWrite(call,"GaudiStatisticsDescription"); 00098 if ( status.isSuccess() ) { 00099 status = m_dbMgr->commitOutput(path, true); 00100 } 00101 } 00102 return status; 00103 } 00104 return StatusCode::FAILURE; 00105 }