Skip to content

Commit 0a1fc96

Browse files
committed
[df] Improve semantics of data member
Change the data member holding the column names which should be ignored in case of TTreeReader errors regarding missing branches, from std::vector to std::set. The column names should not be repeated to avoid having multiple times the same column name left in the data member, which results in leftover names even after the corresponding operation of the computation graph has finished. Once a column is found, it will be available for all nodes of the computation graph anyway.
1 parent 45b2c98 commit 0a1fc96

10 files changed

+36
-33
lines changed

tree/dataframe/inc/ROOT/RDF/RDefaultValueFor.hxx

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public:
7676
{
7777
fLoopManager->Register(this);
7878
// We suppress errors that TTreeReader prints regarding the missing branch
79-
fLoopManager->GetSuppressErrorsForMissingBranches().push_back(fColumnNames[0]);
79+
fLoopManager->InsertSuppressErrorsForMissingBranch(fColumnNames[0]);
8080
}
8181

8282
RDefaultValueFor(const RDefaultValueFor &) = delete;
@@ -86,7 +86,7 @@ public:
8686
~RDefaultValueFor()
8787
{
8888
fLoopManager->Deregister(this);
89-
ROOT::Internal::RDF::Erase(fColumnNames[0], fLoopManager->GetSuppressErrorsForMissingBranches());
89+
fLoopManager->EraseSuppressErrorsForMissingBranch(fColumnNames[0]);
9090
}
9191

9292
void InitSlot(TTreeReader *r, unsigned int slot) final

tree/dataframe/inc/ROOT/RDF/RFilterWithMissingValues.hxx

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public:
8181
{
8282
fLoopManager->Register(this);
8383
// We suppress errors that TTreeReader prints regarding the missing branch
84-
fLoopManager->GetSuppressErrorsForMissingBranches().push_back(fColumnNames[0]);
84+
fLoopManager->InsertSuppressErrorsForMissingBranch(fColumnNames[0]);
8585
}
8686

8787
RFilterWithMissingValues(const RFilterWithMissingValues &) = delete;
@@ -93,7 +93,7 @@ public:
9393
// must Deregister objects from the RLoopManager here, before the fPrevNodePtr data member is destroyed:
9494
// otherwise if fPrevNodePtr is the RLoopManager, it will be destroyed before the calls to Deregister happen.
9595
fLoopManager->Deregister(this);
96-
ROOT::Internal::RDF::Erase(fColumnNames[0], fLoopManager->GetSuppressErrorsForMissingBranches());
96+
fLoopManager->EraseSuppressErrorsForMissingBranch(fColumnNames[0]);
9797
}
9898

9999
bool CheckFilters(unsigned int slot, Long64_t entry) final

tree/dataframe/inc/ROOT/RDF/RLoopManager.hxx

+14-7
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class RLoopManager : public RNodeBase {
196196
// List of branches for which we want to suppress the printed error about
197197
// missing branch when switching to a new tree. This is modified by readers,
198198
// so must be declared before them in this class.
199-
std::vector<std::string> fSuppressErrorsForMissingBranches{};
199+
std::set<std::string> fSuppressErrorsForMissingBranches{};
200200
ROOT::Internal::RDF::RStringCache fCachedColNames;
201201
std::set<std::pair<std::string_view, std::unique_ptr<ROOT::Internal::RDF::RDefinesWithReaders>>>
202202
fUniqueDefinesWithReaders;
@@ -293,15 +293,22 @@ public:
293293
return fUniqueVariationsWithReaders;
294294
}
295295

296-
std::vector<std::string> &GetSuppressErrorsForMissingBranches() { return fSuppressErrorsForMissingBranches; }
297-
const std::vector<std::string> &GetSuppressErrorsForMissingBranches() const
298-
{
299-
return fSuppressErrorsForMissingBranches;
300-
}
301-
302296
void SetTTreeLifeline(std::any lifeline);
303297

304298
void SetDataSource(std::unique_ptr<ROOT::RDF::RDataSource> dataSource);
299+
300+
void InsertSuppressErrorsForMissingBranch(const std::string &branchName)
301+
{
302+
fSuppressErrorsForMissingBranches.insert(branchName);
303+
}
304+
void EraseSuppressErrorsForMissingBranch(const std::string &branchName)
305+
{
306+
fSuppressErrorsForMissingBranches.erase(branchName);
307+
}
308+
const std::set<std::string> &GetSuppressErrorsForMissingBranches() const
309+
{
310+
return fSuppressErrorsForMissingBranches;
311+
}
305312
};
306313

307314
/// \brief Create an RLoopManager that reads a TChain.

tree/dataframe/src/RDFInterfaceUtils.cxx

+2-3
Original file line numberDiff line numberDiff line change
@@ -931,10 +931,9 @@ ColumnNames_t GetValidatedColumnNames(RLoopManager &lm, const unsigned int nColu
931931
// Look for a possible overlap between the unknown columns and the
932932
// columns we should ignore for the purpose of the following exception
933933
std::set<std::string> intersection;
934-
auto colsToIgnore = lm.GetSuppressErrorsForMissingBranches();
934+
const auto &colsToIgnore = lm.GetSuppressErrorsForMissingBranches();
935935
std::sort(unknownColumns.begin(), unknownColumns.end());
936-
std::sort(colsToIgnore.begin(), colsToIgnore.end());
937-
std::set_intersection(unknownColumns.begin(), unknownColumns.end(), colsToIgnore.begin(), colsToIgnore.end(),
936+
std::set_intersection(unknownColumns.cbegin(), unknownColumns.cend(), colsToIgnore.cbegin(), colsToIgnore.cend(),
938937
std::inserter(intersection, intersection.begin()));
939938
if (intersection.empty()) {
940939
std::string errMsg = std::string("Unknown column") + (unknownColumns.size() > 1 ? "s: " : ": ");

tree/treeplayer/inc/ROOT/TTreeProcessorMT.hxx

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public:
7272
const std::vector<std::string> &fileNames,
7373
const ROOT::TreeUtils::RFriendInfo &friendInfo,
7474
const TEntryList &entryList, const std::vector<Long64_t> &nEntries,
75-
const std::vector<std::string> &suppressErrorsForMissingBranches);
75+
const std::set<std::string> &suppressErrorsForMissingBranches);
7676
void Reset();
7777
};
7878
} // End of namespace Internal
@@ -97,7 +97,7 @@ private:
9797

9898
// List of branches for which we want to suppress the printed error about
9999
// missing branch when switching to a new tree
100-
std::vector<std::string> fSuppressErrorsForMissingBranches{};
100+
std::set<std::string> fSuppressErrorsForMissingBranches{};
101101

102102
public:
103103
TTreeProcessorMT(std::string_view filename, std::string_view treename = "", UInt_t nThreads = 0u,
@@ -109,10 +109,10 @@ public:
109109
const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()}):
110110
TTreeProcessorMT(std::vector<std::string_view>(filenames), treename, nThreads, globalRange) {}
111111
TTreeProcessorMT(TTree &tree, const TEntryList &entries, UInt_t nThreads = 0u,
112-
const std::vector<std::string> &suppressErrorsForMissingBranches = {});
112+
const std::set<std::string> &suppressErrorsForMissingBranches = {});
113113
TTreeProcessorMT(TTree &tree, UInt_t nThreads = 0u,
114114
const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()},
115-
const std::vector<std::string> &suppressErrorsForMissingBranches = {});
115+
const std::set<std::string> &suppressErrorsForMissingBranches = {});
116116

117117
void Process(std::function<void(TTreeReader &)> func);
118118

tree/treeplayer/inc/TTreeReader.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <deque>
3030
#include <iterator>
3131
#include <unordered_map>
32+
#include <set>
3233
#include <string>
3334

3435
class TDictionary;
@@ -184,7 +185,7 @@ class TTreeReader : public TObject {
184185
TTreeReader();
185186

186187
TTreeReader(TTree *tree, TEntryList *entryList = nullptr, bool warnAboutLongerFriends = true,
187-
const std::vector<std::string> &suppressErrorsForMissingBranches = {});
188+
const std::set<std::string> &suppressErrorsForMissingBranches = {});
188189
TTreeReader(const char *keyname, TDirectory *dir, TEntryList *entryList = nullptr);
189190
TTreeReader(const char *keyname, TEntryList *entryList = nullptr) : TTreeReader(keyname, nullptr, entryList) {}
190191

