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>
189unsigned int RunGraphs(std::vector<RResultHandle> handles);
226 static_assert(!std::is_same_v<T, SnapshotResult_t>,
227 "Snapshot with variations can only be enabled via RSnapshotOptions.");
229 R__ASSERT(resPtr !=
nullptr &&
"Calling VariationsFor on an empty RResultPtr");
235 std::unique_ptr<RDFInternal::RActionBase> variedAction;
236 std::vector<std::shared_ptr<T>> variedResults;
238 std::shared_ptr<RDFInternal::RActionBase> nominalAction = resPtr.
fActionPtr;
239 std::vector<std::string> variations = nominalAction->GetVariations();
240 const auto nVariations = variations.size();
242 if (nVariations > 0) {
244 variedResults.reserve(nVariations);
245 for (
auto i = 0u; i < nVariations; ++i){
248 variedResults.emplace_back(
new T{*resPtr.
fObjPtr});
251 if constexpr (std::is_base_of<TNamed, T>::value) {
253 std::string variationName = variations[i];
255 std::replace(variationName.begin(), variationName.end(),
':',
'_');
257 auto &variedResult = variedResults.back();
259 variedResult->SetName((std::string(variedResult->GetName()) +
"_" + variationName).c_str());
263 std::vector<void *> typeErasedResults;
264 typeErasedResults.reserve(variedResults.size());
265 for (
auto &res : variedResults)
266 typeErasedResults.emplace_back(&res);
270 variedAction = nominalAction->MakeVariedAction(std::move(typeErasedResults));
274 *resPtr.
fLoopManager, std::move(nominalAction), std::move(variedAction));
337 std::chrono::seconds totalElapsedSeconds)
const;
353 std::chrono::time_point<std::chrono::system_clock>
const fBeginTime = std::chrono::system_clock::now();
371 ProgressHelper(std::size_t increment,
unsigned int totalFiles,
unsigned int printInterval = 0,
372 bool useColors =
true);
384 template <
typename T>
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
TRObject operator()(const T1 &t1) const
std::string RepresentGraph(ROOT::RDataFrame &rDataFrame)
Starting from the root node, prints the entire graph.
unsigned int const fTotalFiles
std::size_t ComputeTotalEvents() const
Compute total events in all open files.
void PrintStatsFinal() const
~ProgressHelper()=default
ProgressHelper(std::size_t increment, unsigned int totalFiles, unsigned int printInterval=0, bool useColors=true)
Create a progress helper.
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.
unsigned int const fNColumns
unsigned int fEventsPerSecondStatisticsCounter
std::chrono::time_point< std::chrono::system_clock > const fBeginTime
void Update()
Record number of events processed and update progress bar.
std::map< std::string, ULong64_t > fSampleNameToEventEntries
ProgressHelper(ProgressHelper const &)=delete
ProgressHelper & operator=(ProgressHelper &&)=delete
std::size_t fLastProcessedEvents
ProgressHelper(ProgressHelper &&)=delete
std::mutex fSampleNameToEventEntriesMutex
std::chrono::seconds const fPrintInterval
double EvtPerSec() const
Compute a running mean of events/s.
std::atomic< std::size_t > fProcessedEvents
std::array< double, 10 > fEventsPerSecondStatistics
std::chrono::time_point< std::chrono::system_clock > fLastPrintTime
void operator()(unsigned int, T &)
Thread-safe callback for RDataFrame.
std::size_t const fIncrement
bool const fUseShellColours
void PrintProgressAndStats(std::ostream &stream, std::size_t currentEventCount, std::chrono::seconds totalElapsedSeconds) const
Print event and time statistics.
ProgressHelper & operator=(ProgressHelper const &)=delete
The public interface to the RDataFrame federation of classes.
Smart pointer for the return type of actions.
std::shared_ptr< T > fObjPtr
Shared pointer encapsulating the wrapped result.
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.
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 ,...
Namespace for ROOT features in testing.
std::function< bool(ArgTypes...)> NotHelper(ROOT::TypeTraits::TypeList< ArgTypes... >, F &&f)
ROOT::RDF::Experimental::RResultMap< T > MakeResultMap(std::shared_ptr< T > nominalResult, std::vector< std::shared_ptr< T > > &&variedResults, std::vector< std::string > &&keys, RLoopManager &lm, std::shared_ptr< ROOT::Internal::RDF::RActionBase > nominalAction, std::shared_ptr< ROOT::Internal::RDF::RActionBase > variedAction)
auto PassAsVec(F &&f) -> PassAsVecHelper< std::make_index_sequence< N >, T, F >
void ThreadsPerTH3(unsigned int nThread=1)
Set the number of threads sharing one TH3 in RDataFrame.
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 PassAsVec(F &&f) -> RDFInternal::PassAsVecHelper< std::make_index_sequence< N >, T, F >
PassAsVec is a callable generator that allows passing N variables of type T to a function as a single...
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 ...
RInterface<::ROOT::Detail::RDF::RNodeBase > RNode
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.
Lightweight storage for a collection of types.