11#ifndef ROOT_RDF_RFilterWithMissingValues
12#define ROOT_RDF_RFilterWithMissingValues
28#include <unordered_map>
35 std::unordered_map<
void *, std::shared_ptr<GraphNode>> &visitedMap);
39 const std::vector<std::string> &prevNodeDefines,
40 std::unordered_map<
void *, std::shared_ptr<GraphNode>> &visitedMap);
57template <
typename PrevNodeRaw>
63 using PrevNode_t = std::conditional_t<std::is_same<PrevNodeRaw, RJittedFilter>::value,
RFilterBase, PrevNodeRaw>;
75 std::string_view filterName =
"",
const std::string &variationName =
"nominal")
76 :
RFilterBase(pd->GetLoopManagerUnchecked(), filterName, pd->GetLoopManagerUnchecked()->GetNSlots(), colRegister,
77 columns, pd->GetVariations(), variationName),
78 fPrevNodePtr(std::move(pd)),
79 fValues(fPrevNodePtr->GetLoopManagerUnchecked()->GetNSlots()),
80 fDiscardEntryWithMissingValue(discardEntry)
82 fLoopManager->Register(
this);
84 fLoopManager->InsertSuppressErrorsForMissingBranch(fColumnNames[0]);
95 fLoopManager->Deregister(
this);
96 fLoopManager->EraseSuppressErrorsForMissingBranch(fColumnNames[0]);
101 constexpr static auto cacheLineStepLong64_t = RDFInternal::CacheLineStep<Long64_t>();
102 constexpr static auto cacheLineStepint = RDFInternal::CacheLineStep<int>();
103 constexpr static auto cacheLineStepULong64_t = RDFInternal::CacheLineStep<ULong64_t>();
105 if (entry != fLastCheckedEntry[slot * cacheLineStepLong64_t]) {
106 if (!fPrevNodePtr->CheckFilters(slot, entry)) {
108 fLastResult[slot * cacheLineStepint] =
false;
111 const bool valueIsMissing = fValues[slot]->template TryGet<void>(entry) ==
nullptr;
112 if (fDiscardEntryWithMissingValue) {
113 valueIsMissing ? ++fRejected[slot * cacheLineStepULong64_t] : ++fAccepted[slot * cacheLineStepULong64_t];
114 fLastResult[slot * cacheLineStepint] = !valueIsMissing;
116 valueIsMissing ? ++fAccepted[slot * cacheLineStepULong64_t] : ++fRejected[slot * cacheLineStepULong64_t];
117 fLastResult[slot * cacheLineStepint] = valueIsMissing;
120 fLastCheckedEntry[slot * cacheLineStepLong64_t] = entry;
122 return fLastResult[slot * cacheLineStepint];
129 *fLoopManager,
r, fColumnNames[0],
typeid(
void));
130 fLastCheckedEntry[slot * RDFInternal::CacheLineStep<Long64_t>()] = -1;
138 fPrevNodePtr->PartialReport(rep);
145 if (fNStopsReceived == fNChildren)
146 fPrevNodePtr->StopProcessing();
153 if (fNChildren == 1 && fName.empty())
154 fPrevNodePtr->IncrChildrenCount();
159 assert(!fName.empty());
160 fPrevNodePtr->IncrChildrenCount();
165 fPrevNodePtr->AddFilterName(
filters);
166 auto name = (HasName() ? fName : fDiscardEntryWithMissingValue ?
"FilterAvailable" :
"FilterMissing");
171 void FinalizeSlot(
unsigned int slot)
final { fValues[slot] =
nullptr; }
173 std::shared_ptr<RDFGraphDrawing::GraphNode>
174 GetGraph(std::unordered_map<
void *, std::shared_ptr<RDFGraphDrawing::GraphNode>> &visitedMap)
final
177 auto prevNode = fPrevNodePtr->GetGraph(visitedMap);
178 const auto &prevColumns = prevNode->GetDefinedColumns();
185 if (!thisNode->IsNew()) {
189 auto upmostNode = AddDefinesToGraph(thisNode, fColRegister, prevColumns, visitedMap);
192 thisNode->AddDefinedColumns(fColRegister.GenerateColumnNames());
194 upmostNode->SetPrevNode(prevNode);
202 assert(fVariation ==
"nominal");
205 assert(variationName !=
"nominal");
210 auto it = fVariedFilters.find(variationName);
211 if (it != fVariedFilters.end())
214 auto prevNode = fPrevNodePtr;
215 if (
static_cast<RNodeBase *
>(fPrevNodePtr.get()) !=
static_cast<RNodeBase *
>(fLoopManager) &&
217 prevNode = std::static_pointer_cast<PrevNode_t>(prevNode->GetVariedFilter(variationName));
222 fDiscardEntryWithMissingValue, std::move(prevNode), fColRegister, fColumnNames, fName, variationName));
223 auto e = fVariedFilters.insert({variationName, std::move(variedFilter)});
224 return e.first->second;
Basic types used by ROOT and required by TInterpreter.
long long Long64_t
Portable signed long integer 8 bytes.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
implementation of FilterAvailable and FilterMissing operations
RFilterWithMissingValues & operator=(RFilterWithMissingValues &&)=delete
const std::shared_ptr< PrevNode_t > fPrevNodePtr
void TriggerChildrenCount() final
void StopProcessing() final
std::vector< RColumnReaderBase * > fValues
bool CheckFilters(unsigned int slot, Long64_t entry) final
void FinalizeSlot(unsigned int slot) final
Clean-up operations to be performed at the end of a task.
bool fDiscardEntryWithMissingValue
std::shared_ptr< RDFGraphDrawing::GraphNode > GetGraph(std::unordered_map< void *, std::shared_ptr< RDFGraphDrawing::GraphNode > > &visitedMap) final
void IncrChildrenCount() final
std::conditional_t< std::is_same< PrevNodeRaw, RJittedFilter >::value, RFilterBase, PrevNodeRaw > PrevNode_t
std::shared_ptr< RNodeBase > GetVariedFilter(const std::string &variationName) final
Return a clone of this Filter that works with values in the variationName "universe".
RFilterWithMissingValues(const RFilterWithMissingValues &)=delete
void InitSlot(TTreeReader *r, unsigned int slot) final
~RFilterWithMissingValues() final
void AddFilterName(std::vector< std::string > &filters) final
RFilterWithMissingValues & operator=(const RFilterWithMissingValues &)=delete
RFilterWithMissingValues(RFilterWithMissingValues &&)=delete
void PartialReport(ROOT::RDF::RCutFlowReport &rep) const final
void Report(ROOT::RDF::RCutFlowReport &rep) const final
RFilterWithMissingValues(bool discardEntry, std::shared_ptr< PrevNode_t > pd, const RDFInternal::RColumnRegister &colRegister, const ColumnNames_t &columns, std::string_view filterName="", const std::string &variationName="nominal")
Base class for non-leaf nodes of the computational graph.
A binder for user-defined columns, variations and aliases.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
std::shared_ptr< GraphNode > CreateFilterNode(const ROOT::Detail::RDF::RFilterBase *filterPtr, std::unordered_map< void *, std::shared_ptr< GraphNode > > &visitedMap)
std::shared_ptr< GraphNode > AddDefinesToGraph(std::shared_ptr< GraphNode > node, const RColumnRegister &colRegister, const std::vector< std::string > &prevNodeDefines, std::unordered_map< void *, std::shared_ptr< GraphNode > > &visitedMap)
RDFDetail::RColumnReaderBase * GetColumnReader(unsigned int slot, RColumnReaderBase *defineOrVariationReader, RLoopManager &lm, TTreeReader *treeReader, std::string_view colName, const std::type_info &ti)
bool IsStrInVec(const std::string &str, const std::vector< std::string > &vec)