13#ifndef ROOT_RDF_HELPERS
14#define ROOT_RDF_HELPERS
36template <
typename... ArgTypes,
typename F>
39 return std::function<
bool(ArgTypes...)>([=](ArgTypes... args)
mutable {
return !
f(args...); });
42template <
typename... ArgTypes,
typename Ret,
typename... Args>
45 return std::function<
bool(ArgTypes...)>([=](ArgTypes... args)
mutable {
return !
f(args...); });
48template <
typename I,
typename T,
typename F>
51template <std::size_t...
N,
typename T,
typename F>
53 template <std::
size_t Idx>
55 std::decay_t<F> fFunc;
59 auto operator()(AlwaysT<N>... args) ->
decltype(fFunc({args...})) {
return fFunc({args...}); }
62template <std::
size_t N,
typename T,
typename F>
81 typename Args =
typename ROOT::TypeTraits::CallableTraits<std::decay_t<F>>::arg_types_nodecay,
82 typename Ret =
typename ROOT::TypeTraits::CallableTraits<std::decay_t<F>>::ret_type>
85 static_assert(std::is_same<Ret, bool>::value,
"RDF::Not requires a callable that returns a bool.");
102template <std::
size_t N,
typename T,
typename F>
119template <
typename NodeType>
138template <
typename NodeType>
139void SaveGraph(NodeType node,
const std::string &outputFile)
144 std::ofstream out(outputFile);
145 if (!out.is_open()) {
146 throw std::runtime_error(
"Could not open output file \"" + outputFile +
"\"for reading");
157template <
typename NodeType>
185unsigned int RunGraphs(std::vector<RResultHandle> handles);
187namespace Experimental {
221 R__ASSERT(resPtr !=
nullptr &&
"Calling VariationsFor on an empty RResultPtr");
227 std::unique_ptr<RDFInternal::RActionBase> variedAction;
228 std::vector<std::shared_ptr<T>> variedResults;
230 std::shared_ptr<RDFInternal::RActionBase> nominalAction = resPtr.
fActionPtr;
231 std::vector<std::string> variations = nominalAction->GetVariations();
232 const auto nVariations = variations.size();
234 if (nVariations > 0) {
236 variedResults.reserve(nVariations);
237 for (
auto i = 0u; i < nVariations; ++i){
240 variedResults.emplace_back(
new T{*resPtr.
fObjPtr});
243 if constexpr (std::is_base_of<TNamed, T>::value) {
245 std::string variationName = variations[i];
247 std::replace(variationName.begin(), variationName.end(),
':',
'_');
249 auto &variedResult = variedResults.back();
251 variedResult->SetName((std::string(variedResult->GetName()) +
"_" + variationName).c_str());
255 std::vector<void *> typeErasedResults;
256 typeErasedResults.reserve(variedResults.size());
257 for (
auto &res : variedResults)
258 typeErasedResults.emplace_back(&res);
262 variedAction = nominalAction->MakeVariedAction(std::move(typeErasedResults));
265 return RDFInternal::MakeResultMap<T>(resPtr.
fObjPtr, std::move(variedResults), std::move(variations),
266 *resPtr.
fLoopManager, std::move(nominalAction), std::move(variedAction));
325 void PrintStats(std::ostream &stream, std::size_t currentEventCount, std::chrono::seconds totalElapsedSeconds)
const;
326 void PrintStatsFinal(std::ostream &stream, std::chrono::seconds totalElapsedSeconds)
const;
327 void PrintProgressBar(std::ostream &stream, std::size_t currentEventCount)
const;
329 std::chrono::time_point<std::chrono::system_clock>
fBeginTime = std::chrono::system_clock::now();
350 std::shared_ptr<TTree>
fTree{
nullptr};
360 ProgressHelper(std::size_t increment,
unsigned int totalFiles = 1,
unsigned int progressBarWidth = 40,
361 unsigned int printInterval = 1,
bool useColors =
true);
388 template <
typename T>
398 template <
typename T>
401 using namespace std::chrono;
417 std::lock_guard<std::mutex> lockGuard(
fPrintMutex, std::adopt_lock);
419 std::size_t eventCount;
420 seconds elapsedSeconds;
427 PrintStats(std::cout, eventCount, elapsedSeconds);
430 std::cout << std::flush;
432 std::cout << std::endl;
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
TRObject operator()(const T1 &t1) const
void Jit()
Add RDF nodes that require just-in-time compilation to the computation graph.
std::string RepresentGraph(ROOT::RDataFrame &rDataFrame)
Starting from the root node, prints the entire graph.
~ProgressHelper()=default
std::pair< std::size_t, std::chrono::seconds > RecordEvtCountAndTime()
Record current event counts and time stamp, populate evts/s statistics array.
void registerNewSample(unsigned int, const ROOT::RDF::RSampleInfo &id)
Register a new sample for completion statistics.
void PrintProgressBar(std::ostream &stream, std::size_t currentEventCount) const
Print a progress bar of width ProgressHelper::fBarWidth if fGetNEventsOfCurrentFile is known.
void operator()(unsigned int, T &value)
Thread-safe callback for RDataFrame.
void PrintStats(std::ostream &stream, std::size_t currentEventCount, std::chrono::seconds totalElapsedSeconds) const
Print event and time statistics.
std::map< std::string, ULong64_t > fSampleNameToEventEntries
std::shared_ptr< TTree > fTree
std::size_t fLastProcessedEvents
std::mutex fSampleNameToEventEntriesMutex
std::array< double, 20 > fEventsPerSecondStatistics
double EvtPerSec() const
Compute a running mean of events/s.
std::atomic< std::size_t > fProcessedEvents
unsigned int ComputeCurrentFileIdx() const
std::chrono::time_point< std::chrono::system_clock > fLastPrintTime
std::chrono::time_point< std::chrono::system_clock > fBeginTime
void PrintStatsFinal(std::ostream &stream, std::chrono::seconds totalElapsedSeconds) const
std::chrono::seconds fPrintInterval
void operator()(T &)
Thread-safe callback for RDataFrame.
std::size_t fEventsPerSecondStatisticsIndex
std::size_t ComputeNEventsSoFar() const
The public interface to the RDataFrame federation of classes.
Smart pointer for the return type of actions.
RDFDetail::RLoopManager * fLoopManager
Non-owning pointer to the RLoopManager at the root of this computation graph.
std::shared_ptr< RDFInternal::RActionBase > fActionPtr
Owning pointer to the action that will produce this result.
SPT_t fObjPtr
Shared pointer encapsulating the wrapped result.
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
std::function< bool(ArgTypes...)> NotHelper(ROOT::TypeTraits::TypeList< ArgTypes... >, F &&f)
auto PassAsVec(F &&f) -> PassAsVecHelper< std::make_index_sequence< N >, T, F >
RResultMap< T > VariationsFor(RResultPtr< T > resPtr)
Produce all required systematic variations for the given result.
void AddProgressBar(ROOT::RDF::RNode df)
Add ProgressBar to a ROOT::RDF::RNode.
auto Not(F &&f) -> decltype(RDFInternal::NotHelper(Args(), std::forward< F >(f)))
Given a callable with signature bool(T1, T2, ...) return a callable with same signature that returns ...
std::string SaveGraph(NodeType node)
Create a graphviz representation of the dataframe computation graph, return it as a string.
RNode AsRNode(NodeType node)
Cast a RDataFrame node to the common type ROOT::RDF::RNode.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Lightweight storage for a collection of types.