Skip to content

Commit 5c88ac1

Browse files
committed
[tutorials] Make ttree tutorials independent of test files
Copy over some test files to the build and install tree to the tutorials directory, in order to enable some more TTree tutorials for testing. Closes #13548.
1 parent e7a6629 commit 5c88ac1

File tree

6 files changed

+93
-40
lines changed

6 files changed

+93
-40
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ if(roofit)
424424
endif()
425425

426426
ROOT_ADD_TEST_SUBDIRECTORY(test)
427-
ROOT_ADD_TEST_SUBDIRECTORY(tutorials)
428427

429428
# Each subdirectory added above will register headers to be copied to the build tree.
430429
# Here, the copy targets are created:
@@ -574,6 +573,8 @@ if(runtime_cxxmodules)
574573
set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES "${library_output_dir}/modules.timestamp")
575574
endif()
576575

576+
ROOT_ADD_TEST_SUBDIRECTORY(tutorials)
577+
577578
#---hsimple.root---------(use the executable for clearer dependencies and proper return code)---
578579
add_custom_target(hsimple ALL DEPENDS tutorials/hsimple.root)
579580
add_dependencies(hsimple onepcm)

tutorials/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ if(DEFINED ROOT_SOURCE_DIR) # Testing using the binary tree
2020
set(ROOT_environ PATH=${CMAKE_BINARY_DIR}/bin:$ENV{PATH}
2121
${ld_library_path}=${CMAKE_BINARY_DIR}/lib:$ENV{${ld_library_path}}
2222
ROOTSYS=${CMAKE_BINARY_DIR}
23+
ROOT_INCLUDE_PATH=${CMAKE_BINARY_DIR}/tutorials/io/tree
2324
PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH})
2425
else()
2526
set(ROOT_environ ROOTSYS=${CMAKE_BINARY_DIR}
27+
ROOT_INCLUDE_PATH=${CMAKE_BINARY_DIR}/tutorials/io/tree
2628
PYTHONPATH=${CMAKE_BINARY_DIR}/bin;$ENV{PYTHONPATH})
2729
endif()
2830
else() # testing using an installation
@@ -423,7 +425,6 @@ set(extra_veto
423425
io/tree/hsimpleProxy.C # A driver uses this macro which cannot be executed directly
424426
io/tree/tree103_tree.C
425427
io/tree/tree106_tree.C
426-
io/tree/tree108_tree.C
427428
roofit/roostats/rs401d_FeldmanCousins.C # Takes too much time
428429
roofit/roostats/rs401d_FeldmanCousins.py
429430
roofit/histfactory/ModifyInterpolation.C
@@ -437,6 +438,11 @@ set(extra_veto
437438
math/r/rootlogon.C
438439
roofit/roostats/StandardFrequentistDiscovery.C)
439440

441+
configure_file(${CMAKE_SOURCE_DIR}/test/Event.h ${CMAKE_BINARY_DIR}/tutorials/io/tree/Event.h COPYONLY)
442+
configure_file(${CMAKE_SOURCE_DIR}/test/Event.cxx ${CMAKE_BINARY_DIR}/tutorials/io/tree/Event.cxx COPYONLY)
443+
install(FILES ${CMAKE_SOURCE_DIR}/test/Event.h ${CMAKE_SOURCE_DIR}/test/Event.cxx
444+
DESTINATION ${CMAKE_INSTALL_TUTDIR}/io/tree COMPONENT tests)
445+
440446
if(MSVC)
441447
# disable run_h1analysis.C because of Endpoint Security HTTP traffic scanning,
442448
# which is corrupting the data on Windows
@@ -549,6 +555,9 @@ set(io-xml-xmlmodifyfile-depends tutorial-io-xml-xmlnewfile)
549555
set(io-xml-xmlreadfile-depends tutorial-io-xml-xmlnewfile)
550556
set(roofit-roofit-rf503_wspaceread-depends tutorial-roofit-roofit-rf502_wspacewrite)
551557
set(io-readCode-depends tutorial-io-importCode)
558+
set(io-tree-tree110_copy-depends tutorial-io-tree-tree108_tree)
559+
set(io-tree-tree111_copy-depends tutorial-io-tree-tree108_tree)
560+
set(io-tree-tree112_copy-depends tutorial-io-tree-tree108_tree)
552561
set(math-fit-fit1-depends tutorial-hist-hist001_TH1_fillrandom)
553562
set(math-fit-myfit-depends tutorial-math-fit-fitslicesy)
554563
set(math-foam-foam_demopers-depends tutorial-math-foam-foam_demo)

tutorials/io/tree/tree108_tree.C

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
///
5050
/// \author Rene Brun
5151

52-
R__LOAD_LIBRARY($ROOTSYS/test/libEvent)
52+
53+
#ifdef ACTUAL_RUN // -------- Second pass: dictionary already built --------
54+
55+
#include "./Event.h" // now safe to include Event, its dictionary is loaded
5356

5457
#include "TFile.h"
5558
#include "TTree.h"
@@ -59,7 +62,6 @@ R__LOAD_LIBRARY($ROOTSYS/test/libEvent)
5962
#include "TClassTable.h"
6063
#include "TSystem.h"
6164
#include "TROOT.h"
62-
#include "../test/Event.h"
6365

6466
void tree108_write()
6567
{
@@ -168,10 +170,23 @@ void tree108_read()
168170
t4->StartViewer();
169171
}
170172

171-
void tree108_tree()
173+
void run()
172174
{
173175
Event::Reset(); // Allow for re-run this script by cleaning static variables.
174176
tree108_write();
175177
Event::Reset(); // Allow for re-run this script by cleaning static variables.
176178
tree108_read();
177179
}
180+
181+
#else // -------- First pass: build dictionary + rerun macro --------
182+
183+
void tree108_tree()
184+
{
185+
TString tutdir = gROOT->GetTutorialDir();
186+
gROOT->ProcessLine(".L " + tutdir + "/io/tree/Event.cxx+");
187+
gROOT->ProcessLine("#define ACTUAL_RUN yes");
188+
gROOT->ProcessLine("#include \"" __FILE__ "\"");
189+
gROOT->ProcessLine("run()");
190+
}
191+
192+
#endif

tutorials/io/tree/tree110_copy.C

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,40 @@
1010
///
1111
/// \author Rene Brun
1212

13-
// Load the library at macro parsing time: we need this to use its content in the code
14-
R__LOAD_LIBRARY($ROOTSYS/test/libEvent)
13+
#ifdef ACTUAL_RUN // -------- Second pass: dictionary already built --------
1514

16-
void tree110_copy()
17-
{
18-
19-
TString dir = "$ROOTSYS/test/Event.root";
20-
gSystem->ExpandPathName(dir);
21-
const auto filename = gSystem->AccessPathName(dir) ? "./Event.root" : "$ROOTSYS/test/Event.root";
15+
#include "./Event.h" // now safe to include Event, its dictionary is loaded
2216

23-
TFile oldfile(filename);
17+
void run()
18+
{
19+
TFile oldfile("tree108.root");
2420
TTree *oldtree;
25-
oldfile.GetObject("T", oldtree);
21+
oldfile.GetObject("t4", oldtree);
2622

2723
// Deactivate all branches
2824
oldtree->SetBranchStatus("*", 0);
2925

3026
// Activate only four of them
31-
for (auto activeBranchName : {"event", "fNtrack", "fNseg", "fH"})
27+
for (auto activeBranchName : {"event_split", "fNtrack", "fNseg", "fH"})
3228
oldtree->SetBranchStatus(activeBranchName, 1);
3329

3430
// Create a new file + a clone of old tree in new file
35-
TFile newfile("small.root", "recreate");
31+
TFile newfile("tree110.root", "recreate");
3632
auto newtree = oldtree->CloneTree();
3733

3834
newtree->Print();
3935
newfile.Write();
4036
}
37+
38+
#else // -------- First pass: build dictionary + rerun macro --------
39+
40+
void tree110_copy()
41+
{
42+
TString tutdir = gROOT->GetTutorialDir();
43+
gROOT->ProcessLine(".L " + tutdir + "/io/tree/Event.cxx+");
44+
gROOT->ProcessLine("#define ACTUAL_RUN yes");
45+
gROOT->ProcessLine("#include \"" __FILE__ "\"");
46+
gROOT->ProcessLine("run()");
47+
}
48+
49+
#endif

tutorials/io/tree/tree111_copy.C

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,23 @@
1111
///
1212
/// \author Rene Brun
1313

14-
// Load the library at macro parsing time: we need this to use its content in the code
15-
R__LOAD_LIBRARY($ROOTSYS/test/libEvent)
14+
#ifdef ACTUAL_RUN // -------- Second pass: dictionary already built --------
1615

17-
void tree111_copy()
18-
{
19-
20-
TString dir = "$ROOTSYS/test/Event.root";
21-
gSystem->ExpandPathName(dir);
22-
const auto filename = gSystem->AccessPathName(dir) ? "./Event.root" : "$ROOTSYS/test/Event.root";
16+
#include "./Event.h" // now safe to include Event, its dictionary is loaded
2317

24-
TFile oldfile(filename);
18+
void run()
19+
{
20+
TFile oldfile("tree108.root");
2521
TTree *oldtree;
26-
oldfile.GetObject("T", oldtree);
22+
oldfile.GetObject("t4", oldtree);
2723

2824
// Activate only four of them
29-
for (auto activeBranchName : {"event", "fNtrack", "fNseg", "fH"}) {
25+
for (auto activeBranchName : {"event_split", "fNtrack", "fNseg", "fH"}) {
3026
oldtree->SetBranchStatus(activeBranchName, 1);
3127
}
3228

3329
// Create a new file + a clone of old tree header. Do not copy events
34-
TFile newfile("small.root", "recreate");
30+
TFile newfile("tree111.root", "recreate");
3531
auto newtree = oldtree->CloneTree(0);
3632

3733
// Divert branch fH to a separate file and copy all events
@@ -41,3 +37,16 @@ void tree111_copy()
4137
newtree->Print();
4238
newfile.Write();
4339
}
40+
41+
#else // -------- First pass: build dictionary + rerun macro --------
42+
43+
void tree111_copy()
44+
{
45+
TString tutdir = gROOT->GetTutorialDir();
46+
gROOT->ProcessLine(".L " + tutdir + "/io/tree/Event.cxx+");
47+
gROOT->ProcessLine("#define ACTUAL_RUN yes");
48+
gROOT->ProcessLine("#include \"" __FILE__ "\"");
49+
gROOT->ProcessLine("run()");
50+
}
51+
52+
#endif

tutorials/io/tree/tree112_copy.C

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,23 @@
1111
///
1212
/// \author Rene Brun
1313

14-
R__LOAD_LIBRARY($ROOTSYS/test/libEvent)
14+
#ifdef ACTUAL_RUN // -------- Second pass: dictionary already built --------
1515

16-
void tree112_copy()
17-
{
18-
// Get old file, old tree and set top branch address
19-
TString dir = "$ROOTSYS/test/Event.root";
20-
gSystem->ExpandPathName(dir);
21-
const auto filename = gSystem->AccessPathName(dir) ? "./Event.root" : "$ROOTSYS/test/Event.root";
16+
#include "./Event.h" // now safe to include Event, its dictionary is loaded
2217

23-
TFile oldfile(filename);
18+
void run()
19+
{
20+
TFile oldfile("tree108.root");
2421
TTree *oldtree;
25-
oldfile.GetObject("T", oldtree);
22+
oldfile.GetObject("t4", oldtree);
2623

2724
const auto nentries = oldtree->GetEntries();
2825

2926
Event *event = nullptr;
30-
oldtree->SetBranchAddress("event", &event);
27+
oldtree->SetBranchAddress("event_split", &event);
3128

3229
// Create a new file + a clone of old tree in new file
33-
TFile newfile("small.root", "recreate");
30+
TFile newfile("tree112.root", "recreate");
3431
auto newtree = oldtree->CloneTree(0);
3532

3633
for (auto i : ROOT::TSeqI(nentries)) {
@@ -43,3 +40,16 @@ void tree112_copy()
4340
newtree->Print();
4441
newfile.Write();
4542
}
43+
44+
#else // -------- First pass: build dictionary + rerun macro --------
45+
46+
void tree112_copy()
47+
{
48+
TString tutdir = gROOT->GetTutorialDir();
49+
gROOT->ProcessLine(".L " + tutdir + "/io/tree/Event.cxx+");
50+
gROOT->ProcessLine("#define ACTUAL_RUN yes");
51+
gROOT->ProcessLine("#include \"" __FILE__ "\"");
52+
gROOT->ProcessLine("run()");
53+
}
54+
55+
#endif

0 commit comments

Comments
 (0)