diff --git a/LArCalorimeter/LArCalibUtils/src/LArConditionsMergerAlg.h b/LArCalorimeter/LArCalibUtils/src/LArConditionsMergerAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..360d9cd4703059d2b93d78ef117beb57562a595f --- /dev/null +++ b/LArCalorimeter/LArCalibUtils/src/LArConditionsMergerAlg.h @@ -0,0 +1,38 @@ +//Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef LARCALIBUTILS_LARCONDITIONSMERGERALG +#define LARCALIBUTILS_LARCONDITIONSMERGERALG + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/CondHandleKeyArray.h" +#include "StoreGate/WriteCondHandleKey.h" + +#include "LArRawConditions/LArConditionsContainer.h" + +template<class T> +class LArConditionsMergerAlg: public AthAlgorithm { + public: + using AthAlgorithm::AthAlgorithm; + ~LArConditionsMergerAlg() = default; + + virtual StatusCode initialize() override; + virtual StatusCode execute() override; + + SG::ReadCondHandleKeyArray<T> m_readKeys{this, "ReadKeys",{},"Input keys" }; + Gaudi::Property<std::string> m_writeKey{this,"WriteKey","output","Output key" }; + + Gaudi::Property<std::string> m_groupingType{this,"GroupingType","","Cool-channel grouping"}; + +}; + +#include "LArConditionsMergerAlg.icc" + +#include "LArRawConditions/LArPedestalComplete.h" +typedef LArConditionsMergerAlg<LArPedestalComplete> LArPedestalMerger; + + +#endif diff --git a/LArCalorimeter/LArCalibUtils/src/LArConditionsMergerAlg.icc b/LArCalorimeter/LArCalibUtils/src/LArConditionsMergerAlg.icc new file mode 100644 index 0000000000000000000000000000000000000000..f5abc966f3f9c24eb977ed6d9873ce6e05a10692 --- /dev/null +++ b/LArCalorimeter/LArCalibUtils/src/LArConditionsMergerAlg.icc @@ -0,0 +1,36 @@ +//Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +template<class T> +StatusCode LArConditionsMergerAlg<T>::initialize() { + + ATH_CHECK(m_readKeys.initialize()); + + return StatusCode::SUCCESS; +} + + +template<class T> +StatusCode LArConditionsMergerAlg<T>::execute() { + + if (m_readKeys.empty()) return StatusCode::FAILURE; + std::unique_ptr<T> out=std::make_unique<T>(); + ATH_CHECK(out->setGroupingType(m_groupingType,msg())); + ATH_CHECK(out->initialize()); + + for (auto& key : m_readKeys) { + SG::ReadCondHandle<T> handle{key}; + const T* obj=*handle; + bool stat=out->merge(*obj); + if (stat) { + ATH_MSG_ERROR("Channels where overwritten while merging " << key); + } + } + + ATH_CHECK(detStore()->record(std::move(out),m_writeKey)); + + return StatusCode::SUCCESS; +} diff --git a/LArCalorimeter/LArCalibUtils/src/components/LArCalibUtils_entries.cxx b/LArCalorimeter/LArCalibUtils/src/components/LArCalibUtils_entries.cxx index 3868d9f2621f71d0f85bf4c2c7b8ff8271ed3d48..619298bee475cc2dba1d98eb0f690d4d50c1f7c6 100644 --- a/LArCalorimeter/LArCalibUtils/src/components/LArCalibUtils_entries.cxx +++ b/LArCalorimeter/LArCalibUtils/src/components/LArCalibUtils_entries.cxx @@ -48,7 +48,7 @@ #include "LArCalibUtils/LArDuplicateConstants.h" #include "LArCalibUtils/LArCalibPatchingAlg.h" #include "LArCalibUtils/LArCalibCopyAlg.h" - +#include "../LArConditionsMergerAlg.h" typedef LArCalibPatchingAlg<LArRampComplete> LArRampPatcher; @@ -116,3 +116,4 @@ DECLARE_COMPONENT( LArPhaseToolConst ) DECLARE_COMPONENT( LArPhaseToolMC ) DECLARE_COMPONENT( LArPhaseToolTB ) +DECLARE_COMPONENT( LArPedestalMerger ) diff --git a/LArCalorimeter/LArRawConditions/LArRawConditions/LArConditionsContainer.h b/LArCalorimeter/LArRawConditions/LArRawConditions/LArConditionsContainer.h index b33c7f5d81fca7a9989efd4ba87011e97718532c..2ad5daa226bd1d0f5f9568cac83227c9ea9239f2 100755 --- a/LArCalorimeter/LArRawConditions/LArRawConditions/LArConditionsContainer.h +++ b/LArCalorimeter/LArRawConditions/LArRawConditions/LArConditionsContainer.h @@ -271,6 +271,9 @@ public: /// Initialization done after creation or read back - derived /// classes may augment the functionality virtual StatusCode initialize(); + + //Merge in data from another conditions container of the same type + bool merge(const LArConditionsContainer<T>& other); protected: diff --git a/LArCalorimeter/LArRawConditions/LArRawConditions/LArConditionsContainer.icc b/LArCalorimeter/LArRawConditions/LArRawConditions/LArConditionsContainer.icc index 759e4c6f93528f517ce99248dcae6db25cbbb784..1199d5a250b352bc5dc109c7da0ea009dd75d005 100755 --- a/LArCalorimeter/LArRawConditions/LArRawConditions/LArConditionsContainer.icc +++ b/LArCalorimeter/LArRawConditions/LArRawConditions/LArConditionsContainer.icc @@ -1204,3 +1204,25 @@ LArConditionsContainer<T>::initialize() +template<class T> +bool LArConditionsContainer<T>::merge(const LArConditionsContainer<T>& other) { + unsigned nOverwrites=0; + //Loop over gains + for (unsigned gain=0;gain<other.nGains();++gain) { + auto it=other.begin(gain); + auto it_e=other.end(gain); + //Loop over channels + for (;it!=it_e;++it) { + const HWIdentifier hwid=it.channelId(); + const T& payload=*it; + if (!payload.isEmpty()) { + const T& currentPayload=this->get(hwid,gain); + if (!currentPayload.isEmpty()) { + ++nOverwrites; + } + this->setPdata(hwid,payload,gain); + } + }//end loop over channels + }//end loop over gains + return (nOverwrites!=0); +}