Logo ROOT   6.21/01
Reference Guide
ROOT::Experimental::RFile Class Reference

A ROOT file.

A ROOT file is an object store: it can serialize any object for which ROOT I/O is available (generally: an object which has a dictionary), and it stores the object's data under a key name.

Definition at line 43 of file RFile.hxx.

Classes

struct  Options_t
 Options for RFile construction. More...
 

Public Member Functions

 ~RFile ()
 Must not call Write() of all attached objects: some might not be needed to be written or writing might be aborted due to an exception; require explicit Write(). More...
 
void Close ()
 Flush() and make the file non-writable: close it. More...
 
void Flush ()
 Save all objects associated with this directory (including file header) to the storage medium. More...
 
template<class T >
std::unique_ptr< T > Read (std::string_view name)
 Read the object for a key. More...
 
template<class T >
void Write (std::string_view name, const T &obj)
 Write an object that is not lifetime managed by this RFileImplBase. More...
 
template<class T >
void Write (std::string_view name, const T *obj)
 Write an object that is not lifetime managed by this RFileImplBase. More...
 
void Write (std::string_view name)
 Write an object that is already lifetime managed by this RFileImplBase. More...
 
template<class T >
void Write (std::string_view name, std::shared_ptr< T > &&obj)
 Hand over lifetime management of an object to this RFileImplBase, and write it. More...
 
- Public Member Functions inherited from ROOT::Experimental::RDirectory
template<class T >
void Add (std::string_view name, const std::shared_ptr< T > &ptr)
 Add an existing object (rather a shared_ptr to it) to the RDirectory. More...
 
template<class T , class... ARGS>
std::shared_ptr< ToContentType_t< T > > Create (std::string_view name, ARGS &&... args)
 Create an object of type T (passing some arguments to its constructor). More...
 
Internal::RDirectoryEntry Find (std::string_view name) const
 Find the RDirectoryEntry associated to the name. More...
 
template<class T >
std::pair< Internal::RDirectoryEntry, EFindStatusFind (std::string_view name) const
 Find the RDirectoryEntry associated with the name. More...
 
template<class T >
std::shared_ptr< ToContentType_t< T > > Get (std::string_view name)
 Get the object for a key. More...
 
bool Remove (std::string_view name)
 Remove entry from RDirectory (if exists) More...
 

Static Public Member Functions

static std::string GetCacheDir ()
 Get the directory used for cached reads. More...
 
static std::string SetCacheDir (std::string_view path)
 Set the new directory used for cached reads, returns the old directory. More...
 
Generator functions
static RFilePtr Open (std::string_view name, const Options_t &opts=Options_t())
 Open a file with name for reading. More...
 
static RFilePtr OpenForUpdate (std::string_view name, const Options_t &opts=Options_t())
 Open an existing file with name for reading and writing. More...
 
static RFilePtr Create (std::string_view name, const Options_t &opts=Options_t())
 Open a file with name for reading and writing. More...
 
static RFilePtr Recreate (std::string_view name, const Options_t &opts=Options_t())
 Open a file with name for reading and writing. More...
 
- Static Public Member Functions inherited from ROOT::Experimental::RDirectory
static RDirectoryHeap ()
 Dedicated, process-wide RDirectory. More...
 

Private Member Functions

 RFile (std::unique_ptr< Internal::RFileStorageInterface > &&storage)
 
void WriteMemoryWithType (std::string_view name, const void *address, TClass *cl)
 Serialize the object at address, using the object's TClass. More...
 

Private Attributes

std::unique_ptr< Internal::RFileStorageInterface > fStorage
 Storage backend. More...
 

Additional Inherited Members

- Public Types inherited from ROOT::Experimental::RDirectory
enum  EFindStatus { EFindStatus::kValidValue, EFindStatus::kValidValueBase, EFindStatus::kKeyNameNotFound, EFindStatus::kTypeMismatch }
 
Status of the call to Find<T>(name). More...
 

#include <ROOT/RFile.hxx>

Inheritance diagram for ROOT::Experimental::RFile:
[legend]

Constructor & Destructor Documentation

◆ RFile()

ROOT::Experimental::RFile::RFile ( std::unique_ptr< Internal::RFileStorageInterface > &&  storage)
private

Definition at line 206 of file RFile.cxx.

◆ ~RFile()

ROOT::Experimental::RFile::~RFile ( )
default

Must not call Write() of all attached objects: some might not be needed to be written or writing might be aborted due to an exception; require explicit Write().

