Skip to content

Commit

Permalink
feat: expose public Filter function in EventBuilderFilter (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Nov 22, 2023
1 parent be81b00 commit 4f3aaa2
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/services/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions src/tests/meson.build
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/tests/main.cc → src/tests/run_banks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/////////////////////////////////////////////////////
Expand Down
46 changes: 46 additions & 0 deletions src/tests/run_rows.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "algorithms/clas12/event_builder_filter/EventBuilderFilter.h"
#include <hipo4/reader.h>

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<iguana::clas12::EventBuilderFilter>();
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<hipo::bank>(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; row<particleBank->getRows(); row++) {
auto pid = particleBank->get("pid", row);
fmt::print("{:>10}:{}\n", pid, algo->Filter(pid) ? " -- ACCEPT" : "");
}

}

/////////////////////////////////////////////////////

algo->Stop();
return 0;
}

0 comments on commit 4f3aaa2

Please sign in to comment.