All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VFSSvc Class Reference

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

#include <src/component/VFSSvc.h>

Inheritance diagram for VFSSvc:
Collaboration diagram for VFSSvc:

Public Member Functions

virtual StatusCode initialize ()
 Initialize Service. More...
 
virtual StatusCode finalize ()
 Finalize Service. More...
 
virtual std::auto_ptr
< std::istream > 
open (const std::string &url)
 
virtual const std::vector
< std::string > & 
protocols () const
 
 VFSSvc (const std::string &name, ISvcLocator *svcloc)
 Standard constructor. More...
 
virtual ~VFSSvc ()
 Destructor. More...
 
- Public Member Functions inherited from extends1< Service, IFileAccess >
 extends1 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments. More...
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments. More...
 
 extends1 (A1 a1)
 Templated constructor with 1 argument. More...
 
 extends1 ()
 Default constructor. More...
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface. More...
 
virtual std::vector< std::string > getInterfaceNames () const
 Implementation of IInterface::getInterfaceNames. More...
 
virtual ~extends1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance. More...
 
virtual const std::string & name () const
 Retrieve name of the service. More...
 
virtual StatusCode configure ()
 Configuration (from OFFLINE to CONFIGURED). More...
 
virtual StatusCode start ()
 Start (from INITIALIZED to RUNNING). More...
 
virtual StatusCode stop ()
 Stop (from RUNNING to INITIALIZED). More...
 
virtual StatusCode terminate ()
 Initialization (from CONFIGURED to OFFLINE). More...
 
virtual Gaudi::StateMachine::State FSMState () const
 Get the current state. More...
 
virtual Gaudi::StateMachine::State targetFSMState () const
 When we are in the middle of a transition, get the state where the transition is leading us. More...
 
virtual StatusCode reinitialize ()
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED). More...
 
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
virtual StatusCode sysInitialize ()
 Initialize Service. More...
 
virtual StatusCode sysStart ()
 Initialize Service. More...
 
virtual StatusCode sysStop ()
 Initialize Service. More...
 
virtual StatusCode sysFinalize ()
 Finalize Service. More...
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service. More...
 
virtual StatusCode sysRestart ()
 Re-initialize the Service. More...
 
virtual StatusCode setProperty (const Property &p)
 Set the property by property. More...
 
virtual StatusCode setProperty (const std::string &s)
 Set the property by string. More...
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Set the property by std::string. More...
 
virtual StatusCode getProperty (Property *p) const
 Get the property by property. More...
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name. More...
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Get the property by std::string. More...
 
virtual const std::vector
< Property * > & 
getProperties () const
 Get list of properties. More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments. More...
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument. More...
 
 CommonMessaging ()
 Default constructor. More...
 
virtual ~CommonMessaging ()
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces3< IService, IProperty, IStateful >
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IService
 DeclareInterfaceID (IService, 3, 0)
 InterfaceID. More...
 
virtual ~IService ()
 virtual destructor More...
 
- Public Member Functions inherited from INamedInterface
 DeclareInterfaceID (INamedInterface, 1, 0)
 InterfaceID. More...
 
virtual ~INamedInterface ()
 Virtual destructor (always needed for abstract classes). More...
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IProperty
 DeclareInterfaceID (IProperty, 2, 0)
 InterfaceID. More...
 
- Public Member Functions inherited from IStateful
 DeclareInterfaceID (IStateful, 1, 0)
 InterfaceID. More...
 
virtual ~IStateful ()
 
- Public Member Functions inherited from extend_interfaces1< IFileAccess >
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IFileAccess
 DeclareInterfaceID (IFileAccess, 2, 0)
 InterfaceID. More...
 
virtual ~IFileAccess ()
 

Private Attributes

std::vector< std::string > m_urlHandlersNames
 Names of the handlers to use. More...
 
std::vector< std::string > m_protocols
 Protocols registered. More...
 
std::string m_fallBackProtocol
 Protocol to use in case there is not a specific tool to handle the URL. More...
 
GaudiUtils::HashMap
< std::string, IFileAccess * > 
m_urlHandlers
 Map of the tools handling the known protocols. More...
 
SmartIF< IToolSvcm_toolSvc
 Handle to the tool service. More...
 
std::list< IAlgTool * > m_acquiredTools
 List of acquired tools (needed to release them). More...
 

Additional Inherited Members

- Public Types inherited from extends1< Service, IFileAccess >
typedef extends1 base_class
 Typedef to this class. More...
 
typedef extend_interfaces1
< IFileAccess
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from Service
typedef
Gaudi::PluginService::Factory
< IService *, const
std::string &, ISvcLocator * > 
Factory
 
- Public Types inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
typedef CommonMessaging base_class
 
- Public Types inherited from implements3< IService, IProperty, IStateful >
typedef implements3 base_class
 Typedef to this class. More...
 
typedef extend_interfaces3
< IService, IProperty,
IStateful
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces3< IService, IProperty, IStateful >
typedef mpl::fold< typename
IService::iid::iids::type,
typename mpl::fold< typename
IProperty::iid::iids::type,
typename
IStateful::iid::iids::type,
mpl::insert< mpl::_1, mpl::_2 >
>::type, mpl::insert< mpl::_1,
mpl::_2 > >::type 
ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IInterface
enum  Status { SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR }
 Return status. More...
 
typedef Gaudi::InterfaceId
< IInterface, 0, 0 > 
iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Public Types inherited from extend_interfaces1< IFileAccess >
typedef
IFileAccess::iid::iids::type 
ext_iids
 MPL set of interfaces extended by this one. More...
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
- Protected Member Functions inherited from Service
virtual ~Service ()
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level. More...
 
Gaudi::StateMachine::State m_state
 Service state. More...
 
Gaudi::StateMachine::State m_targetState
 Service state. More...
 
- Protected Attributes inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
SmartIF< IMessageSvcm_msgsvc
 Pointer to the message service;. More...
 
std::auto_ptr< MsgStreamm_msgStream
 The predefined message stream. More...
 
bool m_streamWithService
 Flag to create a new MsgStream if it was created without the message service. More...
 

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 27 of file VFSSvc.h.

Constructor & Destructor Documentation

VFSSvc::VFSSvc ( const std::string &  name,
ISvcLocator svcloc 
)

Standard constructor.

Definition at line 10 of file VFSSvc.cpp.

10  :
11  base_class(name,svc) {
12 
13  m_urlHandlersNames.push_back("FileReadTool");
14 
15  declareProperty("FileAccessTools",m_urlHandlersNames,
16  "List of tools implementing the IFileAccess interface.");
17 
18  declareProperty("FallBackProtocol",m_fallBackProtocol = "file",
19  "URL prefix to use if the prefix is not present.");
20 }
std::string m_fallBackProtocol
Protocol to use in case there is not a specific tool to handle the URL.
Definition: VFSSvc.h:54
extends1 base_class
Typedef to this class.
Definition: extends.h:12
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:211
std::vector< std::string > m_urlHandlersNames
Names of the handlers to use.
Definition: VFSSvc.h:48
VFSSvc::~VFSSvc ( )
virtual

Destructor.

Definition at line 22 of file VFSSvc.cpp.

22 {}

Member Function Documentation

StatusCode VFSSvc::finalize ( )
virtual

Finalize Service.

Reimplemented from Service.

Definition at line 76 of file VFSSvc.cpp.

76  {
77  m_urlHandlers.clear(); // clear the map
78  m_protocols.clear();
79 
80  if (m_toolSvc) {
81  // release the acquired tools (from the last acquired one)
82  while ( m_acquiredTools.begin() != m_acquiredTools.end() ){
83  m_toolSvc->releaseTool(*m_acquiredTools.begin()).ignore();
84  m_acquiredTools.pop_front();
85  }
86  m_toolSvc->release(); // release the tool service
87  m_toolSvc = 0;
88  }
89  return Service::finalize();
90 }
SmartIF< IToolSvc > m_toolSvc
Handle to the tool service.
Definition: VFSSvc.h:60
std::vector< std::string > m_protocols
Protocols registered.
Definition: VFSSvc.h:51
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:57
std::list< IAlgTool * > m_acquiredTools
List of acquired tools (needed to release them).
Definition: VFSSvc.h:63
void clear()
Definition: Map.h:176
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:199
StatusCode VFSSvc::initialize ( )
virtual

Initialize Service.

Reimplemented from Service.

Definition at line 24 of file VFSSvc.cpp.

