diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 5c3eed6b..3fed40f2 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -130,5 +130,8 @@ jobs: - name: run test run: | test_file=$(find validation_files -name "*.hipo" | head -n1) - echo "TEST FILE = $test_file" - iguana/bin/run $test_file + echo "[+] TEST FILE: $test_file" + for exe in $(find iguana/bin -executable -type f); do + echo "[+] EXECUTE TEST: $exe" + $exe $test_file + done diff --git a/src/algorithms/clas12/event_builder_filter/EventBuilderFilter.cc b/src/algorithms/clas12/event_builder_filter/EventBuilderFilter.cc index dc137497..50b1446b 100644 --- a/src/algorithms/clas12/event_builder_filter/EventBuilderFilter.cc +++ b/src/algorithms/clas12/event_builder_filter/EventBuilderFilter.cc @@ -36,7 +36,7 @@ namespace iguana::clas12 { // filter the input bank for requested PDG code(s) for(int row = 0; row < particleBank->getRows(); row++) { auto pid = particleBank->get("pid", row); - auto accept = m_opt.pids.find(pid) != m_opt.pids.end(); + auto accept = Filter(pid); if(!accept) BlankRow(particleBank, row); m_log->Debug("input PID {} -- accept = {}", pid, accept); @@ -47,6 +47,11 @@ namespace iguana::clas12 { } + bool EventBuilderFilter::Filter(int pid) { + return m_opt.pids.find(pid) != m_opt.pids.end(); + } + + void EventBuilderFilter::Stop() { m_log->Debug("STOP {}", m_name); } diff --git a/src/algorithms/clas12/event_builder_filter/EventBuilderFilter.h b/src/algorithms/clas12/event_builder_filter/EventBuilderFilter.h index 0e36b4b8..5a5f2046 100644 --- a/src/algorithms/clas12/event_builder_filter/EventBuilderFilter.h +++ b/src/algorithms/clas12/event_builder_filter/EventBuilderFilter.h @@ -17,10 +17,13 @@ namespace iguana::clas12 { EventBuilderFilter(); ~EventBuilderFilter() {} + void Start() override { Algorithm::Start(); } void Start(bank_index_cache_t &index_cache) override; void Run(bank_vec_t banks) override; void Stop() override; + bool Filter(int pid); + private: EventBuilderFilterOptions m_opt; int b_particle, b_calo; diff --git a/src/services/Algorithm.h b/src/services/Algorithm.h index e644e69f..59ec8258 100644 --- a/src/services/Algorithm.h +++ b/src/services/Algorithm.h @@ -18,7 +18,6 @@ namespace iguana { /// Initialize an algorithm before any events are processed. /// The `Run` method will assume a default ordering of banks. - /// Derived classes likely do not need to override this method. virtual void Start(); /// Initialize an algorithm before any events are processed diff --git a/src/tests/meson.build b/src/tests/meson.build index 05c6754a..c7700773 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -1,10 +1,12 @@ -test_bin = executable( - 'run', - 'main.cc', - include_directories: project_inc, - dependencies: [ fmt_dep, hipo_dep ], - link_with: iguana_lib, - install: true, - install_dir: project_bin_install_dir, - install_rpath: project_bin_rpath, -) +foreach test_exe : [ 'run_banks', 'run_rows' ] + executable( + test_exe, + test_exe + '.cc', + include_directories: project_inc, + dependencies: [ fmt_dep, hipo_dep ], + link_with: [ iguana_lib, algo_lib ], + install: true, + install_dir: project_bin_install_dir, + install_rpath: project_bin_rpath, + ) +endforeach diff --git a/src/tests/main.cc b/src/tests/run_banks.cc similarity index 93% rename from src/tests/main.cc rename to src/tests/run_banks.cc index 19a81666..5673c02d 100644 --- a/src/tests/main.cc +++ b/src/tests/run_banks.cc @@ -43,9 +43,9 @@ int main(int argc, char **argv) { int iEvent = 0; while(reader.next(event) && (iEvent++ < numEvents || numEvents == 0)) { event.getStructure(*particleBank); - printParticles("PIDS BEFORE FILTER ", particleBank); + printParticles("PIDS BEFORE algo->Run() ", particleBank); algo->Run({particleBank, caloBank}); - printParticles("PIDS AFTER FILTER ", particleBank); + printParticles("PIDS AFTER algo->Run() ", particleBank); } ///////////////////////////////////////////////////// diff --git a/src/tests/run_rows.cc b/src/tests/run_rows.cc new file mode 100644 index 00000000..555625f9 --- /dev/null +++ b/src/tests/run_rows.cc @@ -0,0 +1,46 @@ +#include "algorithms/clas12/event_builder_filter/EventBuilderFilter.h" +#include + +int main(int argc, char **argv) { + + // parse arguments + int argi = 1; + std::string inFileName = argc > argi ? std::string(argv[argi++]) : "data.hipo"; + int numEvents = argc > argi ? std::stoi(argv[argi++]) : 3; + + // start the algorithm + auto algo = std::make_shared(); + algo->Start(); + + ///////////////////////////////////////////////////// + + // read input file + hipo::reader reader; + reader.open(inFileName.c_str()); + + // get bank schema + /* TODO: users should not have to do this; this is a workaround until + * the pattern `hipo::event::getBank("REC::Particle")` is possible + */ + hipo::dictionary factory; + reader.readDictionary(factory); + auto particleBank = std::make_shared(factory.getSchema("REC::Particle")); + + // event loop + hipo::event event; + int iEvent = 0; + while(reader.next(event) && (iEvent++ < numEvents || numEvents == 0)) { + event.getStructure(*particleBank); + fmt::print("PIDS FILTERED BY algo->Filter():\n"); + for(int row=0; rowgetRows(); row++) { + auto pid = particleBank->get("pid", row); + fmt::print("{:>10}:{}\n", pid, algo->Filter(pid) ? " -- ACCEPT" : ""); + } + + } + + ///////////////////////////////////////////////////// + + algo->Stop(); + return 0; +}