Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:48

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    unsigned int fNSlots = 0U;
0029    ULong64_t fSize = 0ULL;
0030    bool fSkipEvenEntries = false;
0031    std::vector<std::pair<ULong64_t, ULong64_t>> fEntryRanges;
0032    std::vector<std::string> fColNames{"col0"};
0033    std::vector<ULong64_t> fCounter;
0034    std::vector<ULong64_t *> fCounterAddr;
0035    std::vector<void *> GetColumnReadersImpl(std::string_view name, const std::type_info &) final;
0036 
0037 protected:
0038    std::string AsString() final { return "trivial data source"; };
0039 
0040 public:
0041    RTrivialDS(ULong64_t size, bool skipEvenEntries = false);
0042    /// This ctor produces a data-source that returns infinite entries
0043    RTrivialDS();
0044    ~RTrivialDS();
0045    const std::vector<std::string> &GetColumnNames() const final;
0046    bool HasColumn(std::string_view colName) const final;
0047    std::string GetTypeName(std::string_view) const final;
0048    std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() final;
0049    bool SetEntry(unsigned int slot, ULong64_t entry) final;
0050    void SetNSlots(unsigned int nSlots) final;
0051    void Initialize() final;
0052    std::string GetLabel() final;
0053 };
0054 
0055 /// \brief Make a RDF wrapping a RTrivialDS with the specified amount of entries.
0056 ///
0057 /// Constructing an RDataFrame as `RDataFrame(nEntries)` is a superior alternative.
0058 /// If size is std::numeric_limits<ULong64_t>::max(), this acts as an infinite data-source:
0059 /// it returns entries from GetEntryRanges forever or until a Range stops the event loop (for test purposes).
0060 RInterface<RDFDetail::RLoopManager> MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries = false);
0061 /// \brief Make a RDF wrapping a RTrivialDS with infinite entries, for demo purposes.
0062 RInterface<RDFDetail::RLoopManager> MakeTrivialDataFrame();
0063 
0064 } // ns RDF
0065 
0066 } // ns ROOT
0067 
0068 #endif