Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:26

0001 from __future__ import print_function
0002 from Cheetah.Template import Template
0003 from getopt import getopt
0004 from sys import argv, exit
0005 
0006 def usage():
0007   print("Usage: " + argv[0] + " -d histo_map_file -t template_file")
0008   print("  Arguments:")
0009   print("    -d, --data=    : file of histogram map")
0010   print("    -t, --tmpl=    : template file")
0011 
0012 
0013 def main():
0014 
0015   data = None
0016   tmpl = None
0017 
0018   try:
0019     opts, args = getopt(argv[1:], "d:t:", ["data=","tmpl="])
0020   except getopt.GetoptError as err:
0021     print(str(err))
0022     usage()
0023     exit(1)
0024 
0025   for o, a in opts:
0026     if o in ("-h", "--help"):
0027       usage()
0028       exit()
0029     elif o in ("-d", "--data"):
0030       data = a
0031     elif o in ("-t", "--tmpl"):
0032       tmpl = a
0033     else:
0034       print("unhandled option: " + o)
0035       usage()
0036       exit(2)
0037 
0038   if data == None or tmpl == None:
0039     usage()
0040     exit(3)
0041 
0042   # Taking data into hashmap
0043   f=open(data,'r')
0044   map = {}
0045   for l in f:
0046     a = l.strip().split()
0047     value = 0
0048     if len(a) > 1:
0049       value = a[1].strip()
0050     map[a[0].strip()] = value
0051   f.close()
0052 
0053   # Process stuff
0054   t = Template(file=tmpl)  
0055   t.datamap = map
0056   print(t)
0057 
0058 if __name__ == "__main__":
0059   main()
0060