From 4dce9b9c04f59b5816192ac34f3bd7a2c6247f93 Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@tu-dortmund.de>
Date: Sun, 19 Apr 2020 18:34:06 +0200
Subject: [PATCH] central access to CORSIKA_DATA path

---
 Framework/Utilities/CMakeLists.txt |  2 ++
 Framework/Utilities/CorsikaData.cc | 14 ++++++++++++++
 Framework/Utilities/CorsikaData.h  | 19 +++++++++++++++++++
 3 files changed, 35 insertions(+)
 create mode 100644 Framework/Utilities/CorsikaData.cc
 create mode 100644 Framework/Utilities/CorsikaData.h

diff --git a/Framework/Utilities/CMakeLists.txt b/Framework/Utilities/CMakeLists.txt
index 6baab4e54..b5796bfd5 100644
--- a/Framework/Utilities/CMakeLists.txt
+++ b/Framework/Utilities/CMakeLists.txt
@@ -20,10 +20,12 @@ endif ()
 set (
   UTILITIES_SOURCES  
   COMBoost.cc
+  CorsikaData.cc
   ${CORSIKA_FENV})
 
 set (
   UTILITIES_HEADERS
+  CorsikaData.h
   COMBoost.h
   Bit.h
   Singleton.h
diff --git a/Framework/Utilities/CorsikaData.cc b/Framework/Utilities/CorsikaData.cc
new file mode 100644
index 000000000..1d30f5132
--- /dev/null
+++ b/Framework/Utilities/CorsikaData.cc
@@ -0,0 +1,14 @@
+#include <corsika/utl/CorsikaData.h>
+
+#include <cstdlib>
+#include <stdexcept>
+#include <string>
+
+std::filesystem::path corsika::utl::CorsikaData(std::filesystem::path const& key) {
+  if (auto const* p = std::getenv("CORSIKA_DATA"); p != nullptr) {
+    auto const path = std::filesystem::path(p) / key;
+    return path;
+  } else {
+    throw std::runtime_error("CORSIKA_DATA not set");
+  }
+}
diff --git a/Framework/Utilities/CorsikaData.h b/Framework/Utilities/CorsikaData.h
new file mode 100644
index 000000000..63e763aa6
--- /dev/null
+++ b/Framework/Utilities/CorsikaData.h
@@ -0,0 +1,19 @@
+/*
+ * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
+ *
+ * See file AUTHORS for a list of contributors.
+ *
+ * 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.
+ */
+
+#include <filesystem>
+#include <string>
+
+namespace corsika::utl {
+  /**
+   * returns the full path of the file \p filename within the CORSIKA_DATA directory
+   */
+  std::filesystem::path CorsikaData(std::filesystem::path const& filename);
+} // namespace corsika::utl
-- 
GitLab