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