CMS 3D CMS Logo

generateStandaloneCode.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 import os
5 from os.path import join
6 
7 
8 def main():
9  path_cms = join(os.environ['CMSSW_BASE'], 'src')
10  path_tools = join(path_cms, 'CondTools/BTau/test')
11 
12  # headers
13  file_h = join(path_tools, 'BTagCalibrationStandalone.h')
14  print('Creating', file_h)
15  with open(file_h, 'w') as fout:
16  for fname in ['CondFormats/BTauObjects/interface/BTagEntry.h',
17  'CondFormats/BTauObjects/interface/BTagCalibration.h',
18  'CondTools/BTau/interface/BTagCalibrationReader.h']:
19  with open(join(path_cms, fname)) as fin:
20  for line in fin:
21  if (line.startswith('#include "Cond') or
22  'COND_SERIALIZABLE' in line):
23  continue
24  fout.write(line)
25  fout.write('\n\n')
26 
27  # implementation
28  file_cc = join(path_tools, 'BTagCalibrationStandalone.cpp')
29  print('Creating', file_cc)
30  with open(file_cc, 'w') as fout:
31  fout.write('#include "BTagCalibrationStandalone.h"\n')
32  fout.write('#include <iostream>\n')
33  fout.write('#include <exception>\n')
34  for fname in ['CondFormats/BTauObjects/src/BTagEntry.cc',
35  'CondFormats/BTauObjects/src/BTagCalibration.cc',
36  'CondTools/BTau/src/BTagCalibrationReader.cc']:
37  with open(join(path_cms, fname)) as fin:
38  err_on_line = -3
39  for line_no, line in enumerate(fin):
40  if (line.startswith('#include "Cond') or
41  line.startswith('#include "FWCore')):
42  continue
43 
44  # cms exceptions cannot be used in the standalone version
45  # in the cpp source, exceptions must be formatted to span three lines, where
46  # the first and last lines are replaced.
47  elif 'throw cms::Exception' in line:
48  line = 'std::cerr << "ERROR in BTagCalibration: "\n'
49  err_on_line = line_no
50  elif line_no == err_on_line + 2:
51  line += 'throw std::exception();\n'
52  fout.write(line)
53  fout.write('\n\n')
54 
55 
56 if __name__ == '__main__':
57  main()
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
generateStandaloneCode.main
def main()
Definition: generateStandaloneCode.py:8
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
main
Definition: main.py:1