10 from utilities
import *
17 tree = f.Get(tree_name)
20 counts[path] = (tree.GetEntries(), 1)
22 counts[path] = (tree.GetEntries(cut), 1)
23 except NonROOTFileError:
26 ePrint(
"Could not open "+path+
". Assuming 0 entries.")
30 if os.path.isfile(path):
34 for root, dirs, files
in os.walk(path, topdown=
False):
40 num_entries += counts[p][0]
41 num_files += counts[p][1]
43 if os.path.islink(os.path.join(root, d)):
continue 46 num_entries += counts[p][0]
47 num_files += counts[p][1]
48 counts[
fullPath(root)] = (num_entries, num_files)
51 for root, dirs, files
in os.walk(path):
53 level = root.replace(path,
"").count(os.sep)
55 if counts[p][1]>0
or root==path
or verbose:
56 print((
"{}"+Term.BOLD+Term.BLUE+
"{}"+Term.END+Term.END+
" [{} entries in {} ROOT files]")
57 .format(indent, os.path.basename(root),
58 locale.format(
"%d", counts[p][0], grouping=
True),
59 locale.format(
"%d", counts[p][1], grouping=
True)))
60 subindent =
" "*2*(level+1)
63 if counts[p][1]>0
and verbose:
64 print((
"{}"+Term.BOLD+Term.GREEN+
"{}"+Term.END+Term.END+
" [{} entries]")
66 locale.format(
"%d", counts[p][0], grouping=
True)))
69 locale.setlocale(locale.LC_ALL,
"en_US")
71 file_dirs = [
fullPath(f)
for sublist
in file_dirs
for f
in glob.glob(sublist) ]
74 for path
in file_dirs:
78 if __name__ ==
"__main__":
79 parser = argparse.ArgumentParser(description=
"Counts the number of entries in ROOT files and directories",
80 formatter_class = argparse.ArgumentDefaultsHelpFormatter)
81 parser.add_argument(
"-c",
"--cut", default=
None,
82 help=
"Count only arguments passing provided cut")
83 parser.add_argument(
"-t",
"--tree", default=
"tree",
84 help=
"Name of tree for which to count entries")
85 parser.add_argument(
"-e",
"--exclusive", action=
"store_true",
86 help=
"Count entries only in files in each directory, but not in its subdirectories.")
87 parser.add_argument(
"-v",
"--verbose", action=
"store_true",
88 help=
"Print entries for individual files.")
89 parser.add_argument(
"files", default=[
"."], nargs=
"*",
90 help=
"List of files and directories in which to count root files")
91 args = parser.parse_args()
93 countEntries(args.cut, args.files, args.tree, args.verbose, args.exclusive)
def countEntries(cut, file_dirs, tree, verbose, exclusive)
def countFile(cut, path, tree_name, counts)
def printCounts(path, counts, verbose)
def countRecursive(cut, path, tree, exclusive, counts)