| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // test an iguana algorithm | ||
| 2 | |||
| 3 | #include <hipo4/reader.h> | ||
| 4 | #include <iguana/algorithms/AlgorithmSequence.h> | ||
| 5 | |||
| 6 | 16 | 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 2 → 3 taken 16 times.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 16 times.
|
16 | 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 6 → 8 taken 16 times.
✗ Branch 6 → 9 not taken.
✓ Branch 8 → 9 taken 16 times.
✗ Branch 8 → 11 not taken.
|
16 | 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 10 → 13 taken 16 times.
✗ Branch 10 → 80 not taken.
|
32 | 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 | 16 | hipo::reader reader_before(data_file.c_str()); // NOTE: not copy-constructable, so make two separate readers | |
| 32 |
1/2✓ Branch 19 → 20 taken 16 times.
✗ Branch 19 → 116 not taken.
|
16 | hipo::reader reader_after(data_file.c_str()); |
| 33 |
2/4✓ Branch 20 → 21 taken 16 times.
✗ Branch 20 → 114 not taken.
✓ Branch 21 → 22 taken 16 times.
✗ Branch 21 → 86 not taken.
|
16 | auto banks_before = reader_before.getBanks(bank_names); |
| 34 |
2/4✓ Branch 23 → 24 taken 16 times.
✗ Branch 23 → 112 not taken.
✓ Branch 24 → 25 taken 16 times.
✗ Branch 24 → 88 not taken.
|
16 | auto banks_after = reader_after.getBanks(bank_names); |
| 35 | |||
| 36 | // define the algorithm | ||
| 37 |
1/2✓ Branch 26 → 27 taken 16 times.
✗ Branch 26 → 110 not taken.
|
16 | iguana::AlgorithmSequence seq; |
| 38 |
2/2✓ Branch 36 → 28 taken 6 times.
✓ Branch 36 → 37 taken 16 times.
|
22 | for(auto const& prerequisite_algo : prerequisite_algos) |
| 39 |
1/2✓ Branch 29 → 30 taken 6 times.
✗ Branch 29 → 90 not taken.
|
6 | seq.Add(prerequisite_algo); |
| 40 |
1/2✓ Branch 38 → 39 taken 16 times.
✗ Branch 38 → 96 not taken.
|
16 | seq.Add(algo_name); |
| 41 |
1/2✓ Branch 44 → 45 taken 16 times.
✗ Branch 44 → 108 not taken.
|
16 | seq.SetName("TEST"); |
| 42 |
1/2✓ Branch 45 → 46 taken 16 times.
✗ Branch 45 → 108 not taken.
|
16 | seq.PrintSequence(); |
| 43 |
2/4✓ Branch 46 → 47 taken 16 times.
✗ Branch 46 → 48 not taken.
✓ Branch 48 → 49 taken 16 times.
✗ Branch 48 → 108 not taken.
|
32 | seq.SetOption(algo_name, "log", verbose ? "trace" : "info"); |
| 44 | |||
| 45 | // start the algorithm | ||
| 46 |
1/2✓ Branch 57 → 68 taken 16 times.
✗ Branch 57 → 108 not taken.
|
16 | seq.Start(banks_after); |
| 47 | |||
| 48 | // event loop | ||
| 49 | int it_ev = 0; | ||
| 50 |
5/8✓ Branch 68 → 69 taken 16016 times.
✗ Branch 68 → 108 not taken.
✓ Branch 69 → 70 taken 16016 times.
✗ Branch 69 → 73 not taken.
✓ Branch 70 → 71 taken 16016 times.
✗ Branch 70 → 72 not taken.
✓ Branch 71 → 72 taken 16000 times.
✓ Branch 71 → 73 taken 16 times.
|
16016 | while(reader_after.next(banks_after) && (num_events == 0 || it_ev++ < num_events)) { |
| 51 | // iterate the 'before' reader too | ||
| 52 |
1/2✓ Branch 72 → 58 taken 16000 times.
✗ Branch 72 → 108 not taken.
|
16000 | reader_before.next(banks_before); |
| 53 | // run the algorithm | ||
| 54 |
1/2✓ Branch 58 → 59 taken 16000 times.
✗ Branch 58 → 60 not taken.
|
16000 | if(command == "algorithm") |
| 55 |
1/2✓ Branch 59 → 68 taken 16000 times.
✗ Branch 59 → 108 not taken.
|
16000 | 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 73 → 74 taken 16 times.
✗ Branch 73 → 108 not taken.
|
16 | seq.Stop(); |
| 78 | return 0; | ||
| 79 | 16 | } | |
| 80 |