Gaudi Framework, version v22r0

Home   Generated: 9 Feb 2011

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   // Note: (1<<4) means RECREATE existing: We need to get the GUID in order to not
00056   //       create a new one, if the catalog is pre-allocated
00057   bool open_existing = isEqualMode(mode,pool::READ)||isEqualMode(mode,pool::UPDATE|(1<<4));
00058   m_dbH = DbDatabase(m_domH.find(fid()));
00059   if ( !m_dbH.isValid() )  {
00060     std::string true_fid;
00061     pool::DbStatus sc = m_dbH.open(m_domH, pfn(), fid(), mode);
00062     if ( sc.isSuccess() && open_existing )  {
00063       m_dbH.param("FID",true_fid);
00064       if ( fid() == pfn() ) {
00065         m_fid = true_fid;
00066         m_dbH.close();
00067         sc = m_dbH.open(m_domH, pfn(), fid(), mode);
00068       }
00069       else if ( strcasecmp(true_fid.c_str(),fid().c_str()) != 0 )  {
00070         m_dbH.close();
00071         throw std::runtime_error("FID mismatch:\n\t\t\t\tFID="+
00072                                  fid()+" (catalog) <> \n\t\t\t\t"+
00073                                  true_fid+" (file) for PFN="+pfn());
00074         return BAD_DATA_CONNECTION;
00075       }
00076     }
00077     else if ( open_existing ) {
00078       return BAD_DATA_CONNECTION;
00079     }
00080     return sc.isSuccess() ? StatusCode::SUCCESS : StatusCode::FAILURE;
00081   }
00082   return StatusCode::SUCCESS;
00083 }
00084 
00086 StatusCode PoolDbDataConnection::disconnect()  {
00087   if ( m_dbH.isValid() )  {
00088     m_dbH.close();
00089     m_dbH = DbDatabase(pool::POOL_StorageType);
00090     return StatusCode::SUCCESS;
00091   }
00092   return StatusCode::FAILURE;
00093 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Wed Feb 9 16:24:58 2011 for Gaudi Framework, version v22r0 by Doxygen version 1.6.2 written by Dimitri van Heesch, © 1997-2004