Logo ROOT  
Reference Guide
RSampleInfo.hxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, 2021
2
3/*************************************************************************
4 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_RDF_RSAMPLEINFO
12#define ROOT_RDF_RSAMPLEINFO
13
15#include <ROOT/RStringView.hxx>
16#include <Rtypes.h>
17
18#include <functional>
19#include <stdexcept>
20#include <string>
21
22#include <tuple>
23
24namespace ROOT {
25namespace RDF {
26
27/// This type represents a sample identifier, to be used in conjunction with RDataFrame features such as
28/// DefinePerSample() and per-sample callbacks.
29///
30/// When the input data comes from a TTree, the string representation of RSampleInfo (which is returned by AsString()
31/// and that can be queried e.g. with Contains()) is of the form "<filename>/<treename>".
32///
33/// In multi-thread runs, different tasks might process different entry ranges of the same sample,
34/// so RSampleInfo also provides methods to inspect which part of a sample is being taken into consideration.
36 std::string fID;
37 std::pair<ULong64_t, ULong64_t> fEntryRange;
38
40
41public:
42 RSampleInfo(std::string_view id, std::pair<ULong64_t, ULong64_t> entryRange,
43 const ROOT::RDF::Experimental::RDatasetGroup &datasetGroup = {"", "", ""})
44 : fID(id), fEntryRange(entryRange), fDatasetGroup(datasetGroup)
45 {
46 }
47 RSampleInfo() = default;
48 RSampleInfo(const RSampleInfo &) = default;
49 RSampleInfo &operator=(const RSampleInfo &) = default;
50 RSampleInfo(RSampleInfo &&) = default;
52 ~RSampleInfo() = default;
53
54 const std::string &GetGroupName() const { return fDatasetGroup.GetGroupName(); }
55
56 unsigned int GetGroupId() const { return fDatasetGroup.GetGroupId(); }
57
58 int GetI(const std::string &key) const { return fDatasetGroup.GetMetaData().GetI(key); }
59
60 double GetD(const std::string &key) const { return fDatasetGroup.GetMetaData().GetD(key); }
61
62 std::string GetS(const std::string &key) const { return fDatasetGroup.GetMetaData().GetS(key); }
63
64 /// Check whether the sample name contains the given substring.
65 bool Contains(std::string_view substr) const
66 {
67 // C++14 needs the conversion from std::string_view to std::string
68 return fID.find(std::string(substr)) != std::string::npos;
69 }
70
71 /// Check whether the sample name is empty.
72 ///
73 /// This is the case e.g. when using a RDataFrame with no input data, constructed as `RDataFrame(nEntries)`.
74 bool Empty() const {
75 return fID.empty();
76 }
77
78 /// Return a string representation of the sample name.
79 ///
80 /// The representation is of the form "<filename>/<treename>" if the input data comes from a TTree or a TChain.
81 const std::string &AsString() const
82 {
83 return fID;
84 }
85
86 /// Return the entry range in this sample that is being taken into consideration.
87 ///
88 /// Multiple multi-threading tasks might process different entry ranges of the same sample.
89 std::pair<ULong64_t, ULong64_t> EntryRange() const { return fEntryRange; }
90
91 /// Return the number of entries of this sample that is being taken into consideration.
92 ULong64_t NEntries() const { return fEntryRange.second - fEntryRange.first; }
93
94 bool operator==(const RSampleInfo &other) const { return fID == other.fID; }
95 bool operator!=(const RSampleInfo &other) const { return !(*this == other); }
96};
97
98/// The type of a data-block callback, registered with a RDataFrame computation graph via e.g.
99/// DefinePerSample() or by certain actions (e.g. Snapshot()).
101
102} // namespace RDF
103} // namespace ROOT
104
105#endif
unsigned long long ULong64_t
Definition: RtypesCore.h:81
Class representing a dataset group (mapping of trees (and their fileglobs) to metadata)
const std::string & GetGroupName() const
const RMetaData & GetMetaData() const
std::string GetS(const std::string &key) const
Definition: RMetaData.cxx:56
double GetD(const std::string &key) const
Definition: RMetaData.cxx:47
int GetI(const std::string &key) const
Definition: RMetaData.cxx:38
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
Definition: RSampleInfo.hxx:35
RSampleInfo(RSampleInfo &&)=default
bool Contains(std::string_view substr) const
Check whether the sample name contains the given substring.
Definition: RSampleInfo.hxx:65
bool operator==(const RSampleInfo &other) const
Definition: RSampleInfo.hxx:94
unsigned int GetGroupId() const
Definition: RSampleInfo.hxx:56
ROOT::RDF::Experimental::RDatasetGroup fDatasetGroup
Definition: RSampleInfo.hxx:39
int GetI(const std::string &key) const
Definition: RSampleInfo.hxx:58
std::string GetS(const std::string &key) const
Definition: RSampleInfo.hxx:62
RSampleInfo(const RSampleInfo &)=default
RSampleInfo(std::string_view id, std::pair< ULong64_t, ULong64_t > entryRange, const ROOT::RDF::Experimental::RDatasetGroup &datasetGroup={"", "", ""})
Definition: RSampleInfo.hxx:42
std::pair< ULong64_t, ULong64_t > fEntryRange
Definition: RSampleInfo.hxx:37
RSampleInfo & operator=(const RSampleInfo &)=default
double GetD(const std::string &key) const
Definition: RSampleInfo.hxx:60
bool Empty() const
Check whether the sample name is empty.
Definition: RSampleInfo.hxx:74
const std::string & AsString() const
Return a string representation of the sample name.
Definition: RSampleInfo.hxx:81
bool operator!=(const RSampleInfo &other) const
Definition: RSampleInfo.hxx:95
ULong64_t NEntries() const
Return the number of entries of this sample that is being taken into consideration.
Definition: RSampleInfo.hxx:92
RSampleInfo & operator=(RSampleInfo &&)=default
const std::string & GetGroupName() const
Definition: RSampleInfo.hxx:54
std::pair< ULong64_t, ULong64_t > EntryRange() const
Return the entry range in this sample that is being taken into consideration.
Definition: RSampleInfo.hxx:89
basic_string_view< char > string_view
void(off) SmallVectorTemplateBase< T
std::function< void(unsigned int, const ROOT::RDF::RSampleInfo &)> SampleCallback_t
The type of a data-block callback, registered with a RDataFrame computation graph via e....
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:167
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.