|
|
|||
File indexing completed on 2025-12-16 10:30:00
0001 /// \file ROOT/RNTupleMerger.hxx 0002 /// \ingroup NTuple 0003 /// \author Jakob Blomer <jblomer@cern.ch>, Max Orok <maxwellorok@gmail.com>, Alaettin Serhan Mete <amete@anl.gov> 0004 /// \date 2020-07-08 0005 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback 0006 /// is welcome! 0007 0008 /************************************************************************* 0009 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. * 0010 * All rights reserved. * 0011 * * 0012 * For the licensing terms see $ROOTSYS/LICENSE. * 0013 * For the list of contributors see $ROOTSYS/README/CREDITS. * 0014 *************************************************************************/ 0015 0016 #ifndef ROOT_RNTupleMerger 0017 #define ROOT_RNTupleMerger 0018 0019 #include <ROOT/RError.hxx> 0020 #include <ROOT/RNTupleDescriptor.hxx> 0021 #include <ROOT/RNTupleTypes.hxx> 0022 #include <ROOT/RPageStorage.hxx> 0023 #include <ROOT/TTaskGroup.hxx> 0024 #include <Compression.h> 0025 0026 #include <memory> 0027 #include <optional> 0028 0029 namespace ROOT { 0030 0031 class RNTuple; 0032 0033 namespace Internal { 0034 class RPageAllocator; 0035 class RClusterPool; 0036 } // namespace Internal 0037 0038 namespace Experimental::Internal { 0039 0040 enum class ENTupleMergingMode { 0041 /// The merger will discard all columns that aren't present in the prototype model (i.e. the model of the first 0042 /// source); also all subsequent RNTuples must contain at least all the columns that are present in the prototype 0043 /// model 0044 kFilter, 0045 /// The merger will refuse to merge any 2 RNTuples whose schema doesn't match exactly 0046 kStrict, 0047 /// The merger will update the output model to include all columns from all sources. Entries corresponding to columns 0048 /// that are not present in a source will be set to the default value of the type. 0049 kUnion 0050 }; 0051 0052 inline const char *ToString(ENTupleMergingMode mode) 0053 { 0054 static const char *const kMergingModeStr[] = {"Filter", "Strict", "Union"}; 0055 return kMergingModeStr[static_cast<int>(mode)]; 0056 } 0057 0058 enum class ENTupleMergeErrBehavior { 0059 /// The merger will abort merging as soon as an error is encountered 0060 kAbort, 0061 /// Upon errors, the merger will skip the current source and continue 0062 kSkip 0063 }; 0064 0065 struct RColumnMergeInfo; 0066 struct RNTupleMergeData; 0067 struct RSealedPageMergeData; 0068 0069 /// Set of merging options to pass to RNTupleMerger. 0070 /// If you're using the merger through TFileMerger you need to give it string-based options instead. 0071 /// Here is the mapping for the TFileMerger options: 0072 /// - "rntuple.MergingMode=(Filter|Union|...)" -> sets fMergingMode 0073 /// - "rntuple.ErrBehavior=(Abort|Skip|...)" -> sets fErrBehavior 0074 /// - "rntuple.ExtraVerbose" -> sets fExtraVerbose to true 0075 /// Rules about the string-based options: 0076 /// 1. there must be no space between the separators (i.e. `.` and `=`) 0077 /// 2. all string matching is case insensitive 0078 struct RNTupleMergeOptions { 0079 /// If fCompressionSettings is empty (the default), the merger will not change the 0080 /// compression of any of its sources (fast merging). Otherwise, all sources will be converted to the specified 0081 /// compression algorithm and level. 0082 std::optional<std::uint32_t> fCompressionSettings; 0083 /// Determines how the merging treats sources with different models (\see ENTupleMergingMode). 0084 ENTupleMergingMode fMergingMode = ENTupleMergingMode::kFilter; 0085 /// Determines how the Merge function behaves upon merging errors 0086 ENTupleMergeErrBehavior fErrBehavior = ENTupleMergeErrBehavior::kAbort; 0087 /// If true, the merger will emit further diagnostics and information. 0088 bool fExtraVerbose = false; 0089 }; 0090 0091 // clang-format off 0092 /** 0093 * \class ROOT::Experimental::Internal::RNTupleMerger 0094 * \ingroup NTuple 0095 * \brief Given a set of RPageSources merge them into an RPagePersistentSink, optionally changing their compression. 0096 * This can also be used to change the compression of a single RNTuple by just passing a single source. 0097 */ 0098 // clang-format on 0099 class RNTupleMerger final { 0100 friend class ROOT::RNTuple; 0101 0102 std::unique_ptr<ROOT::Internal::RPagePersistentSink> fDestination; 0103 std::unique_ptr<ROOT::Internal::RPageAllocator> fPageAlloc; 0104 std::optional<TTaskGroup> fTaskGroup; 0105 std::unique_ptr<ROOT::RNTupleModel> fModel; 0106 0107 [[nodiscard]] 0108 ROOT::RResult<void> MergeCommonColumns(ROOT::Internal::RClusterPool &clusterPool, 0109 const ROOT::RClusterDescriptor &clusterDesc, 0110 std::span<const RColumnMergeInfo> commonColumns, 0111 const ROOT::Internal::RCluster::ColumnSet_t &commonColumnSet, 0112 std::size_t nCommonColumnsInCluster, RSealedPageMergeData &sealedPageData, 0113 const RNTupleMergeData &mergeData, ROOT::Internal::RPageAllocator &pageAlloc); 0114 0115 [[nodiscard]] 0116 ROOT::RResult<void> 0117 MergeSourceClusters(ROOT::Internal::RPageSource &source, std::span<const RColumnMergeInfo> commonColumns, 0118 std::span<const RColumnMergeInfo> extraDstColumns, RNTupleMergeData &mergeData); 0119 0120 /// Creates a RNTupleMerger with the given destination. 0121 /// The model must be given if and only if `destination` has been initialized with that model 0122 /// (i.e. in case of incremental merging). 0123 RNTupleMerger(std::unique_ptr<ROOT::Internal::RPagePersistentSink> destination, 0124 std::unique_ptr<ROOT::RNTupleModel> model); 0125 0126 public: 0127 /// Creates a RNTupleMerger with the given destination. 0128 explicit RNTupleMerger(std::unique_ptr<ROOT::Internal::RPagePersistentSink> destination); 0129 0130 /// Merge a given set of sources into the destination. 0131 /// Note that sources with an empty schema (i.e. created from a Model that had no fields added to it) are in 0132 /// general valid (depending on the merging mode) but add no entries to the destination. 0133 RResult<void> Merge(std::span<ROOT::Internal::RPageSource *> sources, 0134 const RNTupleMergeOptions &mergeOpts = RNTupleMergeOptions()); 0135 0136 }; // end of class RNTupleMerger 0137 0138 } // namespace Experimental::Internal 0139 } // namespace ROOT 0140 0141 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|