(use_cases_howto_py_pass_reference_py)= # Macro **"howtoPassReference.py"** ## 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. ## Macro {{uranie}} {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/overview/use_cases/python/howtoPassReference.py\n" + ":language: python\n" + ":lines: 1-5,11-23\n" + "```" }} 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). {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/overview/use_cases/python/howtoPassReference.py\n" + ":language: python\n" + ":lines: 4\n" + "```" }} Once done, a {{tds}} 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: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/overview/use_cases/python/howtoPassReference.py\n" + ":language: python\n" + ":lines: 17-18\n" + "```" }} Once done, the method is called and the result is displayed by getting the value of the `c_double` object {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/overview/use_cases/python/howtoPassReference.py\n" + ":language: python\n" + ":lines: 23\n" + "```" }} The output of this macro is shown in [](#use_cases_howto_py_pass_reference_py_console). (use_cases_howto_py_pass_reference_py_console)= ## Console {{ "```{literalinclude} " + parent_dir + "/roottest/build/uranie/doc/overview/use_cases/python/howtoPassReference_clean.log\n" + ":language: none\n" + ":lines: 2-8\n" + "```" }}