-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: particleSvc to distribute mass by PDG (#1487)
### Briefly, what does this PR introduce? Instead of storing the mass of the proton etc in various classes, this PR adds an algorithms::ParticleSvc that distributes the correct masses and charge etc by PDG number. Note: I was playing around with using the algorithms::ParticleSvc as a thin interface-only, and let a JService read a data file and provide the actual service. But I gave up since it seemed pointless. ### What kind of change does this PR introduce? - [ ] Bug fix (issue #__) - [x] New feature (issue #__) - [ ] Documentation update - [ ] Other: __ ### Please check if this PR fulfills the following: - [ ] Tests for the changes have been added - [ ] Documentation has been added / updated - [ ] Changes have been communicated to collaborators ### Does this PR introduce breaking changes? What changes might users need to make to their code? No. ### Does this PR change default behavior? No. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
- Loading branch information
1 parent
89b9d65
commit 7c7f310
Showing
29 changed files
with
394 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
set(PLUGIN_NAME "algorithms_interfaces") | ||
plugin_headers_only(${PLUGIN_NAME}) | ||
|
||
# Function creates ${PLUGIN_NAME}_plugin and ${PLUGIN_NAME}_library targets | ||
# Setting default includes, libraries and installation paths | ||
plugin_add(${PLUGIN_NAME} WITH_SHARED_LIBRARY WITHOUT_PLUGIN) | ||
|
||
# The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp Then | ||
# correctly sets sources for ${_name}_plugin and ${_name}_library targets Adds | ||
# headers to the correct installation directory | ||
plugin_glob_all(${PLUGIN_NAME}) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// Copyright (C) 2024 Wouter Deconinck | ||
|
||
#pragma once | ||
|
||
#include <algorithms/service.h> | ||
#include <map> | ||
#include <memory> | ||
#include <string> | ||
|
||
namespace algorithms { | ||
|
||
class ParticleSvc : public Service<ParticleSvc> { | ||
public: | ||
struct ParticleData { | ||
int pdgCode; | ||
int charge; | ||
double mass; | ||
std::string name; | ||
}; | ||
using Particle = ParticleData; | ||
using ParticleMap = std::map<int, Particle>; | ||
|
||
private: | ||
static const std::shared_ptr<ParticleMap> kParticleMap; | ||
|
||
public: | ||
virtual void init(std::shared_ptr<ParticleMap> map = kParticleMap) { | ||
if (map != nullptr) { | ||
m_particleMap = map; | ||
} | ||
} | ||
|
||
virtual std::shared_ptr<ParticleMap> particleMap() const { | ||
return m_particleMap; | ||
}; | ||
|
||
virtual Particle& particle(int pdg) const { | ||
if (m_particleMap->count(pdg) == 0) { | ||
return m_particleMap->at(0); | ||
} | ||
return m_particleMap->at(pdg); | ||
}; | ||
|
||
protected: | ||
std::shared_ptr<ParticleMap> m_particleMap{nullptr}; | ||
|
||
ALGORITHMS_DEFINE_SERVICE(ParticleSvc) | ||
}; | ||
|
||
} // namespace algorithms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.