Skip to content

Commit 71bdf86

Browse files
authored
refactor: use hipo::getBanklistIndex to get bank indices (#300)
1 parent 39edef0 commit 71bdf86

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defaults:
3636

3737
env:
3838
hipo_fork: gavalian/hipo
39-
hipo_ref: 20094876df040ec234dd376fa527cf58442b775a
39+
hipo_ref: 4.2.0
4040
# test options
4141
num_events: 1000
4242
num_threads: 0 # use 0 for "all" available cores

src/iguana/algorithms/Algorithm.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,17 @@ namespace iguana {
145145
{
146146
if(m_rows_only)
147147
return 0;
148-
auto it = std::find_if(
149-
banks.begin(),
150-
banks.end(),
151-
[&bank_name](auto& bank)
152-
{ return bank.getSchema().getName() == bank_name; });
153-
if(it == banks.end()) {
148+
try {
149+
auto idx = hipo::getBanklistIndex(banks, bank_name);
150+
m_log->Debug("cached index of bank '{}' is {}", bank_name, idx);
151+
return idx;
152+
} catch(std::runtime_error const& ex) {
154153
m_log->Error("required input bank '{}' not found; cannot `Start` algorithm '{}'", bank_name, m_class_name);
155154
auto creators = AlgorithmFactory::QueryNewBank(bank_name);
156155
if(creators)
157156
m_log->Error(" -> this bank is created by algorithm(s) [{}]; please `Start` ONE of them BEFORE this algorithm", fmt::join(creators.value(), ", "));
158157
throw std::runtime_error("cannot cache bank index");
159158
}
160-
auto idx = std::distance(banks.begin(), it);
161-
m_log->Debug("cached index of bank '{}' is {}", bank_name, idx);
162-
return idx;
163159
}
164160

165161
///////////////////////////////////////////////////////////////////////////////

src/iguana/algorithms/Algorithm.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ namespace iguana {
135135
/// @param name the directory name
136136
void SetConfigDirectory(std::string const& name);
137137

138-
/// Get the index of a bank in a `hipo::banklist`; throws an exception if the bank is not found
139-
/// @param banks the list of banks this algorithm will use
140-
/// @param bank_name the name of the bank
141-
/// returns the `hipo::banklist` index of the bank
142-
hipo::banklist::size_type GetBankIndex(hipo::banklist& banks, std::string const& bank_name) const noexcept(false);
143-
144138
protected: // methods
145139

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

150+
/// Get the index of a bank in a `hipo::banklist`; throws an exception if the bank is not found
151+
/// @param banks the list of banks this algorithm will use
152+
/// @param bank_name the name of the bank
153+
/// returns the `hipo::banklist` index of the bank
154+
hipo::banklist::size_type GetBankIndex(hipo::banklist& banks, std::string const& bank_name) const noexcept(false);
155+
156156
/// Create a new bank and push it to the bank list
157157
/// @param [out] banks the `hipo::banklist` onto which the new bank will be pushed
158158
/// @param [out] bank_idx will be set to the `hipo::banklist` index of the new bank

0 commit comments

Comments
 (0)