3 from __future__
import print_function
4 from builtins
import range
13 'int' :
'%-40s : form=%%%%8d type=int',
14 'float' :
'%-40s : form=%%%%7.2f prec=',
15 'str' :
'%-40s : form=%%%%20s type=string',
16 'long' :
'%-40s : form=%%%%10d type=long',
25 'unsigned int' :
'int',
28 'std::basic_string<char>' :
'str',
32 # -*- sh -*- For Font lock mode 34 ########################### 35 ## GenObject Definitions ## 36 ########################### 38 # GenObject 'event' definition 46 ## %(OBJS)s Definition ## 52 # 'reco'-tupe 'runevent' 'tofill' information 53 [runevent:%(objs)s:EventAuxiliary shortcut=eventAuxiliary()] 59 colonRE = re.compile (
r':')
60 dotRE = re.compile (
r'\.')
61 nonAlphaRE = re.compile (
r'\W')
62 alphaRE = re.compile (
r'(\w+)')
65 def getObjectList (objectName, base, verbose = False, memberData = False):
66 """Get a list of interesting things from this object""" 70 rootObjConstructor = getattr (ROOT, objectName)
71 except AttributeError
as missingAttr:
72 if str(missingAttr)
in [
'double',
'int']:
73 print(
"Do not need to describe doubles or ints")
78 obj = rootObjConstructor()
79 alreadySeenFunction = set()
80 vetoedFunction = set()
81 etaFound, phiFound =
False,
False 85 classList = [ ROOT.TClass.GetClass(objectName) ]
86 if verbose:
print(classList)
89 alreadySeenFunction.update(vetoedFunction)
90 vetoedFunction.clear()
91 oneclass = classList.pop (0)
92 print(
"Looking at %s" % oneclass.GetName ())
93 bases = oneclass.GetListOfBases()
94 funcs = oneclass.GetListOfMethods()
96 print(
"baseSize", bases.GetSize())
97 print(
"FunctionMemberSize", funcs.GetSize())
98 for baseIndex
in range( bases.GetSize() ) :
99 classList.append( bases.At(baseIndex).GetClassPointer() )
100 for index
in range( funcs.GetSize() ):
101 funcMember = funcs.At (index)
103 name = funcMember.GetName()
110 if name
in alreadySeenFunction:
113 returnType = funcMember.GetReturnTypeName()
114 goType = root2GOtypeDict.get (returnType,
None)
116 print(
" type", returnType, goType)
118 vetoedTypes.add (returnType)
126 if funcMember.Property() & ROOT.kIsConstMethod
and not funcMember.GetNargs():
127 retval.append( (
"%s.%s()" % (base, name), goType))
128 alreadySeenFunction.add( name )
132 vetoedFunction.add( name )
134 print(
" failed IsConst() and GetNargs()")
137 dataList = oneclass.GetListOfDataMembers()
138 for index
in range( dataList.GetSize() ):
139 data = dataList.At( index );
140 name = data.GetName()
141 dataType = data.GetTypeName()
142 goType = root2GOtypeDict.get (dataType,
None)
146 print(
"name", name,
"dataType", dataType,
"goType", goType)
147 retval.append ( (
"%s.%s" % (base, name), goType) )
149 return retval, etaFound
and phiFound
153 """Returns GenObject name and ntuple definition function""" 154 words = dotRE.split (line)[1:]
155 func =
".".join (words)
156 name =
"_".join (words)
157 name = nonAlphaRE.sub (
'', name)
162 """Does something, but I can't remembrer what... """ 163 print(
"tuple %s alias %s label %s type %s" % (tuple, alias, label, type))
165 firstName = mylist[0][0]
166 match = alphaRE.match (firstName)
168 raise RuntimeError(
"firstName doesn't parse correctly. (%s)" \
170 genName = match.group (1)
171 genDef =
" ## GenObject %s Definition ##\n[%s]\n" % \
173 if options.index
or not etaPhiFound:
176 genDef +=
"-equiv: index,0\n";
178 genDef +=
"-equiv: eta,0.1 phi,0.1 index,100000\n";
179 tupleDef =
'[%s:%s:%s label=%s type=%s]\n' % \
180 (genName, tuple, alias, label, type)
182 for variable
in mylist:
183 name, func = genObjNameDef (variable[0])
184 typeInfo = variable[1]
185 form = defsDict[ typeInfo ]
186 genDef += form % name +
'\n' 187 tupleDef +=
"%-40s : %s\n" % (name, func)
188 return genDef, tupleDef
191 if __name__ ==
"__main__":
193 parser = optparse.OptionParser \
194 (
"usage: %prog [options] objectName\n" \
195 "Creates control file for GenObject.")
196 parser.add_option (
'--goName', dest=
'goName', type=
'string',
198 help=
'GenObject name')
199 parser.add_option (
'--index', dest=
'index', action=
'store_true',
200 help=
'use index for matching')
201 parser.add_option (
'--label', dest=
'label', type=
'string',
202 default =
'dummyLabel',
203 help=
"Tell GO to set an label")
204 parser.add_option (
'--output', dest=
'output', type=
'string',
206 help=
"Output (Default 'objectName.txt')")
207 parser.add_option (
'--precision', dest=
'precision', type=
'string',
209 help=
"precision to use for floats (default %default)")
210 parser.add_option (
'--privateMemberData', dest=
'privateMemberData',
212 help=
'include private member data (NOT for comparisons)')
213 parser.add_option (
'--tupleName', dest=
'tupleName', type=
'string',
215 help=
"Tuple name (default '%default')")
216 parser.add_option (
'--type', dest=
'type', type=
'string',
217 default =
'dummyType',
218 help=
"Tell GO to set an type")
219 parser.add_option (
'--verbose', dest=
'verbose', action=
'store_true',
220 help=
'Verbose output')
221 options, args = parser.parse_args()
222 defsDict[
'float'] += options.precision
224 options.type = GenObject.decodeNonAlphanumerics (options.type)
226 raise RuntimeError(
"Need to provide object name.")
228 objectName = GenObject.decodeNonAlphanumerics (args[0])
229 goName = options.goName
or colonRE.sub (
'', objectName)
230 outputFile = options.output
or goName +
'.txt' 231 ROOT.gROOT.SetBatch()
233 ROOT.gSystem.Load(
"libFWCoreFWLite")
234 ROOT.gSystem.Load(
"libDataFormatsFWLite")
236 ROOT.FWLiteEnabler.enable()
237 mylist, etaPhiFound = getObjectList (objectName, goName, options.verbose,
238 options.privateMemberData)
240 print(
"There are no member functions that are useful for comparison.")
241 sys.exit (GenObject.uselessReturnCode)
242 targetFile = open (outputFile,
'w')
243 genDef, tupleDef = genObjectDef (mylist,
249 targetFile.write (startString)
250 targetFile.write (genDef)
251 targetFile.write (defTemplate % {
'objs':
'reco',
'OBJS':
'RECO'})
252 targetFile.write (tupleDef)
253 print(
"Vetoed types:")
254 pprint.pprint ( sorted( list(vetoedTypes) ) )
def genObjectDef(mylist, tuple, alias, label, type, etaPhiFound)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def getObjectList(objectName, base, verbose=False, memberData=False)