Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
rooteventselector.py
Go to the documentation of this file.
1#!/usr/bin/env @python@
2
3# ROOT command line tools: rooteventselector
4# Author: Julien Ripoche
5# Mail: julien.ripoche@u-psud.fr
6# Date: 20/08/15
7
8# Additions
9# Author: Lawrence Lee
10# Mail: lawrence.lee.jr@cern.ch
11# Date: 1/4/16
12
13"""Command line to copy subsets of trees from source ROOT files to new trees on a destination ROOT file"""
14
15import cmdLineUtils
16import sys
17
18
19# Help strings
20description = "Copy subsets of trees from source ROOT files"
21
22FIRST_EVENT_HELP = "specify the first event to copy"
23LAST_EVENT_HELP = "specify the last event to copy"
24
25EPILOG="""Examples:
26- rooteventselector source.root:tree dest.root
27 Copy the tree 'tree' from 'source.root' to 'dest.root'.
28
29- rooteventselector -f 101 source.root:tree dest.root
30 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.
31
32- rooteventselector -l 100 source.root:tree dest.root
33 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.
34
35- rooteventselector --recreate source.root:tree dest.root
36 Recreate the destination file 'dest.root' and copy the tree 'tree' from 'source.root' to 'dest.root'.
37
38- rooteventselector -c 1 source.root:tree dest.root
39 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.
40
41- rooteventselector -s "(branch1Value > 100)&&( branch2Value )" source.root:tree dest.root
42 Copy the tree 'tree' from 'source.root' to 'dest.root' and apply a selection to the output tree.
43
44- rooteventselector -e "muon_*" source.root:tree dest.root
45 Copy the tree 'tree' from 'source.root' to 'dest.root' and remove branches matching "muon_*"
46
47- rooteventselector -e "*" -i "muon_*" source.root:tree dest.root
48 Copy the tree 'tree' from 'source.root' to 'dest.root' and only write branches matching "muon_*"
49"""
50
52 # Collect arguments with the module argparse
53 parser = cmdLineUtils.getParserSourceDest(description, EPILOG)
54 parser.prog = 'rooteventselector'
55 parser.add_argument("-c","--compress", type=int, help=cmdLineUtils.COMPRESS_HELP)
56 parser.add_argument("--recreate", help=cmdLineUtils.RECREATE_HELP, action="store_true")
57 parser.add_argument("-f","--first", type=int, default=0, help=FIRST_EVENT_HELP)
58 parser.add_argument("-l","--last", type=int, default=-1, help=LAST_EVENT_HELP)
59 parser.add_argument("-s","--selection", default="")
60 parser.add_argument("-i","--branchinclude", default="")
61 parser.add_argument("-e","--branchexclude", default="")
62 return parser
63
64def execute():
65 parser = get_argparse()
66 # Put arguments in shape
67 sourceList, destFileName, destPathSplit, optDict = cmdLineUtils.getSourceDestListOptDict(parser)
68
69 # Process rootEventselector
70 return cmdLineUtils.rootEventselector(sourceList, destFileName, destPathSplit, \
71 compress=optDict["compress"], recreate=optDict["recreate"], \
72 first=optDict["first"], last=optDict["last"], \
73 selectionString=optDict["selection"], \
74 branchinclude=optDict["branchinclude"],\
75 branchexclude=optDict["branchexclude"])
76if __name__ == "__main__":
77 sys.exit(execute())
rootEventselector(sourceList, destFileName, destPathSplit, compress=None, recreate=False, first=0, last=-1, selectionString="", branchinclude="", branchexclude="")
getParserSourceDest(theHelp, theEpilog="")
Get a commandline parser with the defaults of the commandline utils, a list of source files and a des...
getSourceDestListOptDict(parser, wildcards=True)
Get the list of tuples of sources, create destination name, destination pathSplit and the dictionary ...