Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:23

0001 #!/usr/bin/env python
0002 
0003 import os
0004 from os.path import join
0005 
0006 
0007 def main():
0008     path_cms = join(os.environ['CMSSW_BASE'], 'src')
0009     path_tools = join(path_cms, 'CondTools/BTau/test')
0010 
0011     #  headers
0012     file_h = join(path_tools, 'BTagCalibrationStandalone.h')
0013     print('Creating', file_h)
0014     with open(file_h, 'w') as fout:
0015         for fname in ['CondFormats/BTauObjects/interface/BTagEntry.h',
0016                       'CondFormats/BTauObjects/interface/BTagCalibration.h',
0017                       'CondTools/BTau/interface/BTagCalibrationReader.h']:
0018             with open(join(path_cms, fname)) as fin:
0019                 for line in fin:
0020                     if (line.startswith('#include "Cond') or
0021                         'COND_SERIALIZABLE' in line):
0022                         continue
0023                     fout.write(line)
0024             fout.write('\n\n')
0025 
0026     # implementation
0027     file_cc = join(path_tools, 'BTagCalibrationStandalone.cpp')
0028     print('Creating', file_cc)
0029     with open(file_cc, 'w') as fout:
0030         fout.write('#include "BTagCalibrationStandalone.h"\n')
0031         fout.write('#include <iostream>\n')
0032         fout.write('#include <exception>\n')
0033         for fname in ['CondFormats/BTauObjects/src/BTagEntry.cc',
0034                       'CondFormats/BTauObjects/src/BTagCalibration.cc',
0035                       'CondTools/BTau/src/BTagCalibrationReader.cc']:
0036             with open(join(path_cms, fname)) as fin:
0037                 err_on_line = -3
0038                 for line_no, line in enumerate(fin):
0039                     if (line.startswith('#include "Cond') or
0040                         line.startswith('#include "FWCore')):
0041                         continue
0042 
0043                     # cms exceptions cannot be used in the standalone version
0044                     # in the cpp source, exceptions must be formatted to span three lines, where
0045                     # the first and last lines are replaced.
0046                     elif 'throw cms::Exception' in line:
0047                         line = 'std::cerr << "ERROR in BTagCalibration: "\n'
0048                         err_on_line = line_no
0049                     elif line_no == err_on_line + 2:
0050                         line += 'throw std::exception();\n'
0051                     fout.write(line)
0052             fout.write('\n\n')
0053 
0054 
0055 if __name__ == '__main__':
0056     main()