CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
generateWrappers.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
4 import string, os, sys
5 
6 
7 def walkPlugins(a):
8  for dir in os.listdir('.'):
9  if(dir.find('Plugins')<0) : continue
10  os.chdir(dir)
11  a.act()
12  os.chdir('../')
13 
14 
15 # All those below run in CondCore/XyzPlugin directory
16 
17 def guessPackage() :
18  lines = ( line for line in file('src/plugin.cc')
19  if (line.find('CondFormats')>0 and line.find('DataRecord')<0)
20  )
21  _f = lines.next()
22  _f = _f[_f.find('CondFormats/')+len('CondFormats/'):]
23  return _f[:_f.find('/')]
24 
25 def guessClasses() :
26  _ret = []
27  lines = ( line for line in file('src/plugin.cc') if line[0:3]=='REG')
28  for line in lines:
29  _ret.append(line[line.find(',')+1:line.find(')')])
30  return _ret
31 
32 # generate the comment in classes.h
33 def generateClassesHeader(package):
34  _header = '/* Condition Objects'
35  _footer = '\n */\n\n#include "CondFormats/Common/interface/PayloadWrapper.h"\n\n'
36  _leader = '\n * '
37 
38  _classes = guessClasses()
39 
40  _newch = file('../../CondFormats/'+package+'/src/classes_new.h','w')
41  _newch.write(_header)
42  for cl in _classes :
43  _newch.write(_leader+cl)
44  _newch.write(_footer)
45  for line in file('../../CondFormats/'+package+'/src/classes.h'):
46  _newch.write(line)
47  _newch.close()
48 
49 def getClasses(package) :
50  _header = 'Condition Objects'
51  _ret = []
52  _ch = file('../../CondFormats/'+package+'/src/classes.h')
53  if (_ch.readline().find(_header)<0) :
54  print 'comment header not found in '+package
55  return _ret
56  for line in _ch:
57  if (line.find('*/')>0) : break
58  _ret.append(line[3:].rstrip())
59  _ch.close()
60  return _ret
61 
62 wrapperDeclarationHeader = """
63 // wrapper declarations
64 namespace {
65  struct wrappers {
66 """
67 wrapperDeclarationFooter = """
68  };
69 }
70 """
71 
72 def declareCondWrappers(package):
73  _newch = file('../../CondFormats/'+package+'/src/classes_new.h','w')
74  for line in file('../../CondFormats/'+package+'/src/classes.h'):
75  if (line.find('wrapper declarations')>0) : break
76  _newch.write(line)
77  _newch.write(wrapperDeclarationHeader)
78  _n=0
79  for cl in getClasses(package):
80  _newch.write(' pool::Ptr<'+cl+' > p'+str(_n)+';\n')
81  _newch.write(' cond::DataWrapper<'+cl+' > dw'+str(_n)+';\n')
82  _n=_n+1
83  _newch.write(wrapperDeclarationFooter)
84  _newch.close()
85 
87  _wrapperComment = '<-- wrapper declarations -->\n'
88  _newxml = file('../../CondFormats/'+package+'/src/classes_def_new.xml','w')
89  for line in file('../../CondFormats/'+package+'/src/classes_def.xml'):
90  if (line.find('wrapper declarations')>0) : break
91  _newch.write(line)
92  _newch.write_(wrapperComment)
93  for cl in getClasses(package):
94  _newch.write(' <class name="pool::Ptr<'+cl+' >"/>\n')
95  _newch.write(' <class name="cond::DataWrapper<'+cl+' >"/>\n')
96  _newch.close()
97 
98 
99 
100 
101 def generateBuildFile(package,classes) :
102  f = file('plugins/BuildFile','w')
103  f.seek(0,2)
104  s = string.Template(buildfileTemplate)
105  for classname in classes:
106  f.write(s.substitute(_PACKAGE_=package, _CLASS_NAME_=classname).replace('-',''))
107 
108 def generateWrapper(package,classes) :
109  s = string.Template(wrapperTemplate)
110  for classname in classes:
111  f = file('plugins/'+classname+'PyWrapper.cc','w')
112  print "generating file:", f.name
113  f.write(s.substitute(_PACKAGE_=package, _CLASS_NAME_=classname, _HEADER_FILE_=classname))
114  f.close()
115 
116 
117 def generateDict(package):
118  os.system('cd ../../;cvs co CondFormats/'+package)
119  declareCondWrappers(package)
120  declareXMLCondWrappers(package)
121 
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
if(conf.exists("allCellsPositionCalc"))