Skip to content

Commit

Permalink
add writing jets selections results to ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Nov 12, 2024
1 parent 940c464 commit 321f097
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions compile/test/jetreconstruction_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ void printClusterSequence(const jetreconstruction_ClusterSequence *sequence) {
}
}

void printJetsResult(const jetreconstruction_JetsResult *results) {
assert(results != NULL);
for (size_t i = 0; i < results->length; ++i) {
printPseudoJet(results->data + i);
}
}

int main(int argc, char *argv[]) {
init_julia(argc, argv);
size_t len = 2;
Expand All @@ -60,6 +67,8 @@ int main(int argc, char *argv[]) {
printClusterSequence(&cluster_seq);
jetreconstruction_JetsResult result;
jetreconstruction_exclusive_jets_njets(&cluster_seq, 2, &result);
printJetsResult(&result);

jetreconstruction_JetsResult_free_members(&result);
jetreconstruction_ClusterSequence_free_members(&cluster_seq);
shutdown_julia(0);
Expand Down
5 changes: 3 additions & 2 deletions src/C_JetReconstruction/C_JetReconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Wraps a C array into a Julia `Vector` for both bits and non-bits types.
This function use 'unsafe' methods and has undefined behaviour
if pointer isn't valid or length isn't correct.
"""

function unsafe_wrap_c_array(ptr::Ptr{T}, array_length::Csize_t) where {T}
if isbitstype(T)
return unsafe_wrap(Vector{T}, ptr, array_length)

Check warning on line 29 in src/C_JetReconstruction/C_JetReconstruction.jl

View check run for this annotation

Codecov / codecov/patch

src/C_JetReconstruction/C_JetReconstruction.jl#L27-L29

Added lines #L27 - L29 were not covered by tests
Expand Down Expand Up @@ -163,9 +164,9 @@ function jets_selection(selector, clustersequence::Ptr{C_ClusterSequence{T}},
result::Ptr{C_JetsResult{U}}; kwargs...)::Cint where {T, U}
c_clusterseq = unsafe_load(clustersequence)
clusterseq = ClusterSequence{T}(c_clusterseq)
jets_result = selector(clusterseq; kwargs...)
jets_result = selector(clusterseq; T=U, kwargs...)
println(jets_result)
c_results = C_JetsResult{U}(C_NULL, 0) # TODO convert and write to result
c_results = C_JetsResult{U}(make_c_array(jets_result)...)
unsafe_store!(result, c_results)
return 0

Check warning on line 171 in src/C_JetReconstruction/C_JetReconstruction.jl

View check run for this annotation

Codecov / codecov/patch

src/C_JetReconstruction/C_JetReconstruction.jl#L165-L171

Added lines #L165 - L171 were not covered by tests
end
Expand Down

0 comments on commit 321f097

Please sign in to comment.