From dd94ed16ad3a0d25b73d3d2483129f3102370918 Mon Sep 17 00:00:00 2001
From: scott snyder <sss@karma>
Date: Sat, 2 May 2020 18:28:56 +0200
Subject: [PATCH] CaloConditions: Additions to ToolConstants.

Add ToolConstants::toString().
Allow ToolConstants::setrep to take the payload via move.
---
 .../CaloConditions/ToolConstants.h            | 23 +++++++++++++++-
 .../CaloConditions/src/ToolConstants.cxx      | 26 ++++++++++++++++++-
 .../test/ToolConstants_test.cxx               | 22 +++++++++++++++-
 3 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/Calorimeter/CaloConditions/CaloConditions/ToolConstants.h b/Calorimeter/CaloConditions/CaloConditions/ToolConstants.h
index 712bb87f6ce..f0bcd25b581 100755
--- a/Calorimeter/CaloConditions/CaloConditions/ToolConstants.h
+++ b/Calorimeter/CaloConditions/CaloConditions/ToolConstants.h
@@ -1,7 +1,7 @@
 // This file's extension implies that it's C, but it's really -*- C++ -*-.
 
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 // $Id: ToolConstants.h,v 1.5 2009-04-09 14:41:17 ssnyder Exp $
@@ -76,11 +76,21 @@ public:
                const CxxUtils::Arrayrep& rep);
 
 
+  /**
+   * @brief Set an entry.
+   * @param key The key of the entry to set.
+   * @param rep The value of the new entry.
+   */
+  void setrep (const std::string& key,
+               CxxUtils::Arrayrep&& rep);
+
+
   /**
    * @brief Test to see if a given key is present.
    */
   bool hasrep (const std::string& key) const;
 
+
   /**
    * @brief Writes out constants in a python-like format
    * @param stream Stream to which to write (file or cout)
@@ -89,6 +99,13 @@ public:
   void writeConstants(std::ostream& stream, const std::string& name) const;
 
 
+  /**
+   * @brief Return the data as a formatted string.
+   * @param name Name of the Maker-Algorithm.
+   */
+  std::string toString (const std::string& name) const;
+
+
   /**
    * @brief Return the name of the C++ class that operates on these constants.
    */
@@ -144,4 +161,8 @@ private:
 
 
 CLASS_DEF(CaloRec::ToolConstants,250904980 ,1)
+
+#include "AthenaKernel/CondCont.h"
+CONDCONT_DEF( CaloRec::ToolConstants, 274098 );
+
 #endif // not CALOREC_TOOLCONSTANTS_H
diff --git a/Calorimeter/CaloConditions/src/ToolConstants.cxx b/Calorimeter/CaloConditions/src/ToolConstants.cxx
index 13854e5c0cc..8396f99ee5c 100755
--- a/Calorimeter/CaloConditions/src/ToolConstants.cxx
+++ b/Calorimeter/CaloConditions/src/ToolConstants.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 // $Id: ToolConstants.cxx,v 1.5 2009-04-09 14:41:17 ssnyder Exp $
@@ -79,6 +79,18 @@ void ToolConstants::setrep (const std::string& key,
 }
 
 
+/**
+ * @brief Set an entry.
+ * @param key The key of the entry to set.
+ * @param rep The value of the new entry.
+ */
+void ToolConstants::setrep (const std::string& key,
+                            CxxUtils::Arrayrep&& rep)
+{
+  m_map[key] = std::move (rep);
+}
+
+
 /**
  * @brief Test to see if a given key is present.
  */
@@ -119,6 +131,18 @@ void ToolConstants::writeConstants(std::ostream& stream,
 }
 
 
+/**
+ * @brief Return the data as a formatted string.
+ * @param name Name of the Maker-Algorithm.
+ */
+std::string ToolConstants::toString (const std::string& name) const
+{
+  std::ostringstream ss;
+  writeConstants (ss, name);
+  return ss.str();
+}
+
+
 /**
  * @brief Return the name of the C++ class that operates on these constants.
  */
diff --git a/Calorimeter/CaloConditions/test/ToolConstants_test.cxx b/Calorimeter/CaloConditions/test/ToolConstants_test.cxx
index e3e295c250b..3cd43b73888 100755
--- a/Calorimeter/CaloConditions/test/ToolConstants_test.cxx
+++ b/Calorimeter/CaloConditions/test/ToolConstants_test.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 // $Id: ToolConstants_test.cxx,v 1.4 2009-04-09 14:41:17 ssnyder Exp $
@@ -65,6 +65,17 @@ void test1()
   Array<0> a4 (tc.getrep ("foo", "fee"));
   assert (a4 == 1.25);
 
+  Arrayrep rep;
+  rep.m_shape.assign ({3});
+  rep.m_data.assign ({1.5, 2.5, 3.5});
+  rep.init_sizes();
+
+  tc.setrep ("bar", std::move (rep));
+  Array<1> a5 = tc.getrep ("foo", "bar");
+  assert (a5.size() == 3);
+  assert (a5[0] == 1.5);
+  assert (rep.m_data.empty());
+
   assert (tc.clsname() == "");
   tc.clsname ("abc");
   assert (tc.clsname() == "abc");
@@ -72,6 +83,15 @@ void test1()
   assert (tc.version() == 0);
   tc.version (10);
   assert (tc.version() == 10);
+
+  std::string s = tc.toString ("foo");
+  assert (s == "foo.a = 1.25\n"
+          "foo.b = [\n"
+          "    [1, 2],\n"
+          "    [3, 4]\n"
+          "    ]\n"
+          "foo.bar = [1.5, 2.5, 3.5]\n"
+          "foo.fee = 1.25\n\n");
 }
 
 
-- 
GitLab