From b0bca118402db2a8acaf13fb71b28e97066b6874 Mon Sep 17 00:00:00 2001
From: Remy Prechelt <prechelt@hawaii.edu>
Date: Fri, 30 Oct 2020 23:05:35 -1000
Subject: [PATCH] Remove name_ from output writer.

---
 Documentation/Examples/vertical_EAS.cc        |  3 +--
 Outputs/ObservationPlaneWriterParquet.h       |  8 ++------
 Outputs/OutputManager.h                       |  8 +++++++-
 Outputs/ParquetStreamer.h                     | 15 ++++++++++++---
 Processes/ObservationPlane/ObservationPlane.h |  1 -
 5 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/Documentation/Examples/vertical_EAS.cc b/Documentation/Examples/vertical_EAS.cc
index 79f3d7ea0..01c5d7382 100644
--- a/Documentation/Examples/vertical_EAS.cc
+++ b/Documentation/Examples/vertical_EAS.cc
@@ -214,8 +214,7 @@ int main(int argc, char** argv) {
   process::longitudinal_profile::LongitudinalProfile longprof{showerAxis};
 
   Plane const obsPlane(showerCore, Vector<dimensionless_d>(rootCS, {0., 0., 1.}));
-  process::observation_plane::ObservationPlane observationLevel(obsPlane, false,
-                                                                "particles");
+  process::observation_plane::ObservationPlane observationLevel(obsPlane, false);
 
   // register the observation plane with the manager
   outputs.Register("obsplane", observationLevel);
diff --git a/Outputs/ObservationPlaneWriterParquet.h b/Outputs/ObservationPlaneWriterParquet.h
index 7a87709e2..89e1fef19 100644
--- a/Outputs/ObservationPlaneWriterParquet.h
+++ b/Outputs/ObservationPlaneWriterParquet.h
@@ -23,9 +23,8 @@ namespace corsika::output {
      *
      * @param name    The name of this output.
      */
-    ObservationPlaneWriterParquet(std::string const& name)
+    ObservationPlaneWriterParquet()
         : ParquetStreamer()
-        , name_(name)
         , event_(0){};
 
     /**
@@ -48,7 +47,6 @@ namespace corsika::output {
 
       // and build the streamer
       BuildStreamer();
-
     }
 
     /**
@@ -64,7 +62,7 @@ namespace corsika::output {
     /**
      * Called at the end of each run.
      */
-    void EndOfRun() final { writer_.reset(); outfile_->Close(); }
+    void EndOfRun() final { CloseStreamer(); }
 
     /**
      * Get final text outputs for the config file.
@@ -84,8 +82,6 @@ namespace corsika::output {
                  << distance / 1_m << parquet::EndRow;
     }
 
-    std::string const name_; ///< The name of this output.
-
   private:
     int event_; ///< The current event number we are processing.
 
diff --git a/Outputs/OutputManager.h b/Outputs/OutputManager.h
index 2a1af4760..e8a38022b 100644
--- a/Outputs/OutputManager.h
+++ b/Outputs/OutputManager.h
@@ -86,8 +86,14 @@ namespace corsika::output {
       // create the directory for this process.
       std::filesystem::create_directory(path);
 
+      // get the config for this output
+      auto config = outputs_.at(name).get().GetConfig();
+
+      // and assign the name for this output
+      config["name"] = name;
+
       // write the config for this output to the file
-      WriteNode(outputs_.at(name).get().GetConfig(), path / "config.yaml");
+      WriteNode(config, path / "config.yaml");
     }
 
   public:
diff --git a/Outputs/ParquetStreamer.h b/Outputs/ParquetStreamer.h
index d83525168..4c2679e56 100644
--- a/Outputs/ParquetStreamer.h
+++ b/Outputs/ParquetStreamer.h
@@ -63,10 +63,19 @@ namespace corsika::output {
           parquet::ParquetFileWriter::Open(outfile_, schema_, builder_.build()));
     }
 
+    /**
+     * Finish writing this stream.
+     *
+     */
+    void CloseStreamer() {
+      writer_.reset();
+      outfile_->Close();
+    }
+
   protected:
-    std::shared_ptr<parquet::StreamWriter> writer_;               ///< The stream writer to 'outfile'
-    parquet::WriterProperties::Builder builder_; ///< The writer properties builder.
-    parquet::schema::NodeVector fields_;         ///< The fields in this file.
+    std::shared_ptr<parquet::StreamWriter> writer_; ///< The stream writer to 'outfile'
+    parquet::WriterProperties::Builder builder_;    ///< The writer properties builder.
+    parquet::schema::NodeVector fields_;            ///< The fields in this file.
     std::shared_ptr<parquet::schema::GroupNode> schema_;   ///< The schema for this file.
     std::shared_ptr<arrow::io::FileOutputStream> outfile_; ///< The output file.
 
diff --git a/Processes/ObservationPlane/ObservationPlane.h b/Processes/ObservationPlane/ObservationPlane.h
index b2dff07ed..1b797d095 100644
--- a/Processes/ObservationPlane/ObservationPlane.h
+++ b/Processes/ObservationPlane/ObservationPlane.h
@@ -94,7 +94,6 @@ namespace corsika::process::observation_plane {
       YAML::Node node;
 
       // basic info
-      node["name"] = this->name_;
       node["type"] = "ObservationPlane";
 
       // the center of the plane
-- 
GitLab