Iguana LATEST
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
TestAlgorithm.h
1#pragma once
2// test an iguana algorithm
3
4#include <hipo4/reader.h>
5#include <iguana/algorithms/AlgorithmSequence.h>
6
7inline int TestAlgorithm(
8 std::string command,
9 std::string algo_name,
10 std::vector<std::string> prerequisite_algos,
11 std::vector<std::string> bank_names,
12 std::string data_file,
13 int data_tag,
14 int num_events,
15 std::string log_level)
16{
17
18 // check arguments
19 if(algo_name == "" || bank_names.empty()) {
20 fmt::print(stderr, "ERROR: need algorithm name and banks\n");
21 return 1;
22 }
23 if(command == "algorithm" && data_file == "") {
24 fmt::print(stderr, "ERROR: need a data file for command 'algorithm'\n");
25 return 1;
26 }
27
28 // set the concurrency model to single-threaded, for optimal performance
29 iguana::GlobalConcurrencyModel = "single";
30
31 // open the HIPO file; we use 2 readers, one for 'before' (i.e., not passed through iguana), and one for 'after'
32 // (passed through iguana), so we may compare them
33 // hipo::reader reader_before(data_file.c_str(), {data_tag}); // NOTE: not copy-constructable, so make two separate readers
34 hipo::reader reader_after(data_file.c_str(), {data_tag});
35 // auto banks_before = reader_before.getBanks(bank_names);
36 auto banks_after = reader_after.getBanks(bank_names);
37
38 // define the algorithm
40 for(auto const& prerequisite_algo : prerequisite_algos)
41 seq.Add(prerequisite_algo);
42 seq.Add(algo_name);
43 seq.SetName("TEST");
44 seq.PrintSequence();
45 seq.SetLogLevel(algo_name, log_level);
46
47 // start the algorithm
48 seq.Start(banks_after);
49
50 // event loop
51 int it_ev = 0;
52 while(reader_after.next(banks_after) && (num_events == 0 || it_ev++ < num_events)) {
53 // iterate the 'before' reader too
54 // reader_before.next(banks_before);
55 // run the algorithm
56 seq.Run(banks_after);
57 // print the banks, before and after
58 // if(log_level == "debug" || log_level == "trace") {
59 // for(decltype(bank_names)::size_type it_bank = 0; it_bank < bank_names.size(); it_bank++) {
60 // fmt::print("{:=^70}\n", fmt::format(" BEFORE: {} ", bank_names.at(it_bank)));
61 // banks_before.at(it_bank).show();
62 // fmt::print("{:=^70}\n", fmt::format(" AFTER: {} ", bank_names.at(it_bank)));
63 // banks_after.at(it_bank).show();
64 // fmt::print("\n");
65 // }
66 // }
67 }
68
69 // stop the algorithm
70 seq.Stop();
71 return 0;
72}
Algorithm: An algorithm that can run a sequence of algorithms
void Add(std::string const &algo_class_name, std::string const &algo_instance_name="")
void SetName(std::string_view name)
void PrintSequence(Logger::Level level=Logger::info) const
void SetLogLevel(std::string const &algo_instance_name, std::string const &lev)
Set an algorithm log level.
virtual bool Run(hipo::banklist &banks) const final
Run Function: Process an event's hipo::banklist
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...