Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 09:08:36

0001 // Author: Enrico Guiraud, Danilo Piparo CERN  9/2017
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_RTRIVIALTDS
0012 #define ROOT_RTRIVIALTDS
0013 
0014 #include "ROOT/RDF/RInterface.hxx"
0015 #include "ROOT/RDataSource.hxx"
0016 
0017 namespace ROOT {
0018 
0019 namespace RDF {
0020 
0021 /// \brief A simple data-source implementation, for demo purposes.
0022 ///
0023 /// Constructing an RDataFrame as `RDataFrame(nEntries)` is a superior alternative.
0024 /// If size is std::numeric_limits<ULong64_t>::max(), this acts as an infinite data-source:
0025 /// it returns entries from GetEntryRanges forever or until a Range stops the event loop (for test purposes).
0026 class RTrivialDS final : public ROOT::RDF::RDataSource {
0027 private:
0028    ULong64_t fSize = 0ULL;
0029    bool fSkipEvenEntries = false;
0030    std::vector<std::pair<ULong64_t, ULong64_t>> fEntryRanges;
0031    std::vector<std::string> fColNames{"col0"};
0032    std::vector<ULong64_t> fCounter;
0033    std::vector<ULong64_t *> fCounterAddr;
0034    std::vector<void *> GetColumnReadersImpl(std::string_view name, const std::type_info &) final;
0035 
0036 protected:
0037    std::string AsString() final { return "trivial data source"; };
0038 
0039 public:
0040    RTrivialDS(ULong64_t size, bool skipEvenEntries = false);
0041    /// This ctor produces a data-source that returns infinite entries
0042    RTrivialDS();
0043    // Rule of five
0044    RTrivialDS(const RTrivialDS &) = delete;
0045    RTrivialDS &operator=(const RTrivialDS &) = delete;
0046    RTrivialDS(RTrivialDS &&) = delete;
0047    RTrivialDS &operator=(RTrivialDS &&) = delete;
0048    ~RTrivialDS() final = default;
0049 
0050    const std::vector<std::string> &GetColumnNames() const final;
0051    bool HasColumn(std::string_view colName) const final;
0052    std::string GetTypeName(std::string_view) const final;
0053    std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() final;
0054    bool SetEntry(unsigned int slot, ULong64_t entry) final;
0055    void SetNSlots(unsigned int nSlots) final;
0056    void Initialize() final;
0057    std::string GetLabel() final;
0058 };
0059 
0060 /// \brief Make a RDF wrapping a RTrivialDS with the specified amount of entries.
0061 ///
0062 /// Constructing an RDataFrame as `RDataFrame(nEntries)` is a superior alternative.
0063 /// If size is std::numeric_limits<ULong64_t>::max(), this acts as an infinite data-source:
0064 /// it returns entries from GetEntryRanges forever or until a Range stops the event loop (for test purposes).
0065 RInterface<RDFDetail::RLoopManager> MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries = false);
0066 /// \brief Make a RDF wrapping a RTrivialDS with infinite entries, for demo purposes.
0067 RInterface<RDFDetail::RLoopManager> MakeTrivialDataFrame();
0068 
0069 } // ns RDF
0070 
0071 } // ns ROOT
0072 
0073 #endif