Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define GAUDISVC_TAGCOLLECTIONSVC_CPP
00023
00024
00025 #include "GaudiKernel/SmartIF.h"
00026 #include "GaudiKernel/Tokenizer.h"
00027 #include "GaudiKernel/SvcFactory.h"
00028 #include "GaudiKernel/DataObject.h"
00029 #include "GaudiKernel/ObjectFactory.h"
00030 #include "GaudiKernel/GenericAddress.h"
00031
00032 #include "GaudiKernel/IProperty.h"
00033 #include "GaudiKernel/ISvcManager.h"
00034 #include "GaudiKernel/ISvcLocator.h"
00035 #include "GaudiKernel/IConversionSvc.h"
00036
00037 #include "GaudiKernel/MsgStream.h"
00038 #include "GaudiKernel/Property.h"
00039
00040 #include "TagCollectionSvc.h"
00041
00042
00043
00044 DECLARE_SERVICE_FACTORY(TagCollectionSvc)
00045
00046
00047 TagCollectionSvc::TagCollectionSvc(const std::string& name, ISvcLocator* svc)
00048 : NTupleSvc(name, svc)
00049 {
00050 }
00051
00053 TagCollectionSvc::~TagCollectionSvc() {
00054 }
00055
00057 StatusCode TagCollectionSvc::initialize() {
00058 StatusCode status = NTupleSvc::initialize();
00059 return status;
00060 }
00061
00063 StatusCode TagCollectionSvc::finalize() {
00064 StatusCode status = NTupleSvc::finalize();
00065 return status;
00066 }
00067
00069 StatusCode TagCollectionSvc::connect(const std::string& ident, std::string& logname) {
00070 MsgStream log ( msgSvc(), name() );
00071 DataObject* pO = 0;
00072 StatusCode status = findObject(m_rootName, pO);
00073 if ( status.isSuccess() ) {
00074 status = INVALID_ROOT;
00075 if ( 0 != pO->registry() ) {
00076 char typ=0;
00077 Tokenizer tok(true);
00078 std::vector<Prop> props;
00079 long loc = ident.find(" ");
00080 std::string filename, auth, svc = "DbCnvSvc";
00081 logname = ident.substr(0,loc);
00082 tok.analyse(ident.substr(loc+1,ident.length()), " ", "", "", "=", "'", "'");
00083 for ( Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++) {
00084 const std::string& tag = (*i).tag();
00085 switch( ::toupper(tag[0]) ) {
00086 case 'A':
00087 props.push_back( Prop("Server", (*i).value()));
00088 break;
00089 case 'F':
00090 case 'D':
00091 filename = (*i).value();
00092 break;
00093 case 'O':
00094 switch( ::toupper((*i).value()[0]) ) {
00095 case 'C':
00096 case 'N':
00097 case 'W': typ = 'N'; break;
00098 case 'U': typ = 'U'; break;
00099 case 'O':
00100 case 'R':
00101 switch( ::toupper((*i).value()[2]) ) {
00102 case 'C': typ = 'R'; break;
00103 case 'A':
00104 default: typ = 'O'; break;
00105 }
00106 break;
00107 default: typ = 0; break;
00108 }
00109 break;
00110 case 'S':
00111 switch( ::toupper(tag[1]) ) {
00112 case 'V': svc = (*i).value(); break;
00113 case 'H':
00114 switch(::toupper((*i).value()[0])) {
00115 case 'Y':
00116 props.push_back( Prop("ShareFiles", (*i).value()));
00117 break ;
00118 }
00119 break;
00120 }
00121 break;
00122 case 'T':
00123 switch(::toupper((*i).value()[0])) {
00124 case 'H':
00125 svc = "HbookCnv::ConvSvc";
00126 break;
00127 case 'P':
00128 props.push_back( Prop("DbType", (*i).value()));
00129 svc = "PoolDbCnvSvc";
00130 break;
00131 default:
00132 props.push_back( Prop("DbType", (*i).value()));
00133 svc = "DbCnvSvc";
00134 break;
00135 }
00136 break;
00137 default:
00138 props.push_back( Prop((*i).tag(), (*i).value()));
00139 break;
00140 }
00141 }
00142 if ( 0 != typ ) {
00143 IConversionSvc* pSvc = 0;
00144 status = createService(name()+'.'+logname, svc, props, pSvc);
00145 if ( status.isSuccess() ) {
00146 status = attachTuple(filename,logname,typ,pSvc->repSvcType());
00147 if ( status.isSuccess() ) {
00148 m_connections.insert(Connections::value_type(m_rootName+'/'+logname,Connection(pSvc)));
00149 return StatusCode::SUCCESS;
00150 }
00151 }
00152 }
00153 }
00154 }
00155 log << MSG::ERROR << "Cannot add " << ident << " invalid filename!" << endmsg;
00156 return StatusCode::FAILURE;
00157 }
00158
00160 StatusCode TagCollectionSvc::createService( const std::string& nam,
00161 const std::string& typ,
00162 const std::vector<Prop>& props,
00163 IConversionSvc*& pSvc) {
00164 using Gaudi::Utils::TypeNameString;
00165 SmartIF<ISvcManager> mgr(serviceLocator());
00166
00167
00168 StatusCode status = NO_INTERFACE;
00169 if ( mgr.isValid() ) {
00170
00171 SmartIF<IService> &isvc = mgr->createService(TypeNameString(nam, typ));
00172 if (isvc.isValid()) {
00173 status = isvc->queryInterface(IConversionSvc::interfaceID(), (void**)&pSvc);
00174 if ( status.isSuccess() ) {
00175 SmartIF<IProperty> iprop(isvc);
00176 status = NO_INTERFACE;
00177 if ( iprop.isValid( ) ) {
00178 for ( std::vector<Prop>::const_iterator j = props.begin(); j != props.end(); j++) {
00179 iprop->setProperty(StringProperty((*j).first, (*j).second)).ignore();
00180 }
00181
00182 status = isvc->sysInitialize();
00183 if ( status.isSuccess() ) {
00184 status = pSvc->setDataProvider(this);
00185 if ( status.isSuccess() ) {
00186 return status;
00187 }
00188 }
00189 }
00190 pSvc->release();
00191 }
00192 }
00193 }
00194 pSvc = 0;
00195 return status;
00196 }