23#include <XrdCl/XrdClFile.hh>
24#include <XrdCl/XrdClFileSystem.hh>
25#include <XrdVersion.hh>
28constexpr int kDefaultBlockSize = 128 * 1024;
59 return std::make_unique<RRawFileNetXNG>(
fUrl,
fOptions );
64 XrdCl::StatInfo *info =
nullptr;
65 auto st =
pImpl->file.Stat(
true, info );
67 throw std::runtime_error(
"Cannot determine size of '" +
fUrl +
"', " +
68 st.ToString() +
"; " + st.GetErrorMessage() );
69 std::uint64_t
ret = info->GetSize();
76 auto st =
pImpl->file.Open(
fUrl, XrdCl::OpenFlags::Read );
78 throw std::runtime_error(
"Cannot open '" +
fUrl +
"', " +
79 st.ToString() +
"; " + st.GetErrorMessage() );
80 if (
fOptions.fBlockSize == ROptions::kUseDefaultBlockSize)
81 fOptions.fBlockSize = kDefaultBlockSize;
86 std::uint32_t btsread = 0;
87 auto st =
pImpl->file.Read( offset, nbytes, buffer, btsread );
89 throw std::runtime_error(
"Cannot read from '" +
fUrl +
"', " +
90 st.ToString() +
"; " + st.GetErrorMessage() );
96 XrdCl::ChunkList chunks;
97 chunks.reserve( nReq );
98 for( std::size_t i = 0; i < nReq; ++i )
101 XrdCl::VectorReadInfo *info =
nullptr;
102 auto st =
pImpl->file.VectorRead( chunks,
nullptr, info );
104 throw std::runtime_error(
"Cannot do vector read from '" +
fUrl +
"', " +
105 st.ToString() +
"; " + st.GetErrorMessage() );
107 XrdCl::ChunkList &rsp = info->GetChunks();
108 for( std::size_t i = 0; i < nReq; ++i )
109 ioVec[i].fOutBytes = rsp[i].length;
122#if XrdVNUMBER >= 40000
123 std::string strLastURL;
124 pImpl->file.GetProperty(
"LastURL", strLastURL);
125 XrdCl::URL lastURL(strLastURL);
128 if (lastURL.GetProtocol().compare(
"file") == 0 && lastURL.GetHostId().compare(
"localhost") == 0) {
130 Info(
"GetReadVLimits",
"Local redirect, using default values");
134 std::string strDataServer;
135 if (!
pImpl->file.GetProperty(
"DataServer", strDataServer)) {
137 Info(
"GetReadVLimits",
"Cannot get DataServer property, using default values");
140 XrdCl::URL dataServer(strDataServer);
142 XrdCl::URL dataServer(
pImpl->file.GetDataServer());
145 XrdCl::FileSystem fs(dataServer);
147 XrdCl::Buffer *response =
nullptr;
148 arg.FromString(
"readv_ior_max readv_iov_max");
150 XrdCl::XRootDStatus status = fs.Query(XrdCl::QueryCode::Config, arg, response);
151 if (!status.IsOK()) {
154 Info(
"GetReadVLimits",
"Cannot query readv limits, using default values");
157 std::istringstream strmResponse;
158 strmResponse.str(response->ToString());
161 std::string readvMaxSingleSize;
162 std::string readvMaxReqs;
163 if (!std::getline(strmResponse, readvMaxSingleSize) || !std::getline(strmResponse, readvMaxReqs)) {
165 Info(
"GetReadVLimits",
"unexpected response from querying readv limits, using default values");
169 if (!readvMaxReqs.empty() && std::isdigit(readvMaxReqs[0])) {
170 std::size_t val = std::stoi(readvMaxReqs);
172 if (val == 0x7FFFFFFF)
178 if (!readvMaxSingleSize.empty() && std::isdigit(readvMaxSingleSize[0])) {
179 fIOVecLimits->fMaxSingleSize = std::stoi(readvMaxSingleSize);
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
std::unique_ptr< RRawFileNetXNGImpl > pImpl
pointer to implementation
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::optional< RIOVecLimits > fIOVecLimits
Set by GetReadVLimits and then cached.
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.
RRawFile(std::string_view url, ROptions options)
void EnsureOpen()
Open the file if not already open. Otherwise noop.
RRawFileNetXNGImpl()=default
RRawFileNetXNGImpl & operator=(const RRawFileNetXNGImpl &)=delete
~RRawFileNetXNGImpl()=default
RRawFileNetXNGImpl(const RRawFileNetXNGImpl &)=delete
Implementations may enforce limits on the use of vector reads.
Used for vector reads from multiple offsets into multiple buffers.
std::size_t fSize
The number of desired bytes.
void * fBuffer
The destination for reading.
std::uint64_t fOffset
The file offset.
On construction, an ROptions parameter can customize the RRawFile behavior.