Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
14#include <ROOT/RStringView.hxx>
15#include <Rtypes.h>
16
17#include <functional>
18#include <stdexcept>
19#include <string>
20
21namespace ROOT {
22namespace RDF {
23
24/// This type represents a sample identifier, to be used in conjunction with RDataFrame features such as
25/// DefinePerSample() and per-sample callbacks.
26///
27/// When the input data comes from a TTree, the string representation of RSampleInfo (which is returned by AsString()
28/// and that can be queried e.g. with Contains()) is of the form "<filename>/<treename>".
29///
30/// In multi-thread runs, different tasks might process different entry ranges of the same sample,
31/// so RSampleInfo also provides methods to inspect which part of a sample is being taken into consideration.
33 std::string fID;
34 std::pair<ULong64_t, ULong64_t> fEntryRange;
35
36public:
37 explicit RSampleInfo(std::string_view id, std::pair<ULong64_t, ULong64_t> entryRange)
38 : fID(id), fEntryRange(entryRange)
39 {
40 }
41 RSampleInfo() = default;
42 RSampleInfo(const RSampleInfo &) = default;
43 RSampleInfo &operator=(const RSampleInfo &) = default;
44 RSampleInfo(RSampleInfo &&) = default;
46 ~RSampleInfo() = default;
47
48 /// Check whether the sample name contains the given substring.
49 bool Contains(std::string_view substr) const
50 {
51 // C++14 needs the conversion from std::string_view to std::string
52 return fID.find(std::string(substr)) != std::string::npos;
53 }
54
55 /// Check whether the sample name is empty.
56 ///
57 /// This is the case e.g. when using a RDataFrame with no input data, constructed as `RDataFrame(nEntries)`.
58 bool Empty() const {
59 return fID.empty();
60 }
61
62 /// Return a string representation of the sample name.
63 ///
64 /// The representation is of the form "<filename>/<treename>" if the input data comes from a TTree or a TChain.
65 const std::string &AsString() const
66 {
67 return fID;
68 }
69
70 /// Return the entry range in this sample that is being taken into consideration.
71 ///
72 /// Multiple multi-threading tasks might process different entry ranges of the same sample.
73 std::pair<ULong64_t, ULong64_t> EntryRange() const { return fEntryRange; }
74
75 /// Return the number of entries of this sample that is being taken into consideration.
76 ULong64_t NEntries() const { return fEntryRange.second - fEntryRange.first; }
77
78 bool operator==(const RSampleInfo &other) const { return fID == other.fID; }
79 bool operator!=(const RSampleInfo &other) const { return !(*this == other); }
80};
81
82/// The type of a data-block callback, registered with a RDataFrame computation graph via e.g.
83/// DefinePerSample() or by certain actions (e.g. Snapshot()).
84using SampleCallback_t = std::function<void(unsigned int, const ROOT::RDF::RSampleInfo &)>;
85
86} // namespace RDF
87} // namespace ROOT
88
89#endif
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
unsigned long long ULong64_t
Definition RtypesCore.h:81
XFontStruct * id
Definition TGX11.cxx:109
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
RSampleInfo(RSampleInfo &&)=default
bool Contains(std::string_view substr) const
Check whether the sample name contains the given substring.
bool operator==(const RSampleInfo &other) const
RSampleInfo(std::string_view id, std::pair< ULong64_t, ULong64_t > entryRange)
RSampleInfo(const RSampleInfo &)=default
std::pair< ULong64_t, ULong64_t > fEntryRange
RSampleInfo & operator=(const RSampleInfo &)=default
bool Empty() const
Check whether the sample name is empty.
const std::string & AsString() const
Return a string representation of the sample name.
bool operator!=(const RSampleInfo &other) const
ULong64_t NEntries() const
Return the number of entries of this sample that is being taken into consideration.
RSampleInfo & operator=(RSampleInfo &&)=default
std::pair< ULong64_t, ULong64_t > EntryRange() const
Return the entry range in this sample that is being taken into consideration.
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....
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...