@@ -338,7 +339,7 @@ class TTreeReader : public TObject {
338339

339340
// List of branches for which we want to suppress the printed error about
340341
// missing branch when switching to a new tree
341-
std::vector<std::string> fSuppressErrorsForMissingBranches{};
342+
std::set<std::string> fSuppressErrorsForMissingBranches{};
342343
std::vector<std::string> fMissingProxies{};
343344

344345
friend class ROOT::Internal::TTreeReaderValueBase;

tree/treeplayer/src/TTreeProcessorMT.cxx

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ std::unique_ptr<TTreeReader>
288288
TTreeView::GetTreeReader(Long64_t start, Long64_t end, const std::vector<std::string> &treeNames,
289289
const std::vector<std::string> &fileNames, const ROOT::TreeUtils::RFriendInfo &friendInfo,
290290
const TEntryList &entryList, const std::vector<Long64_t> &nEntries,
291-
const std::vector<std::string> &suppressErrorsForMissingBranches)
291+
const std::set<std::string> &suppressErrorsForMissingBranches)
292292
{
293293
const bool hasEntryList = entryList.GetN() > 0;
294294
const bool usingLocalEntries = friendInfo.fFriendNames.empty() && !hasEntryList;
@@ -412,7 +412,7 @@ TTreeProcessorMT::TTreeProcessorMT(const std::vector<std::string_view> &filename
412412
/// \param[in] nThreads Number of threads to create in the underlying thread-pool. The semantics of this argument are
413413
/// the same as for TThreadExecutor.
414414
TTreeProcessorMT::TTreeProcessorMT(TTree &tree, const TEntryList &entries, UInt_t nThreads,
415-
const std::vector<std::string> &suppressErrorsForMissingBranches)
415+
const std::set<std::string> &suppressErrorsForMissingBranches)
416416
: fFileNames(Internal::TreeUtils::GetFileNamesFromTree(tree)),
417417
fTreeNames(Internal::TreeUtils::GetTreeFullPaths(tree)),
418418
fEntryList(entries),
@@ -430,7 +430,7 @@ TTreeProcessorMT::TTreeProcessorMT(TTree &tree, const TEntryList &entries, UInt_
430430
/// the same as for TThreadExecutor.
431431
/// \param[in] globalRange Global entry range to process, {begin (inclusive), end (exclusive)}.
432432
TTreeProcessorMT::TTreeProcessorMT(TTree &tree, UInt_t nThreads, const EntryRange &globalRange,
433-
const std::vector<std::string> &suppressErrorsForMissingBranches)
433+
const std::set<std::string> &suppressErrorsForMissingBranches)
434434
: fFileNames(Internal::TreeUtils::GetFileNamesFromTree(tree)),
435435
fTreeNames(Internal::TreeUtils::GetTreeFullPaths(tree)),
436436
fFriendInfo(Internal::TreeUtils::GetFriendInfo(tree, /*retrieveEntries*/ true)),

tree/treeplayer/src/TTreeReader.cxx

+3-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ TTreeReader::TTreeReader() : fNotify(this), fFriendProxies() {}
201201
/// per chain.SetEntryList(&entryList).
202202

203203
TTreeReader::TTreeReader(TTree *tree, TEntryList *entryList /*= nullptr*/, bool warnAboutLongerFriends,
204-
const std::vector<std::string> &suppressErrorsForMissingBranches)
204+
const std::set<std::string> &suppressErrorsForMissingBranches)
205205
: fTree(tree),
206206
fEntryList(entryList),
207207
fNotify(this),
@@ -384,9 +384,8 @@ bool TTreeReader::SetProxies()
384384
// where the first tree of the chain does not contain that branch. In such
385385
// case, we need to postpone the creation of the corresponding proxy until
386386
// we find the branch in a following tree of the chain.
387-
const bool suppressErrorsForThisBranch =
388-
(std::find(fSuppressErrorsForMissingBranches.cbegin(), fSuppressErrorsForMissingBranches.cend(),
389-
reader->fBranchName.View()) != fSuppressErrorsForMissingBranches.cend());
387+
const bool suppressErrorsForThisBranch = (fSuppressErrorsForMissingBranches.find(reader->fBranchName.Data()) !=
388+
fSuppressErrorsForMissingBranches.cend());
390389
// Because of the situation described above, we may have some proxies
391390
// already created and some not, if their branch was not available so far.
392391
// Make sure we do not recreate the proxy unnecessarily, unless the

tree/treeplayer/src/TTreeReaderArray.cxx

+2-4
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,8 @@ void ROOT::Internal::TTreeReaderArrayBase::CreateProxy()
547547

548548
// Tell the branch proxy to suppress the errors for missing branch if this
549549
// branch name is found in the list of suppressions
550-
const bool suppressErrorsForThisBranch =
551-
(std::find(fTreeReader->fSuppressErrorsForMissingBranches.cbegin(),
552-
fTreeReader->fSuppressErrorsForMissingBranches.cend(),
553-
fBranchName.Data()) != fTreeReader->fSuppressErrorsForMissingBranches.cend());
550+
const bool suppressErrorsForThisBranch = (fTreeReader->fSuppressErrorsForMissingBranches.find(fBranchName.Data()) !=
551+
fTreeReader->fSuppressErrorsForMissingBranches.cend());
554552

555553
TDictionary *branchActualType = nullptr;
556554
TBranch *branch = nullptr;

tree/treeplayer/src/TTreeReaderValue.cxx

+1-2
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ void ROOT::Internal::TTreeReaderValueBase::CreateProxy()
544544
// one tree in the chain has that branch
545545
const auto &suppressErrorsForMissingBranches = fTreeReader->fSuppressErrorsForMissingBranches;
546546
const bool suppressErrorsForThisBranch =
547-
(std::find(suppressErrorsForMissingBranches.cbegin(), suppressErrorsForMissingBranches.cend(),
548-
originalBranchName) != suppressErrorsForMissingBranches.cend());
547+
(suppressErrorsForMissingBranches.find(originalBranchName) != suppressErrorsForMissingBranches.cend());
549548

550549
if (!branch) {
551550
// We had an error, the branch name had no "." or we simply did not find anything.

0 commit comments

Comments
 (0)