SQLamarr
The stand-alone ultra-fast simulation option for the LHCb experiment
GenerativePlugin.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 ctypes
11 from ctypes import POINTER
12 from SQLamarr import clib, c_TransformerPtr
13 from typing import List
14 
15 from SQLamarr.db_functions import SQLite3DB
16 
17 clib.new_GenerativePlugin.argtypes = (
18  ctypes.c_void_p, # void *db,
19  ctypes.c_char_p, # const char* library_path,
20  ctypes.c_char_p, # const char* function_name,
21  ctypes.c_char_p, # const char* query,
22  ctypes.c_char_p, # const char* output_table,
23  ctypes.c_char_p, # const char* comma_separated_outputs,
24  ctypes.c_int, # int n_random,
25  ctypes.c_char_p, # const char* comma_separated_references
26  )
27 
28 clib.new_GenerativePlugin.restype = c_TransformerPtr
29 
31  """
32  Wrapper to a compiled parametrization taking conditions and noise as input.
33 
34  Python bindings for SQLamarr::GenerativePlugin.
35  """
36  def __init__ (
37  self,
38  db: SQLite3DB,
39  library_path: str,
40  function_name: str,
41  query: str,
42  output_table: str,
43  outputs: List[str],
44  nRandom: int,
45  references: List[str]
46  ):
47  """
48  Configure a `Transformer` to wrap a parametrization function defined
49  in an external library.
50 
51  @param db: An open database connection;
52  @param library_path: path-like position of the shared library;
53  @param function_name: linker symbol of the function to wrap;
54  @param query: SQL query defining the reference indices and the inputs to
55  be passed to the wrapped function;
56  @param output_table: name of the output TEMPORARY TABLE where outputs are
57  stored toghether with the reference indices;
58  @param outputs: list of the output column names for further reference;
59  @param nRandom: number of normally distributed random noise values;
60  @param references: list of reference indices `SELECT`ed by the `query`,
61  but not part of the input to the wrapped function.
62  """
63  self._self_self = clib.new_GenerativePlugin(
64  db.get(),
65  library_path.encode('ascii'),
66  function_name.encode('ascii'),
67  query.encode('ascii'),
68  output_table.encode('ascii'),
69  ";".join(outputs).encode('ascii'),
70  int(nRandom),
71  ";".join(references).encode('ascii'),
72  )
73 
74  def __del__(self):
75  """@private: Release the bound class instance"""
76  clib.del_Transformer(self._self_self)
77 
78  @property
79  def raw_pointer(self):
80  """@private: Return the raw pointer to the algorithm."""
81  return self._self_self
82 
83 
84 
Wrapper to a compiled parametrization taking conditions and noise as input.
def __init__(self, SQLite3DB db, str library_path, str function_name, str query, str output_table, List[str] outputs, int nRandom, List[str] references)
Configure a Transformer to wrap a parametrization function defined in an external library.