24  {
26  if (sc.isFailure()){
27  return sc;
28  }
29 
30  MsgStream log(msgSvc(), name());
31 
32  m_toolSvc = serviceLocator()->service("ToolSvc");
33  if (!m_toolSvc.isValid()){
34  log << MSG::ERROR << "Cannot locate ToolSvc" << endmsg;
35  return StatusCode::FAILURE;
36  }
37 
38  IAlgTool *tool;
39  IFileAccess *hndlr;
40  std::vector<std::string>::iterator i;
41  for(i = m_urlHandlersNames.begin(); i != m_urlHandlersNames.end(); ++i){
42  // retrieve the tool and the pointer to the interface
43  sc = m_toolSvc->retrieve(*i,IAlgTool::interfaceID(),tool,0,true);
44  if (sc.isFailure()){
45  log << MSG::ERROR << "Cannot get tool " << *i << endmsg;
46  return sc;
47  }
48  m_acquiredTools.push_front(tool); // this is one tool that we will have to release
49  sc = tool->queryInterface(IFileAccess::interfaceID(),pp_cast<void>(&hndlr));
50  if (sc.isFailure()){
51  log << MSG::ERROR << *i << " does not implement IFileAccess" << endmsg;
52  return sc;
53  }
54  // We do not need to increase the reference count for the IFileAccess interface
55  // because we hold the tool by its IAlgTool interface.
56  hndlr->release();
57  // loop over the list of supported protocols and add them to the map (for quick access)
58  for ( std::vector<std::string>::const_iterator prot = hndlr->protocols().begin();
59  prot != hndlr->protocols().end(); ++prot ){
60  m_urlHandlers[*prot] = hndlr;
61  }
62  }
63 
64  // Now let's check if we can handle the fallback protocol
66  log << MSG::ERROR << "No handler specified for fallback protocol prefix "
68  return StatusCode::FAILURE;
69  }
70 
71  // Note: the list of handled protocols will be filled only if requested
72 
73  return sc;
74 }
SmartIF< IToolSvc > m_toolSvc
Handle to the tool service.
Definition: VFSSvc.h:60
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
std::string m_fallBackProtocol
Protocol to use in case there is not a specific tool to handle the URL.
Definition: VFSSvc.h:54
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:57
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
iterator end()
Definition: Map.h:131
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
iterator find(const key_type &key)
Definition: Map.h:148
prot
Definition: ana.py:53
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
std::list< IAlgTool * > m_acquiredTools
List of acquired tools (needed to release them).
Definition: VFSSvc.h:63
virtual unsigned long release()=0
Release Interface instance.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:74
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
Abstract interface for a service or tool implementing a read access to files.
Definition: IFileAccess.h:19
virtual const std::vector< std::string > & protocols() const =0
Protocols supported by the instance.
list i
Definition: ana.py:128
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:171
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::vector< std::string > m_urlHandlersNames
Names of the handlers to use.
Definition: VFSSvc.h:48
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:336
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
std::auto_ptr< std::istream > VFSSvc::open ( const std::string &  url)
virtual
See also
IFileAccess::open

Implements IFileAccess.

Definition at line 92 of file VFSSvc.cpp.

92  {
93 
94  // get the url prefix endpos
95  std::string::size_type pos = url.find("://");
96 
97  if (std::string::npos == pos) { // no url prefix
98  return m_urlHandlers[m_fallBackProtocol]->open(url);
99  }
100 
101  std::string url_prefix(url,0,pos);
102  if ( m_urlHandlers.find(url_prefix) == m_urlHandlers.end() ) {
103  // if we do not have a handler for the URL prefix,
104  // use the fall back one and pass only the path
105  return m_urlHandlers[m_fallBackProtocol]->open(url.substr(pos+3));
106  }
107  return m_urlHandlers[url_prefix]->open(url);
108 }
std::string m_fallBackProtocol
Protocol to use in case there is not a specific tool to handle the URL.
Definition: VFSSvc.h:54
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:57
iterator end()
Definition: Map.h:131
iterator find(const key_type &key)
Definition: Map.h:148
const std::vector< std::string > & VFSSvc::protocols ( ) const
virtual
See also
IFileAccess::protocols

Implements IFileAccess.

Definition at line 127 of file VFSSvc.cpp.

128 {
129  if (m_protocols.empty()){
130  // prepare the list of handled protocols
131  std::for_each(m_urlHandlers.begin(),m_urlHandlers.end(),
132  append_key<std::vector<std::string> >(const_cast<VFSSvc*>(this)->m_protocols));
133  }
134  return m_protocols;
135 }
std::vector< std::string > m_protocols
Protocols registered.
Definition: VFSSvc.h:51
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:57
iterator end()
Definition: Map.h:131
iterator begin()
Definition: Map.h:130
Simple service that allows to read files independently from the storage.
Definition: VFSSvc.h:27

Member Data Documentation

std::list<IAlgTool*> VFSSvc::m_acquiredTools
private

List of acquired tools (needed to release them).

Definition at line 63 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 54 of file VFSSvc.h.

std::vector<std::string> VFSSvc::m_protocols
private

Protocols registered.

Definition at line 51 of file VFSSvc.h.

SmartIF<IToolSvc> VFSSvc::m_toolSvc
private

Handle to the tool service.

Definition at line 60 of file VFSSvc.h.

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

Map of the tools handling the known protocols.

Definition at line 57 of file VFSSvc.h.

std::vector<std::string> VFSSvc::m_urlHandlersNames
private

Names of the handlers to use.

Definition at line 48 of file VFSSvc.h.


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