Skip to content

Commit

Permalink
[skip-ci][RDF] clang-format some RDF tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silverweed authored and guitargeek committed Jun 13, 2024
1 parent 5b0c854 commit 703351a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 82 deletions.
13 changes: 9 additions & 4 deletions tree/dataframe/inc/ROOT/RSnapshotOptions.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ struct RSnapshotOptions {
RSnapshotOptions(RSnapshotOptions &&) = default;
RSnapshotOptions(std::string_view mode, ECAlgo comprAlgo, int comprLevel, int autoFlush, int splitLevel, bool lazy,
bool overwriteIfExists = false)
: fMode(mode), fCompressionAlgorithm(comprAlgo), fCompressionLevel{comprLevel}, fAutoFlush(autoFlush),
fSplitLevel(splitLevel), fLazy(lazy), fOverwriteIfExists(overwriteIfExists)
: fMode(mode),
fCompressionAlgorithm(comprAlgo),
fCompressionLevel{comprLevel},
fAutoFlush(autoFlush),
fSplitLevel(splitLevel),
fLazy(lazy),
fOverwriteIfExists(overwriteIfExists)
{
}
std::string fMode = "RECREATE"; ///< Mode of creation of output file
Expand All @@ -38,7 +43,7 @@ struct RSnapshotOptions {
bool fLazy = false; ///< Do not start the event loop when Snapshot is called
bool fOverwriteIfExists = false; ///< If fMode is "UPDATE", overwrite object in output file if it already exists
};
} // ns RDF
} // ns ROOT
} // namespace RDF
} // namespace ROOT

#endif
38 changes: 19 additions & 19 deletions tree/dataframe/test/dataframe_cache.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ TEST(Cache, FundType)

TEST(Cache, Ambiguity)
{
// This test verifies that the correct method is called and there is no ambiguity between the JIT call to Cache using
// a column list as a parameter and the JIT call to Cache using the Regexp.
ROOT::RDataFrame tdf(5);
int i = 1;
auto d = tdf.Define("c0", [&i]() { return i++; }).Define("c1", []() { return 1.; });
// This test verifies that the correct method is called and there is no ambiguity between the JIT call to Cache using
// a column list as a parameter and the JIT call to Cache using the Regexp.
ROOT::RDataFrame tdf(5);
int i = 1;
auto d = tdf.Define("c0", [&i]() { return i++; }).Define("c1", []() { return 1.; });

auto cached_1 = d.Cache({"c0"});
auto cached_2 = d.Cache({"c0", "c1"});
auto cached_1 = d.Cache({"c0"});
auto cached_2 = d.Cache({"c0", "c1"});

auto c_1 = cached_1.Count();
auto c_2 = cached_2.Count();
auto c_1 = cached_1.Count();
auto c_2 = cached_2.Count();

EXPECT_EQ(5UL, *c_1);
EXPECT_EQ(5UL, *c_2);
EXPECT_EQ(5UL, *c_1);
EXPECT_EQ(5UL, *c_2);
}

