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

feat: Allow multiple aliases for one whiteboard entry in Examples #4035

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Sequencer {
std::vector<SequenceElementWithFpeResult> m_sequenceElements;
std::unique_ptr<const Acts::Logger> m_logger;

std::unordered_map<std::string, std::string> m_whiteboardObjectAliases;
std::unordered_multimap<std::string, std::string> m_whiteboardObjectAliases;

std::unordered_map<std::string, const DataHandleBase *> m_whiteBoardState;

Expand Down
11 changes: 6 additions & 5 deletions Examples/Framework/include/ActsExamples/Framework/WhiteBoard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ namespace ActsExamples {
/// Its lifetime is bound to the lifetime of the white board.
class WhiteBoard {
public:
WhiteBoard(std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("WhiteBoard", Acts::Logging::INFO),
std::unordered_map<std::string, std::string> objectAliases = {});
WhiteBoard(
std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("WhiteBoard", Acts::Logging::INFO),
std::unordered_multimap<std::string, std::string> objectAliases = {});

WhiteBoard(const WhiteBoard& other) = delete;
WhiteBoard& operator=(const WhiteBoard&) = delete;
Expand Down Expand Up @@ -97,7 +98,7 @@ class WhiteBoard {

std::unique_ptr<const Acts::Logger> m_logger;
std::unordered_map<std::string, std::shared_ptr<IHolder>> m_store;
std::unordered_map<std::string, std::string> m_objectAliases;
std::unordered_multimap<std::string, std::string> m_objectAliases;

const Acts::Logger& logger() const { return *m_logger; }

Expand All @@ -115,7 +116,7 @@ class WhiteBoard {

inline ActsExamples::WhiteBoard::WhiteBoard(
std::unique_ptr<const Acts::Logger> logger,
std::unordered_map<std::string, std::string> objectAliases)
std::unordered_multimap<std::string, std::string> objectAliases)
: m_logger(std::move(logger)), m_objectAliases(std::move(objectAliases)) {}

template <typename T>
Expand Down
29 changes: 16 additions & 13 deletions Examples/Framework/src/Framework/Sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "ActsExamples/Framework/Sequencer.hpp"

#include "Acts/Plugins/FpeMonitoring/FpeMonitor.hpp"
#include "Acts/Utilities/Helpers.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
Expand All @@ -26,9 +25,7 @@
#include <atomic>
#include <cctype>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <fstream>
#include <functional>
#include <iterator>
Expand Down Expand Up @@ -256,20 +253,26 @@ void Sequencer::addElement(const std::shared_ptr<SequenceElement>& element) {

void Sequencer::addWhiteboardAlias(const std::string& aliasName,
const std::string& objectName) {
auto [it, success] =
m_whiteboardObjectAliases.insert({objectName, aliasName});
if (!success) {
ACTS_INFO("Key '" << objectName << "' aliased to '" << aliasName
<< "' already set");
return;
const auto range = m_whiteboardObjectAliases.equal_range(objectName);
for (auto it = range.first; it != range.second; ++it) {
const auto& [key, value] = *it;
if (value == aliasName) {
ACTS_INFO("Key '" << objectName << "' aliased to '" << aliasName
<< "' already set");
return;
}
}

ACTS_INFO("Key '" << objectName << "' aliased to '" << aliasName << "'");
m_whiteboardObjectAliases.insert({objectName, aliasName});

if (auto oit = m_whiteBoardState.find(objectName);
oit != m_whiteBoardState.end()) {
m_whiteBoardState[aliasName] = oit->second;
auto oit = m_whiteBoardState.find(objectName);
if (oit == m_whiteBoardState.end()) {
ACTS_ERROR("Key '" << objectName << "' does not exist");
return;
}

ACTS_INFO("Key '" << objectName << "' aliased to '" << aliasName << "'");
m_whiteBoardState[aliasName] = oit->second;
}

std::vector<std::string> Sequencer::listAlgorithmNames() const {
Expand Down
6 changes: 4 additions & 2 deletions Examples/Framework/src/Framework/WhiteBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ void ActsExamples::WhiteBoard::addHolder(const std::string &name,
<< storeIt->second->type().name());

if (success) {
if (auto it = m_objectAliases.find(name); it != m_objectAliases.end()) {
m_store[it->second] = storeIt->second;
// deal with aliases
auto range = m_objectAliases.equal_range(name);
for (auto it = range.first; it != range.second; ++it) {
m_store[it->second] = holder;
ACTS_VERBOSE("Added alias object '" << it->second << "'");
}
}
Expand Down
Loading