Skip to content
Snippets Groups Projects
CreateParsers.py 3.61 KiB
Newer Older
Marko Petric's avatar
Marko Petric committed
This file will automaticcaly create the cpp files for the parsers
for pod and std::containers of pods, and some other maps
Marko Petric's avatar
Marko Petric committed
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

"""

from __future__ import absolute_import, unicode_literals
Marko Petric's avatar
Marko Petric committed
from io import open
Marko Petric's avatar
Marko Petric committed
LICENSE = """// $Id$
//==========================================================================
Marko Petric's avatar
Marko Petric committed
//  AIDA Detector description implementation
//--------------------------------------------------------------------------
// 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.
//
//==========================================================================
"""

Marko Petric's avatar
Marko Petric committed

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',
Marko Petric's avatar
Marko Petric committed
                 ]
  listOfContainers = ['std::vector', 'std::list', 'std::set', 'std::deque']
  listOfMaps = ['int', 'unsigned long', 'std::string', ]

  for typ in listOfTypes:
    for cont in listOfContainers:
Marko Petric's avatar
Marko Petric committed
      createContainerFile(typ, cont)
Marko Petric's avatar
Marko Petric committed
      createMapFile(typ, mtype)

    createMappedFile(typ)
Marko Petric's avatar
Marko Petric committed
def createMappedFile(typ):
  """ create file for mapped parsers """
  tName = typ[5:] if typ.startswith("std::") else typ
Marko Petric's avatar
Marko Petric committed
  filename = "ParserStandardList_Mapped_%s.cpp" % (tName.replace(" ", ""))
  fileContent = """
#include "ParsersStandardListCommon.h"
Markus Frank's avatar
Markus Frank committed
namespace dd4hep{ namespace Parsers{
IMPLEMENT_MAPPED_PARSERS(pair,%(type)s)
  }}
Marko Petric's avatar
Marko Petric committed
""" % {"type": typ}
  fileContent = LICENSE + fileContent
  if os.path.exists(filename):
    os.remove(filename)
  with open(filename, "w") as parseFile:
    parseFile.write(fileContent)


Marko Petric's avatar
Marko Petric committed
def createContainerFile(typ, cont):
  """create file to make container parser"""
  tName = typ[5:] if typ.startswith("std::") else typ
Marko Petric's avatar
Marko Petric committed
  filename = "ParserStandardList_%s_%s.cpp" % (cont[5:], tName.replace(" ", ""))
  fileContent = """
#include "ParsersStandardListCommon.h"
Markus Frank's avatar
Markus Frank committed
namespace dd4hep{ namespace Parsers{
IMPLEMENT_STL_PARSER(%(cont)s,%(type)s)
  }}
Marko Petric's avatar
Marko Petric committed
""" % {"cont": cont, "type": typ}
  fileContent = LICENSE + fileContent
  if os.path.exists(filename):
    os.remove(filename)
  with open(filename, "w") as parseFile:
    parseFile.write(fileContent)


Marko Petric's avatar
Marko Petric committed
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
Marko Petric's avatar
Marko Petric committed
  filename = "ParserStandardList_Map%s_%s.cpp" % (mName.replace(" ", ""), tName.replace(" ", ""))
  fileContent = """
#include "ParsersStandardListCommon.h"
Markus Frank's avatar
Markus Frank committed
namespace dd4hep{ namespace Parsers{
IMPLEMENT_STL_MAP_PARSER(std::map,%(mtype)s,%(type)s)
  }}
Marko Petric's avatar
Marko Petric committed
""" % {"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()