Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleMerger.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleMerger.hxx
2/// \author Jakob Blomer <jblomer@cern.ch>, Max Orok <maxwellorok@gmail.com>, Alaettin Serhan Mete <amete@anl.gov>
3/// \date 2020-07-08
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/*************************************************************************
8 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
15#ifndef ROOT_RNTupleMerger
16#define ROOT_RNTupleMerger
17
18#include <ROOT/RError.hxx>
20#include <ROOT/RNTupleTypes.hxx>
21#include <ROOT/RPageStorage.hxx>
22#include <ROOT/TTaskGroup.hxx>
23#include <Compression.h>
24
25#include <memory>
26#include <optional>
27
28namespace ROOT {
29
30class REntry;
31class RNTuple;
32
33namespace Internal {
34
35class RPageSource;
36class RNTupleMergeStrategySlow;
37struct RNTupleSlowMergeData;
38
40 /// The merger will discard all columns that aren't present in the prototype model (i.e. the model of the first
41 /// source); also all subsequent RNTuples must contain at least all the columns that are present in the prototype
42 /// model
43 kFilter,
44 /// The merger will refuse to merge any 2 RNTuples whose schema doesn't match exactly
45 kStrict,
46 /// The merger will update the output model to include all columns from all sources. Entries corresponding to columns
47 /// that are not present in a source will be set to the default value of the type.
48 kUnion
49};
50
51inline const char *ToString(ENTupleMergingMode mode)
52{
53 static const char *const kMergingModeStr[] = {"Filter", "Strict", "Union"};
54 return kMergingModeStr[static_cast<int>(mode)];
55}
56
58 /// The merger will abort merging as soon as an error is encountered
59 kAbort,
60 /// Upon errors, the merger will skip the current source and continue
61 kSkip
62};
63
65 /// The merger will emit a warning when merging RNTuples with higher version than the latest supported by this
66 /// ROOT version, but merging will work. Some optional features present in the source(s) may be missing from the
67 /// merged RNTuple.
69 /// The merger will refuse to merge RNTuples with higher versions than the latest supported by this ROOT version.
70 /// The merging process will abort as soon as one such source is encountered.
72};
73
74/// Set of merging options to pass to RNTupleMerger.
75/// If you're using the merger through TFileMerger you need to give it string-based options instead.
76/// Here is the mapping for the TFileMerger options:
77/// - "rntuple.MergingMode=(Filter|Union|...)" -> sets fMergingMode
78/// - "rntuple.ErrBehavior=(Abort|Skip|...)" -> sets fErrBehavior
79/// - "rntuple.VersionBehavior=(WarnOnHigherVersion|AbortOnHigherVersion|...)" -> sets fVersionBehavior
80/// - "rntuple.ExtraVerbose" -> sets fExtraVerbose to true
81/// Rules about the string-based options:
82/// 1. there must be no space between the separators (i.e. `.` and `=`)
83/// 2. all string matching is case insensitive
85 /// If fCompressionSettings is empty (the default), the merger will not change the
86 /// compression of any of its sources (fast merging). Otherwise, all sources will be converted to the specified
87 /// compression algorithm and level.
88 std::optional<std::uint32_t> fCompressionSettings;
89 /// Determines how the merging treats sources with different models (\see ENTupleMergingMode).
91 /// Determines how the Merge function behaves upon merging errors
93 /// Determines how the Merge function behaves depending on the RNTuple sources' version.
95 /// If true, the merger will emit further diagnostics and information.
96 bool fExtraVerbose = false;
97};
98
99/// Information regarding the current slow merge process that gets passed to the RNTupleMergeActions
104
106 // Don't emit this entry
107 kDrop,
108 // Emit this entry, then continue
109 kEmit,
110 // Emit this entry, then call the function again
112};
113
114// clang-format off
115/**
116 * \class ROOT::Experimental::Internal::RNTupleMergeActions
117 * \ingroup NTuple
118 * \brief Container for callbacks that are invoked during the "slow merge" process.
119 * This allows customizing how the merging happens entry-by-entry, enabling things like dropping individual
120 * entries from the destination RNTuple, modifying their values on the fly or creating new entries artificially.
121 */
122// clang-format on
124public:
126 virtual ~RNTupleMergeActions() = default;
127
132
133 /// Invoked every time an entry is merged from a source RNTuple to the destination RNTuple.
138
139 // Invoked at the end of each source's merging process.
144
145 /// Invoked at the end of the merge process, right before committing the dataset.
146 /// This allows appending more entries at the end of the merge.
151};
152
153// clang-format off
154/**
155 * \class ROOT::Internal::RNTupleMerger
156 * \ingroup NTuple
157 * \brief Given a set of RPageSources merge them into an RPagePersistentSink, optionally changing their compression.
158 * This can also be used to change the compression of a single RNTuple by just passing a single source.
159 */
160// clang-format on
161class RNTupleMerger final {
162 friend class ROOT::RNTuple;
163
164 std::unique_ptr<ROOT::Internal::RPagePersistentSink> fDestination;
165 std::unique_ptr<ROOT::RNTupleModel> fModel;
166
167 /// Creates a RNTupleMerger with the given destination.
168 /// The model must be given if and only if `destination` has been initialized with that model
169 /// (i.e. in case of incremental merging).
170 RNTupleMerger(std::unique_ptr<ROOT::Internal::RPagePersistentSink> destination,
171 std::unique_ptr<ROOT::RNTupleModel> model);
172
173public:
174 /// Creates a RNTupleMerger with the given destination.
175 explicit RNTupleMerger(std::unique_ptr<ROOT::Internal::RPagePersistentSink> destination);
176
177 /// Merge a given set of sources into the destination.
178 /// Note that sources with an empty schema (i.e. created from a Model that had no fields added to it) are in
179 /// general valid (depending on the merging mode) but add no entries to the destination.
180 RResult<void> Merge(std::span<ROOT::Internal::RPageSource *> sources,
181 const RNTupleMergeOptions &mergeOpts = RNTupleMergeOptions());
182
183}; // end of class RNTupleMerger
184
185} // namespace Internal
186} // namespace ROOT
187
188#endif
Option_t Option_t TPoint TPoint const char mode
RNTupleMergeActions & operator=(const RNTupleMergeActions &)=delete
virtual ENTupleMergeActionResult OnFill(ROOT::REntry &, const RNTupleMergeActionContext &)
Invoked every time an entry is merged from a source RNTuple to the destination RNTuple.
RNTupleMergeActions(RNTupleMergeActions &&)=default
RNTupleMergeActions(const RNTupleMergeActions &)=delete
RNTupleMergeActions & operator=(RNTupleMergeActions &&)=default
virtual ENTupleMergeActionResult OnSourceEnd(ROOT::REntry &, const RNTupleMergeActionContext &)
virtual ENTupleMergeActionResult BeforeCommit(ROOT::REntry &, const RNTupleMergeActionContext &)
Invoked at the end of the merge process, right before committing the dataset.
virtual ~RNTupleMergeActions()=default
Given a set of RPageSources merge them into an RPagePersistentSink, optionally changing their compres...
std::unique_ptr< ROOT::RNTupleModel > fModel
RNTupleMerger(std::unique_ptr< ROOT::Internal::RPagePersistentSink > destination, std::unique_ptr< ROOT::RNTupleModel > model)
Creates a RNTupleMerger with the given destination.
std::unique_ptr< ROOT::Internal::RPagePersistentSink > fDestination
RResult< void > Merge(std::span< ROOT::Internal::RPageSource * > sources, const RNTupleMergeOptions &mergeOpts=RNTupleMergeOptions())
Merge a given set of sources into the destination.
The REntry is a collection of values in an RNTuple corresponding to a complete row in the data set.
Definition REntry.hxx:58
Representation of an RNTuple data set in a ROOT file.
Definition RNTuple.hxx:67
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
Definition RError.hxx:222
@ kAbortOnHigherVersion
The merger will refuse to merge RNTuples with higher versions than the latest supported by this ROOT ...
@ kWarnOnHigherVersion
The merger will emit a warning when merging RNTuples with higher version than the latest supported by...
const char * ToString(ENTupleMergingMode mode)
@ kAbort
The merger will abort merging as soon as an error is encountered.
@ kSkip
Upon errors, the merger will skip the current source and continue.
@ kStrict
The merger will refuse to merge any 2 RNTuples whose schema doesn't match exactly.
@ kUnion
The merger will update the output model to include all columns from all sources.
@ kFilter
The merger will discard all columns that aren't present in the prototype model (i....
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Information regarding the current slow merge process that gets passed to the RNTupleMergeActions.
Set of merging options to pass to RNTupleMerger.
ENTupleMergeVersionBehavior fVersionBehavior
Determines how the Merge function behaves depending on the RNTuple sources' version.
bool fExtraVerbose
If true, the merger will emit further diagnostics and information.
std::optional< std::uint32_t > fCompressionSettings
If fCompressionSettings is empty (the default), the merger will not change the compression of any of ...
ENTupleMergingMode fMergingMode
Determines how the merging treats sources with different models (.
ENTupleMergeErrBehavior fErrBehavior
Determines how the Merge function behaves upon merging errors.