3 from __future__
import print_function
6 from DQMServices.FileIO.DQM
import DQMReader
7 from collections
import namedtuple
9 HistogramEntry = namedtuple(
'HistogramEntry', [
'type',
'bin_size',
'bin_count',
'extra',
'total_bytes'])
17 'TProfile': 8,
'TProfile2D': 8,
24 name = fn.split(
"/")[-1]
26 if hasattr(obj,
'ClassName'):
28 t =
str(obj.ClassName())
29 bin_size = self.BIN_SIZE.get(t,
None)
31 sys.stderr.write(
"warning: unknown root type: %s\n" % t)
35 bin_count = obj.GetNcells()
37 total_bytes = bin_count * bin_size + extra
39 self.
_all[fn] = HistogramEntry(t, bin_size, bin_count, extra, total_bytes)
44 bin_count, bin_size, extra = 0, 0, 10 + len(fn)
45 total_bytes = bin_count * bin_size + extra
47 self.
_all[fn] = HistogramEntry(t, bin_size, bin_count, extra, total_bytes)
49 def group(self, level, countObjects):
52 for k, v
in self._all.items():
53 group_key =
"/".
join(k.split(
"/")[:level])
55 current = group_stats.get(group_key, 0)
56 group_stats[group_key] = current + (1
if countObjects
else v.total_bytes)
64 zero = HistogramEntry(
"null", 0, 0, 0, 0)
66 return HistogramEntry(b.type, b.bin_size,
67 a.bin_count - b.bin_count,
69 a.total_bytes - b.total_bytes )
71 for k, refv
in ref._all.items():
72 results._all[k] = cmp(self._all.get(k, zero), refv)
80 pStr=
"%."+
str(args.precision)+
"f %s" 81 for prefix
in [
'KiB',
'MiB',
'GiB']:
84 if num < 1024.0
or args.units == prefix:
85 return pStr % (num, prefix)
86 return pStr % (num, prefix)
89 group_stats = stats.group(args.depth, args.count)
91 cutoff, display = args.cutoff * 1024, args.display
93 as_list = [(v, k, )
for (k, v)
in group_stats.items()]
94 as_list.sort(reverse=
True, key=
lambda v_k1:
abs(v_k1[0]))
96 if cutoff
is not None:
97 as_list = [v_k
for v_k
in as_list
if abs(v_k[0]) > cutoff]
99 if display
is not None:
100 as_list = as_list[:display]
104 print((
" DQM level %d folder breakdown " % args.depth).center(80,
"*"))
106 print((
"* Size cutoff: %s" %
kibisize(cutoff,args)).ljust(79) +
"*")
108 print((
"* Showing top %d entries." % display).ljust(79) +
"*")
117 if __name__ ==
'__main__':
120 parser = argparse.ArgumentParser()
121 parser.add_argument(
"-i",
"--input", help =
"Input DQM ROOT file")
122 parser.add_argument(
"-r",
"--ref", help =
"Reference DQM ROOT file (to diff)")
123 parser.add_argument(
"--summary", help =
"Dump summary", action =
"store_true")
124 parser.add_argument(
"--count", help =
"Count Histograms", action =
"store_true")
125 parser.add_argument(
"-x",
"--human", help =
"Human readable output.", action =
"store_true")
126 parser.add_argument(
"-n",
"--display", help =
"Max entries to display in --summary.", type = int, default =
None)
127 parser.add_argument(
"-c",
"--cutoff", help =
"Max cutoff to display in --summary.", type = float, default = 512, metavar=
"KiB")
128 parser.add_argument(
"-d",
"--depth", help =
"Folder depth in --summary.", type = int, default = 2)
129 parser.add_argument(
"-u",
"--units", help =
"Memory units to use (KiB,MiB,GiB) if fixed output desired", type = str, default =
"None")
130 parser.add_argument(
"-p",
"--precision", help =
"Places after decimal to display.", type = int, default = 2)
132 args = parser.parse_args()
135 reader = DQMReader(args.input)
136 for (fn, v)
in reader.read_objects():
141 reader = DQMReader(args.ref)
143 for (fn, v)
in reader.read_objects():
144 ref_stats.analyze(fn, v)
147 stats = stats.difference(ref_stats)
152 total = stats.group(0, args.count)
S & print(S &os, JobReport::InputFile const &f)
def group(self, level, countObjects)
def analyze(self, fn, obj)
Abs< T >::type abs(const T &t)
def difference(self, ref)
static std::string join(char **cmd)
def displayDirectoryStatistics(stats, args)