<commit_before>// Author: <NAME> 09/2020

/*************************************************************************
 * Copyright (C) 1995-2020, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_RDF_COLUMNREADERUTILS
#define ROOT_RDF_COLUMNREADERUTILS

#include "RColumnReaderBase.hxx"
#include "RDefineBase.hxx"
#include "RDefineReader.hxx"
#include "RDSColumnReader.hxx"
#include "RTreeColumnReader.hxx"

#include <ROOT/RDataSource.hxx>
#include <ROOT/TypeTraits.hxx>
#include <TError.h> // R__ASSERT
#include <TTreeReader.h>

#include <array>
#include <map>
#include <memory>
#include <string>
#include <typeinfo> // for typeid
#include <vector>

namespace ROOT {
namespace Internal {
namespace RDF {

using namespace ROOT::TypeTraits;
namespace RDFDetail = ROOT::Detail::RDF;

template <typename T>
std::unique_ptr<RDFDetail::RColumnReaderBase>
MakeColumnReader(unsigned int slot, RDFDetail::RDefineBase *define, TTreeReader *r, ROOT::RDF::RDataSource *ds,
                 const std::vector<void *> *DSValuePtrsPtr, const std::string &colName)
{
   using Ret_t = std::unique_ptr<RDFDetail::RColumnReaderBase>;

   // this check must come first!
   // so that Redefine'd columns have precedence over the original columns
   if (define != nullptr)
      return Ret_t(new RDefineReader(slot, *define, typeid(T)));

   if (DSValuePtrsPtr != nullptr) {
      // reading from a RDataSource with the old column reader interface
      auto &DSValuePtrs = *DSValuePtrsPtr;
      return Ret_t(new RDSColumnReader<T>(DSValuePtrs[slot]));
   }

   if (ds != nullptr) {
      // reading from a RDataSource with the new column reader interface
      return ds->GetColumnReaders(slot, colName, typeid(T));
   }

   // reading from a TTree
   return Ret_t(new RTreeColumnReader<T>(*r, colName));
}

template <typename T>
std::unique_ptr<RDFDetail::RColumnReaderBase>
MakeColumnReadersHelper(unsigned int slot, RDFDetail::RDefineBase *define,
                        const std::map<std::string, std::vector<void *>> &DSValuePtrsMap, TTreeReader *r,
                        ROOT::RDF::RDataSource *ds, const std::string &colName)
{
   const auto DSValuePtrsIt = DSValuePtrsMap.find(colName);
   const std::vector<void *> *DSValuePtrsPtr = DSValuePtrsIt != DSValuePtrsMap.end() ? &DSValuePtrsIt->second : nullptr;
   R__ASSERT(define != nullptr || r != nullptr || DSValuePtrsPtr != nullptr || ds != nullptr);
   return MakeColumnReader<T>(slot, define, r, ds, DSValuePtrsPtr, colName);
}

/// This type aggregates some of the arguments passed to InitColumnReaders.
/// We need to pass a single RColumnReadersInfo object rather than each argument separately because with too many
/// arguments passed, gcc 7.5.0 and cling disagree on the ABI, which leads to the last function argument being read
/// incorrectly from a compiled InitColumnReaders symbols when invoked from a jitted symbol.<commit_msg>[NFC][DF] Fix function name in comments<commit_after>// Author: <NAME> CERN 09/2020

/*************************************************************************
 * Copyright (C) 1995-2020, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_RDF_COLUMNREADERUTILS
#define ROOT_RDF_COLUMNREADERUTILS

#include "RColumnReaderBase.hxx"
#include "RDefineBase.hxx"
#include "RDefineReader.hxx"
#include "RDSColumnReader.hxx"
#include "RTreeColumnReader.hxx"

#include <ROOT/RDataSource.hxx>
#include <ROOT/TypeTraits.hxx>
#include <TError.h> // R__ASSERT
#include <TTreeReader.h>

#include <array>
#include <map>
#include <memory>
#include <string>
#include <typeinfo> // for typeid
#include <vector>

namespace ROOT {
namespace Internal {
namespace RDF {

using namespace ROOT::TypeTraits;
namespace RDFDetail = ROOT::Detail::RDF;

template <typename T>
std::unique_ptr<RDFDetail::RColumnReaderBase>
MakeColumnReader(unsigned int slot, RDFDetail::RDefineBase *define, TTreeReader *r, ROOT::RDF::RDataSource *ds,
                 const std::vector<void *> *DSValuePtrsPtr, const std::string &colName)
{
   using Ret_t = std::unique_ptr<RDFDetail::RColumnReaderBase>;

   // this check must come first!
   // so that Redefine'd columns have precedence over the original columns
   if (define != nullptr)
      return Ret_t(new RDefineReader(slot, *define, typeid(T)));

   if (DSValuePtrsPtr != nullptr) {
      // reading from a RDataSource with the old column reader interface
      auto &DSValuePtrs = *DSValuePtrsPtr;
      return Ret_t(new RDSColumnReader<T>(DSValuePtrs[slot]));
   }

   if (ds != nullptr) {
      // reading from a RDataSource with the new column reader interface
      return ds->GetColumnReaders(slot, colName, typeid(T));
   }

   // reading from a TTree
   return Ret_t(new RTreeColumnReader<T>(*r, colName));
}

template <typename T>
std::unique_ptr<RDFDetail::RColumnReaderBase>
MakeColumnReadersHelper(unsigned int slot, RDFDetail::RDefineBase *define,
                        const std::map<std::string, std::vector<void *>> &DSValuePtrsMap, TTreeReader *r,
                        ROOT::RDF::RDataSource *ds, const std::string &colName)
{
   const auto DSValuePtrsIt = DSValuePtrsMap.find(colName);
   const std::vector<void *> *DSValuePtrsPtr = DSValuePtrsIt != DSValuePtrsMap.end() ? &DSValuePtrsIt->second : nullptr;
   R__ASSERT(define != nullptr || r != nullptr || DSValuePtrsPtr != nullptr || ds != nullptr);
   return MakeColumnReader<T>(slot, define, r, ds, DSValuePtrsPtr, colName);
}

/// This type aggregates some of the arguments passed to MakeColumnReaders.
/// We need to pass a single RColumnReadersInfo object rather than each argument separately because with too many
/// arguments passed, gcc 7.5.0 and cling disagree on the ABI, which leads to the last function argument being read
/// incorrectly from a compiled MakeColumnReaders symbols when invoked from a jitted symbol.
{'fraction_non_alphanumeric': 0.14715310639597007, 'fraction_numerical': 0.0051900473210196914, 'mean_word_length': 3.5786163522012577, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '129025', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1860, 'n_words': 541}