Skip to content

Commit

Permalink
fix: centralize creator banks and set unique IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Oct 29, 2024
1 parent e31a651 commit f7af0ed
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
17 changes: 17 additions & 0 deletions src/iguana/algorithms/Algorithm.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Algorithm.h"
#include "BankDefs.h"

#include <numeric>

Expand Down Expand Up @@ -252,6 +253,22 @@ namespace iguana {
return bank_schema;
}

hipo::schema Algorithm::CreateBankNew(
hipo::banklist& banks,
hipo::banklist::size_type& idx,
std::string const& bank_name) const noexcept(false)
{
for(auto const& bank_def : bank_defs) {
if(bank_def.name == bank_name) {
std::vector<std::string> bank_cols;
for(auto const& entry : bank_def.entries)
bank_cols.push_back(entry.name + "/" + entry.type);
return CreateBank(banks, idx, bank_name, bank_cols, bank_def.group, bank_def.item);
}
}
throw std::runtime_error(fmt::format("bank {:?} not found in 'BankDefs.h'", bank_name));
}

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

void Algorithm::ShowBanks(hipo::banklist& banks, std::string_view message, Logger::Level const level) const
Expand Down
10 changes: 10 additions & 0 deletions src/iguana/algorithms/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ namespace iguana {
int group_id, // FIXME: generalize group_id and item_id setting
int item_id) const noexcept(false);

/// Create a new bank and push it to the bank list. The bank must be defined in `BankDefs.h`.
/// @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
/// @returns the bank's schema
hipo::schema CreateBankNew(
hipo::banklist& banks,
hipo::banklist::size_type& idx,
std::string const& bank_name) const noexcept(false);

/// Dump all banks in a `hipo::banklist`
/// @param banks the banks to show
/// @param message if specified, print a header message
Expand Down
49 changes: 49 additions & 0 deletions src/iguana/algorithms/BankDefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <vector>
#include <string>


// FIXME
// This really ought to be a YAML file, however:
// - could be handled by `ConfigFileReader`, but need to prevent users from accidentally overriding this
// file with `IGUANA_CONFIG_PATH`
// - we could generate this header file, given a YAML file, with Python (not Ruby, since Meson already needs Python, but Ruby
// is only needed for Chameleon)

namespace iguana {

struct BankColDef {
std::string name;
std::string type;
};

struct BankDef {
std::string name;
int group;
int item;
std::vector<BankColDef> entries;
};

std::vector<BankDef> const bank_defs{
{
.name = "physics::InclusiveKinematics",
.group = 30000,
.item = 1,
.entries = {
{ .name = "pindex", .type = "S" },
{ .name = "Q2", .type = "D"},
{ .name = "x", .type = "D"},
{ .name = "y", .type = "D"},
{ .name = "W", .type = "D"},
{ .name = "nu", .type = "D"},
{ .name = "qx", .type = "D"},
{ .name = "qy", .type = "D"},
{ .name = "qz", .type = "D"},
{ .name = "qE", .type = "D"},
{ .name = "beamPz", .type = "D"},
{ .name = "targetM", .type = "D"}
}
}
};

}

1 change: 1 addition & 0 deletions src/iguana/algorithms/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ algo_headers = [
'Algorithm.h',
'AlgorithmBoilerplate.h',
'TypeDefs.h',
'BankDefs.h',
'AlgorithmSequence.h',
]
if ROOT_dep.found()
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 = CreateBankNew(banks, b_result, GetClassName());
i_pindex = result_schema.getEntryOrder("pindex");
i_Q2 = result_schema.getEntryOrder("Q2");
i_x = result_schema.getEntryOrder("x");
Expand Down

0 comments on commit f7af0ed

Please sign in to comment.