SQLamarr
The stand-alone ultra-fast simulation option for the LHCb experiment
_find_CDLL.py
1 # (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration.
2 #
3 # This software is distributed under the terms of the GNU General Public
4 # Licence version 3 (GPL Version 3), copied verbatim in the file "LICENCE".
5 #
6 # In applying this licence, CERN does not waive the privileges and immunities
7 # granted to it by virtue of its status as an Intergovernmental Organization
8 # or submit itself to any jurisdiction.
9 
10 import os
11 import ctypes
12 import glob
13 
14 def _find_CDLL():
15  """@private: resolve the compiled DLL"""
16  cwd = os.path.dirname(__file__)
17 
18  # Define resolution strategy for the C++ shared object
19  resolution_attempts = (
20  # Search in the same directory as this source file, first (pip-installed)
21  glob.glob(os.path.join(cwd, "libSQLamarr.*.so")) +
22  [
23  # Search for the bare name without platform modifiers (manually-installed)
24  os.path.join(cwd, "libSQLamarr.so"),
25  # Search in the system lib/ directory (CMake-installed)
26  "libSQLamarr.so",
27  ]
28  )
29 
30 
31 
32  clib = None
33  for resolution_attempt in resolution_attempts:
34  try:
35  clib = ctypes.CDLL(resolution_attempt)
36  except OSError:
37  continue
38  else:
39  break
40 
41 
42  if clib is None:
43  raise OSError("Failed loading libSQLamarr.so")
44 
45  return clib
46 
47