| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# VFSSvc Class Reference

`#include <VFSSvc.h>`

Inheritance diagram for VFSSvc:

[legend]
Collaboration diagram for VFSSvc:

[legend]

List of all members.

## Detailed Description

Simple service that allows to read files independently from the storage.

The service uses tools to resolve URLs and serve the files as input streams. The basic implementations read from the filesystem, and simple extensions allow to read from databases, web...

Author:
  Marco Clemencic

Date:
  2008-01-18

Definition at line 28 of file VFSSvc.h.

## Public Member Functions
virtual StatusCode | queryInterface (const InterfaceID &riid, void **ppvUnknown)
| Query interfaces of Interface.
virtual StatusCode | initialize ()
| Initilize Service.
virtual StatusCode | finalize ()
| Finalize Service.
virtual std::auto_ptr < std::istream > | open (const std::string &url)
virtual const std::vector < std::string > & | protocols () const
## Protected Member Functions
| VFSSvc (const std::string &name, ISvcLocator *svcloc)
| Standard constructor.
virtual | ~VFSSvc ()
| Destructor.
## Private Attributes
std::vector< std::string > | m_urlHandlersNames
| Names of the handlers to use.
std::vector< std::string > | m_protocols
| Protocols registered.
std::string | m_fallBackProtocol
| Protocol to use in case there is not a specific tool to handle the URL.
GaudiUtils::HashMap < std::string, IFileAccess * > | m_urlHandlers
| Map of the tools handling the known protocols.
IToolSvc * | m_toolSvc
| Handle to the tool service.
std::list< IAlgTool * > | m_acquiredTools
| List of acquired tools (needed to release them).
## Friends
class | SvcFactory< VFSSvc >

## Constructor & Destructor Documentation

VFSSvc::VFSSvc | ( | const std::string & | name,
|  | ISvcLocator * | svcloc |
| ) |  |  | `[protected]`

Standard constructor.

Definition at line 11 of file VFSSvc.cpp.

    00011                                                      :
    00012   Service(name,svc), m_toolSvc(0) {
    00013
    00014   m_urlHandlersNames.push_back("FileReadTool");
    00015
    00016   declareProperty("FileAccessTools",m_urlHandlersNames,
    00017                   "List of tools implementing the IFileAccess interface.");
    00018
    00019   declareProperty("FallBackProtocol",m_fallBackProtocol = "file",
    00020                   "URL prefix to use if the prefix is not present.");
    00021 }
    //------------------------------------------------------------------------------

VFSSvc::~VFSSvc | ( |  | ) | `[protected, virtual]`

Destructor.

Definition at line 23 of file VFSSvc.cpp.

    00023 {}

## Member Function Documentation

StatusCode VFSSvc::queryInterface | ( | const InterfaceID & | riid,
|  | void ** | ppvUnknown |
| ) |  |  | `[virtual]`

Query interfaces of Interface.

Parameters:

  | riid | ID of Interface to be retrieved
  | ppvUnknown | Pointer to Location for interface pointer

Reimplemented from Service.

Definition at line 25 of file VFSSvc.cpp.

    00026                                                            {
    00027   StatusCode sc = StatusCode::FAILURE;
    00028   if ( ppvInterface ) {
    00029     *ppvInterface = 0;
    00030
    00031     if ( IFileAccess::interfaceID().versionMatch(riid) )    {
    00032       *ppvInterface = static_cast<IFileAccess*>(this);
    00033       sc = StatusCode::SUCCESS;
    00034       addRef();
    00035     }
    00036     else
    00037       sc = Service::queryInterface( riid, ppvInterface );
    00038   }
    00039   return sc;
    00040 }

StatusCode VFSSvc::initialize | ( |  | ) | `[virtual]`

Initilize Service.

Reimplemented from Service.

Definition at line 42 of file VFSSvc.cpp.

    00042                               {
    00043   StatusCode sc = Service::initialize();
    00044   if (sc.isFailure()){
    00045     return sc;
    00046   }
    00047
    00048   MsgStream log(messageService(), name());
    00049
    00050   sc = serviceLocator()->service( "ToolSvc" , m_toolSvc , true );
    00051   if (sc.isFailure()){
    00052     log << MSG::ERROR << "Cannot locate ToolSvc" << endmsg;
    00053     return sc;
    00054   }
    00055
    00056   IAlgTool *tool;
    00057   IFileAccess *hndlr;
    00058   std::vector<std::string>::iterator i;
    00059   for(i = m_urlHandlersNames.begin(); i != m_urlHandlersNames.end(); ++i){
    00060     // retrieve the tool and the pointer to the interface
    00061     sc = m_toolSvc->retrieve(*i,IAlgTool::interfaceID(),tool,0,true);
    00062     if (sc.isFailure()){
    00063       log << MSG::ERROR << "Cannot get tool " << *i << endmsg;
    00064       return sc;
    00065     }
    00066     m_acquiredTools.push_front(tool); // this is one tool that we will have to release
    00067     sc = tool->queryInterface(IFileAccess::interfaceID(),pp_cast<void>(&hndlr));
    00068     if (sc.isFailure()){
    00069       log << MSG::ERROR << *i << " does not implement IFileAccess" << endmsg;
    00070       return sc;
    00071     }
    00072     // We do not need to increase the reference count for the IFileAccess interface
    00073     // because we hold the tool by its IAlgTool interface.
    00074     hndlr->release();
    00075     // loop over the list of supported protocols and add them to the map (for quick access)
    00076     for ( std::vector<std::string>::const_iterator prot = hndlr->protocols().begin();
    00077           prot != hndlr->protocols().end(); ++prot ){
    00078       m_urlHandlers[*prot] = hndlr;
    00079     }
    00080   }
    00081
    00082   // Now let's check if we can handle the fallback protocol
    00083   if ( m_urlHandlers.find(m_fallBackProtocol) == m_urlHandlers.end() ) {
    00084     log << MSG::ERROR << "No handler specified for fallback protocol prefix "
    00085         << m_fallBackProtocol << endmsg;
    00086     return StatusCode::FAILURE;
    00087   }
    00088
    00089   // Note: the list of handled protocols will be filled only if requested
    00090
    00091   return sc;
    00092 }

StatusCode VFSSvc::finalize | ( | void |  | ) | `[virtual]`

Finalize Service.

Reimplemented from Service.

Definition at line 94 of file VFSSvc.cpp.

    00094                             {
    00095   m_urlHandlers.clear(); // clear the map
    00096   m_protocols.clear();
    00097
    00098   if (m_toolSvc) {
    00099     // release the acquired tools (from the last acquired one)
    00100     while ( m_acquiredTools.begin() != m_acquiredTools.end() ){
    00101       m_toolSvc->releaseTool(*m_acquiredTools.begin()).ignore();
    00102       m_acquiredTools.pop_front();
    00103     }
    00104     m_toolSvc->release(); // release the tool service
    00105     m_toolSvc = 0;
    00106   }
    00107   return Service::finalize();
    00108 }

std::auto_ptr< std::istream > VFSSvc::open | ( | const std::string & | url | ) | `[virtual]`

See also:
  IFileAccess::open

Implements IFileAccess.

Definition at line 110 of file VFSSvc.cpp.

    00110                                                         {
    00111
    00112   // get the url prefix endpos
    00113   std::string::size_type pos = url.find("://");
    00114
    00115   if (std::string::npos == pos) { // no url prefix
    00116     return m_urlHandlers[m_fallBackProtocol]->open(url);
    00117   }
    00118
    00119   std::string url_prefix(url,0,pos);
    00120   if ( m_urlHandlers.find(url_prefix) == m_urlHandlers.end() ) {
    00121     // if we do not have a handler for the URL prefix,
    00122     // use the fall back one and pass only the path
    00123     return m_urlHandlers[m_fallBackProtocol]->open(url.substr(pos+3));
    00124   }
    00125   return m_urlHandlers[url_prefix]->open(url);
    00126 }

const std::vector< std::string > & VFSSvc::protocols | ( |  | ) | const`[virtual]`

See also:
  IFileAccess::protocols

Implements IFileAccess.

Definition at line 145 of file VFSSvc.cpp.

    00146 {
    00147   if (m_protocols.empty()){
    00148     // prepare the list of handled protocols
    00149     std::for_each(m_urlHandlers.begin(),m_urlHandlers.end(),
    00150                   append_key<std::vector<std::string> >(const_cast<VFSSvc*>(this)->m_protocols));
    00151   }
    00152   return m_protocols;
    00153 }

## Friends And Related Function Documentation

friend class SvcFactory< VFSSvc >`[friend]`

Definition at line 59 of file VFSSvc.h.

## Member Data Documentation

std::vector<std::string> VFSSvc::m_urlHandlersNames`[private]`

Names of the handlers to use.

Definition at line 62 of file VFSSvc.h.

std::vector<std::string> VFSSvc::m_protocols`[private]`

Protocols registered.

Definition at line 65 of file VFSSvc.h.

std::string VFSSvc::m_fallBackProtocol`[private]`

Protocol to use in case there is not a specific tool to handle the URL.

Definition at line 68 of file VFSSvc.h.

GaudiUtils::HashMap<std::string,IFileAccess*> VFSSvc::m_urlHandlers`[private]`

Map of the tools handling the known protocols.

Definition at line 71 of file VFSSvc.h.

IToolSvc* VFSSvc::m_toolSvc`[private]`

Handle to the tool service.

Definition at line 74 of file VFSSvc.h.

std::list<IAlgTool*> VFSSvc::m_acquiredTools`[private]`

List of acquired tools (needed to release them).

Definition at line 77 of file VFSSvc.h.

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r4/GaudiSvc/src/VFSSvc/VFSSvc.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r4/GaudiSvc/src/VFSSvc/VFSSvc.cpp