Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RRawFileNetXNG.cxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Michal Simon
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 <cctype>
17#include <memory>
18#include <sstream>
19#include <stdexcept>
20#include <string>
21#include <vector>
22#include <utility>
23#include <XrdCl/XrdClFile.hh>
24#include <XrdCl/XrdClFileSystem.hh>
25#include <XrdVersion.hh>
26
27namespace {
28constexpr int kDefaultBlockSize = 128 * 1024; // Read in relatively large 128k blocks for better network utilization
29} // anonymous namespace
30
31namespace ROOT {
32namespace Internal {
33
35 RRawFileNetXNGImpl() = default;
39
40 XrdCl::File file;
41};
42
43} // namespace Internal
44} // namespace ROOT
45
46
48 RRawFile::ROptions options )
49 : RRawFile( url, options ), pImpl( new RRawFileNetXNGImpl() )
50{
51}
52
54{
55}
56
57std::unique_ptr<ROOT::Internal::RRawFile> ROOT::Internal::RRawFileNetXNG::Clone() const
58{
59 return std::make_unique<RRawFileNetXNG>( fUrl, fOptions );
60}
61
63{
64 XrdCl::StatInfo *info = nullptr;
65 auto st = pImpl->file.Stat( true, info );
66 if( !st.IsOK() )
67 throw std::runtime_error( "Cannot determine size of '" + fUrl + "', " +
68 st.ToString() + "; " + st.GetErrorMessage() );
69 std::uint64_t ret = info->GetSize();
70 delete info; // XrdCl only allocates the object is the status was OK
71 return ret;
72}
73
75{
76 auto st = pImpl->file.Open( fUrl, XrdCl::OpenFlags::Read );
77 if( !st.IsOK() )
78 throw std::runtime_error( "Cannot open '" + fUrl + "', " +
79 st.ToString() + "; " + st.GetErrorMessage() );
80 if( fOptions.fBlockSize < 0 ) fOptions.fBlockSize = kDefaultBlockSize;
81}
82
83size_t ROOT::Internal::RRawFileNetXNG::ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset)
84{
85 std::uint32_t btsread = 0;
86 auto st = pImpl->file.Read( offset, nbytes, buffer, btsread );
87 if( !st.IsOK() )
88 throw std::runtime_error( "Cannot read from '" + fUrl + "', " +
89 st.ToString() + "; " + st.GetErrorMessage() );
90 return btsread;
91}
92
94{
95 XrdCl::ChunkList chunks;
96 chunks.reserve( nReq );
97 for( std::size_t i = 0; i < nReq; ++i )
98 chunks.emplace_back( ioVec[i].fOffset, ioVec[i].fSize, ioVec[i].fBuffer );
99
100 XrdCl::VectorReadInfo *info = nullptr;
101 auto st = pImpl->file.VectorRead( chunks, nullptr, info );
102 if( !st.IsOK() )
103 throw std::runtime_error( "Cannot do vector read from '" + fUrl + "', " +
104 st.ToString() + "; " + st.GetErrorMessage() );
105
106 XrdCl::ChunkList &rsp = info->GetChunks();
107 for( std::size_t i = 0; i < nReq; ++i )
108 ioVec[i].fOutBytes = rsp[i].length;
109 delete info;
110}
111
113{
114 if (fIOVecLimits)
115 return *fIOVecLimits;
116
117 EnsureOpen();
118 // Start with xrootd default values
119 fIOVecLimits = RIOVecLimits{1024, 2097136, static_cast<std::uint64_t>(-1)};
120
121#if XrdVNUMBER >= 40000
122 std::string strLastURL;
123 pImpl->file.GetProperty("LastURL", strLastURL);
124 XrdCl::URL lastURL(strLastURL);
125 // local redirect will split vector reads into multiple local reads anyway,
126 // so we are fine with the default values
127 if (lastURL.GetProtocol().compare("file") == 0 && lastURL.GetHostId().compare("localhost") == 0) {
128 if (gDebug >= 1)
129 Info("GetReadVLimits", "Local redirect, using default values");
130 return *fIOVecLimits;
131 }
132
133 std::string strDataServer;
134 if (!pImpl->file.GetProperty("DataServer", strDataServer)) {
135 if (gDebug >= 1)
136 Info("GetReadVLimits", "Cannot get DataServer property, using default values");
137 return *fIOVecLimits;
138 }
139 XrdCl::URL dataServer(strDataServer);
140#else
141 XrdCl::URL dataServer(pImpl->file.GetDataServer());
142#endif
143
144 XrdCl::FileSystem fs(dataServer);
145 XrdCl::Buffer arg;
146 XrdCl::Buffer *response = nullptr;
147 arg.FromString("readv_ior_max readv_iov_max");
148
149 XrdCl::XRootDStatus status = fs.Query(XrdCl::QueryCode::Config, arg, response);
150 if (!status.IsOK()) {
151 delete response;
152 if (gDebug >= 1)
153 Info("GetReadVLimits", "Cannot query readv limits, using default values");
154 return *fIOVecLimits;
155 }
156 std::istringstream strmResponse;
157 strmResponse.str(response->ToString());
158 delete response;
159
160 std::string readvIorMax;
161 std::string readvIovMax;
162 if (!std::getline(strmResponse, readvIorMax) || !std::getline(strmResponse, readvIovMax)) {
163 if (gDebug >= 1)
164 Info("GetReadVLimits", "unexpected response from querying readv limits, using default values");
165 return *fIOVecLimits;
166 }
167
168 if (!readvIovMax.empty() && std::isdigit(readvIovMax[0])) {
169 std::size_t val = std::stoi(readvIovMax);
170 // Workaround a dCache bug reported here: https://sft.its.cern.ch/jira/browse/ROOT-6639
171 if (val == 0x7FFFFFFF)
172 return *fIOVecLimits;
173
174 fIOVecLimits->fMaxSingleSize = val;
175 }
176
177 if (!readvIorMax.empty() && std::isdigit(readvIorMax[0])) {
178 fIOVecLimits->fMaxReqs = std::stoi(readvIorMax);
179 }
180
181 return *fIOVecLimits;
182}
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:218
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
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 length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Int_t gDebug
Definition TROOT.cxx:597
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
RIOVecLimits GetReadVLimits() final
Returns the limits regarding the ioVec input to ReadV for this specific file; may open the file as a ...
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...
RRawFileNetXNG(std::string_view url, RRawFile::ROptions options)
std::unique_ptr< RRawFile > Clone() const final
Create a new RawFile that accesses the same resource. The file pointer is reset to zero.
size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
Derived classes should implement low-level reading without buffering.
std::uint64_t GetSizeImpl() final
Derived classes should return the file size or kUnknownFileSize.
The RRawFile provides read-only access to local and remote files.
Definition RRawFile.hxx:43
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
RRawFileNetXNGImpl & operator=(const RRawFileNetXNGImpl &)=delete
RRawFileNetXNGImpl(const RRawFileNetXNGImpl &)=delete
Implementations may enforce limits on the use of vector reads.
Definition RRawFile.hxx:85
Used for vector reads from multiple offsets into multiple buffers.
Definition RRawFile.hxx:71
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