managed_lhapdf/
ffi.rs

1pub use ffi::*;
2
3// ALLOW: as soon as the `cxx` offers a `#![cxx::bridge]` we can get rid of the `mod ffi`
4#[allow(clippy::module_inception)]
5#[cxx::bridge]
6mod ffi {
7    // The type `PdfUncertainty` must be separate from the one defined in the C++ namespace LHAPDF
8    // because it differs (at least) from LHAPDF 6.4.x to 6.5.x
9
10    /// Structure for storage of uncertainty info calculated over a PDF error set.
11    struct PdfUncertainty {
12        /// The central value.
13        pub central: f64,
14        /// The unsymmetric error in positive direction.
15        pub errplus: f64,
16        /// The unsymmetric error in negative direction.
17        pub errminus: f64,
18        /// The symmetric error.
19        pub errsymm: f64,
20        /// The scale factor needed to convert between the PDF set's default confidence level and
21        /// the requested confidence level.
22        pub scale: f64,
23        /// Extra variable for separate PDF and parameter variation errors with combined sets.
24        pub errplus_pdf: f64,
25        /// Extra variable for separate PDF and parameter variation errors with combined sets.
26        pub errminus_pdf: f64,
27        /// Extra variable for separate PDF and parameter variation errors with combined sets.
28        pub errsymm_pdf: f64,
29        /// Extra variable for separate PDF and parameter variation errors with combined sets.
30        pub err_par: f64,
31    }
32
33    #[namespace = "LHAPDF"]
34    unsafe extern "C++" {
35        include!("managed-lhapdf/include/lhapdf.hpp");
36
37        fn setVerbosity(verbosity: i32);
38        fn verbosity() -> i32;
39
40        type PDF;
41
42        fn alphasQ2(self: &PDF, q2: f64) -> Result<f64>;
43        fn xfxQ2(self: &PDF, id: i32, x: f64, q2: f64) -> Result<f64>;
44        fn lhapdfID(self: &PDF) -> i32;
45        fn xMin(self: Pin<&mut PDF>) -> f64;
46        fn xMax(self: Pin<&mut PDF>) -> f64;
47        fn setFlavors(self: Pin<&mut PDF>, flavors: &CxxVector<i32>);
48        fn setForcePositive(self: Pin<&mut PDF>, mode: i32);
49        fn flavors<'a>(self: &'a PDF) -> &'a CxxVector<i32>;
50        fn forcePositive(self: &PDF) -> i32;
51
52        type PDFSet;
53
54        fn has_key(self: &PDFSet, key: &CxxString) -> bool;
55        fn get_entry<'a>(self: &'a PDFSet, key: &CxxString) -> &'a CxxString;
56        fn size(self: &PDFSet) -> usize;
57        fn lhapdfID(self: &PDFSet) -> i32;
58    }
59
60    unsafe extern "C++" {
61        include!("managed-lhapdf/include/wrappers.hpp");
62
63        fn pdf_setname(pdf: &PDF, setname: Pin<&mut CxxString>);
64        fn pdf_with_setname_and_member(setname: &CxxString, member: i32) -> Result<UniquePtr<PDF>>;
65        fn pdfset_new(setname: &CxxString) -> Result<UniquePtr<PDFSet>>;
66        fn pdfset_setname(pdf: &PDFSet, setname: Pin<&mut CxxString>);
67
68        #[cfg(feature = "managed")]
69        fn empty_lhaindex();
70
71        fn lookup_pdf_setname(lhaid: i32, setname: Pin<&mut CxxString>);
72        fn lookup_pdf_memberid(lhaid: i32) -> i32;
73        fn get_pdfset_error_type(set: &PDFSet, setname: Pin<&mut CxxString>);
74
75        fn pdf_uncertainty(
76            pdfset: &PDFSet,
77            values: &[f64],
78            cl: f64,
79            alternative: bool,
80        ) -> Result<PdfUncertainty>;
81    }
82}