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