ROOT
Version v6.32
master
v6.36
v6.34
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
▼
ROOT
ROOT Reference Documentation
Tutorials
►
Functional Parts
►
Namespaces
►
All Classes
▼
Files
▼
File List
►
bindings
►
core
►
documentation
►
geom
►
graf2d
►
graf3d
►
gui
►
hist
►
html
►
io
►
main
►
math
►
montecarlo
►
net
►
proof
►
roofit
►
sql
►
tmva
►
tree
▼
tutorials
►
cocoa
►
cont
►
dataframe
►
eve
►
eve7
►
fft
►
fit
►
fitsio
►
foam
►
geom
►
gl
►
graphics
►
graphs
►
gui
►
hist
►
histfactory
►
html
►
http
►
image
►
io
►
legacy
►
math
►
matrix
►
mc
►
multicore
►
net
►
physics
►
proof
►
pyroot
►
pythia
►
quadp
►
r
►
rcanvas
►
roofit
►
roostats
►
spectrum
►
splot
►
sql
►
tmva
▼
tree
▼
dictionary
data2Tree.cxx
►
data2Tree.hxx
data2TreeLinkDef.hxx
►
main.cpp
►
readTree.cxx
►
readTreeDF.cxx
►
writeTree.cxx
basic.C
basic2.C
bill.C
cernbuild.C
cernstaff.C
circular.C
clonesA_Event.C
clonesA_Event.cxx
►
clonesA_Event.h
copytree.C
copytree2.C
copytree3.C
drawsparse.C
h1analysis.C
►
h1analysis.h
h1analysisProxy.C
►
h1analysisProxy.h
►
h1analysisProxyCut.C
h1analysisTreeReader.C
►
h1analysisTreeReader.h
h1chain.C
hsimpleProxy.C
hsimpleProxyDriver.C
hsimpleReader.C
htest.C
hvector.C
JetEvent.cxx
►
JetEvent.h
jets.C
ntuple1.C
parallelcoord.C
parallelcoordtrans.C
printSizes.C
run_h1analysis.C
spider.C
staff.C
tcl.C
temperature.C
tree.C
tree0.C
tree1.C
tree2.C
tree2a.C
tree3.C
tree4.C
treefriend.C
treegetval.C
►
tv3.C
►
tvdemo.C
►
unfold
►
unuran
►
v7
►
vecops
►
webgui
►
xml
.rootlogon.py
demos.C
demoshelp.C
hsimple.C
rootlogoff.C
rootlogon.C
►
v6-32-00-patches
►
File Members
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
writeTree.cxx
Go to the documentation of this file.
1
// Author: Alvaro Tolosa-Delgado CERN 07/2023
2
// Author: Jorge Agramunt Ros IFIC(Valencia,Spain) 07/2023
3
4
/*************************************************************************
5
* Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. *
6
* All rights reserved. *
7
* *
8
* For the licensing terms see $ROOTSYS/LICENSE. *
9
* For the list of contributors see $ROOTSYS/README/CREDITS. *
10
*************************************************************************/
11
12
#include <iostream>
13
14
#include <
TFile.h
>
15
#include <
TTree.h
>
16
#include <
TTreeReader.h
>
17
#include <
TTreeReaderValue.h
>
18
19
#include "
data2Tree.hxx
"
20
21
void
writeTree
()
22
{
23
std::unique_ptr<TFile>
ofile
{
TFile::Open
(
"testFile.root"
,
"recreate"
)};
24
if
(!
ofile
||
ofile
->IsZombie()) {
25
throw
std::runtime_error(
"Could not open file testFile.root"
);
26
}
27
28
std::unique_ptr<TTree>
myTree
= std::make_unique<TTree>(
"myTree"
,
""
);
29
myDetectorData
obj_for_branch1
;
30
myDetectorData
obj_for_branch2
;
31
32
// NOTE: the dot at the end of the branch name is semantically relevant and recommended
33
// because it causes the sub-branch names to be prefixed by the name of the top level branch.
34
// Without the dot, the prefix is not there.
35
// Here, objects of the same class appear in multiple branches, adding the dot removes ambiguities.
36
myTree
->Branch(
"branch1."
, &
obj_for_branch1
);
37
myTree
->Branch(
"branch2."
, &
obj_for_branch2
);
38
39
for
(
int
i = 0; i < 10; ++i) {
40
//-- if i is even, fill branch2 and set branch1's entry to zero
41
if
(i % 2 == 0) {
42
obj_for_branch1
.clear();
43
obj_for_branch2
.time = i + 5;
44
obj_for_branch2
.energy = 2 * i + 5;
45
obj_for_branch2
.detectorID = 3 * i + 5;
46
}
47
//-- if i is odd, we do the opposite
48
else
{
49
obj_for_branch2
.clear();
50
obj_for_branch1
.time = i + 1;
51
obj_for_branch1
.energy = 2 * i + 1;
52
obj_for_branch1
.detectorID = 3 * i + 1;
53
}
54
myTree
->Fill();
55
}
56
57
myTree
->Print();
58
59
ofile
->Write();
// This write the files and the TTree
60
}
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
TFile.h
TTreeReaderValue.h
TTreeReader.h
TTree.h
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TFile::Open
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition
TFile.cxx:4094
myDetectorData
Definition
data2Tree.hxx:20
data2Tree.hxx
writeTree
void writeTree()
Definition
writeTree.cxx:21
tutorials
tree
dictionary
writeTree.cxx
ROOT v6-32 - Reference Guide Generated on Sun Apr 27 2025 05:42:52 (GVA Time) using Doxygen 1.10.0