Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-23 02:25:21

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