Logo ROOT  
Reference Guide
RRange.hxx
Go to the documentation of this file.
1 // Author: Enrico Guiraud, Danilo Piparo CERN 09/2018
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2018, 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_RDFRANGE
12 #define ROOT_RDFRANGE
13 
15 #include "ROOT/RDF/RRangeBase.hxx"
16 #include "RtypesCore.h"
17 
18 #include <memory>
19 
20 namespace ROOT {
21 
22 // fwd decl
23 namespace Internal {
24 namespace RDF {
25 namespace GraphDrawing {
26 std::shared_ptr<GraphNode> CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr);
27 } // ns GraphDrawing
28 } // ns RDF
29 } // ns Internal
30 
31 namespace Detail {
32 namespace RDF {
34 
35 template <typename PrevData>
36 class RRange final : public RRangeBase {
37  const std::shared_ptr<PrevData> fPrevDataPtr;
38  PrevData &fPrevData;
39 
40 public:
41  RRange(unsigned int start, unsigned int stop, unsigned int stride, std::shared_ptr<PrevData> pd)
42  : RRangeBase(pd->GetLoopManagerUnchecked(), start, stop, stride, pd->GetLoopManagerUnchecked()->GetNSlots()),
43  fPrevDataPtr(std::move(pd)), fPrevData(*fPrevDataPtr) {}
44 
45  RRange(const RRange &) = delete;
46  RRange &operator=(const RRange &) = delete;
47  // must call Deregister here, before fPrevDataFrame is destroyed,
48  // otherwise if fPrevDataFrame is fLoopManager we get a use after delete
50 
51  /// Ranges act as filters when it comes to selecting entries that downstream nodes should process
52  bool CheckFilters(unsigned int slot, Long64_t entry) final
53  {
54  if (entry != fLastCheckedEntry) {
55  if (fHasStopped)
56  return false;
57  if (!fPrevData.CheckFilters(slot, entry)) {
58  // a filter upstream returned false, cache the result
59  fLastResult = false;
60  } else {
61  // apply range filter logic, cache the result
64  (fStride != 1 && fNProcessedEntries % fStride != 0))
65  fLastResult = false;
66  else
67  fLastResult = true;
68  if (fNProcessedEntries == fStop) {
69  fHasStopped = true;
70  fPrevData.StopProcessing();
71  }
72  }
73  fLastCheckedEntry = entry;
74  }
75  return fLastResult;
76  }
77 
78  // recursive chain of `Report`s
79  // RRange simply forwards these calls to the previous node
80  void Report(ROOT::RDF::RCutFlowReport &rep) const final { fPrevData.PartialReport(rep); }
81 
82  void PartialReport(ROOT::RDF::RCutFlowReport &rep) const final { fPrevData.PartialReport(rep); }
83 
84  void StopProcessing() final
85  {
88  fPrevData.StopProcessing();
89  }
90 
91  void IncrChildrenCount() final
92  {
93  ++fNChildren;
94  // propagate "children activation" upstream
95  if (fNChildren == 1)
96  fPrevData.IncrChildrenCount();
97  }
98 
99  /// This function must be defined by all nodes, but only the filters will add their name
100  void AddFilterName(std::vector<std::string> &filters) { fPrevData.AddFilterName(filters); }
101  std::shared_ptr<RDFGraphDrawing::GraphNode> GetGraph()
102  {
103  // TODO: Ranges node have no information about custom columns, hence it is not possible now
104  // if defines have been used before.
105  auto prevNode = fPrevData.GetGraph();
106  auto prevColumns = prevNode->GetDefinedColumns();
107 
108  auto thisNode = RDFGraphDrawing::CreateRangeNode(this);
109 
110  /* If the returned node is not new, there is no need to perform any other operation.
111  * This is a likely scenario when building the entire graph in which branches share
112  * some nodes. */
113  if (!thisNode->GetIsNew()) {
114  return thisNode;
115  }
116  thisNode->SetPrevNode(prevNode);
117 
118  // If there have been some defines between the last Filter and this Range node we won't detect them:
119  // Ranges don't keep track of Defines (they have no RBookedDefines data member).
120  // Let's pretend that the Defines of this node are the same as the node above, so that in the graph
121  // the Defines will just appear below the Range instead (no functional change).
122  thisNode->AddDefinedColumns(prevColumns);
123 
124  return thisNode;
125  }
126 };
127 
128 } // namespace RDF
129 } // namespace Detail
130 } // namespace ROOT
131 
132 #endif // ROOT_RDFRANGE
filters
const char * filters[]
Definition: TGFileBrowser.cxx:61
ROOT::Detail::RDF::RRange::RRange
RRange(const RRange &)=delete
ROOT::Detail::RDF::RRangeBase::fStart
unsigned int fStart
Definition: RRangeBase.hxx:34
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
ROOT::Detail::RDF::RRange::operator=
RRange & operator=(const RRange &)=delete
ROOT::Detail::RDF::RRangeBase
Definition: RRangeBase.hxx:32
ROOT::Detail::RDF::RNodeBase::GetLoopManagerUnchecked
virtual RLoopManager * GetLoopManagerUnchecked()
Definition: RNodeBase.hxx:65
ROOT::Detail::RDF::RRange::IncrChildrenCount
void IncrChildrenCount() final
Definition: RRange.hxx:91
ROOT::Detail::RDF::RRange
Definition: RRange.hxx:36
ROOT::Detail::RDF::RRange::CheckFilters
bool CheckFilters(unsigned int slot, Long64_t entry) final
Ranges act as filters when it comes to selecting entries that downstream nodes should process.
Definition: RRange.hxx:52
ROOT::Detail::RDF::RRange::fPrevDataPtr
const std::shared_ptr< PrevData > fPrevDataPtr
Definition: RRange.hxx:37
ROOT::Detail::RDF::RRange::AddFilterName
void AddFilterName(std::vector< std::string > &filters)
This function must be defined by all nodes, but only the filters will add their name.
Definition: RRange.hxx:100
ROOT::Detail::RDF::RRangeBase::fLastCheckedEntry
Long64_t fLastCheckedEntry
Definition: RRangeBase.hxx:37
ROOT::Internal::RDF::GraphDrawing
Definition: GraphNode.hxx:24
ROOT::Detail::RDF::RRange::PartialReport
void PartialReport(ROOT::RDF::RCutFlowReport &rep) const final
Definition: RRange.hxx:82
ROOT::Detail::RDF::RRange::fPrevData
PrevData & fPrevData
Definition: RRange.hxx:38
ROOT::Detail::RDF::RRange::StopProcessing
void StopProcessing() final
Definition: RRange.hxx:84
ROOT::Detail::RDF::RRangeBase::fStop
unsigned int fStop
Definition: RRangeBase.hxx:35
ROOT::Detail::RDF::RRangeBase::fStride
unsigned int fStride
Definition: RRangeBase.hxx:36
ROOT::Detail::RDF::RRangeBase::fNProcessedEntries
ULong64_t fNProcessedEntries
Definition: RRangeBase.hxx:39
ROOT::Detail::RDF::RNodeBase::fNChildren
unsigned int fNChildren
Number of nodes of the functional graph hanging from this object.
Definition: RNodeBase.hxx:44
RRangeBase.hxx
ROOT::Internal::RDF::GraphDrawing::CreateRangeNode
std::shared_ptr< GraphNode > CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr)
Definition: RDFGraphUtils.cxx:126
ROOT::Internal::RDF::GetNSlots
unsigned int GetNSlots()
Definition: RDFUtils.cxx:268
ROOT::Detail::RDF::RRange::RRange
RRange(unsigned int start, unsigned int stop, unsigned int stride, std::shared_ptr< PrevData > pd)
Definition: RRange.hxx:41
ROOT::Detail::RDF::RRange::GetGraph
std::shared_ptr< RDFGraphDrawing::GraphNode > GetGraph()
Definition: RRange.hxx:101
ROOT::Detail::RDF::RNodeBase::fLoopManager
RLoopManager * fLoopManager
Definition: RNodeBase.hxx:43
RtypesCore.h
ROOT::RDF::RCutFlowReport
Definition: RCutFlowReport.hxx:47
ROOT::Detail::RDF::RRangeBase::fHasStopped
bool fHasStopped
True if the end of the range has been reached.
Definition: RRangeBase.hxx:40
ROOT::Detail::RDF::RRange::Report
void Report(ROOT::RDF::RCutFlowReport &rep) const final
Definition: RRange.hxx:80
ROOT::Detail::RDF::RRange::~RRange
~RRange()
Definition: RRange.hxx:49
RLoopManager.hxx
ROOT::Detail::RDF::RLoopManager::Deregister
void Deregister(RDFInternal::RActionBase *actionPtr)
Definition: RLoopManager.cxx:625
ROOT::Detail::RDF::RNodeBase::fNStopsReceived
unsigned int fNStopsReceived
Number of times that a children node signaled to stop processing entries.
Definition: RNodeBase.hxx:45
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Detail::RDF::RRangeBase::fLastResult
bool fLastResult
Definition: RRangeBase.hxx:38