Newer
Older
Andre Sailer
committed
#!/usr/env python
"""
This file will automaticcaly create the cpp files for the parsers for pod and std::containers of pods, and some other maps
This reduces the maximum required memory and allows faster compilation due to higher parallelisation of the build process
This needs only to be run if additional parsers are neccessary.
In this case copy the file to DDCore/src/parsers and run the program.
python CreateParsers.py
"""
Andre Sailer
committed
import os
LICENSE ="""// $Id$
//==========================================================================
Andre Sailer
committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
//==========================================================================
"""
def createParsers():
""" make files for all parsers"""
listOfTypes = ['int',
'long',
'char',
'bool',
'short',
'float',
'double',
'long long',
'long double',
'unsigned int',
'unsigned long',
'unsigned char',
'unsigned short',
'unsigned long long',
'std::string',
'signed char',
]
listOfContainers = ['std::vector','std::list','std::set','std::deque']
listOfMaps = ['int','unsigned long','std::string',]
for typ in listOfTypes:
for cont in listOfContainers:
createContainerFile( typ, cont)
for mtype in listOfMaps:
createMapFile( typ, mtype )
createMappedFile( typ )
def createMappedFile( typ ):
""" create file for mapped parsers """
tName = typ[5:] if typ.startswith("std::") else typ
filename="ParserStandardList_Mapped_%s.cpp" % ( tName.replace(" ", "") )
fileContent= """
#include "ParsersStandardListCommon.h"
Andre Sailer
committed
IMPLEMENT_MAPPED_PARSERS(pair,%(type)s)
}}
""" % { "type":typ }
fileContent = LICENSE+fileContent
if os.path.exists(filename):
os.remove(filename)
with open(filename, "w") as parseFile:
parseFile.write(fileContent)
def createContainerFile( typ, cont ):
"""create file to make container parser"""
tName = typ[5:] if typ.startswith("std::") else typ
filename="ParserStandardList_%s_%s.cpp" % ( cont[5:], tName.replace(" ", ""))
fileContent= """
#include "ParsersStandardListCommon.h"
Andre Sailer
committed
IMPLEMENT_STL_PARSER(%(cont)s,%(type)s)
}}
""" % { "cont": cont, "type":typ }
fileContent = LICENSE+fileContent
if os.path.exists(filename):
os.remove(filename)
with open(filename, "w") as parseFile:
parseFile.write(fileContent)
def createMapFile( typ, mtype ):
""" create file to make map parser"""
mName = mtype[5:] if mtype.startswith("std::") else mtype
tName = typ[5:] if typ.startswith("std::") else typ
filename="ParserStandardList_Map%s_%s.cpp" % ( mName.replace(" ", "") , tName.replace(" ", ""))
fileContent= """
#include "ParsersStandardListCommon.h"
Andre Sailer
committed
IMPLEMENT_STL_MAP_PARSER(std::map,%(mtype)s,%(type)s)
}}
""" % { "mtype": mtype, "type":typ }
fileContent = LICENSE+fileContent
if os.path.exists(filename):
os.remove(filename)
with open(filename, "w") as parseFile:
parseFile.write(fileContent)
if __name__ == "__main__":
createParsers()