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::istream > open (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< BASE, Interfaces >
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::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
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::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Attributes

std::vector< std::string > m_urlHandlersNames = { { {"FileReadTool"} } }
 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::vector< IAlgTool * > m_acquiredTools
 List of acquired tools (needed to release them). More...
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
- 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...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... 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 }
std::string m_fallBackProtocol
Protocol to use in case there is not a specific tool to handle the URL.
Definition: VFSSvc.h:53
extends base_class
Typedef to this class.
Definition: extends.h:14
std::vector< std::string > m_urlHandlersNames
Names of the handlers to use.
Definition: VFSSvc.h:47
VFSSvc::~VFSSvc ( )
overridedefault

Destructor.

Member Function Documentation

StatusCode VFSSvc::finalize ( )
override

Finalize Service.

Definition at line 64 of file VFSSvc.cpp.

64  {
65  m_urlHandlers.clear(); // clear the map
66  m_protocols.clear();
67 
68  if (m_toolSvc) {
69  // release the acquired tools (from the last acquired one)
70  while ( !m_acquiredTools.empty() ){
71  m_toolSvc->releaseTool(m_acquiredTools.back()).ignore();
72  m_acquiredTools.pop_back();
73  }
74  m_toolSvc.reset() ; // release the tool service
75  }
76  return Service::finalize();
77 }
SmartIF< IToolSvc > m_toolSvc
Handle to the tool service.
Definition: VFSSvc.h:59
std::vector< std::string > m_protocols
Protocols registered.
Definition: VFSSvc.h:50
StatusCode finalize() override
Definition: Service.cpp:187
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:56
std::vector< IAlgTool * > m_acquiredTools
List of acquired tools (needed to release them).
Definition: VFSSvc.h:62
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  MsgStream log(msgSvc(), name());
25 
26  m_toolSvc = serviceLocator()->service("ToolSvc");
27  if (!m_toolSvc){
28  log << MSG::ERROR << "Cannot locate ToolSvc" << endmsg;
29  return StatusCode::FAILURE;
30  }
31 
32  IAlgTool *tool;
33  for(const auto& i : m_urlHandlersNames) {
34  // retrieve the tool and the pointer to the interface
35  sc = m_toolSvc->retrieve(i,IAlgTool::interfaceID(),tool,0,true);
36  if (sc.isFailure()){
37  log << MSG::ERROR << "Cannot get tool " << i << endmsg;
38  return sc;
39  }
40  m_acquiredTools.push_back(tool); // this is one tool that we will have to release
41  auto hndlr = SmartIF<IFileAccess>(tool);
42  if (!hndlr){
43  log << MSG::ERROR << i << " does not implement IFileAccess" << endmsg;
44  return StatusCode::FAILURE;
45  }
46  // We do not need to increase the reference count for the IFileAccess interface
47  // because we hold the tool by its IAlgTool interface.
48  // loop over the list of supported protocols and add them to the map (for quick access)
49  for ( const auto& prot : hndlr->protocols() ) m_urlHandlers[prot] = hndlr.get();
50  }
51 
52  // Now let's check if we can handle the fallback protocol
54  log << MSG::ERROR << "No handler specified for fallback protocol prefix "
56  return StatusCode::FAILURE;
57  }
58 
59  // Note: the list of handled protocols will be filled only if requested
60 
61  return sc;
62 }
SmartIF< IToolSvc > m_toolSvc
Handle to the tool service.
Definition: VFSSvc.h:59
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:62
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.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::string m_fallBackProtocol
Protocol to use in case there is not a specific tool to handle the URL.
Definition: VFSSvc.h:53
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:56
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
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:62
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:22
list i
Definition: ana.py:128
std::vector< std::string > m_urlHandlersNames
Names of the handlers to use.
Definition: VFSSvc.h:47
std::unique_ptr< std::istream > VFSSvc::open ( const std::string &  url)
override
See also
IFileAccess::open

Definition at line 79 of file VFSSvc.cpp.

79  {
80 
81  // get the url prefix endpos
82  auto pos = url.find("://");
83 
84  if (std::string::npos == pos) { // no url prefix
85  return m_urlHandlers[m_fallBackProtocol]->open(url);
86  }
87 
88  std::string url_prefix(url,0,pos);
89  if ( m_urlHandlers.find(url_prefix) == m_urlHandlers.end() ) {
90  // if we do not have a handler for the URL prefix,
91  // use the fall back one and pass only the path
92  return m_urlHandlers[m_fallBackProtocol]->open(url.substr(pos+3));
93  }
94  return m_urlHandlers[url_prefix]->open(url);
95 }
std::string m_fallBackProtocol
Protocol to use in case there is not a specific tool to handle the URL.
Definition: VFSSvc.h:53
GaudiUtils::HashMap< std::string, IFileAccess * > m_urlHandlers
Map of the tools handling the known protocols.
Definition: VFSSvc.h:56
iterator end()
Definition: Map.h:132
iterator find(const key_type &key)
Definition: Map.h:149
const std::vector< std::string > & VFSSvc::protocols ( ) const
override
See also
IFileAccess::protocols

Definition at line 107 of file VFSSvc.cpp.

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

Member Data Documentation

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

List of acquired tools (needed to release them).

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

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

Protocols registered.

Definition at line 50 of file VFSSvc.h.

SmartIF<IToolSvc> VFSSvc::m_toolSvc
private

Handle to the tool service.

Definition at line 59 of file VFSSvc.h.

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

Map of the tools handling the known protocols.

Definition at line 56 of file VFSSvc.h.

std::vector<std::string> VFSSvc::m_urlHandlersNames = { { {"FileReadTool"} } }
private

Names of the handlers to use.

Definition at line 47 of file VFSSvc.h.


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