Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RFilterBase.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_RFILTERBASE
12 #define ROOT_RFILTERBASE
13 
15 #include "ROOT/RDF/RNodeBase.hxx"
16 #include "RtypesCore.h"
17 #include "TError.h" // R_ASSERT
18 
19 #include <string>
20 #include <vector>
21 
22 class TTreeReader;
23 
24 namespace ROOT {
25 
26 namespace RDF {
27 class RCutFlowReport;
28 } // ns RDF
29 
30 namespace Detail {
31 namespace RDF {
32 namespace RDFInternal = ROOT::Internal::RDF;
33 
34 class RLoopManager;
35 
36 class RFilterBase : public RNodeBase {
37 protected:
38  std::vector<Long64_t> fLastCheckedEntry;
39  std::vector<int> fLastResult = {true}; // std::vector<bool> cannot be used in a MT context safely
40  std::vector<ULong64_t> fAccepted = {0};
41  std::vector<ULong64_t> fRejected = {0};
42  const std::string fName;
43  const unsigned int fNSlots; ///< Number of thread slots used by this node, inherited from parent node.
44 
45  RDFInternal::RBookedCustomColumns fCustomColumns;
46 
47 public:
48  RFilterBase(RLoopManager *df, std::string_view name, const unsigned int nSlots,
49  const RDFInternal::RBookedCustomColumns &customColumns);
50  RFilterBase &operator=(const RFilterBase &) = delete;
51 
52  virtual ~RFilterBase();
53 
54  virtual void InitSlot(TTreeReader *r, unsigned int slot) = 0;
55  bool HasName() const;
56  std::string GetName() const;
57  virtual void FillReport(ROOT::RDF::RCutFlowReport &) const;
58  virtual void TriggerChildrenCount() = 0;
59  virtual void ResetReportCount()
60  {
61  R__ASSERT(!fName.empty()); // this method is to only be called on named filters
62  // fAccepted and fRejected could be different than 0 if this is not the first event-loop run using this filter
63  std::fill(fAccepted.begin(), fAccepted.end(), 0);
64  std::fill(fRejected.begin(), fRejected.end(), 0);
65  }
66  virtual void ClearValueReaders(unsigned int slot) = 0;
67  virtual void ClearTask(unsigned int slot) = 0;
68  virtual void InitNode();
69  virtual void AddFilterName(std::vector<std::string> &filters) = 0;
70 };
71 
72 } // ns RDF
73 } // ns Detail
74 } // ns ROOT
75 
76 #endif // ROOT_RFILTERBASE