File indexing completed on 2024-11-25 02:29:23
0001
0002
0003 import os
0004 import sys
0005 import itertools
0006 from . import checkBTagCalibrationConsistency as checker
0007
0008
0009 def check_csv_data(csv_data):
0010 res = checker.run_check_csv(csv_data, False, False, False)
0011 if not all(res):
0012 print('Checks on csv data failed. Exit.')
0013 exit(-1)
0014
0015
0016 def main():
0017 if len(sys.argv) < 4:
0018 print('Need at least two input- and one output-filename. Exit.')
0019 exit(-1)
0020 if os.path.exists(sys.argv[-1]):
0021 print('Output file exists. Exit.')
0022 exit(-1)
0023
0024 all_csv_data = dict()
0025 header = None
0026 tagger = None
0027 for fname in sys.argv[1:-1]:
0028 with open(fname) as f:
0029 all_csv_data[fname] = f.readlines()
0030 header = all_csv_data[fname].pop(0)
0031 tggr = header.split('/')[0]
0032 if tagger and tggr != tagger:
0033 print('Found different taggers: %s vs. %s Exit.' % (tagger, tggr))
0034 exit(-1)
0035 else:
0036 tagger = tggr
0037
0038 print('\n' + '='*80)
0039 print('Checking consistency of individual input files...')
0040 print('='*80)
0041 for fname, csv_data in all_csv_data.items():
0042 print('\nChecking file:', fname)
0043 print('='*80)
0044 check_csv_data(csv_data)
0045
0046 print('\n' + '='*80)
0047 print('Checking consistency of combinations...')
0048 print('='*80)
0049 for one, two in itertools.combinations(all_csv_data.items(), 2):
0050 print('\nChecking combination:', one[0], two[0])
0051 print('='*80)
0052 check_csv_data(one[1] + two[1])
0053
0054 print('\nCombining data...')
0055 print('='*80)
0056 with open(sys.argv[-1], 'w') as f:
0057 f.write(header)
0058 for csv_data in all_csv_data.values():
0059 f.write('\n')
0060 f.writelines(csv_data)
0061
0062 print('Done.')
0063
0064
0065 if __name__ == '__main__':
0066 main()