Iguana
1.1.0
Implementation Guardian of Analysis Algorithms
Toggle main menu visibility
Loading...
Searching...
No Matches
TestAlgorithm.h
1
// test an iguana algorithm
2
3
#include <hipo4/reader.h>
4
#include <iguana/algorithms/AlgorithmSequence.h>
5
6
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
if
(algo_name ==
""
|| bank_names.empty()) {
18
fmt::print(stderr,
"ERROR: need algorithm name and banks\n"
);
19
return
1;
20
}
21
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
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
hipo::reader reader_before(data_file.c_str());
// NOTE: not copy-constructable, so make two separate readers
32
hipo::reader reader_after(data_file.c_str());
33
auto
banks_before = reader_before.getBanks(bank_names);
34
auto
banks_after = reader_after.getBanks(bank_names);
35
36
// define the algorithm
37
iguana::AlgorithmSequence
seq;
38
for
(
auto
const
& prerequisite_algo : prerequisite_algos)
39
seq.
Add
(prerequisite_algo);
40
seq.
Add
(algo_name);
41
seq.
SetName
(
"TEST"
);
42
seq.
PrintSequence
();
43
seq.
SetOption
(algo_name,
"log"
, verbose ?
"trace"
:
"info"
);
44
45
// start the algorithm
46
seq.
Start
(banks_after);
47
48
// event loop
49
int
it_ev = 0;
50
while
(reader_after.next(banks_after) && (num_events == 0 || it_ev++ < num_events)) {
51
// iterate the 'before' reader too
52
reader_before.next(banks_before);
53
// run the algorithm
54
if
(command ==
"algorithm"
)
55
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
seq.
Stop
();
78
return
0;
79
}
iguana::AlgorithmSequence
Algorithm: An algorithm that can run a sequence of algorithms
Definition
AlgorithmSequence.h:46
iguana::AlgorithmSequence::Stop
void Stop() override
Finalize this algorithm after all events are processed.
iguana::AlgorithmSequence::Add
void Add(std::string const &algo_class_name, std::string const &algo_instance_name="")
iguana::AlgorithmSequence::SetOption
void SetOption(std::string const &algo_instance_name, std::string const &key, const OPTION_TYPE val)
Definition
AlgorithmSequence.h:117
iguana::AlgorithmSequence::Start
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks.
iguana::AlgorithmSequence::SetName
void SetName(std::string_view name)
iguana::AlgorithmSequence::PrintSequence
void PrintSequence(Logger::Level level=Logger::info) const
iguana::AlgorithmSequence::Run
bool Run(hipo::banklist &banks) const override
Run Function: Process an event's hipo::banklist
iguana_v1.1.0
src
iguana
tests
include
TestAlgorithm.h
Generated by
1.18.0