ATLAS Offline Software
Loading...
Searching...
No Matches
get_hdefs.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4
5'''
6make ordered list of .xml histogram definitions for
7 * input histogram title list (one per line)
8 * and an input .xml file (containing unordered superset
9 of input histo definitions)
10use-case: introducing some order in ~ 1k histograms InDetPVM produces
11'''
12import re
13import argparse
14
15from hist_bookkeep_utils import get_hbuff
16
17parser = argparse.ArgumentParser(
18 description='Get histogram xml blocks for list of id-s')
19
20parser.add_argument('--id',
21 dest='in_histid',
22 type=open,
23 required=True,
24 help='list of histogram id-s, one per line')
25
26parser.add_argument('--xml',
27 dest='in_xmldef',
28 type=open,
29 required=True,
30 help='xml file with histogram definitions')
31
32parser.add_argument('--c',
33 dest='comment',
34 required=False,
35 default='',
36 help='comment to put above each of the histograms')
37
38args = parser.parse_args()
39
40
42in_histid_name=args.in_histid.name
43in_xmldef_name=args.in_xmldef.name
44
45out_xmldef_name=in_xmldef_name.split(".")[0]+"_"+in_histid_name.split(".")[0]+".xml"
46out_missingdef_name=in_xmldef_name.split(".")[0]+"_"+in_histid_name.split(".")[0]+"_missing.txt"
47
48print('')
49print(' reading input histogram ids in: ', in_histid_name)
50print(' reading histogram xml definitions in: ', in_xmldef_name)
51print(' writing histogram definitions to: ', out_xmldef_name)
52print(' writing histos missing definitions to: ', out_missingdef_name)
53print('')
54
55out_xmldef=open(out_xmldef_name, 'w')
56out_missingdef=open(out_missingdef_name, 'w')
57
58
59for line in args.in_histid:
60 id=re.sub('\n','',line)
61 buff=get_hbuff(id,in_xmldef_name)
62 if not buff:
63 out_missingdef.write(id+'\n')
64 else:
65 for bline in buff:
66 out_xmldef.write(bline)
67
68
69
71out_xmldef.close()
72out_missingdef.close()
73
74print('')
75print('all done')
76print('')
void print(char *figname, TCanvas *c1)