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

fix: centralize creator banks and set unique IDs #306

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion doc/gen/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,12 @@ WARN_LOGFILE =

INPUT = @top_srcdir@/src/ \
@top_builddir@/src/iguana/algorithms \
@top_builddir@/src/iguana/bankdefs \
@top_srcdir@/bind/ \
@top_srcdir@/doc/gen/ \
@top_srcdir@/doc/gen/mainpage.md \
@top_srcdir@/examples/
@top_srcdir@/examples/ \
@top_srcdir@/src/iguana/bankdefs/iguana.json

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
3 changes: 3 additions & 0 deletions doc/gen/mainpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ The algorithm types are defined based on what they do to HIPO bank data:
<tr><td> **Creator** </td><td> Create a new bank </td></tr>
</table>

The definitions of the new banks that are created by **Creator** algorithms are found in:
- \link src/iguana/bankdefs/iguana.json **Iguana Bank Definitions:** `iguana.json` \endlink

Most algorithms are configurable:
- [**Algorithm Configuration Guide**](https://github.com/JeffersonLab/iguana/blob/main/doc/configuration.md)

Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ endif

# build and install shared libraries
subdir('src/iguana/services')
subdir('src/iguana/bankdefs')
subdir('src/iguana/algorithms')
subdir('src/iguana/tests')

Expand Down
46 changes: 23 additions & 23 deletions src/iguana/algorithms/Algorithm.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "Algorithm.h"

#include <numeric>

namespace iguana {

void Algorithm::Start()
Expand Down Expand Up @@ -223,29 +221,31 @@ namespace iguana {
hipo::schema Algorithm::CreateBank(
hipo::banklist& banks,
hipo::banklist::size_type& bank_idx,
std::string const& bank_name,
std::vector<std::string> schema_def,
int group_id,
int item_id) const
std::string const& bank_name) const noexcept(false)
{
if(!AlgorithmFactory::QueryNewBank(bank_name)) {
m_log->Error("{:?} creates bank {:?}, which is not registered; new banks must be included in `REGISTER_IGUANA_ALGORITHM` arguments", m_class_name, bank_name);
throw std::runtime_error("CreateBank failed");
}
if(schema_def.empty()) {
m_log->Error("empty schema_def in CreateBank");
throw std::runtime_error("CreateBank failed");
// loop over bank definitions
for(auto const& bank_def : BANK_DEFS) {
if(bank_def.name == bank_name) {
// make sure the new bank is in REGISTER_IGUANA_ALGORITHM
if(!AlgorithmFactory::QueryNewBank(bank_name)) {
m_log->Error("{:?} creates bank {:?}, which is not registered; new banks must be included in `REGISTER_IGUANA_ALGORITHM` arguments", m_class_name, bank_name);
throw std::runtime_error("CreateBank failed");
}
// create the schema format string
std::vector<std::string> schema_def;
for(auto const& entry : bank_def.entries)
schema_def.push_back(entry.name + "/" + entry.type);
auto format_string = fmt::format("{}", fmt::join(schema_def, ","));
// create the new bank schema
hipo::schema bank_schema(bank_name.c_str(), bank_def.group, bank_def.item);
bank_schema.parse(format_string);
// create the new bank
banks.push_back({bank_schema});
bank_idx = GetBankIndex(banks, bank_name);
return bank_schema;
}
}
hipo::schema bank_schema(bank_name.c_str(), group_id, item_id);
bank_schema.parse(std::accumulate(
std::next(schema_def.begin()),
schema_def.end(),
schema_def[0],
[](std::string a, std::string b)
{ return a + "," + b; }));
banks.push_back({bank_schema});
bank_idx = GetBankIndex(banks, bank_name);
return bank_schema;
throw std::runtime_error(fmt::format("bank {:?} not found in 'BankDefs.h'", bank_name));
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 4 additions & 10 deletions src/iguana/algorithms/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include <hipo4/bank.h>


#include "iguana/algorithms/AlgorithmBoilerplate.h"
#include "AlgorithmBoilerplate.h"
#include "iguana/bankdefs/BankDefs.h"
#include "iguana/services/YAMLReader.h"
#include <iguana/services/GlobalParam.h>

Expand Down Expand Up @@ -153,21 +153,15 @@ namespace iguana {
/// returns the `hipo::banklist` index of the bank
hipo::banklist::size_type GetBankIndex(hipo::banklist& banks, std::string const& bank_name) const noexcept(false);

/// Create a new bank and push it to the bank list
/// Create a new bank and push it to the bank list. The bank must be defined in `BANK_DEFS`, which is generated at build time from `src/iguana/bankdefs/iguana.json`
/// @param [out] banks the `hipo::banklist` onto which the new bank will be pushed
/// @param [out] bank_idx will be set to the `hipo::banklist` index of the new bank
/// @param [in] bank_name the new bank name
/// @param [in] schema_def a list of variables for the schema
/// @param [in] group_id the group ID for the schema
/// @param [in] item_id the item ID for the schema
/// @returns the bank's schema
hipo::schema CreateBank(
hipo::banklist& banks,
hipo::banklist::size_type& bank_idx,
std::string const& bank_name,
std::vector<std::string> schema_def,
int group_id, // FIXME: generalize group_id and item_id setting
int item_id) const noexcept(false);
std::string const& bank_name) const noexcept(false);

/// Dump all banks in a `hipo::banklist`
/// @param banks the banks to show
Expand Down
3 changes: 1 addition & 2 deletions src/iguana/algorithms/clas12/SectorFinder/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ namespace iguana::clas12 {
}

// create the output bank
// FIXME: generalize the groupid and itemid
auto result_schema = CreateBank(banks, b_result, "REC::Particle::Sector", {"sector/I","pindex/S"}, 0xF000, 4);
auto result_schema = CreateBank(banks, b_result, "REC::Particle::Sector");
i_sector = result_schema.getEntryOrder("sector");
i_pindex = result_schema.getEntryOrder("pindex");
}
Expand Down
1 change: 1 addition & 0 deletions src/iguana/algorithms/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ algo_sources = [
'Algorithm.cc',
'AlgorithmFactory.cc',
'AlgorithmSequence.cc',
bankdef_tgt[1], # BankDefs.cc
]
algo_headers = [
'Algorithm.h',
Expand Down
22 changes: 1 addition & 21 deletions src/iguana/algorithms/physics/DihadronKinematics/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,7 @@ namespace iguana::physics {
b_inc_kin = GetBankIndex(banks, "physics::InclusiveKinematics");

// create the output bank
// FIXME: generalize the groupid and itemid
auto result_schema = CreateBank(
banks,
b_result,
GetClassName(),
{
"pindex_a/S",
"pindex_b/S",
"pdg_a/I",
"pdg_b/I",
"Mh/D",
"z/D",
"PhPerp/D",
"MX/D",
"xF/D",
"phiH/D",
"phiR/D",
"theta/D"
},
0xF000,
5);
auto result_schema = CreateBank(banks, b_result, GetClassName());
i_pindex_a = result_schema.getEntryOrder("pindex_a");
i_pindex_b = result_schema.getEntryOrder("pindex_b");
i_pdg_a = result_schema.getEntryOrder("pdg_a");
Expand Down
31 changes: 0 additions & 31 deletions src/iguana/algorithms/physics/DihadronKinematics/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,6 @@

namespace iguana::physics {

/// Set of dihadron kinematics variables
struct DihadronKinematicsVars {
/// @brief `REC::Particle` row (`pindex`) of hadron A
int pindex_a;
/// @brief `REC::Particle` row (`pindex`) of hadron B
int pindex_b;
/// @brief PDG code of hadron A
int pdg_a;
/// @brief PDG code of hadron B
int pdg_b;
/// @brief @latex{M_h}: Invariant mass of the dihadron
double Mh;
/// @brief @latex{z}: Momentum fraction of the fragmenting parton carried by the dihadron
double z;
/// @brief @latex{P_h^\perp}: transverse momentum of the dihadron in the @latex{\perp}-frame (transverse to @latex{\vec{q}})
double PhPerp;
/// @brief @latex{M_X(ehhX)}: Missing mass of the dihadron
double MX;
/// @brief @latex{x_F}: Feynman-x of the dihadron
double xF;
/// @brief @latex{\phi_h}: @latex{q}-azimuthal angle between the lepton-scattering plane and the @latex{\vec{q}\times\vec{P}_h} plane;
/// if the value is `tools::UNDEF`, the calculation failed
double phiH;
/// @brief @latex{\phi_R}: @latex{q}-azimuthal angle between the lepton-scattering plane and dihadron plane;
/// if the value is `tools::UNDEF`, the calculation failed
double phiR;
/// @brief @latex{\theta}: The "decay" angle of hadron A in the dihadron rest frame, with respect;
/// to the dihadron momentum direction
double theta;
};

/// @brief_algo Calculate semi-inclusive dihadron kinematic quantities defined in `iguana::physics::DihadronKinematicsVars`
///
/// @begin_doc_algo{physics::DihadronKinematics | Creator}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ namespace iguana::physics {
b_config = GetBankIndex(banks, "RUN::config");

// create the output bank
// FIXME: generalize the groupid and itemid
auto result_schema = CreateBank(
banks,
b_result,
GetClassName(),
{"pindex/S", "Q2/D", "x/D", "y/D", "W/D", "nu/D", "qx/D", "qy/D", "qz/D", "qE/D", "beamPz/D", "targetM/D"},
0xF000,
1);
auto result_schema = CreateBank(banks, b_result, GetClassName());
i_pindex = result_schema.getEntryOrder("pindex");
i_Q2 = result_schema.getEntryOrder("Q2");
i_x = result_schema.getEntryOrder("x");
Expand Down
28 changes: 0 additions & 28 deletions src/iguana/algorithms/physics/InclusiveKinematics/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,6 @@

namespace iguana::physics {

/// Set of inclusive kinematics variables
struct InclusiveKinematicsVars {
/// @brief `REC::Particle` row (`pindex`) of the scattered electron
int pindex;
/// @brief @latex{x}-component of virtual photon momentum @latex{q}
vector_element_t qx;
/// @brief @latex{y}-component of virtual photon momentum @latex{q}
vector_element_t qy;
/// @brief @latex{z}-component of virtual photon momentum @latex{q}
vector_element_t qz;
/// @brief @latex{E}-component of virtual photon momentum @latex{q}
vector_element_t qE;
/// @brief @latex{Q^2} (GeV@latex{^2})
double Q2;
/// @brief @latex{x_B}
double x;
/// @brief @latex{y}
double y;
/// @brief @latex{W} (GeV)
double W;
/// @brief @latex{\nu}
double nu;
/// @brief beam momentum @latex{z}-component (GeV)
double beamPz;
/// @brief target mass (GeV)
double targetM;
};

/// @brief_algo Calculate inclusive kinematics quantities defined in `iguana::physics::InclusiveKinematicsVars`
///
/// @begin_doc_algo{physics::InclusiveKinematics | Creator}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,7 @@ namespace iguana::physics {
b_inc_kin = GetBankIndex(banks, "physics::InclusiveKinematics");

// create the output bank
// FIXME: generalize the groupid and itemid
auto result_schema = CreateBank(
banks,
b_result,
GetClassName(),
{
"pindex/S",
"pdg/I",
"z/D",
"PhPerp/D",
"MX/D",
"xF/D",
"phiH/D",
"xi/D"
},
0xF000,
7);
auto result_schema = CreateBank(banks, b_result, GetClassName());
i_pindex = result_schema.getEntryOrder("pindex");
i_pdg = result_schema.getEntryOrder("pdg");
i_z = result_schema.getEntryOrder("z");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@

namespace iguana::physics {

/// Set of hadron kinematics variables
struct SingleHadronKinematicsVars {
/// @brief `REC::Particle` row (`pindex`) of the hadron
int pindex;
/// @brief PDG code of the hadron
int pdg;
/// @brief @latex{z}: Momentum fraction of the fragmenting parton carried by the hadron
double z;
/// @brief @latex{P_h^\perp}: transverse momentum of the hadron in the @latex{\perp}-frame (transverse to @latex{\vec{q}})
double PhPerp;
/// @brief @latex{M_X(ehX)}: Missing mass of the hadron
double MX;
/// @brief @latex{x_F}: Feynman-x of the hadron
double xF;
/// @brief @latex{\phi_h}: @latex{q}-azimuthal angle between the lepton-scattering plane and the @latex{\vec{q}\times\vec{P}_h} plane;
/// if the value is `tools::UNDEF`, the calculation failed
double phiH;
/// @brief @latex{\xi_h}: Longitudinal momentum fraction of the nucleon carried by the hadron
double xi;
};

/// @brief_algo Calculate semi-inclusive hadron kinematic quantities defined in `iguana::physics::SingleHadronKinematicsVars`
///
/// @begin_doc_algo{physics::SingleHadronKinematics | Creator}
Expand Down
5 changes: 5 additions & 0 deletions src/iguana/bankdefs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Iguana Bank Definitions

Creator algorithms create new banks; the files in this directory describe the new banks, in particular, [`iguana.json`](iguana.json).

This `json` file follows the same format as the `coatjava` bank definitions and may be used as a reference; this `json` file is also installed in `etc/iguana/bankdefs/`.
Loading
Loading