Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "GaudiPoolDb/PoolDbDatabaseCnv.h"
00011
00012 #include "GaudiKernel/IOpaqueAddress.h"
00013 #include "GaudiKernel/IRegistry.h"
00014 #include "GaudiKernel/MsgStream.h"
00015 #include "GaudiKernel/NTuple.h"
00016 #include "GaudiKernel/CnvFactory.h"
00017
00018
00019 PLUGINSVC_FACTORY_WITH_ID( PoolDbDatabaseCnv,
00020 ConverterID(POOL_StorageType,CLID_StatisticsFile),
00021 IConverter*(long, CLID, ISvcLocator*) )
00022
00023
00024 PoolDbDatabaseCnv::PoolDbDatabaseCnv(long typ, const CLID& cl, ISvcLocator* svc)
00025 : PoolDbDirectoryCnv(typ, cl, svc)
00026 {
00027 }
00028
00030 PoolDbDatabaseCnv::~PoolDbDatabaseCnv() {
00031 }
00032
00033
00034 StatusCode
00035 PoolDbDatabaseCnv::createObj(IOpaqueAddress* pAddr, DataObject*& refpObj) {
00036 StatusCode status = StatusCode::FAILURE;
00037 MsgStream log(msgSvc(), "PoolDbDatabaseCnv");
00038 if ( pAddr ) {
00039 IRegistry* pReg = pAddr->registry();
00040 const unsigned long* ipars = pAddr->ipar();
00041 const std::string* spars = pAddr->par();
00042 char mode = char(ipars[1]);
00043 pool::Guid guid(pool::Guid::null());
00044 std::string fname = spars[0];
00045 std::string oname = pReg->name();
00046 bool recrea = mode == 'R';
00047 bool create = mode == 'N';
00048 bool update = mode == 'U';
00049 bool read = mode == 'O';
00050 const CLID& clid = objType();
00051 status = StatusCode::SUCCESS;
00052 guid.Data1 = objType();
00053 std::string cntName = containerName(pReg);
00054 if ( create ) {
00055 status = saveDescription(fname, cntName, "File containing statistics results.",
00056 "", guid, clid, "NEW");
00057 if ( status.isSuccess() ) {
00058 log << MSG::INFO << "Opened NEW Database file:"
00059 << fname << " as " << oname << endmsg;
00060 }
00061 }
00062 else if ( update ) {
00063 status = saveDescription(fname, cntName, "File containing statistics results.",
00064 "", guid, clid, "UPDATE");
00065 if ( status.isSuccess() ) {
00066 log << MSG::INFO << "Connect to existing Database file:"
00067 << fname << " as " << oname << " for UPDATE" << endmsg;
00068 }
00069 }
00070 else if ( read ) {
00071 if ( status.isSuccess() ) {
00072 log << MSG::INFO << "Connect to existing Database file:"
00073 << fname << " as " << oname << " for READ" << endmsg;
00074 }
00075 }
00076 else if ( recrea ) {
00077 status = saveDescription(fname, cntName, "File containing statistics results.",
00078 "", guid, clid, "RECREATE");
00079 if ( status.isSuccess() ) {
00080 log << MSG::INFO << "Recreate Database file:" << fname << " as " << oname << endmsg;
00081 }
00082 }
00083 else {
00084 log << MSG::ERROR << "Don't know what to do:" << fname << endmsg;
00085 status = StatusCode::FAILURE;
00086 }
00087
00088 if ( status.isSuccess() ) {
00089 NTuple::File* pFile = new NTuple::File(objType(), fname, oname);
00090 pFile->setOpen(false);
00091 refpObj = pFile;
00092 }
00093 }
00094 return status;
00095 }
00096