CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
generateStandaloneCode Namespace Reference

Functions

def main
 

Function Documentation

def generateStandaloneCode.main ( )

Definition at line 8 of file generateStandaloneCode.py.

References join(), and print().

8 
9 def main():
10  path_cms = join(os.environ['CMSSW_BASE'], 'src')
11  path_tools = join(path_cms, 'CondTools/BTau/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 ['CondFormats/BTauObjects/interface/BTagEntry.h',
18  'CondFormats/BTauObjects/interface/BTagCalibration.h',
19  'CondTools/BTau/interface/BTagCalibrationReader.h']:
20  with open(join(path_cms, fname)) as fin:
21  for line in fin:
22  if (line.startswith('#include "Cond') 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.cpp')
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 ['CondFormats/BTauObjects/src/BTagEntry.cc',
36  'CondFormats/BTauObjects/src/BTagCalibration.cc',
37  'CondTools/BTau/src/BTagCalibrationReader.cc']:
38  with open(join(path_cms, fname)) as fin:
39  err_on_line = -3
40  for line_no, line in enumerate(fin):
41  if (line.startswith('#include "Cond') or
42  line.startswith('#include "FWCore')):
43  continue
44 
45  # cms exceptions cannot be used in the standalone version
46  # in the cpp source, exceptions must be formatted to span three lines, where
47  # the first and last lines are replaced.
48  elif 'throw cms::Exception' in line:
49  line = 'std::cerr << "ERROR in BTagCalibration: "\n'
50  err_on_line = line_no
51  elif line_no == err_on_line + 2:
52  line += 'throw std::exception();\n'
53  fout.write(line)
54  fout.write('\n\n')
55 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19