diff --git a/compile/test/jetreconstruction_test.c b/compile/test/jetreconstruction_test.c index 0a04917..0f4b32e 100644 --- a/compile/test/jetreconstruction_test.c +++ b/compile/test/jetreconstruction_test.c @@ -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; @@ -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); diff --git a/src/C_JetReconstruction/C_JetReconstruction.jl b/src/C_JetReconstruction/C_JetReconstruction.jl index 4c12334..03303a7 100644 --- a/src/C_JetReconstruction/C_JetReconstruction.jl +++ b/src/C_JetReconstruction/C_JetReconstruction.jl @@ -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) @@ -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 end