Expand description

The C-language interface for PineAPPL.

The PineAPPL Application Programming Interface for the C language (CAPI) defines types and functions that allow one to use PineAPPL without having to write Rust code, and instead using

  • C or C++ (see the C++ example in the repository).
  • Fortran can be used as well, using the iso_c_binding module to wrap CAPI’s functions (see the Fortran example in the repository).

Note that the CAPI only defines a subset of functionality available in the Rust module, which is extended on an as-needed basis. If you happen to miss a function please open a new issue on the github page.

Using and linking the CAPI

To use PineAPPL’s CAPI you have to include its header pineappl_capi.h. To successfully build your program, you should rely on pkgconf or pkg-conf, as follows:

pkg-config --cflags pineappl_capi
pkg-config --libs pineappl_capi

This will read PineAPPL’s .pc file and print the neccessary CFLAGS (--cflags) and linker flags (--libs). This procedure is supported by many build systems, such as

Strings and other types

All strings used in this library, denoted with the Rust type *const c_char or *mut c_char, which correspond to the C types const char* and char*, respectively, are assumed to be encoded using UTF-8, which Rust uses internally. The conversions are performed using CStr::to_string_lossy, which you can consult on how strings are converted.

All other built-in types in Rust (f64, usize, i32, u32, …) correspond to types in C as defined by the translation tables of cbindgen. If in doubt, consult the generated header pineappl_capi.h.

Structs

Key-value storage for passing optional information during grid creation with pineappl_grid_new.

Type for defining a luminosity function.

Type for reading and accessing subgrids.

Functions

Returns the number of bins in grid.

Returns the number of dimensions of the bins this grid has.

Write the left limits for the specified dimension into left.

Write the right limits for the specified dimension into right.

Stores the bin sizes of grid in bin_sizes.

Returns a cloned object of grid.

Convolutes the specified grid with the PDF xfx, which is the PDF for a hadron with the PDG id pdg_id, and strong coupling alphas. These functions must evaluate the PDFs for the given x and q2 for the parton with the given PDG id, pdg_id, and return the result. Note that the value must be the PDF multiplied with its argument x. The value of the pointer state provided to these functions is the same one given to this function. The parameter order_mask must be as long as there are perturbative orders contained in grid and is used to selectively disable (false) or enable (true) individual orders. If order_mask is set to NULL, all orders are active. The parameter lumi_mask can be used similarly, but must be as long as the luminosity function grid was created with has entries, or NULL to enable all luminosities. The values xi_ren and xi_fac can be used to vary the renormalization and factorization from its central value, which corresponds to 1.0. After convolution of the grid with the PDFs the differential cross section for each bin is written into results.

Convolutes the specified grid with the PDFs xfx1 and xfx2, which are the PDFs of hadrons with PDG ids pdg_id1 and pdg_id2, respectively, and strong coupling alphas. These functions must evaluate the PDFs for the given x and q2 for the parton with the given PDG id, pdg_id, and return the result. Note that the value must be the PDF multiplied with its argument x. The value of the pointer state provided to these functions is the same one given to this function. The parameter order_mask must be as long as there are perturbative orders contained in grid and is used to selectively disable (false) or enable (true) individual orders. If order_mask is set to NULL, all orders are active. The parameter lumi_mask can be used similarly, but must be as long as the luminosity function grid was created with has entries, or NULL to enable all luminosities. The values xi_ren and xi_fac can be used to vary the renormalization and factorization from its central value, which corresponds to 1.0. After convolution of the grid with the PDFs the differential cross section for each bin is written into results.

Delete a grid previously created with pineappl_grid_new.

Fills buffer with the q2-slice for the index q2_slice of the grid for the specified order, bin, and lumi.

Fill grid for the given momentum fractions x1 and x2, at the scale q2 for the given value of the order, observable, and lumi with weight.

Fill grid for the given momentum fractions x1 and x2, at the scale q2 for the given value of the order and observable with weights. The parameter of weight must contain a result for entry of the luminosity function the grid was created with.

Fill grid with as many points as indicated by size.

Return the value for key stored in grid. If key isn’t found, NULL will be returned. After usage the string must be deallocated using pineappl_string_delete.

Return the luminosity function of grid.

Merges other into grid and subsequently deletes other.

Creates a new and empty grid. The creation requires four different sets of parameters:

Write into tuple the lower and upper limit of filled q2 slices for the grid with the specified indices. The last slice that is filled is one minus the upper limit.

Optimizes the grid representation for space efficiency.

Return the number of orders in grid.

Write the order parameters of grid into order_params.

Read a PineAPPL grid from a file with name filename.

This function takes replaces the subgrid in grid with the corresponding indices order, bin and lumi with the one given in subgrid. If subgrid is the null pointer, the specied subgrid is replaced with an empty one.

Scale all grids in grid by factor.

Scales each subgrid by a factor which is the product of the given values alphas, alpha, logxir, and logxif, each raised to the corresponding powers for each subgrid. In addition, every subgrid is scaled by a factor global independently of its order.

Sets an internal key-value pair for the grid.

Sets a remapper for the grid. This can be used to ‘upgrade’ one-dimensional bin limits to N-dimensional ones. The new bin limits must be given in the form of tuples giving the left and right limits, and a tuple for each dimension.

Write grid to a file with name filename. If filename ends in .lz4 the grid is automatically LZ4 compressed.

Get the boolean-valued parameter with name key stored in key_vals.

Delete the previously created object pointed to by key_vals.

Get the double-valued parameter with name key stored in key_vals.

Get the string-valued parameter with name key stored in key_vals.

Return a pointer to newly-created pineappl_keyval object.

Set the double-valued parameter with name key to value in key_vals.

Set the double-valued parameter with name key to value in key_vals.

Set the int-valued parameter with name key to value in key_vals.

Set the string-valued parameter with name key to value in key_vals.

Get the int-valued parameter with name key stored in key_vals.

Adds a linear combination of initial states to the luminosity function lumi.

Returns the number of combinations of the luminosity function lumi for the specified entry.

Returns the number of channel for the luminosity function lumi.

Delete luminosity function previously created with pineappl_lumi_new.

Read out the channel with index entry of the luminosity function lumi. The PDG ids and factors will be copied into pdg_ids and factors.

Creates a new luminosity function and returns a pointer to it. If no longer needed, the object should be deleted using pineappl_lumi_delete.

Deletes a string previously allocated by pineappl_grid_key_value. If string is a NULL pointer this function does nothing.

Deletes a subgrid created with pineappl_subgrid_new2. If subgrid is the null pointer, nothing is done.

Imports slice for the given index into subgrid.

Creates a new subgrid, which can be filled with pineappl_subgrid_import_mu2_slice. The array mu2_grid must contain the (squared) values of the renormalization and then the factorization scale, such that twice the value of mu2_grid_len gives the length of the array.