Skip to content

Commit 34ae3b8

Browse files
committed
Specify the number of convolutions once in pineappl_channels_new
1 parent f4bdde0 commit 34ae3b8

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

examples/cpp/advanced-filling.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ int main() {
1111
// Construct the channel object based on the nb of convolutions
1212
std::size_t nb_convolutions = 2;
1313
std::size_t nb_channels = 2;
14-
auto* channels = pineappl_channels_new();
14+
auto* channels = pineappl_channels_new(nb_convolutions);
1515
int32_t pids[] = { 2, -2, 4, -4 };
1616
double factors[] = { 1.0, 1.0 };
17-
pineappl_channels_add(channels, nb_channels, nb_convolutions, pids, factors);
17+
pineappl_channels_add(channels, nb_channels, pids, factors);
1818

1919
std::size_t channel_count = 1;
2020

examples/cpp/fill-grid.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,8 @@ int main() {
115115
// ---
116116
// Create all channels
117117

118-
// this object will contain all channels (initial states) that we define
119-
auto* channels = pineappl_channels_new();
120-
121-
// Specify the dimension of the channel, ie the number of convolutions required
122-
std::size_t nb_convolutions = 2;
118+
// this object will contain all channels (for two initial states) that we define
119+
auto* channels = pineappl_channels_new(2);
123120

124121
// photon-photon initial state, where `22` is the photon (PDG MC ids)
125122
int32_t pids1[] = { 22, 22 };
@@ -128,7 +125,7 @@ int main() {
128125
double factors1[] = { 1.0 };
129126

130127
// define the channel #0
131-
pineappl_channels_add(channels, 1, nb_convolutions, pids1, factors1);
128+
pineappl_channels_add(channels, 1, pids1, factors1);
132129

133130
// create another channel, which we won't fill, however
134131

@@ -143,7 +140,7 @@ int main() {
143140
// can also pass `nullptr`
144141

145142
// define the channel #1
146-
pineappl_channels_add(channels, 3, nb_convolutions, pids2, nullptr);
143+
pineappl_channels_add(channels, 3, pids2, nullptr);
147144

148145
// ---
149146
// Specify the perturbative orders that will be filled into the grid

pineappl_capi/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ pub unsafe extern "C" fn pineappl_string_delete(string: *mut c_char) {
14611461

14621462
/// Type for defining a Channel function.
14631463
#[derive(Default)]
1464-
pub struct Channels(Vec<Channel>);
1464+
pub struct Channels(Vec<Channel>, usize);
14651465

14661466
/// Type for defining the interpolation object
14671467
#[repr(C)]
@@ -1486,8 +1486,8 @@ pub struct Interp {
14861486
/// should be deleted using `pineappl_channels_delete`.
14871487
#[no_mangle]
14881488
#[must_use]
1489-
pub extern "C" fn pineappl_channels_new() -> Box<Channels> {
1490-
Box::default()
1489+
pub extern "C" fn pineappl_channels_new(convolutions: usize) -> Box<Channels> {
1490+
Box::new(Channels(Vec::new(), convolutions))
14911491
}
14921492

14931493
/// Adds a generalized linear combination of initial states to the Luminosity.
@@ -1503,13 +1503,12 @@ pub extern "C" fn pineappl_channels_new() -> Box<Channels> {
15031503
pub unsafe extern "C" fn pineappl_channels_add(
15041504
channels: *mut Channels,
15051505
combinations: usize,
1506-
nb_convolutions: usize,
15071506
pdg_id_combinations: *const i32,
15081507
factors: *const f64,
15091508
) {
15101509
let channels = unsafe { &mut *channels };
15111510
let pdg_id_pairs =
1512-
unsafe { slice::from_raw_parts(pdg_id_combinations, nb_convolutions * combinations) };
1511+
unsafe { slice::from_raw_parts(pdg_id_combinations, channels.1 * combinations) };
15131512
let factors = if factors.is_null() {
15141513
vec![1.0; combinations]
15151514
} else {
@@ -1518,9 +1517,9 @@ pub unsafe extern "C" fn pineappl_channels_add(
15181517

15191518
channels.0.push(Channel::new(
15201519
pdg_id_pairs
1521-
.chunks(nb_convolutions)
1520+
.chunks(channels.1)
15221521
.zip(factors)
1523-
.map(|x| ((0..nb_convolutions).map(|i| x.0[i]).collect(), x.1))
1522+
.map(|x| ((0..channels.1).map(|i| x.0[i]).collect(), x.1))
15241523
.collect(),
15251524
));
15261525
}
@@ -1535,7 +1534,10 @@ pub unsafe extern "C" fn pineappl_channels_add(
15351534
pub unsafe extern "C" fn pineappl_grid_channels(grid: *const Grid) -> Box<Channels> {
15361535
let grid = unsafe { &*grid };
15371536

1538-
Box::new(Channels(grid.channels().to_vec()))
1537+
Box::new(Channels(
1538+
grid.channels().to_vec(),
1539+
grid.convolutions().len(),
1540+
))
15391541
}
15401542

15411543
/// An exact duplicate of `pineappl_lumi_count` to make naming (lumi -> channel) consistent.
@@ -1639,7 +1641,7 @@ pub unsafe extern "C" fn pineappl_grid_new2(
16391641
let channels = unsafe { &*channels };
16401642

16411643
// Construct the convolution objects
1642-
let convolutions = channels.0[0].entry()[0].0.len();
1644+
let convolutions = channels.1;
16431645
let convolution_types =
16441646
unsafe { slice::from_raw_parts(convolution_types, convolutions).to_vec() };
16451647
let convolution_pdg_ids =

0 commit comments

Comments
 (0)