Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:45

0001 # ==========================================================================
0002 #  AIDA Detector description implementation
0003 # --------------------------------------------------------------------------
0004 # Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 # All rights reserved.
0006 #
0007 # For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 # For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 #
0010 # ==========================================================================
0011 #
0012 from __future__ import absolute_import, unicode_literals
0013 import traceback
0014 import sys
0015 from ROOT import gSystem
0016 
0017 import os
0018 import logging
0019 import platform
0020 if platform.system() == "Darwin":
0021   gSystem.SetDynamicPath(os.environ['DD4HEP_LIBRARY_PATH'])
0022 gSystem.Load('libglapi')
0023 gSystem.Load('libDDPython')
0024 from ROOT import dd4hep as Core  # noqa
0025 
0026 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0027 logger = logging.getLogger(__name__)
0028 
0029 name_space = __import__(__name__)
0030 
0031 
0032 def import_namespace_item(ns, nam):
0033   scope = getattr(name_space, ns)
0034   attr = getattr(scope, nam)
0035   setattr(name_space, nam, attr)
0036   return attr
0037 
0038 
0039 def a_func():
0040   logger.info('Hello world')
0041   return 1
0042 
0043 
0044 class a_class:
0045   def __init__(self):
0046     pass
0047 
0048   def fcn(self):
0049     logger.info('Hello world from member function fcn')
0050     return 1
0051 
0052   def fcn_except(self, args, aa):
0053     logger.info('Hello world from member function fcn1 a1=%s a2=%s', str(args), str(aa))
0054     raise RuntimeError('Except from python test object a_class')
0055     return 6
0056 
0057 
0058 py = import_namespace_item('Core', 'DDPython')
0059 
0060 logger.info('+++++ Test: Execute statements in python with C++ indirection')
0061 py.instance().execute(str('import sys, logging'))
0062 py.instance().execute(str('logging.info("Arguments: %s", str(sys.argv))'))
0063 logger.info('\n')
0064 
0065 obj = a_class()
0066 
0067 logger.info('+++++ Test: simple function call')
0068 ret = py.instance().call(a_func, None)
0069 logger.info('ret: %s', str(ret))
0070 logger.info('\n')
0071 
0072 logger.info('+++++ Test: object method call')
0073 ret = py.instance().call(obj.fcn, None)
0074 logger.info('ret: %s', str(ret))
0075 logger.info('\n')
0076 
0077 logger.info('+++++ Test: object method call with non callable')
0078 try:
0079   ret = py.instance().call(1, None)
0080   logger.info('ret: %s', str(ret))
0081 except Exception:
0082   traceback.print_exc()
0083 logger.info('\n')
0084 
0085 logger.info('+++++ Test: object method call with exception in python callback')
0086 try:
0087   ret = py.instance().call(obj.fcn_except, (1, [1, 2, 3, 4, 5, 6],))
0088   logger.info('ret: %s', str(ret))
0089 except Exception:
0090   traceback.print_exc()
0091 logger.info('\n')
0092 logger.info('+++++ All Done....\n\n')
0093 logger.info('TEST_PASSED')
0094 
0095 # py.instance().prompt()
0096 
0097 sys.exit(0)