22 #include "RStringView.h"
27 namespace Experimental {
32 class TFileStorageInterface;
33 class TFileSharedPtrCtor;
46 std::unique_ptr<Internal::TFileStorageInterface>
fStorage;
48 TFile(std::unique_ptr<Internal::TFileStorageInterface>&& storage);
55 friend Internal::TFileSharedPtrCtor;
114 static std::string
SetCacheDir(std::string_view path);
140 std::unique_ptr<T>
Read(std::string_view name) {
145 return std::make_unique<T>(*Get<T>(
name));
151 void Write(std::string_view name,
const T &obj) {
157 void Write(std::string_view name,
const T *obj) {
163 auto dep =
Find(name.to_string());
170 void Write(std::string_view name, std::shared_ptr <T> &&obj) {
205 operator bool()
const {
return fFile.get(); }
int fAsyncTimeout
Timeout for asynchronous opening.
Options_t()
Default constructor needed for member inits.
void Write(std::string_view name, std::shared_ptr< T > &&obj)
Hand over lifetime management of an object to this TFileImplBase, and write it.
std::unique_ptr< Internal::TFileStorageInterface > fStorage
Storage backend.
~TFile()
Must not call Write() of all attached objects: some might not be needed to be written or writing migh...
Options for TFile construction.
std::unique_ptr< T > Read(std::string_view name)
Read the object for a key.
static TFilePtr OpenForUpdate(std::string_view name, const Options_t &opts=Options_t())
Open an existing file with name for reading and writing.
TFile * operator->()
Dereference the file pointer, giving access to the TFileImplBase object.
void Write(std::string_view name, const T *obj)
Write an object that is not lifetime managed by this TFileImplBase.
static TFilePtr Create(std::string_view name, const Options_t &opts=Options_t())
Open a file with name for reading and writing.
static std::string GetCacheDir()
Get the directory used for cached reads.
void Flush()
Save all objects associated with this directory (including file header) to the storage medium...
std::string fCacheDir
Where to cache the file. If empty, defaults to TFilePtr::GetCacheDir().
bool fCachedRead
Whether the file should be cached before reading.
Internal::TDirectoryEntry Find(const std::string &name) const
Find the TDirectoryEntry associated to the name.
static TFilePtr Open(std::string_view name, const Options_t &opts=Options_t())
Open a file with name for reading.
void Add(const std::string &name, const std::shared_ptr< T > &ptr)
Add an existing object (rather a shared_ptr to it) to the TDirectory.
The ROOT global object gROOT contains a list of all defined classes.
static TFilePtr Recreate(std::string_view name, const Options_t &opts=Options_t())
Open a file with name for reading and writing.
std::shared_ptr< TFile > fFile
void WriteMemoryWithType(std::string_view name, const void *address, TClass *cl)
Serialize the object at address, using the object's TClass.
Points to an object that stores or reads objects in ROOT's binary format.
void Write(std::string_view name, const T &obj)
Write an object that is not lifetime managed by this TFileImplBase.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Key/value store of objects.
static std::string SetCacheDir(std::string_view path)
Set the new directory used for cached reads, returns the old directory.
void Close()
Flush() and make the file non-writable: close it.
TFile(std::unique_ptr< Internal::TFileStorageInterface > &&storage)
TFilePtr(std::shared_ptr< TFile > &&)
Constructed by Open etc.
bool fAsynchronousOpen
Whether the file should be opened asynchronously, if available.
void Write(std::string_view name)
Write an object that is already lifetime managed by this TFileImplBase.