Member Function Documentation

◆ Close()

void ROOT::Experimental::RFile::Close ( )

Flush() and make the file non-writable: close it.

Definition at line 218 of file RFile.cxx.

◆ Create()

ROOT::Experimental::RFilePtr ROOT::Experimental::RFile::Create ( std::string_view  name,
const Options_t opts = Options_t() 
)
static

Open a file with name for reading and writing.

Fail (return an invalid RFilePtr) if a file with this name already exists.

Note
: Synchronizes multi-threaded accesses through locks.

Definition at line 162 of file RFile.cxx.

◆ Flush()

void ROOT::Experimental::RFile::Flush ( )

Save all objects associated with this directory (including file header) to the storage medium.

Definition at line 214 of file RFile.cxx.

◆ GetCacheDir()

std::string ROOT::Experimental::RFile::GetCacheDir ( )
static

Get the directory used for cached reads.

Definition at line 198 of file RFile.cxx.

◆ Open()

ROOT::Experimental::RFilePtr ROOT::Experimental::RFile::Open ( std::string_view  name,
const Options_t opts = Options_t() 
)
static

Open a file with name for reading.

Note
: Synchronizes multi-threaded accesses through locks.

Definition at line 153 of file RFile.cxx.

◆ OpenForUpdate()

ROOT::Experimental::RFilePtr ROOT::Experimental::RFile::OpenForUpdate ( std::string_view  name,
const Options_t opts = Options_t() 
)
static

Open an existing file with name for reading and writing.

If a file with that name does not exist, an invalid RFilePtr will be returned.

Note
: Synchronizes multi-threaded accesses through locks.

Definition at line 180 of file RFile.cxx.

◆ Read()

template<class T >
std::unique_ptr<T> ROOT::Experimental::RFile::Read ( std::string_view  name)
inline

Read the object for a key.

T must be the object's type. This will re-read the object for each call, returning a new copy; whether the RDirectory is managing an object attached to this key or not.

Returns
a unique_ptr to the object.
Exceptions
RDirectoryUnknownKeyif no object is stored under this name.
RDirectoryTypeMismatchif the object stored under this name is of a type different from T.

Definition at line 132 of file RFile.hxx.

◆ Recreate()

ROOT::Experimental::RFilePtr ROOT::Experimental::RFile::Recreate ( std::string_view  name,
const Options_t opts = Options_t() 
)
static

Open a file with name for reading and writing.

If a file with this name already exists, delete it and create a new one. Else simply create a new file.

Note
: Synchronizes multi-threaded accesses through locks.

Definition at line 171 of file RFile.cxx.

◆ SetCacheDir()

std::string ROOT::Experimental::RFile::SetCacheDir ( std::string_view  path)
static

Set the new directory used for cached reads, returns the old directory.

Note
: Synchronizes multi-threaded accesses through locks.

Definition at line 189 of file RFile.cxx.

◆ Write() [1/4]

template<class T >
void ROOT::Experimental::RFile::Write ( std::string_view  name,
const T &  obj 
)
inline

Write an object that is not lifetime managed by this RFileImplBase.

Definition at line 144 of file RFile.hxx.

◆ Write() [2/4]

template<class T >
void ROOT::Experimental::RFile::Write ( std::string_view  name,
const T *  obj 
)
inline

Write an object that is not lifetime managed by this RFileImplBase.

Definition at line 151 of file RFile.hxx.

◆ Write() [3/4]

void ROOT::Experimental::RFile::Write ( std::string_view  name)
inline

Write an object that is already lifetime managed by this RFileImplBase.

Definition at line 157 of file RFile.hxx.

◆ Write() [4/4]

template<class T >
void ROOT::Experimental::RFile::Write ( std::string_view  name,
std::shared_ptr< T > &&  obj 
)
inline

Hand over lifetime management of an object to this RFileImplBase, and write it.

Definition at line 166 of file RFile.hxx.

◆ WriteMemoryWithType()

void ROOT::Experimental::RFile::WriteMemoryWithType ( std::string_view  name,
const void address,
TClass cl 
)
private

Serialize the object at address, using the object's TClass.

Definition at line 222 of file RFile.cxx.

Member Data Documentation

◆ fStorage

std::unique_ptr<Internal::RFileStorageInterface> ROOT::Experimental::RFile::fStorage
private

Storage backend.

Definition at line 45 of file RFile.hxx.


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