Skip to content
Snippets Groups Projects
Commit 245c4979 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Merge branch 'improve-vfssvc' into 'master'

allow multiple handlers for a protocol in VFSSvc

See merge request !295
parents 1c2b2e1a 47398847
No related branches found
No related tags found
1 merge request!295allow multiple handlers for a protocol in VFSSvc
Pipeline #
...@@ -21,7 +21,7 @@ StatusCode VFSSvc::initialize() { ...@@ -21,7 +21,7 @@ StatusCode VFSSvc::initialize() {
IAlgTool *tool; IAlgTool *tool;
for(const auto& i : m_urlHandlersNames) { for(const auto& i : m_urlHandlersNames) {
// retrieve the tool and the pointer to the interface // retrieve the tool and the pointer to the interface
sc = m_toolSvc->retrieve(i,IAlgTool::interfaceID(),tool,nullptr,true); sc = m_toolSvc->retrieve(i, IAlgTool::interfaceID(), tool, nullptr, true);
if (sc.isFailure()){ if (sc.isFailure()){
error() << "Cannot get tool " << i << endmsg; error() << "Cannot get tool " << i << endmsg;
return sc; return sc;
...@@ -35,7 +35,7 @@ StatusCode VFSSvc::initialize() { ...@@ -35,7 +35,7 @@ StatusCode VFSSvc::initialize() {
// We do not need to increase the reference count for the IFileAccess interface // We do not need to increase the reference count for the IFileAccess interface
// because we hold the tool by its IAlgTool interface. // because we hold the tool by its IAlgTool interface.
// loop over the list of supported protocols and add them to the map (for quick access) // loop over the list of supported protocols and add them to the map (for quick access)
for ( const auto& prot : hndlr->protocols() ) m_urlHandlers[prot] = hndlr.get(); for ( const auto& prot : hndlr->protocols() ) m_urlHandlers[prot].emplace_back( hndlr.get() );
} }
// Now let's check if we can handle the fallback protocol // Now let's check if we can handle the fallback protocol
...@@ -66,21 +66,29 @@ StatusCode VFSSvc::finalize() { ...@@ -66,21 +66,29 @@ StatusCode VFSSvc::finalize() {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
std::unique_ptr<std::istream> VFSSvc::open(const std::string &url){ std::unique_ptr<std::istream> VFSSvc::open(const std::string &url){
// get the url prefix endpos // get the url prefix endpos
auto pos = url.find("://"); auto pos = url.find("://");
if (std::string::npos == pos) { // no url prefix if (std::string::npos == pos) {
return m_urlHandlers[m_fallBackProtocol]->open(url); // no url prefix, try fallback protocol
return VFSSvc::open(m_fallBackProtocol + "://" + url);
} }
std::string url_prefix(url,0,pos); const std::string url_prefix(url, 0, pos);
if ( m_urlHandlers.find(url_prefix) == m_urlHandlers.end() ) { const auto handlers = m_urlHandlers.find(url_prefix);
if ( handlers == m_urlHandlers.end() ) {
// if we do not have a handler for the URL prefix, // if we do not have a handler for the URL prefix,
// use the fall back one and pass only the path // use the fall back one
return m_urlHandlers[m_fallBackProtocol]->open(url.substr(pos+3)); return VFSSvc::open(m_fallBackProtocol + url.substr(pos));
}
std::unique_ptr<std::istream> out; // this might help RVO
// try the hendlers for the protocol one after the other until one succeds
for( auto hndlr: handlers->second ) {
out = hndlr->open(url);
if ( out ) break;
} }
return m_urlHandlers[url_prefix]->open(url); return out;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace { namespace {
......
...@@ -52,7 +52,7 @@ private: ...@@ -52,7 +52,7 @@ private:
std::vector<std::string> m_protocols; std::vector<std::string> m_protocols;
/// Map of the tools handling the known protocols. /// Map of the tools handling the known protocols.
GaudiUtils::HashMap<std::string, IFileAccess*> m_urlHandlers; GaudiUtils::HashMap<std::string, std::vector<IFileAccess*>> m_urlHandlers;
/// Handle to the tool service. /// Handle to the tool service.
SmartIF<IToolSvc> m_toolSvc; SmartIF<IToolSvc> m_toolSvc;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment