CMS 3D CMS Logo

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