diff --git a/Calorimeter/CaloConditions/CaloConditions/ToolConstants.h b/Calorimeter/CaloConditions/CaloConditions/ToolConstants.h index 712bb87f6ce2bf14edf282d29606382aca6c3f45..f0bcd25b581e12a0b9ce30a06f308151c1ba662f 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 13854e5c0ccbd36926cc71655beda4efcb6b4618..8396f99ee5cf67246bd0b0042021d21d20a3fc12 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 e3e295c250b8af03f6693211e8a197b56f553d09..3cd43b73888ca22334fc13c0ebf49decaebea861 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"); }