| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines