Skip to content

Commit 3bdfe7b

Browse files
committed
[RDF] Extend the tests for #20320
1 parent cd2db41 commit 3bdfe7b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tree/dataframe/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ if(pyroot)
161161
endif()
162162
if(NOT MSVC OR win_broken_tests)
163163
ROOT_ADD_PYUNITTEST(dataframe_merge_results dataframe_merge_results.py)
164+
ROOT_ADD_PYUNITTEST(dataframe_snapshot_py dataframe_snapshot.py)
164165
endif()
165166
endif()
166167

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import unittest
2+
import ROOT
3+
4+
class SnapshotTests(unittest.TestCase):
5+
@classmethod
6+
def setUpClass(cls):
7+
# load all libs and autoparse
8+
df=ROOT.ROOT.RDataFrame(1)
9+
10+
# Regression described in https://github.com/root-project/root/issues/20320#issuecomment-3553697692
11+
# This was caused by an iterator invalidation when snapshots with JIT-ted filters is used
12+
def test_snapshot(self):
13+
df = ROOT.RDataFrame(10) #"Events", "root://eoscms.cern.ch//eos/cms/store/cmst3/group/tthlep/rdftests/TTJets_RunIISummer20UL18NanoAODv9.root")
14+
for var in ['pt', 'eta', 'phi', 'pdgId', 'mass', 'tightId', 'pfIsoId', 'deltaEtaSC', 'cutBased']:
15+
df = df.Define("Muon_%s"%var, "ROOT::RVec<float>(2, 1.)")
16+
df = df.Define("Electron_%s"%var, "ROOT::RVec<float>(2, 1.)")
17+
for var in ['pt', 'eta', 'phi', 'pdgId', 'mass']:
18+
for var2 in []:
19+
df = df.Define("Muon_good_%s"%var2, "ROOT::RVec<float>(2, 1.)")
20+
df = df.Define( "Muon_good_%s"%var, "Muon_%s[abs(Muon_eta) < 2.4 && Muon_pt > 0 && Muon_tightId && Muon_pfIsoId >= 0]"%var)
21+
for var in ['pt', 'eta', 'phi', 'pdgId', 'mass']:
22+
df = df.Define("Electron_good_%s"%var, "Electron_%s[!(abs(Electron_eta+Electron_deltaEtaSC)>0 && abs(Electron_eta+Electron_deltaEtaSC)< 0) && abs(Electron_eta)<2.4 && Electron_pt > 0 && Electron_cutBased > 0]"%var)
23+
24+
25+
df = df.Define("Muon_IDSF", "1+0.01*(Muon_pt-40)")
26+
df = df.Vary("Muon_IDSF", "ROOT::VecOps::RVec<ROOT::VecOps::RVec<float>>({1+0.005*(Muon_pt-40), 1+0.02*(Muon_pt-40)})", ['down', 'up'], "muon_unc")
27+
df = df.Define("Electron_IDSF", "1+0.01*(Electron_pt-40)")
28+
df = df.Vary("Electron_IDSF", "ROOT::VecOps::RVec<ROOT::VecOps::RVec<float>>({1+0.005*(Electron_pt-40), 1+0.02*(Electron_pt-40)})", ['down', 'up'], "electron_unc")
29+
30+
df = df.Filter("(Muon_good_pt.size() + Electron_good_pt.size()) > 0")
31+
32+
comprAlgo = getattr(ROOT.RCompressionSetting.EAlgorithm, "kZLIB")
33+
opts = ROOT.RDF.RSnapshotOptions("RECREATE", comprAlgo, 0, 0, 99, False)
34+
opts.fIncludeVariations = True
35+
36+
snapshot = df.Snapshot( "Events", "output.root", ["Electron_IDSF", "Muon_IDSF"], opts)
37+
38+
with ROOT.TFile.Open("output.root") as f:
39+
tree = f.Get("Events")
40+
self.assertIsNotNone(tree)
41+
self.assertEqual(tree.GetEntries(), 10)
42+
43+
if __name__ == '__main__':
44+
unittest.main()

0 commit comments

Comments
 (0)