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(std::string data_file)
8{
9
10 if(data_file == "") {
11 fmt::print(stderr, "ERROR: need a data file for command 'banklist'\n");
12 return 1;
13 }
14
15 // set the concurrency model to single-threaded, for optimal performance
16 iguana::GlobalConcurrencyModel = "single";
17
18 // input bank names
19 std::vector<std::string> input_bank_names = {
20 "REC::Particle",
21 "RUN::config",
22 "REC::Track",
23 "REC::Calorimeter",
24 "REC::Scintillator",
25 };
26
27 // open the HIPO file
28 hipo::reader reader(data_file.c_str());
29 auto banks = reader.getBanks(input_bank_names);
30
31 // define the algorithm sequence
32 std::vector<std::string> algo_names = {
33 "creator_1a",
34 "creator_2",
35 "creator_1b",
36 };
38 seq.Add("clas12::SectorFinder", "creator_1a");
39 seq.Add("clas12::CalorimeterLinker", "creator_2");
40 seq.Add("clas12::SectorFinder", "creator_1b");
41
42 // print the sequence
43 seq.PrintSequence();
44
45 // start the sequence
46 seq.Start(banks);
47
48 // print the banklist
49 fmt::println("BANKLIST:");
50 for(decltype(banks)::size_type i = 0; i < banks.size(); i++) {
51 auto& bank = banks.at(i);
52 fmt::println(" - {}: {}", i, bank.getSchema().getName());
53 }
54
55 // assert variants
56 assert((seq.Get("creator_1a")->GetCreatedBankVariant() == 0));
57 assert((seq.Get("creator_1b")->GetCreatedBankVariant() == 1));
58 assert((seq.Get("creator_2")->GetCreatedBankVariant() == 0));
59
60 // assert return values of `iguana::tools::GetBankIndex`
62 for(decltype(input_bank_names)::size_type i = 0; i < input_bank_names.size(); i++) {
63 auto const& bank_name = input_bank_names.at(i);
64 auto const idx = iguana::tools::GetBankIndex(banks, bank_name);
65 assert((idx == i));
66 }
68 for(decltype(algo_names)::size_type i = 0; i < algo_names.size(); i++) {
69 auto const& algo_name = algo_names.at(i);
70 auto const idx = iguana::tools::GetBankIndex(banks, seq.GetCreatedBankName(algo_name), seq.Get(algo_name)->GetCreatedBankVariant());
71 assert((idx == input_bank_names.size() + i));
72 }
73
74 // assert equivalence to `Algorithm::GetBankIndex` and `AlgorithmSequence::GetBankIndex`
75 for(auto const& algo_name : algo_names) {
77 for(auto const& bank_name : input_bank_names) {
78 auto const idx = iguana::tools::GetBankIndex(banks, bank_name);
79 assert((idx == seq.Get(algo_name)->GetBankIndex(banks, bank_name)));
80 assert((idx == seq.GetBankIndex(banks, bank_name, algo_name)));
81 }
83 auto const idx = iguana::tools::GetBankIndex(banks, seq.GetCreatedBankName(algo_name), seq.Get(algo_name)->GetCreatedBankVariant());
84 assert((idx == seq.Get(algo_name)->GetBankIndex(banks, seq.GetCreatedBankName(algo_name))));
85 assert((idx == seq.GetBankIndex(banks, seq.GetCreatedBankName(algo_name), algo_name)));
86 }
87
88 // assert equivalence to `Algorithm::GetCreatedBankIndex` and `AlgorithmSequence::GetCreatedBankIndex`
89 for(auto const& algo_name : algo_names) {
90 auto const idx = iguana::tools::GetBankIndex(banks, seq.GetCreatedBankName(algo_name), seq.Get(algo_name)->GetCreatedBankVariant());
91 assert((idx == seq.Get(algo_name)->GetCreatedBankIndex(banks)));
92 assert((idx == seq.GetCreatedBankIndex(banks, algo_name)));
93 }
94
95 // stop the algorithm
96 seq.Stop();
97 return 0;
98}
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 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 PrintSequence(Logger::Level level=Logger::info) const
virtual void Stop() final
Stop Function: Finalize this algorithm after all events are processed.
virtual void Start(hipo::banklist &banks) final
Start Function: Initialize this algorithm before any events are processed, with the intent to process...
hipo::banklist::size_type GetBankIndex(hipo::banklist &banks, std::string const &bank_name, unsigned int const &variant=0) noexcept(false)