CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
generateStandaloneCode.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 from os.path import join
5 
6 
7 def main():
8  path_formats = join(os.environ['CMSSW_BASE'],
9  'src/CondFormats/BTauObjects')
10  path_tools = join(os.environ['CMSSW_BASE'],
11  'src/RecoBTag/PerformanceDB/test')
12 
13  # headers
14  file_h = join(path_tools, 'BTagCalibrationStandalone.h')
15  print 'Creating', file_h
16  with open(file_h, 'w') as fout:
17  for fname in ['BTagEntry.h',
18  'BTagCalibration.h',
19  'BTagCalibrationReader.h']:
20  with open(join(path_formats, 'interface', fname)) as fin:
21  for line in fin:
22  if (line.startswith('#include "CondFormats') or
23  'COND_SERIALIZABLE' in line):
24  continue
25  fout.write(line)
26  fout.write('\n\n')
27 
28  # implementation
29  file_cc = join(path_tools, 'BTagCalibrationStandalone.cc')
30  print 'Creating', file_cc
31  with open(file_cc, 'w') as fout:
32  fout.write('#include "BTagCalibrationStandalone.h"\n')
33  fout.write('#include <iostream>\n')
34  fout.write('#include <exception>\n')
35  for fname in ['BTagEntry.cc',
36  'BTagCalibration.cc',
37  'BTagCalibrationReader.cc']:
38  with open(join(path_formats, 'src', fname)) as fin:
39  err_on_line = -3
40  for line_no, line in enumerate(fin):
41  if (line.startswith('#include "CondFormats') or
42  line.startswith('#include "FWCore')):
43  continue
44  elif 'throw cms::Exception' in line:
45  line = 'std::cerr << "ERROR in BTagCalibration: "\n'
46  err_on_line = line_no
47  elif line_no == err_on_line + 2:
48  line += 'throw std::exception();\n'
49  fout.write(line)
50  fout.write('\n\n')
51 
52 
53 if __name__ == '__main__':
54  main()
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
Definition: main.py:1