Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/ROOT/RTrivialDS.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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