Skip to content

Commit

Permalink
allow multiple aliases to point to the same object; some downstream c…
Browse files Browse the repository at this point in the history
…hanges
  • Loading branch information
andiwand committed Dec 9, 2024
1 parent f3d609f commit 2519b2c
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 106 deletions.
8 changes: 4 additions & 4 deletions CI/physmon/workflows/physmon_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
acts.PdgParticle.eElectron,
]
],
outputParticles="particles_input",
outputParticles="particles_generated",
outputVertices="vertices_input",
randomNumbers=rnd,
)
Expand All @@ -67,7 +67,7 @@
s.addWriter(
acts.examples.RootParticleWriter(
level=acts.logging.INFO,
inputParticles="particles_input",
inputParticles="particles_generated",
filePath=tp / "particles.root",
)
)
Expand All @@ -80,7 +80,7 @@
enableInteractions=True,
preSelectParticles=None,
postSelectParticles=ParticleSelectorConfig(removeSecondaries=True),
inputParticles="particles_input",
inputParticles="particles_generated",
outputParticles="particles_fatras",
outputSimHits="simhits_fatras",
outputDirRoot=tp / "fatras",
Expand All @@ -97,7 +97,7 @@
killVolume=setup.trackingGeometry.highestTrackingVolume,
killAfterTime=25 * u.ns,
killSecondaries=True,
inputParticles="particles_input",
inputParticles="particles_generated",
outputParticles="particles_geant4",
outputSimHits="simhits_geant4",
outputDirRoot=tp / "geant4",
Expand Down
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
18 changes: 11 additions & 7 deletions Examples/Framework/include/ActsExamples/Framework/WhiteBoard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <utility>
Expand All @@ -34,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 = {});

