Skip to content

Commit

Permalink
refactor: minimize example (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Dec 9, 2023
1 parent ac6d156 commit 2e9dc74
Showing 1 changed file with 24 additions and 33 deletions.
57 changes: 24 additions & 33 deletions src/tests/run_banks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,48 @@
#include "algorithms/clas12/lorentz_transformer/LorentzTransformer.h"
#include <hipo4/reader.h>

void printParticles(const std::string prefix, hipo::bank& b) {
std::vector<int> pids;
for(int row=0; row<b.getRows(); row++)
pids.push_back(b.getInt("pid", row));
fmt::print("{}: {}\n", prefix, fmt::join(pids, ", "));
// show a bank along with a header
void prettyPrint(std::string header, hipo::bank& bank) {
fmt::print("{:=^70}\n", " "+header+" ");
bank.show();
}

int main(int argc, char **argv) {

// parse arguments
int argi = 1;
const std::string inFileName = argc > argi ? std::string(argv[argi++]) : "data.hipo";
const int numEvents = argc > argi ? std::stoi(argv[argi++]) : 1;
const char* inFileName = argc > argi ? argv[argi++] : "data.hipo";
const int numEvents = argc > argi ? std::stoi(argv[argi++]) : 1;

// read input file
hipo::reader reader(inFileName);

// set banks
hipo::banklist banks = reader.getBanks({ "REC::Particle", "REC::Calorimeter" });
enum banks_enum { b_particle, b_calo }; // TODO: users shouldn't have to do this

// iguana algorithm sequence
iguana::AlgorithmSequence seq;
seq.Add<iguana::clas12::EventBuilderFilter>("pid_filter");
seq.Add<iguana::clas12::LorentzTransformer>("mirror_frame");
seq.PrintSequence();
seq.Add<iguana::clas12::EventBuilderFilter>("pid_filter"); // filter by Event Builder PID
seq.Add<iguana::clas12::LorentzTransformer>("new_frame"); // Lorentz transform the momenta

// set log levels
seq.SetOption("pid_filter", "log", "trace");
seq.SetOption("mirror_frame", "log", "trace");
seq.SetOption("pid_filter", "log", "debug");
seq.SetOption("new_frame", "log", "debug");

// set algorithm options
seq.SetOption("pid_filter", "pids", std::set<int>{11, 211, -211});
seq.SetOption("pid_filter", "testInt", 3);
seq.SetOption("pid_filter", "testFloat", 11.0);
seq.SetOption("mirror_frame", "frame", "mirror");

// read input file
hipo::reader reader(inFileName.c_str());

// set banks
hipo::banklist banks = reader.getBanks({
"REC::Particle",
"REC::Calorimeter"
});
enum banks_enum { // TODO: make this nicer
b_particle,
b_calo
};
seq.SetOption("pid_filter", "pids", std::set<int>{11, 211, -211});
seq.SetOption("new_frame", "frame", "mirror");

// start the algorithms
seq.Start(banks);

// event loop
// run the algorithm sequence on each event
int iEvent = 0;
while(reader.next(banks) && (iEvent++ < numEvents || numEvents == 0)) {
printParticles("PIDS BEFORE algo->Run() ", banks.at(b_particle));
while(reader.next(banks) && (numEvents==0 || iEvent++ < numEvents)) {
prettyPrint("BEFORE", banks.at(b_particle));
seq.Run(banks);
printParticles("PIDS AFTER algo->Run() ", banks.at(b_particle));
prettyPrint("AFTER", banks.at(b_particle));
}

// stop algorithms
Expand Down

0 comments on commit 2e9dc74

Please sign in to comment.