Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use vector of banks for algorithm I/O #18

Merged
merged 7 commits into from
Nov 22, 2023
Merged

refactor: use vector of banks for algorithm I/O #18

merged 7 commits into from
Nov 22, 2023

Conversation

c-dilks
Copy link
Member

@c-dilks c-dilks commented Nov 22, 2023

  • Algorithm Run method now operates on a BankVec, a std::vector of bank pointers
    • Run now returns void; instead it is allowed to mutate the input BankVec; this saves some time by avoiding copying banks
    • Start will set the index of the BankVec for each required bank, so Run avoids hashing (cf. previous design's BankMap, an unordered map of bank names to bank pointers, which requires extensive hashing)
    • Creator algorithms will need a pointer to the "new" bank in the input BankVec
  • Algorithms may be initialized one of two ways:
    • call Start(): a default (algorithm-dependent) ordering of banks will be assumed by Run
    • call Start(std::unordered_map<std::string, int> m), where m provides the index of the BankVec for each bank

This design provides compatibility with @gavalian's idea of a BankStore:

struct BankStore {
  std::vector<hipo::bank> banks;                 // the vector of banks
  std::unordered_map<std::string, int> bankMap;  // bank name -> index in `banks` for that bank
}

If a user wants to use a BankStore, they would write the following (pseudocode):

Algorithm algo;
BankStore b = reader.getBanks(bank1, bank2);
algo.Start(b.bankMap);
while(event)
  algo.run(b.banks);

Alternatively, if a user wants to work with the banks and avoid the bank store, they need to know the order of the banks that the algorithm Run call expects (or change it using Start(map)):

Algorithm algo;
hipo::bank bank1, bank2;
algo.Start();
while(event) {
  bank1 = event.get("bank1");
  bank2 = event.get("bank2");
  algo.run({bank1, bank2});

This alternative, while slower, may be preferred in the case where refactoring one's analysis code to use BankStore is difficult.

@c-dilks c-dilks marked this pull request as ready for review November 22, 2023 21:53
src/tests/main.cc Outdated Show resolved Hide resolved
@c-dilks c-dilks enabled auto-merge (squash) November 22, 2023 22:03
@c-dilks c-dilks merged commit be81b00 into main Nov 22, 2023
4 checks passed
@c-dilks c-dilks deleted the bank-store branch November 22, 2023 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant