From 155151bb39d31d0e7f8d4991fee17482b82e7f92 Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Sun, 5 Aug 2018 18:58:30 -0500
Subject: [PATCH] Added variable helper function template.

---
 src/THcParmList.cxx |  1 +
 src/THcParmList.h   | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx
index 4e0a781..7f34246 100644
--- a/src/THcParmList.cxx
+++ b/src/THcParmList.cxx
@@ -693,6 +693,7 @@ std::string THcParmList::PrintJSON(int run_number ) const {
       obj->Print();
     }
   }
+
   nlohmann::json jrun;
   jrun[std::to_string(run_number)] = j;
   //std::cout << j.dump(2) << "\n";
diff --git a/src/THcParmList.h b/src/THcParmList.h
index 35490d3..38b192a 100644
--- a/src/THcParmList.h
+++ b/src/THcParmList.h
@@ -23,7 +23,6 @@ using namespace ccdb;
 using namespace std;
 
 
-
 class THcParmList : public THaVarList {
 
 public:
@@ -77,5 +76,23 @@ protected:
   ClassDef(THcParmList,0) // List of analyzer global parameters
 
 };
+
+
+namespace hcana{
+  namespace json {
+
+    template<typename T = double>
+    T FindVarValueOr(THcParmList* parms, std::string var, T value){
+      auto p = parms->Find(var.c_str());
+      if(!p) {
+        return value;
+      }
+      const auto res = static_cast<const T*>(p->GetDataPointer());
+      return *res;
+    }
+
+  }
+}
+
 #endif
 
-- 
GitLab