GCC Code Coverage Report


Directory: ./
File: examples/iguana_ex_cpp_00_run_functions.cc
Date: 2025-01-05 09:03:17
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 2 2 100.0%
Branches: 39 78 50.0%

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 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 taken 1 times.
✗ Branch 1 not taken.
1 char const* inFileName = argc > argi ? argv[argi++] : "data.hipo";
35
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 int const numEvents = argc > argi ? std::stoi(argv[argi++]) : 1;
36
37 // read input file
38
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 hipo::reader reader(inFileName,{0});
39
40 // set banks
41
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 hipo::banklist banks = reader.getBanks({"RUN::config",
42 "REC::Particle",
43 "REC::Calorimeter",
44 "REC::Track",
45
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 "REC::Scintillator"});
46 enum banks_enum { b_config,
47 b_particle }; // TODO: users shouldn't have to do this
48
49 // iguana algorithm sequence
50
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 iguana::AlgorithmSequence seq;
51
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 seq.Add("clas12::EventBuilderFilter"); // filter by Event Builder PID
52
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 seq.Add("clas12::SectorFinder"); // get the sector for each particle
53
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 seq.Add("clas12::MomentumCorrection"); // momentum corrections
54
55 // set log levels
56
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 seq.SetOption("clas12::EventBuilderFilter", "log", "debug");
57
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 seq.SetOption("clas12::MomentumCorrection", "log", "debug");
58
59 // set algorithm options (overrides configuration files)
60
5/12
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
2 seq.SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", {11, 211, -211});
61
62 // start the algorithms
63
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 seq.Start(banks);
64
65 // run the algorithm sequence on each event
66 int iEvent = 0;
67
5/8
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 101 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 100 times.
✓ Branch 7 taken 1 times.
101 while(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) {
68
3/6
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
100 prettyPrint("BEFORE", banks.at(b_particle));
69
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 seq.Run(banks);
70
3/6
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
200 prettyPrint("AFTER", banks.at(b_particle));
71 }
72
73 // stop algorithms
74
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 seq.Stop();
75 return 0;
76 1 }
77