// A WhiteBoard holds unique elements and can not be copied
WhiteBoard(const WhiteBoard& other) = delete;
Expand Down Expand Up @@ -82,7 +82,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 @@ -100,7 +100,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 All @@ -111,10 +111,14 @@ inline void ActsExamples::WhiteBoard::add(const std::string& name, T&& object) {
if (m_store.contains(name)) {
throw std::invalid_argument("Object '" + name + "' already exists");
}

auto holder = std::make_shared<HolderT<T>>(std::forward<T>(object));
m_store.emplace(name, holder);
ACTS_VERBOSE("Added object '" << name << "' of type " << typeid(T).name());
if (auto it = m_objectAliases.find(name); it != m_objectAliases.end()) {

// 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
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
10 changes: 3 additions & 7 deletions Examples/Python/python/acts/examples/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def addParticleGun(
s.addWhiteboardAlias("particles", evGen.config.outputParticles)
s.addWhiteboardAlias("vertices_truth", evGen.config.outputVertices)

s.addWhiteboardAlias("particles_selected", evGen.config.outputParticles)
s.addWhiteboardAlias("particles_generated_selected", evGen.config.outputParticles)

if printParticles:
Expand Down Expand Up @@ -333,7 +332,6 @@ def addPythia8(
s.addWhiteboardAlias("particles", evGen.config.outputParticles)
s.addWhiteboardAlias("vertices_truth", evGen.config.outputVertices)

s.addWhiteboardAlias("particles_selected", evGen.config.outputParticles)
s.addWhiteboardAlias("particles_generated_selected", evGen.config.outputParticles)

if printParticles:
Expand Down Expand Up @@ -400,7 +398,7 @@ def addGenParticleSelection(
customLogLevel = acts.examples.defaultLogging(s, logLevel)

selector = acts.examples.ParticleSelector(
**_getParticleSelectionKWargs(config),
**acts.examples.defaultKWArgs(**_getParticleSelectionKWargs(config)),
level=customLogLevel(),
inputParticles="particles_generated",
outputParticles="tmp_particles_generated_selected",
Expand Down Expand Up @@ -477,7 +475,6 @@ def addFatras(

s.addWhiteboardAlias("particles", outputParticles)

s.addWhiteboardAlias("particles_selected", outputParticles)
s.addWhiteboardAlias("particles_simulated_selected", outputParticles)

addSimWriters(
Expand Down Expand Up @@ -654,7 +651,6 @@ def addGeant4(

s.addWhiteboardAlias("particles", outputParticles)

s.addWhiteboardAlias("particles_selected", outputParticles)
s.addWhiteboardAlias("particles_simulated_selected", outputParticles)

addSimWriters(
Expand Down Expand Up @@ -688,7 +684,7 @@ def addSimParticleSelection(
customLogLevel = acts.examples.defaultLogging(s, logLevel)

selector = acts.examples.ParticleSelector(
**_getParticleSelectionKWargs(config),
**acts.examples.defaultKWArgs(**_getParticleSelectionKWargs(config)),
level=customLogLevel(),
inputParticles="particles_simulated",
outputParticles="tmp_particles_simulated_selected",
Expand Down Expand Up @@ -809,7 +805,7 @@ def addDigiParticleSelection(
customLogLevel = acts.examples.defaultLogging(s, logLevel)

selector = acts.examples.ParticleSelector(
**_getParticleSelectionKWargs(config),
**acts.examples.defaultKWArgs(**_getParticleSelectionKWargs(config)),
level=customLogLevel(),
inputParticles="particles_simulated_selected",
outputParticles="tmp_particles_digitized_selected",
Expand Down
8 changes: 4 additions & 4 deletions Examples/Python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def _basic_prop_seq_factory(geo, s=None):

trkParamExtractor = acts.examples.ParticleTrackParamExtractor(
level=acts.logging.WARNING,
inputParticles="particles_input",
outputTrackParameters="params_particles_input",
inputParticles="particles_generated",
outputTrackParameters="params_particles_generated",
)
s.addAlgorithm(trkParamExtractor)

Expand All @@ -225,7 +225,7 @@ def _basic_prop_seq_factory(geo, s=None):
level=acts.logging.WARNING,
propagatorImpl=prop,
sterileLogger=False,
inputTrackParameters="params_particles_input",
inputTrackParameters="params_particles_generated",
outputSummaryCollection="propagation_summary",
)
s.addAlgorithm(alg)
Expand Down Expand Up @@ -325,7 +325,7 @@ def _factory(s):
),
)
],
outputParticles="particles_input",
outputParticles="particles_generated",
outputVertices="vertices_input",
randomNumbers=rng,
)
Expand Down
6 changes: 3 additions & 3 deletions Examples/Python/tests/test_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ def test_steppers(conf_const, trk_geo):

trkParamExtractor = acts.examples.ParticleTrackParamExtractor(
level=acts.logging.WARNING,
inputParticles="particles_input",
outputTrackParameters="params_particles_input",
inputParticles="particles_generated",
outputTrackParameters="params_particles_generated",
)
seq.addAlgorithm(trkParamExtractor)

alg = conf_const(
acts.examples.PropagationAlgorithm,
level=acts.logging.WARNING,
propagatorImpl=prop,
inputTrackParameters="params_particles_input",
inputTrackParameters="params_particles_generated",
outputSummaryCollection="propagation_summary",
sterileLogger=False,
)
Expand Down
8 changes: 4 additions & 4 deletions Examples/Python/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ def test_root_particle_reader(tmp_path, conf_const, ptcl_gun):
conf_const(
RootParticleReader,
acts.logging.WARNING,
outputParticles="particles_input",
outputParticles="particles_generated",
filePath=str(file),
)
)

alg = AssertCollectionExistsAlg(
"particles_input", "check_alg", acts.logging.WARNING
"particles_generated", "check_alg", acts.logging.WARNING
)
s2.addAlgorithm(alg)

Expand Down Expand Up @@ -317,7 +317,7 @@ def test_edm4hep_simhit_particle_reader(tmp_path):
"LongStripBarrelReadout",
"LongStripEndcapReadout",
],
outputParticlesGenerator="particles_input",
outputParticlesGenerator="particles_generated",
outputParticlesSimulation="particles_simulated",
outputSimHits="simhits",
dd4hepDetector=detector,
Expand All @@ -329,7 +329,7 @@ def test_edm4hep_simhit_particle_reader(tmp_path):
s.addAlgorithm(alg)

alg = AssertCollectionExistsAlg(
"particles_input", "check_alg", acts.logging.WARNING
"particles_generated", "check_alg", acts.logging.WARNING
)
s.addAlgorithm(alg)

Expand Down
2 changes: 1 addition & 1 deletion Examples/Scripts/Optimization/ckf.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def runCKFTracks(
RootParticleReader(
level=acts.logging.INFO,
filePath=str(inputParticlePath.resolve()),
outputParticles="particles_input",
outputParticles="particles_generated",
)
)

Expand Down
2 changes: 1 addition & 1 deletion Examples/Scripts/Python/ckf_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def runCKFTracks(
RootParticleReader(
level=acts.logging.INFO,
filePath=str(inputParticlePath.resolve()),
outputParticles="particles_input",
outputParticles="particles_generated",
)
)

Expand Down
2 changes: 1 addition & 1 deletion Examples/Scripts/Python/digitization.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def runDigitization(
evGen = acts.examples.RootParticleReader(
level=s.config.logLevel,
filePath=str(particlesInput),
outputParticles="particles_input",
outputParticles="particles_generated",
)
s.addReader(evGen)

Expand Down
2 changes: 1 addition & 1 deletion Examples/Scripts/Python/event_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def runEventRecording(detector, outputDir, s=None):
),
)
],
outputParticles="particles_input",
outputParticles="particles_generated",
outputVertices="vertices_input",
randomNumbers=rnd,
)
Expand Down
Loading

0 comments on commit 2519b2c

Please sign in to comment.