Skip to content

Commit

Permalink
feat: copy a bank row
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Nov 15, 2023
1 parent e0a5546 commit ac55033
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/algorithms/clas12/event_builder_filter/EventBuilderFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ namespace iguana::clas12 {

// filter the input bank for requested PDG code(s)
int outRow = -1;
for(int inRow=0; inRow<inBanks.at("particles").getRows(); inRow++) {
for(int inRow = 0; inRow < inBanks.at("particles").getRows(); inRow++) {
auto inPid = inBanks.at("particles").get("pid",inRow);

if(m_opt.pids.contains(inPid)) {
m_log->Debug("input PID {} -- accept", inPid);
if(m_opt.mode == EventBuilderFilterOptions::Modes::blank)
outRow = inRow;
else
outRow++;
outBanks.at("particles").put("pid", outRow, inPid);
CopyBankRow(
inBanks.at("particles"),
outBanks.at("particles"),
m_opt.mode == EventBuilderFilterOptions::Modes::blank ? inRow : outRow++
);
}

else {
m_log->Debug("input PID {} -- reject", inPid);
if(m_opt.mode == EventBuilderFilterOptions::blank)
outBanks.at("particles").put("pid", inRow, 0);
BlankRow(outBanks.at("particles"), inRow);
}

}
Expand Down
14 changes: 14 additions & 0 deletions src/services/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ namespace iguana {
return false;
}

void Algorithm::CopyBankRow(hipo::bank srcBank, hipo::bank destBank, int row) {
// TODO: check srcBank.getSchema() == destBank.getSchema()
for(int item = 0; item < srcBank.getSchema().getEntries(); item++) {
auto val = srcBank.get(item, row);
destBank.put(item, row, 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::ThrowRun() {
throw std::runtime_error(fmt::format("Algorithm '{}' cannot `Run`", m_name));
}
Expand Down
11 changes: 11 additions & 0 deletions src/services/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ namespace iguana {
/// @return true if `banks` is missing any keys in `keys`
bool MissingInputBanks(BankMap banks, std::set<std::string> keys);

/// Copy a row from one bank to another, assuming their schemata are equivalent
/// @param srcBank the source bank
/// @param destBank the destination bank
/// @param row the row to copy from `srcBank` to `destBank`
void CopyBankRow(hipo::bank srcBank, hipo::bank destBank, int row);

/// 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);

/// Throw a runtime exception when calling `Run`
void ThrowRun();

Expand Down

0 comments on commit ac55033

Please sign in to comment.