| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# PoolDbDirectoryCnv.cpp

Go to the documentation of this file.

    00001 // $Id: PoolDbDirectoryCnv.cpp,v 1.8 2008/10/27 16:41:33 marcocle Exp $
    00002 //------------------------------------------------------------------------------
    00003 //
    00004 // Implementation of class :  PoolDbDirectoryCnv
    00005 //
    00006 // Author :                   Markus Frank
    00007 //
    00008 //------------------------------------------------------------------------------
    00009
    00010 // FIXME: Missing in CORAL
    00011 #include <algorithm>
    00012
    00013 #include <memory>
    00014
    00015 // Include files
    00016 #include "GaudiPoolDb/IPoolDbMgr.h"
    00017 #include "GaudiPoolDb/PoolDbDirectoryCnv.h"
    00018 #include "GaudiPoolDb/PoolDbNTupleDescriptor.h"
    00019 #include "GaudiKernel/IOpaqueAddress.h"
    00020 #include "GaudiKernel/IDataManagerSvc.h"
    00021 #include "GaudiKernel/MsgStream.h"
    00022 #include "GaudiKernel/IRegistry.h"
    00023 #include "GaudiKernel/NTuple.h"
    00024 #include "GaudiKernel/CnvFactory.h"
    00025
    00026 #include "StorageSvc/DbReflex.h"
    00027 #include "StorageSvc/DbSelect.h"
    00028 #include "StorageSvc/DbObjectCallBack.h"
    00029
    00030 // Factory declaration
    00031
    00032 PLUGINSVC_FACTORY_WITH_ID( PoolDbDirectoryCnv,
    00033                            ConverterID(POOL_StorageType,CLID_StatisticsDirectory),
    00034                            IConverter*(long, CLID, ISvcLocator*) );
    00035
    00036
    00037 // Standard Constructor
    00038 PoolDbDirectoryCnv::PoolDbDirectoryCnv (long typ,
    00039                                         const CLID& clid,
    00040                                         ISvcLocator* svc)
    00041 : PoolDbStatCnv(typ, clid, svc)
    00042 {
    00043 }
    00044
    00046 StatusCode
    00047 PoolDbDirectoryCnv::createObj(IOpaqueAddress* /* pAddress */,
    00048                               DataObject*&       refpObject   )
    00049 {
    00050   refpObject = new NTuple::Directory();
    00051   return StatusCode::SUCCESS;
    00052 }
    00053
    00054 StatusCode
    00055 PoolDbDirectoryCnv::createRep(DataObject* pObject,
    00056                               IOpaqueAddress*& /* refpAddress */)
    00057 {
    00058   std::string dsc;
    00059   pool::Guid guid(pool::Guid::null());
    00060   guid.Data1 = objType();
    00061
    00062   if ( objType() == CLID_StatisticsDirectory )  {
    00063     dsc = "Directory containing statistics results.";
    00064   }
    00065   else if ( objType() == CLID_StatisticsFile )  {
    00066     dsc = "File containing statistics results.";
    00067   }
    00068   else  {
    00069     return StatusCode::FAILURE;
    00070   }
    00071   std::string ident = containerName(pObject->registry());
    00072   std::string path  = fileName(pObject->registry());
    00073   return saveDescription(path, ident, dsc, "", guid, objType(), "UPDATE");
    00074 }
    00075
    00076 // Fill transient object references
    00077 StatusCode
    00078 PoolDbDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr, DataObject* pObj)
    00079 {
    00080   return updateObjRefs(pAddr, pObj);
    00081 }
    00082
    00083 StatusCode
    00084 PoolDbDirectoryCnv::updateObjRefs(IOpaqueAddress* pAddr,
    00085                                  DataObject* pObject)
    00086 {
    00087   typedef std::vector<PoolDbNTupleDescriptor*> REFS;
    00088   REFS refs;
    00089   StatusCode status = StatusCode(StatusCode::FAILURE,true);
    00090   MsgStream log(msgSvc(), "PoolDbDatabaseCnv");
    00091   if ( pAddr ) {
    00092     IRegistry* pReg = pAddr->registry();
    00093     if ( pReg )  {
    00094       std::string ident   = pReg->identifier();
    00095       std::string fname   = fileName(pReg);
    00096       std::string cntName = containerName(pReg);
    00097       std::auto_ptr<pool::DbSelect> iter(m_dbMgr->createSelect("*", fname, "GaudiStatisticsDescription"));
    00098       if ( iter.get() )  {
    00099         pool::DbObjectCallBack cb(pool::DbReflex::forTypeName("PoolDbNTupleDescriptor"));
    00100         typedef std::vector<IRegistry*> Leaves;
    00101         pool::Token* token = 0;
    00102         Leaves leaves;
    00103         while( iter->next(token).isSuccess() )  {
    00104           m_dbMgr->read(&cb, *token).ignore();
    00105           PoolDbNTupleDescriptor* ref = (PoolDbNTupleDescriptor*)cb.object();
    00106           std::string s = ref->container.substr(0,cntName.length());
    00107           if ( s == cntName )  {
    00108             if ( ref->container.length() > cntName.length()+1 )  {
    00109               if ( ref->container.find('/',cntName.length()+1) == std::string::npos ) {
    00110                 refs.push_back(ref);
    00111                 token->release();
    00112                 continue;
    00113               }
    00114             }
    00115           }
    00116           delete ref;
    00117           token->release();
    00118         }
    00119         status = m_dataMgr->objectLeaves(pObject, leaves);
    00120         if ( status.isSuccess() )    {
    00121           for(REFS::iterator i = refs.begin(); i != refs.end(); ++i)  {
    00122             REFS::value_type& ref = *i;
    00123             if ( ref )   {
    00124               bool need_to_add = true;
    00125               for(Leaves::iterator j=leaves.begin(); j != leaves.end(); ++j )  {
    00126                 std::string curr_leaf = containerName(*j);
    00127                 if ( curr_leaf == ref->container )  {
    00128                   need_to_add = false;
    00129                   break;
    00130                 }
    00131               }
    00132               if ( need_to_add )  {
    00133                 IOpaqueAddress* pA= 0;
    00134                 if ( ref->clid == CLID_StatisticsDirectory ||
    00135                      ref->clid == CLID_StatisticsFile      ||
    00136                      ref->clid == CLID_RowWiseTuple        ||
    00137                      ref->clid == CLID_ColumnWiseTuple      )
    00138                 {
    00139                   std::string spar[]   = { fname, ref->container};
    00140                   unsigned long ipar[] = { pool::INVALID, pool::INVALID};
    00141                   status = m_dbMgr->createAddress(repSvcType(),
    00142                                                   ref->clid,
    00143                                                   spar,
    00144                                                   ipar,
    00145                                                   pA);
    00146                 }
    00147                 if ( status.isSuccess() )  {
    00148                   std::string top = topLevel(pReg);
    00149                   std::string leaf_name = top + ref->container.substr(7);
    00150                   status = m_dataMgr->registerAddress(leaf_name, pA);
    00151                   if ( status.isSuccess() )  {
    00152                     continue;
    00153                   }
    00154                   makeError("Failed to register leaves to directory:"+ident,false).ignore();
    00155                   break;
    00156                 }
    00157                 makeError("Failed to create leave address to directory:"+ident,false).ignore();
    00158                 break;
    00159               }
    00160             }
    00161             makeError("Failed to add leaves to directory:"+ident,false).ignore();
    00162             break;
    00163           }
    00164         }
    00165       }
    00166       else  {
    00167         return makeError("Failed to access required tuple data description.",false);
    00168       }
    00169     }
    00170   }
    00171   for(REFS::iterator k = refs.begin(); k != refs.end(); ++k)  {
    00172     if ( *k ) delete (*k);
    00173   }
    00174   return status;
    00175 }
    00176
    00178 StatusCode
    00179 PoolDbDirectoryCnv::updateObj(IOpaqueAddress* /* pAddr */,
    00180                               DataObject*     /* pObj */)
    00181 {
    00182   return StatusCode::SUCCESS;
    00183 }
    00184
    00186 StatusCode
    00187 PoolDbDirectoryCnv::updateRep(IOpaqueAddress* /* pAddr */,
    00188                               DataObject*     /* pObj */)
    00189 {
    00190   return StatusCode::SUCCESS;
    00191 }
    00192
    00194 StatusCode
    00195 PoolDbDirectoryCnv::updateRepRefs(IOpaqueAddress* /* pAddr */,
    00196                                   DataObject*     /* pObj */)
    00197 {
    00198   return StatusCode::SUCCESS;
    00199 }
    00200