Iguana LATEST
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
TestBanklist.h
1// test banklist behavior
2
3#include <cassert>
4#include <hipo4/reader.h>
5#include <iguana/algorithms/AlgorithmSequence.h>
6
7inline int TestBanklist(
8 std::string data_file,
9 bool verbose)
10{
11
12 if(data_file == "") {
13 fmt::print(stderr, "ERROR: need a data file for command 'banklist'\n");
14 return 1;
15 }
16
17 // set the concurrency model to single-threaded, for optimal performance
18 iguana::GlobalConcurrencyModel = "single";
19
20 // input bank names
21 std::vector<std::string> input_bank_names = {
22 "REC::Particle",
23 "RUN::config",
24 "REC::Track",
25 "REC::Calorimeter",
26 "REC::Scintillator",
27 };
28
29 // open the HIPO file
30 hipo::reader reader(data_file.c_str());
31 auto banks = reader.getBanks(input_bank_names);
32
33 // define the algorithm sequence
34 std::vector<std::string> algo_names = {
35 "creator_1a",
36 "creator_2",
37 "creator_1b",
38 };
40 seq.Add("clas12::SectorFinder", "creator_1a");
41 seq.Add("clas12::CalorimeterLinker", "creator_2");
42 seq.Add("clas12::SectorFinder", "creator_1b");
43
44 // print the sequence
45 seq.PrintSequence();
46
47 // start the sequence
48 seq.Start(banks);
49
50 // print the banklist
51 fmt::println("BANKLIST:");
52 for(decltype(banks)::size_type i = 0; i < banks.size(); i++) {
53 auto& bank = banks.at(i);
54 fmt::println(" - {}: {}", i, bank.getSchema().getName());
55 }
56
57 // assert variants
58 assert((seq.Get("creator_1a")->GetCreatedBankVariant() == 0));
59 assert((seq.Get("creator_1b")->GetCreatedBankVariant() == 1));
60 assert((seq.Get("creator_2")->GetCreatedBankVariant() == 0));
61
62 // assert return values of `iguana::tools::GetBankIndex`
64 for(decltype(input_bank_names)::size_type i = 0; i < input_bank_names.size(); i++) {
65 auto const& bank_name = input_bank_names.at(i);
66 auto const idx = iguana::tools::GetBankIndex(banks, bank_name);
67 assert((idx == i));
68 }
70 for(decltype(algo_names)::size_type i = 0; i < algo_names.size(); i++) {
71 auto const& algo_name = algo_names.at(i);
72 auto const idx = iguana::tools::GetBankIndex(banks, seq.GetCreatedBankName(algo_name), seq.Get(algo_name)->GetCreatedBankVariant());
73 assert((idx == input_bank_names.size() + i));
74 }
75
76 // assert equivalence to `Algorithm::GetBankIndex` and `AlgorithmSequence::GetBankIndex`
77 for(auto const& algo_name : algo_names) {
79 for(auto const& bank_name : input_bank_names) {
80 auto const idx = iguana::tools::GetBankIndex(banks, bank_name);
81 assert((idx == seq.Get(algo_name)->GetBankIndex(banks, bank_name)));
82 assert((idx == seq.GetBankIndex(banks, bank_name, algo_name)));
83 }
85 auto const idx = iguana::tools::GetBankIndex(banks, seq.GetCreatedBankName(algo_name), seq.Get(algo_name)->GetCreatedBankVariant());
86 assert((idx == seq.Get(algo_name)->GetBankIndex(banks, seq.GetCreatedBankName(algo_name))));
87 assert((idx == seq.GetBankIndex(banks, seq.GetCreatedBankName(algo_name), algo_name)));
88 }
89
90 // assert equivalence to `Algorithm::GetCreatedBankIndex` and `AlgorithmSequence::GetCreatedBankIndex`
91 for(auto const& algo_name : algo_names) {
92 auto const idx = iguana::tools::GetBankIndex(banks, seq.GetCreatedBankName(algo_name), seq.Get(algo_name)->GetCreatedBankVariant());
93 assert((idx == seq.Get(algo_name)->GetCreatedBankIndex(banks)));
94 assert((idx == seq.GetCreatedBankIndex(banks, algo_name)));
95 }
96
97 // stop the algorithm
98 seq.Stop();
99 return 0;
100}
Algorithm: An algorithm that can run a sequence of algorithms
hipo::banklist::size_type GetCreatedBankIndex(hipo::banklist &banks, std::string const &algo_instance_name) const noexcept(false)
void Stop() override
Finalize this algorithm after all events are processed.
void Add(std::string const &algo_class_name, std::string const &algo_instance_name="")
ALGORITHM * Get(std::string const &algo_instance_name)
std::string GetCreatedBankName(std::string const &algo_instance_name) const noexcept(false)
hipo::banklist::size_type GetBankIndex(hipo::banklist &banks, std::string const &bank_name, std::string const &algo_instance_name) const noexcept(false)
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks.
void PrintSequence(Logger::Level level=Logger::info) const
hipo::banklist::size_type GetBankIndex(hipo::banklist &banks, std::string const &bank_name, unsigned int const &variant=0) noexcept(false)