Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::Internal::RRawFile Class Referenceabstract

The RRawFile provides read-only access to local and remote files.

Data can be read either byte-wise or line-wise. The RRawFile base class provides line-wise access and buffering for byte-wise access. Derived classes provide the low-level read operations, e.g. from a local file system or from a web server. The RRawFile is used for non-ROOT RDataSource implementations and for RNTuple.

Files are addressed by URL consisting of a transport protocol part and a location, like file:///path/to/data If the transport protocol part and the :// separator are missing, the default protocol is local file. Files are opened when required (on reading, getting file size) and closed on object destruction.

RRawFiles manage system resources and are therefore made non-copyable. They can be explicitly cloned though.

RRawFile objects are conditionally thread safe. See the user manual for further details: https://root.cern/manual/thread_safety/

Definition at line 43 of file RRawFile.hxx.

Classes

struct  RBlockBuffer
 
struct  RIOVec
 Used for vector reads from multiple offsets into multiple buffers. More...
 
struct  RIOVecLimits
 Implementations may enforce limits on the use of vector reads. More...
 
struct  ROptions
 On construction, an ROptions parameter can customize the RRawFile behavior. More...
 

Public Types

enum class  ELineBreaks { kAuto , kSystem , kUnix , kWindows }
 kAuto detects the line break from the first line, kSystem picks the system's default More...
 

Public Member Functions

 RRawFile (const RRawFile &)=delete
 
 RRawFile (std::string_view url, ROptions options)
 
virtual ~RRawFile ()=default
 
virtual std::unique_ptr< RRawFileClone () const =0
 Create a new RawFile that accesses the same resource. The file pointer is reset to zero.
 
std::uint64_t GetFilePos () const
 Returns the offset for the next Read/Readln call.
 
virtual RIOVecLimits GetReadVLimits ()
 Returns the limits regarding the ioVec input to ReadV for this specific file; may open the file as a side-effect.
 
std::uint64_t GetSize ()
 Returns the size of the file.
 
std::string GetUrl () const
 Returns the url of the file.
 
bool IsBuffering () const
 
bool IsOpen () const
 Once opened, the file stay open until destruction of the RRawFile object.
 
RRawFileoperator= (const RRawFile &)=delete
 
size_t Read (void *buffer, size_t nbytes)
 Read from fFilePos offset. Returns the actual number of bytes read.
 
size_t ReadAt (void *buffer, size_t nbytes, std::uint64_t offset)
 Buffered read from a random position.
 
bool Readln (std::string &line)
 Read the next line starting from the current value of fFilePos. Returns false if the end of the file is reached.
 
void ReadV (RIOVec *ioVec, unsigned int nReq)
 Opens the file if necessary and calls ReadVImpl.
 
void Seek (std::uint64_t offset)
 Change the cursor fFilePos.
 
void SetBuffering (bool value)
 Turn off buffered reads; all scalar read requests go directly to the implementation.
 

Static Public Member Functions

static std::unique_ptr< RRawFileCreate (std::string_view url, ROptions options=ROptions())
 Factory method that returns a suitable concrete implementation according to the transport in the url.
 
static std::string GetLocation (std::string_view url)
 Returns only the file location, e.g. "server/file" for http://server/file.
 
static std::string GetTransport (std::string_view url)
 Returns only the transport protocol in lower case, e.g. "http" for HTTP://server/file.
 

Protected Member Functions

void EnsureOpen ()
 Open the file if not already open. Otherwise noop.
 
virtual std::uint64_t GetSizeImpl ()=0
 Derived classes should return the file size.
 
virtual void OpenImpl ()=0
 OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
 
virtual size_t ReadAtImpl (void *buffer, size_t nbytes, std::uint64_t offset)=0
 Derived classes should implement low-level reading without buffering.
 
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 implementations.
 

Protected Attributes

std::uint64_t fFilePos = 0
 The current position in the file, which can be changed by Seek, Read, and Readln.
 
ROptions fOptions
 
std::string fUrl
 

Private Attributes

unsigned int fBlockBufferIdx = 0
 To be used modulo kNumBlockBuffers, points to the last used block buffer in fBlockBuffers.
 
RBlockBuffer fBlockBuffers [kNumBlockBuffers]
 An active buffer and a shadow buffer, which supports "jumping back" to a previously used location in the file.
 
std::unique_ptr< unsigned char[]> fBufferSpace
 Memory block containing the block buffers consecutively.
 
std::uint64_t fFileSize = kUnknownFileSize
 The cached file size.
 
bool fIsBuffering = true
 Runtime switch to decide if reads are buffered or directly sent to ReadAtImpl()
 
bool fIsOpen = false
 Files are opened lazily and only when required; the open state is kept by this flag.
 

Static Private Attributes

static constexpr unsigned int kNumBlockBuffers = 2
 Don't change without adapting ReadAt()
 
