CMS 3D CMS Logo

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

Functions

def genObjectDef
 
def genObjNameDef
 
def getObjectList
 

Variables

string action = 'store_true'
 
tuple alphaRE = re.compile(r'(\w+)')
 
tuple colonRE = re.compile(r':')
 
string default = ''
 
dictionary defsDict
 
string defTemplate
 
tuple dotRE = re.compile(r'\.')
 
tuple goName = options.goNameorcolonRE.sub('', objectName)
 
string help = 'GenObject name'
 
tuple nonAlphaRE = re.compile(r'\W')
 
tuple objectName = GenObject.decodeNonAlphanumerics(args[0])
 
string outputFile = options.outputorgoName+'.txt'
 
 parser = optparse.OptionParser\
 
dictionary root2GOtypeDict
 
string startString
 
tuple targetFile = open(outputFile, 'w')
 
tuple vetoedTypes = set()
 

Function Documentation

def useReflexToDescribeForGenObject.genObjectDef (   mylist,
  tuple,
  alias,
  label,
  type,
  etaPhiFound 
)
Does something, but I can't remembrer what... 

Definition at line 161 of file useReflexToDescribeForGenObject.py.

References print().

162 def genObjectDef (mylist, tuple, alias, label, type, etaPhiFound):
163  """Does something, but I can't remembrer what... """
164  print("tuple %s alias %s label %s type %s" % (tuple, alias, label, type))
165  # first get the name of the object
166  firstName = mylist[0][0]
167  match = alphaRE.match (firstName)
168  if not match:
169  raise RuntimeError("firstName doesn't parse correctly. (%s)" \
170  % firstName)
171  genName = match.group (1)
172  genDef = " ## GenObject %s Definition ##\n[%s]\n" % \
173  (genName, genName)
174  if options.index or not etaPhiFound:
175  # either we told it to always use index OR either eta or phi
176  # is missing.
177  genDef += "-equiv: index,0\n";
178  else:
179  genDef += "-equiv: eta,0.1 phi,0.1 index,100000\n";
180  tupleDef = '[%s:%s:%s label=%s type=%s]\n' % \
181  (genName, tuple, alias, label, type)
182 
183  for variable in mylist:
184  name, func = genObjNameDef (variable[0])
185  typeInfo = variable[1]
186  form = defsDict[ typeInfo ]
187  genDef += form % name + '\n'
188  tupleDef += "%-40s : %s\n" % (name, func)
189  return genDef, tupleDef
190 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def useReflexToDescribeForGenObject.genObjNameDef (   line)
Returns GenObject name and ntuple definition function

Definition at line 152 of file useReflexToDescribeForGenObject.py.

153 def genObjNameDef (line):
154  """Returns GenObject name and ntuple definition function"""
155  words = dotRE.split (line)[1:]
156  func = ".".join (words)
157  name = "_".join (words)
158  name = nonAlphaRE.sub ('', name)
159  return name, func
160 
def useReflexToDescribeForGenObject.getObjectList (   objectName,
  base,
  verbose = False,
  memberData = False 
)
Get a list of interesting things from this object

Definition at line 65 of file useReflexToDescribeForGenObject.py.

References print(), sistrip::SpyUtilities.range(), and str.

65 
66 def getObjectList (objectName, base, verbose = False, memberData = False):
67  """Get a list of interesting things from this object"""
68  # The autoloader needs an object before it loads its dictionary.
69  # So let's give it one.
70  try:
71  rootObjConstructor = getattr (ROOT, objectName)
72  except AttributeError as missingAttr:
73  if str(missingAttr) in ['double', 'int']:
74  print("Do not need to describe doubles or ints")
75  sys.exit(0)
76  else:
77  raise
78 
79  obj = rootObjConstructor()
80  alreadySeenFunction = set()
81  vetoedFunction = set()
82  etaFound, phiFound = False, False
83  global vetoedTypes
84  retval = []
85  # Put the current class on the queue and start the while loop
86  classList = [ ROOT.TClass.GetClass(objectName) ]
87  if verbose: print(classList)
88  # Uses while because reflixList is really a stack
89  while classList:
90  alreadySeenFunction.update(vetoedFunction) # skip functions hidden by derived class
91  vetoedFunction.clear()
92  oneclass = classList.pop (0) # get first element
93  print("Looking at %s" % oneclass.GetName ())
94  bases = oneclass.GetListOfBases()
95  funcs = oneclass.GetListOfMethods()
96  if verbose:
97  print("baseSize", bases.GetSize())
98  print("FunctionMemberSize", funcs.GetSize())
99  for baseIndex in range( bases.GetSize() ) :
100  classList.append( bases.At(baseIndex).GetClassPointer() )
101  for index in range( funcs.GetSize() ):
102  funcMember = funcs.At (index)
103  # if we've already seen this, don't bother again
104  name = funcMember.GetName()
105  if verbose:
106  print("name", name)
107  if name == 'eta':
108  etaFound = True
109  elif name == 'phi':
110  phiFound = True
111  if name in alreadySeenFunction:
112  continue
113  # make sure this is an allowed return type
114  returnType = funcMember.GetReturnTypeName()
115  goType = root2GOtypeDict.get (returnType, None)
116  if verbose:
117  print(" type", returnType, goType)
118  if not goType:
119  vetoedTypes.add (returnType)
120  if verbose:
121  print(" skipped")
122  continue
123  elif verbose:
124  print(" good")
125  # only bother printout out lines where it is a const function
126  # and has no input parameters.
127  if funcMember.Property() & ROOT.kIsConstMethod and not funcMember.GetNargs():
128  retval.append( ("%s.%s()" % (base, name), goType))
129  alreadySeenFunction.add( name )
130  if verbose:
131  print(" added")
132  else :
133  vetoedFunction.add( name )
134  if verbose:
135  print(" failed IsConst() and GetNargs()")
136  if not memberData:
137  continue
138  dataList = oneclass.GetListOfDataMembers()
139  for index in range( dataList.GetSize() ):
140  data = dataList.At( index );
141  name = data.GetName()
142  dataType = data.GetTypeName()
143  goType = root2GOtypeDict.get (dataType, None)
144  if not goType:
145  continue
146  if verbose:
147  print("name", name, "dataType", dataType, "goType", goType)
148  retval.append ( ("%s.%s" % (base, name), goType) )
149  retval.sort()
150  return retval, etaFound and phiFound
151 
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)

