| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# PoolDbStatCnv.cpp

Go to the documentation of this file.

    00001 // $Id: PoolDbStatCnv.cpp,v 1.6 2008/10/27 16:41:33 marcocle 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 #include <memory>
    00024
    00025 // Standard Constructor
    00026 PoolDbStatCnv::PoolDbStatCnv (long typ,
    00027                               const CLID& clid,
    00028                               ISvcLocator* svc)
    00029 : PoolDbBaseCnv(typ, clid, svc)
    00030 {
    00031 }
    00032
    00033 // Retrieve the name of the container a given object is placed into
    00034 const std::string PoolDbStatCnv::containerName(IRegistry* pReg) const {
    00035   const std::string& path = pReg->identifier();
    00036   long loc = path.find('/',1);
    00037   std::string local = "<local>";
    00038   if ( loc > 0 )  {
    00039     loc = path.find('/',++loc);
    00040     if ( loc > 0 )  {
    00041       local += path.substr(loc,path.length()-loc);
    00042     }
    00043   }
    00044   return local;
    00045 }
    00046
    00047 const std::string PoolDbStatCnv::fileName(IRegistry* pReg) const {
    00048   std::string path = topLevel(pReg);
    00049   DataObject* pObj = 0;
    00050   dataProvider()->retrieveObject(path, pObj);
    00051   if ( pObj )  {
    00052     NTuple::File* fptr = dynamic_cast<NTuple::File*>(pObj);
    00053     if ( fptr )  {
    00054       return fptr->name();
    00055     }
    00056   }
    00057   return "";
    00058 }
    00059
    00061 const std::string PoolDbStatCnv::topLevel(IRegistry* pReg) const
    00062 {
    00063   if ( pReg )    {
    00064     std::string path = pReg->identifier();
    00065     size_t idx = path.find('/', 1);
    00066     if ( idx != std::string::npos )  {
    00067       idx = path.find('/', idx+1);
    00068       if ( idx != std::string::npos )  {
    00069         path = path.substr(0, idx);
    00070       }
    00071       return path;
    00072     }
    00073   }
    00074   return "";
    00075 }
    00076
    00077 StatusCode PoolDbStatCnv::saveDescription(const std::string&  path,
    00078                                           const std::string&  ident,
    00079                                           const std::string&  desc,
    00080                                           const std::string&  opt,
    00081                                           const pool::Guid&   guid,
    00082                                           const CLID&         clid,
    00083                                           const std::string&  openMode)
    00084 {
    00085   ROOT::Reflex::Type cl = pool::DbReflex::forTypeInfo(typeid(PoolDbNTupleDescriptor));
    00086   const pool::DbTypeInfo* info = pool::DbTypeInfo::create(cl.Name(ROOT::Reflex::SCOPED));
    00087   if ( info )  {
    00088     StatusCode status = m_dbMgr->connectOutput(path, openMode);
    00089     if ( status.isSuccess() )  {
    00090       std::auto_ptr<PoolDbNTupleDescriptor> dsc(new PoolDbNTupleDescriptor());
    00091       dsc->description = desc;
    00092       dsc->optional    = opt;
    00093       dsc->container   = ident;
    00094       dsc->guid        = guid.toString();
    00095       dsc->clid        = clid;
    00096       pool::DataCallBack* call=new pool::DbObjectCallBack(cl);
    00097       call->setShape(info);
    00098       call->setObject(dsc.release());
    00099       status = m_dbMgr->markWrite(call,"GaudiStatisticsDescription");
    00100       if ( status.isSuccess() ) {
    00101         status = m_dbMgr->commitOutput(path, true);
    00102       }
    00103     }
    00104     return status;
    00105   }
    00106   return StatusCode::FAILURE;
    00107 }