Skip to content

Commit 91bc815

Browse files
committed
[ntuple] Make RNTupleWriter::Append(RFile) a free function
Just for the time being, to avoid exposing experimental API as a public method of the RNTupleWriter, use a free friend function in the Experimental namespace. When we settle on the RFile/RNTuple writing semantics we will remove this function and replace it with a factory method.
1 parent 414d92b commit 91bc815

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

io/io/test/rfile.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ TEST(RFile, RNTuple)
713713
const auto kNEntries = 100;
714714
for (int i = 0; i < kNDatasets; ++i) {
715715
const auto ntuplePath = std::string("data_") + (i + 1);
716-
const auto writer = ROOT::RNTupleWriter::Append(model->Clone(), ntuplePath, *file);
716+
const auto writer = ROOT::Experimental::RNTupleWriter_Append(model->Clone(), ntuplePath, *file);
717717
for (int j = 0; j < kNEntries; ++j) {
718718
*pX = j;
719719
pY->clear();

tree/ntuple/inc/ROOT/RNTupleWriter.hxx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ class RNTupleWriteOptions;
3939

4040
namespace Experimental {
4141
class RFile;
42-
}
42+
43+
/// Creates an RNTupleWriter that writes into the given `file`, appending to it. The RNTuple is written under the
44+
/// path `ntuplePath`.
45+
/// `ntuplePath` may have the form `"path/to/ntuple"`, in which case the ntuple's name will be `"ntuple"` and it will
46+
/// be stored under the given `ntuplePath` in the RFile.
47+
/// Throws an exception if the model is null.
48+
/// NOTE: this is a temporary, experimental API that will be replaced by an overload of RNTupleWriter::Append in the
49+
/// future.
50+
std::unique_ptr<RNTupleWriter>
51+
RNTupleWriter_Append(std::unique_ptr<ROOT::RNTupleModel> model, std::string_view ntuplePath,
52+
ROOT::Experimental::RFile &file,
53+
const ROOT::RNTupleWriteOptions &options = ROOT::RNTupleWriteOptions());
54+
} // namespace Experimental
4355

4456
namespace Internal {
4557
// Non-public factory method for an RNTuple writer that uses an already constructed page sink
@@ -106,6 +118,9 @@ class RNTupleWriter {
106118
friend ROOT::RNTupleModel::RUpdater;
107119
friend std::unique_ptr<RNTupleWriter>
108120
Internal::CreateRNTupleWriter(std::unique_ptr<ROOT::RNTupleModel>, std::unique_ptr<Internal::RPageSink>);
121+
friend std::unique_ptr<RNTupleWriter>
122+
Experimental::RNTupleWriter_Append(std::unique_ptr<ROOT::RNTupleModel> model, std::string_view ntuplePath,
123+
ROOT::Experimental::RFile &file, const ROOT::RNTupleWriteOptions &options);
109124

110125
private:
111126
RNTupleFillContext fFillContext;
@@ -156,12 +171,6 @@ public:
156171
static std::unique_ptr<RNTupleWriter> Append(std::unique_ptr<ROOT::RNTupleModel> model, std::string_view ntupleName,
157172
TDirectory &fileOrDirectory,
158173
const ROOT::RNTupleWriteOptions &options = ROOT::RNTupleWriteOptions());
159-
/// Throws an exception if the model is null.
160-
/// `ntuplePath` may have the form `"path/to/ntuple"`, in which case the ntuple's name will be `"ntuple"` and it will
161-
/// be stored under the given `ntuplePath` in the RFile.
162-
static std::unique_ptr<RNTupleWriter> Append(std::unique_ptr<ROOT::RNTupleModel> model, std::string_view ntuplePath,
163-
ROOT::Experimental::RFile &file,
164-
const ROOT::RNTupleWriteOptions &options = ROOT::RNTupleWriteOptions());
165174

166175
RNTupleWriter(const RNTupleWriter &) = delete;
167176
RNTupleWriter &operator=(const RNTupleWriter &) = delete;

tree/ntuple/src/RNTupleWriter.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,6 @@ ROOT::RNTupleWriter::Append(std::unique_ptr<ROOT::RNTupleModel> model, std::stri
114114
return Create(std::move(model), std::move(sink), options);
115115
}
116116

117-
std::unique_ptr<ROOT::RNTupleWriter>
118-
ROOT::RNTupleWriter::Append(std::unique_ptr<ROOT::RNTupleModel> model, std::string_view ntupleName,
119-
ROOT::Experimental::RFile &file, const ROOT::RNTupleWriteOptions &options)
120-
{
121-
auto [ntupleDir, ntupleBasename] = ROOT::Experimental::Detail::DecomposePath(ntupleName);
122-
auto sink = std::make_unique<Internal::RPageSinkFile>(ntupleBasename, file, ntupleDir, options);
123-
return Create(std::move(model), std::move(sink), options);
124-
}
125-
126117
void ROOT::RNTupleWriter::CommitClusterGroup()
127118
{
128119
if (GetNEntries() == fLastCommittedClusterGroup)
@@ -155,3 +146,12 @@ ROOT::Internal::CreateRNTupleWriter(std::unique_ptr<ROOT::RNTupleModel> model,
155146
{
156147
return std::unique_ptr<ROOT::RNTupleWriter>(new ROOT::RNTupleWriter(std::move(model), std::move(sink)));
157148
}
149+
150+
std::unique_ptr<ROOT::RNTupleWriter>
151+
ROOT::Experimental::RNTupleWriter_Append(std::unique_ptr<ROOT::RNTupleModel> model, std::string_view ntupleName,
152+
ROOT::Experimental::RFile &file, const ROOT::RNTupleWriteOptions &options)
153+
{
154+
auto [ntupleDir, ntupleBasename] = ROOT::Experimental::Detail::DecomposePath(ntupleName);
155+
auto sink = std::make_unique<ROOT::Internal::RPageSinkFile>(ntupleBasename, file, ntupleDir, options);
156+
return ROOT::RNTupleWriter::Create(std::move(model), std::move(sink), options);
157+
}

0 commit comments

Comments
 (0)