File indexing completed on 2025-09-17 09:14:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ROOT_RDFRANGE
0012 #define ROOT_RDFRANGE
0013
0014 #include "ROOT/RDF/RLoopManager.hxx"
0015 #include "ROOT/RDF/RRangeBase.hxx"
0016 #include "ROOT/RDF/Utils.hxx"
0017 #include "RtypesCore.h"
0018
0019 #include <cassert>
0020 #include <memory>
0021 #include <string>
0022 #include <string_view>
0023 #include <vector>
0024
0025 namespace ROOT {
0026
0027
0028 namespace Internal {
0029 namespace RDF {
0030 namespace GraphDrawing {
0031 std::shared_ptr<GraphNode> CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr,
0032 std::unordered_map<void *, std::shared_ptr<GraphNode>> &visitedMap);
0033 }
0034 }
0035 }
0036
0037 namespace Detail {
0038 namespace RDF {
0039 namespace RDFGraphDrawing = ROOT::Internal::RDF::GraphDrawing;
0040 class RJittedFilter;
0041
0042 template <typename PrevNodeRaw>
0043 class RRange final : public RRangeBase {
0044
0045
0046
0047 using PrevNode_t = std::conditional_t<std::is_same<PrevNodeRaw, RJittedFilter>::value, RFilterBase, PrevNodeRaw>;
0048 const std::shared_ptr<PrevNode_t> fPrevNodePtr;
0049 PrevNode_t &fPrevNode;
0050
0051 public:
0052 RRange(unsigned int start, unsigned int stop, unsigned int stride, std::shared_ptr<PrevNode_t> pd)
0053 : RRangeBase(pd->GetLoopManagerUnchecked(), start, stop, stride, pd->GetLoopManagerUnchecked()->GetNSlots(),
0054 pd->GetVariations()),
0055 fPrevNodePtr(std::move(pd)), fPrevNode(*fPrevNodePtr)
0056 {
0057 fLoopManager->Register(this);
0058 }
0059
0060
0061
0062 RRange(const RRange &) = delete;
0063 RRange &operator=(const RRange &) = delete;
0064 RRange(RRange &&) = delete;
0065 RRange &operator=(RRange &&) = delete;
0066
0067
0068 ~RRange() final { fLoopManager->Deregister(this); }
0069
0070
0071 bool CheckFilters(unsigned int slot, Long64_t entry) final
0072 {
0073 if (entry != fLastCheckedEntry) {
0074 if (fHasStopped)
0075 return false;
0076 if (!fPrevNode.CheckFilters(slot, entry)) {
0077
0078 fLastResult = false;
0079 } else {
0080
0081 if (fNProcessedEntries < fStart || (fStop > 0 && fNProcessedEntries >= fStop) ||
0082 (fStride != 1 && (fNProcessedEntries - fStart) % fStride != 0))
0083 fLastResult = false;
0084 else
0085 fLastResult = true;
0086 ++fNProcessedEntries;
0087 if (fNProcessedEntries == fStop) {
0088 fHasStopped = true;
0089 fPrevNode.StopProcessing();
0090 }
0091 }
0092 fLastCheckedEntry = entry;
0093 }
0094 return fLastResult;
0095 }
0096
0097
0098
0099 void Report(ROOT::RDF::RCutFlowReport &rep) const final { fPrevNode.PartialReport(rep); }
0100
0101 void PartialReport(ROOT::RDF::RCutFlowReport &rep) const final { fPrevNode.PartialReport(rep); }
0102
0103 void StopProcessing() final
0104 {
0105 ++fNStopsReceived;
0106 if (fNStopsReceived == fNChildren && !fHasStopped)
0107 fPrevNode.StopProcessing();
0108 }
0109
0110 void IncrChildrenCount() final
0111 {
0112 ++fNChildren;
0113
0114 if (fNChildren == 1)
0115 fPrevNode.IncrChildrenCount();
0116 }
0117
0118
0119 void AddFilterName(std::vector<std::string> &filters) final { fPrevNode.AddFilterName(filters); }
0120 std::shared_ptr<RDFGraphDrawing::GraphNode>
0121 GetGraph(std::unordered_map<void *, std::shared_ptr<RDFGraphDrawing::GraphNode>> &visitedMap) final
0122 {
0123
0124
0125 auto prevNode = fPrevNode.GetGraph(visitedMap);
0126 const auto &prevColumns = prevNode->GetDefinedColumns();
0127
0128 auto thisNode = RDFGraphDrawing::CreateRangeNode(this, visitedMap);
0129
0130
0131
0132
0133 if (!thisNode->IsNew()) {
0134 return thisNode;
0135 }
0136 thisNode->SetPrevNode(prevNode);
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 std::vector<std::string_view> colsViews;
0147 colsViews.reserve(prevColumns.size());
0148 for (const auto &col : prevColumns)
0149 colsViews.push_back(col);
0150 thisNode->AddDefinedColumns(colsViews);
0151
0152 return thisNode;
0153 }
0154
0155 std::shared_ptr<RNodeBase> GetVariedFilter(const std::string &variationName) final
0156 {
0157
0158
0159 assert(variationName != "nominal");
0160
0161
0162 assert(RDFInternal::IsStrInVec(variationName, fVariations));
0163
0164 auto it = fVariedRanges.find(variationName);
0165 if (it != fVariedRanges.end())
0166 return it->second;
0167
0168 auto prevNode = fPrevNodePtr;
0169 if (static_cast<RNodeBase *>(fPrevNodePtr.get()) != static_cast<RNodeBase *>(fLoopManager) &&
0170 RDFInternal::IsStrInVec(variationName, prevNode->GetVariations()))
0171 prevNode = std::static_pointer_cast<PrevNode_t>(prevNode->GetVariedFilter(variationName));
0172
0173 auto variedRange = std::unique_ptr<RRangeBase>(new RRange(fStart, fStop, fStride, std::move(prevNode)));
0174 auto e = fVariedRanges.insert({variationName, std::move(variedRange)});
0175 return e.first->second;
0176 }
0177 };
0178
0179 }
0180 }
0181 }
0182
0183 #endif