Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Root
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
为了安全,强烈建议开启2FA双因子认证:User Settings -> Account -> Enable two-factor authentication!!!
Show more breadcrumbs
cxwx
Root
Commits
4fa4721b
Commit
4fa4721b
authored
6 years ago
by
Danilo Piparo
Browse files
Options
Downloads
Patches
Plain Diff
[Tree] Modernise and format copy tree tutorials
parent
936867ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tutorials/tree/copytree.C
+21
-21
21 additions, 21 deletions
tutorials/tree/copytree.C
tutorials/tree/copytree2.C
+20
-23
20 additions, 23 deletions
tutorials/tree/copytree2.C
tutorials/tree/copytree3.C
+23
-21
23 additions, 21 deletions
tutorials/tree/copytree3.C
with
64 additions
and
65 deletions
tutorials/tree/copytree.C
+
21
−
21
View file @
4fa4721b
...
...
@@ -10,31 +10,31 @@
///
/// \author Rene Brun
// Load the library at macro parsing time: we need this to use its content in the code
R__LOAD_LIBRARY
(
$
ROOTSYS
/
test
/
libEvent
.
so
)
void
copytree
()
{
//Get old file, old tree and set top branch address
TFile
*
oldfile
;
void
copytree
()
{
TString
dir
=
"$ROOTSYS/test/Event.root"
;
gSystem
->
ExpandPathName
(
dir
);
if
(
!
gSystem
->
AccessPathName
(
dir
))
{
oldfile
=
new
TFile
(
"$ROOTSYS/test/Event.root"
);}
else
{
oldfile
=
new
TFile
(
"./Event.root"
);}
TTree
*
oldtree
=
(
TTree
*
)
oldfile
->
Get
(
"T"
);
Event
*
event
=
new
Event
();
oldtree
->
SetBranchAddress
(
"event"
,
&
event
);
oldtree
->
SetBranchStatus
(
"*"
,
0
);
oldtree
->
SetBranchStatus
(
"event"
,
1
);
oldtree
->
SetBranchStatus
(
"fNtrack"
,
1
);
oldtree
->
SetBranchStatus
(
"fNseg"
,
1
);
oldtree
->
SetBranchStatus
(
"fH"
,
1
);
//Create a new file + a clone of old tree in new file
TFile
*
newfile
=
new
TFile
(
"small.root"
,
"recreate"
);
TTree
*
newtree
=
oldtree
->
CloneTree
();
const
auto
filename
=
gSystem
->
AccessPathName
(
dir
)
?
"./Event.root"
:
"$ROOTSYS/test/Event.root"
;
TFile
oldfile
(
filename
);
TTree
*
oldtree
;
oldfile
.
GetObject
(
"T"
,
oldtree
);
// Deactivate all branches
oldtree
->
SetBranchStatus
(
"*"
,
0
);
// Activate only four of them
for
(
auto
activeBranchName
:
{
"event"
,
"fNtrack"
,
"fNseg"
,
"fH"
})
oldtree
->
SetBranchStatus
(
activeBranchName
,
1
);
// Create a new file + a clone of old tree in new file
TFile
newfile
(
"small.root"
,
"recreate"
);
auto
newtree
=
oldtree
->
CloneTree
();
newtree
->
Print
();
newfile
->
Write
();
delete
oldfile
;
delete
newfile
;
newtree
->
Write
();
}
This diff is collapsed.
Click to expand it.
tutorials/tree/copytree2.C
+
20
−
23
View file @
4fa4721b
...
...
@@ -11,36 +11,33 @@
///
/// \author Rene Brun
// Load the library at macro parsing time: we need this to use its content in the code
R__LOAD_LIBRARY
(
$
ROOTSYS
/
test
/
libEvent
.
so
)
void
copytree2
()
{
void
copytree2
()
{
//Get old file, old tree and set top branch address
TFile
*
oldfile
;
TString
dir
=
"$ROOTSYS/test/Event.root"
;
gSystem
->
ExpandPathName
(
dir
);
if
(
!
gSystem
->
AccessPathName
(
dir
))
{
oldfile
=
new
TFile
(
"$ROOTSYS/test/Event.root"
);}
else
{
oldfile
=
new
TFile
(
"./Event.root"
);}
TTree
*
oldtree
=
(
TTree
*
)
oldfile
->
Get
(
"T"
);
Event
*
event
=
new
Event
();
oldtree
->
SetBranchAddress
(
"event"
,
&
event
);
oldtree
->
SetBranchStatus
(
"*"
,
0
);
oldtree
->
SetBranchStatus
(
"event"
,
1
);
oldtree
->
SetBranchStatus
(
"fNtrack"
,
1
);
oldtree
->
SetBranchStatus
(
"fNseg"
,
1
);
oldtree
->
SetBranchStatus
(
"fH"
,
1
);
//Create a new file + a clone of old tree header. Do not copy events
TFile
*
newfile
=
new
TFile
(
"small.root"
,
"recreate"
);
TTree
*
newtree
=
oldtree
->
CloneTree
(
0
);
//Divert branch fH to a separate file and copy all events
const
auto
filename
=
gSystem
->
AccessPathName
(
dir
)
?
"./Event.root"
:
"$ROOTSYS/test/Event.root"
;
TFile
oldfile
(
filename
);
TTree
*
oldtree
;
oldfile
.
GetObject
(
"T"
,
oldtree
);
// Activate only four of them
for
(
auto
activeBranchName
:
{
"event"
,
"fNtrack"
,
"fNseg"
,
"fH"
})
{
oldtree
->
SetBranchStatus
(
activeBranchName
,
1
);
}
// Create a new file + a clone of old tree header. Do not copy events
TFile
newfile
(
"small.root"
,
"recreate"
);
auto
newtree
=
oldtree
->
CloneTree
(
0
);
// Divert branch fH to a separate file and copy all events
newtree
->
GetBranch
(
"fH"
)
->
SetFile
(
"small_fH.root"
);
newtree
->
CopyEntries
(
oldtree
);
newtree
->
Print
();
newfile
->
Write
();
delete
oldfile
;
delete
newfile
;
newtree
->
Write
();
}
This diff is collapsed.
Click to expand it.
tutorials/tree/copytree3.C
+
23
−
21
View file @
4fa4721b
...
...
@@ -13,31 +13,33 @@
R__LOAD_LIBRARY
(
$
ROOTSYS
/
test
/
libEvent
.
so
)
void
copytree3
()
{
//Get old file, old tree and set top branch address
TFile
*
oldfile
;
void
copytree3
()
{
// Get old file, old tree and set top branch address
TString
dir
=
"$ROOTSYS/test/Event.root"
;
gSystem
->
ExpandPathName
(
dir
);
if
(
!
gSystem
->
AccessPathName
(
dir
))
{
oldfile
=
new
TFile
(
"$ROOTSYS/test/Event.root"
);}
else
{
oldfile
=
new
TFile
(
"./Event.root"
);}
TTree
*
oldtree
=
(
TTree
*
)
oldfile
->
Get
(
"T"
);
Long64_t
nentries
=
oldtree
->
GetEntries
();
Event
*
event
=
0
;
oldtree
->
SetBranchAddress
(
"event"
,
&
event
);
//Create a new file + a clone of old tree in new file
TFile
*
newfile
=
new
TFile
(
"small.root"
,
"recreate"
);
TTree
*
newtree
=
oldtree
->
CloneTree
(
0
);
for
(
Long64_t
i
=
0
;
i
<
nentries
;
i
++
)
{
const
auto
filename
=
gSystem
->
AccessPathName
(
dir
)
?
"./Event.root"
:
"$ROOTSYS/test/Event.root"
;
TFile
oldfile
(
filename
);
TTree
*
oldtree
;
oldfile
.
GetObject
(
"T"
,
oldtree
);
const
auto
nentries
=
oldtree
->
GetEntries
();
Event
*
event
=
nullptr
;
oldtree
->
SetBranchAddress
(
"event"
,
&
event
);
// Create a new file + a clone of old tree in new file
TFile
newfile
(
"small.root"
,
"recreate"
);
auto
newtree
=
oldtree
->
CloneTree
(
0
);
for
(
auto
i
:
ROOT
::
TSeqI
(
nentries
))
{
oldtree
->
GetEntry
(
i
);
if
(
event
->
GetNtrack
()
>
605
)
newtree
->
Fill
();
if
(
event
->
GetNtrack
()
>
605
)
newtree
->
Fill
();
event
->
Clear
();
}
newtree
->
Print
();
newtree
->
AutoSave
();
delete
oldfile
;
delete
newfile
;
newtree
->
Write
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment