| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

# PoolDbTupleCallback.cpp

Go to the documentation of this file.

    00001 // $Id: PoolDbTupleCallback.cpp,v 1.5 2008/10/27 16:41:33 marcocle Exp $
    00002 //------------------------------------------------------------------------------
    00003 //
    00004 // Implementation of class :  PoolDbTupleCallback
    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 "GaudiPoolDb/PoolDbTupleCallback.h"
    00019 #include "GaudiKernel/INTuple.h"
    00020 #include "GaudiKernel/ISelectStatement.h"
    00021
    00022 #include "StorageSvc/DbType.h"
    00023 #include "StorageSvc/DbSelect.h"
    00024 #include "StorageSvc/DbColumn.h"
    00025 #include "StorageSvc/DbTypeInfo.h"
    00026 #include "StorageSvc/DbDatabase.h"
    00027 #include "StorageSvc/DbInstanceCount.h"
    00028
    00029 static pool::DbInstanceCount::Counter* s_count =
    00030   pool::DbInstanceCount::getCounter(typeid(PoolDbTupleCallback));
    00031
    00033 PoolDbTupleCallback::PoolDbTupleCallback(DataObject* pObj)
    00034 : pool::DbDefaultDataHandler(),
    00035   pool::DbObjectCallBack(0),
    00036   m_iter(0), m_cntH(pool::POOL_StorageType)
    00037 {
    00038   m_refCount = 1;
    00039   setObject(pObj);
    00040   s_count->increment();
    00041 }
    00042
    00044 PoolDbTupleCallback::~PoolDbTupleCallback()
    00045 {
    00046   pool::deletePtr(m_iter);
    00047   s_count->decrement();
    00048   const pool::DbTypeInfo* typ = (const pool::DbTypeInfo*)shape();
    00049   if ( typ ) typ->deleteRef();
    00050 }
    00051
    00053 pool::DataCallBack* PoolDbTupleCallback::clone() const
    00054 {
    00055   PoolDbTupleCallback* cb = const_cast<PoolDbTupleCallback*>(this);
    00056   cb->m_refCount++;
    00057   return cb;
    00058 }
    00059
    00061 void PoolDbTupleCallback::release()
    00062 {
    00063   if ( --m_refCount <= 0 ) {
    00064     delete this;
    00065   }
    00066 }
    00067
    00069 void PoolDbTupleCallback::configure(const INTuple* pTuple,
    00070                                     const pool::DbTypeInfo* typ,
    00071                                     const pool::DbContainer& cntH)
    00072 {
    00073   pool::DbTypeInfo::Columns::const_iterator ic;
    00074   const INTuple::ItemContainer& items = pTuple->items();
    00075   const pool::DbTypeInfo::Columns& cols = typ->columns();
    00076   size_t colsize = cols.size();
    00077   m_map.resize(items.size()+1,-1);
    00078   for(size_t item_no = 0; item_no < items.size(); ++item_no ) {
    00079     int icc = 0;
    00080     m_map[item_no] = -1;
    00081     const std::string& itm_nam = items[item_no]->name();
    00082     for (ic=cols.begin(); ic != cols.end(); ++ic, ++icc )  {
    00083       if ( (*ic)->name() == itm_nam )  {
    00084         m_map[item_no] = icc;
    00085         break;
    00086       }
    00087     }
    00088   }
    00089   m_addr.resize(colsize);
    00090   m_addr[colsize-1] = &m_stream;
    00091   m_links.resize(m_map.size());
    00092   m_plinks.resize(m_map.size());
    00093   for(size_t i = 0; i < m_map.size(); ++i )  {
    00094     m_plinks[i] = &m_links[i];
    00095   }
    00096   m_cntH = cntH;
    00097   typ->addRef();
    00098   setShape(typ);
    00099 }
    00100
    00101 pool::DbSelect*
    00102 PoolDbTupleCallback::select(ISelectStatement* sel)  {
    00103   pool::deletePtr(m_iter);
    00104   if ( m_cntH.isValid() )  {
    00105     std::string criteria = (sel && (sel->type() & ISelectStatement::STRING))
    00106       ? sel->criteria() : std::string("");
    00107     m_iter = new pool::DbSelect( criteria );
    00108     pool::DbDatabase dbH = m_cntH.containedIn();
    00109     m_iter->start(dbH, m_cntH.name());
    00110   }
    00111   return m_iter;
    00112 }
    00113
    00115 pool::DbStatus
    00116 PoolDbTupleCallback::start (CallType /* action_type */,
    00117                             void*    /* pObj        */,
    00118                             void**   /* context     */)
    00119 {
    00120   return pool::Success;
    00121 }
    00122
    00124 pool::DbStatus PoolDbTupleCallback::end(CallType /* action_type */,
    00125                                         void*    /* context     */)
    00126 {
    00127   return pool::Success;
    00128 }
    00129
    00131 pool::DbStatus
    00132 PoolDbTupleCallback::bind(CallType                 action_type,
    00133                           const pool::DbColumn* /* col_ident */,
    00134                           int                      col_number,
    00135                           void*                 /* context   */,
    00136                           void**                   data_pointer)
    00137 {
    00138   switch(action_type)  {
    00139   case GET:
    00140     *data_pointer = m_addr[col_number];
    00141     break;
    00142   case PUT:
    00143     *data_pointer = m_addr[col_number];
    00144     break;
    00145   }
    00146   return pool::Success;
    00147 }
    00148

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