Back to home page

EIC code displayed by LXR

 
 

    


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

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_RDEFINEREADER
0012 #define ROOT_RDF_RDEFINEREADER
0013 
0014 #include "RColumnReaderBase.hxx"
0015 #include "RDefineBase.hxx"
0016 #include "Utils.hxx"
0017 #include <Rtypes.h>  // Long64_t, R__CLING_PTRCHECK
0018 
0019 #include <limits>
0020 #include <type_traits>
0021 
0022 #include <memory>
0023 #include <string>
0024 #include <string_view>
0025 #include <unordered_map>
0026 #include <unordered_set>
0027 
0028 namespace ROOT {
0029 namespace Internal {
0030 namespace RDF {
0031 
0032 namespace RDFDetail = ROOT::Detail::RDF;
0033 
0034 /// Column reader for defined columns.
0035 class R__CLING_PTRCHECK(off) RDefineReader final : public ROOT::Detail::RDF::RColumnReaderBase {
0036    /// Non-owning reference to the node responsible for the defined column.
0037    RDFDetail::RDefineBase &fDefine;
0038 
0039    /// Non-owning ptr to the defined value.
0040    void *fValuePtr = nullptr;
0041 
0042    /// The slot this value belongs to.
0043    unsigned int fSlot = std::numeric_limits<unsigned int>::max();
0044 
0045    void *GetImpl(Long64_t entry) final
0046    {
0047       fDefine.Update(fSlot, entry);
0048       return fValuePtr;
0049    }
0050 
0051 public:
0052    RDefineReader(unsigned int slot, RDFDetail::RDefineBase &define)
0053       : fDefine(define), fValuePtr(define.GetValuePtr(slot)), fSlot(slot)
0054    {
0055    }
0056 };
0057 
0058 /// A helper type that keeps track of RDefine objects and their corresponding RDefineReaders.
0059 class RDefinesWithReaders {
0060 
0061    // this is a shared_ptr only because we have to track its lifetime with a weak_ptr that we pass to jitted code
0062    // (see BookDefineJit). it is never null.
0063    std::shared_ptr<ROOT::Detail::RDF::RDefineBase> fDefine;
0064    // Column readers per variation (in the map) per slot (in the vector).
0065    std::vector<std::unordered_map<std::string_view, std::unique_ptr<RDefineReader>>> fReadersPerVariation;
0066 
0067    // Strings that were already used to represent column names in this RDataFrame instance.
0068    ROOT::Internal::RDF::RStringCache &fCachedColNames;
0069 
0070 public:
0071    RDefinesWithReaders(std::shared_ptr<ROOT::Detail::RDF::RDefineBase> define, unsigned int nSlots,
0072                        ROOT::Internal::RDF::RStringCache &cachedColNames);
0073    ROOT::Detail::RDF::RDefineBase &GetDefine() const { return *fDefine; }
0074    ROOT::Internal::RDF::RDefineReader &GetReader(unsigned int slot, std::string_view variationName);
0075 };
0076 
0077 } // namespace RDF
0078 } // namespace Internal
0079 }
0080 
0081 #endif