Skip to content

Commit 869ec70

Browse files
Add write and delete FK table objects
1 parent e096453 commit 869ec70

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

pineappl_capi/cbindgen.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ rename_variants = "ScreamingSnakeCase"
4848
"KeyVal" = "pineappl_keyval"
4949
"SubGrid" = "pineappl_subgrid"
5050
"GridOptFlags" = "pineappl_gof"
51-
"OperatorSliceInfo" = "pineappl_operator_slice_info"
51+
"OperatorInfo" = "pineappl_operator_info"
5252

5353
############## Options for How Your Rust library Should Be Parsed ##############
5454

pineappl_capi/src/lib.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ pub unsafe extern "C" fn pineappl_grid_evolve_info(
20962096
ren1.copy_from_slice(&grid.evolve_info(&order_mask).ren1);
20972097
}
20982098

2099-
/// Evolve a grid and dump the resulting FK table
2099+
/// Evolve a grid and dump the resulting FK table.
21002100
///
21012101
/// # Safety
21022102
///
@@ -2202,3 +2202,35 @@ pub unsafe extern "C" fn pineappl_grid_evolve(
22022202

22032203
Box::new(fk_table.unwrap())
22042204
}
2205+
2206+
/// Delete an FK table.
2207+
#[no_mangle]
2208+
#[allow(unused_variables)]
2209+
pub extern "C" fn pineappl_fk_table_delete(fktable: Option<Box<FkTable>>) {}
2210+
2211+
/// Write `fktable` to a file with name `filename`. If `filename` ends in `.lz4` the Fk table is
2212+
/// automatically LZ4 compressed.
2213+
///
2214+
/// # Safety
2215+
///
2216+
/// If `fktable` does not point to a valid `FkTable` object, for example when `fktable` is a null
2217+
/// pointer, this function is not safe to call. The parameter `filename` must be a non-`NULL`,
2218+
/// non-empty, and valid C string pointing to a non-existing, but writable file.
2219+
///
2220+
/// # Panics
2221+
///
2222+
/// TODO
2223+
#[no_mangle]
2224+
pub unsafe extern "C" fn pineappl_fktable_write(fktable: *const FkTable, filename: *const c_char) {
2225+
let fktable = unsafe { &*fktable };
2226+
let filename = unsafe { CStr::from_ptr(filename) };
2227+
let filename = filename.to_string_lossy();
2228+
let path = Path::new(filename.as_ref());
2229+
let writer = File::create(path).unwrap();
2230+
2231+
if path.extension().is_some_and(|ext| ext == "lz4") {
2232+
fktable.grid().write_lz4(writer).unwrap();
2233+
} else {
2234+
fktable.grid().write(writer).unwrap();
2235+
}
2236+
}

0 commit comments

Comments
 (0)