diff --git a/Calorimeter/CaloRec/src/CaloClusterCorrDumper.cxx b/Calorimeter/CaloRec/src/CaloClusterCorrDumper.cxx index bad4ba0d079f5aa1f5264441153a80286122255b..3096077ca993d680531641f7d57d1feb00ed9752 100644 --- a/Calorimeter/CaloRec/src/CaloClusterCorrDumper.cxx +++ b/Calorimeter/CaloRec/src/CaloClusterCorrDumper.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 */ //----------------------------------------------------------------------- @@ -9,102 +9,24 @@ #include "CaloClusterCorrDumper.h" -//#include "GaudiKernel/ISvcLocator.h" -//#include "GaudiKernel/StatusCode.h" -#include "GaudiKernel/MsgStream.h" -//#include "GaudiKernel/IToolSvc.h" -#include "GaudiKernel/ListItem.h" +#include "StoreGate/ReadCondHandle.h" -//#include "CaloRec/ToolWithConstantsMixin.h" -#include "CaloConditions/ToolConstants.h" - -#include <fstream> - - -//############################################################################### -CaloClusterCorrDumper::CaloClusterCorrDumper(const std::string& name, - ISvcLocator* pSvcLocator) - : AthAlgorithm(name, pSvcLocator) -{ - // Name(s) of Cluster Correction Tools - declareProperty("ClusterCorrectionTools", m_correctionToolNames, - "List of Tools whose constants should be dumped"); - declareProperty("FileName",m_fileName="","Name of output text file"); -} - -//############################################################################### - -CaloClusterCorrDumper::~CaloClusterCorrDumper() -{ } - -//############################################################################### - - -StatusCode CaloClusterCorrDumper::execute() { - return StatusCode::SUCCESS; -} StatusCode CaloClusterCorrDumper::initialize() { - //Get ToolSvc - IToolSvc* p_toolSvc; - CHECK( service("ToolSvc", p_toolSvc) ); - - // 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 != 0 ) { - m_correctionTools.push_back(theTool); - } - } - } - REPORT_MESSAGE(MSG::INFO) /*<< m_key << ": "*/ - << "Found " << m_correctionTools.size() << - " tools."; - + ATH_CHECK( m_constants.initialize() ); return StatusCode::SUCCESS; } -StatusCode CaloClusterCorrDumper::finalize() { - std::ofstream file; - file.open(m_fileName.c_str(),std::ios::app); - if (!file.is_open()) { - ATH_MSG_FATAL( "Failed to open file named " << m_fileName ); - return StatusCode::FAILURE; - } - - - std::vector<CaloRec::ToolWithConstantsMixin*>::const_iterator it=m_correctionTools.begin(); - std::vector<CaloRec::ToolWithConstantsMixin*>::const_iterator it_e=m_correctionTools.end(); - for (;it!=it_e;++it) { - file << "Dump of constants:" << std::endl; - (*it)->writeConstants(file,"dumper"); +StatusCode CaloClusterCorrDumper::execute (const EventContext& ctx) const +{ + for (const SG::ReadCondHandleKey<CaloRec::ToolConstants>& k : m_constants) { + SG::ReadCondHandle<CaloRec::ToolConstants> constant (k, ctx); + ATH_MSG_INFO( constant->toString ("dumper") ); } - - - file.close(); return StatusCode::SUCCESS; } - diff --git a/Calorimeter/CaloRec/src/CaloClusterCorrDumper.h b/Calorimeter/CaloRec/src/CaloClusterCorrDumper.h index 07377b06a92ad84bed0eda111fc443b88cd19ba2..8895b7682a25e552dca2852de067ded24a0f3299 100644 --- a/Calorimeter/CaloRec/src/CaloClusterCorrDumper.h +++ b/Calorimeter/CaloRec/src/CaloClusterCorrDumper.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_CALOCLUSTERCORRDUMPER @@ -9,48 +9,31 @@ * @class CaloClusterCorrDumper * @author Walter Lampl <walter.lampl@cern.ch> * @date March, 28th 2006 + * Reworked Jun 2020 sss * - * This algorithm has only an @c initialize() and a @c finalize() method. - * It instantiates all ClusterCorrection Tools given by jobOptions. The - * cluster correction constants (@c ToolConstants) are expected to be - * initialized by job options. In the @c finalize method, this algorithm - * records these objects to the detector store so that they can be - * streamed out to a POOL file. + * Dump out a set of @c ToolConstants objects from the conditions store. */ - -#include "AthenaBaseComps/AthAlgorithm.h" -#include "CaloRec/ToolWithConstantsMixin.h" +#include "CaloConditions/ToolConstants.h" +#include "AthenaBaseComps/AthReentrantAlgorithm.h" +#include "StoreGate/CondHandleKeyArray.h" #include <vector> #include <string> -class CaloClusterCorrDumper : public AthAlgorithm -{ - - public: - - CaloClusterCorrDumper(const std::string& name, ISvcLocator* pSvcLocator); - virtual ~CaloClusterCorrDumper(); - virtual StatusCode initialize(); - virtual StatusCode execute(); - virtual StatusCode finalize(); - - private: - //std::string m_inlineFolder; - - /** @brief The list of tool names (jobOptions)*/ - std::vector<std::string> m_correctionToolNames; - - /** @brief the actual list of tools corresponding to above names */ - std::vector<CaloRec::ToolWithConstantsMixin*> m_correctionTools; +class CaloClusterCorrDumper : public AthReentrantAlgorithm +{ +public: + using AthReentrantAlgorithm::AthReentrantAlgorithm; + virtual StatusCode initialize() override; + virtual StatusCode execute (const EventContext& ctx) const override; - /** @brief Name of the text file where to store the constants - */ - std::string m_fileName; +private: + SG::ReadCondHandleKeyArray<CaloRec::ToolConstants> m_constants + { this, "Constants", {}, "List of constants to dump." }; }; #endif // CALOREC_CALOCLUSTERCORRDUMPER