diff --git a/hipo4/bank.cpp b/hipo4/bank.cpp index abb4bd2..9d54a92 100644 --- a/hipo4/bank.cpp +++ b/hipo4/bank.cpp @@ -362,13 +362,13 @@ void bank::rowlist::setList(list_t list) { m_init = true; } -void bank::rowlist::reduce(std::function func) { +void bank::rowlist::reduce(std::function func) { if(ownerBankIsUnknown("reduce")) return; auto indx = m_list; m_list.clear(); for(auto const& r : indx) - if(func(*m_owner_bank, r) > 0.5) + if(func(*m_owner_bank, r) == true) m_list.push_back(r); } @@ -376,9 +376,9 @@ void bank::rowlist::reduce(const char *expression) { if(ownerBankIsUnknown("reduce")) return; Parser p(expression); - int nitems = m_owner_bank->getSchema().getEntries(); + int nitems = m_owner_bank->getSchema().getEntries(); schema &schema = m_owner_bank->getSchema(); - auto indx = m_list; + auto indx = m_list; m_list.clear(); for(auto const& r : indx){ for(int i = 0; i < nitems; i++) @@ -388,16 +388,11 @@ void bank::rowlist::reduce(const char *expression) { } } -bank::rowlist::list_t bank::rowlist::s_number_list_init(list_t::size_type num) { - list_t result; - for(list_t::size_type i = 0; i < num; i++) - result.push_back(i); - return result; -} - -bank::rowlist::list_t bank::rowlist::getFullList(list_t::size_type num) { - if(num < 0) +bank::rowlist::list_t bank::rowlist::getFullList(int num) { + if(num < 0) { + std::cerr << "ERROR: attempted to call rowlist::getFullRowList with a negative size" << std::endl; return {}; + } if(num <= s_number_list.size()) return list_t(s_number_list.begin(), s_number_list.begin() + num); else { @@ -408,8 +403,6 @@ bank::rowlist::list_t bank::rowlist::getFullList(list_t::size_type num) { } } -bank::rowlist::list_t bank::rowlist::s_number_list = bank::rowlist::s_number_list_init(); - bool bank::rowlist::ownerBankIsUnknown(std::string_view caller) { if(m_owner_bank == nullptr) { std::cerr << @@ -422,6 +415,15 @@ bool bank::rowlist::ownerBankIsUnknown(std::string_view caller) { return false; } +bank::rowlist::list_t bank::rowlist::s_number_list_init(list_t::size_type num) { + list_t result; + for(list_t::size_type i = 0; i < num; i++) + result.push_back(i); + return result; +} + +bank::rowlist::list_t bank::rowlist::s_number_list = bank::rowlist::s_number_list_init(); + ////////////////////////////////////////////////////////////////////////////////// // hipo::bank diff --git a/hipo4/bank.h b/hipo4/bank.h index c887255..a8caf15 100644 --- a/hipo4/bank.h +++ b/hipo4/bank.h @@ -230,15 +230,15 @@ namespace hipo { /// filter the list according to a function /// @param func a function which takes a `hipo::bank` reference and an `int` row number and returns a `double`; - /// if the returned `double` is larger than 0.5, the row is accepted - void reduce(std::function func); + /// if the returned `bool` is `true`, the row is accepted + void reduce(std::function func); /// filter the list according to an expression /// @param expression the filter expression void reduce(char const* expression); /// @returns a list of numbers from 0 to `num` /// @param num the size of the list - static list_t getFullList(list_t::size_type num); + static list_t getFullList(int num); /// @param ownerBank set the owner bank void setOwnerBank(bank* const ownerBank) { m_owner_bank = ownerBank; }