CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
combineBTagCalibrationData.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import sys
5 import itertools
6 import checkBTagCalibrationConsistency as checker
7 
8 
9 def check_csv_data(csv_data):
10  res = checker.run_check_csv(csv_data, False, False, False)
11  if not all(res):
12  print 'Checks on csv data failed. Exit.'
13  exit(-1)
14 
15 
16 def main():
17  if len(sys.argv) < 4:
18  print 'Need at least two input- and one output-filename. Exit.'
19  exit(-1)
20  if os.path.exists(sys.argv[-1]):
21  print 'Output file exists. Exit.'
22  exit(-1)
23 
24  all_csv_data = dict()
25  header = None
26  tagger = None
27  for fname in sys.argv[1:-1]:
28  with open(fname) as f:
29  all_csv_data[fname] = f.readlines()
30  header = all_csv_data[fname].pop(0)
31  tggr = header.split('/')[0]
32  if tagger and tggr != tagger:
33  print 'Found different taggers: %s vs. %s Exit.' % (tagger, tggr)
34  exit(-1)
35  else:
36  tagger = tggr
37 
38  print '\n' + '='*80
39  print 'Checking consistency of individual input files...'
40  print '='*80
41  for fname, csv_data in all_csv_data.iteritems():
42  print '\nChecking file:', fname
43  print '='*80
44  check_csv_data(csv_data)
45 
46  print '\n' + '='*80
47  print 'Checking consistency of combinations...'
48  print '='*80
49  for one, two in itertools.combinations(all_csv_data.iteritems(), 2):
50  print '\nChecking combination:', one[0], two[0]
51  print '='*80
52  check_csv_data(one[1] + two[1])
53 
54  print '\nCombining data...'
55  print '='*80
56  with open(sys.argv[-1], 'w') as f:
57  f.write(header)
58  for csv_data in all_csv_data.itervalues():
59  f.write('\n')
60  f.writelines(csv_data)
61 
62  print 'Done.'
63 
64 
65 if __name__ == '__main__':
66  main()
Definition: main.py:1