From 6094fcfec22c8d0ae30a86f51f2cc89db0673b0e Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Wed, 17 May 2023 12:58:46 +0000
Subject: [PATCH] algo: Replace std::filesystem with boost::filesystem.

---
 algo/CMakeLists.txt           |  1 +
 algo/base/Options.h           |  5 +++--
 algo/base/compat/Filesystem.h | 18 ++++++++++++++++++
 algo/data/sts/LandauTable.cxx |  2 +-
 algo/data/sts/LandauTable.h   |  4 ++--
 algo/global/Reco.cxx          |  8 +++++---
 6 files changed, 30 insertions(+), 8 deletions(-)
 create mode 100644 algo/base/compat/Filesystem.h

diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt
index b8d0864d46..aaca47bcb3 100644
--- a/algo/CMakeLists.txt
+++ b/algo/CMakeLists.txt
@@ -74,6 +74,7 @@ target_link_libraries(Algo
             ROOT::GenVector
             GSL
             Boost::program_options
+            Boost::filesystem
             xpu
             external::yaml-cpp
   INTERFACE FairLogger::FairLogger
diff --git a/algo/base/Options.h b/algo/base/Options.h
index f67827abf6..5075152d0f 100644
--- a/algo/base/Options.h
+++ b/algo/base/Options.h
@@ -4,9 +4,10 @@
 #ifndef CBM_ALGO_BASE_OPTIONS_H
 #define CBM_ALGO_BASE_OPTIONS_H
 
-#include <filesystem>
 #include <string>
 
+#include "compat/Filesystem.h"
+
 namespace cbm::algo
 {
 
@@ -16,7 +17,7 @@ namespace cbm::algo
     Options() = default;
     Options(int argc, char** argv);
 
-    std::filesystem::path ParamsDir() const { return fParamsDir; }
+    fs::path ParamsDir() const { return fParamsDir; }
     const std::string& InputLocator() const { return fInputLocator; }
     const std::string& LogLevel() const { return fLogLevel; }
     const std::string& Device() const { return fDevice; }
diff --git a/algo/base/compat/Filesystem.h b/algo/base/compat/Filesystem.h
new file mode 100644
index 0000000000..51ae1811d9
--- /dev/null
+++ b/algo/base/compat/Filesystem.h
@@ -0,0 +1,18 @@
+/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Felix Weiglhofer [committer] */
+#ifndef CBM_ALGO_BASE_FILESYSTEM_H
+#define CBM_ALGO_BASE_FILESYSTEM_H
+
+#include <boost/filesystem.hpp>
+
+namespace cbm::algo
+{
+
+  // Use boost::filesystem by default instead of std::filesystem for
+  // compatibility with older compilers and ROOT versions
+  namespace fs = boost::filesystem;
+
+}  // namespace cbm::algo
+
+#endif  // CBM_ALGO_BASE_FILESYSTEM_H
diff --git a/algo/data/sts/LandauTable.cxx b/algo/data/sts/LandauTable.cxx
index 3dcf38f753..fe7fcabf5f 100644
--- a/algo/data/sts/LandauTable.cxx
+++ b/algo/data/sts/LandauTable.cxx
@@ -9,7 +9,7 @@
 
 using namespace cbm::algo;
 
-sts::LandauTable sts::LandauTable::FromFile(std::filesystem::path path)
+sts::LandauTable sts::LandauTable::FromFile(fs::path path)
 {
   sts::LandauTable table;
 
diff --git a/algo/data/sts/LandauTable.h b/algo/data/sts/LandauTable.h
index b6ab665e0e..06ca354692 100644
--- a/algo/data/sts/LandauTable.h
+++ b/algo/data/sts/LandauTable.h
@@ -4,17 +4,17 @@
 #ifndef CBM_ALGO_DATA_STS_LANDAUTABLE_H
 #define CBM_ALGO_DATA_STS_LANDAUTABLE_H
 
-#include <filesystem>
 #include <vector>
 
 #include "Prelude.h"
+#include "compat/Filesystem.h"
 
 namespace cbm::algo::sts
 {
 
   struct LandauTable {
 
-    static LandauTable FromFile(std::filesystem::path path);
+    static LandauTable FromFile(fs::path path);
 
     std::vector<f32> values;
     f32 stepSize = 0;
diff --git a/algo/global/Reco.cxx b/algo/global/Reco.cxx
index 1954146892..dc5f6af7c6 100644
--- a/algo/global/Reco.cxx
+++ b/algo/global/Reco.cxx
@@ -26,8 +26,9 @@ void Reco::Init(const Options& opts)
   LOG(info) << "Running CBM Reco on Device " << props.name();
 
   // Reco Params
-  YAML::Node yaml     = YAML::LoadFile(opts.ParamsDir() / "RecoParams.yaml");
-  fContext.recoParams = config::Read<RecoParams>(yaml);
+  fs::path recoParamsPath = opts.ParamsDir() / "Reco.yaml";
+  YAML::Node yaml         = YAML::LoadFile(recoParamsPath.string());
+  fContext.recoParams     = config::Read<RecoParams>(yaml);
 
   // STS Unpacker
   // yaml = YAML::LoadFile(opts.ParamsDir() / "StsReadout.yaml");
@@ -36,7 +37,8 @@ void Reco::Init(const Options& opts)
   fUnpack.Init(readoutConfig);
 
   // STS Hitfinder
-  yaml                               = YAML::LoadFile(opts.ParamsDir() / "StsHitfinder.yaml");
+  fs::path stsHitfinderParamsPath    = opts.ParamsDir() / "StsHitfinder.yaml";
+  yaml                               = YAML::LoadFile(stsHitfinderParamsPath.string());
   sts::HitfinderPars hitFinderConfig = config::Read<sts::HitfinderPars>(yaml);
   hitFinderConfig.landauTable        = sts::LandauTable::FromFile(opts.ParamsDir() / "LandauWidthTable.txt");
   fStsHitFinder.SetParameters(hitFinderConfig);
-- 
GitLab