Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RRawFileDavix.cxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Jakob Blomer
3
4/*************************************************************************
5 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
13
14#include <TEnv.h>
15#include <TError.h>
16#include "utils.h"
17
18#include <memory>
19#include <stdexcept>
20#include <vector>
21
22#include <davix.hpp>
23#include <sys/stat.h>
24
25namespace {
26constexpr int kDefaultBlockSize = 128 * 1024; // Read in relatively large 128k blocks for better network utilization
27} // anonymous namespace
28
29namespace ROOT {
30namespace Internal {
31
33
34 RDavixFileDes() : fd(nullptr), pos(&ctx)
35 {
36 // CA Check
37 const auto ca_check_local_str = gEnv->GetValue("Davix.GSI.CACheck", (const char *)"y");
38 bool ca_check_local = isno(ca_check_local_str);
39 pars.setSSLCAcheck(ca_check_local);
40 }
41 RDavixFileDes(const RDavixFileDes &) = delete;
43 ~RDavixFileDes() = default;
44
45 DAVIX_FD *fd;
46 Davix::Context ctx;
47 Davix::DavPosix pos;
48 Davix::RequestParams pars;
49};
50
51} // namespace Internal
52} // namespace ROOT
53
54
56 : RRawFile(url, options), fFileDes(new RDavixFileDes())
57{
58}
59
61{
62 if (fFileDes->fd != nullptr)
63 fFileDes->pos.close(fFileDes->fd, nullptr);
64}
65
66std::unique_ptr<ROOT::Internal::RRawFile> ROOT::Internal::RRawFileDavix::Clone() const
67{
68 return std::make_unique<RRawFileDavix>(fUrl, fOptions);
69}
70
72{
73 struct stat buf;
74 Davix::DavixError *err = nullptr;
75 if (fFileDes->pos.stat(&fFileDes->pars, fUrl, &buf, &err) == -1) {
76 throw std::runtime_error("Cannot determine size of '" + fUrl + "', error: " + err->getErrMsg());
77 }
78 return buf.st_size;
79}
80
82{
83 Davix::DavixError *err = nullptr;
84 fFileDes->fd = fFileDes->pos.open(&fFileDes->pars, fUrl, O_RDONLY, &err);
85 if (fFileDes->fd == nullptr) {
86 throw std::runtime_error("Cannot open '" + fUrl + "', error: " + err->getErrMsg());
87 }
88 if (fOptions.fBlockSize == ROptions::kUseDefaultBlockSize)
89 fOptions.fBlockSize = kDefaultBlockSize;
90}
91
92size_t ROOT::Internal::RRawFileDavix::ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset)
93{
94 Davix::DavixError *err = nullptr;
95 auto retval = fFileDes->pos.pread(fFileDes->fd, buffer, nbytes, offset, &err);
96 if (retval < 0) {
97 throw std::runtime_error("Cannot read from '" + fUrl + "', error: " + err->getErrMsg());
98 }
99 return static_cast<size_t>(retval);
100}
101
103{
104 Davix::DavixError *davixErr = NULL;
105 std::vector<Davix::DavIOVecInput> in(nReq);
106 std::vector<Davix::DavIOVecOuput> out(nReq);
107
108 for (unsigned int i = 0; i < nReq; ++i) {
109 in[i].diov_buffer = ioVec[i].fBuffer;
110 in[i].diov_offset = ioVec[i].fOffset;
111 in[i].diov_size = ioVec[i].fSize;
112 R__ASSERT(ioVec[i].fSize > 0);
113 }
114
115 auto ret = fFileDes->pos.preadVec(fFileDes->fd, in.data(), out.data(), nReq, &davixErr);
116 if (ret < 0) {
117 throw std::runtime_error("Cannot do vector read from '" + fUrl + "', error: " + davixErr->getErrMsg());
118 }
119
120 for (unsigned int i = 0; i < nReq; ++i) {
121 ioVec[i].fOutBytes = out[i].diov_size;
122 }
123}
char * ret
Definition Rotated.cxx:221
externTEnv * gEnv
Definition TEnv.h:170
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Double_t err
std::unique_ptr< Internal::RDavixFileDes > fFileDes
void ReadVImpl(RIOVec *ioVec, unsigned int nReq) final
By default implemented as a loop of ReadAt calls but can be overwritten, e.g. XRootD or DAVIX impleme...
size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
Derived classes should implement low-level reading without buffering.
std::unique_ptr< RRawFile > Clone() const final
Create a new RawFile that accesses the same resource. The file pointer is reset to zero.
RRawFileDavix(std::string_view url, RRawFile::ROptions options)
std::uint64_t GetSizeImpl() final
Derived classes should return the file size.
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
RRawFile(std::string_view url, ROptions options)
Definition RRawFile.cxx:61
bool isno(const char *str)
Definition utils.h:11
RDavixFileDes(const RDavixFileDes &)=delete
RDavixFileDes & operator=(const RDavixFileDes &)=delete
Used for vector reads from multiple offsets into multiple buffers.
Definition RRawFile.hxx:61
std::size_t fOutBytes
The number of actually read bytes, set by ReadV().
Definition RRawFile.hxx:69
std::size_t fSize
The number of desired bytes.
Definition RRawFile.hxx:67
void * fBuffer
The destination for reading.
Definition RRawFile.hxx:63
std::uint64_t fOffset
The file offset.
Definition RRawFile.hxx:65
On construction, an ROptions parameter can customize the RRawFile behavior.
Definition RRawFile.hxx:49