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 == ROptions::kUseDefaultBlockSize)
81 fOptions.fBlockSize = kDefaultBlockSize;
82}
83
84size_t ROOT::Internal::RRawFileNetXNG::ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset)
85{
86 std::uint32_t btsread = 0;
87 auto st = pImpl->file.Read( offset, nbytes, buffer, btsread );
88 if( !st.IsOK() )
89 throw std::runtime_error( "Cannot read from '" + fUrl + "', " +
90 st.ToString() + "; " + st.GetErrorMessage() );
91 return btsread;
92}
93
95{
96 XrdCl::ChunkList chunks;
97 chunks.reserve( nReq );
98 for( std::size_t i = 0; i < nReq; ++i )
99 chunks.emplace_back( ioVec[i].fOffset, ioVec[i].fSize, ioVec[i].fBuffer );
100
101 XrdCl::VectorReadInfo *info = nullptr;
102 auto st = pImpl->file.VectorRead( chunks, nullptr, info );
103 if( !st.IsOK() )
104 throw std::runtime_error( "Cannot do vector read from '" + fUrl + "', " +
105 st.ToString() + "; " + st.GetErrorMessage() );
106
107 XrdCl::ChunkList &rsp = info->GetChunks();
108 for( std::size_t i = 0; i < nReq; ++i )
109 ioVec[i].fOutBytes = rsp[i].length;
110 delete info;
111}
112
114{
115 if (fIOVecLimits)
116 return *fIOVecLimits;
117
118 EnsureOpen();
119 // Start with xrootd default values
120 fIOVecLimits = RIOVecLimits{1024, 2097136, static_cast<std::uint64_t>(-1)};
121
122#if XrdVNUMBER >= 40000
123 std::string strLastURL;
124 pImpl->file.GetProperty("LastURL", strLastURL);
125 XrdCl::URL lastURL(strLastURL);
126 // local redirect will split vector reads into multiple local reads anyway,
127 // so we are fine with the default values
128 if (lastURL.GetProtocol().compare("file") == 0 && lastURL.GetHostId().compare("localhost") == 0) {
129 if (gDebug >= 1)
130 Info("GetReadVLimits", "Local redirect, using default values");
131 return *fIOVecLimits;
132 }
133
134 std::string strDataServer;
135 if (!pImpl->file.GetProperty("DataServer", strDataServer)) {
136 if (gDebug >= 1)
137 Info("GetReadVLimits", "Cannot get DataServer property, using default values");
138 return *fIOVecLimits;
139 }
140 XrdCl::URL dataServer(strDataServer);
141#else
142 XrdCl::URL dataServer(pImpl->file.GetDataServer());
143#endif
144
145 XrdCl::FileSystem fs(dataServer);
146 XrdCl::Buffer arg;
147 XrdCl::Buffer *response = nullptr;
148 arg.FromString("readv_ior_max readv_iov_max");
149
150 XrdCl::XRootDStatus status = fs.Query(XrdCl::QueryCode::Config, arg, response);
151 if (!status.IsOK()) {
152 delete response;
153 if (gDebug >= 1)
154 Info("GetReadVLimits", "Cannot query readv limits, using default values");
155 return *fIOVecLimits;
156 }
157 std::istringstream strmResponse;
158 strmResponse.str(response->ToString());
159 delete response;
160
161 std::string readvMaxSingleSize;
162 std::string readvMaxReqs;
163 if (!std::getline(strmResponse, readvMaxSingleSize) || !std::getline(strmResponse, readvMaxReqs)) {
164 if (gDebug >= 1)
165 Info("GetReadVLimits", "unexpected response from querying readv limits, using default values");
166 return *fIOVecLimits;
167 }
168
169 if (!readvMaxReqs.empty() && std::isdigit(readvMaxReqs[0])) {
170 std::size_t val = std::stoi(readvMaxReqs);
171 // Workaround a dCache bug reported here: https://sft.its.cern.ch/jira/browse/ROOT-6639
172 if (val == 0x7FFFFFFF)
173 return *fIOVecLimits;
174
175 fIOVecLimits->fMaxReqs = val;
176 }
177
178 if (!readvMaxSingleSize.empty() && std::isdigit(readvMaxSingleSize[0])) {
179 fIOVecLimits->fMaxSingleSize = std::stoi(readvMaxSingleSize);
180 }
181
182 return *fIOVecLimits;
183}
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.
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:75
Used for vector reads from multiple offsets into multiple buffers.
Definition RRawFile.hxx:61
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