Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:43

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