13.2.4. Macro “howtoPassReference.py”
13.2.4.1. Objective
The goal of this macro is to show how to use function that would have been defined using the
“by-reference” prototype, which is specific to C++. A simple exemple in Uranie is provided when
considering the computeQuantile method: the second argument is a double in which the result will
be stored.
13.2.4.2. Macro Uranie
"""
Example of C++style reference usage
"""
from ctypes import c_double # for ROOT version greater or equal to 6.20
from URANIE import DataServer
# create a dataserver and read data
tds = DataServer.TDataServer("pouet", "foo")
tds.fileDataRead("myData.dat")
# compute quantile (this method get the results 'by reference')
proba = 0.9 # ROOT.Double(0.9) for ROOT version lower than 6.20
quant = c_double(0.0) # ROOT.Double(0.0) for ROOT version lower than 6.20
# Compute the quantile and dump the value returned by reference
tds.computeQuantile("x", proba, quant)
print("Result is ")
print(quant.value)
It starts by calling the ctypes module in order to get the c_double interface. This is only for
ROOT version greater than 6.20. For older version, the solution relied on ROOT only (calling
another interface discussed later-on).
from ctypes import c_double # for ROOT version greater or equal to 6.20
Once done, a TDataServer object is created and filled from the myData.dat file. One then wants to
estimate the 90% quantile, which can be done by calling the computeQuantile method, which requires
two double as input, both passed “by-reference”. To do so, one has to create two specific objects as
below:
proba = 0.9 # ROOT.Double(0.9) for ROOT version lower than 6.20
quant = c_double(0.0) # ROOT.Double(0.0) for ROOT version lower than 6.20
Once done, the method is called and the result is displayed by getting the value of the c_double
object
print(quant.value)
The output of this macro is shown in Console.
13.2.4.3. Console
--- Uranie v4.11/0 --- Developed with ROOT (6.36.06)
Copyright (C) 2013-2026 CEA/DES
Contact: support-uranie@cea.fr
Date: Thu Feb 12, 2026
Result is
4.0