| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# 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 #ifdef __ICC
    00012 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
    00013 //   TODO: To be removed, coming from CORAL
    00014 #pragma warning(disable:2259)
    00015 #endif
    00016
    00017 // FIXME: missing in CORAL
    00018 #include <algorithm>
    00019
    00020 // Framework include files
    00021 #include "GaudiPoolDb/PoolDbDataConnection.h"
    00022 #include "GaudiUtils/IIODataManager.h"
    00023 #include "StorageSvc/DbInstanceCount.h"
    00024 #include "GaudiKernel/strcasecmp.h"
    00025 #include <stdexcept>
    00026 #include <iostream>
    00027
    00028 using namespace pool;
    00029
    00030 static pool::DbInstanceCount::Counter* s_connectionCount =
    00031   pool::DbInstanceCount::getCounter(typeid(PoolDbDataConnection));
    00032
    00033 static inline bool isEqualMode(int mode, int flag)  {
    00034   return (mode&flag)==flag;
    00035 }
    00036
    00038 PoolDbDataConnection::PoolDbDataConnection(IInterface* own, const std::string& nam, int typ, int mode, DbDomain& domH)
    00039 : IDataConnection(own,nam), m_type(typ), m_mode(mode), m_domH(domH)
    00040 {
    00041   s_connectionCount->increment();
    00042   if ( typ == Gaudi::IIODataManager::FID && strncmp(nam.c_str(),"FID:",4) != 0 ) {
    00043     m_name = "FID:"+nam;
    00044   }
    00045 }
    00046
    00048 PoolDbDataConnection::~PoolDbDataConnection()         {
    00049   s_connectionCount->decrement();
    00050 }
    00051
    00053 StatusCode PoolDbDataConnection::i_connect()  {
    00054   DbAccessMode mode = (DbAccessMode)m_mode;
    00055   bool open_existing = isEqualMode(mode,pool::READ)||isEqualMode(mode,pool::UPDATE)||(1<<4);
    00056   m_dbH = DbDatabase(m_domH.find(fid()));
    00057   if ( !m_dbH.isValid() )  {
    00058     std::string true_fid;
    00059     pool::DbStatus sc = m_dbH.open(m_domH, pfn(), fid(), mode);
    00060     if ( sc.isSuccess() && open_existing )  {
    00061       m_dbH.param("FID",true_fid);
    00062       if ( fid() == pfn() ) {
    00063         m_fid = true_fid;
    00064         m_dbH.close();
    00065         sc = m_dbH.open(m_domH, pfn(), fid(), mode);
    00066       }
    00067       else if ( strcasecmp(true_fid.c_str(),fid().c_str()) != 0 )  {
    00068         m_dbH.close();
    00069         throw std::runtime_error("FID mismatch:\n\t\t\t\tFID="+
    00070                                  fid()+" (catalog) <> \n\t\t\t\t"+
    00071                                  true_fid+" (file) for PFN="+pfn());
    00072         return BAD_DATA_CONNECTION;
    00073       }
    00074     }
    00075     else if ( open_existing ) {
    00076       return BAD_DATA_CONNECTION;
    00077     }
    00078     return sc.isSuccess() ? StatusCode::SUCCESS : StatusCode::FAILURE;
    00079   }
    00080   return StatusCode::SUCCESS;
    00081 }
    00082
    00084 StatusCode PoolDbDataConnection::disconnect()  {
    00085   if ( m_dbH.isValid() )  {
    00086     m_dbH.close();
    00087     m_dbH = DbDatabase(pool::POOL_StorageType);
    00088     return StatusCode::SUCCESS;
    00089   }
    00090   return StatusCode::FAILURE;
    00091 }