|
Gaudi Framework, version v23r2 |
| Home | Generated: Thu Jun 28 2012 |
Simple service that allows to read files independently from the storage. More...
#include <VFSSvc.h>


Public Member Functions | |
| virtual StatusCode | initialize () |
| Initialize Service. | |
| virtual StatusCode | finalize () |
| Finalize Service. | |
| virtual std::auto_ptr < std::istream > | open (const std::string &url) |
| virtual const std::vector < std::string > & | protocols () const |
Protected Member Functions | |
| VFSSvc (const std::string &name, ISvcLocator *svcloc) | |
| Standard constructor. | |
| virtual | ~VFSSvc () |
| Destructor. | |
Private Attributes | |
| std::vector< std::string > | m_urlHandlersNames |
| Names of the handlers to use. | |
| std::vector< std::string > | m_protocols |
| Protocols registered. | |
| std::string | m_fallBackProtocol |
| Protocol to use in case there is not a specific tool to handle the URL. | |
| GaudiUtils::HashMap < std::string, IFileAccess * > | m_urlHandlers |
| Map of the tools handling the known protocols. | |
| SmartIF< IToolSvc > | m_toolSvc |
| Handle to the tool service. | |
| std::list< IAlgTool * > | m_acquiredTools |
| List of acquired tools (needed to release them). | |
Friends | |
| class | SvcFactory< VFSSvc > |
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...
Definition at line 28 of file VFSSvc.h.
| VFSSvc::VFSSvc | ( | const std::string & | name, |
| ISvcLocator * | svcloc | ||
| ) | [protected] |
Standard constructor.
Definition at line 11 of file VFSSvc.cpp.
: base_class(name,svc) { m_urlHandlersNames.push_back("FileReadTool"); declareProperty("FileAccessTools",m_urlHandlersNames, "List of tools implementing the IFileAccess interface."); declareProperty("FallBackProtocol",m_fallBackProtocol = "file", "URL prefix to use if the prefix is not present."); }
| VFSSvc::~VFSSvc | ( | ) | [protected, virtual] |
| StatusCode VFSSvc::finalize | ( | ) | [virtual] |
Finalize Service.
Reimplemented from Service.
Definition at line 77 of file VFSSvc.cpp.
{
m_urlHandlers.clear(); // clear the map
m_protocols.clear();
if (m_toolSvc) {
// release the acquired tools (from the last acquired one)
while ( m_acquiredTools.begin() != m_acquiredTools.end() ){
m_toolSvc->releaseTool(*m_acquiredTools.begin()).ignore();
m_acquiredTools.pop_front();
}
m_toolSvc->release(); // release the tool service
m_toolSvc = 0;
}
return Service::finalize();
}
| StatusCode VFSSvc::initialize | ( | ) | [virtual] |
Initialize Service.
Reimplemented from Service.
Definition at line 25 of file VFSSvc.cpp.
{
StatusCode sc = Service::initialize();
if (sc.isFailure()){
return sc;
}
MsgStream log(msgSvc(), name());
m_toolSvc = serviceLocator()->service("ToolSvc");
if (!m_toolSvc.isValid()){
log << MSG::ERROR << "Cannot locate ToolSvc" << endmsg;
return StatusCode::FAILURE;
}
IAlgTool *tool;
IFileAccess *hndlr;
std::vector<std::string>::iterator i;
for(i = m_urlHandlersNames.begin(); i != m_urlHandlersNames.end(); ++i){
// retrieve the tool and the pointer to the interface
sc = m_toolSvc->retrieve(*i,IAlgTool::interfaceID(),tool,0,true);
if (sc.isFailure()){
log << MSG::ERROR << "Cannot get tool " << *i << endmsg;
return sc;
}
m_acquiredTools.push_front(tool); // this is one tool that we will have to release
sc = tool->queryInterface(IFileAccess::interfaceID(),pp_cast<void>(&hndlr));
if (sc.isFailure()){
log << MSG::ERROR << *i << " does not implement IFileAccess" << endmsg;
return sc;
}
// We do not need to increase the reference count for the IFileAccess interface
// because we hold the tool by its IAlgTool interface.
hndlr->release();
// loop over the list of supported protocols and add them to the map (for quick access)
for ( std::vector<std::string>::const_iterator prot = hndlr->protocols().begin();
prot != hndlr->protocols().end(); ++prot ){
m_urlHandlers[*prot] = hndlr;
}
}
// Now let's check if we can handle the fallback protocol
if ( m_urlHandlers.find(m_fallBackProtocol) == m_urlHandlers.end() ) {
log << MSG::ERROR << "No handler specified for fallback protocol prefix "
<< m_fallBackProtocol << endmsg;
return StatusCode::FAILURE;
}
// Note: the list of handled protocols will be filled only if requested
return sc;
}
| std::auto_ptr< std::istream > VFSSvc::open | ( | const std::string & | url ) | [virtual] |
Implements IFileAccess.
Definition at line 93 of file VFSSvc.cpp.
{
// get the url prefix endpos
std::string::size_type pos = url.find("://");
if (std::string::npos == pos) { // no url prefix
return m_urlHandlers[m_fallBackProtocol]->open(url);
}
std::string url_prefix(url,0,pos);
if ( m_urlHandlers.find(url_prefix) == m_urlHandlers.end() ) {
// if we do not have a handler for the URL prefix,
// use the fall back one and pass only the path
return m_urlHandlers[m_fallBackProtocol]->open(url.substr(pos+3));
}
return m_urlHandlers[url_prefix]->open(url);
}
| const std::vector< std::string > & VFSSvc::protocols | ( | ) | const [virtual] |
Implements IFileAccess.
Definition at line 128 of file VFSSvc.cpp.
{
if (m_protocols.empty()){
// prepare the list of handled protocols
std::for_each(m_urlHandlers.begin(),m_urlHandlers.end(),
append_key<std::vector<std::string> >(const_cast<VFSSvc*>(this)->m_protocols));
}
return m_protocols;
}
friend class SvcFactory< VFSSvc > [friend] |
std::list<IAlgTool*> VFSSvc::m_acquiredTools [private] |
std::string VFSSvc::m_fallBackProtocol [private] |
std::vector<std::string> VFSSvc::m_protocols [private] |
SmartIF<IToolSvc> VFSSvc::m_toolSvc [private] |
std::vector<std::string> VFSSvc::m_urlHandlersNames [private] |