Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
iguana_ex_cpp_00_run_functions.cc
Go to the documentation of this file.
1
15
16#include <hipo4/reader.h>
17#include <iguana/algorithms/AlgorithmSequence.h>
18
22void prettyPrint(std::string header, hipo::bank& bank)
23{
24 fmt::print("{:=^70}\n", " " + header + " ");
25 bank.show();
26}
27
29int main(int argc, char** argv)
30{
31
32 // parse arguments
33 int argi = 1;
34 char const* inFileName = argc > argi ? argv[argi++] : "data.hipo";
35 int const numEvents = argc > argi ? std::stoi(argv[argi++]) : 1;
36
37 // read input file
38 hipo::reader reader(inFileName,{0});
39
40 // set banks
41 hipo::banklist banks = reader.getBanks({"RUN::config",
42 "REC::Particle",
43 "REC::Calorimeter",
44 "REC::Track",
45 "REC::Scintillator"});
46 enum banks_enum { b_config,
47 b_particle }; // TODO: users shouldn't have to do this
48
49 // iguana algorithm sequence
51 seq.Add("clas12::EventBuilderFilter"); // filter by Event Builder PID
52 seq.Add("clas12::SectorFinder"); // get the sector for each particle
53 seq.Add("clas12::MomentumCorrection"); // momentum corrections
54
55 // set log levels
56 seq.SetOption("clas12::EventBuilderFilter", "log", "debug");
57 seq.SetOption("clas12::MomentumCorrection", "log", "debug");
58
59 // set algorithm options (overrides configuration files)
60 seq.SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", {11, 211, -211});
61
62 // start the algorithms
63 seq.Start(banks);
64
65 // run the algorithm sequence on each event
66 int iEvent = 0;
67 while(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) {
68 prettyPrint("BEFORE", banks.at(b_particle));
69 seq.Run(banks);
70 prettyPrint("AFTER", banks.at(b_particle));
71 }
72
73 // stop algorithms
74 seq.Stop();
75 return 0;
76}
User-level class for running a sequence of algorithms.
void SetOption(std::string const &algo_name, std::string const &key, const OPTION_TYPE val)
void Stop() override
Finalize this algorithm after all events are processed.
void Run(hipo::banklist &banks) const override
Run this algorithm for an event.
void Add(std::string const &class_name, std::string const &instance_name="")
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks
int main(int argc, char **argv)
main function
void prettyPrint(std::string header, hipo::bank &bank)
show a bank along with a header