Line | Branch | Exec | Source |
---|---|---|---|
1 | /// @begin_doc_example{cpp} | ||
2 | /// @file iguana_ex_cpp_00_run_functions.cc | ||
3 | /// @brief Example using **full HIPO banks** with Iguana algorithms' `Run` functions. This example requires the | ||
4 | /// user to have the C++ `hipo::bank` objects; see other examples if you do not have banks in this format. | ||
5 | /// @par Usage | ||
6 | /// ```bash | ||
7 | /// iguana_ex_cpp_00_run_functions [HIPO_FILE] [NUM_EVENTS] | ||
8 | /// | ||
9 | /// HIPO_FILE the HIPO file to analyze | ||
10 | /// | ||
11 | /// NUM_EVENTS the number of events to analyze; | ||
12 | /// set to zero to analyze all events | ||
13 | /// ``` | ||
14 | /// @end_doc_example | ||
15 | |||
16 | #include <hipo4/reader.h> | ||
17 | #include <iguana/algorithms/AlgorithmSequence.h> | ||
18 | |||
19 | /// @brief show a bank along with a header | ||
20 | /// @param header the header to print above the bank | ||
21 | /// @param bank the bank to show | ||
22 | 200 | void prettyPrint(std::string header, hipo::bank& bank) | |
23 | { | ||
24 |
1/2✓ Branch 0 (8→9) taken 200 times.
✗ Branch 1 (8→11) not taken.
|
400 | fmt::print("{:=^70}\n", " " + header + " "); |
25 | 200 | bank.show(); | |
26 | 200 | } | |
27 | |||
28 | /// main function | ||
29 | 1 | int main(int argc, char** argv) | |
30 | { | ||
31 | |||
32 | // parse arguments | ||
33 | int argi = 1; | ||
34 |
1/2✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→12) not taken.
|
1 | char const* inFileName = argc > argi ? argv[argi++] : "data.hipo"; |
35 |
1/2✓ Branch 0 (3→4) taken 1 times.
✗ Branch 1 (3→12) not taken.
|
1 | int const numEvents = argc > argi ? std::stoi(argv[argi++]) : 1; |
36 | |||
37 | // read input file | ||
38 |
1/2✓ Branch 0 (13→14) taken 1 times.
✗ Branch 1 (13→148) not taken.
|
1 | hipo::reader reader(inFileName,{0}); |
39 | |||
40 | // set list of banks to be read | ||
41 |
1/2✓ Branch 0 (17→18) taken 1 times.
✗ Branch 1 (17→252) not taken.
|
2 | hipo::banklist banks = reader.getBanks({"RUN::config", |
42 | "REC::Particle", | ||
43 | "REC::Calorimeter", | ||
44 | "REC::Track", | ||
45 |
1/2✓ Branch 0 (18→19) taken 1 times.
✗ Branch 1 (18→152) not taken.
|
1 | "REC::Scintillator"}); |
46 | |||
47 | // get bank index, for each bank we want to use after Iguana algorithms run | ||
48 |
2/4✓ Branch 0 (20→21) taken 1 times.
✗ Branch 1 (20→250) not taken.
✓ Branch 2 (21→22) taken 1 times.
✗ Branch 3 (21→154) not taken.
|
1 | auto b_particle = hipo::getBanklistIndex(banks, "REC::Particle"); |
49 | |||
50 | // iguana algorithm sequence | ||
51 |
2/4✓ Branch 0 (27→28) taken 1 times.
✗ Branch 1 (27→250) not taken.
✓ Branch 2 (28→29) taken 1 times.
✗ Branch 3 (28→248) not taken.
|
1 | iguana::AlgorithmSequence seq; |
52 |
3/8✓ Branch 0 (29→30) taken 1 times.
✗ Branch 1 (29→166) not taken.
✓ Branch 2 (30→31) taken 1 times.
✗ Branch 3 (30→160) not taken.
✓ Branch 4 (36→37) taken 1 times.
✗ Branch 5 (36→39) not taken.
✗ Branch 6 (166→167) not taken.
✗ Branch 7 (166→169) not taken.
|
2 | seq.Add("clas12::EventBuilderFilter"); // filter by Event Builder PID |
53 |
3/8✓ Branch 0 (42→43) taken 1 times.
✗ Branch 1 (42→178) not taken.
✓ Branch 2 (43→44) taken 1 times.
✗ Branch 3 (43→172) not taken.
✓ Branch 4 (49→50) taken 1 times.
✗ Branch 5 (49→52) not taken.
✗ Branch 6 (178→179) not taken.
✗ Branch 7 (178→181) not taken.
|
2 | seq.Add("clas12::SectorFinder"); // get the sector for each particle |
54 |
3/8✓ Branch 0 (55→56) taken 1 times.
✗ Branch 1 (55→190) not taken.
✓ Branch 2 (56→57) taken 1 times.
✗ Branch 3 (56→184) not taken.
✓ Branch 4 (62→63) taken 1 times.
✗ Branch 5 (62→65) not taken.
✗ Branch 6 (190→191) not taken.
✗ Branch 7 (190→193) not taken.
|
2 | seq.Add("clas12::MomentumCorrection"); // momentum corrections |
55 | // TODO: | ||
56 | // - getRowList for filter | ||
57 | // - add a creator algo | ||
58 | |||
59 | // set log levels | ||
60 |
3/8✓ Branch 0 (67→68) taken 1 times.
✗ Branch 1 (67→248) not taken.
✓ Branch 2 (68→69) taken 1 times.
✗ Branch 3 (68→202) not taken.
✓ Branch 4 (77→78) taken 1 times.
✗ Branch 5 (77→80) not taken.
✗ Branch 6 (202→203) not taken.
✗ Branch 7 (202→205) not taken.
|
2 | seq.SetOption("clas12::EventBuilderFilter", "log", "debug"); |
61 |
3/8✓ Branch 0 (82→83) taken 1 times.
✗ Branch 1 (82→248) not taken.
✓ Branch 2 (83→84) taken 1 times.
✗ Branch 3 (83→214) not taken.
✓ Branch 4 (92→93) taken 1 times.
✗ Branch 5 (92→95) not taken.
✗ Branch 6 (214→215) not taken.
✗ Branch 7 (214→217) not taken.
|
2 | seq.SetOption("clas12::MomentumCorrection", "log", "debug"); |
62 | |||
63 | // set algorithm options (overrides configuration files) | ||
64 |
6/16✓ Branch 0 (97→98) taken 1 times.
✗ Branch 1 (97→248) not taken.
✓ Branch 2 (98→99) taken 1 times.
✗ Branch 3 (98→232) not taken.
✓ Branch 4 (99→100) taken 1 times.
✗ Branch 5 (99→226) not taken.
✓ Branch 6 (100→101) taken 1 times.
✗ Branch 7 (100→220) not taken.
✓ Branch 8 (106→107) taken 1 times.
✗ Branch 9 (106→109) not taken.
✓ Branch 10 (111→112) taken 1 times.
✗ Branch 11 (111→114) not taken.
✗ Branch 12 (226→227) not taken.
✗ Branch 13 (226→229) not taken.
✗ Branch 14 (232→233) not taken.
✗ Branch 15 (232→235) not taken.
|
3 | seq.SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", {11, 211, -211}); |
65 | |||
66 | // start the algorithms | ||
67 |
1/2✓ Branch 0 (114→132) taken 1 times.
✗ Branch 1 (114→248) not taken.
|
1 | seq.Start(banks); |
68 | |||
69 | // run the algorithm sequence on each event | ||
70 | int iEvent = 0; | ||
71 |
5/8✓ Branch 0 (132→133) taken 101 times.
✗ Branch 1 (132→248) not taken.
✓ Branch 2 (133→134) taken 101 times.
✗ Branch 3 (133→137) not taken.
✓ Branch 4 (134→135) taken 101 times.
✗ Branch 5 (134→136) not taken.
✓ Branch 6 (135→136) taken 100 times.
✓ Branch 7 (135→137) taken 1 times.
|
101 | while(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) { |
72 |
3/6✓ Branch 0 (115→116) taken 100 times.
✗ Branch 1 (115→248) not taken.
✓ Branch 2 (116→117) taken 100 times.
✗ Branch 3 (116→236) not taken.
✓ Branch 4 (136→115) taken 100 times.
✗ Branch 5 (136→248) not taken.
|
100 | prettyPrint("BEFORE", banks.at(b_particle)); |
73 |
1/2✓ Branch 0 (122→123) taken 100 times.
✗ Branch 1 (122→248) not taken.
|
100 | seq.Run(banks); |
74 |
3/6✓ Branch 0 (123→124) taken 100 times.
✗ Branch 1 (123→248) not taken.
✓ Branch 2 (124→125) taken 100 times.
✗ Branch 3 (124→248) not taken.
✓ Branch 4 (125→126) taken 100 times.
✗ Branch 5 (125→242) not taken.
|
200 | prettyPrint("AFTER", banks.at(b_particle)); |
75 | } | ||
76 | |||
77 | // stop algorithms | ||
78 |
1/2✓ Branch 0 (137→138) taken 1 times.
✗ Branch 1 (137→248) not taken.
|
1 | seq.Stop(); |
79 | return 0; | ||
80 | 1 | } | |
81 |