CMS 3D CMS Logo

Functions
generateStandaloneCode Namespace Reference

Functions

def main ()
 

Function Documentation

def generateStandaloneCode.main ( )

Definition at line 7 of file generateStandaloneCode.py.

References join().

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