-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[rfile] Introduce RFile first prototype #19958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the work!
Seeing the code sparked a lot of questions. Many of those might be either addressed in later PRs and some might be irrelevant, so feel free to "Resolve" those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After yesterday's discussion, is it wise to put this in io/v7
? Version numbers in file names or configs will just create headaches. How about putting it in io/rfile
, where it can remain also in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the end I just put it in io/io
to avoid CMake headaches. Since it's always built anyway it doesn't make much of a difference in my opinion.
|
||
} // namespace Internal | ||
|
||
class RFile final { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
will prevent users from inheriting and possibly overriding. Is this the intention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A larger docstring for the class documentation would be desirable, but it
- can be added later
- and could be placed in the
.cxx
, so you don't have to recompile everything when updating the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
will prevent users from inheriting and possibly overriding. Is this the intention?
Considering we're not defining any virtual method (including the destructor) I don't see how the user could effectively inherit this class anyway. If we change our mind later we can just remove the final
, but I consider it a good default.
/// The caller should immediately wrap it into a unique_ptr of the type described by `type`. | ||
[[nodiscard]] void *GetUntyped(std::string_view path, const TClass &type) const; | ||
|
||
/// Writes `obj` to file, without taking its ownership. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this makes it clearer?
/// Writes `obj` to file, without taking its ownership. | |
/// Writes a copy of `obj` to file, without taking its ownership. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An explanation of type
and flags
would be great, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I see now that this is private, so the request has low priority.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the "a copy of" part; the object is not really copied in memory, it's just serialized into the file. At least, that's the mental model that the both us and the user should have, regardless of how TFile actually implements it
return std::unique_ptr<T>(static_cast<T *>(obj)); | ||
} | ||
|
||
/// Puts an object into the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Puts an object into the file. | |
/// Puts a copy of an object into the file. |
@@ -0,0 +1,397 @@ | |||
#include "gtest/gtest.h" | |||
#include "gmock/gmock.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it using gmock
? I might have removed gmock
from the automatically linked CMake targets, so you might have to add it if required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is apparently needed by testing::HasSubstr
EXPECT_FALSE(file->Get<TH1F>("hist")); | ||
EXPECT_TRUE(file->Get<TH1>("hist")); | ||
|
||
// We do NOT want to globally register RFiles ever. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Maybe yes if the browser is supposed to show a list of open files. But if we decide that that's what it should do, one should maybe do this in a different list with weak pointers or so ...
auto hist = file->Get<TH1D>("hist"); | ||
ASSERT_TRUE(hist); | ||
EXPECT_EQ(static_cast<int>(hist->GetEntries()), 10); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this hold?
EXPECT_EQ(*file->Get<TH1D>("hist;2"), *hist); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the equality operator is defined for TH1..
constexpr const char *kFileName = "http://root.cern/files/RNTuple.root"; | ||
|
||
auto file = RFile::Open(kFileName); | ||
auto ntuple = file->Get<ROOT::RNTuple>("Contributors"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this gracefully fail with GTEST_SKIP() if one is offline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know...how can we reliably detect whether we're offline? Do we do this in other tests?
TH1D hist(histName, histTitle, 100, -10 * (i + 1), 10 * (i + 1)); | ||
file->Put(histPath, hist); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this test increases coverage. Also, if it was covering a new case, wouldn't you at least have to check that the objects can be read / listed?
Test Results 21 files 21 suites 3d 17h 56m 43s ⏱️ For more details on these failures, see this check. Results for commit 6cbc229. ♻️ This comment has been updated with latest results. |
978733c
to
7430133
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small comments, but in general I'll leave review to others...
ROOT_ADD_GTEST(RIoUring RIoUring.cxx LIBRARIES RIO) | ||
endif() | ||
|
||
ROOT_ADD_GTEST(rfile rfile.cxx LIBRARIES RIO Hist ROOTNTuple) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle, ROOTNTuple
is a higher level in terms of layering than RIO
, not sure if it's a good idea to depend on it (even for a test)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that the case also for Hist
?
7430133
to
868ac3e
Compare
868ac3e
to
6cbc229
Compare
This PR adds a first version of the new RFile prototype, implementing basic Open/Append/Recreate/Get/Put methods.
For a sneak peek of the final shape of the prototype, see here
Checklist: