ATLAS Offline Software
Functions | Variables
CreateClassesForFolder Namespace Reference

Functions

def add_args (parser)
 
def _mapToCpp (t)
 
def _toCamelCase (identifier)
 
def _createAddSpecificationList (nameList)
 
def _createDefineSpecificationList (nameTypeList)
 
def _createReadSpecificationList (nameTypeList)
 
def _createGetterList (nameTypeList)
 
def _createSetterList (nameTypeList)
 
def _createAttrDefinitions (nameTypeList)
 
def _createAttrConstructorList (nameList)
 
def _writeToFile (fname, template, mapping)
 
def create_classes_from_folder (folder, attrExcludeList, attrIncludeList, containerName, objectName)
 
def main ()
 

Variables

 __doc__
 
 _dbSvc
 
 _cliddb
 
 _container_header
 
 _container_src
 
 _object_header
 
 _object_src
 

Function Documentation

◆ _createAddSpecificationList()

def CreateClassesForFolder._createAddSpecificationList (   nameList)
private

Definition at line 235 of file CreateClassesForFolder.py.

235 def _createAddSpecificationList(nameList):
236  _l = ' attrList[specificationName(e{AttrName})].setValue(item.{attrName}());'
237  result = []
238  for name in nameList:
239  result.append(_l.format(AttrName=name, attrName=_toCamelCase(name)))
240  return '\n'.join(result)
241 

◆ _createAttrConstructorList()

def CreateClassesForFolder._createAttrConstructorList (   nameList)
private

Definition at line 277 of file CreateClassesForFolder.py.

277 def _createAttrConstructorList(nameList):
278  _l = ' , m_{attrName}({attrName})'
279  result = []
280  for n in nameList:
281  result.append(_l.format(attrName=_toCamelCase(n)))
282  return '\n'.join(result)
283 

◆ _createAttrDefinitions()

def CreateClassesForFolder._createAttrDefinitions (   nameTypeList)
private

Definition at line 270 of file CreateClassesForFolder.py.

270 def _createAttrDefinitions(nameTypeList):
271  _l = ' {attrType} m_{attrName} = 0;'
272  result = []
273  for (n, t) in nameTypeList:
274  result.append(_l.format(attrName=_toCamelCase(n), attrType=_mapToCpp(t)))
275  return '\n'.join(result)
276 

◆ _createDefineSpecificationList()

def CreateClassesForFolder._createDefineSpecificationList (   nameTypeList)
private

Definition at line 242 of file CreateClassesForFolder.py.

242 def _createDefineSpecificationList(nameTypeList):
243  _l = ' this->addSpecification(e{AttrName}, "{AttrName}", "{attrType}");'
244  result = []
245  for (n, t) in nameTypeList:
246  result.append(_l.format(AttrName=n, attrType=_mapToCpp(t)))
247  return '\n'.join(result)
248 

◆ _createGetterList()

def CreateClassesForFolder._createGetterList (   nameTypeList)
private

Definition at line 256 of file CreateClassesForFolder.py.

256 def _createGetterList(nameTypeList):
257  _l = ' {attrType} {attrName}() const {{ return m_{attrName}; }}'
258  result = []
259  for (n, t) in nameTypeList:
260  result.append(_l.format(attrName=_toCamelCase(n), attrType=_mapToCpp(t)))
261  return '\n'.join(result)
262 

◆ _createReadSpecificationList()

def CreateClassesForFolder._createReadSpecificationList (   nameTypeList)
private

Definition at line 249 of file CreateClassesForFolder.py.

249 def _createReadSpecificationList(nameTypeList):
250  _l = ' auto {attrName} = attrList[specificationName(e{AttrName})].data<{attrType}>();'
251  result = []
252  for (n, t) in nameTypeList:
253  result.append(_l.format(AttrName=n, attrName=_toCamelCase(n), attrType=_mapToCpp(t)))
254  return '\n'.join(result)
255 

◆ _createSetterList()

def CreateClassesForFolder._createSetterList (   nameTypeList)
private

Definition at line 263 of file CreateClassesForFolder.py.

263 def _createSetterList(nameTypeList):
264  _l = ' void set{AttrName}({attrType} {attrName}) {{ m_{attrName} = {attrName}; }}'
265  result = []
266  for (n, t) in nameTypeList:
267  result.append(_l.format(AttrName=n, attrName=_toCamelCase(n), attrType=_mapToCpp(t)))
268  return '\n'.join(result)
269 

◆ _mapToCpp()

def CreateClassesForFolder._mapToCpp (   t)
private

Definition at line 219 of file CreateClassesForFolder.py.

219 def _mapToCpp(t):
220  _m = {
221  'UInt16': 'unsigned short',
222  'UInt32': 'unsigned int',
223  'UInt63': 'unsigned long long',
224  'Int16' : 'short',
225  'Int32' : 'int',
226  'Double': 'double',
227  'Blob64k': 'char*',
228  'String255': 'char*'
229  }
230  return _m[t]
231 

