File indexing completed on 2026-09-21 09:25:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ROOT_RDF_RSAMPLEINFO
0012 #define ROOT_RDF_RSAMPLEINFO
0013
0014 #include <ROOT/RDF/RSample.hxx>
0015 #include <string_view>
0016 #include <Rtypes.h>
0017
0018 #include <functional>
0019 #include <stdexcept>
0020 #include <string>
0021
0022 #include <tuple>
0023
0024 namespace ROOT {
0025 namespace RDF {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 class RSampleInfo {
0036 std::string fID;
0037 std::pair<ULong64_t, ULong64_t> fEntryRange;
0038
0039 const ROOT::RDF::Experimental::RSample *fSample = nullptr;
0040 ULong64_t fTotalEntries = 0;
0041
0042 void ThrowIfNoSample() const
0043 {
0044 if (fSample == nullptr) {
0045 const auto msg = "RSampleInfo: sample data was requested but no samples are available.";
0046 throw std::logic_error(msg);
0047 }
0048 }
0049
0050 public:
0051 RSampleInfo(std::string_view id, std::pair<ULong64_t, ULong64_t> entryRange,
0052 const ROOT::RDF::Experimental::RSample *sample = nullptr, ULong64_t totalEntries = 0)
0053 : fID(id), fEntryRange(entryRange), fSample(sample), fTotalEntries{totalEntries}
0054 {
0055 }
0056 RSampleInfo() = default;
0057 RSampleInfo(const RSampleInfo &) = default;
0058 RSampleInfo &operator=(const RSampleInfo &) = default;
0059 RSampleInfo(RSampleInfo &&) = default;
0060 RSampleInfo &operator=(RSampleInfo &&) = default;
0061 ~RSampleInfo() = default;
0062
0063
0064 const std::string &GetSampleName() const
0065 {
0066 ThrowIfNoSample();
0067 return fSample->GetSampleName();
0068 }
0069
0070
0071 unsigned int GetSampleId() const
0072 {
0073 ThrowIfNoSample();
0074 return fSample->GetSampleId();
0075 }
0076
0077
0078 int GetI(const std::string &key) const
0079 {
0080 ThrowIfNoSample();
0081 return fSample->GetMetaData().GetI(key);
0082 }
0083
0084
0085 double GetD(const std::string &key) const
0086 {
0087 ThrowIfNoSample();
0088 return fSample->GetMetaData().GetD(key);
0089 }
0090
0091
0092 std::string GetS(const std::string &key) const
0093 {
0094 ThrowIfNoSample();
0095 return fSample->GetMetaData().GetS(key);
0096 }
0097
0098
0099 bool Contains(std::string_view substr) const
0100 {
0101
0102 return fID.find(std::string(substr)) != std::string::npos;
0103 }
0104
0105
0106
0107
0108 bool Empty() const {
0109 return fID.empty();
0110 }
0111
0112
0113
0114
0115 const std::string &AsString() const
0116 {
0117 return fID;
0118 }
0119
0120
0121
0122
0123 std::pair<ULong64_t, ULong64_t> EntryRange() const { return fEntryRange; }
0124
0125
0126 ULong64_t NEntries() const { return fEntryRange.second - fEntryRange.first; }
0127
0128
0129
0130
0131 ULong64_t NEntriesTotal() const { return std::max(fTotalEntries, fEntryRange.second); }
0132
0133 bool operator==(const RSampleInfo &other) const { return fID == other.fID; }
0134 bool operator!=(const RSampleInfo &other) const { return !(*this == other); }
0135 };
0136
0137
0138
0139
0140 using SampleCallback_t = std::function<void(unsigned int, const ROOT::RDF::RSampleInfo &)>;
0141
0142 }
0143 }
0144
0145 #endif