static constexpr std::uint64_t kUnknownFileSize = std::uint64_t(-1)
 Used as a marker that the file size was not yet queried.
 

#include <ROOT/RRawFile.hxx>

Inheritance diagram for ROOT::Internal::RRawFile:
[legend]

Member Enumeration Documentation

◆ ELineBreaks

kAuto detects the line break from the first line, kSystem picks the system's default

Enumerator
kAuto 
kSystem 
kUnix 
kWindows 

Definition at line 46 of file RRawFile.hxx.

Constructor & Destructor Documentation

◆ RRawFile() [1/2]

ROOT::Internal::RRawFile::RRawFile ( std::string_view  url,
ROptions  options 
)

Definition at line 61 of file RRawFile.cxx.

◆ RRawFile() [2/2]

ROOT::Internal::RRawFile::RRawFile ( const RRawFile )
delete

◆ ~RRawFile()

virtual ROOT::Internal::RRawFile::~RRawFile ( )
virtualdefault

Member Function Documentation

◆ Clone()

virtual std::unique_ptr< RRawFile > ROOT::Internal::RRawFile::Clone ( ) const
pure virtual

Create a new RawFile that accesses the same resource. The file pointer is reset to zero.

Implemented in ROOT::Internal::RRawFileTFile, ROOT::Internal::RRawFileUnix, ROOT::Internal::RRawFileWin, ROOT::Internal::RRawFileDavix, and ROOT::Internal::RRawFileNetXNG.

◆ Create()

std::unique_ptr< ROOT::Internal::RRawFile > ROOT::Internal::RRawFile::Create ( std::string_view  url,
ROptions  options = ROptions() 
)
static

Factory method that returns a suitable concrete implementation according to the transport in the url.

Definition at line 64 of file RRawFile.cxx.

◆ EnsureOpen()

void ROOT::Internal::RRawFile::EnsureOpen ( )
protected

Open the file if not already open. Otherwise noop.

Definition at line 90 of file RRawFile.cxx.

◆ GetFilePos()

std::uint64_t ROOT::Internal::RRawFile::GetFilePos ( ) const
inline

Returns the offset for the next Read/Readln call.

Definition at line 170 of file RRawFile.hxx.

◆ GetLocation()

std::string ROOT::Internal::RRawFile::GetLocation ( std::string_view  url)
static

Returns only the file location, e.g. "server/file" for http://server/file.

Definition at line 106 of file RRawFile.cxx.

◆ GetReadVLimits()

virtual RIOVecLimits ROOT::Internal::RRawFile::GetReadVLimits ( )
inlinevirtual

Returns the limits regarding the ioVec input to ReadV for this specific file; may open the file as a side-effect.

Reimplemented in ROOT::Internal::RRawFileNetXNG.

Definition at line 179 of file RRawFile.hxx.

◆ GetSize()

std::uint64_t ROOT::Internal::RRawFile::GetSize ( )

Returns the size of the file.

Definition at line 114 of file RRawFile.cxx.

◆ GetSizeImpl()

virtual std::uint64_t ROOT::Internal::RRawFile::GetSizeImpl ( )
protectedpure virtual

◆ GetTransport()

std::string ROOT::Internal::RRawFile::GetTransport ( std::string_view  url)
static

Returns only the transport protocol in lower case, e.g. "http" for HTTP://server/file.

Definition at line 128 of file RRawFile.cxx.

◆ GetUrl()

std::string ROOT::Internal::RRawFile::GetUrl ( ) const

Returns the url of the file.

Definition at line 124 of file RRawFile.cxx.

◆ IsBuffering()

bool ROOT::Internal::RRawFile::IsBuffering ( ) const
inline

Definition at line 184 of file RRawFile.hxx.

◆ IsOpen()

bool ROOT::Internal::RRawFile::IsOpen ( ) const
inline

Once opened, the file stay open until destruction of the RRawFile object.

Definition at line 190 of file RRawFile.hxx.

◆ OpenImpl()

virtual void ROOT::Internal::RRawFile::OpenImpl ( )
protectedpure virtual

OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.

If fOptions.fBlocksize is negative, derived classes are responsible to set a sensible value. After a call to OpenImpl(), fOptions.fBlocksize must be larger or equal to zero.

Implemented in ROOT::Internal::RRawFileTFile, ROOT::Internal::RRawFileUnix, ROOT::Internal::RRawFileWin, ROOT::Internal::RRawFileDavix, and ROOT::Internal::RRawFileNetXNG.

◆ operator=()

RRawFile & ROOT::Internal::RRawFile::operator= ( const RRawFile )
delete

◆ Read()

size_t ROOT::Internal::RRawFile::Read ( void *  buffer,
size_t  nbytes 
)

Read from fFilePos offset. Returns the actual number of bytes read.

Definition at line 138 of file RRawFile.cxx.

◆ ReadAt()

