From 99697d4b5bf0a1eb7ebc6f8ae94223f084a7b5f9 Mon Sep 17 00:00:00 2001
From: Remy Prechelt <prechelt@hawaii.edu>
Date: Tue, 1 Jun 2021 22:10:52 -1000
Subject: [PATCH] Rework ObservationPlane into old-style with ParticleWriter.

---
 corsika/detail/modules/ObservationPlane.inl   |  7 ++--
 corsika/detail/output/OutputManager.inl       |  9 +++++
 corsika/modules/ObservationPlane.hpp          | 13 +------
 corsika/modules/writers/ParticleWriterOff.hpp | 39 -------------------
 corsika/modules/writers/WriterOff.hpp         | 33 ++++++++++++++++
 corsika/output/BaseOutput.hpp                 |  5 +++
 6 files changed, 52 insertions(+), 54 deletions(-)
 delete mode 100644 corsika/modules/writers/ParticleWriterOff.hpp
 create mode 100644 corsika/modules/writers/WriterOff.hpp

diff --git a/corsika/detail/modules/ObservationPlane.inl b/corsika/detail/modules/ObservationPlane.inl
index 4a9efbca6..0d2ea0639 100644
--- a/corsika/detail/modules/ObservationPlane.inl
+++ b/corsika/detail/modules/ObservationPlane.inl
@@ -11,9 +11,8 @@ namespace corsika {
   template <typename TOutput>
   ObservationPlane<TOutput>::ObservationPlane(Plane const& obsPlane,
                                               DirectionVector const& x_axis,
-                                              TOutput& output, bool deleteOnHit)
+                                              bool const deleteOnHit)
       : plane_(obsPlane)
-      , output_(output)
       , deleteOnHit_(deleteOnHit)
       , energy_ground_(0_GeV)
       , count_ground_(0)
@@ -54,11 +53,11 @@ namespace corsika {
     Code const pid = particle.getPID();
     if (pid == Code::Nucleus) {
       // add our particles to the output file stream
-      output_.write(particle.getNuclearA(), particle.getNuclearZ(), energy,
+      this->write(particle.getNuclearA(), particle.getNuclearZ(), energy,
                     displacement.dot(xAxis_), displacement.dot(yAxis_), 0_m, weight);
     } else {
       // add our particles to the output file stream
-      output_.write(particle.getPID(), energy, displacement.dot(xAxis_),
+      this->write(particle.getPID(), energy, displacement.dot(xAxis_),
                     displacement.dot(yAxis_), 0_m, weight);
     }
 
diff --git a/corsika/detail/output/OutputManager.inl b/corsika/detail/output/OutputManager.inl
index 2cc5e9780..82fe4cdb4 100644
--- a/corsika/detail/output/OutputManager.inl
+++ b/corsika/detail/output/OutputManager.inl
@@ -153,6 +153,15 @@ namespace corsika {
 
       // and start the library
       output.get().startOfLibrary(root_ / name);
+
+      // get the config from this output
+      auto config = output.get().getConfig();
+
+      // add the name keyword
+      config["name"] = name;
+      
+      // write the output configuration to config.yaml in the output directory
+      writeYAML(config, root_ / name / ("config.yaml"));
     }
 
     // we have now started running
diff --git a/corsika/modules/ObservationPlane.hpp b/corsika/modules/ObservationPlane.hpp
index bf1798c18..b2c276ee6 100644
--- a/corsika/modules/ObservationPlane.hpp
+++ b/corsika/modules/ObservationPlane.hpp
@@ -36,16 +36,9 @@ namespace corsika {
         public TOutputWriter {
 
   public:
-    ObservationPlane(Plane const&, DirectionVector const&, TOutput& output, bool = true);
+    ObservationPlane(Plane const&, DirectionVector const&, bool const = true);
 
-    ObservationPlane(Plane const& p, DirectionVector const& d, bool f = true)
-        : ObservationPlane(p, d, *(new ParticleWriterOff()), f) {
-      ownOutput_ = true;
-    }
-
-    ~ObservationPlane() {
-      if (ownOutput_) delete &output_;
-    }
+    ~ObservationPlane() {}
 
     template <typename TParticle, typename TTrajectory>
     ProcessReturn doContinuous(TParticle& vParticle, TTrajectory& vTrajectory,
@@ -61,8 +54,6 @@ namespace corsika {
 
   private:
     Plane const plane_;
-    TOutput& output_;
-    bool ownOutput_ = false;
     bool const deleteOnHit_;
     HEPEnergyType energy_ground_;
     unsigned int count_ground_;
diff --git a/corsika/modules/writers/ParticleWriterOff.hpp b/corsika/modules/writers/ParticleWriterOff.hpp
deleted file mode 100644
index 27a6ab763..000000000
--- a/corsika/modules/writers/ParticleWriterOff.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu
- *
- * This software is distributed under the terms of the GNU General Public
- * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
- * the license.
- */
-
-#pragma once
-
-#include <corsika/output/BaseOutput.hpp>
-#include <corsika/framework/core/PhysicalUnits.hpp>
-#include <corsika/framework/core/ParticleProperties.hpp>
-
-namespace corsika {
-
-  class ParticleWriterOff : public BaseOutput {
-
-  public:
-    ParticleWriterOff() {}
-    virtual ~ParticleWriterOff() {}
-
-    void startOfLibrary(boost::filesystem::path const&) final override {}
-
-    void endOfShower(unsigned int const) final override {}
-
-    void endOfLibrary() final override {}
-
-    // for pdg particles
-    void write(Code const&, HEPEnergyType const&, LengthType const&, LengthType const&, LengthType const&,
-               double const) {}
-
-    // for nuclei
-    void write(unsigned int const, unsigned int const, HEPEnergyType const&,
-               LengthType const&, LengthType const&, LengthType const&, double const) {}
-
-  }; // class ParticleWriterOff
-
-} // namespace corsika
diff --git a/corsika/modules/writers/WriterOff.hpp b/corsika/modules/writers/WriterOff.hpp
new file mode 100644
index 000000000..783507a48
--- /dev/null
+++ b/corsika/modules/writers/WriterOff.hpp
@@ -0,0 +1,33 @@
+/*
+ * (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu
+ *
+ * This software is distributed under the terms of the GNU General Public
+ * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
+ * the license.
+ */
+
+#pragma once
+
+#include <corsika/output/BaseOutput.hpp>
+
+
+namespace corsika {
+
+  class WriterOff : public BaseOutput {
+
+  public:
+    WriterOff() {}
+    virtual ~WriterOff() {}
+
+    void startOfLibrary(boost::filesystem::path const&) final override {}
+
+    void endOfShower(unsigned int const) final override {}
+
+    void endOfLibrary() final override {}
+
+    template <typename... TArgs>
+    void write(TArgs&&... args) {}
+
+  }; // class WriterOff
+
+} // namespace corsika
diff --git a/corsika/output/BaseOutput.hpp b/corsika/output/BaseOutput.hpp
index 8581f1fa4..435519a2c 100644
--- a/corsika/output/BaseOutput.hpp
+++ b/corsika/output/BaseOutput.hpp
@@ -63,6 +63,11 @@ namespace corsika {
      */
     virtual YAML::Node getSummary() const { return YAML::Node(); }
 
+    /**
+     * Provide YAML configuration for this BaseOutput.
+     */
+    virtual YAML::Node getConfig() const = 0;
+
   protected:
     /**
      * Set init flag.
-- 
GitLab