◆ _toCamelCase()

def CreateClassesForFolder._toCamelCase (   identifier)
private

Definition at line 232 of file CreateClassesForFolder.py.

232 def _toCamelCase(identifier):
233  return '{0}{1}'.format(identifier[0].lower(), identifier[1:])
234 

◆ _writeToFile()

def CreateClassesForFolder._writeToFile (   fname,
  template,
  mapping 
)
private

Definition at line 284 of file CreateClassesForFolder.py.

284 def _writeToFile(fname, template, mapping):
285  f = open(fname, 'w')
286  f.write(string.Template(template).substitute(mapping))
287  f.close()
288 

◆ add_args()

def CreateClassesForFolder.add_args (   parser)
Add arguments to the ArgumentParser @parser. 

Definition at line 209 of file CreateClassesForFolder.py.

209 def add_args(parser):
210  """ Add arguments to the ArgumentParser @parser. """
211  parser.add_argument('folder', help='Folder which the class should represent')
212  parser.add_argument('--include', help='Comma separated list of attributes to include')
213  parser.add_argument('--exclude', help='Comma separated list of attributes to exclude')
214  parser.add_argument('--objectName', help='Name of object class')
215  parser.add_argument('--containerName', help='Name of container class')
216  parser.add_argument('--db', help='Connection string of the database',
217  default='COOLONL_TRIGGER/CONDBR2')
218 

◆ create_classes_from_folder()

def CreateClassesForFolder.create_classes_from_folder (   folder,
  attrExcludeList,
  attrIncludeList,
  containerName,
  objectName 
)
Does the actual work ... 

Definition at line 289 of file CreateClassesForFolder.py.

289 def create_classes_from_folder(folder, attrExcludeList, attrIncludeList, containerName, objectName):
290  """ Does the actual work ... """
291  folderName = folder.fullPath().split('/')[-1]
292  attrNames = [ps.name() for ps in folder.payloadSpecification()]
293  if attrIncludeList:
294  attrNames = filter(lambda n: n in attrIncludeList, attrNames)
295  elif attrExcludeList:
296  attrNames = filter(lambda n: n not in attrExcludeList, attrNames)
297 
298  attrTypes = [ps.storageType().name() for ps in folder.payloadSpecification() \
299  if ps.name() in attrNames]
300  attrNameTypes = zip(attrNames, attrTypes)
301 
302  if not containerName:
303  containerName = 'L1Calo{0}Container'.format(folderName)
304  if not objectName:
305  objectName = 'L1Calo{0}'.format(folderName)
306 
307  # prepare the replacements for the container class
308  mapping = {}
309  mapping['CommandLine'] = ' '.join(sys.argv)
310  mapping['ContainerName'] = containerName
311  mapping['CONTAINERNAME'] = containerName.upper()
312  mapping['FolderName'] = folderName
313  mapping['folderName'] = _toCamelCase(folderName)
314  mapping['ObjectName'] = objectName
315  mapping['EnumAttrSpecification'] = ', '.join(['e{0}'.format(n) for n in attrNames])
316  mapping['FullFolderPath'] = folder.fullPath()
317  mapping['ClassDefMacro'] = \
318  'CLASS_DEF( {0}, {1}, 1 )'.format(containerName,
319  _cliddb.genClidFromName(containerName))
320 
321  mapping['DefineSpecificationList'] = _createDefineSpecificationList(attrNameTypes)
322  mapping['AddSpecificationList'] = _createAddSpecificationList(attrNames)
323  mapping['ReadSpecificationList'] = _createReadSpecificationList(attrNameTypes)
324  mapping['AttrList'] = ', '.join(map(_toCamelCase, attrNames))
325 
326  # write the files
327  _writeToFile('{0}.h'.format(containerName), _container_header, mapping)
328  _writeToFile('{0}.cxx'.format(containerName), _container_src, mapping)
329 
330  # prepare the replacements for the object class
331  for not_needed in ('ContainerName', 'CONTAINERNAME', 'FolderName', 'folderName',
332  'EnumAttrSpecification', 'ClassDefMacro', 'DefineSpecificationList',
333  'AddSpecificationList', 'ReadSpecificationList', 'AttrList'):
334  del mapping[not_needed]
335  mapping['OBJECTNAME'] = objectName.upper()
336  mapping['AttrTypeNameList'] = ', '.join(['{0} {1}'.format(_mapToCpp(t), _toCamelCase(n)) for (n,t) in attrNameTypes])
337  mapping['GetterList'] = _createGetterList(attrNameTypes)
338  mapping['SetterList'] = _createSetterList(attrNameTypes)
339  mapping['AttrDefinitions'] = _createAttrDefinitions(attrNameTypes)
340  mapping['AttrConstructorList'] = _createAttrConstructorList(attrNames)
341 
342  # write the files
343  _writeToFile('{0}.h'.format(objectName), _object_header, mapping)
344  _writeToFile('{0}.cxx'.format(objectName), _object_src, mapping)
345 
346  # redefine mapping for slection.xml / *PACKAGE*Dict.h
347  mapping = {
348  'cont' : containerName,
349  'obj' : objectName,
350  'id' : str(uuid.uuid4()).upper()
351  }
352  print
353  print '[I] Add the following to the selection.xml file:'
354  print ' <class name="{cont}" id="{id}" />'.format(**mapping)
355  print ' <class name="{cont}::const_iterator" />'.format(**mapping)
356  print ' <class name="{obj}" />'.format(**mapping)
357  print
358  print '[I] Add the following to the TrigT1CaloCalibConditionsDict.h file:'
359  print '#include "TrigT1CaloCalibConditions/{cont}.h"'.format(**mapping)
360  print '#include "TrigT1CaloCalibConditions/{obj}.h"'.format(**mapping)
361  print
362  print ' {cont}::const_iterator {cont}ConstInterator;'.format(**mapping)
363 