size_t ROOT::Internal::RRawFile::ReadAt ( void *  buffer,
size_t  nbytes,
std::uint64_t  offset 
)

Buffered read from a random position.

Returns the actual number of bytes read. Short reads indicate the end of the file

Definition at line 145 of file RRawFile.cxx.

◆ ReadAtImpl()

virtual size_t ROOT::Internal::RRawFile::ReadAtImpl ( void *  buffer,
size_t  nbytes,
std::uint64_t  offset 
)
protectedpure virtual

Derived classes should implement low-level reading without buffering.

Short reads indicate the end of the file, therefore derived classes should return nbytes bytes if available.

Implemented in ROOT::Internal::RRawFileTFile, ROOT::Internal::RRawFileUnix, ROOT::Internal::RRawFileWin, ROOT::Internal::RRawFileDavix, and ROOT::Internal::RRawFileNetXNG.

◆ Readln()

bool ROOT::Internal::RRawFile::Readln ( std::string &  line)

Read the next line starting from the current value of fFilePos. Returns false if the end of the file is reached.

Definition at line 207 of file RRawFile.cxx.

◆ ReadV()

void ROOT::Internal::RRawFile::ReadV ( RIOVec ioVec,
unsigned int  nReq 
)

Opens the file if necessary and calls ReadVImpl.

Definition at line 194 of file RRawFile.cxx.

◆ ReadVImpl()

void ROOT::Internal::RRawFile::ReadVImpl ( RIOVec ioVec,
unsigned int  nReq 
)
protectedvirtual

By default implemented as a loop of ReadAt calls but can be overwritten, e.g. XRootD or DAVIX implementations.

Reimplemented in ROOT::Internal::RRawFileUnix, ROOT::Internal::RRawFileDavix, and ROOT::Internal::RRawFileNetXNG.

Definition at line 99 of file RRawFile.cxx.

◆ Seek()

void ROOT::Internal::RRawFile::Seek ( std::uint64_t  offset)

Change the cursor fFilePos.

Definition at line 240 of file RRawFile.cxx.

◆ SetBuffering()

void ROOT::Internal::RRawFile::SetBuffering ( bool  value)

Turn off buffered reads; all scalar read requests go directly to the implementation.

Buffering can be turned back on.

Definition at line 200 of file RRawFile.cxx.

Member Data Documentation

◆ fBlockBufferIdx

unsigned int ROOT::Internal::RRawFile::fBlockBufferIdx = 0
private

To be used modulo kNumBlockBuffers, points to the last used block buffer in fBlockBuffers.

Definition at line 110 of file RRawFile.hxx.

◆ fBlockBuffers

RBlockBuffer ROOT::Internal::RRawFile::fBlockBuffers[kNumBlockBuffers]
private

An active buffer and a shadow buffer, which supports "jumping back" to a previously used location in the file.

Definition at line 112 of file RRawFile.hxx.

◆ fBufferSpace

std::unique_ptr<unsigned char[]> ROOT::Internal::RRawFile::fBufferSpace
private

Memory block containing the block buffers consecutively.

Definition at line 114 of file RRawFile.hxx.

◆ fFilePos

std::uint64_t ROOT::Internal::RRawFile::fFilePos = 0
protected

The current position in the file, which can be changed by Seek, Read, and Readln.

Definition at line 128 of file RRawFile.hxx.

◆ fFileSize

std::uint64_t ROOT::Internal::RRawFile::fFileSize = kUnknownFileSize
private

The cached file size.

Definition at line 118 of file RRawFile.hxx.

◆ fIsBuffering

bool ROOT::Internal::RRawFile::fIsBuffering = true
private

Runtime switch to decide if reads are buffered or directly sent to ReadAtImpl()

Definition at line 122 of file RRawFile.hxx.

◆ fIsOpen

bool ROOT::Internal::RRawFile::fIsOpen = false
private

Files are opened lazily and only when required; the open state is kept by this flag.

Definition at line 120 of file RRawFile.hxx.

◆ fOptions

ROptions ROOT::Internal::RRawFile::fOptions
protected

Definition at line 126 of file RRawFile.hxx.

◆ fUrl

std::string ROOT::Internal::RRawFile::fUrl
protected

Definition at line 125 of file RRawFile.hxx.

◆ kNumBlockBuffers

constexpr unsigned int ROOT::Internal::RRawFile::kNumBlockBuffers = 2
staticconstexprprivate

Don't change without adapting ReadAt()

Definition at line 92 of file RRawFile.hxx.

◆ kUnknownFileSize

constexpr std::uint64_t ROOT::Internal::RRawFile::kUnknownFileSize = std::uint64_t(-1)
staticconstexprprivate

Used as a marker that the file size was not yet queried.

Definition at line 116 of file RRawFile.hxx.

Libraries for ROOT::Internal::RRawFile:

The documentation for this class was generated from the following files: