Skip to content

Commit

Permalink
[DF] Rename SnapshotHelper -> SnapshotTTreeHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
enirolf committed Aug 19, 2024
1 parent c701f1f commit c086453
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
61 changes: 31 additions & 30 deletions tree/dataframe/inc/ROOT/RDF/ActionHelpers.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "Compression.h"
#include <string_view>
#include "ROOT/RVec.hxx"
#include "ROOT/TBufferMerger.hxx" // for SnapshotHelper
#include "ROOT/TBufferMerger.hxx" // for SnapshotTTreeHelper
#include "ROOT/RDF/RCutFlowReport.hxx"
#include "ROOT/RDF/RSampleInfo.hxx"
#include "ROOT/RDF/Utils.hxx"
Expand All @@ -35,14 +35,14 @@
#include "TClassRef.h"
#include "TDirectory.h"
#include "TError.h" // for R__ASSERT, Warning
#include "TFile.h" // for SnapshotHelper
#include "TFile.h" // for SnapshotTTreeHelper
#include "TH1.h"
#include "TGraph.h"
#include "TGraphAsymmErrors.h"
#include "TLeaf.h"
#include "TObject.h"
#include "TTree.h"
#include "TTreeReader.h" // for SnapshotHelper
#include "TTreeReader.h" // for SnapshotTTreeHelper
#include "TStatistic.h"
#include "ROOT/RDF/RActionImpl.hxx"
#include "ROOT/RDF/RMergeableValue.hxx"
Expand Down Expand Up @@ -1385,7 +1385,7 @@ void SetBranchesHelper(TTree *inputTree, TTree &outputTree, const std::string &i
branchAddress = nullptr;
}

/// Helper function for SnapshotHelper and SnapshotHelperMT. It creates new branches for the output TTree of a
/// Helper function for SnapshotTTreeHelper and SnapshotTTreeHelperMT. It creates new branches for the output TTree of a
/// Snapshot. This overload is called for columns of type `RVec<T>`. For RDF, these can represent:
/// 1. c-style arrays in ROOT files, so we are sure that there are input trees to which we can ask the correct branch
/// title
Expand Down Expand Up @@ -1487,11 +1487,12 @@ void SetBranchesHelper(TTree *inputTree, TTree &outputTree, const std::string &i
}
}

void ValidateSnapshotOutput(const RSnapshotOptions &opts, const std::string &treeName, const std::string &fileName);
void ValidateSnapshotTTreeOutput(const RSnapshotOptions &opts, const std::string &treeName,
const std::string &fileName);

