Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VFSSvc.cpp
Go to the documentation of this file.
1 #include "VFSSvc.h"
2 
4 #include "GaudiKernel/IToolSvc.h"
5 #include "GaudiKernel/IAlgTool.h"
6 
8 
9 //------------------------------------------------------------------------------
10 VFSSvc::VFSSvc(const std::string& name, ISvcLocator* svc):
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 }
21 //------------------------------------------------------------------------------
23 //------------------------------------------------------------------------------
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;
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)
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 }
75 //------------------------------------------------------------------------------
77  m_urlHandlers.clear(); // clear the map
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();
85  }
86  m_toolSvc->release(); // release the tool service
87  m_toolSvc = 0;
88  }
89  return Service::finalize();
90 }
91 //------------------------------------------------------------------------------
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 }
109 //------------------------------------------------------------------------------
110 namespace {
113  template <class Container>
114  struct append_key
115  {
116  append_key(Container &C):c(C){}
117 
118  template <class PAIR>
119  void operator() (const PAIR &x)
120  {
121  c.push_back(x.first);
122  }
123 
124  Container &c;
125  };
126 }
128 {
129  if (m_protocols.empty()){
130  // prepare the list of handled protocols
132  append_key<std::vector<std::string> >(const_cast<VFSSvc*>(this)->m_protocols));
133  }
134  return m_protocols;
135 }

Generated at Mon Feb 17 2014 14:37:49 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004