5 from DQMServices.FileIO.DQM
import DQMReader
6 from collections
import namedtuple
8 HistogramEntry = namedtuple(
'HistogramEntry', [
'type',
'bin_size',
'bin_count',
'extra',
'total_bytes'])
16 'TProfile': 8,
'TProfile2D': 8,
23 name = fn.split(
"/")[-1]
25 if hasattr(obj,
'ClassName'):
27 t =
str(obj.ClassName())
28 bin_size = self.BIN_SIZE.get(t,
None)
30 sys.stderr.write(
"warning: unknown root type: %s\n" % t)
34 bin_count = obj.GetNcells()
36 total_bytes = bin_count * bin_size + extra
38 self.
_all[fn] = HistogramEntry(t, bin_size, bin_count, extra, total_bytes)
41 bin_count, bin_size, extra = 0, 0, len(
str(obj)) + len(fn)
42 total_bytes = bin_count * bin_size + extra
44 self.
_all[fn] = HistogramEntry(t, bin_size, bin_count, extra, total_bytes)
49 for k, v
in self._all.items():
50 group_key =
"/".
join(k.split(
"/")[:level])
52 current = group_stats.get(group_key, 0)
53 group_stats[group_key] = current + v.total_bytes
61 zero = HistogramEntry(
"null", 0, 0, 0, 0)
63 return HistogramEntry(b.type, b.bin_size,
64 a.bin_count - b.bin_count,
66 a.total_bytes - b.total_bytes )
68 for k, refv
in ref._all.items():
69 results._all[k] = cmp(self._all.get(k, zero), refv)
75 for prefix
in [
'KiB',
'MiB',
'GiB']:
79 return "%.2f %s" % (num, prefix)
82 group_stats = stats.group(args.depth)
84 cutoff, display = args.cutoff * 1024, args.display
86 as_list = [(v, k, )
for (k, v)
in group_stats.items()]
87 as_list.sort(reverse=
True, key=
lambda (v, k):
abs(v))
89 if cutoff
is not None:
90 as_list =
filter(
lambda (v, k):
abs(v) > cutoff, as_list)
92 if display
is not None:
93 as_list = as_list[:display]
97 print (
" DQM level %d folder breakdown " % args.depth).center(80,
"*")
99 print (
"* Size cutoff: %s" %
kibisize(cutoff)).ljust(79) +
"*" 101 print (
"* Showing top %d entries." % display).ljust(79) +
"*" 110 if __name__ ==
'__main__':
114 parser.add_argument(
"-i",
"--input", help =
"Input DQM ROOT file")
115 parser.add_argument(
"-r",
"--ref", help =
"Reference DQM ROOT file (to diff)")
116 parser.add_argument(
"--summary", help =
"Dump summary", action =
"store_true")
117 parser.add_argument(
"-x",
"--human", help =
"Human readable output.", action =
"store_true")
118 parser.add_argument(
"-n",
"--display", help =
"Max entries to display in --summary.", type = int, default =
None)
119 parser.add_argument(
"-c",
"--cutoff", help =
"Max cutoff to display in --summary.", type = float, default = 512, metavar=
"KiB")
120 parser.add_argument(
"-d",
"--depth", help =
"Folder depth in --summary.", type = int, default = 2)
122 args = parser.parse_args()
125 reader = DQMReader(args.input)
126 for (fn, v)
in reader.read_objects():
131 reader = DQMReader(args.ref)
133 for (fn, v)
in reader.read_objects():
134 ref_stats.analyze(fn, v)
137 stats = stats.difference(ref_stats)
142 total = stats.group(0)
144 print "Total bytes: %s" %
kibisize(total[
""])
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)