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

refactor: use hipo::getBanklistIndex to get bank indices #300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading