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 "LocalByteSource.h"
15#ifdef AODNATIVE_WITH_XROOTD
16#include "XRootDByteSource.h"
17#endif
18#ifdef AODNATIVE_WITH_CURL
19#include "HttpByteSource.h"
20#endif
21
22namespace o2::aod::native
23{
24
25ByteSource::~ByteSource() = default;
26
27std::unique_ptr<ByteSource> ByteSource::open(std::string url, const Options& options)
28{
29 if (url.starts_with("file://")) {
30 return std::make_unique<LocalByteSource>(url.substr(7), options);
31 }
32 for (auto scheme : {"root://", "roots://", "xroot://", "xroots://"}) {
33 if (url.starts_with(scheme)) {
34#ifdef AODNATIVE_WITH_XROOTD
35 return std::make_unique<XRootDByteSource>(std::move(url), options);
36#else
37 throw IoError(url, "the native reader was built without XRootD");
38#endif
39 }
40 }
41 for (auto scheme : {"http://", "https://"}) {
42 if (url.starts_with(scheme)) {
43#ifdef AODNATIVE_WITH_CURL
44 return std::make_unique<HttpByteSource>(std::move(url), options);
45#else
46 throw IoError(url, "the native reader was built without curl");
47#endif
48 }
49 }
50 // alien:// names are resolved to root:// replicas by the caller.
51 for (auto scheme : {"alien://"}) {
52 if (url.starts_with(scheme)) {
53 throw IoError(url, "alien:// names must be resolved to a replica first");
54 }
55 }
56 if (url.find("://") != std::string::npos) {
57 throw IoError(url, "unknown URL scheme");
58 }
59 return std::make_unique<LocalByteSource>(std::move(url), options);
60}
61
62} // namespace o2::aod::native
std::string url
static std::unique_ptr< ByteSource > open(std::string url, const Options &)
virtual std::string url() const =0
Failure of the underlying transport.
Definition Errors.h:69