Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFile.hxx
Go to the documentation of this file.
1/// \file ROOT/RFile.hxx
2/// \author Giacomo Parolini <giacomo.parolini@cern.ch>
3/// \date 2025-03-19
4/// \warning This is part of the ROOT 7 prototype! It will change without notice. Feedback
5/// is welcome!
6
7#ifndef ROOT7_RFile
8#define ROOT7_RFile
9
10#include <Compression.h>
11#include <Rtypes.h>
12#include <ROOT/RError.hxx>
13
14#include <deque>
15#include <functional>
16#include <iostream>
17#include <memory>
18#include <string_view>
19#include <typeinfo>
20#include <type_traits>
21#include <variant>
22
23class TFile;
24class TIterator;
25class TKey;
26class TTree;
27
28namespace ROOT {
29
30class RKeyInfo;
31class RFile;
32
33namespace Internal {
34
36
37/// Returns an **owning** pointer to the object referenced by `key`. The caller must delete this pointer.
38/// This method is meant to only be used by the pythonization.
39[[nodiscard]] void *RFile_GetObjectFromKey(RFile &file, const RKeyInfo &key);
40
42
43} // namespace Internal
44
45namespace Detail {
46
47/// Given a "path-like" string (like foo/bar/baz), returns a pair `{ dirName, baseName }`.
48/// `baseName` will be empty if the string ends with '/'.
49/// `dirName` will be empty if the string contains no '/'.
50/// `dirName`, if not empty, always ends with a '/'.
51/// NOTE: this function does no semantic checking or path expansion, nor does it interact with the
52/// filesystem in any way (so it won't follow symlink or anything like that).
53/// Moreover it doesn't trim the path in any way, so any leading or trailing whitespaces will be preserved.
54/// This function does not perform any copy: the returned string_views have the same lifetime as `path`.
55std::pair<std::string_view, std::string_view> DecomposePath(std::string_view path);
56
57} // namespace Detail
58
59class RFileKeyIterable;
60
61/**
62\class ROOT::RKeyInfo
63\ingroup io_files
64\brief Information about an RFile object's Key.
65
66Every object inside a ROOT file has an associated "Key" which contains metadata on the object, such as its name, type
67etc.
68Querying this information can be done via RFile::ListKeys(). Reading an object's Key
69doesn't deserialize the full object, so it's a relatively lightweight operation.
70*/
71class RKeyInfo final {
72 friend class ROOT::RFile;
74
75public:
76 enum class ECategory : std::uint16_t {
78 kObject,
80 };
81
82private:
83 std::string fPath;
84 std::string fTitle;
85 std::string fClassName;
86 std::uint16_t fCycle = 0;
88 std::uint64_t fLenObj = 0;
89 std::uint64_t fNBytesObj = 0;
90 std::uint64_t fNBytesKey = 0;
91 std::uint64_t fSeekKey = 0;
92 std::uint64_t fSeekParentDir = 0;
93
94 explicit RKeyInfo(const TKey &key);
95
96public:
97 RKeyInfo() = default;
98
99 /// Returns the absolute path of this key, i.e. the directory part plus the object name.
100 const std::string &GetPath() const { return fPath; }
101 /// Returns the base name of this key, i.e. the name of the object without the directory part.
102 std::string GetBaseName() const { return std::string(Detail::DecomposePath(fPath).second); }
103 const std::string &GetTitle() const { return fTitle; }
104 const std::string &GetClassName() const { return fClassName; }
105 std::uint16_t GetCycle() const { return fCycle; }
106 ECategory GetCategory() const { return fCategory; }
107 /// Returns the in-memory size of the uncompressed object.
108
109 std::uint64_t GetLenObj() const { return fLenObj; }
110 /// Returns the on-disk size of the (potentially compressed) object, excluding its key.
111 std::uint64_t GetNBytesObj() const { return fNBytesObj; }
112
113 /// Returns the on-disk size of this object's key.
114 std::uint64_t GetNBytesKey() const { return fNBytesKey; }
115 /// Returns the on-disk offset of this object's key.
116 std::uint64_t GetSeekKey() const { return fSeekKey; }
117
118 /// Returns the on-disk offset of this object's parent directory key.
119 std::uint64_t GetSeekParentDir() const { return fSeekParentDir; }
120};
121
122/// The iterable returned by RFile::ListKeys()
123class RFileKeyIterable final {
124 using Pattern_t = std::string;
125
126 TFile *fFile = nullptr;
128 std::uint32_t fFlags = 0;
129
130public:
131 class RIterator {
132 friend class RFileKeyIterable;
133
135 // This is ugly, but TList returns an (owning) pointer to a polymorphic TIterator...and we need this class
136 // to be copy-constructible.
137 std::shared_ptr<TIterator> fIter;
138 std::string fDirPath;
139
140 // Outlined to avoid including TIterator.h
141 RIterStackElem(TIterator *it, const std::string &path = "");
142 // Outlined to avoid including TIterator.h
144
145 // fDirPath doesn't need to be compared because it's implied by fIter.
146 bool operator==(const RIterStackElem &other) const { return fIter == other.fIter; }
147 };
148
149 // Using a deque to have pointer stability
150 std::deque<RIterStackElem> fIterStack;
152 const TKey *fCurKey = nullptr;
153 std::uint16_t fRootDirNesting = 0;
154 std::uint32_t fFlags = 0;
155
156 void Advance();
157
158 // NOTE: `iter` here is an owning pointer (or null)
159 RIterator(TIterator *iter, Pattern_t pattern, std::uint32_t flags);
160
161 public:
163 using iterator_category = std::input_iterator_tag;
164 using difference_type = std::ptrdiff_t;
166 using pointer = const value_type *;
167 using reference = const value_type &;
168
170 {
171 Advance();
172 return *this;
173 }
174 value_type operator*();
175 bool operator!=(const iterator &rh) const { return !(*this == rh); }
176 bool operator==(const iterator &rh) const { return fIterStack == rh.fIterStack; }
177 };
178
179 RFileKeyIterable(TFile *file, std::string_view rootDir, std::uint32_t flags)
180 : fFile(file), fPattern(std::string(rootDir)), fFlags(flags)
181 {
182 }
183
184 RIterator begin() const;
185 RIterator end() const;
186};
187
188/// The data stored in the ROOT file header
189class RFileHeader final {
190 friend class ROOT::RFile;
191
192 std::int32_t fVersion = 0;
193 std::int64_t fBEGIN = 0;
194 std::int64_t fEND = 0;
195 std::int64_t fSeekFree = 0;
196 std::int32_t fNBytesFree = 0;
197 std::int8_t fUnits = 0;
198 std::int32_t fCompression = 0;
199 std::int64_t fSeekInfo = 0;
200 std::int32_t fNBytesInfo = 0;
201
202public:
203 /// Version of ROOT which wrote this file. When creating a file this is set to gROOT->GetVersionInt().
204 std::int32_t GetVersion() const { return fVersion; }
205 /// First used byte in the file (except header)
206 std::int64_t GetBEGIN() const { return fBEGIN; }
207 /// Last used byte in the file
208 std::int64_t GetEND() const { return fEND; }
209 /// Offset into the file of the Free List section
210 std::int64_t GetSeekFree() const { return fSeekFree; }
211 /// Size on disk of the (potentially compressed) Free List section
212 std::int32_t GetNBytesFree() const { return fNBytesFree; }
213 /// Offset into the file of the File Info section
214 std::int64_t GetSeekInfo() const { return fSeekInfo; }
215 /// Size on disk of the (potentially compressed) File Info section
216 std::int32_t GetNBytesInfo() const { return fNBytesInfo; }
217 /// How many bytes do the Seek fields take up on disk. This is 4 for regular files and 8 for "big" files.
218 std::int8_t GetUnits() const { return fUnits; }
219 /// Compression settings used by the file. See Compression.h for details.
220 std::int32_t GetCompression() const { return fCompression; }
221};
222
223/**
224\class ROOT::RFile
225\ingroup io_files
226\brief An interface to read from, or write to, a ROOT file, as well as performing other common operations.
227
228Please refer to the documentation of TFile for the details related to how data and executable code can be stored
229in ROOT files.
230
231## When and why should you use RFile
232
233RFile is a modern and minimalistic interface to ROOT files, both local and remote, that can be used instead of TFile
234when you only need basic Put/Get operations and don't need the more advanced TFile/TDirectory functionalities.
235It provides:
236- a simple interface that makes it easy to do things right and hard to do things wrong;
237- more robustness and better error reporting for those operations;
238- clearer ownership semantics expressed through the type system.
239
240RFile doesn't cover the entirety of use cases covered by TFile/TDirectory/TDirectoryFile and is not
241a 1:1 replacement for them. It is meant to simplify the most common use cases by following newer standard C++
242practices.
243
244## Ownership model
245
246RFile handles ownership via smart pointers, typically std::unique_ptr.
247
248When getting an object from the file (via RFile::Get) you get back a unique copy of the object. Calling `Get` on the
249same object twice produces two independent clones of the object. The ownership over that object is solely on the caller
250and not shared with the RFile. Therefore, the object will remain valid after closing or destroying the RFile that
251generated it. This also means that any modification done to the object are **not** reflected to the file automatically:
252to update the object in the file you need to write it again (via RFile::Overwrite).
253
254RFile::Put and RFile::Overwrite are the way to write objects to the file. Both methods take a const reference to the
255object to write and don't change the ownership of the object in any way. Calling Put or Overwrite doesn't guarantee that
256the object is immediately written to the underlying storage: to ensure that, you need to call RFile::Flush (or close the
257file).
258
259## Directories
260
261Even though there is no equivalent of TDirectory in the RFile API, directories are still an existing concept in RFile
262(since they are a concept in the ROOT binary format). However they are for now only interacted with indirectly, via the
263use of filesystem-like string-based paths. If you Put an object in an RFile under the path "path/to/object", "object"
264will be stored under directory "to" which is in turn stored under directory "path". This hierarchy is encoded in the
265ROOT file itself and it can provide some optimization and/or conveniences when querying objects.
266
267For the most part, it is convenient to think about RFile in terms of a key-value storage where string-based paths are
268used to refer to arbitrary objects. However, given the hierarchical nature of ROOT files, certain filesystem-like
269properties are applied to paths, for ease of use: the '/' character is treated specially as the directory separator;
270multiple '/' in a row are collapsed into one (since RFile doesn't allow directories with empty names).
271
272At the moment, RFile doesn't allow getting directories via Get, nor writing ones via Put (this may change in the
273future).
274
275## Sample usage
276Opening an RFile (for writing) and writing an object to it:
277~~~{.cpp}
278auto rfile = ROOT::RFile::Recreate("my_file.root");
279auto myObj = TH1D("h", "h", 10, 0, 1);
280rfile->Put(myObj.GetName(), myObj);
281~~~
282
283Opening an RFile (for reading) and reading an object from it:
284~~~{.cpp}
285auto rfile = ROOT::RFile::Open("my_file.root");
286auto myObj = file->Get<TH1D>("h");
287~~~
288*/
289class RFile final {
290 friend void *Internal::RFile_GetObjectFromKey(RFile &file, const RKeyInfo &key);
292
293 /// Flags used in PutInternal()
295 /// When encountering an object at the specified path, overwrite it with the new one instead of erroring out.
297 /// When overwriting an object, preserve the existing one and create a new cycle, rather than removing it.
299 };
300
301 std::unique_ptr<TFile> fFile;
302
303 // Outlined to avoid including TFile.h
304 explicit RFile(std::unique_ptr<TFile> file);
305
306 /// Gets object `path` from the file and returns an **owning** pointer to it.
307 /// The caller should immediately wrap it into a unique_ptr of the type described by `type`.
308 [[nodiscard]] void *GetUntyped(std::string_view path,
309 std::variant<const char *, std::reference_wrapper<const std::type_info>> type) const;
310
311 /// Writes `obj` to file, without taking its ownership.
312 void PutUntyped(std::string_view path, const std::type_info &type, const void *obj, std::uint32_t flags,
313 std::string_view title);
314
315 template <typename T>
316 void PutInternal(std::string_view path, const T &obj, std::uint32_t flags, std::string_view title)
317 {
318 PutUntyped(path, typeid(T), &obj, flags, title);
319 }
320
321 /// Given `path`, returns the TKey corresponding to the object at that path (assuming the path is fully split, i.e.
322 /// "a/b/c" always means "object 'c' inside directory 'b' inside directory 'a'").
323 /// IMPORTANT: `path` must have been validated/normalized via ValidateAndNormalizePath() (see RFile.cxx).
324 TKey *GetTKey(std::string_view path) const;
325
326public:
335
337 /// See core/zip/inc/Compression.h for the meaning of the `compression` argument.
338 /// Default compression is 505 (ZSTD level 10).
340 /// If true the RFile will show up in the TBrowser window. This causes the file to also be added
341 /// to the list of global files. Set to false to prevent this global registration.
343
345 };
346
348 /// If true the RFile will show up in the TBrowser window. This causes the file to also be added
349 /// to the list of global files. Set to false to prevent this global registration.
351
353 };
354
356 /// If true the RFile will show up in the TBrowser window. This causes the file to also be added
357 /// to the list of global files. Set to false to prevent this global registration.
359
361 };
362
363 // This is arbitrary, but it's useful to avoid pathological cases
364 static constexpr int kMaxPathNesting = 1000;
365
366 ///// Factory methods /////
367
368 /// Opens the file for reading. `path` may be a regular file path or a remote URL.
369 /// \throw ROOT::RException if the file at `path` could not be opened.
370 static std::unique_ptr<RFile> Open(std::string_view path, const ROpenOptions &opts = ROpenOptions());
371
372 /// Opens the file for reading/writing, overwriting it if it already exists.
373 /// \throw ROOT::RException if a file could not be created at `path` (e.g. if the specified
374 /// directory tree does not exist).
375 static std::unique_ptr<RFile> Recreate(std::string_view path, const RRecreateOptions &opts = RRecreateOptions());
376
377 /// Opens the file for updating, creating a new one if it doesn't exist.
378 /// \throw ROOT::RException if the file at `path` could neither be read nor created
379 /// (e.g. if the specified directory tree does not exist).
380 static std::unique_ptr<RFile> Update(std::string_view path, const RUpdateOptions &opts = RUpdateOptions());
381
382 ///// Instance methods /////
383
384 // Outlined to avoid including TFile.h
386
387 /// Retrieves an object from the file.
388 /// `path` should be a string such that `IsValidPath(path) == true`, otherwise an exception will be thrown.
389 /// See \ref ValidateAndNormalizePath() for info about valid path names.
390 /// \return A copy of the object at `path`, or `nullptr` if there is no object of type `T` at the specified path.
391 template <typename T>
392 std::unique_ptr<T> Get(std::string_view path) const
393 {
394 void *obj = GetUntyped(path, typeid(T));
395 return std::unique_ptr<T>(static_cast<T *>(obj));
396 }
397
398 /// Puts object `obj` into the file and gives it a title.
399 /// The application retains ownership of the object.
400 /// The object will be effectively copied into the file, so any further modifications won't be seen by the object
401 /// inside the file.
402 /// Note that the object is not necessarily written to storage until the RFile is closed or `Flush()` is called.
403 ///
404 /// `path` should be a string such that `IsValidPath(path) == true`, otherwise an exception will be thrown.
405 /// See \ref ValidateAndNormalizePath() for info about valid path names.
406 ///
407 /// \throws ROOT::RException if `path` already identifies a valid object or directory.
408 /// \throws ROOT::RException if the file was opened in read-only mode.
409 template <typename T>
410 void Put(std::string_view path, const T &obj, std::string_view title = "")
411 {
412 static_assert(!std::is_base_of_v<TTree, T>, "Writing TTree with RFile is unsupported.");
413 PutInternal(path, obj, /* flags = */ 0, title);
414 }
415
416 /// Puts object `namedObj` in the file under the path `dirPath/namedObj.GetName()`, giving it a title equal to
417 /// `namedObj.GetTitle()`.
418 /// If `dirPath` is empty (default), the object is put at the top level of the file.
419 ///
420 /// \throws ROOT::RException if `dirPath/namedObj.GetName()` results in an invalid object path. Notably, this
421 /// includes the case where `namedObj.GetName()` contains a slash character.
422 void Put(const class TNamed &namedObj, std::string_view dirPath = "");
423
424 /// Puts an object into the file, overwriting any previously-existing object at that path.
425 /// See Put for more details.
426 ///
427 /// `overwriteFlags` must contain values from the `EOverwriteFlags` enum.
428 /// If an object already exists at that path AND it has type `T`, it is kept as a backup cycle
429 /// unless `overwriteFlags` contains `kOverwrite_NoNewCycle`.
430 /// If the existing object's type differs from `T`, an exception is thrown.
431 /// Note that even if no new cycle is created, only the *latest* cycle will be deleted.
432 ///
433 /// \throws ROOT::RException if `path` is already the path of a directory.
434 /// \throws ROOT::RException if the file was opened in read-only mode.
435 template <typename T>
436 void Overwrite(std::string_view path, const T &obj, std::uint32_t overwriteFlags = 0)
437 {
438 static_assert(!std::is_base_of_v<TTree, T>, "Writing TTree with RFile is unsupported.");
439 Overwrite(path, obj, "", overwriteFlags);
440 }
441
442 /// Like Overwrite(std::string_view, const T&, bool) but allows giving a title to the object.
443 template <typename T>
444 void Overwrite(std::string_view path, const T &obj, std::string_view title, std::uint32_t overwriteFlags = 0)
445 {
446 std::uint32_t flags = kPutFlag_AllowOverwrite;
447 const bool createNewCycle = !(overwriteFlags & kOverwrite_NoNewCycle);
448 flags |= createNewCycle * kPutFlag_OverwriteKeepCycle;
449 PutInternal(path, obj, flags, title);
450 }
451
452 /// Writes all objects and the file structure to disk.
453 /// \return the number of bytes written.
454 size_t Flush();
455
456 /// Flushes the RFile if needed and closes it, disallowing any further reading or writing.
457 void Close();
458
459 /// Returns whether the file is still open or not.
460 bool IsOpen() const { return !!fFile; }
461
462 /// Returns an iterable over all keys of objects and/or directories written into this RFile starting at path
463 /// `basePath` (defaulting to include the content of all subdirectories).
464 /// The iterable yields values of type ROOT::Experimental::RKeyInfo.
465 ///
466 /// By default, keys referring to directories are not returned: only those referring to leaf objects are.
467 /// If `basePath` is the path of a leaf object, only `basePath` itself will be returned.
468 /// If `basePath` is the path of a directory, it won't appear in the listing.
469 /// `flags` is a bitmask specifying the listing mode.
470 /// If `(flags & kListObjects) != 0`, the listing will include keys of non-directory objects (default);
471 /// If `(flags & kListDirs) != 0`, the listing will include keys of directory objects;
472 /// If `(flags & kListRecursive) != 0`, the listing will recurse on all subdirectories of `basePath` (default),
473 /// otherwise it will only list immediate children of `basePath`.
474 ///
475 /// Example usage:
476 /// ~~~{.cpp}
477 /// for (RKeyInfo key : file->ListKeys()) {
478 /// // iterate over all objects in the RFile
479 /// cout << key.GetPath() << ";" << key.GetCycle() << " of type " << key.GetClassName() << "\n";
480 /// }
481 /// for (RKeyInfo key : file->ListKeys("", kListDirs|kListObjects|kListRecursive)) {
482 /// // iterate over all objects and directories in the RFile
483 /// }
484 /// for (RKeyInfo key : file->ListKeys("a/b", kListObjects)) {
485 /// // iterate over all objects that are immediate children of directory "a/b"
486 /// }
487 /// for (RKeyInfo key : file->ListKeys("foo", kListDirs|kListRecursive)) {
488 /// // iterate over all directories under directory "foo", recursively
489 /// }
490 /// ~~~
491 RFileKeyIterable ListKeys(std::string_view basePath = "", std::uint32_t flags = kListObjects | kListRecursive) const
492 {
493 if (!fFile)
494 throw ROOT::RException(R__FAIL("File has been closed"));
495
496 return RFileKeyIterable(fFile.get(), basePath, flags);
497 }
498
499 /// Retrieves information about the key of object at `path`, if one exists.
500 std::optional<RKeyInfo> GetKeyInfo(std::string_view path) const;
501
502 /// Prints the internal structure of this RFile to the given stream.
503 void Print(std::ostream &out = std::cout) const;
504
505 /// Returns the data contained in the ROOT file's header.
507};
508
509} // namespace ROOT
510
511#endif
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:322
#define BIT(n)
Definition Rtypes.h:90
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
The data stored in the ROOT file header.
Definition RFile.hxx:189
std::int8_t GetUnits() const
How many bytes do the Seek fields take up on disk. This is 4 for regular files and 8 for "big" files.
Definition RFile.hxx:218
std::int64_t fSeekFree
Definition RFile.hxx:195
std::int32_t fCompression
Definition RFile.hxx:198
std::int32_t GetCompression() const
Compression settings used by the file. See Compression.h for details.
Definition RFile.hxx:220
std::int8_t fUnits
Definition RFile.hxx:197
std::int32_t fNBytesFree
Definition RFile.hxx:196
std::int64_t GetBEGIN() const
First used byte in the file (except header)
Definition RFile.hxx:206
std::int64_t GetSeekFree() const
Offset into the file of the Free List section.
Definition RFile.hxx:210
std::int32_t GetVersion() const
Version of ROOT which wrote this file. When creating a file this is set to gROOT->GetVersionInt().
Definition RFile.hxx:204
std::int64_t fBEGIN
Definition RFile.hxx:193
std::int64_t GetEND() const
Last used byte in the file.
Definition RFile.hxx:208
std::int32_t fNBytesInfo
Definition RFile.hxx:200
std::int64_t fSeekInfo
Definition RFile.hxx:199
std::int32_t GetNBytesFree() const
Size on disk of the (potentially compressed) Free List section.
Definition RFile.hxx:212
std::int64_t fEND
Definition RFile.hxx:194
std::int32_t GetNBytesInfo() const
Size on disk of the (potentially compressed) File Info section.
Definition RFile.hxx:216
std::int64_t GetSeekInfo() const
Offset into the file of the File Info section.
Definition RFile.hxx:214
std::int32_t fVersion
Definition RFile.hxx:192
RIterator(TIterator *iter, Pattern_t pattern, std::uint32_t flags)
Definition RFile.cxx:424
bool operator!=(const iterator &rh) const
Definition RFile.hxx:175
bool operator==(const iterator &rh) const
Definition RFile.hxx:176
std::deque< RIterStackElem > fIterStack
Definition RFile.hxx:150
std::input_iterator_tag iterator_category
Definition RFile.hxx:163
The iterable returned by RFile::ListKeys()
Definition RFile.hxx:123
std::string Pattern_t
Definition RFile.hxx:124
RIterator end() const
Definition RFile.cxx:449
RFileKeyIterable(TFile *file, std::string_view rootDir, std::uint32_t flags)
Definition RFile.hxx:179
RIterator begin() const
Definition RFile.cxx:443
std::uint32_t fFlags
Definition RFile.hxx:128
An interface to read from, or write to, a ROOT file, as well as performing other common operations.
Definition RFile.hxx:289
@ kOverwrite_NoNewCycle
Definition RFile.hxx:333
void Close()
Flushes the RFile if needed and closes it, disallowing any further reading or writing.
Definition RFile.cxx:563
static constexpr int kMaxPathNesting
Definition RFile.hxx:364
static std::unique_ptr< RFile > Open(std::string_view path, const ROpenOptions &opts=ROpenOptions())
Opens the file for reading.
Definition RFile.cxx:205
void PutUntyped(std::string_view path, const std::type_info &type, const void *obj, std::uint32_t flags, std::string_view title)
Writes obj to file, without taking its ownership.
Definition RFile.cxx:342
std::unique_ptr< TFile > fFile
Definition RFile.hxx:301
void PutInternal(std::string_view path, const T &obj, std::uint32_t flags, std::string_view title)
Definition RFile.hxx:316
void Overwrite(std::string_view path, const T &obj, std::uint32_t overwriteFlags=0)
Puts an object into the file, overwriting any previously-existing object at that path.
Definition RFile.hxx:436
size_t Flush()
Writes all objects and the file structure to disk.
Definition RFile.cxx:555
void Print(std::ostream &out=std::cout) const
Prints the internal structure of this RFile to the given stream.
Definition RFile.cxx:541
TKey * GetTKey(std::string_view path) const
Given path, returns the TKey corresponding to the object at that path (assuming the path is fully spl...
Definition RFile.cxx:242
RFileKeyIterable ListKeys(std::string_view basePath="", std::uint32_t flags=kListObjects|kListRecursive) const
Returns an iterable over all keys of objects and/or directories written into this RFile starting at p...
Definition RFile.hxx:491
void Overwrite(std::string_view path, const T &obj, std::string_view title, std::uint32_t overwriteFlags=0)
Like Overwrite(std::string_view, const T&, bool) but allows giving a title to the object.
Definition RFile.hxx:444
bool IsOpen() const
Returns whether the file is still open or not.
Definition RFile.hxx:460
void * GetUntyped(std::string_view path, std::variant< const char *, std::reference_wrapper< const std::type_info > > type) const
Gets object path from the file and returns an owning pointer to it.
Definition RFile.cxx:287
static std::unique_ptr< RFile > Recreate(std::string_view path, const RRecreateOptions &opts=RRecreateOptions())
Opens the file for reading/writing, overwriting it if it already exists.
Definition RFile.cxx:227
std::unique_ptr< T > Get(std::string_view path) const
Retrieves an object from the file.
Definition RFile.hxx:392
void Put(std::string_view path, const T &obj, std::string_view title="")
Puts object obj into the file and gives it a title.
Definition RFile.hxx:410
@ kListRecursive
Definition RFile.hxx:330
EPutFlags
Flags used in PutInternal()
Definition RFile.hxx:294
@ kPutFlag_AllowOverwrite
When encountering an object at the specified path, overwrite it with the new one instead of erroring ...
Definition RFile.hxx:296
@ kPutFlag_OverwriteKeepCycle
When overwriting an object, preserve the existing one and create a new cycle, rather than removing it...
Definition RFile.hxx:298
std::optional< RKeyInfo > GetKeyInfo(std::string_view path) const
Retrieves information about the key of object at path, if one exists.
Definition RFile.cxx:582
RFile(std::unique_ptr< TFile > file)
Definition RFile.cxx:238
RFileHeader GetFileHeader() const
Returns the data contained in the ROOT file's header.
Definition RFile.cxx:592
static std::unique_ptr< RFile > Update(std::string_view path, const RUpdateOptions &opts=RUpdateOptions())
Opens the file for updating, creating a new one if it doesn't exist.
Definition RFile.cxx:216
void Put(const class TNamed &namedObj, std::string_view dirPath="")
Puts object namedObj in the file under the path dirPath/namedObj.GetName(), giving it a title equal t...
Information about an RFile object's Key.
Definition RFile.hxx:71
std::uint64_t GetNBytesKey() const
Returns the on-disk size of this object's key.
Definition RFile.hxx:114
std::uint64_t fSeekKey
Definition RFile.hxx:91
std::uint64_t fNBytesObj
Definition RFile.hxx:89
std::string fTitle
Definition RFile.hxx:84
RKeyInfo()=default
std::uint64_t fSeekParentDir
Definition RFile.hxx:92
std::uint16_t GetCycle() const
Definition RFile.hxx:105
std::uint64_t fNBytesKey
Definition RFile.hxx:90
const std::string & GetPath() const
Returns the absolute path of this key, i.e. the directory part plus the object name.
Definition RFile.hxx:100
std::uint16_t fCycle
Definition RFile.hxx:86
std::uint64_t GetSeekParentDir() const
Returns the on-disk offset of this object's parent directory key.
Definition RFile.hxx:119
const std::string & GetClassName() const
Definition RFile.hxx:104
ECategory GetCategory() const
Definition RFile.hxx:106
std::string fPath
Definition RFile.hxx:83
std::uint64_t fLenObj
Definition RFile.hxx:88
std::uint64_t GetSeekKey() const
Returns the on-disk offset of this object's key.
Definition RFile.hxx:116
std::string GetBaseName() const
Returns the base name of this key, i.e. the name of the object without the directory part.
Definition RFile.hxx:102
std::uint64_t GetNBytesObj() const
Returns the on-disk size of the (potentially compressed) object, excluding its key.
Definition RFile.hxx:111
std::string fClassName
Definition RFile.hxx:85
ECategory fCategory
Definition RFile.hxx:87
const std::string & GetTitle() const
Definition RFile.hxx:103
std::uint64_t GetLenObj() const
Returns the in-memory size of the uncompressed object.
Definition RFile.hxx:109
A log configuration for a channel, e.g.
Definition RLogger.hxx:97
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
Iterator abstract base class.
Definition TIterator.h:30
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
A TTree represents a columnar dataset.
Definition TTree.h:95
std::pair< std::string_view, std::string_view > DecomposePath(std::string_view path)
Given a "path-like" string (like foo/bar/baz), returns a pair { dirName, baseName }.
Definition RFile.cxx:194
ROOT::RLogChannel & RFileLog()
Definition RFile.cxx:25
void * RFile_GetObjectFromKey(RFile &file, const RKeyInfo &key)
Returns an owning pointer to the object referenced by key.
Definition RFile.cxx:611
TFile * GetRFileTFile(RFile &rfile)
Definition RFile.cxx:618
@ kUseGeneralPurpose
Use the new recommended general-purpose setting; it is a best trade-off between compression ratio/dec...
Definition Compression.h:58
RIterStackElem(TIterator *it, const std::string &path="")
Definition RFile.cxx:417
bool operator==(const RIterStackElem &other) const
Definition RFile.hxx:146
bool fEnableBrowsability
If true the RFile will show up in the TBrowser window.
Definition RFile.hxx:350
int fCompressionSettings
See core/zip/inc/Compression.h for the meaning of the compression argument.
Definition RFile.hxx:339
bool fEnableBrowsability
If true the RFile will show up in the TBrowser window.
Definition RFile.hxx:342
bool fEnableBrowsability
If true the RFile will show up in the TBrowser window.
Definition RFile.hxx:358