Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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");
39 pars.setSSLCAcheck(ca_check_local);
40 }
41 RDavixFileDes(const RDavixFileDes &) = delete;
43 ~RDavixFileDes() = default;
44
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 < 0)
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}
dim_t fSize
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
#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
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
RDavixFileDes(const RDavixFileDes &)=delete
RDavixFileDes & operator=(const RDavixFileDes &)=delete
Used for vector reads from multiple offsets into multiple buffers.
Definition RRawFile.hxx:71
On construction, an ROptions parameter can customize the RRawFile behavior.
Definition RRawFile.hxx:59
bool isno(const char *str)
Definition utils.h:11