Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose public Filter function in EventBuilderFilter #19

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}