Skip to content

Commit

Permalink
fix: pass banks by reference (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Nov 21, 2023
1 parent 4b06b01 commit 7555dea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/algorithms/clas12/event_builder_filter/EventBuilderFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ namespace iguana::clas12 {

// define the output schemata and banks
BankMap outBanks = {
{ "particles", hipo::bank(inBanks.at("particles").getSchema()) }
{ "particles", std::make_shared<hipo::bank>(inBanks.at("particles")->getSchema()) }
};

// filter the input bank for requested PDG code(s)
std::set<int> acceptedRows;
for(int row = 0; row < inBanks.at("particles").getRows(); row++) {
auto pid = inBanks.at("particles").get("pid", row);
for(int row = 0; row < inBanks.at("particles")->getRows(); row++) {
auto pid = inBanks.at("particles")->get("pid", row);
auto accept = m_opt.pids.find(pid) != m_opt.pids.end();
if(accept) acceptedRows.insert(row);
m_log->Debug("input PID {} -- accept = {}", pid, accept);
Expand All @@ -38,8 +38,8 @@ namespace iguana::clas12 {

case EventBuilderFilterOptions::Modes::blank:
{
outBanks.at("particles").setRows(inBanks.at("particles").getRows());
for(int row = 0; row < inBanks.at("particles").getRows(); row++) {
outBanks.at("particles")->setRows(inBanks.at("particles")->getRows());
for(int row = 0; row < inBanks.at("particles")->getRows(); row++) {
if(acceptedRows.find(row) != acceptedRows.end())
CopyBankRow(inBanks.at("particles"), row, outBanks.at("particles"), row);
else
Expand All @@ -50,7 +50,7 @@ namespace iguana::clas12 {

case EventBuilderFilterOptions::Modes::compact:
{
outBanks.at("particles").setRows(acceptedRows.size());
outBanks.at("particles")->setRows(acceptedRows.size());
int row = 0;
for(auto acceptedRow : acceptedRows)
CopyBankRow(inBanks.at("particles"), acceptedRow, outBanks.at("particles"), row++);
Expand Down
1 change: 0 additions & 1 deletion src/iguana/Iguana.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "services/Algorithm.h"
#include <unordered_map>
#include <memory>

// TODO: avoid listing the algos
#include "algorithms/clas12/event_builder_filter/EventBuilderFilter.h"
Expand Down
18 changes: 9 additions & 9 deletions src/services/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ namespace iguana {
return false;
}

void Algorithm::CopyBankRow(hipo::bank srcBank, int srcRow, hipo::bank destBank, int destRow) {
// TODO: check srcBank.getSchema() == destBank.getSchema()
for(int item = 0; item < srcBank.getSchema().getEntries(); item++) {
auto val = srcBank.get(item, srcRow);
destBank.put(item, destRow, val);
void Algorithm::CopyBankRow(std::shared_ptr<hipo::bank> srcBank, int srcRow, std::shared_ptr<hipo::bank> destBank, int destRow) {
// TODO: check srcBank->getSchema() == destBank.getSchema()
for(int item = 0; item < srcBank->getSchema().getEntries(); item++) {
auto val = srcBank->get(item, srcRow);
destBank->put(item, destRow, val);
}
}

void Algorithm::BlankRow(hipo::bank bank, int row) {
for(int item = 0; item < bank.getSchema().getEntries(); item++) {
bank.put(item, row, 0);
void Algorithm::BlankRow(std::shared_ptr<hipo::bank> bank, int row) {
for(int item = 0; item < bank->getSchema().getEntries(); item++) {
bank->put(item, row, 0);
}
}

Expand All @@ -38,7 +38,7 @@ namespace iguana {
m_log->Print(level, message);
for(auto [key,bank] : banks) {
m_log->Print(level, "BANK: '{}'", key);
bank.show();
bank->show();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace iguana {

public:

using BankMap = std::unordered_map<std::string, hipo::bank>;
using BankMap = std::unordered_map<std::string, std::shared_ptr<hipo::bank>>;

/// Algorithm base class constructor
/// @param name the unique name for a derived class instance
Expand Down Expand Up @@ -43,12 +43,12 @@ namespace iguana {
/// @param srcRow the row in `srcBank` to copy from
/// @param destBank the destination bank
/// @param destRow the row in `destBank` to copy to
void CopyBankRow(hipo::bank srcBank, int srcRow, hipo::bank destBank, int destRow);
void CopyBankRow(std::shared_ptr<hipo::bank> srcBank, int srcRow, std::shared_ptr<hipo::bank> destBank, int destRow);

/// Blank a row, setting all items to zero
/// @param bank the bank to modify
/// @param row the row to blank
void BlankRow(hipo::bank bank, int row);
void BlankRow(std::shared_ptr<hipo::bank> bank, int row);

/// Dump all banks in a BankMap
/// @param banks the banks to show
Expand Down
4 changes: 2 additions & 2 deletions src/tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ int main(int argc, char **argv) {
*/
hipo::dictionary factory;
reader.readDictionary(factory);
hipo::bank particleBank(factory.getSchema("REC::Particle"));
auto particleBank = std::make_shared<hipo::bank>(factory.getSchema("REC::Particle"));

// event loop
hipo::event event;
int iEvent = 0;
while(reader.next(event) && (iEvent++ < numEvents || numEvents == 0)) {
event.getStructure(particleBank);
event.getStructure(*particleBank);
auto resultBank = algo->Run({{"particles", particleBank}});
}

Expand Down

0 comments on commit 7555dea

Please sign in to comment.