Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
TestValidator.h
1// test an iguana algorithm validator
2
3#include <filesystem>
4#include <hipo4/reader.h>
5#include <iguana/algorithms/Validator.h>
6
7inline int TestValidator(
8 std::string vdor_name,
9 std::vector<std::string> bank_names,
10 std::string data_file,
11 int num_events,
12 std::string output_dir,
13 bool verbose)
14{
15
16 // check arguments
17 if(vdor_name == "" || bank_names.empty()) {
18 fmt::print(stderr, "ERROR: need validator name and banks\n");
19 return 1;
20 }
21 if(data_file == "") {
22 fmt::print(stderr, "ERROR: need a data file for command 'validator'\n");
23 return 1;
24 }
25
26 // open the HIPO file
27 hipo::reader reader(data_file.c_str());
28 auto banks = reader.getBanks(bank_names);
29
30 // make the output directory
31 if(output_dir != "")
32 std::filesystem::create_directories(output_dir);
33
34 // define the validator
35 auto vdor = iguana::AlgorithmFactory::Create(vdor_name);
36 dynamic_cast<iguana::Validator*>(vdor.get())->SetOutputDirectory(output_dir);
37 vdor->SetOption("log", verbose ? "trace" : "info");
38
39 // event loop
40 vdor->Start(banks);
41 int it_ev = 0;
42 while(reader.next(banks) && (num_events == 0 || it_ev++ < num_events)) {
43 vdor->Run(banks);
44 }
45 vdor->Stop();
46 return 0;
47}
static algo_t Create(std::string const &name) noexcept(false)
Base class for all algorithm validators to inherit from.
Definition Validator.h:18
void SetOutputDirectory(std::string_view output_dir)