34constexpr int kDefaultBlockSize = 4096;
47 return std::make_unique<RRawFileUnix>(fUrl, fOptions);
54 int res = fstat64(fFileDes, &info);
57 int res = fstat(fFileDes, &info);
60 throw std::runtime_error(
"Cannot call fstat on '" + fUrl +
"', error: " + std::string(strerror(errno)));
67 fFileDes = open64(GetLocation(fUrl).c_str(), O_RDONLY);
69 fFileDes = open(GetLocation(fUrl).c_str(), O_RDONLY);
72 throw std::runtime_error(
"Cannot open '" + fUrl +
"', error: " + std::string(strerror(errno)));
75 if (fOptions.fBlockSize != ROptions::kUseDefaultBlockSize)
80 int res = fstat64(fFileDes, &info);
83 int res = fstat(fFileDes, &info);
86 throw std::runtime_error(
"Cannot call fstat on '" + fUrl +
"', error: " + std::string(strerror(errno)));
88 if (info.st_blksize > 0) {
89 fOptions.fBlockSize = info.st_blksize;
91 fOptions.fBlockSize = kDefaultBlockSize;
98 posix_fadvise(fFileDes, 0, 0,
value ? POSIX_FADV_RANDOM : POSIX_FADV_SEQUENTIAL);
109 static const bool sIoUringAvailable = [] {
113 Warning(
"RIoUring",
"io_uring is not available because:\n%s", errMsg.c_str());
114 Warning(
"RRawFileUnix",
"io_uring setup failed, falling back to blocking I/O in ReadV");
117 thread_local bool uring_failed =
false;
118 if (!uring_failed && sIoUringAvailable) {
121 std::vector<RIoUring::RReadEvent> reads;
123 for (std::size_t i = 0; i < nReq; ++i) {
132 for (std::size_t i = 0; i < nReq; ++i) {
133 ioVec[i].
fOutBytes = reads.at(i).fOutBytes;
137 catch(
const std::runtime_error &
e) {
138 Warning(
"RIoUring",
"io_uring is not available because:\n%s",
e.what());
140 "io_uring setup failed, falling back to blocking I/O in ReadV");
150 size_t total_bytes = 0;
153 ssize_t res = pread64(fFileDes, buffer, nbytes,
offset);
155 ssize_t res = pread(fFileDes, buffer, nbytes,
offset);
160 throw std::runtime_error(
"Cannot read from '" + fUrl +
"', error: " + std::string(strerror(errno)));
161 }
else if (res == 0) {
164 R__ASSERT(
static_cast<size_t>(res) <= nbytes);
165 buffer =
reinterpret_cast<unsigned char *
>(buffer) + res;
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
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 value
static bool IsAvailable(std::string *errMsg=nullptr)
Probes whether io_uring is actually usable at runtime.
void SubmitReadsAndWait(RReadEvent *readEvents, unsigned int nReads)
Submit a number of read events and wait for completion.
std::unique_ptr< RRawFile > Clone() const final
Create a new RawFile that accesses the same resource. The file pointer is reset to zero.
RRawFileUnix(std::string_view url, RRawFile::ROptions options)
std::uint64_t GetSizeImpl() final
Derived classes should return the file size.
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...
void SetDiscourageReadAheadImpl(bool value) final
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
Derived classes should implement low-level reading without buffering.
The RRawFile provides read-only access to local and remote files.
virtual void ReadVImpl(RIOVec *ioVec, unsigned int nReq)
By default implemented as a loop of ReadAt calls but can be overwritten, e.g. XRootD or DAVIX impleme...
Basic read event composed of IO data and a target file descriptor.
int fFileDes
The file descriptor.
std::uint64_t fOffset
The file offset.
void * fBuffer
The destination for reading.
std::size_t fSize
The number of desired bytes.
Used for vector reads from multiple offsets into multiple buffers.
std::size_t fOutBytes
The number of actually read bytes, set by ReadV()
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.