From d62ab5d4d3f4cb153276375106db647b27de39b9 Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <fwinkl@cern>
Date: Wed, 9 Sep 2020 18:43:41 +0200
Subject: [PATCH] AthenaMonitoring: Migrate to IOptionsSvc

---
 .../AthenaMonitoring/src/AthenaMonManager.cxx | 26 +++++------------
 .../src/ManagedMonitorToolBase.cxx            | 29 ++++++++++---------
 2 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/Control/AthenaMonitoring/src/AthenaMonManager.cxx b/Control/AthenaMonitoring/src/AthenaMonManager.cxx
index 9e50504f57ee..8306a6575dc0 100644
--- a/Control/AthenaMonitoring/src/AthenaMonManager.cxx
+++ b/Control/AthenaMonitoring/src/AthenaMonManager.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "AthenaMonitoring/AthenaMonManager.h"
@@ -16,8 +16,8 @@
 #include "LWHistAthMonWrapper.h"
 #include "AthMonBench.h"
 
+#include "Gaudi/Interfaces/IOptionsSvc.h"
 #include "GaudiKernel/IMessageSvc.h"
-#include "GaudiKernel/IJobOptionsSvc.h"
 #include "GaudiKernel/ISvcLocator.h"
 #include "GaudiKernel/ITHistSvc.h"
 #include "GaudiKernel/MsgStream.h"
@@ -472,25 +472,15 @@ initialize()
     m_d->m_environmentProp = Imp::s_environmentStr;
 
     // Provide a virtual Algorithm with a subset of the properties
-    IJobOptionsSvc* joSvc = 0;
-    sc = service( "JobOptionsSvc", joSvc );
-    if( !sc.isSuccess() ) {
-        msg(MSG::ERROR) << "!! Unable to locate the JobOptionsSvc service !!" << endmsg;
-        return sc;
-    }
+    ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc", name());
+    ATH_CHECK( joSvc.retrieve() );
     ATH_MSG_DEBUG("  --> Found service \"JobOptionsSvc\"");
 
-    std::string client = name() + std::string("Properties");
+    const std::string client = name() + std::string("Properties");
     ATH_MSG_DEBUG("  --> Adding properties under name \"" << client << "\"");
-    StatusCode sc1 = joSvc->addPropertyToCatalogue( client, StringProperty("FileKey",m_d->m_fileKeyProp) );
-    StatusCode sc2 = joSvc->addPropertyToCatalogue( client, StringProperty("DataType",m_d->m_dataTypeProp) );
-    StatusCode sc3 = joSvc->addPropertyToCatalogue( client, StringProperty("Environment",m_d->m_environmentProp) );
-    joSvc->release();
-    if( !(sc1.isSuccess() && sc2.isSuccess() && sc3.isSuccess()) ) {
-        msg(MSG::ERROR) << "!! Unable to add properties to JobOptionsSvc service !!" << endmsg;
-        return StatusCode::FAILURE;
-    }
-    ATH_MSG_DEBUG("  --> Added Properties");
+    joSvc->set( client + ".FileKey", m_d->m_fileKeyProp );
+    joSvc->set( client + ".DataType", m_d->m_dataTypeProp );
+    joSvc->set( client + ".Environment", m_d->m_environmentProp );
 
     //Determine (globally for now), whether or not LW histograms use a
     //ROOT backend (necessary for online monitoring, and perhaps for
diff --git a/Control/AthenaMonitoring/src/ManagedMonitorToolBase.cxx b/Control/AthenaMonitoring/src/ManagedMonitorToolBase.cxx
index c3ce13f77ed8..10e3b70046ea 100644
--- a/Control/AthenaMonitoring/src/ManagedMonitorToolBase.cxx
+++ b/Control/AthenaMonitoring/src/ManagedMonitorToolBase.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef ManagedMonitorToolBase_CXX
@@ -24,8 +24,8 @@
 #include "AthMonBench.h"
 #include "StoreGate/ReadCondHandle.h"
 
+#include "Gaudi/Interfaces/IOptionsSvc.h"
 #include "GaudiKernel/IHistogramSvc.h"
-#include "GaudiKernel/IJobOptionsSvc.h"
 #include "GaudiKernel/IMessageSvc.h"
 #include "GaudiKernel/ISvcLocator.h"
 #include "GaudiKernel/MsgStream.h"
@@ -745,21 +745,22 @@ initialize()
      return sc;
    }
 
-   ServiceHandle<IJobOptionsSvc> joSvc( "JobOptionsSvc", name() );
-   sc = joSvc.retrieve();
-   if( !sc.isSuccess() ) {
-      msg(MSG::ERROR) << "!! Unable to locate the JobOptionsSvc service !!" << endmsg;
-      return StatusCode::FAILURE;
-   }
+   ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc( "JobOptionsSvc", name() );
+   ATH_CHECK( joSvc.retrieve() );
    ATH_MSG_DEBUG("  --> Found service \"JobOptionsSvc\"");
 
-   std::string client( m_managerNameProp + "Properties" );
+   const std::string client( m_managerNameProp + "Properties" );
    ATH_MSG_DEBUG("  --> Asking for properties " << client);
-   sc = joSvc->setMyProperties( client, this );
-   if( !sc.isSuccess() ) {
-      msg(MSG::ERROR) << "!! Unable to set properties in JobOptionsSvc !!" << endmsg;
-   }
-   ATH_MSG_DEBUG("  --> Set Properties in \"JobOptionsSvc\"");
+
+   auto getProp = [this,joSvc](std::string& var, const std::string& name) {
+     if (joSvc->has(name))
+       var = joSvc->get(name);
+     else
+       ATH_MSG_ERROR("Cannot read " << name);
+   };
+   getProp( m_fileKey, client + ".FileKey");
+   getProp( m_dataTypeStr, client + ".DataType");
+   getProp( m_environmentStr, client + ".Environment");
 
    ATH_MSG_DEBUG("      * Properties set from " << client << " to the values:\n"
 		 << "        FileKey: " << m_fileKey << "\n"
-- 
GitLab