SQLamarr
The stand-alone ultra-fast simulation option for the LHCb experiment
SQLamarr.db_functions.SQLite3DB Class Reference

A database connection handler easying sharing the DB between C++ and Python. More...

Public Member Functions

def __init__ (self, str path="file::memory:?cache=shared")
 Open the connection for the C++ application, with shared cache to ease access from Python to the same tables. More...
 
def seed (self, int seed)
 Define the seed for the random number generated from Transformers interacting with the database through this connection. More...
 
def connect (self)
 Python-like connection with a context-manager. More...
 

Detailed Description

A database connection handler easying sharing the DB between C++ and Python.

Definition at line 24 of file db_functions.py.

Constructor & Destructor Documentation

◆ __init__()

def SQLamarr.db_functions.SQLite3DB.__init__ (   self,
str   path = "file::memory:?cache=shared" 
)

Open the connection for the C++ application, with shared cache to ease access from Python to the same tables.

Parameters
pathpath-like or URI identifying the target resource; by default, an non-threadsafe connection to an in-memory database is opened.

Examples

Connecting to an existing, prepared database stored on file mydata.db

db = SQLamarr.SQLite3DB("mydata.db")

Connecting to an empty, in-memory database for prototyping

db = SQLamarr.SQLite3DB()

Connecting to an empty, in-memory database in a multithreaded application with each thread working on its own db.

db_wn1 = SQLamarr.SQLite3DB("file:wn1?mode=memory&cache=shared")
db_wn2 = SQLamarr.SQLite3DB("file:wn2?mode=memory&cache=shared")

Definition at line 29 of file db_functions.py.

Member Function Documentation

◆ connect()

def SQLamarr.db_functions.SQLite3DB.connect (   self)

Python-like connection with a context-manager.

Example.

# Define the DB handler and seeds the random number generator
db = SQLamarr.SQLite3DB().seed(42)
# Load some event from HepMC2 ASCII file
loader = SQLamarr.HepMC2DataLoader(db)
loader.load(<file_path>, <evtNumber>,<runNumber>)
# Connect to the DB (while still open in C++ memory!)
with db.connect() as c:
# Loads in a pandas DataFrame the object
df = pandas.read_sql_query("SELECT * FROM GenParticles")

Definition at line 81 of file db_functions.py.

◆ seed()

def SQLamarr.db_functions.SQLite3DB.seed (   self,
int  seed 
)

Define the seed for the random number generated from Transformers interacting with the database through this connection.

Parameters
seedinteger seed for randomization
Returns
SQLite3DB (self) instance

Definition at line 68 of file db_functions.py.


The documentation for this class was generated from the following file: