Skip to content

Commit a70791d

Browse files
committed
[rfile] Some improvements to doc and tests; use Info for extension msg
1 parent 9070e49 commit a70791d

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

io/io/inc/ROOT/RFile.hxx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ ROOT::RLogChannel &RFileLog();
3737
## When and why should you use RFile
3838
3939
RFile is a modern and minimalistic interface to ROOT files, both local and remote, that can be used instead of TFile
40-
when the following conditions are met:
41-
- you want a simple interface that makes it easy to do things right and hard to do things wrong;
42-
- you only need basic Put/Get operations and don't need the more advanced TFile/TDirectory functionalities;
43-
- you want more robustness and better error reporting for those operations;
44-
- you want clearer ownership semantics expressed through the type system rather than having objects "automagically"
45-
handled for you via implicit ownership of raw pointers.
40+
when you only need basic Put/Get operations and don't need the more advanced TFile/TDirectory functionalities.
41+
It provides:
42+
- a simple interface that makes it easy to do things right and hard to do things wrong;
43+
- more robustness and better error reporting for those operations;
44+
- clearer ownership semantics expressed through the type system.
4645
47-
RFile doesn't try to cover the entirety of use cases covered by TFile/TDirectory/TDirectoryFile and is not
48-
a 1:1 replacement for them. It is meant to simplify the most common use cases and make them easier to handle by
49-
minimizing the amount of ROOT-specific quirks and conforming to more standard C++ practices.
46+
RFile doesn't cover the entirety of use cases covered by TFile/TDirectory/TDirectoryFile and is not
47+
a 1:1 replacement for them. It is meant to simplify the most common use cases by following newer standard C++
48+
practices.
5049
5150
## Ownership model
5251
@@ -65,13 +64,11 @@ file).
6564
6665
## Directories
6766
68-
Differently from TFile, the RFile class itself is not also a "directory". In fact, there is no RDirectory class at all.
69-
70-
Directories are still an existing concept in RFile (since they are a concept in the ROOT binary format),
71-
but they are usually interacted with indirectly, via the use of filesystem-like string-based paths. If you Put an object
72-
in an RFile under the path "path/to/object", "object" will be stored under directory "to" which is in turn stored under
73-
directory "path". This hierarchy is encoded in the ROOT file itself and it can provide some optimization and/or
74-
conveniencies when querying objects.
67+
Even though there is no equivalent of TDirectory in the RFile API, directories are still an existing concept in RFile
68+
(since they are a concept in the ROOT binary format). However they are for now only interacted with indirectly, via the
69+
use of filesystem-like string-based paths. If you Put an object in an RFile under the path "path/to/object", "object"
70+
will be stored under directory "to" which is in turn stored under directory "path". This hierarchy is encoded in the
71+
ROOT file itself and it can provide some optimization and/or conveniencies when querying objects.
7572
7673
For the most part, it is convenient to think about RFile in terms of a key-value storage where string-based paths are
7774
used to refer to arbitrary objects. However, given the hierarchical nature of ROOT files, certain filesystem-like
@@ -96,8 +93,11 @@ auto myObj = file->Get<TH1D>("h");
9693
~~~
9794
*/
9895
class RFile final {
96+
/// Flags used in PutInternal()
9997
enum PutFlags {
98+
/// When encountering an object at the specified path, overwrite it with the new one instead of erroring out.
10099
kPutAllowOverwrite = 0x1,
100+
/// When overwriting an object, preserve the existing one and create a new cycle, rather than removing it.
101101
kPutOverwriteKeepCycle = 0x2,
102102
};
103103

io/io/src/RFile.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void CheckExtension(std::string_view path)
3535
}
3636

3737
if (!ROOT::EndsWith(path, ".root")) {
38-
R__LOG_WARNING(RFileLog()) << "ROOT::RFile only supports ROOT files. The preferred file extension is \".root\"";
38+
R__LOG_INFO(RFileLog()) << "ROOT::RFile only supports ROOT files. The preferred file extension is \".root\"";
3939
}
4040
}
4141

io/io/test/rfile.cxx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <ROOT/RError.hxx>
99
#include <ROOT/RFile.hxx>
1010
#include <ROOT/TestSupport.hxx>
11-
#include <numeric>
11+
#include <ROOT/RLogger.hxx>
1212

1313
using ROOT::Experimental::RFile;
1414

@@ -74,9 +74,6 @@ TEST(RFile, OpenInexistent)
7474
{
7575
FileRaii fileGuard("does_not_exist.root");
7676

77-
// make sure that the file really does not exist, in case a previous test didn't clean it up.
78-
gSystem->Unlink(fileGuard.GetPath().c_str());
79-
8077
ROOT::TestSupport::CheckDiagsRAII diags;
8178
diags.optionalDiag(kSysError, "TFile::TFile", "", false);
8279
diags.optionalDiag(kError, "TFile::TFile", "", false);
@@ -101,7 +98,10 @@ TEST(RFile, OpenInexistent)
10198
}
10299

103100
// This succeeds because Update creates the file if it doesn't exist.
104-
EXPECT_NO_THROW(RFile::Update("does_not_exist.root"));
101+
FileRaii fileGuard2("created_by_update.root");
102+
// in case a previous run of the test failed to clean up, make sure the file doesn't exist:
103+
gSystem->Unlink(fileGuard2.GetPath().c_str());
104+
EXPECT_NO_THROW(RFile::Update(fileGuard2.GetPath()));
105105
}
106106

107107
TEST(RFile, OpenForWriting)
@@ -148,8 +148,8 @@ TEST(RFile, CheckNoAutoRegistrationRead)
148148
auto file = RFile::Open(fileGuard.GetPath());
149149
EXPECT_EQ(gDirectory, gROOT);
150150
auto hist = file->Get<TH1D>("hist");
151-
EXPECT_EQ(hist->GetDirectory(), nullptr);
152151
ASSERT_NE(hist, nullptr);
152+
EXPECT_EQ(hist->GetDirectory(), nullptr);
153153
EXPECT_FLOAT_EQ(hist->GetEntries(), 1);
154154
}
155155
// no double free should happen when ROOT exits
@@ -265,10 +265,11 @@ TEST(RFile, PutOverwrite)
265265

266266
TEST(RFile, WrongExtension)
267267
{
268+
ROOT::RLogScopedVerbosity logVerb(ROOT::ELogLevel::kInfo);
268269
{
269270
FileRaii fileGuard("test_rfile_wrong.root.1");
270271
ROOT::TestSupport::CheckDiagsRAII diagsRaii;
271-
diagsRaii.requiredDiag(kWarning, "ROOT.File", "preferred file extension is \".root\"", false);
272+
diagsRaii.requiredDiag(kInfo, "ROOT.File", "preferred file extension is \".root\"", false);
272273
RFile::Recreate(fileGuard.GetPath());
273274
}
274275
{

0 commit comments

Comments
 (0)