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->GetSuppressErrorsForMissingBranches().push_back(fColumnNames[0]);
95 fLoopManager->Deregister(
this);
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];
130 if (
auto *defineOrVariationReader = fColRegister.GetReaderUnchecked(slot, fColumnNames[0], fVariation))
131 return defineOrVariationReader;
135 if (
auto *datasetColReader = fLoopManager->GetDatasetColumnReader(slot, fColumnNames[0],
typeid(
void)))
136 return datasetColReader;
140 return fLoopManager->AddTreeColumnReader(
141 slot, fColumnNames[0], std::make_unique<ROOT::Internal::RDF::RTreeOpaqueColumnReader>(*
r, fColumnNames[0]),
147 fValues[slot] = GetOrCreateColumnReader(
r, slot);
148 fLastCheckedEntry[slot * RDFInternal::CacheLineStep<Long64_t>()] = -1;
156 fPrevNodePtr->PartialReport(rep);
163 if (fNStopsReceived == fNChildren)
164 fPrevNodePtr->StopProcessing();
171 if (fNChildren == 1 && fName.empty())
172 fPrevNodePtr->IncrChildrenCount();
177 assert(!fName.empty());
178 fPrevNodePtr->IncrChildrenCount();
183 fPrevNodePtr->AddFilterName(
filters);
184 auto name = (HasName() ? fName : fDiscardEntryWithMissingValue ?
"FilterAvailable" :
"FilterMissing");
189 void FinalizeSlot(
unsigned int slot)
final { fValues[slot] =
nullptr; }
191 std::shared_ptr<RDFGraphDrawing::GraphNode>
192 GetGraph(std::unordered_map<
void *, std::shared_ptr<RDFGraphDrawing::GraphNode>> &visitedMap)
final
195 auto prevNode = fPrevNodePtr->GetGraph(visitedMap);
196 const auto &prevColumns = prevNode->GetDefinedColumns();
203 if (!thisNode->IsNew()) {
207 auto upmostNode = AddDefinesToGraph(thisNode, fColRegister, prevColumns, visitedMap);
210 thisNode->AddDefinedColumns(fColRegister.GenerateColumnNames());
212 upmostNode->SetPrevNode(prevNode);
220 assert(fVariation ==
"nominal");
223 assert(variationName !=
"nominal");
228 auto it = fVariedFilters.find(variationName);
229 if (it != fVariedFilters.end())
232 auto prevNode = fPrevNodePtr;
233 if (
static_cast<RNodeBase *
>(fPrevNodePtr.get()) !=
static_cast<RNodeBase *
>(fLoopManager) &&
235 prevNode = std::static_pointer_cast<PrevNode_t>(prevNode->GetVariedFilter(variationName));
240 fDiscardEntryWithMissingValue, std::move(prevNode), fColRegister, fColumnNames, fName, variationName));
241 auto e = fVariedFilters.insert({variationName, std::move(variedFilter)});
242 return e.first->second;
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
ROOT::Detail::RDF::RColumnReaderBase * GetOrCreateColumnReader(TTreeReader *r, unsigned int slot)
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)
bool IsStrInVec(const std::string &str, const std::vector< std::string > &vec)
void Erase(const T &that, std::vector< T > &v)
Erase that element from vector v