Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:46

0001 /// \file ROOT/RNTupleMerger.hxx
0002 /// \ingroup NTuple ROOT7
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 ROOT7_RNTupleMerger
0017 #define ROOT7_RNTupleMerger
0018 
0019 #include <ROOT/RError.hxx>
0020 #include <ROOT/RNTupleDescriptor.hxx>
0021 #include <ROOT/RNTupleUtil.hxx>
0022 #include <ROOT/RPageStorage.hxx>
0023 
0024 #include <memory>
0025 #include <string>
0026 #include <vector>
0027 #include <unordered_map>
0028 
0029 namespace ROOT {
0030 namespace Experimental {
0031 namespace Internal {
0032 
0033 // clang-format off
0034 /**
0035  * \class ROOT::Experimental::Internal::RNTupleMerger
0036  * \ingroup NTuple
0037  * \brief Given a set of RPageSources merge them into an RPageSink
0038  */
0039 // clang-format on
0040 class RNTupleMerger {
0041 
0042 private:
0043    // Struct to hold column information
0044    struct RColumnInfo {
0045       std::string fColumnName; ///< The qualified field name to which the column belongs, followed by the column index
0046       std::string fColumnTypeAndVersion; ///< "<type>.<version>" of the field to which the column belongs
0047       DescriptorId_t fColumnInputId;
0048       DescriptorId_t fColumnOutputId;
0049 
0050       RColumnInfo(const std::string &name, const std::string &typeAndVersion, const DescriptorId_t &inputId,
0051                   const DescriptorId_t &outputId)
0052          : fColumnName(name), fColumnTypeAndVersion(typeAndVersion), fColumnInputId(inputId), fColumnOutputId(outputId)
0053       {
0054       }
0055    };
0056 
0057    /// Build the internal column id map from the first source
0058    /// This is where we assign the output ids for the first source
0059    void BuildColumnIdMap(std::vector<RColumnInfo> &columns);
0060 
0061    /// Validate the columns against the internal map that is built from the first source
0062    /// This is where we assign the output ids for the remaining sources
0063    void ValidateColumns(std::vector<RColumnInfo> &columns);
0064 
0065    /// Recursively add columns from a given field
0066    void AddColumnsFromField(std::vector<RColumnInfo> &columns, const RNTupleDescriptor &desc,
0067                             const RFieldDescriptor &fieldDesc, const std::string &prefix = "");
0068 
0069    /// Recursively collect all the columns for all the fields rooted at field zero
0070    std::vector<RColumnInfo> CollectColumns(const RNTupleDescriptor &descriptor);
0071 
0072    // Internal map that holds column name, type, and type id : output ID information
0073    std::unordered_map<std::string, DescriptorId_t> fOutputIdMap;
0074 
0075 public:
0076    /// Merge a given set of sources into the destination
0077    void Merge(std::span<RPageSource *> sources, RPageSink &destination);
0078 
0079 }; // end of class RNTupleMerger
0080 
0081 } // namespace Internal
0082 } // namespace Experimental
0083 } // namespace ROOT
0084 
0085 #endif