File indexing completed on 2026-09-29 08:25:57
0001
0002 """
0003 This file will automaticcaly create the cpp files for the parsers
0004 for pod and std::containers of pods, and some other maps
0005
0006 This reduces the maximum required memory and allows faster compilation due to
0007 higher parallelisation of the build process
0008 This needs only to be run if additional parsers are neccessary.
0009 In this case copy the file to DDCore/src/parsers and run the program.
0010
0011 python CreateParsers.py
0012
0013 """
0014
0015 import io
0016 import os
0017
0018
0019 LICENSE = """// $Id$
0020 //==========================================================================
0021 // AIDA Detector description implementation
0022 //--------------------------------------------------------------------------
0023 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0024 // All rights reserved.
0025 //
0026 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0027 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0028 //
0029 //==========================================================================
0030 """
0031
0032
0033 def createParsers():
0034 """ make files for all parsers"""
0035
0036 listOfTypes = ['int',
0037 'long',
0038 'char',
0039 'bool',
0040 'short',
0041 'float',
0042 'double',
0043 'long long',
0044 'long double',
0045 'unsigned int',
0046 'unsigned long',
0047 'unsigned char',
0048 'unsigned short',
0049 'unsigned long long',
0050 'std::string',
0051 'signed char',
0052 ]
0053 listOfContainers = ['std::vector', 'std::list', 'std::set', 'std::deque']
0054 listOfMaps = ['int', 'unsigned long', 'std::string', ]
0055
0056 for typ in listOfTypes:
0057 for cont in listOfContainers:
0058 createContainerFile(typ, cont)
0059 for mtype in listOfMaps:
0060 createMapFile(typ, mtype)
0061
0062 createMappedFile(typ)
0063
0064
0065 def createMappedFile(typ):
0066 """ create file for mapped parsers """
0067 tName = typ[5:] if typ.startswith("std::") else typ
0068 filename = "ParserStandardList_Mapped_%s.cpp" % (tName.replace(" ", ""))
0069 fileContent = """
0070 #include "ParsersStandardListCommon.h"
0071 namespace dd4hep{ namespace Parsers{
0072 IMPLEMENT_MAPPED_PARSERS(pair,%(type)s)
0073 }}
0074 """ % {"type": typ}
0075 fileContent = LICENSE + fileContent
0076 if os.path.exists(filename):
0077 os.remove(filename)
0078 with io.open(filename, "w") as parseFile:
0079 parseFile.write(fileContent)
0080
0081
0082 def createContainerFile(typ, cont):
0083 """create file to make container parser"""
0084 tName = typ[5:] if typ.startswith("std::") else typ
0085 filename = "ParserStandardList_%s_%s.cpp" % (cont[5:], tName.replace(" ", ""))
0086 fileContent = """
0087 #include "ParsersStandardListCommon.h"
0088 namespace dd4hep{ namespace Parsers{
0089 IMPLEMENT_STL_PARSER(%(cont)s,%(type)s)
0090 }}
0091 """ % {"cont": cont, "type": typ}
0092 fileContent = LICENSE + fileContent
0093 if os.path.exists(filename):
0094 os.remove(filename)
0095 with io.open(filename, "w") as parseFile:
0096 parseFile.write(fileContent)
0097
0098
0099 def createMapFile(typ, mtype):
0100 """ create file to make map parser"""
0101 mName = mtype[5:] if mtype.startswith("std::") else mtype
0102 tName = typ[5:] if typ.startswith("std::") else typ
0103 filename = "ParserStandardList_Map%s_%s.cpp" % (mName.replace(" ", ""), tName.replace(" ", ""))
0104 fileContent = """
0105 #include "ParsersStandardListCommon.h"
0106 namespace dd4hep{ namespace Parsers{
0107 IMPLEMENT_STL_MAP_PARSER(std::map,%(mtype)s,%(type)s)
0108 }}
0109 """ % {"mtype": mtype, "type": typ}
0110 fileContent = LICENSE + fileContent
0111 if os.path.exists(filename):
0112 os.remove(filename)
0113 with io.open(filename, "w") as parseFile:
0114 parseFile.write(fileContent)
0115
0116
0117 if __name__ == "__main__":
0118 createParsers()