| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# TagCollectionSvc.cpp

Go to the documentation of this file.

    00001 //====================================================================
    00002 //  TagCollectionSvc.cpp
    00003 //--------------------------------------------------------------------
    00004 //
    00005 //  Package   : GaudiSvc/TagCollectionSvc ( The LHCb Offline System)
    00006 //
    00007 //  Description: implementation of the NTuple service
    00008 //
    00009 //  Author    : M.Frank
    00010 //  History   :
    00011 // +---------+----------------------------------------------+---------
    00012 // |    Date |                 Comment                      | Who
    00013 // +---------+----------------------------------------------+---------
    00014 // | 29/10/98| Initial version                              | MF
    00015 // | 29/09/99| Added access to ICnvManager for missing      |
    00016 // |         | converters                                   | MF
    00017 // | 20/09/00| Connect dynamically to conversion service    |
    00018 // |         | for N-tuple persistency                      | MF
    00019 // +---------+----------------------------------------------+---------
    00020 //
    00021 //====================================================================
    00022 #define  GAUDISVC_TAGCOLLECTIONSVC_CPP
    00023
    00024 // Framework include files
    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 // Instantiation of a static factory class used by clients to create
    00043 // instances of this service
    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': /* FILE='<file name>' */
    00090         case 'D': /* DATAFILE='<file name>' */
    00091           filename = (*i).value();
    00092           break;
    00093         case 'O': /* OPT='<NEW<CREATE,WRITE>, UPDATE, READ>' */
    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': /* RECREATE */  typ = 'R';            break;
    00103             case 'A': /* READ     */
    00104             default:                  typ = 'O';            break;
    00105             }
    00106             break;
    00107           default:                    typ = 0;              break;
    00108           }
    00109           break;
    00110         case 'S':   // SVC='<service type>'
    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             }
    00118             break;
    00119           }
    00120           break;
    00121         case 'T':   // TYP='<HBOOK,ROOT,OBJY,...>'
    00122           switch(::toupper((*i).value()[0]))  {
    00123           case 'H':
    00124             svc = "HbookCnv::ConvSvc";
    00125             break;
    00126           case 'P':
    00127             props.push_back( Prop("DbType", (*i).value()));
    00128             svc = "PoolDbCnvSvc";
    00129             break;
    00130           default:
    00131             props.push_back( Prop("DbType", (*i).value()));
    00132             svc = "DbCnvSvc";
    00133             break;
    00134           }
    00135           break;
    00136         default:
    00137           props.push_back( Prop((*i).tag(), (*i).value()));
    00138           break;
    00139         }
    00140       }
    00141       if ( 0 != typ )    {
    00142         IConversionSvc* pSvc = 0;
    00143         status = createService(name()+'.'+logname, svc, props, pSvc);
    00144         if ( status.isSuccess() )   {
    00145           status = attachTuple(filename,logname,typ,pSvc->repSvcType());
    00146           if ( status.isSuccess() )    {
    00147             m_connections.insert(Connections::value_type(m_rootName+'/'+logname,Connection(pSvc)));
    00148             return StatusCode::SUCCESS;
    00149           }
    00150         }
    00151       }
    00152     }
    00153   }
    00154   log << MSG::ERROR << "Cannot add " << ident << " invalid filename!" << endmsg;
    00155   return StatusCode::FAILURE;
    00156 }
    00157
    00159 StatusCode TagCollectionSvc::createService( const std::string& nam,
    00160                                             const std::string& typ,
    00161                                             const std::vector<Prop>& props,
    00162                                             IConversionSvc*& pSvc)    {
    00163   using Gaudi::Utils::TypeNameString;
    00164   SmartIF<ISvcManager> mgr(serviceLocator());
    00165
    00166   // TagCollectionSvc has to directly create a ConversionSvc to manage it directly.
    00167   StatusCode status = NO_INTERFACE;
    00168   if ( mgr.isValid() )    {
    00169
    00170     SmartIF<IService> &isvc = mgr->createService(TypeNameString(nam, typ));
    00171     if (isvc.isValid())   {
    00172       status = isvc->queryInterface(IConversionSvc::interfaceID(), (void**)&pSvc);
    00173       if ( status.isSuccess() )     {
    00174         SmartIF<IProperty> iprop(isvc);
    00175         status = NO_INTERFACE;
    00176         if ( iprop.isValid( ) )    {
    00177           for ( std::vector<Prop>::const_iterator j = props.begin(); j != props.end(); j++)   {
    00178             iprop->setProperty(StringProperty((*j).first, (*j).second)).ignore();
    00179           }
    00180           // NTupleSvc has to directly create a ConversionSvc to manage it directly.
    00181           status = isvc->sysInitialize();
    00182           if ( status.isSuccess() )   {
    00183             status = pSvc->setDataProvider(this);
    00184             if ( status.isSuccess() )   {
    00185               return status;
    00186             }
    00187           }
    00188         }
    00189         pSvc->release();
    00190       }
    00191     }
    00192   }
    00193   pSvc = 0;
    00194   return status;
    00195 }