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