Gaudi Framework, version v23r9

Home   Generated: Thu Jul 18 2013
 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 
5 #include "GaudiKernel/IToolSvc.h"
6 #include "GaudiKernel/IAlgTool.h"
7 
9 
10 //------------------------------------------------------------------------------
11 VFSSvc::VFSSvc(const std::string& name, ISvcLocator* svc):
12  base_class(name,svc) {
13 
14  m_urlHandlersNames.push_back("FileReadTool");
15 
16  declareProperty("FileAccessTools",m_urlHandlersNames,
17  "List of tools implementing the IFileAccess interface.");
18 
19  declareProperty("FallBackProtocol",m_fallBackProtocol = "file",
20  "URL prefix to use if the prefix is not present.");
21 }
22 //------------------------------------------------------------------------------
24 //------------------------------------------------------------------------------
27  if (sc.isFailure()){
28  return sc;
29  }
30 
31  MsgStream log(msgSvc(), name());
32 
33  m_toolSvc = serviceLocator()->service("ToolSvc");
34  if (!m_toolSvc.isValid()){
35  log << MSG::ERROR << "Cannot locate ToolSvc" << endmsg;
36  return StatusCode::FAILURE;
37  }
38 
39  IAlgTool *tool;
40  IFileAccess *hndlr;
42  for(i = m_urlHandlersNames.begin(); i != m_urlHandlersNames.end(); ++i){
43  // retrieve the tool and the pointer to the interface
44  sc = m_toolSvc->retrieve(*i,IAlgTool::interfaceID(),tool,0,true);
45  if (sc.isFailure()){
46  log << MSG::ERROR << "Cannot get tool " << *i << endmsg;
47  return sc;
48  }
49  m_acquiredTools.push_front(tool); // this is one tool that we will have to release
50  sc = tool->queryInterface(IFileAccess::interfaceID(),pp_cast<void>(&hndlr));
51  if (sc.isFailure()){
52  log << MSG::ERROR << *i << " does not implement IFileAccess" << endmsg;
53  return sc;
54  }
55  // We do not need to increase the reference count for the IFileAccess interface
56  // because we hold the tool by its IAlgTool interface.
57  hndlr->release();
58  // loop over the list of supported protocols and add them to the map (for quick access)
60  prot != hndlr->protocols().end(); ++prot ){
61  m_urlHandlers[*prot] = hndlr;
62  }
63  }
64 
65  // Now let's check if we can handle the fallback protocol
67  log << MSG::ERROR << "No handler specified for fallback protocol prefix "
69  return StatusCode::FAILURE;
70  }
71 
72  // Note: the list of handled protocols will be filled only if requested
73 
74  return sc;
75 }
76 //------------------------------------------------------------------------------
78  m_urlHandlers.clear(); // clear the map
80 
81  if (m_toolSvc) {
82  // release the acquired tools (from the last acquired one)
83  while ( m_acquiredTools.begin() != m_acquiredTools.end() ){
84  m_toolSvc->releaseTool(*m_acquiredTools.begin()).ignore();
86  }
87  m_toolSvc->release(); // release the tool service
88  m_toolSvc = 0;
89  }
90  return Service::finalize();
91 }
92 //------------------------------------------------------------------------------
94 
95  // get the url prefix endpos
96  std::string::size_type pos = url.find("://");
97 
98  if (std::string::npos == pos) { // no url prefix
99  return m_urlHandlers[m_fallBackProtocol]->open(url);
100  }
101 
102  std::string url_prefix(url,0,pos);
103  if ( m_urlHandlers.find(url_prefix) == m_urlHandlers.end() ) {
104  // if we do not have a handler for the URL prefix,
105  // use the fall back one and pass only the path
106  return m_urlHandlers[m_fallBackProtocol]->open(url.substr(pos+3));
107  }
108  return m_urlHandlers[url_prefix]->open(url);
109 }
110 //------------------------------------------------------------------------------
111 namespace {
114  template <class Container>
115  struct append_key
116  {
117  append_key(Container &C):c(C){}
118 
119  template <class PAIR>
120  void operator() (const PAIR &x)
121  {
122  c.push_back(x.first);
123  }
124 
125  Container &c;
126  };
127 }
129 {
130  if (m_protocols.empty()){
131  // prepare the list of handled protocols
133  append_key<std::vector<std::string> >(const_cast<VFSSvc*>(this)->m_protocols));
134  }
135  return m_protocols;
136 }

Generated at Thu Jul 18 2013 12:18:05 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004