Project
Loading...
Searching...
No Matches
ByteSource.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include "AODNative/Errors.h"
14#include "FailoverByteSource.h"
15#include "LocalByteSource.h"
16#ifdef AODNATIVE_WITH_XROOTD
17#include "XRootDByteSource.h"
18#endif
19#ifdef AODNATIVE_WITH_CURL
20#include "HttpByteSource.h"
21#endif
22
23namespace o2::aod::native
24{
25
26ByteSource::~ByteSource() = default;
27
28std::unique_ptr<ByteSource> ByteSource::open(std::string url, const Options& options)
29{
30 if (url.starts_with("file://")) {
31 return std::make_unique<LocalByteSource>(url.substr(7), options);
32 }
33 for (auto scheme : {"root://", "roots://", "xroot://", "xroots://"}) {
34 if (url.starts_with(scheme)) {
35#ifdef AODNATIVE_WITH_XROOTD
36 return std::make_unique<XRootDByteSource>(std::move(url), options);
37#else
38 throw IoError(url, "the native reader was built without XRootD");
39#endif
40 }
41 }
42 for (auto scheme : {"http://", "https://"}) {
43 if (url.starts_with(scheme)) {
44#ifdef AODNATIVE_WITH_CURL
45 return std::make_unique<HttpByteSource>(std::move(url), options);
46#else
47 throw IoError(url, "the native reader was built without curl");
48#endif
49 }
50 }
51 // alien:// names are resolved to root:// replicas by the caller.
52 for (auto scheme : {"alien://"}) {
53 if (url.starts_with(scheme)) {
54 throw IoError(url, "alien:// names must be resolved to a replica first");
55 }
56 }
57 if (url.find("://") != std::string::npos) {
58 throw IoError(url, "unknown URL scheme");
59 }
60 return std::make_unique<LocalByteSource>(std::move(url), options);
61}
62
63std::unique_ptr<ByteSource> ByteSource::openReplicas(std::vector<Replica> replicas, const Options& options,
64 std::function<void(std::string const&)> log)
65{
66 return std::make_unique<FailoverByteSource>(std::move(replicas), options, &ByteSource::open, std::move(log));
67}
68
69} // namespace o2::aod::native
std::string url
static std::unique_ptr< ByteSource > open(std::string url, const Options &)
virtual std::string url() const =0
static std::unique_ptr< ByteSource > openReplicas(std::vector< Replica > replicas, const Options &, std::function< void(std::string const &)> log={})
Failure of the underlying transport.
Definition Errors.h:69