IAP GITLAB

Skip to content
Snippets Groups Projects
Commit e5913aae authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan: Committed by Ralf Ulrich
Browse files

take ownership of underlying process

parent d2bee853
No related branches found
No related tags found
1 merge request!351Adding wrapper process to modify interaction lengths
...@@ -17,9 +17,9 @@ namespace corsika { ...@@ -17,9 +17,9 @@ namespace corsika {
template <class TUnderlyingProcess> template <class TUnderlyingProcess>
inline IntLengthModifyingProcess<TUnderlyingProcess>::IntLengthModifyingProcess( inline IntLengthModifyingProcess<TUnderlyingProcess>::IntLengthModifyingProcess(
TUnderlyingProcess& process, TUnderlyingProcess&& process,
std::function<IntLengthModifyingProcess::functor_signature> modifier) std::function<IntLengthModifyingProcess::functor_signature> modifier)
: process_{process} : process_{std::move(process)}
, modifier_{std::move(modifier)} {} , modifier_{std::move(modifier)} {}
template <class TUnderlyingProcess> template <class TUnderlyingProcess>
...@@ -40,4 +40,15 @@ namespace corsika { ...@@ -40,4 +40,15 @@ namespace corsika {
return modifier_(original, pid, energy); return modifier_(original, pid, energy);
} }
template <class TUnderlyingProcess>
inline TUnderlyingProcess const&
IntLengthModifyingProcess<TUnderlyingProcess>::getProcess() const {
return process_;
}
template <class TUnderlyingProcess>
inline TUnderlyingProcess& IntLengthModifyingProcess<TUnderlyingProcess>::getProcess() {
return process_;
}
} // namespace corsika } // namespace corsika
...@@ -35,7 +35,7 @@ namespace corsika { ...@@ -35,7 +35,7 @@ namespace corsika {
//! energy //! energy
using functor_signature = GrammageType(GrammageType, corsika::Code, HEPEnergyType); using functor_signature = GrammageType(GrammageType, corsika::Code, HEPEnergyType);
IntLengthModifyingProcess(TUnderlyingProcess& process, IntLengthModifyingProcess(TUnderlyingProcess&& process,
std::function<functor_signature> modifier); std::function<functor_signature> modifier);
//! wrapper around internal process doInteraction //! wrapper around internal process doInteraction
...@@ -46,8 +46,11 @@ namespace corsika { ...@@ -46,8 +46,11 @@ namespace corsika {
template <typename TParticle> template <typename TParticle>
GrammageType getInteractionLength(TParticle const& particle); GrammageType getInteractionLength(TParticle const& particle);
TUnderlyingProcess const& getProcess() const;
TUnderlyingProcess& getProcess();
private: private:
TUnderlyingProcess& process_; TUnderlyingProcess process_;
std::function<functor_signature> const modifier_{non_modifying_functor}; std::function<functor_signature> const modifier_{non_modifying_functor};
}; };
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
using namespace corsika; using namespace corsika;
struct DummyProcess { struct DummyProcess {
int id{0};
template <typename TParticle> template <typename TParticle>
GrammageType getInteractionLength(TParticle const&) { GrammageType getInteractionLength(TParticle const&) {
return 100_g / 1_cm / 1_cm; return 100_g / 1_cm / 1_cm;
...@@ -23,6 +25,13 @@ struct DummyProcess { ...@@ -23,6 +25,13 @@ struct DummyProcess {
void doInteraction(TArgument& arg) { void doInteraction(TArgument& arg) {
arg = 3; arg = 3;
} }
DummyProcess() = default;
DummyProcess(DummyProcess&&) = default;
// prevent copying
DummyProcess(DummyProcess const&) = delete;
DummyProcess& operator=(DummyProcess const&) = delete;
}; };
struct DummyParticle { struct DummyParticle {
...@@ -33,12 +42,14 @@ struct DummyParticle { ...@@ -33,12 +42,14 @@ struct DummyParticle {
TEST_CASE("IntLengthModifyingProcess", "[process]") { TEST_CASE("IntLengthModifyingProcess", "[process]") {
DummyProcess u; DummyProcess u;
u.id = 38;
auto const modifier = [](GrammageType orig, Code, HEPEnergyType) -> GrammageType { auto const modifier = [](GrammageType orig, Code, HEPEnergyType) -> GrammageType {
return orig * 2; return orig * 2;
}; };
IntLengthModifyingProcess mod{u, modifier}; IntLengthModifyingProcess mod{std::move(u), modifier};
REQUIRE(std::is_same_v<decltype(mod), IntLengthModifyingProcess<DummyProcess>>);
SECTION("getInteractionLength") { SECTION("getInteractionLength") {
DummyParticle const p; DummyParticle const p;
...@@ -50,4 +61,13 @@ TEST_CASE("IntLengthModifyingProcess", "[process]") { ...@@ -50,4 +61,13 @@ TEST_CASE("IntLengthModifyingProcess", "[process]") {
mod.doInteraction(k); mod.doInteraction(k);
REQUIRE(k == 3); REQUIRE(k == 3);
} }
SECTION("getProcess") {
DummyProcess& uRef = mod.getProcess();
REQUIRE(uRef.id == 38);
decltype(mod) const& modConstRef = mod;
DummyProcess const& uConstRef = modConstRef.getProcess();
REQUIRE(uConstRef.id == 38);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment