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