Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFile.cxx
Go to the documentation of this file.
1/// \file v7/src/RFile.cxx
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. It might trigger earthquakes. Feedback
5/// is welcome!
6
7#include "ROOT/RFile.hxx"
8
10#include <ROOT/RLogger.hxx>
11#include <ROOT/RError.hxx>
12
13#include <Byteswap.h>
14#include <TError.h>
15#include <TFile.h>
16#include <TIterator.h>
17#include <TKey.h>
18#include <TList.h>
19#include <TROOT.h>
20
21#include <algorithm>
22#include <cstring>
23
25{
26 static ROOT::RLogChannel sLog("ROOT.File");
27 return sLog;
28}
29
32
33namespace {
34enum class ENameCycleError {
35 kNoError,
36 kAnyCycle,
37 kInvalidSyntax,
38 kCycleTooLarge,
39 kNameEmpty,
40 kCOUNT
41};
42
43struct RNameCycleResult {
44 std::string fName;
45 std::optional<std::int16_t> fCycle;
46 ENameCycleError fError;
47};
48} // namespace
49
50static const char *ToString(ENameCycleError err)
51{
52 static const char *const kErrorStr[] = {"", "", "invalid syntax", "cycle is too large", "name is empty"};
53 static_assert(std::size(kErrorStr) == static_cast<std::size_t>(ENameCycleError::kCOUNT));
54 return kErrorStr[static_cast<std::size_t>(err)];
55}
56
57static ENameCycleError DecodeNumericCycle(const char *str, std::optional<std::int16_t> &out)
58{
59 uint32_t res = 0;
60 do {
61 if (!isdigit(*str))
62 return ENameCycleError::kInvalidSyntax;
63 if (res * 10 > std::numeric_limits<std::int16_t>::max())
64 return ENameCycleError::kCycleTooLarge;
65 res *= 10;
66 res += *str - '0';
67 } while (*++str);
68
69 assert(res < std::numeric_limits<std::int16_t>::max());
70 out = static_cast<std::int16_t>(res);
71
72 return ENameCycleError::kNoError;
73}
74
75static RNameCycleResult DecodeNameCycle(std::string_view nameCycleRaw)
76{
77 RNameCycleResult result{};
78
79 if (nameCycleRaw.empty())
80 return result;
81
82 // Scan the string to find the name length and the semicolon
83 std::size_t semicolonIdx = nameCycleRaw.find_first_of(';');
84
85 if (semicolonIdx == 0) {
86 result.fError = ENameCycleError::kNameEmpty;
87 return result;
88 }
89
90 // Verify that we have at most one ';'
91 if (nameCycleRaw.substr(semicolonIdx + 1).find_first_of(';') != std::string_view::npos) {
92 result.fError = ENameCycleError::kInvalidSyntax;
93 return result;
94 }
95
96 result.fName = nameCycleRaw.substr(0, semicolonIdx);
97 if (semicolonIdx < std::string_view::npos) {
98 if (semicolonIdx == nameCycleRaw.length() - 1 && nameCycleRaw[semicolonIdx] == '*')
99 result.fError = ENameCycleError::kAnyCycle;
100 else
101 result.fError = DecodeNumericCycle(nameCycleRaw.substr(semicolonIdx + 1).data(), result.fCycle);
102 }
103
104 return result;
105}
106
107/// This function first validates, then normalizes the given path in place.
108///
109/// Returns an empty string if `path` is a suitable path to store an object into a RFile,
110/// otherwise returns a description of why that is not the case.
111///
112/// A valid object path must:
113/// - not be empty
114/// - not contain the character '.'
115/// - not contain ASCII control characters or whitespace characters (including tab or newline).
116/// - not contain more than RFile::kMaxPathNesting path fragments (i.e. more than RFile::kMaxPathNesting - 1 '/')
117/// - not end with a '/'
118///
119/// In addition, when *writing* an object to RFile, the character ';' is also banned.
120///
121/// Passing an invalid path to Put will cause it to throw an exception, and
122/// passing an invalid path to Get will always return nullptr.
123///
124/// If required, `path` is modified to make its hierarchy-related meaning consistent. This entails:
125/// - combining any consecutive '/' into a single one;
126/// - stripping any leading '/'.
127///
128static std::string ValidateAndNormalizePath(std::string &path)
129{
130 ////// First, validate path.
131
132 if (path.empty())
133 return "path cannot be empty";
134
135 if (path.back() == '/')
136 return "path cannot end with a '/'";
137
138 bool valid = true;
139 for (char ch : path) {
140 // Disallow control characters, tabs, newlines, whitespace and dot.
141 // NOTE: not short-circuiting or early returning to enable loop vectorization.
142 valid &= !(ch < 33 || ch == '.');
143 }
144 if (!valid)
145 return "path cannot contain control characters, whitespaces or dots";
146
147 //// Path is valid so far, normalize it.
148
149 // Strip all leading '/'
150 {
151 auto nToStrip = 0u;
152 const auto len = path.length();
153 while (nToStrip < len && path[nToStrip] == '/')
154 ++nToStrip;
155
156 if (nToStrip > 0)
157 path.erase(0, nToStrip);
158 }
159
160 // Remove duplicate consecutive '/'
161 const auto it = std::unique(path.begin(), path.end(), [](char a, char b) { return (a == '/' && b == '/'); });
162 path.erase(it, path.end());
163
164 //// After the path has been normalized, check the nesting level by counting how many slashes it contains.
165 const auto nesting = std::count(path.begin(), path.end(), '/');
166 if (nesting > RFile::kMaxPathNesting)
167 return "pathView contains too many levels of nesting";
168
169 return "";
170}
171
172static void EnsureFileOpenAndBinary(const TFile *tfile, std::string_view path)
173{
174 if (!tfile || tfile->IsZombie())
175 throw ROOT::RException(R__FAIL("failed to open file " + std::string(path) + " for reading"));
176
177 if (tfile->IsRaw() || !tfile->IsBinary() || tfile->IsArchive())
178 throw ROOT::RException(R__FAIL("Opened file " + std::string(path) + " is not a ROOT binary file"));
179}
180
181static std::string ReconstructFullKeyPath(const TKey &key)
182{
183 std::string path = key.GetName();
184 TDirectory *parent = key.GetMotherDir();
185 while (parent && parent->GetMotherDir()) {
186 path = std::string(parent->GetName()) + "/" + path;
187 parent = parent->GetMotherDir();
188 }
189 return path;
190}
191
192/////////////////////////////////////////////////////////////////////////////////////////////////
193std::pair<std::string_view, std::string_view> ROOT::Experimental::Detail::DecomposePath(std::string_view path)
194{
195 auto lastSlashIdx = path.rfind('/');
196 if (lastSlashIdx == std::string_view::npos)
197 return {{}, path};
198
199 auto dirName = path.substr(0, lastSlashIdx + 1);
200 auto pathName = path.substr(lastSlashIdx + 1);
201 return {dirName, pathName};
202}
203
204std::unique_ptr<RFile> RFile::Open(std::string_view path, const ROpenOptions &opts)
205{
206 TDirectory::TContext ctx(nullptr); // XXX: probably not thread safe?
207 const char *mode = opts.fEnableBrowsability ? "READ" : "READ_WITHOUT_GLOBALREGISTRATION";
208 auto tfile = std::unique_ptr<TFile>(TFile::Open(std::string(path).c_str(), mode));
209 EnsureFileOpenAndBinary(tfile.get(), path);
210
211 auto rfile = std::unique_ptr<RFile>(new RFile(std::move(tfile)));
212 return rfile;
213}
214
215std::unique_ptr<RFile> RFile::Update(std::string_view path, const RUpdateOptions &opts)
216{
217 TDirectory::TContext ctx(nullptr); // XXX: probably not thread safe?
218 const char *mode = opts.fEnableBrowsability ? "UPDATE" : "UPDATE_WITHOUT_GLOBALREGISTRATION";
219 auto tfile = std::unique_ptr<TFile>(TFile::Open(std::string(path).c_str(), mode));
220 EnsureFileOpenAndBinary(tfile.get(), path);
221
222 auto rfile = std::unique_ptr<RFile>(new RFile(std::move(tfile)));
223 return rfile;
224}
225
226std::unique_ptr<RFile> RFile::Recreate(std::string_view path, const RRecreateOptions &opts)
227{
228 TDirectory::TContext ctx(nullptr); // XXX: probably not thread safe?
229 const char *mode = opts.fEnableBrowsability ? "RECREATE" : "RECREATE_WITHOUT_GLOBALREGISTRATION";
230 auto tfile = std::unique_ptr<TFile>(TFile::Open(std::string(path).c_str(), mode, "", opts.fCompressionSettings));
231 EnsureFileOpenAndBinary(tfile.get(), path);
232
233 auto rfile = std::unique_ptr<RFile>(new RFile(std::move(tfile)));
234 return rfile;
235}
236
237RFile::RFile(std::unique_ptr<TFile> file) : fFile(std::move(file)) {}
238
239RFile::~RFile() = default;
240
241TKey *RFile::GetTKey(std::string_view path) const
242{
243 // In RFile, differently from TFile, when dealing with a path like "a/b/c", we always consider it to mean
244 // "object 'c' in subdirectory 'b' of directory 'a'". We don't try to get any other of the possible combinations,
245 // including the object called "a/b/c".
246 std::string fullPath = std::string(path);
247 char *dirName = fullPath.data();
248 char *restOfPath = strchr(dirName, '/');
249 TDirectory *dir = fFile.get();
250 while (restOfPath) {
251 // Truncate `dirName` to the position of this '/'.
252 *restOfPath = 0;
253 ++restOfPath;
254 // `restOfPath` should always be a non-empty string unless `path` ends with '/' (which it shouldn't, as we are
255 // supposed to have normalized it before calling this function).
256 assert(*restOfPath);
257
258 dir = dir->GetDirectory(dirName);
259 if (!dir)
260 return nullptr;
261
262 dirName = restOfPath;
263 restOfPath = strchr(restOfPath, '/');
264 }
265 // NOTE: after this loop `dirName` contains the base name of the object.
266
267 // Get the leaf object from the innermost directory.
268 TKey *key = dir->FindKey(dirName);
269 if (key) {
270 // For some reason, FindKey will not return nullptr if we asked for a specific cycle and that cycle
271 // doesn't exist. It will instead return any key whose cycle is *at most* the requested one.
272 // This is very confusing, so in RFile we actually return null if the requested cycle is not there.
273 RNameCycleResult res = DecodeNameCycle(dirName);
274 if (res.fError != ENameCycleError::kAnyCycle) {
275 if (res.fError != ENameCycleError::kNoError) {
276 R__LOG_ERROR(RFileLog()) << "error decoding namecycle '" << dirName << "': " << ToString(res.fError);
277 key = nullptr;
278 } else if (res.fCycle && *res.fCycle != key->GetCycle()) {
279 key = nullptr;
280 }
281 }
282 }
283 return key;
284}
285
286void *RFile::GetUntyped(std::string_view path,
287 std::variant<const char *, std::reference_wrapper<const std::type_info>> type) const
288{
289 if (!fFile)
290 throw ROOT::RException(R__FAIL("File has been closed"));
291
292 std::string pathStr{path};
293
294 struct {
295 TClass *operator()(const char *name) { return TClass::GetClass(name); }
296 TClass *operator()(std::reference_wrapper<const std::type_info> ty) { return TClass::GetClass(ty.get()); }
297 } typeVisitor;
298 const TClass *cls = std::visit(std::move(typeVisitor), type);
299
300 if (!cls)
301 throw ROOT::RException(R__FAIL(std::string("Could not determine type of object ") + pathStr));
302
303 if (auto err = ValidateAndNormalizePath(pathStr); !err.empty())
304 throw RException(R__FAIL("Invalid object pathStr '" + pathStr + "': " + err));
305
306 TKey *key = GetTKey(pathStr);
307 void *obj = key ? key->ReadObjectAny(cls) : nullptr;
308
309 if (obj) {
310 // Disavow any ownership on `obj` unless the object is a TTree, in which case we need to link it to our internal
311 // file for it to be usable.
312 if (auto autoAddFunc = cls->GetDirectoryAutoAdd()) {
313 if (cls->InheritsFrom("TTree")) {
314 autoAddFunc(obj, fFile.get());
315 // NOTE(gparolini): this is a hacky but effective way of preventing the Tree from being deleted by
316 // the internal TFile once we close it. We need to avoid that because this TTree will be returned inside
317 // a unique_ptr and would end up being double-freed if we allowed ROOT to do its own memory management.
319 } else {
320 autoAddFunc(obj, nullptr);
321 }
322 }
323 } else if (key) {
324 R__LOG_INFO(RFileLog()) << "Tried to get object '" << path << "' of type " << cls->GetName()
325 << " but that path contains an object of type " << key->GetClassName();
326 }
327
328 return obj;
329}
330
331void RFile::PutUntyped(std::string_view pathSV, const std::type_info &type, const void *obj, std::uint32_t flags)
332{
333 const TClass *cls = TClass::GetClass(type);
334 if (!cls)
335 throw ROOT::RException(R__FAIL(std::string("Could not determine type of object ") + std::string(pathSV)));
336
337 std::string path{pathSV};
338 if (auto err = ValidateAndNormalizePath(path); !err.empty())
339 throw RException(R__FAIL("Invalid object path '" + path + "': " + err));
340
341 if (path.find_first_of(';') != std::string_view::npos) {
342 throw RException(
343 R__FAIL("Invalid object path '" + path +
344 "': character ';' is used to specify an object cycle, which only makes sense when reading."));
345 }
346
347 if (!fFile)
348 throw ROOT::RException(R__FAIL("File has been closed"));
349
350 if (!fFile->IsWritable())
351 throw ROOT::RException(R__FAIL("File is not writable"));
352
353 // If `path` refers to a subdirectory, make sure we always write in an actual TDirectory,
354 // otherwise we may have a mix of top-level objects called "a/b/c" and actual directory
355 // structures.
356 // Sadly, TFile does nothing to prevent this and will happily write "a/b" even if there
357 // is already a directory "a" containing an object "b". We don't want that ambiguity here, so we take extra steps
358 // to ensure it doesn't happen.
359 const auto tokens = ROOT::Split(path, "/");
360 const auto FullPathUntil = [&tokens](auto idx) {
361 return ROOT::Join("/", std::span<const std::string>{tokens.data(), idx + 1});
362 };
363 TDirectory *dir = fFile.get();
364 for (auto tokIdx = 0u; tokIdx < tokens.size() - 1; ++tokIdx) {
365 // Alas, not only does mkdir not fail if the file already contains an object "a/b" and you try
366 // to create dir "a", but even when it does fail it doesn't tell you why.
367 // We obviously don't want to allow the coexistence of regular object named "a/b" and the directory
368 // named "a", so we manually check if each level of nesting doesn't exist already as a non-directory.
369 const TKey *existing = dir->GetKey(tokens[tokIdx].c_str());
370 if (existing && strcmp(existing->GetClassName(), "TDirectory") != 0 &&
371 strcmp(existing->GetClassName(), "TDirectoryFile") != 0) {
372 throw ROOT::RException(R__FAIL("error adding object '" + path + "': failed to create directory '" +
373 FullPathUntil(tokIdx) + "': name already taken by an object of type '" +
374 existing->GetClassName() + "'"));
375 }
376 dir = dir->mkdir(tokens[tokIdx].c_str(), "", true);
377 if (!dir) {
378 throw ROOT::RException(R__FAIL(std::string("failed to create directory ") + FullPathUntil(tokIdx)));
379 }
380 }
381
382 const bool allowOverwrite = (flags & kPutAllowOverwrite) != 0;
383 const bool backupCycle = (flags & kPutOverwriteKeepCycle) != 0;
384 const Option_t *writeOpts = "";
385 if (!allowOverwrite) {
386 const TKey *existing = dir->GetKey(tokens[tokens.size() - 1].c_str());
387 if (existing) {
388 throw ROOT::RException(R__FAIL(std::string("trying to overwrite object ") + path + " of type " +
389 existing->GetClassName() + " with another object of type " + cls->GetName()));
390 }
391 } else if (!backupCycle) {
392 writeOpts = "WriteDelete";
393 }
394
395 int success = dir->WriteObjectAny(obj, cls, tokens[tokens.size() - 1].c_str(), writeOpts);
396
397 if (!success) {
398 throw ROOT::RException(R__FAIL(std::string("Failed to write ") + path + " to file"));
399 }
400}
401
403 : fIter(it), fDirPath(path)
404{
405}
406
408
410 : fPattern(pattern), fFlags(flags)
411{
412 if (iter) {
413 fIterStack.emplace_back(iter);
414
415 if (!pattern.empty()) {
416 fRootDirNesting = std::count(pattern.begin(), pattern.end(), '/');
417 // `pattern` may or may not end with '/', but we consider it a directory regardless.
418 // In other words, like in virtually all filesystem operations, "dir" and "dir/" are equivalent.
419 fRootDirNesting += pattern.back() != '/';
420 }
421
422 // Advance the iterator to skip the first key, which is always the TFile key.
423 // This will also skip keys until we reach the first correct key we want to return.
424 Advance();
425 }
426}
427
432
437
439{
440 fCurKey = nullptr;
441
442 const bool recursive = fFlags & RFile::kListRecursive;
443 const bool includeObj = fFlags & RFile::kListObjects;
444 const bool includeDirs = fFlags & RFile::kListDirs;
445
446 // We only want to return keys that refer to user objects, not internal ones, therefore we skip
447 // all keys that have internal class names.
448 while (!fIterStack.empty()) {
449 auto &[iter, dirPath] = fIterStack.back();
450 assert(iter);
451 TObject *keyObj = iter->Next();
452 if (!keyObj) {
453 // reached end of the iteration
454 fIterStack.pop_back();
455 continue;
456 }
457
458 assert(keyObj->IsA() == TClass::GetClass<TKey>());
459 auto key = static_cast<TKey *>(keyObj);
460
461 const std::string dirSep = (dirPath.empty() ? "" : "/");
462 const bool isDir = TClass::GetClass(key->GetClassName())->InheritsFrom(TDirectory::Class());
463
464 if (isDir) {
465 TDirectory *dir = key->ReadObject<TDirectory>();
466 TIterator *innerIter = dir->GetListOfKeys()->MakeIterator();
467 assert(innerIter);
468 fIterStack.emplace_back(innerIter, dirPath + dirSep + dir->GetName());
469 if (!includeDirs)
470 continue;
471 } else if (!includeObj) {
472 continue;
473 }
474
475 // Reconstruct the full path of the key
476 const std::string &fullPath = dirPath + dirSep + key->GetName();
477 assert(!fIterStack.empty());
478 const std::size_t nesting = fIterStack.size() - 1;
479
480 // Skip key if it's the root dir itself
481 if (isDir && fullPath == fPattern)
482 continue;
483
484 // Skip key if it's not a child of root dir
485 if (!ROOT::StartsWith(fullPath, fPattern))
486 continue;
487
488 // Check that we are in the same directory as "rootDir".
489 // Note that for directories we list both the root dir and the immediate children (in non-recursive mode).
490 if (!recursive && nesting != fRootDirNesting &&
491 (!isDir || nesting != static_cast<std::size_t>(fRootDirNesting + 1)))
492 continue;
493
494 // All checks passed: return this key.
495 assert(!fullPath.empty());
496 fCurKey = key;
497 break;
498 }
499}
500
502{
503 if (fIterStack.empty())
504 throw ROOT::RException(R__FAIL("tried to dereference an invalid iterator"));
505
506 const TKey *key = fCurKey;
507 if (!key)
508 throw ROOT::RException(R__FAIL("tried to dereference an invalid iterator"));
509
510 const bool isDir =
511 strcmp(key->GetClassName(), "TDirectory") == 0 || strcmp(key->GetClassName(), "TDirectoryFile") == 0;
512 const auto &dirPath = fIterStack.back().fDirPath;
513
514 RKeyInfo keyInfo;
516 keyInfo.fPath = dirPath;
517 if (!isDir)
518 keyInfo.fPath += std::string(dirPath.empty() ? "" : "/") + key->GetName();
519 keyInfo.fClassName = key->GetClassName();
520 keyInfo.fCycle = key->GetCycle();
521 keyInfo.fTitle = key->GetTitle();
522 return keyInfo;
523}
524
525void RFile::Print(std::ostream &out) const
526{
527 std::vector<RKeyInfo> keys;
528 auto keysIter = ListKeys();
529 for (const auto &key : keysIter) {
530 keys.emplace_back(key);
531 }
532
533 std::sort(keys.begin(), keys.end(), [](const auto &a, const auto &b) { return a.GetPath() < b.GetPath(); });
534 for (const auto &key : keys) {
535 out << key.GetClassName() << " " << key.GetPath() << ";" << key.GetCycle() << ": \"" << key.GetTitle() << "\"\n";
536 }
537}
538
540{
541 return fFile->Write();
542}
543
545{
546 // NOTE: this also flushes the file internally
547 fFile.reset();
548}
549
551 : fPath(ReconstructFullKeyPath(key)),
552 fTitle(key.GetTitle()),
553 fClassName(key.GetClassName()),
554 fCycle(key.GetCycle()),
555 fLenObj(key.GetObjlen()),
556 fNBytesObj(key.GetNbytes() - key.GetKeylen()),
557 fNBytesKey(key.GetKeylen()),
558 fSeekKey(key.GetSeekKey()),
559 fSeekParentDir(key.GetSeekPdir())
560{
561}
562
563std::optional<ROOT::Experimental::RKeyInfo> RFile::GetKeyInfo(std::string_view path) const
564{
565 const TKey *key = GetTKey(path);
566 if (!key)
567 return {};
568
569 RKeyInfo keyInfo(*key);
570 return keyInfo;
571}
572
574{
575 void *obj = file.GetUntyped(key.GetPath(), key.GetClassName().c_str());
576 return obj;
577}
578
580{
581 return file.fFile.get();
582}
583
#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
static const char * ToString(ENameCycleError err)
Definition RFile.cxx:50
static ENameCycleError DecodeNumericCycle(const char *str, std::optional< std::int16_t > &out)
Definition RFile.cxx:57
static void EnsureFileOpenAndBinary(const TFile *tfile, std::string_view path)
Definition RFile.cxx:172
static std::string ReconstructFullKeyPath(const TKey &key)
Definition RFile.cxx:181
static RNameCycleResult DecodeNameCycle(std::string_view nameCycleRaw)
Definition RFile.cxx:75
static std::string ValidateAndNormalizePath(std::string &path)
This function first validates, then normalizes the given path in place.
Definition RFile.cxx:128
#define R__LOG_ERROR(...)
Definition RLogger.hxx:356
#define R__LOG_INFO(...)
Definition RLogger.hxx:358
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
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 result
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 UChar_t len
Option_t Option_t TPoint TPoint const char mode
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
char name[80]
Definition TGX11.cxx:142
std::deque< RIterStackElem > fIterStack
Definition RFile.hxx:150
RIterator(TIterator *iter, Pattern_t pattern, std::uint32_t flags)
Definition RFile.cxx:409
An interface to read from, or write to, a ROOT file, as well as performing other common operations.
Definition RFile.hxx:254
void Close()
Flushes the RFile if needed and closes it, disallowing any further reading or writing.
Definition RFile.cxx:544
std::unique_ptr< TFile > fFile
Definition RFile.hxx:266
size_t Flush()
Writes all objects and the file structure to disk.
Definition RFile.cxx:539
void Print(std::ostream &out=std::cout) const
Prints the internal structure of this RFile to the given stream.
Definition RFile.cxx:525
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:241
std::optional< RKeyInfo > GetKeyInfo(std::string_view path) const
Retrieves information about the key of object at path, if one exists.
Definition RFile.cxx:563
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:286
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:226
void PutUntyped(std::string_view path, const std::type_info &type, const void *obj, std::uint32_t flags)
Writes obj to file, without taking its ownership.
Definition RFile.cxx:331
@ kPutOverwriteKeepCycle
When overwriting an object, preserve the existing one and create a new cycle, rather than removing it...
Definition RFile.hxx:263
@ kPutAllowOverwrite
When encountering an object at the specified path, overwrite it with the new one instead of erroring ...
Definition RFile.hxx:261
RFile(std::unique_ptr< TFile > file)
Definition RFile.cxx:237
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:215
Information about an RFile object's Key.
Definition RFile.hxx:71
const std::string & GetClassName() const
Definition RFile.hxx:104
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
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
A log configuration for a channel, e.g.
Definition RLogger.hxx:97
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
ROOT::DirAutoAdd_t GetDirectoryAutoAdd() const
Return the wrapper around the directory auto add function.
Definition TClass.cxx:7715
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4995
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.
Definition TClass.cxx:2999
TList * GetListOfKeys() const override
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
Describe directory structure in memory.
Definition TDirectory.h:45
static TClass * Class()
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual Int_t WriteObjectAny(const void *, const char *, const char *, Option_t *="", Int_t=0)
Definition TDirectory.h:301
virtual TKey * GetKey(const char *, Short_t=9999) const
Definition TDirectory.h:222
virtual TKey * FindKey(const char *) const
Definition TDirectory.h:198
virtual TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE)
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
virtual TList * GetListOfKeys() const
Definition TDirectory.h:224
TDirectory * GetMotherDir() const
Definition TDirectory.h:226
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
Bool_t IsBinary() const
Definition TFile.h:347
Bool_t IsRaw() const
Definition TFile.h:348
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write memory objects to this file.
Definition TFile.cxx:2503
virtual Bool_t IsArchive() const
Definition TFile.h:346
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3802
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
const char * GetTitle() const override
Returns title (title can contain 32x32 xpm thumbnail/icon).
Definition TKey.cxx:1678
virtual const char * GetClassName() const
Definition TKey.h:77
virtual void * ReadObjectAny(const TClass *expectedClass)
To read an object (non deriving from TObject) from the file.
Definition TKey.cxx:1043
TDirectory * GetMotherDir() const
Definition TKey.h:87
Short_t GetCycle() const
Return cycle number associated to this key.
Definition TKey.cxx:623
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Return a list iterator.
Definition TList.cxx:852
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Mother of all ROOT objects.
Definition TObject.h:42
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:161
virtual TClass * IsA() const
Definition TObject.h:248
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:193
ROOT::RLogChannel & RFileLog()
Definition RFile.cxx:24
void * RFile_GetObjectFromKey(RFile &file, const RKeyInfo &key)
Returns an owning pointer to the object referenced by key.
Definition RFile.cxx:573
TFile * GetRFileTFile(RFile &rfile)
Definition RFile.cxx:579
void MarkTObjectAsNotOnHeap(TObject &obj)
Definition TObject.cxx:1277
std::string Join(const std::string &sep, InputIt_t begin, InputIt_t end)
Concatenate a list of strings with a separator.
bool StartsWith(std::string_view string, std::string_view prefix)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
RIterStackElem(TIterator *it, const std::string &path="")
Definition RFile.cxx:402
bool fEnableBrowsability
If true the RFile will show up in the TBrowser window.
Definition RFile.hxx:312
bool fEnableBrowsability
If true the RFile will show up in the TBrowser window.
Definition RFile.hxx:304
int fCompressionSettings
See core/zip/inc/Compression.h for the meaning of the compression argument.
Definition RFile.hxx:301
bool fEnableBrowsability
If true the RFile will show up in the TBrowser window.
Definition RFile.hxx:320