ATLAS Offline Software
Loading...
Searching...
No Matches
CreateClassesForFolder Namespace Reference

Functions

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

Variables

str __doc__
 _dbSvc = cool.DatabaseSvcFactory.databaseService()
 _cliddb = clidGenerator("")
str _container_header
str _container_src
str _object_header
str _object_src

Function Documentation

◆ _createAddSpecificationList()

CreateClassesForFolder._createAddSpecificationList ( nameList)
protected

Definition at line 235 of file CreateClassesForFolder.py.

235def _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()

CreateClassesForFolder._createAttrConstructorList ( nameList)
protected

Definition at line 277 of file CreateClassesForFolder.py.

277def _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()

CreateClassesForFolder._createAttrDefinitions ( nameTypeList)
protected

Definition at line 270 of file CreateClassesForFolder.py.

270def _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()

CreateClassesForFolder._createDefineSpecificationList ( nameTypeList)
protected

Definition at line 242 of file CreateClassesForFolder.py.

242def _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()

CreateClassesForFolder._createGetterList ( nameTypeList)
protected

Definition at line 256 of file CreateClassesForFolder.py.

256def _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()

CreateClassesForFolder._createReadSpecificationList ( nameTypeList)
protected

Definition at line 249 of file CreateClassesForFolder.py.

249def _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()

CreateClassesForFolder._createSetterList ( nameTypeList)
protected

Definition at line 263 of file CreateClassesForFolder.py.

263def _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()

CreateClassesForFolder._mapToCpp ( t)
protected

Definition at line 219 of file CreateClassesForFolder.py.

219def _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()

CreateClassesForFolder._toCamelCase ( identifier)
protected

Definition at line 232 of file CreateClassesForFolder.py.

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

◆ _writeToFile()

CreateClassesForFolder._writeToFile ( fname,
template,
mapping )
protected

Definition at line 284 of file CreateClassesForFolder.py.

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

◆ add_args()

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

Definition at line 209 of file CreateClassesForFolder.py.

209def 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()

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

Definition at line 289 of file CreateClassesForFolder.py.

289def 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
int upper(int c)
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ main()

CreateClassesForFolder.main ( )
Entry point 

Definition at line 364 of file CreateClassesForFolder.py.

364def 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
376 create_classes_from_folder(folder,
377 args.exclude.split(',') if args.exclude else None,
378 args.include.split(',') if args.include else None,
379 args.containerName, args.objectName)
380
int main()
Definition hello.cxx:18

Variable Documentation

◆ __doc__

str CreateClassesForFolder.__doc__
private
Initial value:
1= """
2CreateClassesForFolder.py
3
4Python script that creates C++ .h/.cxx files that contain the container and object class
5representing the structure of a database folder.
6"""

Definition at line 5 of file CreateClassesForFolder.py.

◆ _cliddb

CreateClassesForFolder._cliddb = clidGenerator("")
protected

Definition at line 22 of file CreateClassesForFolder.py.

◆ _container_header

str CreateClassesForFolder._container_header
protected

Definition at line 24 of file CreateClassesForFolder.py.

◆ _container_src

str CreateClassesForFolder._container_src
protected

Definition at line 84 of file CreateClassesForFolder.py.

◆ _dbSvc

CreateClassesForFolder._dbSvc = cool.DatabaseSvcFactory.databaseService()
protected

Definition at line 21 of file CreateClassesForFolder.py.

◆ _object_header

str CreateClassesForFolder._object_header
protected
Initial value:
1= """// -*- C++ -*-
2#ifndef TRIGT1CALOCALIBCONDITIONS_${OBJECTNAME}_H
3#define TRIGT1CALOCALIBCONDITIONS_${OBJECTNAME}_H
4
5/**
6 * Folder <-> Object mapping for ${FullFolderPath} .
7 * Automatically created using:
8 *
9 * ${CommandLine}
10 */
11class ${ObjectName}
12{
13public:
14 ${ObjectName}() {}
15 ${ObjectName}(unsigned int channelId, ${AttrTypeNameList});
16
17 unsigned int channelId() const { return m_channelId; }
18${GetterList}
19
20 void setChannelId(unsigned int channelId) { m_channelId = channelId; }
21${SetterList}
22
23private:
24 unsigned int m_channelId = 0;
25${AttrDefinitions}
26};
27
28#endif // TRIGT1CALOCALIBCONDITIONS_${OBJECTNAME}_H
29"""

Definition at line 170 of file CreateClassesForFolder.py.

◆ _object_src

str CreateClassesForFolder._object_src
protected
Initial value:
1= """#include "TrigT1CaloCalibConditions/${ObjectName}.h"
2
3${ObjectName}::${ObjectName}(unsigned int channelId, ${AttrTypeNameList})
4 : m_channelId(channelId)
5${AttrConstructorList}
6{
7}
8"""

Definition at line 200 of file CreateClassesForFolder.py.