/// Helper object for a single-thread TTree-based Snapshot action
template <typename... ColTypes>
class R__CLING_PTRCHECK(off) SnapshotHelper : public RActionImpl<SnapshotHelper<ColTypes...>> {
class R__CLING_PTRCHECK(off) SnapshotTTreeHelper : public RActionImpl<SnapshotTTreeHelper<ColTypes...>> {
std::string fFileName;
std::string fDirName;
std::string fTreeName;
Expand All @@ -1510,9 +1511,9 @@ class R__CLING_PTRCHECK(off) SnapshotHelper : public RActionImpl<SnapshotHelper<

public:
using ColumnTypes_t = TypeList<ColTypes...>;
SnapshotHelper(std::string_view filename, std::string_view dirname, std::string_view treename,
const ColumnNames_t &vbnames, const ColumnNames_t &bnames, const RSnapshotOptions &options,
std::vector<bool> &&isDefine)
SnapshotTTreeHelper(std::string_view filename, std::string_view dirname, std::string_view treename,
const ColumnNames_t &vbnames, const ColumnNames_t &bnames, const RSnapshotOptions &options,
std::vector<bool> &&isDefine)
: fFileName(filename),
fDirName(dirname),
fTreeName(treename),
Expand All @@ -1523,12 +1524,12 @@ public:
fBranchAddresses(vbnames.size(), nullptr),
fIsDefine(std::move(isDefine))
{
ValidateSnapshotOutput(fOptions, fTreeName, fFileName);
ValidateSnapshotTTreeOutput(fOptions, fTreeName, fFileName);
}

SnapshotHelper(const SnapshotHelper &) = delete;
SnapshotHelper(SnapshotHelper &&) = default;
~SnapshotHelper()
SnapshotTTreeHelper(const SnapshotTTreeHelper &) = delete;
SnapshotTTreeHelper(SnapshotTTreeHelper &&) = default;
~SnapshotTTreeHelper()
{
if (!fTreeName.empty() /*not moved from*/ && !fOutputFile /* did not run */ && fOptions.fLazy)
Warning("Snapshot", "A lazy Snapshot action was booked but never triggered.");
Expand Down Expand Up @@ -1626,27 +1627,27 @@ public:
}

/**
* @brief Create a new SnapshotHelper with a different output file name
* @brief Create a new SnapshotTTreeHelper with a different output file name
*
* @param newName A type-erased string with the output file name
* @return SnapshotHelper
* @return SnapshotTTreeHelper
*
* This MakeNew implementation is tied to the cloning feature of actions
* of the computation graph. In particular, cloning a Snapshot node usually
* also involves changing the name of the output file, otherwise the cloned
* Snapshot would overwrite the same file.
*/
SnapshotHelper MakeNew(void *newName)
SnapshotTTreeHelper MakeNew(void *newName)
{
const std::string finalName = *reinterpret_cast<const std::string *>(newName);
return SnapshotHelper{
return SnapshotTTreeHelper{
finalName, fDirName, fTreeName, fInputBranchNames, fOutputBranchNames, fOptions, std::vector<bool>(fIsDefine)};
}
};

/// Helper object for a multi-thread TTree-based Snapshot action
template <typename... ColTypes>
class R__CLING_PTRCHECK(off) SnapshotHelperMT : public RActionImpl<SnapshotHelperMT<ColTypes...>> {
class R__CLING_PTRCHECK(off) SnapshotTTreeHelperMT : public RActionImpl<SnapshotTTreeHelperMT<ColTypes...>> {
unsigned int fNSlots;
std::unique_ptr<ROOT::TBufferMerger> fMerger; // must use a ptr because TBufferMerger is not movable
std::vector<std::shared_ptr<ROOT::TBufferMergerFile>> fOutputFiles;
Expand All @@ -1668,9 +1669,9 @@ class R__CLING_PTRCHECK(off) SnapshotHelperMT : public RActionImpl<SnapshotHelpe

public:
using ColumnTypes_t = TypeList<ColTypes...>;
SnapshotHelperMT(const unsigned int nSlots, std::string_view filename, std::string_view dirname,
std::string_view treename, const ColumnNames_t &vbnames, const ColumnNames_t &bnames,
const RSnapshotOptions &options, std::vector<bool> &&isDefine)
SnapshotTTreeHelperMT(const unsigned int nSlots, std::string_view filename, std::string_view dirname,
std::string_view treename, const ColumnNames_t &vbnames, const ColumnNames_t &bnames,
const RSnapshotOptions &options, std::vector<bool> &&isDefine)
: fNSlots(nSlots),
fOutputFiles(fNSlots),
fOutputTrees(fNSlots),
Expand All @@ -1687,11 +1688,11 @@ public:
fOutputBranches(fNSlots),
fIsDefine(std::move(isDefine))
{
ValidateSnapshotOutput(fOptions, fTreeName, fFileName);
ValidateSnapshotTTreeOutput(fOptions, fTreeName, fFileName);
}
SnapshotHelperMT(const SnapshotHelperMT &) = delete;
SnapshotHelperMT(SnapshotHelperMT &&) = default;
~SnapshotHelperMT()
SnapshotTTreeHelperMT(const SnapshotTTreeHelperMT &) = delete;
SnapshotTTreeHelperMT(SnapshotTTreeHelperMT &&) = default;
~SnapshotTTreeHelperMT()
{
if (!fTreeName.empty() /*not moved from*/ && fOptions.fLazy &&
std::all_of(fOutputFiles.begin(), fOutputFiles.end(), [](const auto &f) { return !f; }) /* never run */)
Expand Down Expand Up @@ -1821,21 +1822,21 @@ public:
}

/**
* @brief Create a new SnapshotHelperMT with a different output file name
* @brief Create a new SnapshotTTreeHelperMT with a different output file name
*
* @param newName A type-erased string with the output file name
* @return SnapshotHelperMT
* @return SnapshotTTreeHelperMT
*
* This MakeNew implementation is tied to the cloning feature of actions
* of the computation graph. In particular, cloning a Snapshot node usually
* also involves changing the name of the output file, otherwise the cloned
* Snapshot would overwrite the same file.
*/
SnapshotHelperMT MakeNew(void *newName)
SnapshotTTreeHelperMT MakeNew(void *newName)
{
const std::string finalName = *reinterpret_cast<const std::string *>(newName);
return SnapshotHelperMT{fNSlots, finalName, fDirName, fTreeName,
fInputBranchNames, fOutputBranchNames, fOptions, std::vector<bool>(fIsDefine)};
return SnapshotTTreeHelperMT{fNSlots, finalName, fDirName, fTreeName,
fInputBranchNames, fOutputBranchNames, fOptions, std::vector<bool>(fIsDefine)};
}
};

Expand Down
6 changes: 3 additions & 3 deletions tree/dataframe/inc/ROOT/RDF/InterfaceUtils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ struct SnapshotHelperArgs {
bool fToNTuple;
};

// Snapshot action
// SnapshotTTree action
template <typename... ColTypes, typename PrevNodeType>
std::unique_ptr<RActionBase>
BuildAction(const ColumnNames_t &colNames, const std::shared_ptr<SnapshotHelperArgs> &snapHelperArgs,
Expand Down Expand Up @@ -297,14 +297,14 @@ BuildAction(const ColumnNames_t &colNames, const std::shared_ptr<SnapshotHelperA
} else {
if (!ROOT::IsImplicitMTEnabled()) {
// single-thread snapshot
using Helper_t = SnapshotHelper<ColTypes...>;
using Helper_t = SnapshotTTreeHelper<ColTypes...>;
using Action_t = RAction<Helper_t, PrevNodeType>;
actionPtr.reset(
new Action_t(Helper_t(filename, dirname, treename, colNames, outputColNames, options, std::move(isDefine)),
colNames, prevNode, colRegister));
} else {
// multi-thread snapshot
using Helper_t = SnapshotHelperMT<ColTypes...>;
using Helper_t = SnapshotTTreeHelperMT<ColTypes...>;
using Action_t = RAction<Helper_t, PrevNodeType>;
actionPtr.reset(new Action_t(
Helper_t(nSlots, filename, dirname, treename, colNames, outputColNames, options, std::move(isDefine)),
Expand Down
4 changes: 2 additions & 2 deletions tree/dataframe/inc/ROOT/RDF/RInterface.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3087,8 +3087,8 @@ private:
// The Snapshot helper will use validCols (with aliases resolved) as input columns, and
// columnListWithoutSizeColumns (still with aliases in it, passed through snapHelperArgs) as output column
// names.
resPtr = CreateAction<RDFInternal::ActionTags::Snapshot, ColumnTypes...>(validCols, newRDF, snapHelperArgs,
fProxiedPtr);
resPtr = CreateAction<RDFInternal::ActionTags::Snapshot, ColumnTypes...>(validCols, newRDF,
snapHelperArgs, fProxiedPtr);
}

if (!options.fLazy)
Expand Down
2 changes: 1 addition & 1 deletion tree/dataframe/src/RDFActionHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ template class TakeHelper<float, float, std::vector<float>>;
template class TakeHelper<double, double, std::vector<double>>;
#endif

void ValidateSnapshotOutput(const RSnapshotOptions &opts, const std::string &treeName, const std::string &fileName)
void ValidateSnapshotTTreeOutput(const RSnapshotOptions &opts, const std::string &treeName, const std::string &fileName)
{
TString fileMode = opts.fMode;
fileMode.ToLower();
Expand Down

0 comments on commit c086453

Please sign in to comment.