From 0756baa3881c96d20618b681e50708a96e641e52 Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Tue, 22 Sep 2020 16:19:14 -0400 Subject: [PATCH] CaloRec: Update CaloClusterCorrDBWriter for ToolWithConstants. Update CaloClusterCorrDBWriter to use ToolWithConstants, rather than the obsolete ToolWithConstantsMixin. --- .../CaloRec/src/CaloClusterCorrDBWriter.cxx | 78 ++++--------------- .../CaloRec/src/CaloClusterCorrDBWriter.h | 36 ++++----- 2 files changed, 30 insertions(+), 84 deletions(-) diff --git a/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.cxx b/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.cxx index 28f5b2c4b1d..1ea957fb5ec 100644 --- a/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.cxx +++ b/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.cxx @@ -9,76 +9,23 @@ #include "CaloClusterCorrDBWriter.h" -#include "GaudiKernel/ISvcLocator.h" -#include "GaudiKernel/StatusCode.h" -#include "GaudiKernel/MsgStream.h" -#include "GaudiKernel/IToolSvc.h" -#include "GaudiKernel/ListItem.h" +#include "GaudiKernel/ThreadLocalContext.h" #include "CaloRec/ToolWithConstantsMixin.h" #include "CaloConditions/ToolConstants.h" #include "AthenaKernel/errorcheck.h" -//#include "ToolConstants2Blob.h" - using namespace CaloRec; -//############################################################################# -CaloClusterCorrDBWriter::CaloClusterCorrDBWriter(const std::string& name, - ISvcLocator* pSvcLocator) - : AthAlgorithm(name, pSvcLocator), - m_blobTool("Blob2ToolConstants") -{ - // Name(s) of Cluster Correction Tools - declareProperty("ClusterCorrectionTools", m_correctionToolNames); - declareProperty("key",m_key=""); - declareProperty("COOLInlineFolder",m_inlineFolder); -} - -//############################################################################# - -CaloClusterCorrDBWriter::~CaloClusterCorrDBWriter() -{ } - //############################################################################# StatusCode CaloClusterCorrDBWriter::initialize() { - //Get ToolSvc - IToolSvc* p_toolSvc; - CHECK( service("ToolSvc", p_toolSvc) ); - - CHECK( m_blobTool.retrieve()); - - - // allocate tools derived from ToolsWithConstants - std::vector<std::string>::const_iterator firstTool=m_correctionToolNames.begin(); - std::vector<std::string>::const_iterator lastTool =m_correctionToolNames.end(); - for ( ; firstTool != lastTool; ++firstTool ) { - IAlgTool* algToolPtr; - ListItem clusAlgoTool(*firstTool); - StatusCode scTool = p_toolSvc->retrieveTool(clusAlgoTool.type(), - clusAlgoTool.name(), - algToolPtr, - this); - if ( scTool.isFailure() ) { - REPORT_MESSAGE(MSG::ERROR) << "Cannot find tool for " << *firstTool; - } - else { - REPORT_MESSAGE(MSG::INFO) << m_key << ": " - << "Found tool for " << *firstTool; - - // check for tool type - CaloRec::ToolWithConstantsMixin* theTool = - dynamic_cast<CaloRec::ToolWithConstantsMixin*>(algToolPtr); - if ( theTool != nullptr ) { - m_correctionTools.push_back(theTool); - } - } - } + ATH_CHECK( m_blobTool.retrieve()); + ATH_CHECK( m_tools.retrieve()); REPORT_MESSAGE(MSG::INFO) << m_key << ": " - << "Found " << m_correctionTools.size() << + << "Found " << m_tools.size() << " tools."; return StatusCode::SUCCESS; } @@ -87,6 +34,7 @@ StatusCode CaloClusterCorrDBWriter::initialize() StatusCode CaloClusterCorrDBWriter::finalize() { + const EventContext& ctx = Gaudi::Hive::currentContext(); if (!m_inlineFolder.empty()) { CaloRec::ToolConstants tc; std::string toolnames; @@ -100,15 +48,15 @@ StatusCode CaloClusterCorrDBWriter::finalize() CHECK(detStore()->record(attrColl,m_inlineFolder)); } - for (size_t i = 0; i < m_correctionTools.size(); i++) { - CHECK( m_correctionTools[i]->mergeConstants (tc) ); - toolnames += m_correctionTools[i]->name() + " "; + for (size_t i = 0; i < m_tools.size(); i++) { + CHECK( m_tools[i]->mergeConstants (tc, ctx) ); + toolnames += m_tools[i]->name() + " "; } coral::AttributeList* attrList=m_blobTool->ToolConstantsToAttrList(&tc); if (!attrList) return StatusCode::FAILURE; - const std::string& tName=m_key;//m_correctionTools[i]->name(); + const std::string& tName=m_key; attrColl->add(coolChannelNbr,tName); attrColl->add(coolChannelNbr,*attrList); @@ -121,9 +69,9 @@ StatusCode CaloClusterCorrDBWriter::finalize() else { auto tc = std::make_unique<CaloRec::ToolConstants>(); std::string toolnames; - for (size_t i = 0; i < m_correctionTools.size(); i++) { - CHECK( m_correctionTools[i]->mergeConstants (*tc) ); - toolnames += m_correctionTools[i]->name() + " "; + for (size_t i = 0; i < m_tools.size(); i++) { + CHECK( m_tools[i]->mergeConstants (*tc, ctx) ); + toolnames += m_tools[i]->name() + " "; } CHECK( detStore()->record (std::move(tc), m_key) ); @@ -142,7 +90,7 @@ StatusCode CaloClusterCorrDBWriter::finalize() //############################################################################# -StatusCode CaloClusterCorrDBWriter::execute() +StatusCode CaloClusterCorrDBWriter::execute (const EventContext& /*ctx*/) const { return StatusCode::SUCCESS; } diff --git a/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.h b/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.h index 4955af8e4c5..319da945ca3 100644 --- a/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.h +++ b/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.h @@ -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 CALOREC_CALOCLUSTERCORRDBWRITER @@ -20,42 +20,40 @@ -#include "AthenaBaseComps/AthAlgorithm.h" +#include "AthenaBaseComps/AthReentrantAlgorithm.h" #include "GaudiKernel/ToolHandle.h" -#include "CaloRec/ToolWithConstantsMixin.h" +#include "CaloInterface/IToolWithConstants.h" #include "CaloRec/Blob2ToolConstants.h" #include <vector> #include <string> -class CaloClusterCorrDBWriter : public AthAlgorithm +class CaloClusterCorrDBWriter : public AthReentrantAlgorithm { public: + using AthReentrantAlgorithm::AthReentrantAlgorithm; - CaloClusterCorrDBWriter(const std::string& name, ISvcLocator* pSvcLocator); - virtual ~CaloClusterCorrDBWriter(); - virtual StatusCode initialize(); - virtual StatusCode execute(); - virtual StatusCode finalize(); + virtual StatusCode initialize() override; + virtual StatusCode execute(const EventContext& ctx) const override; + virtual StatusCode finalize() override; private: - - /** @brief The list of tool names (jobOptions)*/ - std::vector<std::string> m_correctionToolNames; + /** @brief The list of tools */ + ToolHandleArray<IToolWithConstants> m_tools + { this, "ClusterCorrectionTools", {}, "Cluster correction tools" }; /** @brief Key for the DetectorStore (jobOptions) * The ToolConstants will be recorded with this key. */ - std::string m_key; - - std::string m_inlineFolder; + StringProperty m_key + { this, "key", "" }; - /** @brief the actual list of tools corresponding to above names */ - std::vector<CaloRec::ToolWithConstantsMixin*> m_correctionTools; + StringProperty m_inlineFolder + { this, "COOLInlineFolder", "" }; - ToolHandle<Blob2ToolConstants> m_blobTool; - + ToolHandle<Blob2ToolConstants> m_blobTool + { this, "Blob2ToolConstants", "Blob2ToolConstants" }; }; #endif // CALOREC_CALOCLUSTERCORRDBWRITER -- GitLab