Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:50

0001 // Author: Enrico Guiraud, Danilo Piparo CERN  09/2018
0002 
0003 /*************************************************************************
0004  * Copyright (C) 1995-2018, 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_RJITTEDDEFINE
0012 #define ROOT_RJITTEDDEFINE
0013 
0014 #include "ROOT/RDF/RDefineBase.hxx"
0015 #include "ROOT/RDF/RSampleInfo.hxx"
0016 #include "ROOT/RDF/Utils.hxx" // TypeName2TypeID
0017 #include <string_view>
0018 #include "RtypesCore.h"
0019 
0020 #include <memory>
0021 #include <stdexcept>
0022 #include <string>
0023 #include <typeinfo>
0024 #include <vector>
0025 
0026 class TTreeReader;
0027 
0028 namespace ROOT {
0029 namespace Detail {
0030 namespace RDF {
0031 
0032 /// A wrapper around a concrete RDefine, which forwards all calls to it
0033 /// RJittedDefine is a placeholder that is put in the collection of custom columns in place of a RDefine
0034 /// that will be just-in-time compiled. Jitted code will assign the concrete RDefine to this RJittedDefine
0035 /// before the event-loop starts.
0036 class RJittedDefine : public RDefineBase {
0037    std::unique_ptr<RDefineBase> fConcreteDefine = nullptr;
0038    /// Type info obtained through TypeName2TypeID based on the column type name.
0039    /// The expectation is that this always compares equal to fConcreteDefine->GetTypeId() (which however is only
0040    /// available after jitting). It can be null if TypeName2TypeID failed to figure out this type.
0041    const std::type_info *fTypeId = nullptr;
0042 
0043 public:
0044    RJittedDefine(std::string_view name, std::string_view type, RLoopManager &lm,
0045                  const RDFInternal::RColumnRegister &colRegister, const ColumnNames_t &columns)
0046       : RDefineBase(name, type, colRegister, lm, columns)
0047    {
0048       // try recovering the type_info of this type, no problem if we fail (as long as no one calls GetTypeId)
0049       try {
0050          fTypeId = &RDFInternal::TypeName2TypeID(std::string(type));
0051       } catch (const std::runtime_error &) {
0052       }
0053    }
0054    ~RJittedDefine();
0055 
0056    void SetDefine(std::unique_ptr<RDefineBase> c) { fConcreteDefine = std::move(c); }
0057 
0058    void InitSlot(TTreeReader *r, unsigned int slot) final;
0059    void *GetValuePtr(unsigned int slot) final;
0060    const std::type_info &GetTypeId() const final;
0061    void Update(unsigned int slot, Long64_t entry) final;
0062    void Update(unsigned int slot, const ROOT::RDF::RSampleInfo &id) final;
0063    void FinalizeSlot(unsigned int slot) final;
0064    void MakeVariations(const std::vector<std::string> &variations) final;
0065    RDefineBase &GetVariedDefine(const std::string &variationName) final;
0066 };
0067 
0068 } // ns RDF
0069 } // ns Detail
0070 } // ns ROOT
0071 
0072 #endif // ROOT_RJITTEDDEFINE