File indexing completed on 2025-01-18 10:10:35
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
0041 void ThrowIfNoSample() const
0042 {
0043 if (fSample == nullptr) {
0044 const auto msg = "RSampleInfo: sample data was requested but no samples are available.";
0045 throw std::logic_error(msg);
0046 }
0047 }
0048
0049 public:
0050 RSampleInfo(std::string_view id, std::pair<ULong64_t, ULong64_t> entryRange,
0051 const ROOT::RDF::Experimental::RSample *sample = nullptr)
0052 : fID(id), fEntryRange(entryRange), fSample(sample)
0053 {
0054 }
0055 RSampleInfo() = default;
0056 RSampleInfo(const RSampleInfo &) = default;
0057 RSampleInfo &operator=(const RSampleInfo &) = default;
0058 RSampleInfo(RSampleInfo &&) = default;
0059 RSampleInfo &operator=(RSampleInfo &&) = default;
0060 ~RSampleInfo() = default;
0061
0062
0063 const std::string &GetSampleName() const
0064 {
0065 ThrowIfNoSample();
0066 return fSample->GetSampleName();
0067 }
0068
0069
0070 unsigned int GetSampleId() const
0071 {
0072 ThrowIfNoSample();
0073 return fSample->GetSampleId();
0074 }
0075
0076
0077 int GetI(const std::string &key) const
0078 {
0079 ThrowIfNoSample();
0080 return fSample->GetMetaData().GetI(key);
0081 }
0082
0083
0084 double GetD(const std::string &key) const
0085 {
0086 ThrowIfNoSample();
0087 return fSample->GetMetaData().GetD(key);
0088 }
0089
0090
0091 std::string GetS(const std::string &key) const
0092 {
0093 ThrowIfNoSample();
0094 return fSample->GetMetaData().GetS(key);
0095 }
0096
0097
0098 bool Contains(std::string_view substr) const
0099 {
0100
0101 return fID.find(std::string(substr)) != std::string::npos;
0102 }
0103
0104
0105
0106
0107 bool Empty() const {
0108 return fID.empty();
0109 }
0110
0111
0112
0113
0114 const std::string &AsString() const
0115 {
0116 return fID;
0117 }
0118
0119
0120
0121
0122 std::pair<ULong64_t, ULong64_t> EntryRange() const { return fEntryRange; }
0123
0124
0125 ULong64_t NEntries() const { return fEntryRange.second - fEntryRange.first; }
0126
0127 bool operator==(const RSampleInfo &other) const { return fID == other.fID; }
0128 bool operator!=(const RSampleInfo &other) const { return !(*this == other); }
0129 };
0130
0131
0132
0133
0134 using SampleCallback_t = std::function<void(unsigned int, const ROOT::RDF::RSampleInfo &)>;
0135
0136 }
0137 }
0138
0139 #endif