Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:53:05

0001 // Author: Enrico Guiraud CERN 09/2020
0002 
0003 /*************************************************************************
0004  * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOT_RDF_COLUMNREADERUTILS
0012 #define ROOT_RDF_COLUMNREADERUTILS
0013 
0014 #include "RColumnReaderBase.hxx"
0015 #include "RColumnRegister.hxx"
0016 #include "RDefineBase.hxx"
0017 #include "RDefineReader.hxx"
0018 #include "RDSColumnReader.hxx"
0019 #include "RLoopManager.hxx"
0020 #include "RTreeColumnReader.hxx"
0021 #include "RVariationBase.hxx"
0022 #include "RVariationReader.hxx"
0023 
0024 #include <ROOT/RDataSource.hxx>
0025 #include <ROOT/TypeTraits.hxx>
0026 #include <TTreeReader.h>
0027 
0028 #include <array>
0029 #include <cassert>
0030 #include <map>
0031 #include <memory>
0032 #include <string>
0033 #include <typeinfo> // for typeid
0034 #include <vector>
0035 
0036 namespace ROOT {
0037 namespace Internal {
0038 namespace RDF {
0039 
0040 using namespace ROOT::TypeTraits;
0041 namespace RDFDetail = ROOT::Detail::RDF;
0042 
0043 template <typename T>
0044 RDFDetail::RColumnReaderBase *GetColumnReader(unsigned int slot, RColumnReaderBase *defineOrVariationReader,
0045                                               RLoopManager &lm, TTreeReader *r, const std::string &colName)
0046 {
0047    if (defineOrVariationReader != nullptr)
0048       return defineOrVariationReader;
0049 
0050    // Check if we already inserted a reader for this column in the dataset column readers (RDataSource or Tree/TChain
0051    // readers)
0052    auto *datasetColReader = lm.GetDatasetColumnReader(slot, colName, typeid(T));
0053    if (datasetColReader != nullptr)
0054       return datasetColReader;
0055 
0056    assert(r != nullptr && "We could not find a reader for this column, this should never happen at this point.");
0057 
0058    // Make a RTreeColumnReader for this column and insert it in RLoopManager's map
0059    auto treeColReader = std::make_unique<RTreeColumnReader<T>>(*r, colName);
0060    return lm.AddTreeColumnReader(slot, colName, std::move(treeColReader), typeid(T));
0061 }
0062 
0063 /// This type aggregates some of the arguments passed to GetColumnReaders.
0064 /// We need to pass a single RColumnReadersInfo object rather than each argument separately because with too many
0065 /// arguments passed, gcc 7.5.0 and cling disagree on the ABI, which leads to the last function argument being read
0066 /// incorrectly from a compiled GetColumnReaders symbols when invoked from a jitted symbol.
0067 struct RColumnReadersInfo {
0068    const std::vector<std::string> &fColNames;
0069    RColumnRegister &fColRegister;
0070    const bool *fIsDefine;
0071    RLoopManager &fLoopManager;
0072 };
0073 
0074 /// Create a group of column readers, one per type in the parameter pack.
0075 template <typename... ColTypes>
0076 std::array<RDFDetail::RColumnReaderBase *, sizeof...(ColTypes)>
0077 GetColumnReaders(unsigned int slot, TTreeReader *r, TypeList<ColTypes...>, const RColumnReadersInfo &colInfo,
0078                  const std::string &variationName = "nominal")
0079 {
0080    // see RColumnReadersInfo for why we pass these arguments like this rather than directly as function arguments
0081    const auto &colNames = colInfo.fColNames;
0082    auto &lm = colInfo.fLoopManager;
0083    auto &colRegister = colInfo.fColRegister;
0084 
0085    int i = -1;
0086    std::array<RDFDetail::RColumnReaderBase *, sizeof...(ColTypes)> ret{
0087       (++i, GetColumnReader<ColTypes>(slot, colRegister.GetReader(slot, colNames[i], variationName, typeid(ColTypes)),
0088                                       lm, r, colNames[i]))...};
0089    return ret;
0090 }
0091 
0092 // Shortcut overload for the case of no columns
0093 inline std::array<RDFDetail::RColumnReaderBase *, 0>
0094 GetColumnReaders(unsigned int, TTreeReader *, TypeList<>, const RColumnReadersInfo &, const std::string & = "nominal")
0095 {
0096    return {};
0097 }
0098 
0099 } // namespace RDF
0100 } // namespace Internal
0101 } // namespace ROOT
0102 
0103 #endif // ROOT_RDF_COLUMNREADERS