GCC Code Coverage Report


Directory: ./
File: src/iguana/tests/include/TestAlgorithm.h
Date: 2025-03-24 18:50:00
Exec Total Coverage
Lines: 22 31 71.0%
Functions: 1 1 100.0%
Branches: 33 68 48.5%

Line Branch Exec Source
1 // test an iguana algorithm
2
3 #include <hipo4/reader.h>
4 #include <iguana/algorithms/AlgorithmSequence.h>
5
6 12 inline int TestAlgorithm(
7 std::string command,
8 std::string algo_name,
9 std::vector<std::string> prerequisite_algos,
10 std::vector<std::string> bank_names,
11 std::string data_file,
12 int num_events,
13 bool verbose)
14 {
15
16 // check arguments
17
2/4
✓ Branch 0 (2→3) taken 12 times.
✗ Branch 1 (2→4) not taken.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→6) taken 12 times.
12 if(algo_name == "" || bank_names.empty()) {
18 fmt::print(stderr, "ERROR: need algorithm name and banks\n");
19 return 1;
20 }
21
2/4
✓ Branch 0 (6→8) taken 12 times.
✗ Branch 1 (6→9) not taken.
✓ Branch 2 (8→9) taken 12 times.
✗ Branch 3 (8→11) not taken.
12 if(command == "algorithm" && data_file == "") {
22 fmt::print(stderr, "ERROR: need a data file for command 'algorithm'\n");
23 return 1;
24 }
25
26 // set the concurrency model to single-threaded, for optimal performance
27
1/2
✓ Branch 0 (10→13) taken 12 times.
✗ Branch 1 (10→62) not taken.
24 iguana::GlobalConcurrencyModel = "single";
28
29 // open the HIPO file; we use 2 readers, one for 'before' (i.e., not passed through iguana), and one for 'after'
30 // (passed through iguana), so we may compare them
31 12 hipo::reader reader_before(data_file.c_str()); // NOTE: not copy-constructable, so make two separate readers
32
1/2
✓ Branch 0 (15→16) taken 12 times.
✗ Branch 1 (15→82) not taken.
12 hipo::reader reader_after(data_file.c_str());
33
2/4
✓ Branch 0 (16→17) taken 12 times.
✗ Branch 1 (16→80) not taken.
✓ Branch 2 (17→18) taken 12 times.
✗ Branch 3 (17→64) not taken.
12 auto banks_before = reader_before.getBanks(bank_names);
34
3/6
✓ Branch 0 (19→20) taken 12 times.
✗ Branch 1 (19→78) not taken.
✓ Branch 2 (20→21) taken 12 times.
✗ Branch 3 (20→66) not taken.
✓ Branch 4 (22→23) taken 12 times.
✗ Branch 5 (22→76) not taken.
12 auto banks_after = reader_after.getBanks(bank_names);
35
36 // define the algorithm
37
1/2
✓ Branch 0 (22→23) taken 12 times.
✗ Branch 1 (22→76) not taken.
12 iguana::AlgorithmSequence seq;
38
2/2
✓ Branch 0 (28→24) taken 4 times.
✓ Branch 1 (28→29) taken 12 times.
16 for(auto const& prerequisite_algo : prerequisite_algos)
39
2/4
✓ Branch 0 (24→25) taken 4 times.
✗ Branch 1 (24→74) not taken.
✓ Branch 2 (25→26) taken 4 times.
✗ Branch 3 (25→68) not taken.
8 seq.Add(prerequisite_algo);
40
3/6
✓ Branch 0 (29→30) taken 12 times.
✗ Branch 1 (29→74) not taken.
✓ Branch 2 (30→31) taken 12 times.
✗ Branch 3 (30→70) not taken.
✓ Branch 4 (32→33) taken 12 times.
✗ Branch 5 (32→74) not taken.
24 seq.Add(algo_name);
41
1/2
✓ Branch 0 (32→33) taken 12 times.
✗ Branch 1 (32→74) not taken.
12 seq.SetName("TEST");
42
1/2
✓ Branch 0 (33→34) taken 12 times.
✗ Branch 1 (33→74) not taken.
12 seq.PrintSequence();
43
2/4
✓ Branch 0 (34→35) taken 12 times.
✗ Branch 1 (34→36) not taken.
✓ Branch 2 (36→37) taken 12 times.
✗ Branch 3 (36→74) not taken.
24 seq.SetOption(algo_name, "log", verbose ? "trace" : "info");
44
45 // start the algorithm
46
1/2
✓ Branch 0 (41→50) taken 12 times.
✗ Branch 1 (41→74) not taken.
12 seq.Start(banks_after);
47
48 // event loop
49 int it_ev = 0;
50
5/8
✓ Branch 0 (50→51) taken 12012 times.
✗ Branch 1 (50→74) not taken.
✓ Branch 2 (51→52) taken 12012 times.
✗ Branch 3 (51→55) not taken.
✓ Branch 4 (52→53) taken 12012 times.
✗ Branch 5 (52→54) not taken.
✓ Branch 6 (53→54) taken 12000 times.
✓ Branch 7 (53→55) taken 12 times.
12012 while(reader_after.next(banks_after) && (num_events == 0 || it_ev++ < num_events)) {
51 // iterate the 'before' reader too
52
1/2
✓ Branch 0 (54→42) taken 12000 times.
✗ Branch 1 (54→74) not taken.
12000 reader_before.next(banks_before);
53 // run the algorithm
54
1/2
✓ Branch 0 (42→43) taken 12000 times.
✗ Branch 1 (42→44) not taken.
12000 if(command == "algorithm")
55
1/2
✓ Branch 0 (43→50) taken 12000 times.
✗ Branch 1 (43→74) not taken.
12000 seq.Run(banks_after);
56 else if(command == "unit") {
57 fmt::print(stderr, "ERROR: unit tests are not yet implemented (TODO)\n");
58 return 1;
59 }
60 else {
61 fmt::print(stderr, "ERROR: unknown command '{}'\n", command);
62 return 1;
63 }
64 // print the banks, before and after
65 // if(verbose) {
66 // for(decltype(bank_names)::size_type it_bank = 0; it_bank < bank_names.size(); it_bank++) {
67 // fmt::print("{:=^70}\n", fmt::format(" BEFORE: {} ", bank_names.at(it_bank)));
68 // banks_before.at(it_bank).show();
69 // fmt::print("{:=^70}\n", fmt::format(" AFTER: {} ", bank_names.at(it_bank)));
70 // banks_after.at(it_bank).show();
71 // fmt::print("\n");
72 // }
73 // }
74 }
75
76 // stop the algorithm
77
1/2
✓ Branch 0 (55→56) taken 12 times.
✗ Branch 1 (55→74) not taken.
12 seq.Stop();
78 return 0;
79 12 }
80