The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
VFSSvc Class Reference

Simple service that allows to read files independently from the storage. More...

Inheritance diagram for VFSSvc:
Collaboration diagram for VFSSvc:

Public Member Functions

StatusCode initialize () override
 Initialize Service.
 
StatusCode finalize () override
 Finalize Service.
 
std::unique_ptr< std::istream > open (std::string const &url) override
 
const std::vector< std::string > & protocols () const override
 
- Public Member Functions inherited from extends< Service, IFileAccess >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service.
 
StatusCode sysStart () override
 Initialize Service.
 
StatusCode sysStop () override
 Initialize Service.
 
StatusCode sysFinalize () override
 Finalize Service.
 
StatusCode sysReinitialize () override
 Re-initialize the Service.
 
StatusCode sysRestart () override
 Re-initialize the Service.
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Private Attributes

Gaudi::Property< std::vector< std::string > > m_urlHandlersNames
 
Gaudi::Property< std::string > m_fallBackProtocol
 
std::vector< std::string > m_protocols
 Protocols registered.
 
GaudiUtils::HashMap< std::string, std::vector< IFileAccess * > > m_urlHandlers
 Map of the tools handling the known protocols.
 
SmartIF< IToolSvcm_toolSvc
 Handle to the tool service.
 
std::vector< IAlgTool * > m_acquiredTools
 List of acquired tools (needed to release them).
 

Additional Inherited Members

- Public Types inherited from extends< Service, IFileAccess >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service.
 

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 30 of file VFSSvc.cpp.

Member Function Documentation

◆ finalize()

StatusCode VFSSvc::finalize ( )
override

Finalize Service.

Definition at line 108 of file VFSSvc.cpp.

108 {
109 m_urlHandlers.clear(); // clear the map
110 m_protocols.clear();
111
112 if ( m_toolSvc ) {
113 // release the acquired tools (from the last acquired one)
114 while ( !m_acquiredTools.empty() ) {
115 m_toolSvc->releaseTool( m_acquiredTools.back() ).ignore();
116 m_acquiredTools.pop_back();
117 }
118 m_toolSvc.reset(); // release the tool service
119 }
120 return Service::finalize();
121}
StatusCode finalize() override
Definition Service.cpp:223
std::vector< IAlgTool * > m_acquiredTools
List of acquired tools (needed to release them).
Definition VFSSvc.cpp:61
std::vector< std::string > m_protocols
Protocols registered.
Definition VFSSvc.cpp:52
SmartIF< IToolSvc > m_toolSvc
Handle to the tool service.
Definition VFSSvc.cpp:58
GaudiUtils::HashMap< std::string, std::vector< IFileAccess * > > m_urlHandlers
Map of the tools handling the known protocols.
Definition VFSSvc.cpp:55

◆ initialize()

StatusCode VFSSvc::initialize ( )
override

Initialize Service.

Definition at line 67 of file VFSSvc.cpp.

67 {
68 StatusCode sc = Service::initialize();
69 if ( sc.isFailure() ) return sc;
70
71 m_toolSvc = serviceLocator()->service( "ToolSvc" );
72 if ( !m_toolSvc ) {
73 error() << "Cannot locate ToolSvc" << endmsg;
75 }
76
77 IAlgTool* tool;
78 for ( const auto& i : m_urlHandlersNames ) {
79 // retrieve the tool and the pointer to the interface
80 sc = m_toolSvc->retrieve( i, IAlgTool::interfaceID(), tool, nullptr, true );
81 if ( sc.isFailure() ) {
82 error() << "Cannot get tool " << i << endmsg;
83 return sc;
84 }
85 m_acquiredTools.push_back( tool ); // this is one tool that we will have to release
86 auto hndlr = SmartIF<IFileAccess>( tool );
87 if ( !hndlr ) {
88 error() << i << " does not implement IFileAccess" << endmsg;
90 }
91 // We do not need to increase the reference count for the IFileAccess interface
92 // because we hold the tool by its IAlgTool interface.
93 // loop over the list of supported protocols and add them to the map (for quick access)
94 for ( const auto& prot : hndlr->protocols() ) m_urlHandlers[prot].emplace_back( hndlr.get() );
95 }
96
97 // Now let's check if we can handle the fallback protocol
98 if ( m_urlHandlers.find( m_fallBackProtocol ) == m_urlHandlers.end() ) {
99 error() << "No handler specified for fallback protocol prefix " << m_fallBackProtocol.value() << endmsg;
100 return StatusCode::FAILURE;
101 }
102
103 // Note: the list of handled protocols will be filled only if requested
104
105 return sc;
106}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition IInterface.h:234
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
StatusCode initialize() override
Definition Service.cpp:118
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto FAILURE
Definition StatusCode.h:100
Gaudi::Property< std::string > m_fallBackProtocol
Definition VFSSvc.cpp:48
Gaudi::Property< std::vector< std::string > > m_urlHandlersNames
Definition VFSSvc.cpp:46

◆ open()

std::unique_ptr< std::istream > VFSSvc::open ( std::string const & url)
override
See also
IFileAccess::open

Definition at line 123 of file VFSSvc.cpp.

123 {
124 // get the url prefix endpos
125 auto pos = url.find( "://" );
126
127 if ( url.npos == pos ) {
128 // no url prefix, try fallback protocol
129 return VFSSvc::open( std::string{ m_fallBackProtocol }.append( "://" ).append( url ) );
130 }
131
132 const std::string url_prefix( url, 0, pos );
133 const auto handlers = m_urlHandlers.find( url_prefix );
134 if ( handlers == m_urlHandlers.end() ) {
135 // if we do not have a handler for the URL prefix,
136 // use the fall back one
137 return VFSSvc::open( std::string{ m_fallBackProtocol }.append( url.substr( pos ) ) );
138 }
139
140 std::unique_ptr<std::istream> out; // this might help RVO
141 // try the hendlers for the protocol one after the other until one succeds
142 for ( auto hndlr : handlers->second ) {
143 out = hndlr->open( url );
144 if ( out ) break;
145 }
146 return out;
147}
std::unique_ptr< std::istream > open(std::string const &url) override
Definition VFSSvc.cpp:123

◆ protocols()

const std::vector< std::string > & VFSSvc::protocols ( ) const
override
See also
IFileAccess::protocols

Definition at line 150 of file VFSSvc.cpp.

150 {
151 if ( m_protocols.empty() ) {
152 // prepare the list of handled protocols
153 std::transform( m_urlHandlers.begin(), m_urlHandlers.end(),
154 std::back_inserter( const_cast<VFSSvc*>( this )->m_protocols ),
155 []( const auto& pair ) { return pair.first; } );
156 }
157 return m_protocols;
158}

Member Data Documentation

◆ m_acquiredTools

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

List of acquired tools (needed to release them).

Definition at line 61 of file VFSSvc.cpp.

◆ m_fallBackProtocol

Gaudi::Property<std::string> VFSSvc::m_fallBackProtocol
private
Initial value:
{ this, "FallBackProtocol", "file",
"URL prefix to use if the prefix is not present." }

Definition at line 48 of file VFSSvc.cpp.

48 { this, "FallBackProtocol", "file",
49 "URL prefix to use if the prefix is not present." };

◆ m_protocols

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

Protocols registered.

Definition at line 52 of file VFSSvc.cpp.

◆ m_toolSvc

SmartIF<IToolSvc> VFSSvc::m_toolSvc
private

Handle to the tool service.

Definition at line 58 of file VFSSvc.cpp.

◆ m_urlHandlers

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

Map of the tools handling the known protocols.

Definition at line 55 of file VFSSvc.cpp.

◆ m_urlHandlersNames

Gaudi::Property<std::vector<std::string> > VFSSvc::m_urlHandlersNames
private
Initial value:
{
this, "FileAccessTools", { { "FileReadTool" } }, "List of tools implementing the IFileAccess interface." }

Definition at line 46 of file VFSSvc.cpp.

46 {
47 this, "FileAccessTools", { { "FileReadTool" } }, "List of tools implementing the IFileAccess interface." };

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