Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012

RootDirectoryCnv.cpp

Go to the documentation of this file.
00001 // $Id: RootDirectoryCnv.cpp,v 1.8 2010-09-27 15:43:53 frankb Exp $
00002 //------------------------------------------------------------------------------
00003 //
00004 // Implementation of class :  RootDirectoryCnv
00005 //
00006 // Author :                   Markus Frank
00007 //
00008 //------------------------------------------------------------------------------
00009 
00010 #include <algorithm>
00011 #include <memory>
00012 
00013 // Include files
00014 #include "RootCnv/RootCnvSvc.h"
00015 #include "RootCnv/RootDirectoryCnv.h"
00016 #include "RootCnv/RootDataConnection.h"
00017 #include "GaudiKernel/IRegistry.h"
00018 #include "GaudiKernel/NTuple.h"
00019 #include "TBranch.h"
00020 
00021 // Factory declaration
00022 using namespace Gaudi;
00023 using namespace std;
00024 
00025 #if 0
00026 #include "GaudiKernel/CnvFactory.h"
00027 PLUGINSVC_FACTORY_WITH_ID( RootDirectoryCnv, 
00028                           ConverterID(POOL_StorageType,CLID_StatisticsDirectory),
00029                           IConverter*(long, CLID, ISvcLocator*) );
00030 #endif
00031 
00032 // Standard Constructor
00033 RootDirectoryCnv::RootDirectoryCnv (long typ, 
00034                                     const CLID& clid, 
00035                                     ISvcLocator* svc, RootCnvSvc* mgr) 
00036                                     : RootStatCnv(typ, clid, svc, mgr)
00037 {
00038 }
00039 
00040 // Create transient object from persistent data
00041 StatusCode 
00042 RootDirectoryCnv::createObj(IOpaqueAddress* /* pAddr */,DataObject*& refpObj)  {
00043   refpObj = new NTuple::Directory();
00044   return StatusCode::SUCCESS;
00045 }
00046 
00047 // Converter overrides: Convert the transient object to the requested representation.
00048 StatusCode 
00049 RootDirectoryCnv::createRep(DataObject* pObj,IOpaqueAddress*& /* refpAddr */)  {
00050   string dsc;
00051   if ( objType() == CLID_StatisticsDirectory )  {
00052     dsc = "Directory containing statistics results.";
00053   }
00054   else if ( objType() == CLID_StatisticsFile )  {
00055     dsc = "File containing statistics results.";
00056   }
00057   else  {
00058     return StatusCode::FAILURE;
00059   }
00060   string ident = containerName(pObj->registry());
00061   string path  = fileName(pObj->registry());
00062   return saveDescription(path, ident, dsc, ident, objType());
00063 }
00064 
00065 // Fill transient object references
00066 StatusCode RootDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr, DataObject* pObj)  {
00067   return updateObjRefs(pAddr, pObj);
00068 }
00069 
00070 // Converter overrides: Update the references of an updated transient object.
00071 StatusCode 
00072 RootDirectoryCnv::updateObjRefs(IOpaqueAddress* pAddr, 
00073                                 DataObject* pObject)
00074 {
00075   typedef vector<RootNTupleDescriptor*> REFS;
00076   REFS refs;
00077   StatusCode status = StatusCode(StatusCode::FAILURE,true);
00078   if ( pAddr ) {
00079     IRegistry* pReg = pAddr->registry();
00080     if ( pReg )  {
00081       typedef vector<IRegistry*> Leaves;
00082       string ident   = pReg->identifier();
00083       string fname   = fileName(pReg);
00084       string cntName = containerName(pReg);
00085       RootDataConnection* con = 0;
00086       Leaves leaves;
00087       status = m_dbMgr->connectDatabase(fname, IDataConnection::READ, &con);
00088       if ( status.isSuccess() )  {
00089         TBranch* b = con->getBranch("##Descriptors","GaudiStatisticsDescription");
00090         if ( b ) {
00091           for(Long64_t n=b->GetEntries(), i=0; i<n; ++i)  {
00092             RootNTupleDescriptor* ref=0;
00093             b->SetAddress(&ref);
00094             int nb = b->GetEntry(i);
00095             if ( nb > 1 ) {
00096               string s = ref->container.substr(0,cntName.length());
00097               log() << MSG::VERBOSE << "Read description:" << ref->container 
00098                 << " " << ident << " " << cntName << endmsg;
00099               if ( s == cntName )  {
00100                 if ( ref->container.length() >= cntName.length()+1 )  {
00101                   if ( ref->container.find('/',cntName.length()+1) == string::npos ) {
00102                     refs.push_back(ref);
00103                     continue;
00104                   }
00105                 }
00106               }
00107             }
00108             delete ref;
00109           }
00110         }
00111         log() << MSG::DEBUG << "Got " << refs.size() << " tuple connection(s)....." << endmsg;
00112         status = m_dataMgr->objectLeaves(pObject, leaves);
00113         if ( status.isSuccess() )    {
00114           for(REFS::iterator i = refs.begin(); i != refs.end(); ++i)  {
00115             REFS::value_type& ref = *i;
00116             if ( ref )   {
00117               bool need_to_add = true;
00118               for(Leaves::iterator j=leaves.begin(); j != leaves.end(); ++j )  {
00119                 string curr_leaf = containerName(*j);
00120                 if ( curr_leaf == ref->container )  {
00121                   need_to_add = false;
00122                   break;
00123                 }
00124               }
00125               if ( need_to_add )  {
00126                 IOpaqueAddress* pA= 0;
00127                 if ( ref->clid == CLID_StatisticsDirectory ||
00128                   ref->clid == CLID_StatisticsFile      || 
00129                   ref->clid == CLID_RowWiseTuple        ||
00130                   ref->clid == CLID_ColumnWiseTuple      )
00131                 {
00132                   string spar[]   = { fname, ref->container};
00133                   unsigned long ipar[] = { ~0x0UL, ~0x0UL };
00134                   status = m_dbMgr->createAddress(repSvcType(),
00135                     ref->clid,
00136                     spar,
00137                     ipar,
00138                     pA);
00139                 }
00140                 if ( status.isSuccess() )  {
00141                   string top = topLevel(pReg);
00142                   string leaf_name = top + ref->container.substr(7);
00143                   status = m_dataMgr->registerAddress(leaf_name, pA);
00144                   if ( status.isSuccess() )  {
00145                     log() << MSG::DEBUG << "Created address for " << leaf_name 
00146                       << " of type " << ref->clid << endmsg;
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 
00172 // Converter overrides: Update transient object from persistent data
00173 StatusCode 
00174 RootDirectoryCnv::updateObj(IOpaqueAddress* /* pAddr */,
00175                             DataObject*     /* pObj */)
00176 {  
00177   return StatusCode::SUCCESS;
00178 }
00179 
00180 // Converter overrides: Update persistent object representation.
00181 StatusCode 
00182 RootDirectoryCnv::updateRep(IOpaqueAddress* /* pAddr */,
00183                             DataObject*     /* pObj */)
00184 {
00185   return StatusCode::SUCCESS;
00186 }
00187 
00188 // Converter overrides: Update references of persistent object representation.
00189 StatusCode 
00190 RootDirectoryCnv::updateRepRefs(IOpaqueAddress* /* pAddr */,
00191                                 DataObject*     /* pObj */)
00192 {
00193   return StatusCode::SUCCESS;
00194 }
00195 
00196 // Converter overrides: Fill references of persistent object representation.
00197 StatusCode 
00198 RootDirectoryCnv::fillRepRefs(IOpaqueAddress* /* pAddr */,
00199                               DataObject*     /* pObj */)
00200 {
00201   return StatusCode::SUCCESS;
00202 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:29 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004