Variable Documentation

string useReflexToDescribeForGenObject.action = 'store_true'

Definition at line 211 of file useReflexToDescribeForGenObject.py.

tuple useReflexToDescribeForGenObject.alphaRE = re.compile(r'(\w+)')

Definition at line 62 of file useReflexToDescribeForGenObject.py.

tuple useReflexToDescribeForGenObject.colonRE = re.compile(r':')

Definition at line 59 of file useReflexToDescribeForGenObject.py.

string useReflexToDescribeForGenObject.default = ''

Definition at line 197 of file useReflexToDescribeForGenObject.py.

dictionary useReflexToDescribeForGenObject.defsDict
Initial value:
1 = {
2  'int' : '%-40s : form=%%%%8d type=int',
3  'float' : '%-40s : form=%%%%7.2f prec=',
4  'str' : '%-40s : form=%%%%20s type=string',
5  'long' : '%-40s : form=%%%%10d type=long',
6  }

Definition at line 12 of file useReflexToDescribeForGenObject.py.

string useReflexToDescribeForGenObject.defTemplate
Initial value:
1 = """
2 #####################
3 ## %(OBJS)s Definition ##
4 #####################
5 
6 # Nickname and Tree
7 [%(objs)s:FWLite]
8 
9 # 'reco'-tupe 'runevent' 'tofill' information
10 [runevent:%(objs)s:EventAuxiliary shortcut=eventAuxiliary()]
11 run: run()
12 event: event()
13 
14 """

Definition at line 44 of file useReflexToDescribeForGenObject.py.

tuple useReflexToDescribeForGenObject.dotRE = re.compile(r'\.')

Definition at line 60 of file useReflexToDescribeForGenObject.py.

tuple useReflexToDescribeForGenObject.goName = options.goNameorcolonRE.sub('', objectName)

Definition at line 229 of file useReflexToDescribeForGenObject.py.

string useReflexToDescribeForGenObject.help = 'GenObject name'

Definition at line 198 of file useReflexToDescribeForGenObject.py.

tuple useReflexToDescribeForGenObject.nonAlphaRE = re.compile(r'\W')

Definition at line 61 of file useReflexToDescribeForGenObject.py.

tuple useReflexToDescribeForGenObject.objectName = GenObject.decodeNonAlphanumerics(args[0])

Definition at line 228 of file useReflexToDescribeForGenObject.py.

string useReflexToDescribeForGenObject.outputFile = options.outputorgoName+'.txt'

Definition at line 230 of file useReflexToDescribeForGenObject.py.

useReflexToDescribeForGenObject.parser = optparse.OptionParser\

Definition at line 193 of file useReflexToDescribeForGenObject.py.

dictionary useReflexToDescribeForGenObject.root2GOtypeDict
Initial value:
1 = {
2  'int' : 'int',
3  'float' : 'float',
4  'double' : 'float',
5  'long' : 'long',
6  'long int' : 'long',
7  'unsigned int' : 'int',
8  'bool' : 'int',
9  'string' : 'str',
10  'std::basic_string<char>' : 'str',
11  }

Definition at line 19 of file useReflexToDescribeForGenObject.py.

string useReflexToDescribeForGenObject.startString
Initial value:
1 = """
2 # -*- sh -*- For Font lock mode
3 
4 ###########################
5 ## GenObject Definitions ##
6 ###########################
7 
8 # GenObject 'event' definition
9 [runevent singleton]
10 run: type=int
11 event: type=int
12 """

Definition at line 31 of file useReflexToDescribeForGenObject.py.

tuple useReflexToDescribeForGenObject.targetFile = open(outputFile, 'w')

Definition at line 242 of file useReflexToDescribeForGenObject.py.

tuple useReflexToDescribeForGenObject.vetoedTypes = set()

Definition at line 63 of file useReflexToDescribeForGenObject.py.