forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrooteventselector.py
More file actions
executable file
·77 lines (59 loc) · 3.26 KB
/
rooteventselector.py
File metadata and controls
executable file
·77 lines (59 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env @python@
# ROOT command line tools: rooteventselector
# Author: Julien Ripoche
# Mail: julien.ripoche@u-psud.fr
# Date: 20/08/15
# Additions
# Author: Lawrence Lee
# Mail: lawrence.lee.jr@cern.ch
# Date: 1/4/16
"""Command line to copy subsets of trees from source ROOT files to new trees on a destination ROOT file"""
import cmdLineUtils
import sys
# Help strings
description = "Copy subsets of trees from source ROOT files"
FIRST_EVENT_HELP = "specify the first event to copy"
LAST_EVENT_HELP = "specify the last event to copy"
EPILOG="""Examples:
- rooteventselector source.root:tree dest.root
Copy the tree 'tree' from 'source.root' to 'dest.root'.
- rooteventselector -f 101 source.root:tree dest.root
Copy a subset of the tree 'tree' from 'source.root' to 'dest.root'. The new tree contains events from the old tree except the first hundred.
- rooteventselector -l 100 source.root:tree dest.root
Copy a subset of the tree 'tree' from 'source.root' to 'dest.root'. The new tree contains the first hundred events from the old tree.
- rooteventselector --recreate source.root:tree dest.root
Recreate the destination file 'dest.root' and copy the tree 'tree' from 'source.root' to 'dest.root'.
- rooteventselector -c 1 source.root:tree dest.root
Change the compression factor of the destination file 'dest.root' and copy the tree 'tree' from 'source.root' to 'dest.root'. For more information about compression settings of ROOT file, please look at the reference guide available on the ROOT site.
- rooteventselector -s "(branch1Value > 100)&&( branch2Value )" source.root:tree dest.root
Copy the tree 'tree' from 'source.root' to 'dest.root' and apply a selection to the output tree.
- rooteventselector -e "muon_*" source.root:tree dest.root
Copy the tree 'tree' from 'source.root' to 'dest.root' and remove branches matching "muon_*"
- rooteventselector -e "*" -i "muon_*" source.root:tree dest.root
Copy the tree 'tree' from 'source.root' to 'dest.root' and only write branches matching "muon_*"
"""
def get_argparse():
# Collect arguments with the module argparse
parser = cmdLineUtils.getParserSourceDest(description, EPILOG)
parser.prog = 'rooteventselector'
parser.add_argument("-c","--compress", type=int, help=cmdLineUtils.COMPRESS_HELP)
parser.add_argument("--recreate", help=cmdLineUtils.RECREATE_HELP, action="store_true")
parser.add_argument("-f","--first", type=int, default=0, help=FIRST_EVENT_HELP)
parser.add_argument("-l","--last", type=int, default=-1, help=LAST_EVENT_HELP)
parser.add_argument("-s","--selection", default="")
parser.add_argument("-i","--branchinclude", default="")
parser.add_argument("-e","--branchexclude", default="")
return parser
def execute():
parser = get_argparse()
# Put arguments in shape
sourceList, destFileName, destPathSplit, optDict = cmdLineUtils.getSourceDestListOptDict(parser)
# Process rootEventselector
return cmdLineUtils.rootEventselector(sourceList, destFileName, destPathSplit, \
compress=optDict["compress"], recreate=optDict["recreate"], \
first=optDict["first"], last=optDict["last"], \
selectionString=optDict["selection"], \
branchinclude=optDict["branchinclude"],\
branchexclude=optDict["branchexclude"])
if __name__ == "__main__":
sys.exit(execute())