| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# PoolDbDataConnection.cpp

Go to the documentation of this file.

    00001 // $Id: PoolDbDataConnection.cpp,v 1.5 2008/10/27 16:41:33 marcocle Exp $
    00002 //====================================================================
    00003 //      PoolDbDataConnection implementation
    00004 //--------------------------------------------------------------------
    00005 //
    00006 //  Description: Implementation of the POOL data storage
    00007 //
    00008 //      Author     : M.Frank
    00009 //
    00010 //====================================================================
    00011 // $Id: PoolDbDataConnection.cpp,v 1.5 2008/10/27 16:41:33 marcocle Exp $
    00012
    00013 // FIXME: missing in CORAL
    00014 #include <algorithm>
    00015
    00016 // Framework include files
    00017 #include "GaudiPoolDb/PoolDbDataConnection.h"
    00018 #include "GaudiUtils/IIODataManager.h"
    00019 #include "StorageSvc/DbInstanceCount.h"
    00020 #include "GaudiKernel/strcasecmp.h"
    00021 #include <stdexcept>
    00022 #include <iostream>
    00023
    00024 using namespace pool;
    00025
    00026 static pool::DbInstanceCount::Counter* s_connectionCount =
    00027   pool::DbInstanceCount::getCounter(typeid(PoolDbDataConnection));
    00028
    00029 static inline bool isEqualMode(int mode, int flag)  {
    00030   return (mode&flag)==flag;
    00031 }
    00032
    00034 PoolDbDataConnection::PoolDbDataConnection(IInterface* own, const std::string& nam, int typ, int mode, DbDomain& domH)
    00035 : IDataConnection(own,nam), m_type(typ), m_mode(mode), m_domH(domH)
    00036 {
    00037   s_connectionCount->increment();
    00038   if ( typ == Gaudi::IIODataManager::FID && strncmp(nam.c_str(),"FID:",4) != 0 ) {
    00039     m_name = "FID:"+nam;
    00040   }
    00041 }
    00042
    00044 PoolDbDataConnection::~PoolDbDataConnection()         {
    00045   s_connectionCount->decrement();
    00046 }
    00047
    00049 StatusCode PoolDbDataConnection::i_connect()  {
    00050   DbAccessMode mode = (DbAccessMode)m_mode;
    00051   bool open_existing = isEqualMode(mode,pool::READ)||isEqualMode(mode,pool::UPDATE)||(1<<4);
    00052   m_dbH = DbDatabase(m_domH.find(fid()));
    00053   if ( !m_dbH.isValid() )  {
    00054     std::string true_fid;
    00055     pool::DbStatus sc = m_dbH.open(m_domH, pfn(), fid(), mode);
    00056     if ( sc.isSuccess() && open_existing )  {
    00057       m_dbH.param("FID",true_fid);
    00058       if ( fid() == pfn() ) {
    00059         m_fid = true_fid;
    00060         m_dbH.close();
    00061         sc = m_dbH.open(m_domH, pfn(), fid(), mode);
    00062       }
    00063       else if ( strcasecmp(true_fid.c_str(),fid().c_str()) != 0 )  {
    00064         m_dbH.close();
    00065         throw std::runtime_error("FID mismatch:\n\t\t\t\tFID="+
    00066                                  fid()+" (catalog) <> \n\t\t\t\t"+
    00067                                  true_fid+" (file) for PFN="+pfn());
    00068         return BAD_DATA_CONNECTION;
    00069       }
    00070     }
    00071     else if ( open_existing ) {
    00072       return BAD_DATA_CONNECTION;
    00073     }
    00074     return sc.isSuccess() ? StatusCode::SUCCESS : StatusCode::FAILURE;
    00075   }
    00076   return StatusCode::SUCCESS;
    00077 }
    00078
    00080 StatusCode PoolDbDataConnection::disconnect()  {
    00081   if ( m_dbH.isValid() )  {
    00082     m_dbH.close();
    00083     m_dbH = DbDatabase(pool::POOL_StorageType);
    00084     return StatusCode::SUCCESS;
    00085   }
    00086   return StatusCode::FAILURE;
    00087 }