◆ main()

def CreateClassesForFolder.main ( )
Entry point 

Definition at line 364 of file CreateClassesForFolder.py.

364 def main():
365  """ Entry point """
366  parser = argparse.ArgumentParser(description='Create C++ classes that represent COOL database folders')
367  add_args(parser)
368  args = parser.parse_args()
369 
370  if args.include and args.exclude:
371  raise RuntimeError("Options --include and --exclude are mutually exclusive.")
372 
373  db = _dbSvc.openDatabase(args.db)
374  folder = db.getFolder(args.folder)
375 
377  args.exclude.split(',') if args.exclude else None,
378  args.include.split(',') if args.include else None,
379  args.containerName, args.objectName)
380 

Variable Documentation

◆ __doc__

CreateClassesForFolder.__doc__
private

Definition at line 5 of file CreateClassesForFolder.py.

◆ _cliddb

CreateClassesForFolder._cliddb
private

Definition at line 22 of file CreateClassesForFolder.py.

◆ _container_header

CreateClassesForFolder._container_header
private

Definition at line 24 of file CreateClassesForFolder.py.

◆ _container_src

CreateClassesForFolder._container_src
private

Definition at line 84 of file CreateClassesForFolder.py.

◆ _dbSvc

CreateClassesForFolder._dbSvc
private

Definition at line 21 of file CreateClassesForFolder.py.

◆ _object_header

CreateClassesForFolder._object_header
private

Definition at line 170 of file CreateClassesForFolder.py.

◆ _object_src

CreateClassesForFolder._object_src
private

Definition at line 200 of file CreateClassesForFolder.py.

CreateClassesForFolder._toCamelCase
def _toCamelCase(identifier)
Definition: CreateClassesForFolder.py:232
vtune_athena.format
format
Definition: vtune_athena.py:14
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
CreateClassesForFolder._createAttrConstructorList
def _createAttrConstructorList(nameList)
Definition: CreateClassesForFolder.py:277
covarianceTool.filter
filter
Definition: covarianceTool.py:514
CreateClassesForFolder.add_args
def add_args(parser)
Definition: CreateClassesForFolder.py:209
CreateClassesForFolder._createGetterList
def _createGetterList(nameTypeList)
Definition: CreateClassesForFolder.py:256
CreateClassesForFolder._createDefineSpecificationList
def _createDefineSpecificationList(nameTypeList)
Definition: CreateClassesForFolder.py:242
CreateClassesForFolder._writeToFile
def _writeToFile(fname, template, mapping)
Definition: CreateClassesForFolder.py:284
CreateClassesForFolder.main
def main()
Definition: CreateClassesForFolder.py:364
CreateClassesForFolder._createReadSpecificationList
def _createReadSpecificationList(nameTypeList)
Definition: CreateClassesForFolder.py:249
CreateClassesForFolder._createSetterList
def _createSetterList(nameTypeList)
Definition: CreateClassesForFolder.py:263
CreateClassesForFolder._mapToCpp
def _mapToCpp(t)
Definition: CreateClassesForFolder.py:219
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CreateClassesForFolder._createAddSpecificationList
def _createAddSpecificationList(nameList)
Definition: CreateClassesForFolder.py:235
Trk::open
@ open
Definition: BinningType.h:40
RCU::substitute
std::string substitute(const std::string &str, const std::string &pattern, const std::string &with)
effects: substitute all occurences of "pattern" with "with" in the string "str" returns: the substitu...
Definition: StringUtil.cxx:24
str
Definition: BTagTrackIpAccessor.cxx:11
CreateClassesForFolder._createAttrDefinitions
def _createAttrDefinitions(nameTypeList)
Definition: CreateClassesForFolder.py:270
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
CreateClassesForFolder.create_classes_from_folder
def create_classes_from_folder(folder, attrExcludeList, attrIncludeList, containerName, objectName)
Definition: CreateClassesForFolder.py:289