Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

DbDatabaseCnv.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 //
00003 // Implementation of class :  DbDatabaseCnv
00004 //
00005 // Author :                   Markus Frank
00006 //
00007 //------------------------------------------------------------------------------
00008 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiDb/src/NTuples/DbDatabaseCnv.cpp,v 1.1.1.1 2001/04/18 21:13:35 tlindner Exp $
00009 #define DBCNV_DBDATABASECNV_CPP
00010 
00011 // Include files
00012 #include "DbDatabaseCnv.h"
00013 #include "GaudiDb/DbFederation.h"
00014 #include "GaudiDb/IDataBaseMgr.h"
00015 #include "GaudiDb/DbCnvFactory.h"
00016 
00017 #include "GaudiKernel/IConversionSvc.h"
00018 #include "GaudiKernel/IOpaqueAddress.h"
00019 #include "GaudiKernel/MsgStream.h"
00020 #include "GaudiKernel/NTuple.h"
00021 
00022 // Factory declaration
00023 static DbOOMsCnvFactory<DbDatabaseCnv> s_factory;
00024 const ICnvFactory& DbOOMsDbDatabaseCnvFactory = s_factory;
00025 
00027 DbDatabaseCnv::DbDatabaseCnv(IOODataBase* db, ISvcLocator* svc)
00028 : DbDirectoryCnv(classID(), db, svc),
00029   m_cnvSvc(0)
00030 {
00031 }
00032 
00034 DbDatabaseCnv::~DbDatabaseCnv()   {
00035   if ( m_cnvSvc ) m_cnvSvc->release();
00036   m_cnvSvc = 0;
00037 }
00038 
00039 // Inquire class type (used by factory)
00040 const CLID& DbDatabaseCnv::classID()    {
00041   return CLID_NTupleFile;
00042 }
00043 
00044 // Initialize the converter
00045 StatusCode DbDatabaseCnv::initialize()   {
00046   StatusCode status = DbDirectoryCnv::initialize();
00047   MsgStream log(messageService(),"DbDirectoryCnv");
00048   if ( !status.isSuccess() )   {
00049     log << MSG::ERROR << "Cannot initialize base class \"DbDirectoryCnv\"" << endreq;
00050     return status;
00051   }
00052   status = m_dbaseMgr->queryInterface(IID_IConversionSvc, (void**)&m_cnvSvc);
00053   if ( !status.isSuccess() )    {
00054     log << MSG::ERROR << "Cannot connect to \"" << m_svcName << "\"(IConversionSvc)" << endreq;
00055     return status;
00056   }
00057   return status;
00058 }
00059 
00060 // Finalize the Db converter 
00061 StatusCode DbDatabaseCnv::finalize()   {
00062   if ( m_cnvSvc ) m_cnvSvc->release();
00063   m_cnvSvc = 0;
00064   return DbDirectoryCnv::finalize();
00065 }
00066 
00067 // Create database object
00068 StatusCode DbDatabaseCnv::createObj(IOpaqueAddress* pAddress, DataObject*& refpObject)   {
00069   StatusCode status = StatusCode::FAILURE;
00070   MsgStream log(msgSvc(), "DbDatabaseCnv");
00071   dbHandle<DbFederation>& fedH = m_dbaseMgr->defaultFederationHdl();
00072   if ( fedH.isValid() )   {
00073     char mode = char(pAddress->genericLink()->genericInfo()->m_info[1]);
00074     std::string fname   = pAddress->dbName();
00075     std::string oname   = pAddress->objectName();
00076     bool exists = fedH.existsDbase(fname);
00077     bool create = mode == 'N';
00078     bool update = mode == 'U';
00079     bool read   = mode == 'O';
00080     status = StatusCode::SUCCESS;
00081     if ( !exists && create )    {
00082       status = m_cnvSvc->connectOutput(fname);
00083       if ( status.isSuccess() )   {
00084         log << MSG::INFO << "Opened NEW Database file:" << fname 
00085             << " as " << oname << endreq;
00086       }
00087     }
00088     else if ( exists && update )    {
00089       status = m_cnvSvc->connectOutput(fname);
00090       if ( status.isSuccess() )   {
00091         log << MSG::INFO << "Connect to existing Database file:" << fname 
00092             << " as " << oname << " for UPDATE" << endreq;
00093       }
00094     }
00095     else if ( exists && read )    {
00096       log << MSG::INFO << "Connect to existing Database file:" << fname 
00097           << " as " << oname << " for READ" << endreq;
00098     }
00099     else if ( exists && create )   {
00100       log << MSG::ERROR << "Cannot recreate existing database:" << fname << endreq;
00101       status = StatusCode::FAILURE;
00102     }
00103     else    {
00104       log << MSG::ERROR << "Don't know what to do:" << fname << endreq;
00105       status = StatusCode::FAILURE;
00106     }
00107     // Now create object
00108     if ( status.isSuccess() )   {
00109       NTuple::File* pFile = new NTuple::File(objType(), fname, oname);
00110       pFile->setOpen(false);
00111       refpObject = pFile;
00112     }
00113   }
00114   return status;
00115 }
00116 

Generated at Wed Nov 21 12:22:19 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000