From 7054a040a66876b46913c039508e9b4e0305f84d Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 20 Jan 2026 10:20:53 -0500 Subject: [PATCH 1/2] feat: example subclass algorithm Demonstrate how to write an algorithm that inherits from an existing algorithm; for example, suppose RG-B want to use RG-A's fiducial cuts, but with different configuration-parameter values, and perhaps extend the `Run` function a bit. RG-B's algorithm could inherit from that of RG-A. --- .../example/ExampleAlgorithm/README.md | 4 ++++ .../ExampleSubclassAlgorithm/Action.yaml | 4 ++++ .../ExampleSubclassAlgorithm/Algorithm.cc | 4 ++++ .../ExampleSubclassAlgorithm/Algorithm.h | 21 +++++++++++++++++++ .../ExampleSubclassAlgorithm/Config.yaml | 13 ++++++++++++ src/iguana/algorithms/meson.build | 8 +++++++ 6 files changed, 54 insertions(+) create mode 100644 src/iguana/algorithms/example/ExampleSubclassAlgorithm/Action.yaml create mode 100644 src/iguana/algorithms/example/ExampleSubclassAlgorithm/Algorithm.cc create mode 100644 src/iguana/algorithms/example/ExampleSubclassAlgorithm/Algorithm.h create mode 100644 src/iguana/algorithms/example/ExampleSubclassAlgorithm/Config.yaml diff --git a/src/iguana/algorithms/example/ExampleAlgorithm/README.md b/src/iguana/algorithms/example/ExampleAlgorithm/README.md index a8bf0690..2d465bfc 100644 --- a/src/iguana/algorithms/example/ExampleAlgorithm/README.md +++ b/src/iguana/algorithms/example/ExampleAlgorithm/README.md @@ -40,5 +40,9 @@ Once you have generated your new algorithm: > errors, and will allow you to _see_ the documentation before it's deployed > online. +> [!TIP] +> If you are writing an algorithm that is very similar to another algorithm, consider inheriting from it; +> see [`ExampleSubclassAlgorithm`](../ExampleSubclassAlgorithm) for an example. + > [!TIP] > Enable debugging symbols when building by setting the Iguana build option `buildtype` to `debug`. diff --git a/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Action.yaml b/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Action.yaml new file mode 100644 index 00000000..e63a6836 --- /dev/null +++ b/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Action.yaml @@ -0,0 +1,4 @@ +algorithm: + name: 'example::ExampleSubclassAlgorithm' +include: + - '../../clas12/rga/FiducialFilterPass1/Action.yaml' # include these action functions diff --git a/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Algorithm.cc b/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Algorithm.cc new file mode 100644 index 00000000..d01e2819 --- /dev/null +++ b/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Algorithm.cc @@ -0,0 +1,4 @@ +#include "Algorithm.h" +namespace iguana::example { + REGISTER_IGUANA_ALGORITHM(ExampleSubclassAlgorithm); +} diff --git a/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Algorithm.h b/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Algorithm.h new file mode 100644 index 00000000..4259372a --- /dev/null +++ b/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Algorithm.h @@ -0,0 +1,21 @@ +#pragma once + +#include "iguana/algorithms/clas12/rga/FiducialFilterPass1/Algorithm.h" + +namespace iguana::example { + + /// @algo_brief{example demonstrating inheritance from another algorithm} + /// @algo_type_filter + class ExampleSubclassAlgorithm : public clas12::rga::FiducialFilterPass1 + { + // use `DEFINE_IGUANA_SUBALGORITHM` rather than the usual `DEFINE_IGUANA_ALGORITHM`; + // include the base-class algorithm as an argument + DEFINE_IGUANA_SUBALGORITHM(ExampleSubclassAlgorithm, example::ExampleSubclassAlgorithm, clas12::rga::FiducialFilterPass1) + + public: + + // make sure base-class specialized `Run` functions (overloads) are not shadowed by any `Run` function overrides here + using clas12::rga::FiducialFilterPass1::Run; + }; + +} diff --git a/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Config.yaml b/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Config.yaml new file mode 100644 index 00000000..260dc4bf --- /dev/null +++ b/src/iguana/algorithms/example/ExampleSubclassAlgorithm/Config.yaml @@ -0,0 +1,13 @@ +example::ExampleSubclassAlgorithm: + + ################################################################################### + # NOTE: config is the same as `rga::FiducialFilterPass1`, but with value changes + ################################################################################### + + # cut levels for PCAL homogeneous cuts; one of 'loose', 'medium', or 'tight' + pcal_electron_cut_level: tight # for electrons and positrons + pcal_photon_cut_level: tight # for photons + + # enable/disable certain cuts for more fine-grained control + enable_pcal_cuts: 1 + enable_dc_cuts: 1 diff --git a/src/iguana/algorithms/meson.build b/src/iguana/algorithms/meson.build index 733b271d..60a53f0a 100644 --- a/src/iguana/algorithms/meson.build +++ b/src/iguana/algorithms/meson.build @@ -28,6 +28,14 @@ algo_dict = [ 'has_action_yaml': false, 'test_args': {'banks': [ 'REC::Particle' ]}, }, + { + 'name': 'example::ExampleSubclassAlgorithm', + 'has_validator': false, + 'test_args': { + 'banks': [ 'REC::Particle', 'RUN::config', 'REC::Traj', 'REC::Calorimeter' ], + 'prerequisites': [ 'clas12::CalorimeterLinker', 'clas12::TrajLinker' ], + }, + }, { 'name': 'clas12::EventBuilderFilter', 'has_validator': false, From 3535578dab1bd2e52be531f6dfb617bf1be7e670 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 20 Jan 2026 10:28:17 -0500 Subject: [PATCH 2/2] fix: update CODEOWNERS --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/CODEOWNERS b/CODEOWNERS index 3c788977..4d33c03a 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -21,6 +21,7 @@ src/iguana/algorithms/clas12/rga/FiducialFilterPass1/* @Gregtom3 src/iguana/algorithms/clas12/rga/FiducialFilterPass2/* @tbhayward src/iguana/algorithms/clas12/rga/MomentumCorrection/* @RichCap @c-dilks src/iguana/algorithms/example/ExampleAlgorithm/* @c-dilks +src/iguana/algorithms/example/ExampleSubclassAlgorithm/* @c-dilks src/iguana/algorithms/physics/Depolarization/* @c-dilks src/iguana/algorithms/physics/DihadronKinematics/* @c-dilks src/iguana/algorithms/physics/InclusiveKinematics/* @c-dilks