The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
FileReadTool.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include <GaudiKernel/AlgTool.h>
13#include <fstream>
14
24struct FileReadTool : extends<AlgTool, IFileAccess> {
26 using extends::extends;
27
28 std::unique_ptr<std::istream> open( std::string const& url ) override {
29 // remove the optional "file://" from the beginning of the url
30 constexpr auto prefix = std::string_view{ "file://" };
31 return std::make_unique<std::ifstream>( url.compare( 0, prefix.size(), prefix ) == 0 ? url.substr( prefix.size() )
32 : url );
33 }
34
36 const std::vector<std::string>& protocols() const override {
38 static const std::vector<std::string> s_protocols = { { "file" } };
39 return s_protocols;
40 }
41};
42
#define DECLARE_COMPONENT(type)
Base class used to extend a class implementing other interfaces.
Definition extends.h:19
Basic implementation of the IFileAccess interface.
std::unique_ptr< std::istream > open(std::string const &url) override
const std::vector< std::string > & protocols() const override
Protocols supported by the instance.