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

StatusCode initialize () override
 Initialize Service. More...
 
StatusCode finalize () override
 Finalize Service. More...
 
std::unique_ptr< std::istreamopen (const std::string &url) override
 
const std::vector< std::string > & protocols () const override
 
 VFSSvc (const std::string &name, ISvcLocator *svcloc)
 Standard constructor. More...
 
 ~VFSSvc () override=default
 Destructor. More...
 
- Public Member Functions inherited from extends< Service, IFileAccess >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
StatusCode setProperty (const Property &p) override
 
StatusCode setProperty (const std::string &s) override
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 
StatusCode getProperty (Property *p) const override
 
const PropertygetProperty (const std::string &name) const override
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 
const std::vector< Property * > & getProperties () const override
 
bool hasProperty (const std::string &name) const override
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 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<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, 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...
 
template<class T >
StatusCode declarePrivateTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Private tool. More...
 
template<class T >
StatusCode declarePublicTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Public tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 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...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Attributes

std::vector< std::stringm_urlHandlersNames = { { "FileReadTool" } }
 Names of the handlers to use. More...
 
std::vector< std::stringm_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::vector< IAlgTool * > m_acquiredTools
 List of acquired tools (needed to release them). More...
 

Additional Inherited Members

- Public Types inherited from extends< Service, IFileAccess >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel = MSG::NIL
 Service output level. More...
 
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. 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 26 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  declareProperty("FileAccessTools",m_urlHandlersNames,
14  "List of tools implementing the IFileAccess interface.");
15 
16  declareProperty("FallBackProtocol",m_fallBackProtocol = "file",
17  "URL prefix to use if the prefix is not present.");
18 }
extends base_class
Typedef to this class.
Definition: extends.h:14
std::string m_fallBackProtocol
Protocol to use in case there is not a specific tool to handle the URL.
Definition: VFSSvc.h:54
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
std::vector< std::string > m_urlHandlersNames
Names of the handlers to use.
Definition: VFSSvc.h:48
VFSSvc::~VFSSvc ( )
overridedefault

Destructor.

Member Function Documentation

StatusCode VFSSvc::finalize ( )
override

Finalize Service.

Definition at line 63 of file VFSSvc.cpp.

63  {
64  m_urlHandlers.clear(); // clear the map
66 
67  if (m_toolSvc) {
68  // release the acquired tools (from the last acquired one)
69  while ( !m_acquiredTools.empty() ){
72  }
73  m_toolSvc.reset() ; // release the tool service
74  }
75  return Service::finalize();
76 }
SmartIF< IToolSvc > m_toolSvc
Handle to the tool service.
Definition: VFSSvc.h:60
T empty(T...args)
std::vector< std::string > m_protocols
Protocols registered.
Definition: VFSSvc.h:51
StatusCode finalize() override
Definition: Service.cpp:193
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:57
T pop_back(T...args)
T clear(T...args)
std::vector< IAlgTool * > m_acquiredTools
List of acquired tools (needed to release them).
Definition: VFSSvc.h:63
T back(T...args)
void clear()
Definition: Map.h:178
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
StatusCode VFSSvc::initialize ( )
override

Initialize Service.

Definition at line 20 of file VFSSvc.cpp.

20  {
22  if (sc.isFailure()) return sc;
23 
24 
25  m_toolSvc = serviceLocator()->service("ToolSvc");
26  if (!m_toolSvc){
27  error() << "Cannot locate ToolSvc" << endmsg;
28  return StatusCode::FAILURE;
29  }
30 
31  IAlgTool *tool;
32  for(const auto& i : m_urlHandlersNames) {
33  // retrieve the tool and the pointer to the interface
34  sc = m_toolSvc->retrieve(i,IAlgTool::interfaceID(),tool,nullptr,true);
35  if (sc.isFailure()){
36  error() << "Cannot get tool " << i << endmsg;
37  return sc;
38  }
39  m_acquiredTools.push_back(tool); // this is one tool that we will have to release
40  auto hndlr = SmartIF<IFileAccess>(tool);
41  if (!hndlr){
42  error() << i << " does not implement IFileAccess" << endmsg;
43  return StatusCode::FAILURE;
44  }
45  // We do not need to increase the reference count for the IFileAccess interface
46  // because we hold the tool by its IAlgTool interface.
47  // loop over the list of supported protocols and add them to the map (for quick access)
48  for ( const auto& prot : hndlr->protocols() ) m_urlHandlers[prot] = hndlr.get();
49  }
50 
51  // Now let's check if we can handle the fallback protocol
53  error() << "No handler specified for fallback protocol prefix "
55  return StatusCode::FAILURE;
56  }
57 
58  // Note: the list of handled protocols will be filled only if requested
59 
60  return sc;
61 }
SmartIF< IToolSvc > m_toolSvc
Handle to the tool service.
Definition: VFSSvc.h:60
StatusCode initialize() override
Definition: Service.cpp:68
virtual StatusCode retrieve(const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent=0, bool createIf=true)=0
Retrieve tool with tool dependent part of the name automatically assigned.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
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:86
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
T push_back(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
iterator end()
Definition: Map.h:132
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
iterator find(const key_type &key)
Definition: Map.h:149
prot
Definition: ana.py:53
std::vector< IAlgTool * > m_acquiredTools
List of acquired tools (needed to release them).
Definition: VFSSvc.h:63
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
list i
Definition: ana.py:128
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:243
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
std::unique_ptr< std::istream > VFSSvc::open ( const std::string url)
override
See also
IFileAccess::open

Definition at line 78 of file VFSSvc.cpp.

78  {
79 
80  // get the url prefix endpos
81  auto pos = url.find("://");
82 
83  if (std::string::npos == pos) { // no url prefix
84  return m_urlHandlers[m_fallBackProtocol]->open(url);
85  }
86 
87  std::string url_prefix(url,0,pos);
88  if ( m_urlHandlers.find(url_prefix) == m_urlHandlers.end() ) {
89  // if we do not have a handler for the URL prefix,
90  // use the fall back one and pass only the path
91  return m_urlHandlers[m_fallBackProtocol]->open(url.substr(pos+3));
92  }
93  return m_urlHandlers[url_prefix]->open(url);
94 }
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
STL class.
iterator end()
Definition: Map.h:132
iterator find(const key_type &key)
Definition: Map.h:149
T find(T...args)
T substr(T...args)
const std::vector< std::string > & VFSSvc::protocols ( ) const
override
See also
IFileAccess::protocols

Definition at line 106 of file VFSSvc.cpp.

107 {
108  if (m_protocols.empty()){
109  // prepare the list of handled protocols
111  std::back_inserter(const_cast<VFSSvc*>(this)->m_protocols),
112  select1st );
113  }
114  return m_protocols;
115 }
T empty(T...args)
std::vector< std::string > m_protocols
Protocols registered.
Definition: VFSSvc.h:51
constexpr struct select1st_t select1st
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:57
iterator end()
Definition: Map.h:132
iterator begin()
Definition: Map.h:131
T back_inserter(T...args)
T transform(T...args)

Member Data Documentation

std::vector<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 = { { "FileReadTool" } }
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: