Skip to content

Commit f2d59c5

Browse files
committed
add example cmake downstream, add comments
1 parent 4934f00 commit f2d59c5

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed

compile/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ In case the compiled library resides in non-standard location, add its location
6363
LD_LIBRARY_PATH=JetReconstructionCompiled/lib/:${LD_LIBRARY_PATH} ./jetreconstruction_test
6464
```
6565

66+
### Compilation with CMake
67+
68+
The JetReconstruction library comes with a CMake target `JetReconstruction::JetReconstruction`. Example usage in CMake file:
69+
70+
```cmake
71+
find_package(JetReconstruction REQUIRED)
72+
73+
target_link_libraries(myTarget PUBLIC JetReconstruction::JetReconstruction)
74+
```
75+
76+
## Limitations
77+
78+
Currently it's not possible to create libraries for different platforms - no cross-compilation!
79+
80+
The library is relocatable given the whole installation tree is moved, including libraries in the `lib/julia/` directory.
81+
82+
It's advised to install the library in a separate directory to avoid possible conflicts.
83+
The library must not be installed in the same directory as another Julia package compiled with `PackageCompiler.jl` as they would overwrite the package specific files in `share/julia`.

compile/downstream/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project(
4+
JetReconstruction_downstream
5+
LANGUAGES C
6+
VERSION 0.1.0)
7+
8+
find_package(JetReconstruction 0.4.3 REQUIRED)
9+
10+
add_executable(jetreconstruction_test jetreconstruction_test.c)
11+
target_link_libraries(jetreconstruction_test
12+
PUBLIC JetReconstruction::JetReconstruction)
13+
14+
enable_testing()
15+
add_test(NAME JetReconstructionTest COMMAND jetreconstruction_test)

compile/downstream/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Downstream project example
2+
3+
Example downstream project using C-bindings of JetReconstruction.jl
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "JetReconstruction.h"
2+
#include "julia_init.h"
3+
#include <assert.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <time.h>
7+
8+
void printPseudoJet(const jetreconstruction_PseudoJet *jet) {
9+
assert(jet != NULL);
10+
printf("PseudoJet(%f %f %f %f %ld %f %f %f %f)\n", jet->px, jet->py, jet->pz,
11+
jet->E, jet->_cluster_hist_index, jet->_pt2, jet->_inv_pt2, jet->_rap,
12+
jet->_phi);
13+
}
14+
15+
void printHistoryElement(const jetreconstruction_HistoryElement *history) {
16+
assert(history != NULL);
17+
printf("HistoryElement(%ld %ld %ld %ld %lf %lf)\n", history->parent1,
18+
history->parent2, history->child, history->jetp_index, history->dij,
19+
history->max_dij_so_far);
20+
}
21+
22+
void printClusterSequence(const jetreconstruction_ClusterSequence *sequence) {
23+
printf("Cluster Sequence Information:\n"
24+
"Algorithm: %d\n"
25+
"Power: %f\n"
26+
"R parameter: %f\n"
27+
"Strategy: %d\n"
28+
"Initial number of jets: %ld\n"
29+
"Total event energy (Qtot): %f\n",
30+
sequence->algorithm, sequence->power, sequence->R, sequence->strategy,
31+
sequence->n_initial_jets, sequence->Qtot);
32+
printf("Number of jets: %zu\n", sequence->jets_length);
33+
if (sequence->jets != NULL) {
34+
for (size_t i = 0; i < sequence->jets_length; i++) {
35+
printPseudoJet(sequence->jets + i);
36+
}
37+
}
38+
printf("History length: %zu\n", sequence->history_length);
39+
if (sequence->history != NULL) {
40+
for (size_t i = 0; i < sequence->history_length; i++) {
41+
printHistoryElement(sequence->history + i);
42+
}
43+
}
44+
}
45+
46+
void printJetsResult(const jetreconstruction_JetsResult *results) {
47+
assert(results != NULL);
48+
for (size_t i = 0; i < results->length; ++i) {
49+
printPseudoJet(results->data + i);
50+
}
51+
}
52+
53+
int main(int argc, char *argv[]) {
54+
clock_t start_time = clock();
55+
init_julia(argc, argv);
56+
size_t len = 2;
57+
jetreconstruction_PseudoJet particles[2];
58+
jetreconstruction_PseudoJet_init(&particles[0], 0.0, 1.0, 2.0, 3.0);
59+
jetreconstruction_PseudoJet_init(&particles[1], 1.0, 2.0, 3.0, 4.0);
60+
61+
jetreconstruction_JetAlgorithm algorithm = JETRECONSTRUCTION_JETALGORITHM_CA;
62+
double R = 3.0;
63+
jetreconstruction_RecoStrategy strategy = JETRECONSTRUCTION_RECOSTRATEGY_BEST;
64+
65+
jetreconstruction_ClusterSequence cluster_seq;
66+
jetreconstruction_jet_reconstruct(particles, len, algorithm, R, strategy,
67+
&cluster_seq);
68+
69+
printClusterSequence(&cluster_seq);
70+
jetreconstruction_JetsResult result;
71+
jetreconstruction_exclusive_jets_njets(&cluster_seq, 2, &result);
72+
printJetsResult(&result);
73+
74+
jetreconstruction_JetsResult_free_members(&result);
75+
jetreconstruction_ClusterSequence_free_members(&cluster_seq);
76+
shutdown_julia(0);
77+
78+
clock_t end_time = clock();
79+
double time_spent = (double)(end_time - start_time) / CLOCKS_PER_SEC;
80+
printf("Execution time: %f seconds\n", time_spent);
81+
return 0;
82+
}

compile/precompile_execution.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Dummy code to call and cache compilation of all C-bindings
2+
# The numeric values doesn't make sense and are used only to select correct dispatch
13

24
using JetReconstruction
35
using JetReconstruction.C_JetReconstruction: jetreconstruction_PseudoJet_init,

0 commit comments

Comments
 (0)