From f7e5a7f056775a75aaf3ae17ec192ccb28fb1fae Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <fwinkl@cern>
Date: Mon, 14 Sep 2020 19:10:12 +0200
Subject: [PATCH] AthAnalysisBaseComps: Migrate to IOptionsSvc

Migrate `AthAnalysisHelper` to `IOptionsSvc`. Probably code should be
cleaned up further to better match the new interface...
---
 .../AthAnalysisBaseComps/AthAnalysisHelper.h  | 13 ++++----
 .../src/AthAnalysisHelper.cxx                 | 30 +++++--------------
 2 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h b/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h
index 18ee0c47274d..51707fde53be 100644
--- a/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h
+++ b/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h
@@ -1,7 +1,7 @@
 ///////////////////////// -*- C++ -*- /////////////////////////////
 
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 // AthAnalysisHelper.h 
@@ -16,7 +16,7 @@
 #include "StoreGate/StoreGateSvc.h"
 #include "GaudiKernel/ServiceHandle.h"
 
-#include "GaudiKernel/IJobOptionsSvc.h"
+#include "Gaudi/Interfaces/IOptionsSvc.h"
 #include "GaudiKernel/IToolSvc.h"
 
 #include "IOVDbDataModel/IOVMetaDataContainer.h"
@@ -45,7 +45,7 @@ public:
    ///helper method for adding a property to the JobOptionsSvc
    ///to list all the properties in the catalogue, do: AthAnalysisHelper::dumpJobOptionProperties()
    template<typename W> static StatusCode addPropertyToCatalogue( const std::string& name , const std::string& property, const W& value, bool override=true) {
-     ServiceHandle<IJobOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
+     ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
      if(joSvc.retrieve().isFailure()) return StatusCode::FAILURE;
      if(!override) {
       //check if property already defined. If so, then print a warning and return failure
@@ -55,9 +55,8 @@ public:
         return StatusCode::FAILURE;
       }
      }
-     StatusCode result = joSvc->addPropertyToCatalogue( name , StringProperty( property , Gaudi::Utils::toString ( value ) ) );
-     if(joSvc.release().isFailure()) return StatusCode::FAILURE;
-     return result;
+     joSvc->set( name+"."+property , Gaudi::Utils::toString ( value ) );
+     return StatusCode::SUCCESS;
    }
    
 
@@ -367,7 +366,7 @@ public:
 
    ///we keep a static handle to the joboptionsvc, since it's very useful
    ///can e.g. do: AAH::joSvc->readOptions("myJob.opts","$JOBOPTSEARCHPATH")
-   static ServiceHandle<IJobOptionsSvc> joSvc; 
+   static ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc;
 
 
 }; //AthAnalysisHelper class
diff --git a/Control/AthAnalysisBaseComps/src/AthAnalysisHelper.cxx b/Control/AthAnalysisBaseComps/src/AthAnalysisHelper.cxx
index 295ec0ace295..4d27d5f130b5 100644
--- a/Control/AthAnalysisBaseComps/src/AthAnalysisHelper.cxx
+++ b/Control/AthAnalysisBaseComps/src/AthAnalysisHelper.cxx
@@ -8,7 +8,7 @@
 
 const std::string AthAnalysisHelper::UNDEFINED = "__UNDEFINED__";
 
-ServiceHandle<IJobOptionsSvc> AthAnalysisHelper::joSvc = ServiceHandle<IJobOptionsSvc>("JobOptionsSvc","AthAnalysisHelper");
+ServiceHandle<Gaudi::Interfaces::IOptionsSvc> AthAnalysisHelper::joSvc = ServiceHandle<Gaudi::Interfaces::IOptionsSvc>("JobOptionsSvc","AthAnalysisHelper");
 
 //need a constructor, implemented here, so that the dictionary library is linked to 
 //the implementation library (see ldd libAthAnalysisBaseCompsDict.so ... needs a link)
@@ -49,32 +49,18 @@ bool AthAnalysisHelper::toolExists( const std::string& fullName ) {
 }
 
 void AthAnalysisHelper::dumpJobOptionProperties(const std::string& client) {
-   ServiceHandle<IJobOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
+   ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
    if(joSvc.retrieve().isFailure()) return;
-   std::vector<std::string> clients = joSvc->getClients();
-   for(auto& cl : clients) {
-      if(cl.find(client)!=0) continue; //must start with client
-      auto props = joSvc->getProperties(cl);
-      if(!props) continue;
-      for(auto prop : *props) {
-         std::cout << cl << "." << prop->name() << " = " << prop->toString() << std::endl;
-      }
+   for(const auto& [name,value] : joSvc->items()) {
+     if(name.find(client)!=0) continue; //must start with client
+     std::cout << name << " = " << value << std::endl;
    }
-   joSvc.release().ignore();
 }
 
 std::string AthAnalysisHelper::getProperty(const std::string& client, const std::string& property) {
-   std::string out(UNDEFINED);
-   ServiceHandle<IJobOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
-   if(joSvc.retrieve().isFailure()) return out;
-   auto props = joSvc->getProperties(client);
-   if(!props) { joSvc.release().ignore(); return out; }
-   for(auto prop : *props) {
-     if(prop->name()!=property) continue;
-     out = prop->toString(); break;
-   }
-   joSvc.release().ignore();
-   return out;
+   ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
+   if(joSvc.retrieve().isFailure()) return UNDEFINED;
+   return joSvc->get(client+"."+property, UNDEFINED);
 }
 
 void AthAnalysisHelper::printAuxElement(const SG::AuxElement& ae) {
-- 
GitLab