From b942bc11739b81d45b351214bb7fae4af96eb150 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 25 Oct 2024 15:28:01 -0400 Subject: [PATCH] refactor: use `hipo::getBanklistIndex` to get bank indices - finding a bank is upstreamed: https://github.com/gavalian/hipo/pull/65 - reverts https://github.com/JeffersonLab/iguana/pull/299 --- src/iguana/algorithms/Algorithm.cc | 14 +++++--------- src/iguana/algorithms/Algorithm.h | 12 ++++++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/iguana/algorithms/Algorithm.cc b/src/iguana/algorithms/Algorithm.cc index 343a40c9..b6f37a27 100644 --- a/src/iguana/algorithms/Algorithm.cc +++ b/src/iguana/algorithms/Algorithm.cc @@ -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; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/iguana/algorithms/Algorithm.h b/src/iguana/algorithms/Algorithm.h index fdc21866..1700ca5c 100644 --- a/src/iguana/algorithms/Algorithm.h +++ b/src/iguana/algorithms/Algorithm.h @@ -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`. @@ -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