File indexing completed on 2025-01-18 09:14:37
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 from __future__ import absolute_import, unicode_literals
0016 import io
0017 import os
0018
0019
0020 LICENSE = """// $Id$
0021 //==========================================================================
0022 // AIDA Detector description implementation
0023 //--------------------------------------------------------------------------
0024 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0025 // All rights reserved.
0026 //
0027 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0028 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0029 //
0030 //==========================================================================
0031 """
0032
0033
0034 def createParsers():
0035 """ make files for all parsers"""
0036
0037 listOfTypes = ['int',
0038 'long',
0039 'char',
0040 'bool',
0041 'short',
0042 'float',
0043 'double',
0044 'long long',
0045 'long double',
0046 'unsigned int',
0047 'unsigned long',
0048 'unsigned char',
0049 'unsigned short',
0050 'unsigned long long',
0051 'std::string',
0052 'signed char',
0053 ]
0054 listOfContainers = ['std::vector', 'std::list', 'std::set', 'std::deque']
0055 listOfMaps = ['int', 'unsigned long', 'std::string', ]
0056
0057 for typ in listOfTypes:
0058 for cont in listOfContainers:
0059 createContainerFile(typ, cont)
0060 for mtype in listOfMaps:
0061 createMapFile(typ, mtype)
0062
0063 createMappedFile(typ)
0064
0065
0066 def createMappedFile(typ):
0067 """ create file for mapped parsers """
0068 tName = typ[5:] if typ.startswith("std::") else typ
0069 filename = "ParserStandardList_Mapped_%s.cpp" % (tName.replace(" ", ""))
0070 fileContent = """
0071 #include "ParsersStandardListCommon.h"
0072 namespace dd4hep{ namespace Parsers{
0073 IMPLEMENT_MAPPED_PARSERS(pair,%(type)s)
0074 }}
0075 """ % {"type": typ}
0076 fileContent = LICENSE + fileContent
0077 if os.path.exists(filename):
0078 os.remove(filename)
0079 with io.open(filename, "w") as parseFile:
0080 parseFile.write(fileContent)
0081
0082
0083 def createContainerFile(typ, cont):
0084 """create file to make container parser"""
0085 tName = typ[5:] if typ.startswith("std::") else typ
0086 filename = "ParserStandardList_%s_%s.cpp" % (cont[5:], tName.replace(" ", ""))
0087 fileContent = """
0088 #include "ParsersStandardListCommon.h"
0089 namespace dd4hep{ namespace Parsers{
0090 IMPLEMENT_STL_PARSER(%(cont)s,%(type)s)
0091 }}
0092 """ % {"cont": cont, "type": typ}
0093 fileContent = LICENSE + fileContent
0094 if os.path.exists(filename):
0095 os.remove(filename)
0096 with io.open(filename, "w") as parseFile:
0097 parseFile.write(fileContent)
0098
0099
0100 def createMapFile(typ, mtype):
0101 """ create file to make map parser"""
0102 mName = mtype[5:] if mtype.startswith("std::") else mtype
0103 tName = typ[5:] if typ.startswith("std::") else typ
0104 filename = "ParserStandardList_Map%s_%s.cpp" % (mName.replace(" ", ""), tName.replace(" ", ""))
0105 fileContent = """
0106 #include "ParsersStandardListCommon.h"
0107 namespace dd4hep{ namespace Parsers{
0108 IMPLEMENT_STL_MAP_PARSER(std::map,%(mtype)s,%(type)s)
0109 }}
0110 """ % {"mtype": mtype, "type": typ}
0111 fileContent = LICENSE + fileContent
0112 if os.path.exists(filename):
0113 os.remove(filename)
0114 with io.open(filename, "w") as parseFile:
0115 parseFile.write(fileContent)
0116
0117
0118 if __name__ == "__main__":
0119 createParsers()