/*
Expand Down Expand Up @@ -144,7 +144,7 @@ TEST(Cache, InternalColumnsSnapshot)
auto cached = orig.Cache<float, float>({colName, "dummy"});
auto snapshot = cached.Snapshot("t", "InternalColumnsSnapshot.root", "", {"RECREATE", ROOT::kZLIB, 0, 0, 99, false});

auto op = [&](){
auto op = [&]() {
testing::internal::CaptureStderr();
snapshot->Mean<ULong64_t>(colName);
};
Expand Down Expand Up @@ -205,10 +205,11 @@ TEST(Cache, evtCounter)
const std::vector<ULong64_t> evenE_ref{0, 2};
const std::vector<ULong64_t> allE_ref{0, 1};

auto test = [&](std::string_view entryColName){
auto c0 = ROOT::RDataFrame(4).Alias("entry", entryColName)
.Filter([](ULong64_t e) { return 0 == e % 2; }, {"entry"})
.Cache<ULong64_t>({"entry"});
auto test = [&](std::string_view entryColName) {
auto c0 = ROOT::RDataFrame(4)
.Alias("entry", entryColName)
.Filter([](ULong64_t e) { return 0 == e % 2; }, {"entry"})
.Cache<ULong64_t>({"entry"});
auto evenE = c0.Take<ULong64_t>("entry");
for (auto i : {0, 1}) {
EXPECT_EQ(evenE->at(i), evenE_ref[i]);
Expand All @@ -221,7 +222,6 @@ TEST(Cache, evtCounter)

test("tdfentry_");
test("rdfentry_");

}

TEST(Cache, Regex)
Expand Down Expand Up @@ -253,7 +253,7 @@ TEST(Cache, Regex)
std::string base("col_");
for (auto i : ROOT::TSeqI(128)) {
auto colName = base + std::to_string(i);
n = n.Define(colName, [](){return 0;});
n = n.Define(colName, []() { return 0; });
}
const auto df_even_cols = n.Cache(".*[02468]$").GetColumnNames();

Expand All @@ -265,7 +265,7 @@ TEST(Cache, Regex)
std::size_t cursor = 0u;
for (auto &&col : df_even_cols) {
EXPECT_TRUE(col == evenColNames[cursor]) << "Checking even columns. An error was encountered: expecting "
<< evenColNames[cursor] << " but found " << col;
<< evenColNames[cursor] << " but found " << col;
++cursor;
}

Expand Down
69 changes: 36 additions & 33 deletions tree/dataframe/test/dataframe_simple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ struct RFoo {};
TEST_P(RDFSimpleTests, Define_jitted_type_unknown_to_interpreter)
{
RDataFrame tdf(10);
auto d = tdf.Define("foo", [](){return RFoo();});
auto d2 = tdf.Define("foo2", [](){return std::array<RFoo, 2>();});
auto d = tdf.Define("foo", []() { return RFoo(); });
auto d2 = tdf.Define("foo2", []() { return std::array<RFoo, 2>(); });

// We check that if nothing is done with RFoo in jitted strings everything works fine
EXPECT_EQ(10U, *d.Count());
Expand Down Expand Up @@ -542,8 +542,6 @@ TEST_P(RDFSimpleTests, Aggregate)
EXPECT_EQ(*r2, 120);
}



TEST_P(RDFSimpleTests, AggregateGraph)
{
auto d = RDataFrame(20).DefineSlotEntry("x", [](unsigned int, ULong64_t e) { return static_cast<double>(e); });
Expand Down Expand Up @@ -592,7 +590,7 @@ TEST_P(RDFSimpleTests, Graph)
EXPECT_STREQ(dfGraph->GetXaxis()->GetTitle(), "x1");
EXPECT_STREQ(dfGraph->GetYaxis()->GetTitle(), "x2");

//To perform the test, it's easier to sort
// To perform the test, it's easier to sort
dfGraph->Sort();

Double_t x, y;
Expand All @@ -607,7 +605,7 @@ TEST_P(RDFSimpleTests, BookCustomAction)
{
RDataFrame d(1);
const auto nWorkers = std::max(1u, ROOT::GetThreadPoolSize());
const auto expected = nWorkers-1;
const auto expected = nWorkers - 1;

auto maxSlot0 = d.Book<unsigned int>(MaxSlotHelper(nWorkers), {"tdfslot_"});
auto maxSlot1 = d.Book<unsigned int>(MaxSlotHelper(nWorkers), {"rdfslot_"});
Expand All @@ -619,7 +617,7 @@ TEST_P(RDFSimpleTests, BookCustomActionJitted)
{
RDataFrame d(1);
const auto nWorkers = std::max(1u, ROOT::GetThreadPoolSize());
const auto expected = nWorkers-1;
const auto expected = nWorkers - 1;

auto maxSlot0 = d.Book(MaxSlotHelper(nWorkers), {"tdfslot_"});
auto maxSlot1 = d.Book(MaxSlotHelper(nWorkers), {"rdfslot_"});
Expand Down Expand Up @@ -737,7 +735,7 @@ TEST_P(RDFSimpleTests, StandardDeviationEmpty)

/*
/// This test was deactivated because it is not possible to Sum Strings using a Kahan Sum.
/// The reason is that there is no minus operator for that case.
/// The reason is that there is no minus operator for that case.
TEST(RDFSimpleTests, SumOfStrings)
{
auto df = RDataFrame(2).Define("str", []() -> std::string { return "bla"; });
Expand Down Expand Up @@ -792,16 +790,16 @@ TEST(RDFSimpleTests, GenVector)
// The leading underscore of "_hh" tests against ROOT-10305.
using MVector = ROOT::Math::PtEtaPhiMVector;
ROOT::RDataFrame t(1);
auto aa = t.Define("_hh", []() { return MVector(1, 1, 1, 1); })
.Define("h", [](MVector &v) { return v.Rapidity(); }, {"_hh"});
auto aa = t.Define("_hh", []() {
return MVector(1, 1, 1, 1);
}).Define("h", [](MVector &v) { return v.Rapidity(); }, {"_hh"});
auto m = aa.Mean<double>("h");
EXPECT_TRUE(0 != *m);
}

TEST(RDFSimpleTests, AutomaticNamesOfHisto1DAndGraph)
{
auto df = RDataFrame(1).Define("x", [](){return 1;})
.Define("y", [](){return 1;});
auto df = RDataFrame(1).Define("x", []() { return 1; }).Define("y", []() { return 1; });
auto hx = df.Histo1D<int>("x");
auto hxy = df.Histo1D<int, int>("x", "y");
auto gxy = df.Graph<int, int>("x", "y");
Expand All @@ -818,7 +816,6 @@ TEST(RDFSimpleTests, AutomaticNamesOfHisto1DAndGraph)
EXPECT_STREQ(gxy->GetTitle(), "y vs x");
EXPECT_STREQ(gxy->GetXaxis()->GetTitle(), "x");
EXPECT_STREQ(gxy->GetYaxis()->GetTitle(), "y");

}

TEST_P(RDFSimpleTests, DifferentTreesInDifferentThreads)
Expand Down Expand Up @@ -846,27 +843,30 @@ TEST_P(RDFSimpleTests, HistosOneWeightPerEvent)
{
using floats = std::vector<float>;
auto df = RDataFrame(1);
auto d = df.Define("v0", [](){floats v({1,2,3});return v;})
.Define("v1", [](){floats v({4,5,6});return v;})
.Define("v2", [](){floats v({7,8,9});return v;})
.Define("w",[](){return 3;});

auto h1 = d.Histo1D<floats, int>("v0","w");
// clang-format off
auto d = df.Define("v0", []() { floats v({1, 2, 3}); return v; })
.Define("v1", []() { floats v({4, 5, 6}); return v; })
.Define("v2", []() { floats v({7, 8, 9}); return v; })
.Define("w", []() { return 3; });
// clang-format on

auto h1 = d.Histo1D<floats, int>("v0", "w");
EXPECT_DOUBLE_EQ(h1->GetMean(), 2.);
auto h2 = d.Histo2D<floats, floats, int>({"","",16,0,16,16,0,16}, "v0", "v1", "w");
auto h2 = d.Histo2D<floats, floats, int>({"", "", 16, 0, 16, 16, 0, 16}, "v0", "v1", "w");
EXPECT_DOUBLE_EQ(h2->GetMean(), 2.);
auto h3 = d.Histo3D<floats, floats, floats, int>({"","",16,0,16,16,0,16,16,0,16},"v0", "v1", "v2", "w");
auto h3 = d.Histo3D<floats, floats, floats, int>({"", "", 16, 0, 16, 16, 0, 16, 16, 0, 16}, "v0", "v1", "v2", "w");
EXPECT_DOUBLE_EQ(h3->GetMean(), 2.);
}

TEST_P(RDFSimpleTests, ManyRangesPerWorker)
{
auto filename = "ManyRangesPerWorker_file.root";
{
ROOT::RDataFrame(184).Define("i",[](){return 0;})
.Snapshot<int>("t",filename,{"i"},{"RECREATE", ROOT::kZLIB, 1, 1, 99, false});
ROOT::RDataFrame(184)
.Define("i", []() { return 0; })
.Snapshot<int>("t", filename, {"i"}, {"RECREATE", ROOT::kZLIB, 1, 1, 99, false});
}
ROOT::RDataFrame("t",filename).Mean<int>("i");
ROOT::RDataFrame("t", filename).Mean<int>("i");
gSystem->Unlink(filename);
}

Expand Down Expand Up @@ -896,8 +896,9 @@ TEST_P(RDFSimpleTests, NonExistingFileInChain)
// in the single-thread case the error happens when TTreeReader is calling LoadTree the first time
// otherwise we notice the file does not exist beforehand, e.g. in TTreeProcessorMT
if (!ROOT::IsImplicitMTEnabled())
diagRAII.requiredDiag(kWarning, "TTreeReader::SetEntryBase()", "There was an issue opening the last file associated "
"to the TChain being processed.");
diagRAII.requiredDiag(kWarning, "TTreeReader::SetEntryBase()",
"There was an issue opening the last file associated "
"to the TChain being processed.");

bool exceptionCaught = false;
try {
Expand All @@ -918,12 +919,14 @@ TEST_P(RDFSimpleTests, NonExistingFileInChain)
TEST_P(RDFSimpleTests, Stats)
{
ROOT::RDataFrame r(256);
auto rr = r.Define("v", [](ULong64_t e){return e;}, {"rdfentry_"})
.Define("vec_v", [](ULong64_t e){return std::vector<ULong64_t>({e, e+1, e+2});}, {"v"})
.Define("w", [](ULong64_t e){return 1./(e+1);}, {"v"})
.Define("vec_w", [](double w){return std::vector<double>({w, w+1, w+2});}, {"w"})
.Define("one", [](){return 1.;})
.Define("ones", [](){return std::vector<double>({1.,1.,1.});});
// clang-format off
auto rr = r.Define("v", [](ULong64_t e) { return e; }, {"rdfentry_"})
.Define("vec_v", [](ULong64_t e) { return std::vector<ULong64_t>({e, e + 1, e + 2}); }, {"v"})
.Define("w", [](ULong64_t e) { return 1. / (e + 1); }, {"v"})
.Define("vec_w", [](double w) { return std::vector<double>({w, w + 1, w + 2}); }, {"w"})
.Define("one", []() { return 1.; })
.Define("ones", []() { return std::vector<double>({1., 1., 1.}); });
// clang-format on

auto s0 = rr.Stats("v");
auto s0c = rr.Stats<ULong64_t>("v");
Expand Down Expand Up @@ -1045,5 +1048,5 @@ INSTANTIATE_TEST_SUITE_P(Seq, RDFSimpleTests, ::testing::Values(false));

// run multi-thread tests
#ifdef R__USE_IMT
INSTANTIATE_TEST_SUITE_P(MT, RDFSimpleTests, ::testing::Values(true));
INSTANTIATE_TEST_SUITE_P(MT, RDFSimpleTests, ::testing::Values(true));
#endif
Loading

0 comments on commit 703351a

Please sign in to comment.