Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
rootslimtree.py
Go to the documentation of this file.
1#!/usr/bin/env @python@
2
3# ROOT command line tools: rootslimtree
4# Author: Lawrence Lee via Julien Ripoche's rooteventselector
5# Mail: lawrence.lee.jr@cern.ch
6# Date: 4/4/16
7
8"""Command line to copy trees with subset of branches from source ROOT files to new trees on a destination ROOT file"""
9
10import cmdLineUtils
11import sys
12
13# Help strings
14COMMAND_HELP = "Copy trees with a subset of branches from source ROOT files"
15
16EPILOG="""Examples:
17- rootslimtree source.root:tree dest.root
18 Copy the tree 'tree' from 'source.root' to 'dest.root'.
19
20- rootslimtree --recreate source.root:tree dest.root
21 Recreate the destination file 'dest.root' and copy the tree 'tree' from 'source.root' to 'dest.root'.
22
23- rootslimtree -c 1 source.root:tree dest.root
24 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.
25
26- rootslimtree -e "muon_*" source.root:tree dest.root
27 Copy the tree 'tree' from 'source.root' to 'dest.root' and remove branches matching "muon_*"
28
29- rootslimtree -e "*" -i "muon_*" source.root:tree dest.root
30 Copy the tree 'tree' from 'source.root' to 'dest.root' and only write branches matching "muon_*"
31"""
32
34 # Collect arguments with the module argparse
35 parser = cmdLineUtils.getParserSourceDest(COMMAND_HELP, EPILOG)
36 parser.prog = 'rootslimtree'
37
38 parser.add_argument("-c","--compress", type=int, help=cmdLineUtils.COMPRESS_HELP)
39 parser.add_argument("--recreate", help=cmdLineUtils.RECREATE_HELP, action="store_true")
40 parser.add_argument("-i","--branchinclude", default="")
41 parser.add_argument("-e","--branchexclude", default="")
42
43 return parser
44
45def execute():
46 parser = get_argparse()
47
48 # Put arguments in shape
49 sourceList, destFileName, destPathSplit, optDict = cmdLineUtils.getSourceDestListOptDict(parser)
50
51 # Process rootEventselector in simplified slimtree mode
52 return cmdLineUtils.rootEventselector(sourceList, destFileName, destPathSplit, \
53 compress=optDict["compress"], recreate=optDict["recreate"], \
54 first=0, last=-1, \
55 selectionString="", \
56 branchinclude=optDict["branchinclude"],\
57 branchexclude=optDict["branchexclude"])
58if __name__ == "__main__":
59 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 ...