Skip to content

Commit

Permalink
refactor: use hipo::getBanklistIndex to get bank indices (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Nov 19, 2024
1 parent 39edef0 commit 71bdf86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defaults:

env:
hipo_fork: gavalian/hipo
hipo_ref: 20094876df040ec234dd376fa527cf58442b775a
hipo_ref: 4.2.0
# test options
num_events: 1000
num_threads: 0 # use 0 for "all" available cores
Expand Down
14 changes: 5 additions & 9 deletions src/iguana/algorithms/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,17 @@ namespace iguana {
{
if(m_rows_only)
return 0;
auto it = std::find_if(
banks.begin(),
banks.end(),
[&bank_name](auto& bank)
{ return bank.getSchema().getName() == bank_name; });
if(it == banks.end()) {
try {
auto idx = hipo::getBanklistIndex(banks, bank_name);
m_log->Debug("cached index of bank '{}' is {}", bank_name, idx);
return idx;
} catch(std::runtime_error const& ex) {
m_log->Error("required input bank '{}' not found; cannot `Start` algorithm '{}'", bank_name, m_class_name);
auto creators = AlgorithmFactory::QueryNewBank(bank_name);
if(creators)
m_log->Error(" -> this bank is created by algorithm(s) [{}]; please `Start` ONE of them BEFORE this algorithm", fmt::join(creators.value(), ", "));
throw std::runtime_error("cannot cache bank index");
}
auto idx = std::distance(banks.begin(), it);
m_log->Debug("cached index of bank '{}' is {}", bank_name, idx);
return idx;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions src/iguana/algorithms/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ namespace iguana {
/// @param name the directory name
void SetConfigDirectory(std::string const& name);

/// Get the index of a bank in a `hipo::banklist`; throws an exception if the bank is not found
/// @param banks the list of banks this algorithm will use
/// @param bank_name the name of the bank
/// returns the `hipo::banklist` index of the bank
hipo::banklist::size_type GetBankIndex(hipo::banklist& banks, std::string const& bank_name) const noexcept(false);

protected: // methods

/// Parse YAML configuration files. Sets `m_yaml_config`.
Expand All @@ -153,6 +147,12 @@ namespace iguana {
/// @return a reference to the bank
hipo::bank& GetBank(hipo::banklist& banks, hipo::banklist::size_type const idx, std::string const& expected_bank_name = "") const noexcept(false);

/// Get the index of a bank in a `hipo::banklist`; throws an exception if the bank is not found
/// @param banks the list of banks this algorithm will use
/// @param bank_name the name of the bank
/// 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
/// @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
Expand Down

0 comments on commit 71bdf86

Please sign in to comment.