diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/ATLAS_CHECK_THREAD_SAFETY b/LArCalorimeter/LArGeoModel/LArHV/LArHV/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 0000000000000000000000000000000000000000..3398454a4ea0c5a19258a20e0c0fec3996412cd4 --- /dev/null +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +LArCalorimeter/LArGeoModel/LArHV diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBHVElectrode.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBHVElectrode.h index a19b2ad1dd07f62a1923d0bb87504ec695677849..5d12fb57eca9ef591cf7e82f8b2f5c9c25712c1e 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBHVElectrode.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBHVElectrode.h @@ -26,21 +26,10 @@ class EMBHVElectrode double getPhi() const; - // HV Status - bool hvOn(int iGap) const; - - double voltage(int iGap) const; - double current(int iGap) const; - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) - int hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping=nullptr) const; -#else - int hvLineNo(int iGap) const; + int hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping) const; #endif - // Voltage and current at the same tine.: - void voltage_current(int iGap, double& v, double& i) const; - private: EMBHVElectrode(const EMBHVElectrode& right); EMBHVElectrode& operator=(const EMBHVElectrode& right); diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBHVManager.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBHVManager.h index 7518b08f24ad167092ec25af494d8b413af49eee..9331e9291ca8c01009b85537e2c6aedf088b6b9b 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBHVManager.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBHVManager.h @@ -7,9 +7,14 @@ #include "LArHV/EMBHVModule.h" #include "LArHV/EMBHVDescriptor.h" +#include "Identifier/HWIdentifier.h" +#include "CxxUtils/checker_macros.h" +#include <memory> +#include <functional> #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) class LArHVIdMapping; +class CondAttrListCollection; #endif struct EMBHVPayload; @@ -31,6 +36,22 @@ struct EMBHVPayload; class EMBHVManager { public: + class EMBHVData + { + public: + class Payload; + EMBHVData(); + EMBHVData (std::unique_ptr<Payload> payload); + EMBHVData& operator= (EMBHVData&& other); + ~EMBHVData(); + double voltage (const EMBHVElectrode& electrode, const int& iGap) const; + double current (const EMBHVElectrode& electrode, const int& iGap) const; + int hvLineNo (const EMBHVElectrode& electrode, const int& iGap) const; + private: + int index (const EMBHVElectrode& electrode) const; + std::unique_ptr<Payload> m_payload; + }; + EMBHVManager(); ~EMBHVManager(); @@ -56,16 +77,12 @@ class EMBHVManager unsigned int beginSideIndex() const; unsigned int endSideIndex() const; - // Refresh from the database if needed - void update() const; - - // Make the data stale. Force update of data. - void reset() const; - // Get the database payload - EMBHVPayload *getPayload(const EMBHVElectrode &) const; + EMBHVData getData ATLAS_NOT_THREAD_SAFE () const; #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) + EMBHVData getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const; // Get hvLine for an electrode int hvLineNo(const EMBHVElectrode& electrode , int gap @@ -73,12 +90,16 @@ class EMBHVManager #endif private: - EMBHVManager(const EMBHVManager& right); - EMBHVManager& operator=(const EMBHVManager& right); + using idfunc_t = std::function<std::vector<HWIdentifier>(HWIdentifier)>; + EMBHVData getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const; + + EMBHVManager(const EMBHVManager& right) = delete; + EMBHVManager& operator=(const EMBHVManager& right) = delete; friend class ImaginaryFriend; class Clockwork; - Clockwork *m_c; + std::unique_ptr<const Clockwork> m_c; }; #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBPresamplerHVManager.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBPresamplerHVManager.h index bc8fbbd9443e5e6ed21f15e2b4d06a70d46af48c..81d66d2a2993e56a010f4f136e869f8abe06c571 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBPresamplerHVManager.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBPresamplerHVManager.h @@ -6,12 +6,18 @@ #define LARHV_EMBPRESAMPLERHVMANAGER_H #include "LArHV/EMBPresamplerHVModule.h" +#include "Identifier/HWIdentifier.h" +#include "CxxUtils/checker_macros.h" +#include <memory> +#include <functional> #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) class LArHVIdMapping; +class CondAttrListCollection; #endif class EMBPresamplerHVDescriptor; +class EMBPresamplerHVModule; struct EMBPresamplerHVPayload; /** @@ -31,6 +37,22 @@ struct EMBPresamplerHVPayload; class EMBPresamplerHVManager { public: + class EMBPresamplerHVData + { + public: + class Payload; + EMBPresamplerHVData(); + EMBPresamplerHVData (std::unique_ptr<Payload> payload); + EMBPresamplerHVData& operator= (EMBPresamplerHVData&& other); + ~EMBPresamplerHVData(); + double voltage (const EMBPresamplerHVModule& module, const int& iGap) const; + double current (const EMBPresamplerHVModule& module, const int& iGap) const; + int hvLineNo (const EMBPresamplerHVModule& module, const int& iGap) const; + private: + int index (const EMBPresamplerHVModule& module) const; + std::unique_ptr<Payload> m_payload; + }; + EMBPresamplerHVManager(); ~EMBPresamplerHVManager(); @@ -51,16 +73,12 @@ class EMBPresamplerHVManager unsigned int beginSideIndex() const; unsigned int endSideIndex() const; - // Refresh from the database if needed - void update() const; - - // Make the data stale. Force update of data. - void reset() const; - // Get the database payload - EMBPresamplerHVPayload *getPayload(const EMBPresamplerHVModule &) const; + EMBPresamplerHVData getData ATLAS_NOT_THREAD_SAFE () const; #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) + EMBPresamplerHVData getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const; // Get hvLine for a module int hvLineNo(const EMBPresamplerHVModule& module , int gap @@ -68,13 +86,17 @@ class EMBPresamplerHVManager #endif private: + using idfunc_t = std::function<std::vector<HWIdentifier>(HWIdentifier)>; + EMBPresamplerHVData getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const; + // Illegal operations - EMBPresamplerHVManager(const EMBPresamplerHVManager& right); - EMBPresamplerHVManager& operator=(const EMBPresamplerHVManager& right); + EMBPresamplerHVManager(const EMBPresamplerHVManager& right) = delete; + EMBPresamplerHVManager& operator=(const EMBPresamplerHVManager& right) = delete; friend class ImaginaryFriend; class Clockwork; - Clockwork *m_c; + std::unique_ptr<const Clockwork> m_c; }; #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBPresamplerHVModule.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBPresamplerHVModule.h index 56a8bf4fa37fa1ace335a0ee1e91b9cbd0b38242..00f8dd48ee674e8ac69cd844467897c3d0980b07 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBPresamplerHVModule.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMBPresamplerHVModule.h @@ -38,19 +38,8 @@ class EMBPresamplerHVModule double getPhiMin() const; double getPhiMax() const; - // HV Status - bool hvOn(int iGap) const; - - double voltage(int iGap) const; - double current(int iGap) const; - - // Voltage and current at the same time... - void voltage_current(int iGap, double& v, double& i) const; - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) - int hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping=nullptr) const; -#else - int hvLineNo(int iGap) const; + int hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping) const; #endif const EMBPresamplerHVManager& getManager() const; diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECHVElectrode.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECHVElectrode.h index 2bb5a64b479397ff0b38ba6485f86a742909aa1a..87beae4bde87259e4d9b89c0a18744952a05f446 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECHVElectrode.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECHVElectrode.h @@ -25,23 +25,9 @@ class EMECHVElectrode double getPhi() const; - // HV Status - bool hvOn(int iGap) const; - - // Voltage - double voltage(int iGap) const; - - // Current - double current(int iGap) const; - - // Voltage and current at the same time - void voltage_current(int iGap, double& v, double& i) const; - // HVLine no #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) - int hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping=nullptr) const; -#else - int hvLineNo(int iGap) const; + int hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping) const; #endif private: diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECHVManager.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECHVManager.h index 5316fb7a540cb28969f97b983956e73e9ff6b3af..12cb4f404f7294c18209defa746ba32a8d05802d 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECHVManager.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECHVManager.h @@ -7,9 +7,14 @@ #include "LArHV/EMECHVModule.h" #include "LArHV/EMECHVDescriptor.h" +#include "Identifier/HWIdentifier.h" +#include "CxxUtils/checker_macros.h" +#include <memory> +#include <functional> #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) class LArHVIdMapping; +class CondAttrListCollection; #endif struct EMECHVPayload; @@ -33,6 +38,22 @@ class EMECHVManager public: typedef EMECHVModule::IOType IOType; + class EMECHVData + { + public: + class Payload; + EMECHVData(); + EMECHVData (std::unique_ptr<Payload> payload); + EMECHVData& operator= (EMECHVData&& other); + ~EMECHVData(); + double voltage (const EMECHVElectrode& electrode, const int& iGap) const; + double current (const EMECHVElectrode& electrode, const int& iGap) const; + int hvLineNo (const EMECHVElectrode& electrode, const int& iGap) const; + private: + int index (const EMECHVElectrode& electrode) const; + std::unique_ptr<Payload> m_payload; + }; + EMECHVManager(IOType wheel); ~EMECHVManager(); @@ -59,16 +80,12 @@ class EMECHVManager // Gets the Wheel, 0 for the Outer Wheel HV Manager and 1 for the inner Wheel HV Manager EMECHVManager::IOType getWheelIndex() const; - // Refresh from the database if needed - void update() const; - - // Make the data stale. Force update of data. - void reset() const; - // Get the database payload - EMECHVPayload *getPayload(const EMECHVElectrode &) const; + EMECHVData getData ATLAS_NOT_THREAD_SAFE () const; #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) + EMECHVData getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const; // Get hvLine for an electrode int hvLineNo(const EMECHVElectrode& electrode , int gap @@ -76,11 +93,15 @@ class EMECHVManager #endif private: - EMECHVManager& operator=(const EMECHVManager& right); - EMECHVManager(const EMECHVManager& right); + using idfunc_t = std::function<std::vector<HWIdentifier>(HWIdentifier)>; + EMECHVData getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const; + + EMECHVManager& operator=(const EMECHVManager& right) = delete; + EMECHVManager(const EMECHVManager& right) = delete; class Clockwork; - Clockwork *m_c; + std::unique_ptr<const Clockwork> m_c; }; #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECPresamplerHVManager.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECPresamplerHVManager.h index fa10b0b66398fdabcf1a5cb4d06d6d2f95a7a16d..023a94d2ffe17da52af61cbce4003bafbe0f148a 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECPresamplerHVManager.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECPresamplerHVManager.h @@ -6,9 +6,14 @@ #define LARHV_EMECPRESAMPLERHVMANAGER_H #include "LArHV/EMECPresamplerHVModule.h" +#include "Identifier/HWIdentifier.h" +#include "CxxUtils/checker_macros.h" +#include <memory> +#include <functional> #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) class LArHVIdMapping; +class CondAttrListCollection; #endif struct EMECPresamplerHVPayload; @@ -31,6 +36,22 @@ class CellBinning; class EMECPresamplerHVManager { public: + class EMECPresamplerHVData + { + public: + class Payload; + EMECPresamplerHVData(); + EMECPresamplerHVData (std::unique_ptr<Payload> payload); + EMECPresamplerHVData& operator= (EMECPresamplerHVData&& other); + ~EMECPresamplerHVData(); + double voltage (const EMECPresamplerHVModule& module, const int& iGap) const; + double current (const EMECPresamplerHVModule& module, const int& iGap) const; + int hvLineNo (const EMECPresamplerHVModule& module, const int& iGap) const; + private: + int index (const EMECPresamplerHVModule& module) const; + std::unique_ptr<Payload> m_payload; + }; + EMECPresamplerHVManager(); ~EMECPresamplerHVManager(); @@ -46,28 +67,28 @@ class EMECPresamplerHVManager // Get a link to the HV module: const EMECPresamplerHVModule& getHVModule(unsigned int iSide, unsigned int iPhi) const; - // Refresh from the database if needed - void update() const; - - // Make the data stale. Force update of data. - void reset() const; - // Get the database payload - EMECPresamplerHVPayload *getPayload(const EMECPresamplerHVModule &) const; + EMECPresamplerHVData getData ATLAS_NOT_THREAD_SAFE () const; #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) + EMECPresamplerHVData getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const; // Get hvLine for a module int hvLineNo(const EMECPresamplerHVModule& module , const LArHVIdMapping* hvIdMapping) const; #endif private: + using idfunc_t = std::function<std::vector<HWIdentifier>(HWIdentifier)>; + EMECPresamplerHVData getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const; + // Illegal operations - EMECPresamplerHVManager& operator=(const EMECPresamplerHVManager& right); - EMECPresamplerHVManager(const EMECPresamplerHVManager& right); + EMECPresamplerHVManager& operator=(const EMECPresamplerHVManager& right) = delete; + EMECPresamplerHVManager(const EMECPresamplerHVManager& right) = delete; class Clockwork; - Clockwork *m_c; + std::unique_ptr<const Clockwork> m_c; }; diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECPresamplerHVModule.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECPresamplerHVModule.h index 624a9a1d4fc639fabe0cdc730fc63848f753bfa8..f3e6b02ca818c54cf5199b3af5f70ef0998ed926 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECPresamplerHVModule.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/EMECPresamplerHVModule.h @@ -37,19 +37,8 @@ class EMECPresamplerHVModule // Side Index (0=Negative, 1=Positive) unsigned int getSideIndex() const; - // HV Status - bool hvOn(int iGap) const; - - double voltage(int iGap) const; - double current(int iGap) const; - - // Current and voltage at the same time: - void voltage_current(int iGap, double& v, double& i) const; - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) - int hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping=nullptr) const; -#else - int hvLineNo(int iGap) const; + int hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping) const; #endif const EMECPresamplerHVManager& getManager() const; diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/FCALHVLine.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/FCALHVLine.h index 711b93630575ef951c262875a4e0a09b61666572..498a7bed56cfa3bcff1ec707a763ba76c269e6cd 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/FCALHVLine.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/FCALHVLine.h @@ -22,17 +22,8 @@ class FCALHVLine unsigned int getLineIndex() const; - bool hvOn() const; - double voltage() const; - double current() const; - - // Voltage and current at the same time: - void voltage_current(double& v, double& i) const; - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) - int hvLineNo(const LArHVIdMapping* hvIdMapping=nullptr) const; -#else - int hvLineNo() const; + int hvLineNo(const LArHVIdMapping* hvIdMapping) const; #endif private: diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/FCALHVManager.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/FCALHVManager.h index 632472942233d76066410bc77a166e62dca28fb4..753948c55f7c79de0673ad8e7b8278547882f037 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/FCALHVManager.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/FCALHVManager.h @@ -6,9 +6,14 @@ #define LARHV_FCALHVMANAGER_H #include "LArHV/FCALHVModule.h" +#include "Identifier/HWIdentifier.h" +#include "CxxUtils/checker_macros.h" +#include <memory> +#include <functional> #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) class LArHVIdMapping; +class CondAttrListCollection; #endif struct FCALHVPayload; @@ -30,6 +35,22 @@ struct FCALHVPayload; class FCALHVManager { public: + class FCALHVData + { + public: + class Payload; + FCALHVData(); + FCALHVData (std::unique_ptr<Payload> payload); + FCALHVData& operator= (FCALHVData&& other); + ~FCALHVData(); + double voltage (const FCALHVLine& line) const; + double current (const FCALHVLine& line) const; + int hvLineNo (const FCALHVLine& line) const; + private: + int index (const FCALHVLine& line) const; + std::unique_ptr<Payload> m_payload; + }; + FCALHVManager(); ~FCALHVManager(); @@ -47,27 +68,27 @@ class FCALHVManager , unsigned int iSector , unsigned int iSampling) const; - // Refresh from the database if needed - void update() const; - - // Make the data stale. Force update of data. - void reset() const; - // Get the database payload - FCALHVPayload *getPayload(const FCALHVLine &) const; + FCALHVData getData ATLAS_NOT_THREAD_SAFE () const; #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) - // Get hvLine for a subgap + FCALHVData getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const; + // Get hvLine for an electrode int hvLineNo(const FCALHVLine& line , const LArHVIdMapping* hvIdMapping) const; #endif private: - FCALHVManager(const FCALHVManager& right); - FCALHVManager& operator=(const FCALHVManager& right); + using idfunc_t = std::function<std::vector<HWIdentifier>(HWIdentifier)>; + FCALHVData getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const; + + FCALHVManager(const FCALHVManager& right) = delete; + FCALHVManager& operator=(const FCALHVManager& right) = delete; class Clockwork; - Clockwork *m_c; + std::unique_ptr<const Clockwork> m_c; }; #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/HECHVManager.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/HECHVManager.h index a91a94a1016befeee217b137c17390d91a7732dd..97b14c1ac6c66cf4ac52496d224e4e49388f2206 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/HECHVManager.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/HECHVManager.h @@ -7,9 +7,14 @@ #include "LArHV/HECHVDescriptor.h" #include "LArHV/HECHVModule.h" +#include "Identifier/HWIdentifier.h" +#include "CxxUtils/checker_macros.h" +#include <memory> +#include <functional> #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) class LArHVIdMapping; +class CondAttrListCollection; #endif struct HECHVPayload; @@ -31,6 +36,22 @@ struct HECHVPayload; class HECHVManager { public: + class HECHVData + { + public: + class Payload; + HECHVData(); + HECHVData (std::unique_ptr<Payload> payload); + HECHVData& operator= (HECHVData&& other); + ~HECHVData(); + double voltage (const HECHVSubgap& subgap) const; + double current (const HECHVSubgap& subgap) const; + int hvLineNo (const HECHVSubgap& subgap) const; + private: + int index (const HECHVSubgap& subgap) const; + std::unique_ptr<Payload> m_payload; + }; + HECHVManager(); ~HECHVManager(); @@ -50,27 +71,27 @@ class HECHVManager , unsigned int iPhi , unsigned int iSampling) const; - // Refresh from the database if needed - void update() const; - - // Make the data stale. Force update of data. - void reset() const; - // Get the database payload - HECHVPayload *getPayload(const HECHVSubgap &) const; + HECHVData getData ATLAS_NOT_THREAD_SAFE () const; #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) + HECHVData getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const; // Get hvLine for a subgap int hvLineNo(const HECHVSubgap& subgap , const LArHVIdMapping* hvIdMapping) const; #endif private: - HECHVManager(const HECHVManager& right); - HECHVManager& operator=(const HECHVManager& right); + using idfunc_t = std::function<std::vector<HWIdentifier>(HWIdentifier)>; + HECHVData getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const; + + HECHVManager(const HECHVManager& right) = delete; + HECHVManager& operator=(const HECHVManager& right) = delete; class Clockwork; - Clockwork *m_c; + std::unique_ptr<const Clockwork> m_c; }; #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/HECHVSubgap.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/HECHVSubgap.h index 20385fae6354c025a7875921b4a1351951f915f7..19ccaef7e76438ef844a54292635fcf36b37d994 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/HECHVSubgap.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/HECHVSubgap.h @@ -23,19 +23,10 @@ class HECHVSubgap // Returns the index of this electrode. unsigned int getSubgapIndex() const; - bool hvOn() const; - double voltage() const; - double current() const; - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) - int hvLineNo(const LArHVIdMapping* hvIdMapping=nullptr) const; -#else - int hvLineNo() const; + int hvLineNo(const LArHVIdMapping* hvIdMapping) const; #endif - // Voltage and current at the same time: - void voltage_current(double& v, double& i) const; - private: HECHVSubgap(const HECHVSubgap& right); HECHVSubgap& operator=(const HECHVSubgap& right); diff --git a/LArCalorimeter/LArGeoModel/LArHV/LArHV/LArHVManager.h b/LArCalorimeter/LArGeoModel/LArHV/LArHV/LArHVManager.h index 4ea6a3c16b33aa151190bdfafe7e94201c0e2ddf..f79f2af9ab49a7f9c8f87939f53938c467317b66 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/LArHV/LArHVManager.h +++ b/LArCalorimeter/LArGeoModel/LArHV/LArHV/LArHVManager.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 LARHV_LARHVMANAGER_H @@ -47,7 +47,6 @@ class LArHVManager // Returns the FCALHVManager const FCALHVManager& getFCALHVManager() const; - void reset() const; protected: diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVElectrode.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVElectrode.cxx index 5c641572cfee8873fe8f06872e30383c10a5973a..339b36da7a7fd0b8ab0ff507a834a2ae5acc1e3a 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVElectrode.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVElectrode.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 "LArHV/EMBHVElectrode.h" @@ -39,40 +39,12 @@ double EMBHVElectrode::getPhi() const return m_c->module->getPhiMin()+m_c->iElectrode*2.0*M_PI/1024.0; } -bool EMBHVElectrode::hvOn(int iGap) const -{ - EMBHVPayload *payload = m_c->module->getManager().getPayload(*this); - return (payload->voltage[iGap]>=-9999); -} - -double EMBHVElectrode::voltage(int iGap) const { - EMBHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->voltage[iGap]; -} - -double EMBHVElectrode::current(int iGap) const { - EMBHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->current[iGap]; -} - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) int EMBHVElectrode::hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping) const { - return hvIdMapping - ? m_c->module->getManager().hvLineNo(*this, iGap, hvIdMapping) - : m_c->module->getManager().getPayload(*this)->hvLineNo[iGap]; -} -#else -int EMBHVElectrode::hvLineNo(int iGap) const { - return m_c->module->getManager().getPayload(*this)->hvLineNo[iGap]; + return m_c->module->getManager().hvLineNo(*this, iGap, hvIdMapping); } #endif -void EMBHVElectrode::voltage_current(int iGap,double& voltage, double¤t) const { - EMBHVPayload *payload = m_c->module->getManager().getPayload(*this); - voltage = payload->voltage[iGap]; - current = payload->current[iGap]; -} - unsigned int EMBHVElectrode::getElectrodeIndex() const{ return m_c->iElectrode; } diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVManager.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVManager.cxx index d92032af94022997a9b55c995fda86f83420aebb..f4cf04aa9710a6853e06826931977ee52ed12bc9 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVManager.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVManager.cxx @@ -33,6 +33,34 @@ #include <mutex> #include <atomic> + +namespace { + + +struct ATLAS_NOT_THREAD_SAFE LegacyIdFunc +{ + LegacyIdFunc(); + std::vector<HWIdentifier> operator()(HWIdentifier id) + { + return m_cablingTool->getLArElectrodeIDvec (id); + } + LArHVCablingTool* m_cablingTool; +}; + + +LegacyIdFunc::LegacyIdFunc() +{ + ToolHandle<LArHVCablingTool> tool ("LArHVCablingTool"); + if (!tool.retrieve().isSuccess()) { + std::abort(); + } + m_cablingTool = tool.get(); +} + + +} // Anonymous namespace + + class EMBHVManager::Clockwork { public: Clockwork(const EMBHVManager* manager) { @@ -40,7 +68,7 @@ public: for(int iEta=0; iEta<8; ++iEta) { for(int iPhi=0; iPhi<16; ++iPhi) { for(int iSector=0; iSector<2; ++iSector) { - moduleArray[iSide][iEta][iPhi][iSector] = new EMBHVModule(manager,iSide,iEta,iPhi,iSector); + moduleArray[iSide][iEta][iPhi][iSector] = std::make_unique<EMBHVModule>(manager,iSide,iEta,iPhi,iSector); } } } @@ -57,33 +85,85 @@ public: } Clockwork(const Clockwork&) = delete; ~Clockwork() { - for(int iSide=0; iSide<2; ++iSide) { - for(int iEta=0; iEta<8; ++iEta) { - for(int iPhi=0; iPhi<16; ++iPhi) { - for(int iSector=0; iSector<2; ++iSector) { - delete moduleArray[iSide][iEta][iPhi][iSector]; - } - } - } - } } EMBHVDescriptor descriptor{CellBinning(0.0, 1.4, 7, 1),CellBinning(0.0, 2*M_PI, 16)}; - const EMBHVModule* moduleArray[2][8][16][2]; - std::atomic<bool> init{false}; - std::mutex mtx; - std::vector<EMBHVPayload> payloadArray; + std::unique_ptr<const EMBHVModule> moduleArray[2][8][16][2]; const LArElectrodeID* elecId; const LArHVLineID* hvId; }; + +class EMBHVManager::EMBHVData::Payload +{ +public: + std::vector<EMBHVPayload> m_payloadArray; +}; + + +EMBHVManager::EMBHVData::EMBHVData() +{ +} + + +EMBHVManager::EMBHVData::EMBHVData (std::unique_ptr<Payload> payload) + : m_payload (std::move (payload)) +{ +} + + +EMBHVManager::EMBHVData& +EMBHVManager::EMBHVData::operator= (EMBHVData&& other) +{ + if (this != &other) { + m_payload = std::move (other.m_payload); + } + return *this; +} + + +EMBHVManager::EMBHVData::~EMBHVData() +{ +} + + +double EMBHVManager::EMBHVData::voltage (const EMBHVElectrode& electrode, const int& iGap) const +{ + return m_payload->m_payloadArray[index(electrode)].voltage[iGap]; +} + + +double EMBHVManager::EMBHVData::current (const EMBHVElectrode& electrode, const int& iGap) const +{ + return m_payload->m_payloadArray[index(electrode)].current[iGap]; +} + + +int EMBHVManager::EMBHVData::hvLineNo (const EMBHVElectrode& electrode, const int& iGap) const +{ + return m_payload->m_payloadArray[index(electrode)].hvLineNo[iGap]; +} + + +int EMBHVManager::EMBHVData::index (const EMBHVElectrode& electrode) const +{ + unsigned int electrodeIndex = electrode.getElectrodeIndex(); + const EMBHVModule& module = electrode.getModule(); + unsigned int etaIndex = module.getEtaIndex(); + unsigned int phiIndex = module.getPhiIndex(); + unsigned int sectorIndex = module.getSectorIndex(); + unsigned int sideIndex = module.getSideIndex(); + unsigned int index = 8192*sideIndex+1024*etaIndex+64*phiIndex+32*sectorIndex+electrodeIndex; + return index; +} + + EMBHVManager::EMBHVManager() - : m_c(new Clockwork(this)) + : m_c (std::make_unique<Clockwork> (this)) { } EMBHVManager::~EMBHVManager() { - delete m_c; } const EMBHVDescriptor& EMBHVManager::getDescriptor() const @@ -136,70 +216,47 @@ unsigned int EMBHVManager::endSideIndex() const return 2; } -void EMBHVManager::update() const { - std::lock_guard<std::mutex> lock(m_c->mtx); - if (!(m_c->init)) { - m_c->init=true; - m_c->payloadArray.reserve(2*8*16*2*32); +EMBHVManager::EMBHVData +EMBHVManager::getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto payload = std::make_unique<EMBHVData::Payload>(); + payload->m_payloadArray.reserve(2*8*16*2*32); - for (int i=0;i<16384;i++) { - m_c->payloadArray[i].voltage[0]=-99999.; - m_c->payloadArray[i].voltage[1]=-99999.; - } + for (int i=0;i<16384;i++) { + payload->m_payloadArray[i].voltage[0]=-99999.; + payload->m_payloadArray[i].voltage[1]=-99999.; + } - ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager"); - - ISvcLocator* svcLocator = Gaudi::svcLocator(); - IToolSvc* toolSvc; - LArHVCablingTool* hvcablingTool; - - if(StatusCode::SUCCESS!=svcLocator->service("ToolSvc",toolSvc)) - return; - - if(StatusCode::SUCCESS!=toolSvc->retrieveTool("LArHVCablingTool",hvcablingTool)) - return; + for (const CondAttrListCollection* atrlistcol : attrLists) { - std::vector<std::string> colnames; - colnames.push_back("/LAR/DCS/HV/BARREl/I16"); - colnames.push_back("/LAR/DCS/HV/BARREL/I8"); - - std::vector<std::string>::const_iterator it = colnames.begin(); - std::vector<std::string>::const_iterator ie = colnames.end(); - - for (;it!=ie;it++) { - - //std::cout << " --- Start reading folder " << (*it) << std::endl; - const CondAttrListCollection* atrlistcol; - if (StatusCode::SUCCESS!=detStore->retrieve(atrlistcol,*it)) - return; - - for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { + for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { - // Construct HWIdentifier - // 1. decode COOL Channel ID - unsigned int chanID = (*citr).first; - int cannode = chanID/1000; - int line = chanID%1000; - //std::cout << " ++ found data for cannode, line " << cannode << " " << line << std::endl; + // Construct HWIdentifier + // 1. decode COOL Channel ID + unsigned int chanID = (*citr).first; + int cannode = chanID/1000; + int line = chanID%1000; + //std::cout << " ++ found data for cannode, line " << cannode << " " << line << std::endl; - // 2. Construct the identifier - HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); + // 2. Construct the identifier + HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); - std::vector<HWIdentifier> electrodeIdVec = hvcablingTool->getLArElectrodeIDvec(id); + std::vector<HWIdentifier> electrodeIdVec = idfunc(id); - for(size_t i=0;i<electrodeIdVec.size();i++) - { - HWIdentifier& elecHWID = electrodeIdVec[i]; - int detector = m_c->elecId->detector(elecHWID); - if (detector==0) { + for(size_t i=0;i<electrodeIdVec.size();i++) + { + HWIdentifier& elecHWID = electrodeIdVec[i]; + int detector = m_c->elecId->detector(elecHWID); + if (detector==0) { - //std::cout << " in Barrel " << std::endl; + //std::cout << " in Barrel " << std::endl; // side in standard offline 0 for z<0 (C) 1 for z>0 (A) // in electrode numbering, this is the opposite (0 for A and 1 for C) - unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); + unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); // eta index, no trouble - unsigned int etaIndex=m_c->elecId->hv_eta(elecHWID); + unsigned int etaIndex=m_c->elecId->hv_eta(elecHWID); // phi index // offline 0 to 2pi in 2pi/16 bins // this is module in the electrode numbering: on the A side 0 to 15, 0 is halfway around phi=0 (FT-1 (hv_phi=1 is a lower phi) @@ -209,12 +266,12 @@ void EMBHVManager::update() const { // hv_phi 0 1 0 0 1 // phiIndex 0 0 1 15 15 // sector Index 0 1 0 0 1 - unsigned int phiIndex; - unsigned int sectorIndex; - if (sideIndex==1) { - phiIndex=m_c->elecId->module(elecHWID); - sectorIndex=m_c->elecId->hv_phi(elecHWID); - } + unsigned int phiIndex; + unsigned int sectorIndex; + if (sideIndex==1) { + phiIndex=m_c->elecId->module(elecHWID); + sectorIndex=m_c->elecId->hv_phi(elecHWID); + } // module numbering on the C side 0 around phi=pi, running backwards // offline phi 0 pi 2pi // Module P8 P7 P7 P0 P0 P9 P8 @@ -222,74 +279,80 @@ void EMBHVManager::update() const { // hv_phi 1 0 1 0 1 1 0 // phiIndex 0 0 1 7 8 15 15 // sectorIndex 0 1 0 1 0 0 1 - else { - int imodule=m_c->elecId->module(elecHWID); - if (imodule<9) phiIndex = 8 - imodule; - else phiIndex = 24 - imodule; - sectorIndex = 1-m_c->elecId->hv_phi(elecHWID); - } - - if (sectorIndex==1) { - if (phiIndex>0) phiIndex = phiIndex - 1; - else phiIndex=15; - } - - unsigned int electrodeIndex=m_c->elecId->electrode(elecHWID); - if (sideIndex==0) { - if (m_c->elecId->hv_phi(elecHWID)==1) electrodeIndex=31-electrodeIndex; // FT-1 change 0->31 to 31->0 - else electrodeIndex=63-electrodeIndex; // FT 0 change 32->63 to 31-0 - } - else { - if (m_c->elecId->hv_phi(elecHWID)==0) electrodeIndex=electrodeIndex-32; // FT 0 change 31-63 to 0-31 - } + else { + int imodule=m_c->elecId->module(elecHWID); + if (imodule<9) phiIndex = 8 - imodule; + else phiIndex = 24 - imodule; + sectorIndex = 1-m_c->elecId->hv_phi(elecHWID); + } + + if (sectorIndex==1) { + if (phiIndex>0) phiIndex = phiIndex - 1; + else phiIndex=15; + } + + unsigned int electrodeIndex=m_c->elecId->electrode(elecHWID); + if (sideIndex==0) { + if (m_c->elecId->hv_phi(elecHWID)==1) electrodeIndex=31-electrodeIndex; // FT-1 change 0->31 to 31->0 + else electrodeIndex=63-electrodeIndex; // FT 0 change 32->63 to 31-0 + } + else { + if (m_c->elecId->hv_phi(elecHWID)==0) electrodeIndex=electrodeIndex-32; // FT 0 change 31-63 to 0-31 + } - unsigned int index = 8192*sideIndex+1024*etaIndex+64*phiIndex+32*sectorIndex+electrodeIndex; + unsigned int index = 8192*sideIndex+1024*etaIndex+64*phiIndex+32*sectorIndex+electrodeIndex; - unsigned int gapIndex=m_c->elecId->gap(elecHWID); - if (sideIndex==0) gapIndex=1-gapIndex; + unsigned int gapIndex=m_c->elecId->gap(elecHWID); + if (sideIndex==0) gapIndex=1-gapIndex; - float voltage = -99999.; - if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); - float current = 0.; - if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - unsigned int status = 0; - if (!((*citr).second)["R_STAT"].isNull()) status = ((*citr).second)["R_STAT"].data<unsigned int>(); + float voltage = -99999.; + if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); + float current = 0.; + if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - // std::cout << " hvlineId,elecHWID,cannode,line, side,phi module, sector,eta,electrode,gap,index " << std::hex << id << " " << elecHWID << std::dec << " " << cannode << " " << line << " " << m_c->elecId->zside(elecHWID) << " " << m_c->elecId->module(elecHWID) << " " << m_c->elecId->hv_phi(elecHWID) << " " << m_c->elecId->hv_eta(elecHWID) << " " << m_c->elecId->electrode(elecHWID) + // std::cout << " hvlineId,elecHWID,cannode,line, side,phi module, sector,eta,electrode,gap,index " << std::hex << id << " " << elecHWID << std::dec << " " << cannode << " " << line << " " << m_c->elecId->zside(elecHWID) << " " << m_c->elecId->module(elecHWID) << " " << m_c->elecId->hv_phi(elecHWID) << " " << m_c->elecId->hv_eta(elecHWID) << " " << m_c->elecId->electrode(elecHWID) // << " " << gapIndex << " " << index << " " << voltage << std::endl; - m_c->payloadArray[index].voltage[gapIndex]=voltage; - m_c->payloadArray[index].current[gapIndex]=current; - m_c->payloadArray[index].status[gapIndex]=status; - m_c->payloadArray[index].hvLineNo[gapIndex]=chanID; - } -// std::cerr << "\n"; + payload->m_payloadArray[index].voltage[gapIndex]=voltage; + payload->m_payloadArray[index].current[gapIndex]=current; + payload->m_payloadArray[index].hvLineNo[gapIndex]=chanID; } } } - } -} -void EMBHVManager::reset() const { - m_c->init=false; + return EMBHVManager::EMBHVData (std::move (payload)); } -EMBHVPayload* EMBHVManager::getPayload(const EMBHVElectrode &electrode) const { - update(); - unsigned int electrodeIndex = electrode.getElectrodeIndex(); - const EMBHVModule& module = electrode.getModule(); - unsigned int etaIndex = module.getEtaIndex(); - unsigned int phiIndex = module.getPhiIndex(); - unsigned int sectorIndex = module.getSectorIndex(); - unsigned int sideIndex = module.getSideIndex(); - unsigned int index = 8192*sideIndex+1024*etaIndex+64*phiIndex+32*sectorIndex+electrodeIndex; - return &m_c->payloadArray[index]; + +EMBHVManager::EMBHVData +EMBHVManager::getData ATLAS_NOT_THREAD_SAFE () const +{ + std::vector<const CondAttrListCollection*> attrLists; + ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "EMBHVManager"); + const CondAttrListCollection* atrlistcol = nullptr; + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I16").isSuccess()) { + attrLists.push_back (atrlistcol); + } + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I8").isSuccess()) { + attrLists.push_back (atrlistcol); + } + return getData (LegacyIdFunc(), attrLists); } + #ifndef SIMULATIONBASE #ifndef GENERATIONBASE +EMBHVManager::EMBHVData +EMBHVManager::getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto idfunc = [&] (HWIdentifier id) { return hvIdMapping.getLArElectrodeIDvec(id); }; + return getData (idfunc, attrLists); +} + + int EMBHVManager::hvLineNo(const EMBHVElectrode& electrode , int gap , const LArHVIdMapping* hvIdMapping) const diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVPayload.h b/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVPayload.h index cc04799758c940585427fa36049f782e09ca7acc..bb4dad93373ca9aa133a4765ac42138ad2d0ead2 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVPayload.h +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMBHVPayload.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 LARHV_EMBHVPAYLOAD_H @@ -8,13 +8,12 @@ struct EMBHVPayload { double voltage[2]; double current[2]; - unsigned int status[2]; int hvLineNo[2]; }; inline std::ostream & operator << (std::ostream & o, const EMBHVPayload & payload) { - o << "Half Gap #0: HV Line No " << payload.hvLineNo[0] << ' ' << payload.voltage[0] << " volts; " << payload.current[0] << " amps; status = " << payload.status[0] << std::endl; - o << "Half Gap #1: HV Line No " << payload.hvLineNo[1] << ' ' << payload.voltage[1] << " volts; " << payload.current[1] << " amps; status = " << payload.status[1] << std::endl; + o << "Half Gap #0: HV Line No " << payload.hvLineNo[0] << ' ' << payload.voltage[0] << " volts; " << payload.current[0] << " amps" << std::endl; + o << "Half Gap #1: HV Line No " << payload.hvLineNo[1] << ' ' << payload.voltage[1] << " volts; " << payload.current[1] << " amps" << std::endl; return o; } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVManager.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVManager.cxx index dd040ea2802d4efc67c1bc58c1c600fbc0f04f02..3876a98d0690924a52fa882f37b0d5ed8ffd355b 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVManager.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVManager.cxx @@ -34,18 +34,46 @@ #include <atomic> + +namespace { + + +struct ATLAS_NOT_THREAD_SAFE LegacyIdFunc +{ + LegacyIdFunc(); + std::vector<HWIdentifier> operator()(HWIdentifier id) + { + return m_cablingTool->getLArElectrodeIDvec (id); + } + LArHVCablingTool* m_cablingTool; +}; + + +LegacyIdFunc::LegacyIdFunc() +{ + ToolHandle<LArHVCablingTool> tool ("LArHVCablingTool"); + if (!tool.retrieve().isSuccess()) { + std::abort(); + } + m_cablingTool = tool.get(); +} + + +} // Anonymous namespace + + class EMBPresamplerHVManager::Clockwork { public: Clockwork(const EMBPresamplerHVManager* manager) { CellPartitioning etaPartitioning; for (unsigned int i= 0; i<4; i++) etaPartitioning.addValue(i*0.4); etaPartitioning.addValue(1.525); - descriptor = new EMBPresamplerHVDescriptor(etaPartitioning,CellBinning(0.0, 2*M_PI, 32)); + descriptor = std::make_unique<EMBPresamplerHVDescriptor>(etaPartitioning,CellBinning(0.0, 2*M_PI, 32)); for(int iSide=0; iSide<2; ++iSide) { for(int iEta=0; iEta<4; ++iEta) { for(int iPhi=0; iPhi<32; ++iPhi) { - moduleArray[iSide][iEta][iPhi] = new EMBPresamplerHVModule(manager, iSide, iEta,iPhi); + moduleArray[iSide][iEta][iPhi] = std::make_unique<EMBPresamplerHVModule>(manager, iSide, iEta,iPhi); } } } @@ -60,37 +88,92 @@ public: } } ~Clockwork() { - delete descriptor; - for(int iSide=0; iSide<2; ++iSide) { - for(int iEta=0; iEta<4; ++iEta) { - for(int iPhi=0; iPhi<32; ++iPhi) { - delete moduleArray[iSide][iEta][iPhi]; - } - } - } } - EMBPresamplerHVDescriptor* descriptor; - const EMBPresamplerHVModule* moduleArray[2][4][32]; - std::atomic<bool> init{false}; - std::mutex mtx; - std::vector<EMBPresamplerHVPayload> payloadArray; + std::unique_ptr<EMBPresamplerHVDescriptor> descriptor; + std::unique_ptr<const EMBPresamplerHVModule> moduleArray[2][4][32]; const LArElectrodeID* elecId; const LArHVLineID* hvId; }; + +class EMBPresamplerHVManager::EMBPresamplerHVData::Payload +{ +public: + std::vector<EMBPresamplerHVPayload> m_payloadArray; +}; + + +EMBPresamplerHVManager::EMBPresamplerHVData::EMBPresamplerHVData() +{ +} + + +EMBPresamplerHVManager::EMBPresamplerHVData::EMBPresamplerHVData + (std::unique_ptr<Payload> payload) + : m_payload (std::move (payload)) +{ +} + + +EMBPresamplerHVManager::EMBPresamplerHVData& +EMBPresamplerHVManager::EMBPresamplerHVData::operator= (EMBPresamplerHVData&& other) +{ + if (this != &other) { + m_payload = std::move (other.m_payload); + } + return *this; +} + + +EMBPresamplerHVManager::EMBPresamplerHVData::~EMBPresamplerHVData() +{ +} + + +double EMBPresamplerHVManager::EMBPresamplerHVData::voltage + (const EMBPresamplerHVModule& module, const int& iGap) const +{ + return m_payload->m_payloadArray[index(module)].voltage[iGap]; +} + + +double EMBPresamplerHVManager::EMBPresamplerHVData::current + (const EMBPresamplerHVModule& module, const int& iGap) const +{ + return m_payload->m_payloadArray[index(module)].current[iGap]; +} + + +int EMBPresamplerHVManager::EMBPresamplerHVData::hvLineNo + (const EMBPresamplerHVModule& module, const int& iGap) const +{ + return m_payload->m_payloadArray[index(module)].hvLineNo[iGap]; +} + + +int EMBPresamplerHVManager::EMBPresamplerHVData::index + (const EMBPresamplerHVModule& module) const +{ + unsigned int sideIndex = module.getSideIndex(); + unsigned int phiIndex = module.getPhiIndex(); + unsigned int etaIndex = module.getEtaIndex(); + unsigned int index = 128*sideIndex+32*etaIndex+phiIndex; + return index; +} + + EMBPresamplerHVManager::EMBPresamplerHVManager() - : m_c(new Clockwork(this)) + : m_c (std::make_unique<Clockwork> (this)) { } EMBPresamplerHVManager::~EMBPresamplerHVManager() { - delete m_c; } const EMBPresamplerHVDescriptor* EMBPresamplerHVManager::getDescriptor() const { - return m_c->descriptor; + return m_c->descriptor.get(); } unsigned int EMBPresamplerHVManager::beginPhiIndex() const @@ -128,72 +211,49 @@ unsigned int EMBPresamplerHVManager::endSideIndex() const return 2; } -void EMBPresamplerHVManager::update() const { - std::lock_guard<std::mutex> lock(m_c->mtx); - if (!(m_c->init)) { - m_c->init=true; - m_c->payloadArray.reserve(2*4*32); +EMBPresamplerHVManager::EMBPresamplerHVData +EMBPresamplerHVManager::getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto payload = std::make_unique<EMBPresamplerHVData::Payload>(); + payload->m_payloadArray.reserve(2*4*32); - for (int i=0;i<256;i++) { - m_c->payloadArray[i].voltage[0]=-99999.; - m_c->payloadArray[i].voltage[1]=-99999.; - } + for (int i=0;i<256;i++) { + payload->m_payloadArray[i].voltage[0]=-99999.; + payload->m_payloadArray[i].voltage[1]=-99999.; + } - ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager"); - - ISvcLocator* svcLocator = Gaudi::svcLocator(); - IToolSvc* toolSvc; - LArHVCablingTool* hvcablingTool; - - if(StatusCode::SUCCESS!=svcLocator->service("ToolSvc",toolSvc)) - return; + for (const CondAttrListCollection* atrlistcol : attrLists) { - if(StatusCode::SUCCESS!=toolSvc->retrieveTool("LArHVCablingTool",hvcablingTool)) - return; - - std::vector<std::string> colnames; - colnames.push_back("/LAR/DCS/HV/BARREl/I16"); - colnames.push_back("/LAR/DCS/HV/BARREL/I8"); - - std::vector<std::string>::const_iterator it = colnames.begin(); - std::vector<std::string>::const_iterator ie = colnames.end(); - - for (;it!=ie;it++) { - - //std::cout << " --- Start reading folder " << (*it) << std::endl; - const CondAttrListCollection* atrlistcol; - if (StatusCode::SUCCESS!=detStore->retrieve(atrlistcol,*it)) - return; - - for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { + for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { - // Construct HWIdentifier - // 1. decode COOL Channel ID - unsigned int chanID = (*citr).first; - int cannode = chanID/1000; - int line = chanID%1000; - //std::cout << " ++ found data for cannode, line " << cannode << " " << line << std::endl; - - // 2. Construct the identifier - HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); + // Construct HWIdentifier + // 1. decode COOL Channel ID + unsigned int chanID = (*citr).first; + int cannode = chanID/1000; + int line = chanID%1000; + //std::cout << " ++ found data for cannode, line " << cannode << " " << line << std::endl; - std::vector<HWIdentifier> electrodeIdVec = hvcablingTool->getLArElectrodeIDvec(id); + // 2. Construct the identifier + HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); + std::vector<HWIdentifier> electrodeIdVec = idfunc(id); - for(size_t i=0;i<electrodeIdVec.size();i++) - { - HWIdentifier& elecHWID = electrodeIdVec[i]; - int detector = m_c->elecId->detector(elecHWID); - if (detector==1) { - //std::cout << " in Barrel " << std::endl; + for(size_t i=0;i<electrodeIdVec.size();i++) + { + HWIdentifier& elecHWID = electrodeIdVec[i]; + int detector = m_c->elecId->detector(elecHWID); + if (detector==1) { + //std::cout << " in Barrel " << std::endl; + // side in standard offline 0 for z<0 (C) 1 for z>0 (A) // in electrode numbering, this is the opposite (0 for A and 1 for C) - unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); + unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); // eta index, no trouble - unsigned int etaIndex=m_c->elecId->hv_eta(elecHWID)-1; + unsigned int etaIndex=m_c->elecId->hv_eta(elecHWID)-1; // phi index // offline 0 to 2pi in 2pi/32 bins (2 presampler cells per phi_HV) // module from elecID : 0 to 31 @@ -202,68 +262,74 @@ void EMBPresamplerHVManager::update() const { // FT 0 -1 0 -1 0 -1 // Module 0 1 2 3 4 5 6 7 9 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 39 30 31 // offline phi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - unsigned int phiIndex; - if (sideIndex==1) { - phiIndex=m_c->elecId->module(elecHWID); - } + unsigned int phiIndex; + if (sideIndex==1) { + phiIndex=m_c->elecId->module(elecHWID); + } // module numbering on the C side 0 around phi=pi, running backwards // phi 0 pi 2pi // P8 P7 P6 P5 P4 P3 P2 P1 P0 P15 P14 P13 P12 P11 P10 P9 P8 // FT -1 0 0 -1 0 -1 0 // Module 15 14 9 8 7 6 5 4 3 2 1 0 31 30 29 38 27 26 25 24 23 22 21 20 19 18 17 16 // offline phi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - else { - int imodule=m_c->elecId->module(elecHWID); - if (imodule<16) phiIndex = 15 - imodule; - else phiIndex = 47 - imodule; - } + else { + int imodule=m_c->elecId->module(elecHWID); + if (imodule<16) phiIndex = 15 - imodule; + else phiIndex = 47 - imodule; + } - unsigned int index = 128*sideIndex+32*etaIndex+phiIndex; + unsigned int index = 128*sideIndex+32*etaIndex+phiIndex; - unsigned int gapIndex=m_c->elecId->gap(elecHWID); - if (sideIndex==0) gapIndex=1-gapIndex; + unsigned int gapIndex=m_c->elecId->gap(elecHWID); + if (sideIndex==0) gapIndex=1-gapIndex; - float voltage = -99999.; - if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); - float current = 0.; - if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - unsigned int status = 0; - if (!((*citr).second)["R_STAT"].isNull()) status = ((*citr).second)["R_STAT"].data<unsigned int>(); + float voltage = -99999.; + if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); + float current = 0.; + if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); + // std::cout << " hvlineId,elecHWID,cannode,line, side,phi module, sector,eta,electrode,gap,index " << std::hex << id << " " << elecHWID << std::dec << " " << cannode << " " << line << " " << m_c->elecId->zside(elecHWID) << " " << m_c->elecId->module(elecHWID) << " " << m_c->elecId->hv_phi(elecHWID) << " " << m_c->elecId->hv_eta(elecHWID) << " " << m_c->elecId->electrode(elecHWID) + // << " " << gapIndex << " " << index << " " << voltage << std::endl; - // std::cout << " hvlineId,elecHWID,cannode,line, side,phi module, sector,eta,electrode,gap,index " << std::hex << id << " " << elecHWID << std::dec << " " << cannode << " " << line << " " << m_c->elecId->zside(elecHWID) << " " << m_c->elecId->module(elecHWID) << " " << m_c->elecId->hv_phi(elecHWID) << " " << m_c->elecId->hv_eta(elecHWID) << " " << m_c->elecId->electrode(elecHWID) - // << " " << gapIndex << " " << index << " " << voltage << std::endl; - - - m_c->payloadArray[index].voltage[gapIndex]=voltage; - m_c->payloadArray[index].current[gapIndex]=current; - m_c->payloadArray[index].status[gapIndex]=status; - m_c->payloadArray[index].hvLineNo[gapIndex]=chanID; - } -// std::cerr << "\n"; + payload->m_payloadArray[index].voltage[gapIndex]=voltage; + payload->m_payloadArray[index].current[gapIndex]=current; + payload->m_payloadArray[index].hvLineNo[gapIndex]=chanID; } } } - } -} -void EMBPresamplerHVManager::reset() const { - m_c->init=false; + return EMBPresamplerHVManager::EMBPresamplerHVData (std::move (payload)); } -EMBPresamplerHVPayload *EMBPresamplerHVManager::getPayload(const EMBPresamplerHVModule &module) const { - update(); - unsigned int sideIndex = module.getSideIndex(); - unsigned int phiIndex = module.getPhiIndex(); - unsigned int etaIndex = module.getEtaIndex(); - unsigned int index = 128*sideIndex+32*etaIndex+phiIndex; - return &m_c->payloadArray[index]; +EMBPresamplerHVManager::EMBPresamplerHVData +EMBPresamplerHVManager::getData ATLAS_NOT_THREAD_SAFE () const +{ + std::vector<const CondAttrListCollection*> attrLists; + ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "EMBHVManager"); + const CondAttrListCollection* atrlistcol = nullptr; + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I16").isSuccess()) { + attrLists.push_back (atrlistcol); + } + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I8").isSuccess()) { + attrLists.push_back (atrlistcol); + } + return getData (LegacyIdFunc(), attrLists); } + #ifndef SIMULATIONBASE #ifndef GENERATIONBASE +EMBPresamplerHVManager::EMBPresamplerHVData +EMBPresamplerHVManager::getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto idfunc = [&] (HWIdentifier id) { return hvIdMapping.getLArElectrodeIDvec(id); }; + return getData (idfunc, attrLists); +} + + int EMBPresamplerHVManager::hvLineNo(const EMBPresamplerHVModule& module , int gap , const LArHVIdMapping* hvIdMapping) const { diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVModule.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVModule.cxx index 13ff4ad396b6889c9a22f5f5e091ee5e428932e0..fae04e731ab45e56185fd92dc973e400f63de1ef 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVModule.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVModule.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 "LArHV/EMBPresamplerHVModule.h" @@ -87,36 +87,8 @@ const EMBPresamplerHVManager& EMBPresamplerHVModule::getManager() const return *(m_c->manager); } -bool EMBPresamplerHVModule::hvOn(int iGap) const -{ - EMBPresamplerHVPayload *payload = m_c->manager->getPayload(*this); - return (payload->voltage[iGap]>=-9999); -} - -double EMBPresamplerHVModule::voltage(int iGap) const { - EMBPresamplerHVPayload *payload = m_c->manager->getPayload(*this); - return payload->voltage[iGap]; -} - -double EMBPresamplerHVModule::current(int iGap) const { - EMBPresamplerHVPayload *payload = m_c->manager->getPayload(*this); - return payload->current[iGap]; -} - -void EMBPresamplerHVModule::voltage_current(int iGap,double& voltage, double¤t) const { - EMBPresamplerHVPayload *payload = m_c->manager->getPayload(*this); - voltage = payload->voltage[iGap]; - current = payload->current[iGap]; -} - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) int EMBPresamplerHVModule::hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping) const { - return hvIdMapping - ? m_c->manager->hvLineNo(*this,iGap,hvIdMapping) - : m_c->manager->getPayload(*this)->hvLineNo[iGap]; -} -#else -int EMBPresamplerHVModule::hvLineNo(int iGap) const { - return m_c->manager->getPayload(*this)->hvLineNo[iGap]; + return m_c->manager->hvLineNo(*this,iGap,hvIdMapping); } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVPayload.h b/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVPayload.h index 2f97804b80ab7b61f9dcb9e85d8e1b767e15e947..6510ec53bcf54ab5a4ca4a940651e3143f247b74 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVPayload.h +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMBPresamplerHVPayload.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 LARHV_EMBPRESAMPLERHVPAYLOAD_H @@ -8,13 +8,12 @@ struct EMBPresamplerHVPayload { double voltage[2]; double current[2]; - unsigned int status[2]; int hvLineNo[2]; }; inline std::ostream & operator << (std::ostream & o, const EMBPresamplerHVPayload & payload) { - o << "Half Gap #0: HV Line No " << payload.hvLineNo[0] << ' ' << payload.voltage[0] << " volts; " << payload.current[0] << " amps; status = " << payload.status[0] << std::endl; - o << "Half Gap #1: HV Line No " << payload.hvLineNo[1] << ' ' << payload.voltage[1] << " volts; " << payload.current[1] << " amps; status = " << payload.status[1] << std::endl; + o << "Half Gap #0: HV Line No " << payload.hvLineNo[0] << ' ' << payload.voltage[0] << " volts; " << payload.current[0] << " amps" << std::endl; + o << "Half Gap #1: HV Line No " << payload.hvLineNo[1] << ' ' << payload.voltage[1] << " volts; " << payload.current[1] << " amps" << std::endl; return o; } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVElectrode.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVElectrode.cxx index ae9a06dfbfce0cc5bfcb73a11fa6afed537c61e4..582d82b0b9716eaafd8be40d854c5a23757abb00 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVElectrode.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVElectrode.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 "LArHV/EMECHVElectrode.h" @@ -45,36 +45,8 @@ double EMECHVElectrode::getPhi() const return m_c->module->getPhiMin()+m_c->iElectrode*2.0*M_PI/N; } -bool EMECHVElectrode::hvOn(int iGap ) const -{ - EMECHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->voltage[iGap]>=-9999; -} - -double EMECHVElectrode::voltage(int iGap) const { - EMECHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->voltage[iGap]; -} - -double EMECHVElectrode::current(int iGap) const { - EMECHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->current[iGap]; -} - -void EMECHVElectrode::voltage_current(int iGap,double& voltage, double¤t) const { - EMECHVPayload *payload = m_c->module->getManager().getPayload(*this); - voltage = payload->voltage[iGap]; - current = payload->current[iGap]; -} - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) int EMECHVElectrode::hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping) const { - return hvIdMapping - ? m_c->module->getManager().hvLineNo(*this, iGap, hvIdMapping) - : m_c->module->getManager().getPayload(*this)->hvLineNo[iGap]; -} -#else -int EMECHVElectrode::hvLineNo(int iGap) const { - return m_c->module->getManager().getPayload(*this)->hvLineNo[iGap]; + return m_c->module->getManager().hvLineNo(*this, iGap, hvIdMapping); } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVManager.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVManager.cxx index c059da3103e8f647473e4d3c2f909073071fee00..29027c796aff85cd4cb532ea884c762dde0b1acb 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVManager.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVManager.cxx @@ -33,16 +33,46 @@ #include <atomic> + +namespace { + + +struct ATLAS_NOT_THREAD_SAFE LegacyIdFunc +{ + LegacyIdFunc(); + std::vector<HWIdentifier> operator()(HWIdentifier id) + { + return m_cablingTool->getLArElectrodeIDvec (id); + } + LArHVCablingTool* m_cablingTool; +}; + + +LegacyIdFunc::LegacyIdFunc() +{ + ToolHandle<LArHVCablingTool> tool ("LArHVCablingTool"); + if (!tool.retrieve().isSuccess()) { + std::abort(); + } + m_cablingTool = tool.get(); +} + + +} // Anonymous namespace + + class EMECHVManager::Clockwork { public: - Clockwork(const EMECHVManager* manager, IOType wheel) - : iWheel(wheel) + Clockwork(const EMECHVManager* manager, IOType wheel, + std::unique_ptr<EMECHVDescriptor> the_descriptor) + : descriptor(std::move(the_descriptor)), + iWheel(wheel) { for(int iSide=0; iSide<2; ++iSide) { for(int iEta=0; iEta<8; ++iEta) { for(int iPhi=0; iPhi<8; ++iPhi) { for(int iSector=0; iSector<8; ++iSector) { - moduleArray[iSide][iEta][iPhi][iSector] = new EMECHVModule(manager,wheel,iSide,iEta,iPhi,iSector); + moduleArray[iSide][iEta][iPhi][iSector] = std::make_unique<EMECHVModule>(manager,wheel,iSide,iEta,iPhi,iSector); } } } @@ -58,31 +88,86 @@ public: } } ~Clockwork() { - for(int iSide=0; iSide<2; ++iSide) { - for(int iEta=0; iEta<8; ++iEta) { - for(int iPhi=0; iPhi<8; ++iPhi) { - for(int iSector=0; iSector<8; ++iSector) { - delete moduleArray[iSide][iEta][iPhi][iSector]; - } - } - } - } - delete descriptor; } - EMECHVDescriptor* descriptor{nullptr}; + std::unique_ptr<EMECHVDescriptor> descriptor; IOType iWheel; - const EMECHVModule* moduleArray[2][8][8][8]; // not dense - std::atomic<bool> init{false}; - std::mutex mtx; - std::vector<EMECHVPayload> payloadArray; + std::unique_ptr<const EMECHVModule> moduleArray[2][8][8][8]; // not dense const LArElectrodeID* elecId; const LArHVLineID* hvId; }; +class EMECHVManager::EMECHVData::Payload +{ +public: + std::vector<EMECHVPayload> m_payloadArray; +}; + + +EMECHVManager::EMECHVData::EMECHVData() +{ +} + + +EMECHVManager::EMECHVData::EMECHVData (std::unique_ptr<Payload> payload) + : m_payload (std::move (payload)) +{ +} + + +EMECHVManager::EMECHVData& +EMECHVManager::EMECHVData::operator= (EMECHVData&& other) +{ + if (this != &other) { + m_payload = std::move (other.m_payload); + } + return *this; +} + + +EMECHVManager::EMECHVData::~EMECHVData() +{ +} + + +double EMECHVManager::EMECHVData::voltage (const EMECHVElectrode& electrode, const int& iGap) const +{ + return m_payload->m_payloadArray[index(electrode)].voltage[iGap]; +} + + +double EMECHVManager::EMECHVData::current (const EMECHVElectrode& electrode, const int& iGap) const +{ + return m_payload->m_payloadArray[index(electrode)].current[iGap]; +} + + +int EMECHVManager::EMECHVData::hvLineNo (const EMECHVElectrode& electrode, const int& iGap) const +{ + return m_payload->m_payloadArray[index(electrode)].hvLineNo[iGap]; +} + + +int EMECHVManager::EMECHVData::index (const EMECHVElectrode& electrode) const +{ + unsigned int electrodeIndex = electrode.getElectrodeIndex(); + const EMECHVModule& module = electrode.getModule(); + unsigned int etaIndex = module.getEtaIndex(); + unsigned int phiIndex = module.getPhiIndex(); + unsigned int sectorIndex = module.getSectorIndex(); + unsigned int sideIndex = module.getSideIndex(); + + unsigned int index=0; + if (module.getWheelIndex()==EMECHVModule::OUTER) index= 5376*sideIndex+768*etaIndex+96*phiIndex+24*sectorIndex+electrodeIndex; + else if (module.getWheelIndex()==EMECHVModule::INNER) index= 512*sideIndex+256*etaIndex+32*phiIndex+4*sectorIndex+electrodeIndex; + + return index; +} + + EMECHVManager::EMECHVManager(IOType wheel) - : m_c(new Clockwork(this,wheel)) { + std::unique_ptr<EMECHVDescriptor> descriptor; if (wheel==EMECHVModule::OUTER) { CellPartitioning etaBinning; etaBinning.addValue(1.375); @@ -93,15 +178,16 @@ EMECHVManager::EMECHVManager(IOType wheel) etaBinning.addValue(2.1); etaBinning.addValue(2.3); etaBinning.addValue(2.5); - m_c->descriptor = new EMECHVDescriptor(etaBinning,CellBinning(0.0, 2*M_PI, 8),CellBinning(0,M_PI/4.0,4)); + descriptor = std::make_unique<EMECHVDescriptor>(etaBinning,CellBinning(0.0, 2*M_PI, 8),CellBinning(0,M_PI/4.0,4)); } else { CellPartitioning etaBinning; etaBinning.addValue(2.5); etaBinning.addValue(2.8); etaBinning.addValue(3.2); - m_c->descriptor=new EMECHVDescriptor(etaBinning,CellBinning(0.0, 2*M_PI, 8),CellBinning(0,M_PI/4.0,8)); + descriptor = std::make_unique<EMECHVDescriptor>(etaBinning,CellBinning(0.0, 2*M_PI, 8),CellBinning(0,M_PI/4.0,8)); } + m_c = std::make_unique<Clockwork> (this, wheel, std::move(descriptor)); } const EMECHVDescriptor& EMECHVManager::getDescriptor() const @@ -136,7 +222,6 @@ const EMECHVModule& EMECHVManager::getHVModule(unsigned int iSide, unsigned int EMECHVManager::~EMECHVManager() { - delete m_c; } unsigned int EMECHVManager::beginSideIndex() const @@ -164,163 +249,147 @@ EMECHVManager::IOType EMECHVManager::getWheelIndex() const return m_c->iWheel; } -void EMECHVManager::update() const { - std::lock_guard<std::mutex> lock(m_c->mtx); - if (!(m_c->init)) { - m_c->init=true; - if (m_c->iWheel==EMECHVModule::OUTER) { - m_c->payloadArray.reserve(2*7*8*4*24); - for (unsigned int i=0;i<10752;i++) { - m_c->payloadArray[i].voltage[0]=-99999; - m_c->payloadArray[i].voltage[1]=-99999; - } +EMECHVManager::EMECHVData +EMECHVManager::getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto payload = std::make_unique<EMECHVData::Payload>(); + + if (m_c->iWheel==EMECHVModule::OUTER) { + payload->m_payloadArray.reserve(2*7*8*4*24); + for (unsigned int i=0;i<10752;i++) { + payload->m_payloadArray[i].voltage[0]=-99999.; + payload->m_payloadArray[i].voltage[1]=-99999.; } - else if (m_c->iWheel==EMECHVModule::INNER) { - m_c->payloadArray.reserve(2*2*8*8*4); - for (unsigned int i=0;i<1024;i++) { - m_c->payloadArray[i].voltage[0]=-99999; - m_c->payloadArray[i].voltage[1]=-99999; - } + } + else if (m_c->iWheel==EMECHVModule::INNER) { + payload->m_payloadArray.reserve(2*2*8*8*4); + for (unsigned int i=0;i<1024;i++) { + payload->m_payloadArray[i].voltage[0]=-99999.; + payload->m_payloadArray[i].voltage[1]=-99999.; } + } - ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager"); + for (const CondAttrListCollection* atrlistcol : attrLists) { - ISvcLocator* svcLocator = Gaudi::svcLocator(); - IToolSvc* toolSvc; - LArHVCablingTool* hvcablingTool; + for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { + // Construct HWIdentifier + // 1. decode COOL Channel ID + unsigned int chanID = (*citr).first; + int cannode = chanID/1000; + int line = chanID%1000; + //std::cout << " ++ found data for cannode, line " << cannode << " " << line << std::endl; - if(StatusCode::SUCCESS!=svcLocator->service("ToolSvc",toolSvc)) - return; + // 2. Construct the identifier + HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); - if(StatusCode::SUCCESS!=toolSvc->retrieveTool("LArHVCablingTool",hvcablingTool)) - return; - std::vector<std::string> colnames; - colnames.push_back("/LAR/DCS/HV/BARREl/I16"); - colnames.push_back("/LAR/DCS/HV/BARREL/I8"); + std::vector<HWIdentifier> electrodeIdVec = idfunc(id); - std::vector<std::string>::const_iterator it = colnames.begin(); - std::vector<std::string>::const_iterator ie = colnames.end(); + for(size_t i=0;i<electrodeIdVec.size();i++) { + HWIdentifier& elecHWID = electrodeIdVec[i]; - for (;it!=ie;it++) { - //std::cout << " --- Start reading folder " << (*it) << std::endl; - const CondAttrListCollection* atrlistcol; - if (StatusCode::SUCCESS!=detStore->retrieve(atrlistcol,*it)) - return; + int detector = m_c->elecId->detector(elecHWID); + // check we are in EMEC + if (detector==2) { - for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { - // Construct HWIdentifier - // 1. decode COOL Channel ID - unsigned int chanID = (*citr).first; - int cannode = chanID/1000; - int line = chanID%1000; - //std::cout << " ++ found data for cannode, line " << cannode << " " << line << std::endl; - // 2. Construct the identifier - HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); + unsigned int etaIndex=m_c->elecId->hv_eta(elecHWID); + if ( (etaIndex>6 && m_c->iWheel==EMECHVModule::INNER) || (etaIndex<7 && m_c->iWheel==EMECHVModule::OUTER) ) { - std::vector<HWIdentifier> electrodeIdVec = hvcablingTool->getLArElectrodeIDvec(id); - - for(size_t i=0;i<electrodeIdVec.size();i++) { - HWIdentifier& elecHWID = electrodeIdVec[i]; - - int detector = m_c->elecId->detector(elecHWID); - // check we are in EMEC - if (detector==2) { - - - unsigned int etaIndex=m_c->elecId->hv_eta(elecHWID); - - if ( (etaIndex>6 && m_c->iWheel==EMECHVModule::INNER) || (etaIndex<7 && m_c->iWheel==EMECHVModule::OUTER) ) { - - unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); - unsigned int phiIndex=m_c->elecId->module(elecHWID); // 0 to 7 + unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); + unsigned int phiIndex=m_c->elecId->module(elecHWID); // 0 to 7 // rotation for C side - if (sideIndex==0) { - if (phiIndex<4) phiIndex=3-phiIndex; - else phiIndex=11-phiIndex; - } - unsigned int sectorIndex=m_c->elecId->hv_phi(elecHWID)-1; // 0 to 3 in Outer, 0 to 7 in Inner + if (sideIndex==0) { + if (phiIndex<4) phiIndex=3-phiIndex; + else phiIndex=11-phiIndex; + } + unsigned int sectorIndex=m_c->elecId->hv_phi(elecHWID)-1; // 0 to 3 in Outer, 0 to 7 in Inner // rotation for C side - if (sideIndex==0) { - if (m_c->iWheel==EMECHVModule::OUTER) sectorIndex=3-sectorIndex; - else sectorIndex=7-sectorIndex; - } - unsigned int electrodeIndex = m_c->iWheel==EMECHVModule::OUTER ? - m_c->elecId->electrode(elecHWID)%24: - m_c->elecId->electrode(elecHWID)%4; + if (sideIndex==0) { + if (m_c->iWheel==EMECHVModule::OUTER) sectorIndex=3-sectorIndex; + else sectorIndex=7-sectorIndex; + } + unsigned int electrodeIndex = m_c->iWheel==EMECHVModule::OUTER ? + m_c->elecId->electrode(elecHWID)%24: + m_c->elecId->electrode(elecHWID)%4; // rotation for C side - if (sideIndex==0) { - if (m_c->iWheel==EMECHVModule::OUTER) electrodeIndex=23-electrodeIndex; - else electrodeIndex=3-electrodeIndex; - } + if (sideIndex==0) { + if (m_c->iWheel==EMECHVModule::OUTER) electrodeIndex=23-electrodeIndex; + else electrodeIndex=3-electrodeIndex; + } - unsigned int index = m_c->iWheel==EMECHVModule::OUTER ? - 5376*sideIndex+768*etaIndex+96*phiIndex+24*sectorIndex+electrodeIndex: - 512*sideIndex+256*(etaIndex-7)+32*phiIndex+4*sectorIndex+electrodeIndex; - - if (m_c->iWheel==EMECHVModule::OUTER && index>10752) { - std::cout << "invalid index outer " << index << " side,eta,phi,sector,electrode " << sideIndex << " " << etaIndex << " " << phiIndex << - " " << sectorIndex << " " << electrodeIndex << std::endl; - continue; - } - if (m_c->iWheel==EMECHVModule::INNER && index>1024) { - std::cout << "invalid index inner " << index << " side,eta,phi,sector,electrode " << sideIndex << " " << etaIndex << " " << phiIndex << - " " << sectorIndex << " " << electrodeIndex << std::endl; - continue; - } + unsigned int index = m_c->iWheel==EMECHVModule::OUTER ? + 5376*sideIndex+768*etaIndex+96*phiIndex+24*sectorIndex+electrodeIndex: + 512*sideIndex+256*(etaIndex-7)+32*phiIndex+4*sectorIndex+electrodeIndex; + + if (m_c->iWheel==EMECHVModule::OUTER && index>10752) { + std::cout << "invalid index outer " << index << " side,eta,phi,sector,electrode " << sideIndex << " " << etaIndex << " " << phiIndex << + " " << sectorIndex << " " << electrodeIndex << std::endl; + continue; + } + if (m_c->iWheel==EMECHVModule::INNER && index>1024) { + std::cout << "invalid index inner " << index << " side,eta,phi,sector,electrode " << sideIndex << " " << etaIndex << " " << phiIndex << + " " << sectorIndex << " " << electrodeIndex << std::endl; + continue; + } - unsigned int gapIndex=m_c->elecId->gap(elecHWID); - if (gapIndex>1) { - std::cout << "invalid gapIndex " << gapIndex << std::endl; - continue; - } - if (sideIndex==0) gapIndex=1-gapIndex; + unsigned int gapIndex=m_c->elecId->gap(elecHWID); + if (gapIndex>1) { + std::cout << "invalid gapIndex " << gapIndex << std::endl; + continue; + } + if (sideIndex==0) gapIndex=1-gapIndex; - float voltage = -99999.; - if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); - float current = 0.; - if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - unsigned int status = 0; - if (!((*citr).second)["R_STAT"].isNull()) status = ((*citr).second)["R_STAT"].data<unsigned int>(); + float voltage = -99999.; + if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); + float current = 0.; + if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - //std::cout << " hvlineId,elecHWID,cannode,line, side,phi module, sector,eta,electrode,gap,index " << std::hex << id << " " << elecHWID << std::dec << " " << cannode << " " << line << " " << m_c->elecId->zside(elecHWID) << " " << m_c->elecId->module(elecHWID) << " " << m_c->elecId->hv_phi(elecHWID) << " " << m_c->elecId->hv_eta(elecHWID) << " " << m_c->elecId->electrode(elecHWID) - // << " " << gapIndex << " " << index << " " << voltage << std::endl; + //std::cout << " hvlineId,elecHWID,cannode,line, side,phi module, sector,eta,electrode,gap,index " << std::hex << id << " " << elecHWID << std::dec << " " << cannode << " " << line << " " << m_c->elecId->zside(elecHWID) << " " << m_c->elecId->module(elecHWID) << " " << m_c->elecId->hv_phi(elecHWID) << " " << m_c->elecId->hv_eta(elecHWID) << " " << m_c->elecId->electrode(elecHWID) + // << " " << gapIndex << " " << index << " " << voltage << std::endl; - m_c->payloadArray[index].voltage[gapIndex]=voltage; - m_c->payloadArray[index].current[gapIndex]=current; - m_c->payloadArray[index].status[gapIndex]=status; - m_c->payloadArray[index].hvLineNo[gapIndex]=chanID; - } // if etaIndex... - } // for (electrodeIdVec) - } // is EMEC - } // for (atrlistcol) - } - } // if(!m_c->init) -} + payload->m_payloadArray[index].voltage[gapIndex]=voltage; + payload->m_payloadArray[index].current[gapIndex]=current; + payload->m_payloadArray[index].hvLineNo[gapIndex]=chanID; + } // if etaIndex... + } // for (electrodeIdVec) + } // is EMEC + } // for (atrlistcol) + } -void EMECHVManager::reset() const { - m_c->init=false; + return EMECHVManager::EMECHVData (std::move (payload)); } -EMECHVPayload *EMECHVManager::getPayload(const EMECHVElectrode &electrode) const { - update(); - unsigned int electrodeIndex = electrode.getElectrodeIndex(); - const EMECHVModule& module = electrode.getModule(); - unsigned int etaIndex = module.getEtaIndex(); - unsigned int phiIndex = module.getPhiIndex(); - unsigned int sectorIndex = module.getSectorIndex(); - unsigned int sideIndex = module.getSideIndex(); - unsigned int index=0; - if (m_c->iWheel==EMECHVModule::OUTER) index= 5376*sideIndex+768*etaIndex+96*phiIndex+24*sectorIndex+electrodeIndex; - else if (m_c->iWheel==EMECHVModule::INNER) index= 512*sideIndex+256*etaIndex+32*phiIndex+4*sectorIndex+electrodeIndex; - return &m_c->payloadArray[index]; +EMECHVManager::EMECHVData +EMECHVManager::getData ATLAS_NOT_THREAD_SAFE () const +{ + std::vector<const CondAttrListCollection*> attrLists; + ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "EMBHVManager"); + const CondAttrListCollection* atrlistcol = nullptr; + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I16").isSuccess()) { + attrLists.push_back (atrlistcol); + } + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I8").isSuccess()) { + attrLists.push_back (atrlistcol); + } + return getData (LegacyIdFunc(), attrLists); } + #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) +EMECHVManager::EMECHVData +EMECHVManager::getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto idfunc = [&] (HWIdentifier id) { return hvIdMapping.getLArElectrodeIDvec(id); }; + return getData (idfunc, attrLists); +} + + int EMECHVManager::hvLineNo(const EMECHVElectrode& electrode , int gap , const LArHVIdMapping* hvIdMapping) const diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVPayload.h b/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVPayload.h index d61e6fc3157006af7b2a3e7d4b267a2b4156db21..22f174b7731efaac084ece1a7cf4e2be68be785e 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVPayload.h +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMECHVPayload.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 LARHV_EMECHVPAYLOAD_H @@ -8,14 +8,13 @@ struct EMECHVPayload { double voltage[2]; double current[2]; - unsigned int status[2]; int hvLineNo[2]; }; inline std::ostream & operator << (std::ostream & o, const EMECHVPayload & payload) { - o << "Half Gap #0: HV Line No " << payload.hvLineNo[0] << ' ' << payload.voltage[0] << " volts; " << payload.current[0] << " amps; status = " << payload.status[0] << std::endl; - o << "Half Gap #1: HV Line No " << payload.hvLineNo[1] << ' ' << payload.voltage[1] << " volts; " << payload.current[1] << " amps; status = " << payload.status[1] << std::endl; + o << "Half Gap #0: HV Line No " << payload.hvLineNo[0] << ' ' << payload.voltage[0] << " volts; " << payload.current[0] << " amps" << std::endl; + o << "Half Gap #1: HV Line No " << payload.hvLineNo[1] << ' ' << payload.voltage[1] << " volts; " << payload.current[1] << " amps" << std::endl; return o; } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVManager.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVManager.cxx index 655edf3f95ad6f003d1446d93e100fbaf01ac31f..ba6f5be5c64340089862aa87a06ab7c4785b719a 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVManager.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVManager.cxx @@ -32,12 +32,40 @@ #include <atomic> + +namespace { + + +struct ATLAS_NOT_THREAD_SAFE LegacyIdFunc +{ + LegacyIdFunc(); + std::vector<HWIdentifier> operator()(HWIdentifier id) + { + return m_cablingTool->getLArElectrodeIDvec (id); + } + LArHVCablingTool* m_cablingTool; +}; + + +LegacyIdFunc::LegacyIdFunc() +{ + ToolHandle<LArHVCablingTool> tool ("LArHVCablingTool"); + if (!tool.retrieve().isSuccess()) { + std::abort(); + } + m_cablingTool = tool.get(); +} + + +} // Anonymous namespace + + class EMECPresamplerHVManager::Clockwork { public: Clockwork(const EMECPresamplerHVManager* manager) { for(int iSide=0; iSide<2; ++iSide) { for(int iPhi=0; iPhi<64; ++iPhi) { - moduleArray[iSide][iPhi] = new EMECPresamplerHVModule(manager, iSide, iPhi); + moduleArray[iSide][iPhi] = std::make_unique<EMECPresamplerHVModule>(manager, iSide, iPhi); } } ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager"); @@ -50,29 +78,86 @@ public: } } ~Clockwork() { - for(int iSide=0; iSide<2; ++iSide) { - for(int iPhi=0; iPhi<64; ++iPhi) { - delete moduleArray[iSide][iPhi]; - } - } } CellBinning phiBinning{0.0, 2*M_PI, 64}; - const EMECPresamplerHVModule* moduleArray[2][64]; // not dense - std::atomic<bool> init{false}; - std::mutex mtx; - std::vector<EMECPresamplerHVPayload> payloadArray; + std::unique_ptr<const EMECPresamplerHVModule> moduleArray[2][64]; // not dense const LArElectrodeID* elecId; const LArHVLineID* hvId; }; + +class EMECPresamplerHVManager::EMECPresamplerHVData::Payload +{ +public: + std::vector<EMECPresamplerHVPayload> m_payloadArray; +}; + + +EMECPresamplerHVManager::EMECPresamplerHVData::EMECPresamplerHVData() +{ +} + + +EMECPresamplerHVManager::EMECPresamplerHVData::EMECPresamplerHVData + (std::unique_ptr<Payload> payload) + : m_payload (std::move (payload)) +{ +} + + +EMECPresamplerHVManager::EMECPresamplerHVData& +EMECPresamplerHVManager::EMECPresamplerHVData::operator= (EMECPresamplerHVData&& other) +{ + if (this != &other) { + m_payload = std::move (other.m_payload); + } + return *this; +} + + +EMECPresamplerHVManager::EMECPresamplerHVData::~EMECPresamplerHVData() +{ +} + + +double EMECPresamplerHVManager::EMECPresamplerHVData::voltage + (const EMECPresamplerHVModule& module, const int& /*iGap*/) const +{ + return m_payload->m_payloadArray[index(module)].voltage; +} + + +double EMECPresamplerHVManager::EMECPresamplerHVData::current + (const EMECPresamplerHVModule& module, const int& /*iGap*/) const +{ + return m_payload->m_payloadArray[index(module)].current; +} + + +int EMECPresamplerHVManager::EMECPresamplerHVData::hvLineNo + (const EMECPresamplerHVModule& module, const int& /*iGap*/) const +{ + return m_payload->m_payloadArray[index(module)].hvLineNo; +} + + +int EMECPresamplerHVManager::EMECPresamplerHVData::index + (const EMECPresamplerHVModule& module) const +{ + unsigned int phiIndex = module.getPhiIndex(); + unsigned int sideIndex = module.getSideIndex(); + unsigned int index = 64*sideIndex+phiIndex; + return index; +} + + EMECPresamplerHVManager::EMECPresamplerHVManager() - : m_c(new Clockwork(this)) + : m_c (std::make_unique<Clockwork> (this)) { } EMECPresamplerHVManager::~EMECPresamplerHVManager() { - delete m_c; } const CellBinning *EMECPresamplerHVManager::getPhiBinning() const @@ -105,73 +190,47 @@ unsigned int EMECPresamplerHVManager::endSideIndex() const return 2; } -void EMECPresamplerHVManager::update() const { - std::lock_guard<std::mutex> lock(m_c->mtx); - if (!(m_c->init)) { - m_c->init=true; - { - m_c->payloadArray.reserve(2*64); - for (unsigned int i=0;i<64;i++) { - m_c->payloadArray[i].voltage[0]=-99999; - m_c->payloadArray[i].voltage[1]=-99999; - } - } +EMECPresamplerHVManager::EMECPresamplerHVData +EMECPresamplerHVManager::getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto payload = std::make_unique<EMECPresamplerHVData::Payload>(); + payload->m_payloadArray.reserve(2*64); + for (unsigned int i=0;i<64;i++) { + payload->m_payloadArray[i].voltage=-99999.; + } - ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager"); - - ISvcLocator* svcLocator = Gaudi::svcLocator(); - IToolSvc* toolSvc; - LArHVCablingTool* hvcablingTool; + for (const CondAttrListCollection* atrlistcol : attrLists) { - if(StatusCode::SUCCESS!=svcLocator->service("ToolSvc",toolSvc)) - return; - - if(StatusCode::SUCCESS!=toolSvc->retrieveTool("LArHVCablingTool",hvcablingTool)) - return; - - std::vector<std::string> colnames; - colnames.push_back("/LAR/DCS/HV/BARREl/I16"); - colnames.push_back("/LAR/DCS/HV/BARREL/I8"); - - std::vector<std::string>::const_iterator it = colnames.begin(); - std::vector<std::string>::const_iterator ie = colnames.end(); - - for (;it!=ie;it++) { - - //std::cout << " --- Start reading folder " << (*it) << std::endl; - const CondAttrListCollection* atrlistcol; - if (StatusCode::SUCCESS!=detStore->retrieve(atrlistcol,*it)) - return; - - for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { + for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { - // Construct HWIdentifier - // 1. decode COOL Channel ID - unsigned int chanID = (*citr).first; - int cannode = chanID/1000; - int line = chanID%1000; - //std::cout << " ++ found data for cannode, line " << cannode << " " << line << std::endl; + // Construct HWIdentifier + // 1. decode COOL Channel ID + unsigned int chanID = (*citr).first; + int cannode = chanID/1000; + int line = chanID%1000; + //std::cout << " ++ found data for cannode, line " << cannode << " " << line << std::endl; - // 2. Construct the identifier - HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); + // 2. Construct the identifier + HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); - std::vector<HWIdentifier> electrodeIdVec = hvcablingTool->getLArElectrodeIDvec(id); + std::vector<HWIdentifier> electrodeIdVec = idfunc(id); - for(size_t i=0;i<electrodeIdVec.size();i++) { - HWIdentifier& elecHWID = electrodeIdVec[i]; - int detector = m_c->elecId->detector(elecHWID); - // check we are in EMECPresampler - if (detector==3) { + for(size_t i=0;i<electrodeIdVec.size();i++) { + HWIdentifier& elecHWID = electrodeIdVec[i]; + int detector = m_c->elecId->detector(elecHWID); + // check we are in EMECPresampler + if (detector==3) { - unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); - unsigned int phiIndex=m_c->elecId->module(elecHWID); // from 0 to 31 + unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); + unsigned int phiIndex=m_c->elecId->module(elecHWID); // from 0 to 31 // rotation for C side - if (sideIndex==0) { - if (phiIndex<16) phiIndex=15-phiIndex; - else phiIndex=47-phiIndex; - } + if (sideIndex==0) { + if (phiIndex<16) phiIndex=15-phiIndex; + else phiIndex=47-phiIndex; + } // GU January 2017 - fix for HV EMEC PS distribution // 0-31 in phi module @@ -181,48 +240,55 @@ void EMECPresamplerHVManager::update() const { // so in total 64 sectors in phi given by 2*phiIndex+gapIndex // the two gap of these sectors are powered by the same line and have the same HV - unsigned int gapIndex=m_c->elecId->gap(elecHWID); + unsigned int gapIndex=m_c->elecId->gap(elecHWID); - unsigned int index = 64*sideIndex+2*phiIndex+gapIndex; + unsigned int index = 64*sideIndex+2*phiIndex+gapIndex; - float voltage = -99999.; - if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); - float current = 0.; - if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - unsigned int status = 0; - if (!((*citr).second)["R_STAT"].isNull()) status = ((*citr).second)["R_STAT"].data<unsigned int>(); - - - for (unsigned int gap=0;gap<2;gap++) { - m_c->payloadArray[index].voltage[gap]=voltage; - m_c->payloadArray[index].current[gap]=current; - m_c->payloadArray[index].status[gap]=status; - m_c->payloadArray[index].hvLineNo[gap]=chanID; - } - } // for (electrodeIdVec) - } // is EMECPresampler - } // for (atrlistcol) - } - } // if(!m_c->init) + float voltage = -99999.; + if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); + float current = 0.; + if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); + + + payload->m_payloadArray[index].voltage=voltage; + payload->m_payloadArray[index].current=current; + payload->m_payloadArray[index].hvLineNo=chanID; + } // for (electrodeIdVec) + } // is EMECPresampler + } // for (atrlistcol) + } + + return EMECPresamplerHVManager::EMECPresamplerHVData (std::move (payload)); } -void EMECPresamplerHVManager::reset() const { - m_c->init=false; +EMECPresamplerHVManager::EMECPresamplerHVData +EMECPresamplerHVManager::getData ATLAS_NOT_THREAD_SAFE () const +{ + std::vector<const CondAttrListCollection*> attrLists; + ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "EMBHVManager"); + const CondAttrListCollection* atrlistcol = nullptr; + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I16").isSuccess()) { + attrLists.push_back (atrlistcol); + } + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I8").isSuccess()) { + attrLists.push_back (atrlistcol); + } + return getData (LegacyIdFunc(), attrLists); } -EMECPresamplerHVPayload *EMECPresamplerHVManager::getPayload(const EMECPresamplerHVModule & module) const { - update(); - unsigned int phiIndex = module.getPhiIndex(); - unsigned int sideIndex = module.getSideIndex(); - - unsigned int index = 64*sideIndex+phiIndex; - return &m_c->payloadArray[index]; +#if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) +EMECPresamplerHVManager::EMECPresamplerHVData +EMECPresamplerHVManager::getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto idfunc = [&] (HWIdentifier id) { return hvIdMapping.getLArElectrodeIDvec(id); }; + return getData (idfunc, attrLists); } -#if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) + int EMECPresamplerHVManager::hvLineNo(const EMECPresamplerHVModule& module , const LArHVIdMapping* hvIdMapping) const { int sideIndex = module.getSideIndex(); diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVModule.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVModule.cxx index 077dee06afa7290ebfc5b044ef65c41e1362e542..7ab3bbe7c825f007e82b3c5636fa6855941c9690 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVModule.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVModule.cxx @@ -70,39 +70,9 @@ const EMECPresamplerHVManager& EMECPresamplerHVModule::getManager() const return *(m_c->manager); } -bool EMECPresamplerHVModule::hvOn(int iGap ) const -{ - EMECPresamplerHVPayload *payload = getManager().getPayload(*this); - return (payload->voltage[iGap]>=-9999); -} - -double EMECPresamplerHVModule::voltage(int iGap) const { - EMECPresamplerHVPayload *payload = getManager().getPayload(*this); - return payload->voltage[iGap]; -} - -double EMECPresamplerHVModule::current(int iGap) const { - EMECPresamplerHVPayload *payload = getManager().getPayload(*this); - return payload->current[iGap]; -} - -void EMECPresamplerHVModule::voltage_current(int iGap,double& voltage, double¤t) const -{ - EMECPresamplerHVPayload *payload = getManager().getPayload(*this); - voltage = payload->voltage[iGap]; - current = payload->current[iGap]; -} - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) -int EMECPresamplerHVModule::hvLineNo(int iGap, const LArHVIdMapping* hvIdMapping) const -{ - return hvIdMapping - ? getManager().hvLineNo(*this,hvIdMapping) - : getManager().getPayload(*this)->hvLineNo[iGap]; -} -#else -int EMECPresamplerHVModule::hvLineNo(int iGap) const +int EMECPresamplerHVModule::hvLineNo(int /*iGap*/, const LArHVIdMapping* hvIdMapping) const { - return getManager().getPayload(*this)->hvLineNo[iGap]; + return getManager().hvLineNo(*this,hvIdMapping); } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVPayload.h b/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVPayload.h index a4796090e4e3ccbe5a2ce559b8c286aa3da9b469..a6544ebcb90154d73bd96942f9fee7778aee718d 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVPayload.h +++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVPayload.h @@ -1,20 +1,18 @@ /* - 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 LARHV_EMECPRESAMPLERHVPAYLOAD_H #define LARHV_EMECPRESAMPLERHVPAYLOAD_H #include <iostream> struct EMECPresamplerHVPayload { - double voltage[2]; - double current[2]; - unsigned int status[2]; - int hvLineNo[2]; + double voltage; + double current; + int hvLineNo; }; inline std::ostream & operator << (std::ostream & o, const EMECPresamplerHVPayload & payload) { - o << "Half Gap #0: HV Line No " << payload.hvLineNo[0] << ' ' << payload.voltage[0] << " volts; " << payload.current[0] << " amps; status = " << payload.status[0] << std::endl; - o << "Half Gap #1: HV Line No " << payload.hvLineNo[1] << ' ' << payload.voltage[1] << " volts; " << payload.current[1] << " amps; status = " << payload.status[1] << std::endl; + o << "HV Line No " << payload.hvLineNo << ' ' << payload.voltage << " volts; " << payload.current << " amps" << std::endl; return o; } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVLine.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVLine.cxx index 16c671eb3f14550a48226b61e0451f568e61de62..f2681297e593d5668559ce4002b0cab7f5f41639 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVLine.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVLine.cxx @@ -40,36 +40,8 @@ unsigned int FCALHVLine::getLineIndex() const return m_c->iLine; } -bool FCALHVLine::hvOn() const -{ - FCALHVPayload *payload = m_c->module->getManager().getPayload(*this); - return (payload->voltage>=-9999); -} - -double FCALHVLine::voltage() const { - FCALHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->voltage; -} - -double FCALHVLine::current() const { - FCALHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->current; -} - -void FCALHVLine::voltage_current(double& voltage, double¤t) const { - FCALHVPayload *payload = m_c->module->getManager().getPayload(*this); - voltage = payload->voltage; - current = payload->current; -} - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) int FCALHVLine::hvLineNo(const LArHVIdMapping* hvIdMapping) const { - return hvIdMapping - ? m_c->module->getManager().hvLineNo(*this,hvIdMapping) - : m_c->module->getManager().getPayload(*this)->hvLineNo; -} -#else -int FCALHVLine::hvLineNo() const { - return m_c->module->getManager().getPayload(*this)->hvLineNo; + return m_c->module->getManager().hvLineNo(*this,hvIdMapping); } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVManager.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVManager.cxx index 632e1295db295f9b02a333f402235ab9bf85f5f5..e58d4120df7c709a1ad76abdbb5394405a5f6714 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVManager.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVManager.cxx @@ -25,6 +25,34 @@ #include <atomic> + +namespace { + + +struct ATLAS_NOT_THREAD_SAFE LegacyIdFunc +{ + LegacyIdFunc(); + std::vector<HWIdentifier> operator()(HWIdentifier id) + { + return m_cablingTool->getLArElectrodeIDvec (id); + } + LArHVCablingTool* m_cablingTool; +}; + + +LegacyIdFunc::LegacyIdFunc() +{ + ToolHandle<LArHVCablingTool> tool ("LArHVCablingTool"); + if (!tool.retrieve().isSuccess()) { + std::abort(); + } + m_cablingTool = tool.get(); +} + + +} // Anonymous namespace + + class FCALHVManager::Clockwork { public: Clockwork(const FCALHVManager* manager) @@ -32,7 +60,7 @@ public: for(int iSide=0; iSide<2; ++iSide) { for(int iSector=0; iSector<16; ++iSector) { for(int iSampling=0; iSampling<3; ++iSampling) { - moduleArray[iSide][iSector][iSampling] = new FCALHVModule(manager,iSide,iSector,iSampling); + moduleArray[iSide][iSector][iSampling] = std::make_unique<FCALHVModule>(manager,iSide,iSector,iSampling); } } } @@ -48,30 +76,83 @@ public: } ~Clockwork() { - for(int iSide=0; iSide<2; ++iSide) { - for(int iSector=0; iSector<16; ++iSector) { - for(int iSampling=0; iSampling<3; ++iSampling) { - delete moduleArray[iSide][iSector][iSampling]; - } - } - } } - const FCALHVModule* moduleArray[2][16][3]; - std::atomic<bool> init{false}; - std::mutex mtx; - std::vector<FCALHVPayload> payloadArray; + std::unique_ptr<const FCALHVModule> moduleArray[2][16][3]; const LArElectrodeID* elecId; const LArHVLineID* hvId; }; + +class FCALHVManager::FCALHVData::Payload +{ +public: + std::vector<FCALHVPayload> m_payloadArray; +}; + + +FCALHVManager::FCALHVData::FCALHVData() +{ +} + + +FCALHVManager::FCALHVData::FCALHVData (std::unique_ptr<Payload> payload) + : m_payload (std::move (payload)) +{ +} + + +FCALHVManager::FCALHVData& +FCALHVManager::FCALHVData::operator= (FCALHVData&& other) +{ + if (this != &other) { + m_payload = std::move (other.m_payload); + } + return *this; +} + + +FCALHVManager::FCALHVData::~FCALHVData() +{ +} + + +double FCALHVManager::FCALHVData::voltage (const FCALHVLine& line) const +{ + return m_payload->m_payloadArray[index(line)].voltage; +} + + +double FCALHVManager::FCALHVData::current (const FCALHVLine& line) const +{ + return m_payload->m_payloadArray[index(line)].current; +} + + +int FCALHVManager::FCALHVData::hvLineNo (const FCALHVLine& line) const +{ + return m_payload->m_payloadArray[index(line)].hvLineNo; +} + + +int FCALHVManager::FCALHVData::index (const FCALHVLine& line) const +{ + unsigned int lineIndex = line.getLineIndex(); + const FCALHVModule& module = line.getModule(); + unsigned int sectorIndex = module.getSectorIndex(); + unsigned int sideIndex = module.getSideIndex(); + unsigned int samplingIndex = module.getSamplingIndex(); + unsigned int index = 192*sideIndex+12*sectorIndex+4*samplingIndex+lineIndex; + return index; +} + + FCALHVManager::FCALHVManager() - : m_c(new Clockwork(this)) + : m_c (std::make_unique<Clockwork> (this)) { } FCALHVManager::~FCALHVManager() { - delete m_c; } unsigned int FCALHVManager::beginSideIndex() const @@ -112,115 +193,98 @@ const FCALHVModule& FCALHVManager::getHVModule(unsigned int iSide, unsigned int return *(m_c->moduleArray[iSide][iSector][iSampling]); } -void FCALHVManager::update() const { - std::lock_guard<std::mutex> lock(m_c->mtx); - if (!(m_c->init)) { - m_c->init=true; - m_c->payloadArray.reserve(2*16*3*4); - for (unsigned int i=0;i<384;i++) { - m_c->payloadArray[i].voltage = -99999; - } - - ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager"); - - ISvcLocator* svcLocator = Gaudi::svcLocator(); - IToolSvc* toolSvc; - LArHVCablingTool* hvcablingTool; - - if(StatusCode::SUCCESS!=svcLocator->service("ToolSvc",toolSvc)) - return; - - if(StatusCode::SUCCESS!=toolSvc->retrieveTool("LArHVCablingTool",hvcablingTool)) - return; - - std::vector<std::string> colnames; - colnames.push_back("/LAR/DCS/HV/BARREl/I16"); - colnames.push_back("/LAR/DCS/HV/BARREL/I8"); - - std::vector<std::string>::const_iterator it = colnames.begin(); - std::vector<std::string>::const_iterator ie = colnames.end(); - - for (;it!=ie;it++) { +FCALHVManager::FCALHVData +FCALHVManager::getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto payload = std::make_unique<FCALHVData::Payload>(); + payload->m_payloadArray.reserve(2*16*3*4); + for (unsigned int i=0;i<384;i++) { + payload->m_payloadArray[i].voltage=-99999.; + } - //std::cout << " --- Start reading folder " << (*it) << std::endl; - const CondAttrListCollection* atrlistcol; - if (StatusCode::SUCCESS!=detStore->retrieve(atrlistcol,*it)) - return; + for (const CondAttrListCollection* atrlistcol : attrLists) { - for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { + for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { - // 1. decode COOL Channel ID - unsigned int chanID = (*citr).first; - int cannode = chanID/1000; - int line = chanID%1000; - //std::cout << " cannode,line " << cannode << " " << line << std::endl; + // 1. decode COOL Channel ID + unsigned int chanID = (*citr).first; + int cannode = chanID/1000; + int line = chanID%1000; + //std::cout << " cannode,line " << cannode << " " << line << std::endl; - // 2. Construct the identifier - HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); + // 2. Construct the identifier + HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); - std::vector<HWIdentifier> electrodeIdVec = hvcablingTool->getLArElectrodeIDvec(id); + std::vector<HWIdentifier> electrodeIdVec = idfunc(id); - for(size_t i=0;i<electrodeIdVec.size();i++) { + for(size_t i=0;i<electrodeIdVec.size();i++) { - HWIdentifier& elecHWID = electrodeIdVec[i]; - int detector = m_c->elecId->detector(elecHWID); - if (detector==5) { + HWIdentifier& elecHWID = electrodeIdVec[i]; + int detector = m_c->elecId->detector(elecHWID); + if (detector==5) { - //std::cout << " FCAl channel found " << (*citr).first << std::endl; + //std::cout << " FCAl channel found " << (*citr).first << std::endl; - float voltage = -99999.; - if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); - float current = 0.; - if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - unsigned int status = 0; - if (!((*citr).second)["R_STAT"].isNull()) status = ((*citr).second)["R_STAT"].data<unsigned int>(); + float voltage = -99999.; + if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); + float current = 0.; + if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); // 0 C side, 1 A side (unline HV numbering) - unsigned int samplingIndex=m_c->elecId->hv_eta(elecHWID)-1; // 0 to 2 for the FCAL modules 1-2-3 - unsigned int sectorIndex=m_c->elecId->module(elecHWID); // 0-15 FCAL1, 0-7 FCAl2, 0-3 FCAL3 - unsigned int lineIndex=m_c->elecId->gap(elecHWID); // 0-3 + unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); // 0 C side, 1 A side (unline HV numbering) + unsigned int samplingIndex=m_c->elecId->hv_eta(elecHWID)-1; // 0 to 2 for the FCAL modules 1-2-3 + unsigned int sectorIndex=m_c->elecId->module(elecHWID); // 0-15 FCAL1, 0-7 FCAl2, 0-3 FCAL3 + unsigned int lineIndex=m_c->elecId->gap(elecHWID); // 0-3 - //std::cout << " channel found " << sideIndex << " " << samplingIndex << " " << sectorIndex << " " << lineIndex << " "<< voltage << std::endl; + //std::cout << " channel found " << sideIndex << " " << samplingIndex << " " << sectorIndex << " " << lineIndex << " "<< voltage << std::endl; - // do we have to worry about phi sector numbering running backwards in phi for z<0 like in EM/HEC ???? + // do we have to worry about phi sector numbering running backwards in phi for z<0 like in EM/HEC ???? - unsigned int index = 192*sideIndex+12*sectorIndex+4*samplingIndex+lineIndex; + unsigned int index = 192*sideIndex+12*sectorIndex+4*samplingIndex+lineIndex; - if (index>384) { - std::cout << " invalid index for FCAL " << sideIndex << " " << samplingIndex << " " << sectorIndex << " " << lineIndex << std::endl; - continue; - } + if (index>384) { + std::cout << " invalid index for FCAL " << sideIndex << " " << samplingIndex << " " << sectorIndex << " " << lineIndex << std::endl; + continue; + } - m_c->payloadArray[index].voltage=voltage; - m_c->payloadArray[index].current=current; - m_c->payloadArray[index].status=status; - m_c->payloadArray[index].hvLineNo=chanID; - } // if FCAL - } // loop over electrodes - } // loop over collection - } // loop over folders - } // m_c->init + payload->m_payloadArray[index].voltage=voltage; + payload->m_payloadArray[index].current=current; + payload->m_payloadArray[index].hvLineNo=chanID; + } // if FCAL + } // loop over electrodes + } // loop over collection + } // loop over folders + + return FCALHVManager::FCALHVData (std::move (payload)); } -void FCALHVManager::reset() const { - m_c->init=false; +FCALHVManager::FCALHVData +FCALHVManager::getData ATLAS_NOT_THREAD_SAFE () const +{ + std::vector<const CondAttrListCollection*> attrLists; + ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "EMBHVManager"); + const CondAttrListCollection* atrlistcol = nullptr; + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I16").isSuccess()) { + attrLists.push_back (atrlistcol); + } + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I8").isSuccess()) { + attrLists.push_back (atrlistcol); + } + return getData (LegacyIdFunc(), attrLists); } -FCALHVPayload *FCALHVManager::getPayload(const FCALHVLine &line) const { - update(); - unsigned int lineIndex = line.getLineIndex(); - const FCALHVModule& module = line.getModule(); - unsigned int sectorIndex = module.getSectorIndex(); - unsigned int sideIndex = module.getSideIndex(); - unsigned int samplingIndex = module.getSamplingIndex(); - unsigned int index = 192*sideIndex+12*sectorIndex+4*samplingIndex+lineIndex; - //std::cout << "in Fcal getPayload: " << this << ' ' << index << ' ' << sideIndex << ' ' << sectorIndex << ' ' << samplingIndex << ' ' << lineIndex << std::endl; - return &m_c->payloadArray[index]; + +#if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) +FCALHVManager::FCALHVData +FCALHVManager::getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto idfunc = [&] (HWIdentifier id) { return hvIdMapping.getLArElectrodeIDvec(id); }; + return getData (idfunc, attrLists); } -#if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) int FCALHVManager::hvLineNo(const FCALHVLine& line , const LArHVIdMapping* hvIdMapping) const { diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVPayload.h b/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVPayload.h index cfff045575b8043399dc0f226e91a921c452add5..96dacaaafef109f69021eab3ad0d34b6e83bc2a1 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVPayload.h +++ b/LArCalorimeter/LArGeoModel/LArHV/src/FCALHVPayload.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 LARHV_FCALHVPAYLOAD_H @@ -8,12 +8,11 @@ struct FCALHVPayload { double voltage; double current; - unsigned int status; int hvLineNo; }; inline std::ostream & operator << (std::ostream & o, const FCALHVPayload & payload) { - o << "FCAL Line: HV Line No " << payload.hvLineNo << ' ' << payload.voltage << " volts; " << payload.current << " amps; status = " << payload.status << std::endl; + o << "FCAL Line: HV Line No " << payload.hvLineNo << ' ' << payload.voltage << " volts; " << payload.current << " amps" << std::endl; return o; } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/HECHVManager.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/HECHVManager.cxx index 0849948926979b383b112ea58a1e66603419c62f..8128556606a26b5fe0ae8f858bdbea9e36799396 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/HECHVManager.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/HECHVManager.cxx @@ -28,6 +28,34 @@ #include "Identifier/HWIdentifier.h" + +namespace { + + +struct ATLAS_NOT_THREAD_SAFE LegacyIdFunc +{ + LegacyIdFunc(); + std::vector<HWIdentifier> operator()(HWIdentifier id) + { + return m_cablingTool->getLArElectrodeIDvec (id); + } + LArHVCablingTool* m_cablingTool; +}; + + +LegacyIdFunc::LegacyIdFunc() +{ + ToolHandle<LArHVCablingTool> tool ("LArHVCablingTool"); + if (!tool.retrieve().isSuccess()) { + std::abort(); + } + m_cablingTool = tool.get(); +} + + +} // Anonymous namespace + + class HECHVManager::Clockwork { public: Clockwork(const HECHVManager* manager) @@ -35,7 +63,7 @@ public: for(int iSide=0; iSide<2; ++iSide) { for(int iPhi=0; iPhi<32; ++iPhi) { for(int iSampling=0; iSampling<4; ++iSampling) { - moduleArray[iSide][iPhi][iSampling] = new HECHVModule(manager,iSide,iPhi,iSampling); + moduleArray[iSide][iPhi][iSampling] = std::make_unique<HECHVModule>(manager,iSide,iPhi,iSampling); } } } @@ -51,25 +79,79 @@ public: } ~Clockwork() { - for(int iSide=0; iSide<2; ++iSide) { - for(int iPhi=0; iPhi<32; ++iPhi) { - for(int iSampling=0; iSampling<4; ++iSampling) { - delete moduleArray[iSide][iPhi][iSampling]; - } - } - } } HECHVDescriptor descriptor{CellBinning(0,2*M_PI,32)}; - const HECHVModule* moduleArray[2][32][4]; - std::atomic<bool> init{false}; - std::mutex mtx; - std::vector<HECHVPayload> payloadArray; + std::unique_ptr<const HECHVModule> moduleArray[2][32][4]; const LArElectrodeID* elecId; const LArHVLineID* hvId; }; + +class HECHVManager::HECHVData::Payload +{ +public: + std::vector<HECHVPayload> m_payloadArray; +}; + + +HECHVManager::HECHVData::HECHVData() +{ +} + + +HECHVManager::HECHVData::HECHVData (std::unique_ptr<Payload> payload) + : m_payload (std::move (payload)) +{ +} + + +HECHVManager::HECHVData& +HECHVManager::HECHVData::operator= (HECHVData&& other) +{ + if (this != &other) { + m_payload = std::move (other.m_payload); + } + return *this; +} + + +HECHVManager::HECHVData::~HECHVData() +{ +} + + +double HECHVManager::HECHVData::voltage (const HECHVSubgap& subgap) const +{ + return m_payload->m_payloadArray[index(subgap)].voltage; +} + + +double HECHVManager::HECHVData::current (const HECHVSubgap& subgap) const +{ + return m_payload->m_payloadArray[index(subgap)].current; +} + + +int HECHVManager::HECHVData::hvLineNo (const HECHVSubgap& subgap) const +{ + return m_payload->m_payloadArray[index(subgap)].hvLineNo; +} + + +int HECHVManager::HECHVData::index (const HECHVSubgap& subgap) const +{ + unsigned int subgapIndex = subgap.getSubgapIndex(); + const HECHVModule& module = subgap.getModule(); + unsigned int phiIndex = module.getPhiIndex(); + unsigned int samplingIndex = module.getSamplingIndex(); + unsigned int sideIndex = module.getSideIndex(); + unsigned int index = 512*sideIndex+16*phiIndex+4*samplingIndex+subgapIndex; + return index; +} + + HECHVManager::HECHVManager() - : m_c(new Clockwork(this)) + : m_c (std::make_unique<Clockwork> (this)) { } @@ -117,116 +199,101 @@ const HECHVModule& HECHVManager::getHVModule(unsigned int iSide HECHVManager::~HECHVManager() { - delete m_c; } -void HECHVManager::update() const { - std::lock_guard<std::mutex> lock(m_c->mtx); - if (!(m_c->init)) { - m_c->init=true; - m_c->payloadArray.reserve(2*32*4*4); - for (unsigned int i=0;i<1024;i++) { - m_c->payloadArray[i].voltage = -99999; - } - - ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager"); - - ISvcLocator* svcLocator = Gaudi::svcLocator(); - IToolSvc* toolSvc; - LArHVCablingTool* hvcablingTool; - - if(StatusCode::SUCCESS!=svcLocator->service("ToolSvc",toolSvc)) - return; - - if(StatusCode::SUCCESS!=toolSvc->retrieveTool("LArHVCablingTool",hvcablingTool)) - return; +HECHVManager::HECHVData +HECHVManager::getData (idfunc_t idfunc, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto payload = std::make_unique<HECHVData::Payload>(); + payload->m_payloadArray.reserve(2*32*4*4); + for (unsigned int i=0;i<1024;i++) { + payload->m_payloadArray[i].voltage=-99999.; + } - std::vector<std::string> colnames; - colnames.push_back("/LAR/DCS/HV/BARREl/I16"); - colnames.push_back("/LAR/DCS/HV/BARREL/I8"); + for (const CondAttrListCollection* atrlistcol : attrLists) { - std::vector<std::string>::const_iterator it = colnames.begin(); - std::vector<std::string>::const_iterator ie = colnames.end(); + for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { - for (;it!=ie;it++) { + // Construct HWIdentifier + // 1. decode COOL Channel ID + unsigned int chanID = (*citr).first; + int cannode = chanID/1000; + int line = chanID%1000; - //std::cout << " --- Start reading folder " << (*it) << std::endl; - const CondAttrListCollection* atrlistcol; - if (StatusCode::SUCCESS!=detStore->retrieve(atrlistcol,*it)) - return; + // 2. Construct the identifier + HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); - for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { + std::vector<HWIdentifier> electrodeIdVec = idfunc(id); - // Construct HWIdentifier - // 1. decode COOL Channel ID - unsigned int chanID = (*citr).first; - int cannode = chanID/1000; - int line = chanID%1000; + for(size_t i=0;i<electrodeIdVec.size();i++) { + HWIdentifier& elecHWID = electrodeIdVec[i]; - // 2. Construct the identifier - HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line); + int detector = m_c->elecId->detector(elecHWID); - std::vector<HWIdentifier> electrodeIdVec = hvcablingTool->getLArElectrodeIDvec(id); + // check we are in HEC + if (detector != 4) { + //std::cout << " Not HEC ??? " << std::endl; + continue; + } - for(size_t i=0;i<electrodeIdVec.size();i++) { - HWIdentifier& elecHWID = electrodeIdVec[i]; + float voltage = -99999.; + if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); + float current = 0.; + if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - int detector = m_c->elecId->detector(elecHWID); + + unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); // 0 for C side, 1 for A side, opposite to HV numbering + unsigned int phiIndex=m_c->elecId->module(elecHWID); // 0 to 31 + unsigned int samplingIndex=m_c->elecId->hv_eta(elecHWID)-1; // 0 to 3 + unsigned int subgapIndex=m_c->elecId->gap(elecHWID); // 0 to 3 - // check we are in HEC - if (detector != 4) { - //std::cout << " Not HEC ??? " << std::endl; - continue; - } + unsigned int index = 512*sideIndex+16*phiIndex+4*samplingIndex+subgapIndex; - float voltage = -99999.; - if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>(); - float current = 0.; - if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>(); - unsigned int status = 0; - if (!((*citr).second)["R_STAT"].isNull()) status = ((*citr).second)["R_STAT"].data<unsigned int>(); + if (index>1023) { + std::cout << "invalid index " << index << " side,phi,sampling,gap " << sideIndex << " " << phiIndex << " " << samplingIndex + << " " << subgapIndex << std::endl; + continue; + } - unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); // 0 for C side, 1 for A side, opposite to HV numbering - unsigned int phiIndex=m_c->elecId->module(elecHWID); // 0 to 31 - unsigned int samplingIndex=m_c->elecId->hv_eta(elecHWID)-1; // 0 to 3 - unsigned int subgapIndex=m_c->elecId->gap(elecHWID); // 0 to 3 + payload->m_payloadArray[index].voltage=voltage; + payload->m_payloadArray[index].current=current; + payload->m_payloadArray[index].hvLineNo=chanID; + } // For (electrodeIdVec) + } // for (atrlistcol) + } - unsigned int index = 512*sideIndex+16*phiIndex+4*samplingIndex+subgapIndex; + return HECHVManager::HECHVData (std::move (payload)); +} - if (index>1023) { - std::cout << "invalid index " << index << " side,phi,sampling,gap " << sideIndex << " " << phiIndex << " " << samplingIndex - << " " << subgapIndex << std::endl; - continue; - } - - m_c->payloadArray[index].voltage=voltage; - m_c->payloadArray[index].current=current; - m_c->payloadArray[index].status=status; - m_c->payloadArray[index].hvLineNo=chanID; - } // For (electrodeIdVec) - } // for (atrlistcol) - } - } // if(!m_c->init) +HECHVManager::HECHVData +HECHVManager::getData ATLAS_NOT_THREAD_SAFE () const +{ + std::vector<const CondAttrListCollection*> attrLists; + ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "EMBHVManager"); + const CondAttrListCollection* atrlistcol = nullptr; + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I16").isSuccess()) { + attrLists.push_back (atrlistcol); + } + if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I8").isSuccess()) { + attrLists.push_back (atrlistcol); + } + return getData (LegacyIdFunc(), attrLists); } -void HECHVManager::reset() const { - m_c->init=false; -} -HECHVPayload *HECHVManager::getPayload(const HECHVSubgap &subgap) const { - update(); - unsigned int subgapIndex = subgap.getSubgapIndex(); - const HECHVModule& module = subgap.getModule(); - unsigned int phiIndex = module.getPhiIndex(); - unsigned int samplingIndex = module.getSamplingIndex(); - unsigned int sideIndex = module.getSideIndex(); - unsigned int index = 512*sideIndex+16*phiIndex+4*samplingIndex+subgapIndex; - return &m_c->payloadArray[index]; +#if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) +HECHVManager::HECHVData +HECHVManager::getData (const LArHVIdMapping& hvIdMapping, + const std::vector<const CondAttrListCollection*>& attrLists) const +{ + auto idfunc = [&] (HWIdentifier id) { return hvIdMapping.getLArElectrodeIDvec(id); }; + return getData (idfunc, attrLists); } -#if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) + int HECHVManager::hvLineNo(const HECHVSubgap& subgap , const LArHVIdMapping* hvIdMapping) const { const HECHVModule& module = subgap.getModule(); diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/HECHVPayload.h b/LArCalorimeter/LArGeoModel/LArHV/src/HECHVPayload.h index 977dff9d7984b159ceafa46d2837091c8bb3ea02..bbaa5d2b26d57643c86785b2e3f655589d2b3bc8 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/HECHVPayload.h +++ b/LArCalorimeter/LArGeoModel/LArHV/src/HECHVPayload.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 LARHV_HECHVPAYLOAD_H @@ -8,12 +8,11 @@ struct HECHVPayload { double voltage; double current; - unsigned int status; int hvLineNo; }; inline std::ostream & operator << (std::ostream & o, const HECHVPayload & payload) { - o << "HEC Subgap: HV Line No " << payload.hvLineNo << ' ' << payload.voltage << " volts; " << payload.current << " amps; status = " << payload.status << std::endl; + o << "HEC Subgap: HV Line No " << payload.hvLineNo << ' ' << payload.voltage << " volts; " << payload.current << " amps" << std::endl; return o; } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/HECHVSubgap.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/HECHVSubgap.cxx index 8a0297cefdd4f0730bb4d0e738460699954cbee7..e2c94187b5f21e63499f81353026635137283a3d 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/HECHVSubgap.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/HECHVSubgap.cxx @@ -41,37 +41,8 @@ unsigned int HECHVSubgap::getSubgapIndex() const return m_c->iSubgap; } -bool HECHVSubgap::hvOn() const -{ - HECHVPayload *payload = m_c->module->getManager().getPayload(*this); - return (payload->voltage>=-9999); -} - -double HECHVSubgap::voltage() const { - HECHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->voltage; -} - - -double HECHVSubgap::current() const { - HECHVPayload *payload = m_c->module->getManager().getPayload(*this); - return payload->current; -} - -void HECHVSubgap::voltage_current(double& voltage, double¤t) const { - HECHVPayload *payload = m_c->module->getManager().getPayload(*this); - voltage = payload->voltage; - current = payload->current; -} - #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE)) int HECHVSubgap::hvLineNo(const LArHVIdMapping* hvIdMapping) const { - return hvIdMapping - ? m_c->module->getManager().hvLineNo(*this,hvIdMapping) - : m_c->module->getManager().getPayload(*this)->hvLineNo; -} -#else -int HECHVSubgap::hvLineNo() const { - return m_c->module->getManager().getPayload(*this)->hvLineNo; + return m_c->module->getManager().hvLineNo(*this,hvIdMapping); } #endif diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/LArHVManager.cxx b/LArCalorimeter/LArGeoModel/LArHV/src/LArHVManager.cxx index 1bcef1d250729d8e3c43a22017a9538118d038d2..94e3a9afec476074de7a3acf3d9d75c752940972 100644 --- a/LArCalorimeter/LArGeoModel/LArHV/src/LArHVManager.cxx +++ b/LArCalorimeter/LArGeoModel/LArHV/src/LArHVManager.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 "LArHV/LArHVManager.h" @@ -21,18 +21,6 @@ LArHVManager::LArHVManager() { } -void LArHVManager::reset() const -{ - m_embHV.reset(); - m_emecHVInner.reset(); - m_emecHVOuter.reset(); - m_hecHV.reset(); - m_fcalHV.reset(); - m_embPreHV.reset(); - m_emecPreHV.reset(); -} - - LArHVManager::~LArHVManager() { }