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 <TError.h>
15
16#include <memory>
17#include <stdexcept>
18#include <vector>
19
20#include <davix.hpp>
21#include <sys/stat.h>
22
23namespace {
24constexpr int kDefaultBlockSize = 128 * 1024; // Read in relatively large 128k blocks for better network utilization
25} // anonymous namespace
26
27namespace ROOT {
28namespace Internal {
29
31 RDavixFileDes() : fd(nullptr), pos(&ctx) {}
32 RDavixFileDes(const RDavixFileDes &) = delete;
34 ~RDavixFileDes() = default;
35
36 DAVIX_FD *fd;
37 Davix::Context ctx;
38 Davix::DavPosix pos;
39};
40
41} // namespace Internal
42} // namespace ROOT
43
44
46 : RRawFile(url, options), fFileDes(new RDavixFileDes())
47{
48}
49
51{
52 if (fFileDes->fd != nullptr)
53 fFileDes->pos.close(fFileDes->fd, nullptr);
54}
55
56std::unique_ptr<ROOT::Internal::RRawFile> ROOT::Internal::RRawFileDavix::Clone() const
57{
58 return std::make_unique<RRawFileDavix>(fUrl, fOptions);
59}
60
62{
63 struct stat buf;
64 Davix::DavixError *err = nullptr;
65 if (fFileDes->pos.stat(nullptr, fUrl, &buf, &err) == -1) {
66 throw std::runtime_error("Cannot determine size of '" + fUrl + "', error: " + err->getErrMsg());
67 }
68 return buf.st_size;
69}
70
72{
73 Davix::DavixError *err = nullptr;
74 fFileDes->fd = fFileDes->pos.open(nullptr, fUrl, O_RDONLY, &err);
75 if (fFileDes->fd == nullptr) {
76 throw std::runtime_error("Cannot open '" + fUrl + "', error: " + err->getErrMsg());
77 }
78 if (fOptions.fBlockSize < 0)
79 fOptions.fBlockSize = kDefaultBlockSize;
80}
81
82size_t ROOT::Internal::RRawFileDavix::ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset)
83{
84 Davix::DavixError *err = nullptr;
85 auto retval = fFileDes->pos.pread(fFileDes->fd, buffer, nbytes, offset, &err);
86 if (retval < 0) {
87 throw std::runtime_error("Cannot read from '" + fUrl + "', error: " + err->getErrMsg());
88 }
89 return static_cast<size_t>(retval);
90}
91
92void ROOT::Internal::RRawFileDavix::ReadVImpl(RIOVec *ioVec, unsigned int nReq)
93{
94 Davix::DavixError *davixErr = NULL;
95 std::vector<Davix::DavIOVecInput> in(nReq);
96 std::vector<Davix::DavIOVecOuput> out(nReq);
97
98 for (unsigned int i = 0; i < nReq; ++i) {
99 in[i].diov_buffer = ioVec[i].fBuffer;
100 in[i].diov_offset = ioVec[i].fOffset;
101 in[i].diov_size = ioVec[i].fSize;
102 R__ASSERT(ioVec[i].fSize > 0);
103 }
104
105 auto ret = fFileDes->pos.preadVec(fFileDes->fd, in.data(), out.data(), nReq, &davixErr);
106 if (ret < 0) {
107 throw std::runtime_error("Cannot do vector read from '" + fUrl + "', error: " + davixErr->getErrMsg());
108 }
109
110 for (unsigned int i = 0; i < nReq; ++i) {
111 ioVec[i].fOutBytes = out[i].diov_size;
112 }
113}
size_t fSize
#define R__ASSERT(e)
Definition TError.h:118
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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 or kUnknownFileSize.
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
The RRawFile provides read-only access to local and remote files.
Definition RRawFile.hxx:43
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
RDavixFileDes(const RDavixFileDes &)=delete
RDavixFileDes & operator=(const RDavixFileDes &)=delete
Used for vector reads from multiple offsets into multiple buffers.
Definition RRawFile.hxx:71
std::size_t fOutBytes
The number of actually read bytes, set by ReadV()
Definition RRawFile.hxx:79
std::size_t fSize
The number of desired bytes.
Definition RRawFile.hxx:77
void * fBuffer
The destination for reading.
Definition RRawFile.hxx:73
std::uint64_t fOffset
The file offset.
Definition RRawFile.hxx:75
On construction, an ROptions parameter can customize the RRawFile behavior.
Definition RRawFile.hxx:59