diff --git a/LArCalorimeter/LArCondUtils/LArCondUtils/LArFEBTempTool.h b/LArCalorimeter/LArCondUtils/LArCondUtils/LArFEBTempTool.h new file mode 100755 index 0000000000000000000000000000000000000000..71a27e2eadd0d7cf14e2e6c9d17a34783d2cde73 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/LArCondUtils/LArFEBTempTool.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef LARFEBTEMPTOOL_H +#define LARFEBTEMPTOOL_H + +/** + @class LArFEBTempTool + @brief concrete tool to provide FEB TEMP DCS information. + + Environment: + Software developed for the ATLAS Detector at the CERN LHC + + @author + Kirill Skovpen <kskovpen@cern.ch> +*/ + +// Includes for Gaudi +#include "GaudiKernel/AlgTool.h" + +#include "LArElecCalib/ILArFEBTempTool.h" +#include "StoreGate/DataHandle.h" +#include "Identifier/Identifier.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" + +// forward declaration +using namespace coral; +class StoreGateSvc; +class AttributeList; +class HWIdentifier; +class LArOnlineID; +class CondAttrListCollection; + +class LArFEBTempTool: public AlgTool, virtual public ILArFEBTempTool +{ + + public: + LArFEBTempTool(const std::string& type, const std::string& name, + const IInterface* parent); + + virtual ~LArFEBTempTool(); + + virtual StatusCode initialize(); + virtual StatusCode finalize(){return StatusCode::SUCCESS;} + + // Given a FEB ID, return std::vector of temp1 and temp2 values + FEBTemp getFebTemp( const HWIdentifier& id ) ; + + private: + + StoreGateSvc* m_detStore; + StoreGateSvc* StoreGate; + std::string m_foldername; + + const CondAttrListCollection* m_atrlistcol; + bool m_isinit; +}; + +#endif diff --git a/LArCalorimeter/LArCondUtils/LArCondUtils/LArFecLvTempDcsTool.h b/LArCalorimeter/LArCondUtils/LArCondUtils/LArFecLvTempDcsTool.h new file mode 100755 index 0000000000000000000000000000000000000000..0b6ff69dc84bdf97de10666cc1157abf615b8416 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/LArCondUtils/LArFecLvTempDcsTool.h @@ -0,0 +1,73 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef LARFECLVTEMPDCSTOOL_H +#define LARFECLVTEMPDCSTOOL_H + +/** + @class LArFecLvTempDcsTool + @brief concrete tool to provide FEC LV TEMP DCS information. + + Environment: + Software developed for the ATLAS Detector at the CERN LHC + + @author + Denis Oliveira Damazio <damazio@bnl.gov> +*/ + +// Includes for Gaudi +#include "GaudiKernel/AlgTool.h" + +#include "LArElecCalib/ILArFecLvTempDcsTool.h" +#include "StoreGate/DataHandle.h" +#include "Identifier/Identifier.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" +#include "StoreGate/DataHandle.h" + +#include <string> + + +// forward declaration +using namespace coral; +class StoreGateSvc; +class LArFecLvTempDcs; +class AttributeList; +class HWIdentifier; +class LArOnlineID; +class CondAttrListCollection; + +class LArFecLvTempDcsTool: public AlgTool, virtual public ILArFecLvTempDcsTool +{ + + public: + LArFecLvTempDcsTool(const std::string& type, const std::string& name, + const IInterface* parent); + + virtual ~LArFecLvTempDcsTool(); + + virtual StatusCode initialize(); + virtual StatusCode finalize(){return StatusCode::SUCCESS;} + + + // Given a HV ID, return its voltage value + virtual StatusCode getV1( const std::string& cratename, float& volt ) ; + virtual StatusCode getFec( const std::string& cratename + , LArFecLvTempDcs& volt ) ; + virtual StatusCode getFec( const HWIdentifier& crateID + , LArFecLvTempDcs& volt ) ; + + private: + + void translateFec( const coral::AttributeList, LArFecLvTempDcs& ) const; + + StoreGateSvc* m_detStore; + StoreGateSvc* StoreGate; + const LArOnlineID* m_larOnlineId; + std::string m_foldername; + + const DataHandle<CondAttrListCollection> m_atrlistcol; + +}; + +#endif diff --git a/LArCalorimeter/LArCondUtils/LArCondUtils/LArHV2Ntuple.h b/LArCalorimeter/LArCondUtils/LArCondUtils/LArHV2Ntuple.h new file mode 100644 index 0000000000000000000000000000000000000000..a2c6430e451da0d7d096d855052a128a967a6669 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/LArCondUtils/LArHV2Ntuple.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// TheLArHV2Ntuple.h +// + +#ifndef _LArCondUtils_LArHV2Ntuple_H +#define _LArCondUtils_LArHV2Ntuple_H + +#include <string> + +// Gaudi includes + +#include "GaudiKernel/Algorithm.h" +#include "GaudiKernel/ToolHandle.h" +#include "StoreGate/StoreGateSvc.h" +#include "GaudiKernel/ITHistSvc.h" +#include "TTree.h" + + +class LArHV2Ntuple : public Algorithm { + public: + //Gaudi style constructor and execution methods + /** Standard Athena-Algorithm Constructor */ + LArHV2Ntuple(const std::string& name, ISvcLocator* pSvcLocator); + /** Default Destructor */ + ~LArHV2Ntuple(); + + /** standard Athena-Algorithm method */ + StatusCode initialize(); + /** standard Athena-Algorithm method */ + StatusCode execute(); + /** standard Athena-Algorithm method */ + StatusCode finalize(){return StatusCode::SUCCESS;} + + private: + + //--------------------------------------------------- + // Member variables + //--------------------------------------------------- + /** The StoreGate Service */ + StoreGateSvc* m_sgSvc; + StoreGateSvc* m_detStore; + + ITHistSvc* m_thistSvc; + TTree* m_tree; + + int m_bec; + int m_isPresampler; + float m_eta; + float m_phi; + int m_electrode; + int m_gap; + int m_hvline; + float m_hv; + float m_current; + +}; +#endif diff --git a/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVPathologyDbAlg.h b/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVPathologyDbAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..1ab513d9e23ad58ff6632f34719a20e2d0cb3192 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVPathologyDbAlg.h @@ -0,0 +1,63 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef LArHVPathologyDbAlg_H +#define LArHVPathologyDbAlg_H + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "GaudiKernel/ToolHandle.h" + +class EventInfo; +class IIOVRegistrationSvc; +class ILArHVPathologyDbTool; +class LArCablingService ; +class LArEM_ID; +class LArHEC_ID; +class LArFCAL_ID; +class LArOnlineID; +class CaloIdManager; +class CaloDetDescrManager; +class Identifier; + +class LArHVPathologyDbAlg : public AthAlgorithm +{ + public: + LArHVPathologyDbAlg(const std::string& name, ISvcLocator* pSvcLocator); + ~LArHVPathologyDbAlg(); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(){return StatusCode::SUCCESS;} + StatusCode stop(); + + private: + StatusCode createCondObjects(); + StatusCode printCondObjects(); + StatusCode registerCondObjects(); + std::vector<unsigned int> getElectInd(const Identifier& id, unsigned int module, unsigned int line); + + BooleanProperty m_writeCondObjs; + StringProperty m_inpFile; + + StringProperty m_folder; + StringProperty m_outpTag; + + const EventInfo* m_evt; + + ServiceHandle<IIOVRegistrationSvc> m_regSvc; + ToolHandle<ILArHVPathologyDbTool> m_pathologyTool; + + int m_mode; + + const DataHandle<CaloIdManager> m_caloIdMgr; + const DataHandle<CaloDetDescrManager> m_calodetdescrmgr; + ToolHandle<LArCablingService> m_cablingService; + const LArEM_ID* m_larem_id; + const LArHEC_ID* m_larhec_id; + const LArFCAL_ID* m_larfcal_id; + const LArOnlineID* m_laronline_id; + +}; + +#endif diff --git a/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVToolDB.h b/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVToolDB.h new file mode 100755 index 0000000000000000000000000000000000000000..ad55c9a368efe841153dc31a0fb084735fd7e9b3 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVToolDB.h @@ -0,0 +1,127 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//Dear emacs, this is -*-c++-*- +#ifndef LARHVToolDB_H +#define LARHVToolDB_H + + +/** + @class LArHVToolDB + @brief concrete Tool to provide HV information for readout cells for MC + + Environment: + Software developed for the ATLAS Detector at the CERN LHC + + @author + Guillaume Unal <unal@lal.in2p3.fr> + +*/ + + +// Includes for Gaudi +#include "GaudiKernel/ToolHandle.h" +#include "LArElecCalib/ILArHVTool.h" +#include "StoreGate/DataHandle.h" +#include "Identifier/Identifier.h" +#include "AthenaBaseComps/AthAlgTool.h" + +// forward declaration +class StoreGateSvc; +class CondAttrListCollection; +class AthenaAttributeList; +class ILArHVPathologyDbTool; +class LArHVPathologiesDb; +class LArEM_ID; +class LArHEC_ID; +class LArFCAL_ID; +class CaloIdManager; +class CaloDetDescrManager; +class Identifier; +class LArElectrodeID; +class LArHVLineID; +class LArHVCablingTool; + +class LArHVToolDB: public AthAlgTool, virtual public ILArHVTool +{ + + public: + LArHVToolDB(const std::string& type, const std::string& name, + const IInterface* parent); + + virtual ~LArHVToolDB(); + + virtual StatusCode initialize(); + virtual StatusCode finalize(); + + // Given a Offline Readout ID, return values of HV and Weight + virtual StatusCode getHV(const Identifier& id, + std::vector< HV_t > & v ) ; + + // Given a Offline Readout ID, return values of Current and Weight + virtual StatusCode getCurrent(const Identifier& id, + std::vector< CURRENT_t > & ihv ) ; + + virtual StatusCode LoadCalibration(IOVSVC_CALLBACK_ARGS); + + + const std::vector<HWIdentifier>& getUpdatedElectrodes(); + + private: + + static const unsigned m_nHVCoolChannels; + + StatusCode getPayload(const Identifier& id,std::vector< HV_t > & v,std::vector< CURRENT_t > & ihv); + void addHV(std::vector< HV_t > & v, double hv, double wt); + void addCurr(std::vector< CURRENT_t > & ihv, double curr, double wt); + std::vector<unsigned int> getElecList(const Identifier& id); + StatusCode fillUpdatedHVChannelsVec(const std::set<size_t>& folderIndices); + + + const DataHandle<CaloIdManager> m_caloIdMgr; + const DataHandle<CaloDetDescrManager> m_calodetdescrmgr; + const LArEM_ID* m_larem_id; + const LArHEC_ID* m_larhec_id; + const LArFCAL_ID* m_larfcal_id; + const LArElectrodeID* m_electrodeID; + const LArHVLineID* m_hvLineID; + + Identifier m_id; + std::vector<HV_t> m_v; + std::vector<CURRENT_t> m_i; + + const DataHandle<AthenaAttributeList> m_pathologiesHandle; + + ToolHandle<ILArHVPathologyDbTool> m_pathologyTool; + ToolHandle<LArHVCablingTool> m_hvCablingTool; + + + LArHVPathologiesDb* m_pathologyContainer; + + std::vector<bool> m_hasPathologyEM; + std::vector<bool> m_hasPathologyHEC; + std::vector<bool> m_hasPathologyFCAL; + std::string m_HVPathologiesFolderName; + + std::vector<HWIdentifier> m_updatedElectrodes; + std::vector<std::vector<std::pair<unsigned,float> > > m_voltageCache; + + std::vector<std::string> m_DCSFolderNames; + + struct COUNTERS { + COUNTERS() : m_nCallbacks(0), m_nVoltageUpdates(0) {}; + unsigned m_nCallbacks; + unsigned m_nVoltageUpdates; + }; + std::vector<COUNTERS> m_nUpdatesPerFolder; + + +}; + +inline +const std::vector<HWIdentifier>& LArHVToolDB::getUpdatedElectrodes() { + return m_updatedElectrodes; +} + +#endif diff --git a/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVToolMC.h b/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVToolMC.h new file mode 100755 index 0000000000000000000000000000000000000000..d47e722bc55c967bc46c2ccbb65cb81bd2c29494 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/LArCondUtils/LArHVToolMC.h @@ -0,0 +1,83 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef LARHVTOOLMC_H +#define LARHVTOOLMC_H + + +/** + @class LArHVToolMC + @brief concrete Tool to provide HV information for readout cells for MC + + Environment: + Software developed for the ATLAS Detector at the CERN LHC + + @author + Guillaume Unal <unal@lal.in2p3.fr> + +*/ + + +// Includes for Gaudi +#include "GaudiKernel/AlgTool.h" + +#include "LArElecCalib/ILArHVTool.h" +#include "StoreGate/DataHandle.h" +#include "Identifier/HWIdentifier.h" + +// forward declaration +class StoreGateSvc; +class LArEM_ID; +class CaloIdManager; + +class LArHVToolMC: public AlgTool, virtual public ILArHVTool +{ + + public: + LArHVToolMC(const std::string& type, const std::string& name, + const IInterface* parent); + + virtual ~LArHVToolMC(); + + virtual StatusCode initialize(); + virtual StatusCode finalize(){return StatusCode::SUCCESS;} + + + // Given a Offline Readout ID, return values of HV and Weight + virtual StatusCode getHV(const Identifier& id, + std::vector< HV_t > & v ) ; + + // Given a Offline Readout ID, return values of Current and Weight + virtual StatusCode getCurrent(const Identifier& id, + std::vector< CURRENT_t > & v ) ; + + virtual StatusCode LoadCalibration(IOVSVC_CALLBACK_ARGS); + + const std::vector<HWIdentifier>& getUpdatedElectrodes(); + + private: + + bool m_readASCII; + + // pointer to Detector Store. + StoreGateSvc* m_detStore; + + double m_hv[2][1024][7][2]; + + bool m_first; + + const LArEM_ID* m_larem_id; + const DataHandle<CaloIdManager> m_caloIdMgr; + + void InitHV(); + + std::vector<HWIdentifier> m_updatedElectrodes; +}; + + +inline +const std::vector<HWIdentifier>& LArHVToolMC::getUpdatedElectrodes() { + return m_updatedElectrodes; +} +#endif diff --git a/LArCalorimeter/LArCondUtils/cmt/requirements b/LArCalorimeter/LArCondUtils/cmt/requirements new file mode 100755 index 0000000000000000000000000000000000000000..31a5c701bd544a740630a37e594de08cb210511e --- /dev/null +++ b/LArCalorimeter/LArCondUtils/cmt/requirements @@ -0,0 +1,40 @@ +package LArCondUtils + +author Hong Ma <hma@bnl.gov> + +use AtlasPolicy AtlasPolicy-* +use GaudiInterface GaudiInterface-* External +use AtlasROOT AtlasROOT-* External +use StoreGate StoreGate-* Control +use AthenaBaseComps AthenaBaseComps-* Control +use Identifier Identifier-* DetectorDescription +use LArElecCalib LArElecCalib-* LArCalorimeter +use AthenaBaseComps AthenaBaseComps-* Control +use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL + + + +library LArCondUtils *.cxx -s=components *.cxx +apply_pattern component_library + +apply_pattern declare_joboptions files=" *.py" +apply_pattern declare_runtime extras="LArEmLvl1.data LArHecLvl1.data LArFcalLvl1.data" +apply_pattern declare_scripts files="LArBuildHVPathologies.sh" + +private +use AthenaKernel AthenaKernel-* Control +use EventInfo EventInfo-* Event +use RegistrationServices RegistrationServices-* Database +use RDBAccessSvc RDBAccessSvc-* Database/AthenaPOOL +use CaloIdentifier CaloIdentifier-* Calorimeter +use CaloDetDescr CaloDetDescr-* Calorimeter +use LArIdentifier LArIdentifier-* LArCalorimeter +use LArRawConditions LArRawConditions-* LArCalorimeter +use LArRecConditions LArRecConditions-* LArCalorimeter +use LArHV LArHV-* LArCalorimeter/LArGeoModel +use LArReadoutGeometry LArReadoutGeometry-* LArCalorimeter/LArGeoModel +use LArTools LArTools-* LArCalorimeter + +#private +#macro cppdebugflags '$(cppdebugflags_s) -O2 ' +#macro_remove componentshr_linkopts "-Wl,-s" diff --git a/LArCalorimeter/LArCondUtils/share/FCAL_ShortList_August17_2010.txt b/LArCalorimeter/LArCondUtils/share/FCAL_ShortList_August17_2010.txt new file mode 100644 index 0000000000000000000000000000000000000000..eaff63fd8df268a2e42579e2470f3641adc938a8 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/FCAL_ShortList_August17_2010.txt @@ -0,0 +1,36 @@ +/LAR/HVPathologiesOfl/Pathologies +1 0 6 2 61 182 7 1 +1 0 6 2 68 182 3 1 +1 0 6 3 39 181 4 1 +1 0 6 3 108 181 1 1 +1 0 6 4 42 180 6 1 +1 0 6 5 1 187 4 1 +1 0 6 5 92 187 3 1 +1 0 6 7 124 185 0 1 +1 0 6 9 41 184 7 1 +1 0 6 9 126 184 0 1 +1 0 6 12 122 191 2 1 +1 0 6 12 124 191 3 1 +1 1 6 2 4 81 2 1 +1 1 6 2 17 81 3 1 +1 1 6 2 18 81 1 1 +1 1 6 2 34 81 2 1 +1 1 6 2 111 81 4 1 +1 1 6 3 36 82 2 1 +1 1 6 3 106 82 5 1 +1 1 6 4 82 83 6 1 +1 1 6 4 100 83 4 1 +1 1 6 5 0 84 1 1 +1 1 6 5 60 84 2 1 +1 1 6 5 63 84 0 1 +1 1 6 6 5 85 2 1 +1 1 6 6 22 85 3 1 +1 1 6 7 7 86 0 1 +1 1 6 7 124 86 7 1 +1 1 6 9 42 87 2 1 +1 1 6 10 85 88 7 1 +1 1 6 11 5 89 0 1 +1 1 6 12 92 90 6 1 +1 1 6 14 100 92 4 1 +1 1 6 14 124 92 6 1 +1 1 6 15 61 93 1 1 diff --git a/LArCalorimeter/LArCondUtils/share/LArBuildHVPathologies.sh b/LArCalorimeter/LArCondUtils/share/LArBuildHVPathologies.sh new file mode 100755 index 0000000000000000000000000000000000000000..71cb4717e156d3bb44aeb6492a8ca6d15f7dadaf --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/LArBuildHVPathologies.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +if [ $# -ne 3 ] +then + echo " Syntax $0 <Run> <LB> <FileName>" + echo " Run/LB = IoV start for UPD4 tag" + echo " FileName = full list of HVPathologies (first line /LAR/HVPathologiesOfl/Pathologies, then fields barrel_ec pos_neg FT Slot channel HVModule HVLine pathology)" + exit +fi + +runStart=$1 +lbStart=$2 +inputTextFile=$3 + +if [ -f larhvpathology.db ] +then + /bin/rm larhvpathology.db +fi + +if [ -f write.log ] +then + /bin/rm write.log +fi + +if [ -f read.log ] +then + /bin/rm read.log +fi + +if [ -f newList.txt ] +then + /bin/rm newList.txt +fi + +echo " Produce HV pathology DB from input file " $inputTextFile +echo " IoV start to use for UPD4 tag " ${runStart} ${lbStart} + +upd1TagName="LARHVPathologiesOflPathologies-UPD1-00" +upd4TagName="LARHVPathologiesOflPathologies-UPD4-01" + +echo " Run athena to produce sqlite file" + +athena.py -c "InputFile=\"${inputTextFile}\";tagName=\"${upd1TagName}\"" LArCondUtils/LArHVPathologyDbWrite.py > write.log 2>&1 + +if [ $? -ne 0 ]; then + echo " Athena reported an error! Please check write.log!" + exit +fi + +if grep -q ERROR write.log + then + echo " An error occured ! Please check write.log!" + exit +fi + + +echo " Run athena to test sqlite file reading" + +athena.py LArCondUtils/LArHVPathologyDbRead.py > read.log 2>&1 + +if [ $? -ne 0 ]; then + echo " Athena reported an error! Please check read.log!" + exit +fi + +if grep -q ERROR read.log + then + echo " An error occured ! Please check read.log!" + exit +fi + +grep "Got pathology for cell ID:" read.log > newList.txt + +echo " List of pathologies in new sqlite file can be found in newList.txt" + + +AtlCoolCopy.exe "sqlite://;schema=larhvpathology.db;dbname=COMP200" "sqlite://;schema=larhvpathology.db;dbname=COMP200" -f /LAR/HVPathologiesOfl/Pathologies -of /LAR/HVPathologiesOfl/Pathologies -t ${upd1TagName} -ot ${upd4TagName} -rls ${runStart} ${lbStart} -truncate + +echo " Sqlite file produced, to merge it to Oracle execute: " +echo " /afs/cern.ch/user/a/atlcond/utils/AtlCoolMerge.py larhvpathology.db COMP200 ATLAS_COOLWRITE ATLAS_COOLOFL_LAR_W <password>" + +exit diff --git a/LArCalorimeter/LArCondUtils/share/LArEmLvl1.data b/LArCalorimeter/LArCondUtils/share/LArEmLvl1.data new file mode 100755 index 0000000000000000000000000000000000000000..e8210b4a57b0ccfb8b1ee81107850c0208aa9629 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/LArEmLvl1.data @@ -0,0 +1,87 @@ + 307200. 0.05 0.10 0.47 1.00 0.60 0.12 -0.10 -0.20 -0.24 -0.24 -0.23 -0.23 -0.22 -0.21 -0.21 -0.21 -0.20 -0.19 -0.18 -0.17 -0.16 -0.11 -0.06 -0.01 + 0.0011 0.0030 0.0341 0.0009 -.0217 -.0115 -.0069 -.0027 -.0005 0.0000 0.0003 0.0001 0.0002 0.0014 0.0016 0.0028 0.0037 0.0024 0.0032 0.0047 0.0093 0.0232 0.0214 0.0090 + 360000. 0.06 0.11 0.53 1.13 0.70 0.15 -0.11 -0.23 -0.28 -0.28 -0.27 -0.26 -0.26 -0.25 -0.25 -0.24 -0.23 -0.22 -0.21 -0.20 -0.19 -0.13 -0.07 -0.02 + 0.0010 0.0035 0.0389 0.0030 -.0247 -.0130 -.0061 -.0029 -.0007 0.0000 0.0006 0.0003 0.0002 0.0012 0.0024 0.0033 0.0039 0.0027 0.0035 0.0055 0.0113 0.0269 0.0243 0.0101 + 480000. 0.07 0.13 0.65 1.23 0.85 0.20 -0.14 -0.30 -0.36 -0.37 -0.36 -0.34 -0.33 -0.32 -0.32 -0.31 -0.30 -0.29 -0.28 -0.26 -0.24 -0.16 -0.08 -0.01 + 0.0012 0.0048 0.0366 0.0037 -.0331 -.0210 -.0088 -.0034 -.0007 0.0000 0.0005 0.0005 0.0003 0.0014 0.0024 0.0042 0.0049 0.0039 0.0049 0.0073 0.0158 0.0359 0.0326 0.0155 + 600000. 0.07 0.14 0.72 1.26 0.96 0.27 -0.16 -0.37 -0.44 -0.44 -0.43 -0.42 -0.41 -0.40 -0.39 -0.37 -0.36 -0.35 -0.34 -0.31 -0.29 -0.18 -0.09 0.00 + 0.0016 0.0057 0.0414 0.0024 -.0283 -.0231 -.0141 -.0053 -.0010 0.0000 0.0003 0.0004 0.0005 0.0023 0.0047 0.0051 0.0054 0.0051 0.0060 0.0094 0.0205 0.0453 0.0400 0.0178 + 720000. 0.07 0.14 0.76 1.28 1.05 0.33 -0.17 -0.43 -0.51 -0.53 -0.51 -0.49 -0.48 -0.46 -0.45 -0.44 -0.42 -0.40 -0.39 -0.36 -0.34 -0.21 -0.10 0.01 + 0.0017 0.0048 0.0456 0.0027 -.0220 -.0233 -.0134 -.0066 -.0014 0.0000 0.0008 0.0009 0.0008 0.0017 0.0040 0.0063 0.0064 0.0068 0.0080 0.0107 0.0238 0.0541 0.0489 0.0217 + 840000. 0.07 0.14 0.85 1.30 1.10 0.39 -0.19 -0.50 -0.60 -0.61 -0.59 -0.57 -0.55 -0.53 -0.52 -0.50 -0.48 -0.46 -0.45 -0.41 -0.38 -0.23 -0.10 0.02 + 0.0015 0.0067 0.0436 0.0014 -.0201 -.0309 -.0186 -.0060 -.0016 0.0000 0.0009 0.0009 0.0008 0.0028 0.0059 0.0072 0.0077 0.0073 0.0090 0.0131 0.0297 0.0642 0.0537 0.0270 + 960000. 0.07 0.15 0.83 1.31 1.14 0.45 -0.20 -0.57 -0.67 -0.68 -0.67 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.47 -0.43 -0.26 -0.11 0.03 + 0.0015 0.0066 0.0431 0.0013 -.0143 -.0272 -.0215 -.0089 -.0018 0.0000 0.0014 0.0009 0.0008 0.0034 0.0072 0.0084 0.0081 0.0084 0.0093 0.0155 0.0330 0.0714 0.0658 0.0253 + 1080000. 0.08 0.15 0.88 1.31 1.17 0.50 -0.20 -0.64 -0.75 -0.77 -0.75 -0.71 -0.69 -0.67 -0.65 -0.62 -0.60 -0.58 -0.56 -0.51 -0.47 -0.29 -0.12 0.05 + 0.0015 0.0068 0.0440 0.0014 -.0119 -.0362 -.0224 -.0110 -.0016 0.0000 0.0010 0.0011 0.0008 0.0038 0.0084 0.0098 0.0090 0.0099 0.0123 0.0173 0.0351 0.0790 0.0740 0.0331 + 1200000. 0.08 0.16 0.90 1.32 1.19 0.61 -0.22 -0.70 -0.83 -0.84 -0.82 -0.79 -0.76 -0.73 -0.72 -0.69 -0.66 -0.63 -0.61 -0.57 -0.52 -0.31 -0.11 0.06 + 0.0018 0.0060 0.0337 0.0011 -.0100 -.0366 -.0248 -.0096 -.0022 0.0000 0.0014 0.0013 0.0009 0.0044 0.0092 0.0106 0.0114 0.0112 0.0120 0.0186 0.0414 0.0908 0.0814 0.0369 + 1800000. 0.07 0.16 0.93 1.32 1.19 0.68 -0.36 -0.75 -0.82 -0.92 -1.08 -1.15 -1.08 -1.05 -1.03 -1.01 -1.00 -0.96 -0.89 -0.82 -0.76 -0.45 -0.11 0.00 + 0.0020 0.0068 0.0399 0.0004 -.0094 -.0423 -.0261 -.0062 -.0024 0.0000 -.0060 0.0016 0.0025 0.0033 0.0062 0.0073 0.0100 0.0251 0.0294 0.0262 0.0573 0.1455 0.1164 0.0000 + 2400000. 0.08 0.18 0.98 1.32 1.19 0.63 -0.36 -0.76 -0.82 -0.82 -0.83 -0.89 -1.05 -1.26 -1.25 -1.16 -1.14 -1.12 -1.10 -1.06 -1.01 -0.74 -0.32 0.11 + 0.0016 0.0092 0.0371 -.0005 -.0077 -.0498 -.0250 -.0053 -.0003 0.0000 -.0009 -.0049 -.0080 0.0008 0.0188 0.0180 0.0094 0.0091 0.0113 0.0207 0.0479 0.1594 0.1915 0.0762 + 3600000. 0.08 0.19 1.04 1.32 1.20 0.86 -0.27 -0.97 -1.13 -1.13 -1.10 -1.06 -1.03 -1.01 -1.02 -1.20 -1.36 -1.35 -1.31 -1.24 -1.17 -0.94 -0.65 -0.04 + 0.0017 0.0104 0.0360 -.0009 -.0077 -.0361 -.0473 -.0161 -.0014 0.0000 0.0013 0.0015 0.0010 -.0024 -.0231 -.0784 -.0440 0.0189 0.0224 0.0272 0.0455 0.1205 0.1667 0.1737 + 1.00 0.10 -0.30 -0.20 -0.05 -0.01 -0.01 + barrel + 1 0.999 + 160. 312. 351. + 2 0.989 + 160. 317. 356. + 3 0.970 + 160. 314. 353. + 4 0.942 + 156. 311. 347. + 5 0.907 + 159. 317. 355. + 6 0.866 + 153. 306. 342. + 7 0.820 + 151. 305. 341. + 8 0.772 + 144. 292. 325. + 9 0.723 + 187. 305. 358. + 10 0.673 + 172. 287. 335. + 11 0.624 + 163. 282. 326. + 12 0.576 + 157. 276. 317. + 13 0.530 + 144. 250. 289. + 14 0.486 + 133. 181. 225. + 15 0.445 + 0. 0. 0. + endcap + 1 0.445 + 156. 186. 243. + 2 0.406 + 115. 117. 164. + 3 0.370 + 109. 101. 148. + 4 0.337 + 102. 85. 133. + 5 0.307 + 132. 82. 156. + 6 0.279 + 118. 67. 136. + 7 0.253 + 116. 60. 131. + 8 0.230 + 107. 51. 119. + 9 0.208 + 97. 44. 107. + 10 0.189 + 94. 40. 101. + 11 0.171 + 76. 37. 84. + 12 0.148 + 91. 0. 91. + 13 0.121 + 73. 0. 73. + 14 0.099 + 59. 0. 59. + 15 0.084 + 59. 0. 59. diff --git a/LArCalorimeter/LArCondUtils/share/LArFcalLvl1.data b/LArCalorimeter/LArCondUtils/share/LArFcalLvl1.data new file mode 100755 index 0000000000000000000000000000000000000000..307ca8a5ea20c95662625ac828a498411fb86b89 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/LArFcalLvl1.data @@ -0,0 +1,10 @@ + 1 134.00 102.00 65.00 33.00 + 0.00 0.00 0.21 1.00 0.30 -0.45 -0.55 -0.37 -0.11 -0.08 -0.07 -0.05 -0.02 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.00 0.00 0.00 0.00 + 0.0000 0.0000 0.0400 -.0011 -.0386 -.0167 0.0032 0.0135 0.0054 0.0005 0.0010 0.0006 0.0016 0.0000 -.0001 -.0001 -.0001 0.0001 -.0001 -.0001 0.0000 0.0000 0.0000 0.0000 + 2 163.00 73.00 -1. -1. + 0.00 0.00 0.26 1.00 0.52 -0.23 -0.65 -0.47 -0.27 -0.15 -0.12 -0.07 -0.03 0.00 0.00 0.00 0.01 0.01 0.01 0.01 0.01 0.00 0.00 0.00 + 0.0000 0.0000 0.0402 -.0002 -.0276 -.0282 -.0037 0.0115 0.0062 0.0020 0.0010 0.0025 0.0012 0.0007 0.0001 0.0001 0.0001 0.0001 -.0001 0.0000 0.0000 0.0000 0.0000 0.0000 + 3 -1. -1. 163.00 73.00 + 0.00 0.00 0.35 1.00 0.66 0.05 -0.47 -0.58 -0.47 -0.32 -0.21 -0.14 -0.09 -0.04 -0.02 0.00 0.00 0.01 0.01 0.01 0.01 0.00 0.00 0.00 + 0.0000 0.0000 0.0408 0.0002 -.0218 -.0236 -.0135 0.0013 0.0063 0.0051 0.0030 0.0028 0.0019 0.0013 0.0007 0.0004 0.0002 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 + 1.00 0.10 -0.30 -0.20 -0.05 -0.01 -0.01 diff --git a/LArCalorimeter/LArCondUtils/share/LArHV2Ntuple_jobOptions.py b/LArCalorimeter/LArCondUtils/share/LArHV2Ntuple_jobOptions.py new file mode 100644 index 0000000000000000000000000000000000000000..3222371088201dd38506316b198f8abef5763e56 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/LArHV2Ntuple_jobOptions.py @@ -0,0 +1,113 @@ +################################################################## +# +# example jobOptions to read HV from Cool/DCS in athena and fill simple ntuple +# +################################################################## + +import time + +tuple=(2010, 04, 29, 16, 00, 0,-1,-1,-1) +itime = int(time.mktime(tuple)) + +TimeStamp=itime + +# run number only relevant for HV mapping information.. Use latest mapping here +RunNumber = 999999 + +# global tag to read other conditions if needed +GlobalTag = 'COMCOND-ES1P-002-00' + + +################################################################### +from PerfMonComps.PerfMonFlags import jobproperties +jobproperties.PerfMonFlags.doMonitoring = True + +from RecExConfig.RecFlags import rec + +from AthenaCommon.DetFlags import DetFlags +DetFlags.all_setOff() +DetFlags.LAr_setOn() +DetFlags.Tile_setOn() + +from AthenaCommon.GlobalFlags import GlobalFlags +GlobalFlags.DetGeo.set_atlas() +GlobalFlags.DataSource.set_data() +GlobalFlags.Luminosity.set_zero() + +# Get a handle to the default top-level algorithm sequence +from AthenaCommon.AppMgr import ToolSvc +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +# Get a handle to the ServiceManager +from AthenaCommon.AppMgr import ServiceMgr as svcMgr + +# Get a handle to the ApplicationManager +from AthenaCommon.AppMgr import theApp + +# Setup Db stuff +import AthenaPoolCnvSvc.AthenaPool + +from AthenaCommon.GlobalFlags import jobproperties +jobproperties.Global.DetDescrVersion='ATLAS-GEO-10-00-00' + +from AtlasGeoModel import SetGeometryVersion +from AtlasGeoModel import GeoModelInit + +svcMgr.IOVDbSvc.GlobalTag = GlobalTag + +include( "AthenaCommon/Atlas_Gen.UnixStandardJob.py" ) + +include( "CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv_joboptions.py") +include( "CaloIdCnv/CaloIdCnv_joboptions.py" ) +include( "TileIdCnv/TileIdCnv_jobOptions.py" ) +include( "LArDetDescr/LArDetDescr_joboptions.py" ) +include("TileConditions/TileConditions_jobOptions.py" ) +include("LArConditionsCommon/LArConditionsCommon_comm_jobOptions.py") + +include( "LArCondAthenaPool/LArCondAthenaPool_joboptions.py" ) + +from IOVDbSvc.CondDB import conddb +conddb.addFolder("DCS_OFL","/LAR/DCS/HV/BARREl/I16") +conddb.addFolder("DCS_OFL","/LAR/DCS/HV/BARREL/I8") + +# to read HV mapping from database file instead of Ascii file in LArTools +from IOVDbSvc.CondDB import conddb +conddb.addFolder("LAR_OFL","/LAR/IdentifierOfl/HVLineToElectrodeMap"); + +from LArCondUtils.LArCondUtilsConf import LArHV2Ntuple +theLArHV2Ntuple = LArHV2Ntuple("LArHV2Ntuple") +topSequence += theLArHV2Ntuple + +# ------------------------------------------------------------------ +# --- Ntuple +# ------------------------------------------------------------------ +if not hasattr(ServiceMgr, 'THistSvc'): + from GaudiSvc.GaudiSvcConf import THistSvc + ServiceMgr += THistSvc() + +ServiceMgr.THistSvc.Output = ["file1 DATAFILE='dump_hv.root' OPT='RECREATE'"]; + + + +#-------------------------------------------------------------- +#--- Dummy event loop parameters +#-------------------------------------------------------------- +svcMgr.EventSelector.RunNumber = RunNumber +svcMgr.EventSelector.EventsPerRun = 100 +svcMgr.EventSelector.FirstEvent = 0 +svcMgr.EventSelector.EventsPerLB = 100 +svcMgr.EventSelector.FirstLB = 1 +svcMgr.EventSelector.InitialTimeStamp = TimeStamp +svcMgr.EventSelector.TimeStampInterval = 5 +svcMgr.EventSelector.OverrideRunNumber=True +theApp.EvtMax = 1 + +#-------------------------------------------------------------- +# Set output level threshold (1=VERBOSE, 2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL ) +#-------------------------------------------------------------- +svcMgr.MessageSvc.OutputLevel = INFO +svcMgr.MessageSvc.debugLimit = 100000 +svcMgr.MessageSvc.infoLimit = 100000 +svcMgr.MessageSvc.Format = "% F%30W%S%7W%R%T %0W%M" +svcMgr.IOVDbSvc.OutputLevel = INFO diff --git a/LArCalorimeter/LArCondUtils/share/LArHVPathology.inp b/LArCalorimeter/LArCondUtils/share/LArHVPathology.inp new file mode 100644 index 0000000000000000000000000000000000000000..68e1ba0088c47b02eb6ad2dedb84672e4b977aa2 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/LArHVPathology.inp @@ -0,0 +1,42 @@ +########################################################################### +# # +# This is a sample input file used by LArHVPathologyDbAlg in # +# order to write LAr HV Pathologies into COOL # +# # +# Organization of the file: # +# The file consists of sections, one per LAr subsystem folder. # +# # +# Each folder section starts with the name of the folder. The name is # +# followed by list of electrode pathologies of the form: # +# <Cell ID> <Electrode index within the cell> <Pathology type> # +# # +# NB. # +# 1. If the list of electrode pathologies is empty, then an empty # +# container object will be recorded into COOL # +# # +# 2. If there is more than one section for some subsystem, then only # +# first one is used # +########################################################################### + +# EMB + +#/LAR/HVPathologies/EMB +#10001 0 0 +#10002 2 4 +#10003 4 8 +#10004 8 16 + +# EMEC + +#/LAR/HVPathologies/EMEC +#10101 0 0 +#10102 2 4 +#10103 4 8 +#10104 8 16 + + +# HEC +#/LAR/HVPathologies/HEC + +# FCAL +#/LAR/HVPathologies/FCAL diff --git a/LArCalorimeter/LArCondUtils/share/LArHVPathologyDbRead.py b/LArCalorimeter/LArCondUtils/share/LArHVPathologyDbRead.py new file mode 100755 index 0000000000000000000000000000000000000000..8ed4a2a5b5c8f2de8226f069f898a358dbde18b6 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/LArHVPathologyDbRead.py @@ -0,0 +1,103 @@ +# +# Job Options for reading LAr HV Pathologies from COOL using local SQLite database +# + +if "GloablTag" not in dir(): + GlobalTag = 'COMCOND-BLKPA-006-01' + + + +## basic job configuration +import AthenaCommon.AtlasUnixGeneratorJob + +## get a handle to the default top-level algorithm sequence +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +## get a handle to the ServiceManager +from AthenaCommon.AppMgr import ServiceMgr as svcMgr + +## get a handle to the ApplicationManager +from AthenaCommon.AppMgr import theApp + +## get a handle to the default top-level algorithm sequence +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +## get a handle to the ServiceManager +from AthenaCommon.AppMgr import ServiceMgr as svcMgr + +## get a handle to the ApplicationManager +from AthenaCommon.AppMgr import theApp + +from AthenaCommon.DetFlags import DetFlags +DetFlags.all_setOff() +DetFlags.LAr_setOn() +DetFlags.Tile_setOn() + +from AthenaCommon.GlobalFlags import globalflags +globalflags.DetGeo = 'atlas' +globalflags.DataSource = 'data' +globalflags.InputFormat = 'pool' + +from AthenaCommon.GlobalFlags import jobproperties +jobproperties.Global.DetDescrVersion='ATLAS-GEO-20-00-00' + +from AtlasGeoModel import SetGeometryVersion +from AtlasGeoModel import GeoModelInit +from AtlasGeoModel import SetupRecoGeometry + +svcMgr.IOVDbSvc.GlobalTag = GlobalTag + +TileUseDCS=False +include( "CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv_joboptions.py") +include( "CaloIdCnv/CaloIdCnv_joboptions.py" ) +include( "TileIdCnv/TileIdCnv_jobOptions.py" ) +include( "LArDetDescr/LArDetDescr_joboptions.py" ) +include("TileConditions/TileConditions_jobOptions.py" ) +include("LArConditionsCommon/LArConditionsCommon_comm_jobOptions.py") + + +#-------------------------------------------------------------- +# Access to IOVSvc, IOVDbSvc and CondDBMySQLCnvSvc +#-------------------------------------------------------------- +import IOVDbSvc.IOVDb + +from LArCondUtils.LArCondUtilsConf import LArHVPathologyDbAlg +LArHVPathologyDbAlg = LArHVPathologyDbAlg() +LArHVPathologyDbAlg.Folder = "/LAR/HVPathologiesOfl/Pathologies" +topSequence += LArHVPathologyDbAlg + +# Here mytest.db is the name of SQLite file created by this job +svcMgr.IOVDbSvc.dbConnection = "sqlite://;schema=larhvpathology.db;dbname=COMP200" +svcMgr.IOVDbSvc.Folders += [ "/LAR/HVPathologiesOfl/Pathologies<tag>LARHVPathologiesOflPathologies-UPD1-00</tag>" ] + +svcMgr.MessageSvc.OutputLevel = 4 +svcMgr.MessageSvc.debugLimit = 100000 +svcMgr.MessageSvc.infoLimit = 100000 + +LArHVPathologyDbAlg.OutputLevel = 3 +svcMgr.IOVDbSvc.OutputLevel = 3 + +#-------------------------------------------------------------- +# The following turns off the ability to set EventSelector parameters +# below +#ApplicationMgr.EvtSel = "NONE" +#-------------------------------------------------------------- +# Set the following when reading back to adjust the run/event numbers +svcMgr.EventSelector.RunNumber = 9999999 +svcMgr.EventSelector.EventsPerRun = 1 +svcMgr.EventSelector.FirstEvent = 1 +svcMgr.EventSelector.EventsPerLB = 1 +svcMgr.EventSelector.FirstLB = 1 +svcMgr.EventSelector.InitialTimeStamp = 0 +svcMgr.EventSelector.TimeStampInterval = 5 +theApp.EvtMax = 1 + +#-------------------------------------------------------------- +# Load POOL support +#-------------------------------------------------------------- +import AthenaPoolCnvSvc.WriteAthenaPool + +# Check the dictionary in memory for completeness +svcMgr.AthenaSealSvc.CheckDictionary = TRUE diff --git a/LArCalorimeter/LArCondUtils/share/LArHVPathologyDbWrite.py b/LArCalorimeter/LArCondUtils/share/LArHVPathologyDbWrite.py new file mode 100755 index 0000000000000000000000000000000000000000..f14de900d9f56b6231e66338931dc7c05bc9c4d3 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/LArHVPathologyDbWrite.py @@ -0,0 +1,155 @@ +# +# Job Options for writing LAr Cell HV Pathologies to COOL using local SQLite database +# + +from time import strptime,time +from calendar import timegm + +if "InputFile" not in dir(): + InputFile="HVPathologies.txt" + +if "tagName" not in dir(): + tagName="LARHVPathologiesOflPathologies-UPD1-00" + +if "RunNumber" not in dir(): + RunNumber = 999999 + +if "GloablTag" not in dir(): + GlobalTag = 'COMCOND-BLKPA-006-01' + +if "date" not in dir(): + date="2010-09-02:12:00:00" + + +if "TimeStamp" not in dir(): + try: + ts=strptime(date+'/UTC','%Y-%m-%d:%H:%M:%S/%Z') + TimeStamp=int(timegm(ts))*1000000000L + except ValueError: + print "ERROR in time specification, use e.g. 2007-05-25:14:01:00" + + +## basic job configuration +import AthenaCommon.AtlasUnixGeneratorJob + +## get a handle to the default top-level algorithm sequence +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +## get a handle to the ServiceManager +from AthenaCommon.AppMgr import ServiceMgr as svcMgr + +## get a handle to the ApplicationManager +from AthenaCommon.AppMgr import theApp + +from AthenaCommon.DetFlags import DetFlags +DetFlags.all_setOff() +DetFlags.LAr_setOn() +DetFlags.Tile_setOn() + +from AthenaCommon.GlobalFlags import globalflags +globalflags.DetGeo = 'atlas' +globalflags.DataSource = 'data' +globalflags.InputFormat = 'pool' + + +from AthenaCommon.GlobalFlags import jobproperties +jobproperties.Global.DetDescrVersion='ATLAS-GEO-20-00-00' + +from AtlasGeoModel import SetGeometryVersion +from AtlasGeoModel import GeoModelInit +from AtlasGeoModel import SetupRecoGeometry + +svcMgr.IOVDbSvc.GlobalTag = GlobalTag + +TileUseDCS=False +include( "CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv_joboptions.py") +include( "CaloIdCnv/CaloIdCnv_joboptions.py" ) +include( "TileIdCnv/TileIdCnv_jobOptions.py" ) +include( "LArDetDescr/LArDetDescr_joboptions.py" ) +include("TileConditions/TileConditions_jobOptions.py" ) +include("LArConditionsCommon/LArConditionsCommon_comm_jobOptions.py") + +#from LArConditionsCommon import LArHVDB + +from IOVDbSvc.CondDB import conddb +conddb.addFolder("LAR_OFL","/LAR/IdentifierOfl/HVLineToElectrodeMap") +conddb.addFolder("DCS_OFL","/LAR/DCS/HV/BARREl/I16") +conddb.addFolder("DCS_OFL","/LAR/DCS/HV/BARREL/I8") + + + + +#-------------------------------------------------------------- +# Access to IOVSvc, IOVDbSvc and CondDBMySQLCnvSvc +#-------------------------------------------------------------- +import IOVDbSvc.IOVDb + +from LArCondUtils.LArCondUtilsConf import LArHVPathologyDbAlg +LArHVPathologyDbAlg = LArHVPathologyDbAlg() +topSequence += LArHVPathologyDbAlg + +# Here mytest.db is the name of SQLite file created by this job +svcMgr.IOVDbSvc.dbConnection = "sqlite://;schema=larhvpathology.db;dbname=COMP200" + +svcMgr.MessageSvc.OutputLevel = 4 +svcMgr.MessageSvc.debugLimit = 100000 +svcMgr.MessageSvc.infoLimit = 100000 + +LArHVPathologyDbAlg.OutputLevel = 2 +svcMgr.IOVDbSvc.OutputLevel = 3 + +# Choose the following to write out cond objects . +LArHVPathologyDbAlg.WriteCondObjs = True + +# Other properties of LArHVPathologyDbAlg +LArHVPathologyDbAlg.InpFile = InputFile +LArHVPathologyDbAlg.Folder = "/LAR/HVPathologiesOfl/Pathologies" +LArHVPathologyDbAlg.TagName = tagName +LArHVPathologyDbAlg.Mode = 1 + +#-------------------------------------------------------------- +# Options for IOVRegistrationSvc +import RegistrationServices.IOVRegistrationSvc +regSvc = svcMgr.IOVRegistrationSvc + +# Select the following to delete and recreate the folders. Default is +# NOT to recreate +regSvc.RecreateFolders = False + + +#-------------------------------------------------------------- +# The following turns off the ability to set EventSelector parameters +# below +#ApplicationMgr.EvtSel = "NONE" +#-------------------------------------------------------------- +# Set the following when reading back to adjust the run/event numbers +svcMgr.EventSelector.RunNumber = RunNumber +svcMgr.EventSelector.EventsPerRun = 1 +svcMgr.EventSelector.FirstEvent = 1 +svcMgr.EventSelector.EventsPerLB = 1 +svcMgr.EventSelector.FirstLB = 1 +svcMgr.EventSelector.InitialTimeStamp = int(TimeStamp/1e9) +svcMgr.EventSelector.TimeStampInterval = 5 +theApp.EvtMax = 1 + +#-------------------------------------------------------------- +# Load POOL support +#-------------------------------------------------------------- +#import AthenaPoolCnvSvc.WriteAthenaPool + +#-------------------------------------------------------------- +# AthenaPool details +#-------------------------------------------------------------- + +# Check the dictionary in memory for completeness +svcMgr.AthenaSealSvc.CheckDictionary = TRUE + +#-------------------------------------------------------------- +# Use AthenaOutputStreamTool to write +# Must "turn off" standard AthenaOutputStream +#-------------------------------------------------------------- +#theApp.OutStream = [] + + + diff --git a/LArCalorimeter/LArCondUtils/share/LArHecLvl1.data b/LArCalorimeter/LArCondUtils/share/LArHecLvl1.data new file mode 100755 index 0000000000000000000000000000000000000000..74863497dfe79e042e16ec0c5827c8340a47842d --- /dev/null +++ b/LArCalorimeter/LArCondUtils/share/LArHecLvl1.data @@ -0,0 +1,30 @@ + 0.00 0.03 0.61 1.00 0.76 0.39 0.12 -0.02 -0.02 -0.15 -0.17 -0.19 -0.20 -0.21 -0.21 -0.22 -0.22 -0.22 -0.22 -0.22 -0.19 -0.14 -0.08 -0.05 + 0.0000 0.0080 0.0288 0.0002 -.0152 -.0132 -.0079 -.0043 -.0023 -.0013 -.0008 -.0005 -.0004 -.0002 -.0002 -.0001 -.0001 0.0000 0.0000 0.0003 0.0019 0.0024 0.0017 0.0010 + 2 300000. 0.406 52.0 + 1.00 0.11 -0.31 -0.17 -0.05 -0.02 -0.01 + 3 300000. 0.370 55.5 + 1.00 0.11 -0.31 -0.17 -0.05 -0.02 -0.01 + 4 300000. 0.337 64.3 + 1.00 0.08 -0.33 -0.16 -0.04 -0.01 0.00 + 5 300000. 0.307 52.0 + 1.00 0.08 -0.33 -0.16 -0.04 0.00 0.00 + 6 300000. 0.279 37.3 + 1.00 0.05 -0.35 -0.16 -0.03 0.00 0.00 + 7 300000. 0.253 25.685 + 1.00 0.08 -0.34 -0.16 -0.04 0.00 0.00 + 8 300000. 0.230 23.559 + 1.00 0.12 -0.34 -0.18 -0.05 -0.01 0.00 + 9 300000. 0.208 22.005 + 1.00 0.13 -0.32 -0.18 -0.06 -0.01 -0.01 + 10 300000. 0.189 20.979 + 1.00 0.17 -0.32 -0.20 -0.07 -0.02 -0.01 + 11 300000. 0.171 20.105 + 1.00 0.18 -0.31 -0.20 -0.07 -0.02 -0.01 + 12 300000. 0.148 30.246 + 1.00 0.11 -0.40 -0.18 -0.03 0.01 0.01 + 13 300000. 0.121 25.319 + 1.00 0.14 -0.37 -0.19 -0.05 0.00 0.00 + 14 300000. 0.099 22.350 + 1.00 0.17 -0.35 -0.20 -0.06 -0.01 0.00 + 15 460000. 0.084 29. + 1.00 0.24 -0.30 -0.22 -0.09 -0.03 -0.02 diff --git a/LArCalorimeter/LArCondUtils/src/LArFEBTempTool.cxx b/LArCalorimeter/LArCondUtils/src/LArFEBTempTool.cxx new file mode 100755 index 0000000000000000000000000000000000000000..b8814d13d3535748c04bcec455370fdba0aa3e66 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/src/LArFEBTempTool.cxx @@ -0,0 +1,95 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//----------------------------------------------------------------------- +// File and Version Information: +// LArFEBTempTool.cxx +// +// Description: Tool to provide FEB TEMP DCS information. +// +// Environment: +// Software developed for the ATLAS Detector at the CERN LHC +// +// Author List: +// Kirill Skovpen <kskovpen@cern.ch> +// +//----------------------------------------------------------------------- + +#include "LArCondUtils/LArFEBTempTool.h" +#include "LArIdentifier/LArOnlineID.h" + +#include "GaudiKernel/IToolSvc.h" +#include "GaudiKernel/MsgStream.h" +#include "StoreGate/StoreGateSvc.h" + +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" + +// constructor +LArFEBTempTool::LArFEBTempTool(const std::string& type, + const std::string& name, + const IInterface* parent) + : AlgTool(type,name,parent), m_foldername("/LAR/DCS/FEBTEMP") +{ + declareInterface< ILArFEBTempTool >( this ); + declareProperty("FolderName",m_foldername); +} + +// destructor +LArFEBTempTool::~LArFEBTempTool() +{ } + +// intialize +StatusCode LArFEBTempTool::initialize() +{ + MsgStream log(msgSvc(),name()); + + StatusCode sc = service("StoreGateSvc",StoreGate); + if(sc!=StatusCode::SUCCESS) return sc; + else log << MSG::DEBUG << "Retrieved StoreGateSvc" << endreq; + + sc = service("DetectorStore",m_detStore); + if(sc!=StatusCode::SUCCESS) return sc; + else log << MSG::DEBUG << "Retrieved Detector Store" << endreq; + + m_isinit=false; + return StatusCode::SUCCESS; +} + +FEBTemp LArFEBTempTool::getFebTemp( const HWIdentifier& id ) +{ + MsgStream log(msgSvc(),name()); + FEBTemp m_temp; + m_temp.clear(); + + if(!m_isinit) { + StatusCode sc = m_detStore->retrieve(m_atrlistcol,m_foldername); + if (sc.isFailure()) { + log << MSG::ERROR << "Unable to retrieve AttrListCollection "<<m_foldername<<endreq; + return m_temp; + } else { + log << MSG::DEBUG << "Successfully retrieved AttrListCollection" << endreq; + m_isinit = true; + } + } + + + for (CondAttrListCollection::const_iterator citr=m_atrlistcol->begin(); + citr!=m_atrlistcol->end();++citr) + { + if( (*citr).first == id.get_identifier32().get_compact() ) + { + float temp1=-1; + if(! ((*citr).second)["temp1"].isNull()) temp1 = (((*citr).second)["temp1"]).data<float>(); + float temp2 =-1; + if(! ((*citr).second)["temp2"].isNull()) temp2 = (((*citr).second)["temp2"]).data<float>(); + m_temp.push_back(std::make_pair(temp1,temp2)); + } + } + + return m_temp; +} + + diff --git a/LArCalorimeter/LArCondUtils/src/LArFecLvTempDcsTool.cxx b/LArCalorimeter/LArCondUtils/src/LArFecLvTempDcsTool.cxx new file mode 100755 index 0000000000000000000000000000000000000000..d00b9163c51ae6c95e68eac19c804c9a5c20d000 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/src/LArFecLvTempDcsTool.cxx @@ -0,0 +1,244 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//----------------------------------------------------------------------- +// File and Version Information: +// $Id: LArFecLvTempDcsTool.cxx,v 1.3 2008-10-17 13:00:09 gunal Exp $ +// +// Description: Tool to provide FEC LV TEMP DCS information. +// +// Environment: +// Software developed for the ATLAS Detector at the CERN LHC +// +// Author List: +// Denis Oliveira Damazio <damazio@bnl.gov> +// +//----------------------------------------------------------------------- + +#include "LArIdentifier/LArIdManager.h" +#include "LArCondUtils/LArFecLvTempDcsTool.h" +#include "LArRawConditions/LArFecLvTempDcs.h" + +#include "GaudiKernel/IToolSvc.h" +#include "GaudiKernel/MsgStream.h" +#include "StoreGate/StoreGateSvc.h" +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "LArIdentifier/LArOnlineID.h" +#include <iostream> +#include <string> + +// constructor +LArFecLvTempDcsTool::LArFecLvTempDcsTool(const std::string& type, + const std::string& name, + const IInterface* parent) + : AlgTool(type,name,parent), m_foldername("/LAR/DCS/CLVTEMP") +{ + declareInterface< ILArFecLvTempDcsTool >( this ); + declareProperty("FolderName",m_foldername); + +} + +// destructor +LArFecLvTempDcsTool::~LArFecLvTempDcsTool() +{ } + +// intialize +StatusCode LArFecLvTempDcsTool::initialize() +{ + MsgStream log(msgSvc(),name()); + + StatusCode sc = service("StoreGateSvc",StoreGate); + if(sc!=StatusCode::SUCCESS) return sc; + else log << MSG::DEBUG << "Retrieved StoreGateSvc" << endreq; + + sc = service("DetectorStore",m_detStore); + if(sc!=StatusCode::SUCCESS) return sc; + else log << MSG::DEBUG << "Retrieved Detector Store" << endreq; + + const LArIdManager* larMgr; + sc= m_detStore->retrieve(larMgr); + if (sc.isFailure()) { + log << MSG::ERROR << "Unable to retrieve LArIdManager from DetectorStore" << endreq; + return StatusCode::FAILURE; + } else { + log << MSG::DEBUG << "Successfully retrieved LArIdManager from DetectorStore" << endreq; + } + // retrieve LArOnlineID + m_larOnlineId = larMgr->getOnlineID(); + if (!m_larOnlineId) { + log << MSG::ERROR + << "Unable to retrieve pointer to LArOnlineID " + << endreq; + return sc; + } + log << MSG::DEBUG << "Retrieved LArOnlineID" << endreq; + + + sc= m_detStore->regHandle(m_atrlistcol,m_foldername); + if (sc.isFailure()) { + log << MSG::ERROR << "Unable to register DataHandle "<<m_foldername<<endreq; + return StatusCode::FAILURE; + } else { + log << MSG::DEBUG << "Successfully registered DataHandle<CondAttrListCollection>" << endreq; + } + + return StatusCode::SUCCESS; +} + + + + +StatusCode LArFecLvTempDcsTool::getV1( const std::string& cratename, + float& hv ) +{ + MsgStream log(msgSvc(),name()); + +/* + // first print event number and time details + const EventInfo* event; + if (StatusCode::SUCCESS==StoreGate->retrieve(event)) { + int time=event->event_ID()->time_stamp(); + log << MSG::INFO << "In run/event [" << event->event_ID()->run_number() << + "," << event->event_ID()->event_number() << "] timestamp " << time << + endreq; + } else { + log << MSG::ERROR << "Could not get pointer to event" << endreq; + } + + +*/ + + bool crate_found = false; + if ( m_atrlistcol.isValid() ) + { + // loop over collection + for (CondAttrListCollection::const_iterator citr=m_atrlistcol->begin(); + citr!=m_atrlistcol->end();++citr) { + log << MSG::DEBUG << (((*citr).second)["DPNAME"]).data<std::string>() + << endreq; + if ( ((((*citr).second)["DPNAME"]).data<std::string>()).find(cratename) + != std::string::npos ){ + crate_found = true; + hv = (((*citr).second)["V1_VOLT"]).data<float>(); + // Dont search anymore + break; + } + } + } else { + log << MSG::INFO << " No valid CondAttrListCollection with key " << + m_foldername << endreq; + } + if ( !crate_found ){ + log << MSG::ERROR << "Crate : " << cratename << " Not Found" << endreq; + return StatusCode::SUCCESS; + } + + return StatusCode::SUCCESS; +} + +StatusCode LArFecLvTempDcsTool::getFec( const std::string& cratename, + LArFecLvTempDcs& fec ) +{ + MsgStream log(msgSvc(),name()); + +/* + // first print event number and time details + const EventInfo* event; + if (StatusCode::SUCCESS==StoreGate->retrieve(event)) { + int time=event->event_ID()->time_stamp(); + log << MSG::INFO << "In run/event [" << event->event_ID()->run_number() << + "," << event->event_ID()->event_number() << "] timestamp " << time << + endreq; + } else { + log << MSG::ERROR << "Could not get pointer to event" << endreq; + } + const CondAttrListCollection* atrlistcol; + +*/ + + bool crate_found = false; + // through joboptions + if (m_atrlistcol.isValid() ) { + // loop over collection + for (CondAttrListCollection::const_iterator citr=m_atrlistcol->begin(); + citr!=m_atrlistcol->end();++citr) { + log << MSG::VERBOSE << "trying to find : " + <<(((*citr).second)["DPNAME"]).data<std::string>() + << endreq; + if ( ((((*citr).second)["DPNAME"]).data<std::string>()).find(cratename) + != std::string::npos ){ + crate_found = true; + translateFec( (((*citr).second)), fec); + // Dont search anymore + break; + } + } + } else { + log << MSG::INFO << " DataHandle of CondAttrListCollection " << + m_foldername << endreq; + } + if ( !crate_found ){ + log << MSG::ERROR << "Crate : " << cratename << " Not Found" << endreq; + return StatusCode::SUCCESS; + } + + return StatusCode::SUCCESS; +} + +StatusCode LArFecLvTempDcsTool::getFec( const HWIdentifier& crateID, + LArFecLvTempDcs& fec ) +{ + MsgStream log(msgSvc(),name()); + std::string partial_cratename = + m_larOnlineId->feedthrough_name( crateID ); + std::string cratename("crate_"); + cratename+=partial_cratename; + cratename.resize(cratename.length()-1); + return getFec(cratename,fec); +} + +void +LArFecLvTempDcsTool::translateFec( const coral::AttributeList att, + LArFecLvTempDcs& fec ) const +{ + // Temporary variables + std::vector<float> volts; + std::vector<float> temps; + // Dump data into temporary vars + volts.push_back(att["V1_VOLT"].data<float>() ); + volts.push_back(att["V2_VOLT"].data<float>() ); + volts.push_back(att["V3_VOLT"].data<float>() ); + volts.push_back(att["V4_VOLT"].data<float>() ); + volts.push_back(att["V5_VOLT"].data<float>() ); + volts.push_back(att["V6_VOLT"].data<float>() ); + volts.push_back(att["V7_VOLT"].data<float>() ); + temps.push_back(att["T1_TEMP"].data<float>() ); + temps.push_back(att["T2_TEMP"].data<float>() ); + temps.push_back(att["T3_TEMP"].data<float>() ); + temps.push_back(att["T4_TEMP"].data<float>() ); + fec.getVolts().voltage( volts ); + fec.getManifold().temperature( temps ); + fec.getOCEM().powerOn ( att["OCEM_POWER"].data<bool>() ); + fec.getOCEM().powerOut ( att["OCEM_OUTPUT"].data<bool>() ); + fec.getOCEM().interlock ( att["OCEM_INTERLOCK"].data<bool>() ); + fec.getOCEM().overCurrent ( att["OCEM_OVERCURRENT"].data<bool>() ); + fec.getOCEM().overTemperature ( att["OCEM_OVERTEMPERATURE"].data<bool>() ); + fec.getOCEM().remote ( att["OCEM_REMOTE"].data<bool>() ); + fec.getOCEM().voltage ( att["OCEM_CORTENSION"].data<float>() ); + fec.getOCEM().current ( att["OCEM_CORCURRENT"].data<float>() ); + fec.getOCEM().on ( att["OCEM_OCEMON"].data<bool>() ); + fec.getOCEM().out ( att["OCEM_OCEMOUTPUT"].data<bool>() ); + fec.getOCEM().state ( att["OCEM_STATE"].data<int>() ); + fec.getLVPS().allVoltGood ( att["AVG"].data<bool>() ); + fec.getLVPS().allModGood ( att["AMG"].data<bool>() ); + fec.getLVPS().overTemperature ( att["PS_OT"].data<bool>() ); + fec.getLVPS().overTemperatureOverRide ( att["PS_OT"].data<bool>() ); + fec.getLVPS().temperature ( att["PS_TEMP"].data<float>() ); + fec.ELMBStat ( att["ELMBSTAT"].data<std::string>() == "OPERATIONAL" ); + fec.crateName ( att["DPNAME"].data<std::string>() ); + +} + diff --git a/LArCalorimeter/LArCondUtils/src/LArHV2Ntuple.cxx b/LArCalorimeter/LArCondUtils/src/LArHV2Ntuple.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7918d140247b10ca0eeb23e7967a3e684231e1e1 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/src/LArHV2Ntuple.cxx @@ -0,0 +1,313 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "LArCondUtils/LArHV2Ntuple.h" +#include "GaudiKernel/Property.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/NTuple.h" +#include "LArHV/LArHVManager.h" +#include "LArHV/EMBHVManager.h" +#include "LArHV/EMBHVModule.h" +#include "LArHV/EMBHVModuleConstLink.h" +#include "LArHV/EMBHVElectrode.h" +#include "LArHV/EMBHVElectrodeConstLink.h" +#include "LArHV/EMECHVManager.h" +#include "LArHV/EMECHVModule.h" +#include "LArHV/EMECHVModuleConstLink.h" +#include "LArHV/EMECHVElectrode.h" +#include "LArHV/EMECHVElectrodeConstLink.h" +#include "LArHV/HECHVManager.h" +#include "LArHV/HECHVModule.h" +#include "LArHV/HECHVModuleConstLink.h" +#include "LArHV/HECHVSubgap.h" +#include "LArHV/EMBPresamplerHVManager.h" +#include "LArHV/EMBPresamplerHVModule.h" +#include "LArHV/EMBPresamplerHVModuleConstLink.h" +#include "LArHV/EMECPresamplerHVManager.h" +#include "LArHV/EMECPresamplerHVModule.h" +#include "LArHV/EMECPresamplerHVModuleConstLink.h" + + + + //Constructor + LArHV2Ntuple:: LArHV2Ntuple(const std::string& name, ISvcLocator* pSvcLocator): + Algorithm(name,pSvcLocator), + m_sgSvc(0), + m_detStore(0), + m_thistSvc(0), + m_tree(0), + m_bec(0), + m_isPresampler(0), + m_eta(0), + m_phi(0), + m_electrode(0), + m_gap(0), + m_hvline(0), + m_hv(0), + m_current(0) + { + + } + + //__________________________________________________________________________ + //Destructor + LArHV2Ntuple::~LArHV2Ntuple() + { + MsgStream log( messageService(), name() ) ; + log << MSG::DEBUG << "LArHV2Ntuple destructor called" << endreq; + } + //__________________________________________________________________________ + StatusCode LArHV2Ntuple::initialize() + { + + MsgStream log( messageService(), name() ); + log << MSG::INFO <<"LArHV2Ntuple initialize()" << endreq; + + // Get the StoreGateSvc + if (service("StoreGateSvc", m_sgSvc).isFailure()) { + log << MSG::ALWAYS << "No StoreGate!!!!!!!" << endreq; + } + + if (service("DetectorStore",m_detStore).isFailure()) { + log << MSG::ALWAYS << "No DetectorStore !!!!!!!" << endreq; + } + +// get THistSvc + if (service("THistSvc",m_thistSvc).isFailure()) { + log << MSG::ERROR << " cannot find THistSvc " << endreq; + return StatusCode::FAILURE; + } + + + + m_tree = new TTree("mytree","Calo Noise ntuple"); + m_tree->Branch("bec",&m_bec,"bec/I"); + m_tree->Branch("isPresampler",&m_isPresampler,"isPresampler/I"); + m_tree->Branch("eta",&m_eta,"eta/F"); + m_tree->Branch("phi",&m_phi,"phi/F"); + m_tree->Branch("HVline",&m_hvline,"HVline/I"); + m_tree->Branch("electrode",&m_electrode,"electrode/I"); + m_tree->Branch("gap",&m_gap,"gap/I"); + m_tree->Branch("hv",&m_hv,"hv/F"); + m_tree->Branch("current",&m_current,"current/F"); + + if( m_thistSvc->regTree("/file1/hv/mytree",m_tree).isFailure()) { + log << MSG::ERROR << " cannot register ntuple " << endreq; + return StatusCode::FAILURE; + } + + + + return StatusCode::SUCCESS; + + } + //__________________________________________________________________________ + StatusCode LArHV2Ntuple::execute() + { + //............................................. + + MsgStream log( messageService(), name() ); + log << MSG::DEBUG << "LArHV2Ntuple execute()" << endreq; + + const LArHVManager *manager = NULL; + if (m_detStore->retrieve(manager)==StatusCode::SUCCESS) { + const EMBHVManager* hvManager_EMB=manager->getEMBHVManager(); + for (unsigned int iSide=hvManager_EMB->beginSideIndex();iSide<hvManager_EMB->endSideIndex();iSide++) { // loop over HV modules + for (unsigned int iPhi=hvManager_EMB->beginPhiIndex();iPhi<hvManager_EMB->endPhiIndex();iPhi++) { + for (unsigned int iSector=hvManager_EMB->beginSectorIndex();iSector<hvManager_EMB->endSectorIndex();iSector++) { + for (unsigned int iEta=hvManager_EMB->beginEtaIndex();iEta<hvManager_EMB->endEtaIndex();iEta++) { //0 to 7 + EMBHVModuleConstLink hvMod = hvManager_EMB->getHVModule(iSide,iEta,iPhi,iSector); + float eta=0.5*(hvMod->getEtaMin()+hvMod->getEtaMax()); + for (unsigned int ielec=0;ielec<32;ielec++) { //use hvMod->getNumElectrodes when bug is corrected + EMBHVElectrodeConstLink electrode = hvMod->getElectrode(ielec); + for (unsigned int iGap=0;iGap<2;iGap++) { // EMB : 2, TRY TO FIND AUTOMATICALLY NB OF GAPS + float hv=electrode->voltage(iGap); + float current = electrode->current(iGap); + float phi = electrode->getPhi(); + + m_bec=0; + m_isPresampler=0; + m_eta=eta; + m_phi=phi; + m_electrode = ielec; + m_gap = iGap; + m_hv = hv; + m_current= current; + m_hvline = electrode->hvLineNo(iGap); + + m_tree->Fill(); + + } //end for iGap + } + } + } + } + } + + const EMBPresamplerHVManager* hvManager_EMBPS=manager->getEMBPresamplerHVManager(); + for (unsigned int iSide=hvManager_EMBPS->beginSideIndex();iSide<hvManager_EMBPS->endSideIndex();iSide++) { // loop over HV modules + for (unsigned int iPhi=hvManager_EMBPS->beginPhiIndex();iPhi<hvManager_EMBPS->endPhiIndex();iPhi++) { + for (unsigned int iEta=hvManager_EMBPS->beginEtaIndex();iEta<hvManager_EMBPS->endEtaIndex();iEta++) { //0 to 7 + EMBPresamplerHVModuleConstLink hvMod = hvManager_EMBPS->getHVModule(iSide,iEta,iPhi); + for (int iGap=0;iGap<2;iGap++) { + float hv = hvMod->voltage(iGap); + float current =hvMod->current(iGap); + float eta = 0.5*(hvMod->getEtaMin()+hvMod->getEtaMax()); + float phi= 0.5*(hvMod->getPhiMin()+hvMod->getPhiMax()); + + m_bec=0; + m_isPresampler=1; + m_eta=eta; + m_phi=phi; + m_electrode = 0; + m_gap = iGap; + m_hv = hv; + m_current= current; + m_hvline = hvMod->hvLineNo(iGap); + + m_tree->Fill(); + + } //end for iGap + } + } + } + + const EMECPresamplerHVManager* hvManager_EMECPS=manager->getEMECPresamplerHVManager(); + for (unsigned int iSide=hvManager_EMECPS->beginSideIndex();iSide<hvManager_EMECPS->endSideIndex();iSide++) { // loop over HV modules + for (unsigned int iPhi=hvManager_EMECPS->beginPhiIndex();iPhi<hvManager_EMECPS->endPhiIndex();iPhi++) { + EMECPresamplerHVModuleConstLink hvMod = hvManager_EMECPS->getHVModule(iSide,iPhi); + for (int iGap=0;iGap<2;iGap++) { + float hv = hvMod->voltage(iGap); + float current =hvMod->current(iGap); + float eta = 0.5*(hvMod->getEtaMin()+hvMod->getEtaMax()); + float phi=0.5*(hvMod->getPhiMin()+hvMod->getPhiMax()); + + m_bec=1; + m_isPresampler=1; + m_eta=eta; + m_phi=phi; + m_electrode = 0; + m_gap = iGap; + m_hv = hv; + m_current= current; + m_hvline = hvMod->hvLineNo(iGap); + + m_tree->Fill(); + + } //end for iGap + } + } + + + + const EMECHVManager* hvManager_EMEC=manager->getEMECHVManager(EMECHVModule::OUTER); + for (unsigned int iSide=hvManager_EMEC->beginSideIndex();iSide<hvManager_EMEC->endSideIndex();iSide++) { // loop over HV modules + for (unsigned int iPhi=hvManager_EMEC->beginPhiIndex();iPhi<hvManager_EMEC->endPhiIndex();iPhi++) { + for (unsigned int iSector=hvManager_EMEC->beginSectorIndex();iSector<hvManager_EMEC->endSectorIndex();iSector++) { + for (unsigned int iEta=hvManager_EMEC->beginEtaIndex();iEta<hvManager_EMEC->endEtaIndex();iEta++) { + EMECHVModuleConstLink hvMod=hvManager_EMEC->getHVModule(iSide,iEta,iPhi,iSector); + float eta=0.5*(hvMod->getEtaMin()+hvMod->getEtaMax()); + for (unsigned int ielec=0;ielec<hvMod->getNumElectrodes();ielec++) { //use hvMod->getNumElectrodes when bug is corrected + EMECHVElectrodeConstLink electrode = hvMod->getElectrode(ielec); + for (unsigned int iGap=0;iGap<2;iGap++) { //EMEC : 2 gaps, TRY TO FIND AUTOMATICALLY NB OF GAPS + float hv=electrode->voltage(iGap); + float current = electrode->current(iGap); + float phi = electrode->getPhi(); + + m_bec=1; + m_isPresampler=0; + m_eta=eta; + m_phi=phi; + m_electrode = ielec; + m_gap = iGap; + m_hv = hv; + m_current= current; + m_hvline = electrode->hvLineNo(iGap); + + m_tree->Fill(); + + } //end for iGap + } + } + } + } + } + + hvManager_EMEC=manager->getEMECHVManager(EMECHVModule::INNER); + for (unsigned int iSide=hvManager_EMEC->beginSideIndex();iSide<hvManager_EMEC->endSideIndex();iSide++) { // loop over HV modules + for (unsigned int iPhi=hvManager_EMEC->beginPhiIndex();iPhi<hvManager_EMEC->endPhiIndex();iPhi++) { + for (unsigned int iSector=hvManager_EMEC->beginSectorIndex();iSector<hvManager_EMEC->endSectorIndex();iSector++) { + for (unsigned int iEta=hvManager_EMEC->beginEtaIndex();iEta<hvManager_EMEC->endEtaIndex();iEta++) { + EMECHVModuleConstLink hvMod=hvManager_EMEC->getHVModule(iSide,iEta,iPhi,iSector); + float eta=0.5*(hvMod->getEtaMin()+hvMod->getEtaMax()); + for (unsigned int ielec=0;ielec<hvMod->getNumElectrodes();ielec++) { //use hvMod->getNumElectrodes when bug is corrected + EMECHVElectrodeConstLink electrode = hvMod->getElectrode(ielec); + for (unsigned int iGap=0;iGap<2;iGap++) { //EMEC : 2 gaps, TRY TO FIND AUTOMATICALLY NB OF GAPS + float hv=electrode->voltage(iGap); + float current = electrode->current(iGap); + float phi = electrode->getPhi(); + + m_bec=2; + m_isPresampler=0; + m_eta=eta; + m_phi=phi; + m_electrode = ielec; + m_gap = iGap; + m_hv = hv; + m_current= current; + m_hvline = electrode->hvLineNo(iGap); + + m_tree->Fill(); + + } //end for iGap + } + } + } + } + } + + const HECHVManager* hvManager_HEC=manager->getHECHVManager(); + float etamax_layer[4]={3.3,3.1,3.1,3.3}; + float etamin_layer[4]={1.5,1.5,1.6,1.7}; + + + for (unsigned int iSide=hvManager_HEC->beginSideIndex();iSide<hvManager_HEC->endSideIndex();iSide++) { // loop over HV modules + for (unsigned int iPhi=hvManager_HEC->beginPhiIndex();iPhi<hvManager_HEC->endPhiIndex();iPhi++) { + for (unsigned int iSampling=hvManager_HEC->beginSamplingIndex();iSampling<hvManager_HEC->endSamplingIndex();iSampling++) { + float eta_min,eta_max; + if (iSide==1) { + eta_min = etamin_layer[iSampling]; + eta_max = etamax_layer[iSampling]; + } else { + eta_min = -1.*etamax_layer[iSampling]; + eta_max = -1.*etamin_layer[iSampling]; + } + float eta = 0.5*(eta_min+eta_max); + HECHVModuleConstLink hvMod = hvManager_HEC->getHVModule(iSide,iPhi,iSampling); + float phi = 0.5*(hvMod->getPhiMin()+hvMod->getPhiMax()); + + for (unsigned int iGap=0;iGap<hvMod->getNumSubgaps();iGap++) {//HEC : 4 gaps, TRY TO FIND AUTOMATICALLY NB OF GAPS + HECHVSubgapConstLink subgap=hvMod->getSubgap(iGap); + float hv = subgap->voltage(); + float current = subgap->current(); + m_bec = 10+iSampling; + m_isPresampler=0; + m_eta=eta; + m_phi=phi; + m_electrode = 0; + m_gap = iGap; + m_hv=hv; + m_current=current; + m_hvline = subgap->hvLineNo(); + m_tree->Fill(); + }// end for iGap + } + } + } + + } + + return StatusCode::SUCCESS; + } + diff --git a/LArCalorimeter/LArCondUtils/src/LArHVPathologyDbAlg.cxx b/LArCalorimeter/LArCondUtils/src/LArHVPathologyDbAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..63055b9ed6bfebca8a2531cc59943ed1f8c6cf4f --- /dev/null +++ b/LArCalorimeter/LArCondUtils/src/LArHVPathologyDbAlg.cxx @@ -0,0 +1,423 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "LArCondUtils/LArHVPathologyDbAlg.h" +#include "LArElecCalib/ILArHVPathologyDbTool.h" +#include "LArRecConditions/LArHVPathologiesDb.h" +#include "RegistrationServices/IIOVRegistrationSvc.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" + +#include "CaloIdentifier/CaloIdManager.h" +#include "CaloIdentifier/LArEM_ID.h" +#include "CaloIdentifier/LArHEC_ID.h" +#include "CaloIdentifier/LArFCAL_ID.h" +#include "LArIdentifier/LArOnlineID.h" +#include "LArTools/LArCablingService.h" +#include "CaloDetDescr/CaloDetDescrManager.h" + +#include "CaloDetDescr/CaloDetectorElements.h" +#include "LArReadoutGeometry/EMBCell.h" +#include "LArHV/EMBHVElectrode.h" +#include "LArHV/EMBHVElectrodeConstLink.h" +#include "LArHV/EMBPresamplerHVModuleConstLink.h" +#include "LArHV/EMBPresamplerHVModule.h" +#include "LArReadoutGeometry/EMECCell.h" +#include "LArHV/EMECHVElectrode.h" +#include "LArHV/EMECHVElectrodeConstLink.h" +#include "LArHV/EMECPresamplerHVModuleConstLink.h" +#include "LArHV/EMECPresamplerHVModule.h" +#include "LArReadoutGeometry/HECCell.h" +#include "LArHV/HECHVSubgapConstLink.h" +#include "LArHV/HECHVSubgap.h" +#include "LArReadoutGeometry/FCALTile.h" +#include "LArHV/FCALHVLineConstLink.h" +#include "LArHV/FCALHVLine.h" + + +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +#include <fstream> + +LArHVPathologyDbAlg::LArHVPathologyDbAlg(const std::string& name, ISvcLocator* pSvcLocator) + : AthAlgorithm(name, pSvcLocator) + , m_writeCondObjs(false) + , m_inpFile("LArHVPathology.inp") + , m_folder("") + , m_outpTag("HVPathologies-TEST") + , m_evt(0) + , m_regSvc("IOVRegistrationSvc",name) + , m_pathologyTool("LArHVPathologyDbTool") + , m_mode(0) + , m_larem_id(0) + , m_larhec_id(0) + , m_larfcal_id(0) + , m_laronline_id(0) +{ + declareProperty("WriteCondObjs", m_writeCondObjs); + declareProperty("InpFile", m_inpFile); + declareProperty("Folder", m_folder); + declareProperty("TagName", m_outpTag); + declareProperty("Mode", m_mode,"Mode to read file (0=offlineID/elecID, 1=online ID fields + HV module/line"); +} + +LArHVPathologyDbAlg::~LArHVPathologyDbAlg() +{ +} + +StatusCode LArHVPathologyDbAlg::initialize() +{ + msg(MSG::INFO) << " in initialize()" << endreq; + + if(m_folder.value().empty()) { + msg(MSG::ERROR) << "Folder property not set. Exiting ... " << endreq; + return StatusCode::FAILURE; + } + + // Get HVPathology tool + StatusCode sc = m_pathologyTool.retrieve(); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Unable to initialize LArHVPathologyDbTool" << endreq; + return sc; + } + else { + msg(MSG::INFO) << "Retrieved LArHVPathologyDbTool" << endreq; + } + + // Get the IOVRegistrationSvc when needed + if(m_writeCondObjs) { + sc = m_regSvc.retrieve(); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Unable to find IOVRegistrationSvc" << endreq; + m_writeCondObjs = false; + return sc; + } + else { + msg(MSG::INFO) << "Retrieved IOVRegistrationSvc " << endreq; + } + } + +// retrieve LArEM id helpers + + sc = detStore()->retrieve( m_caloIdMgr ); + if (sc.isFailure()) { + msg(MSG::ERROR) << "Unable to retrieve CaloIdMgr " << endreq; + return sc; + } + + m_larem_id = m_caloIdMgr->getEM_ID(); + m_larhec_id = m_caloIdMgr->getHEC_ID(); + m_larfcal_id = m_caloIdMgr->getFCAL_ID(); + +// retrieve CaloDetDescrMgr + sc = detStore()->retrieve(m_calodetdescrmgr); + if (sc.isFailure()) { + msg(MSG::ERROR) << "Unable to retrieve CaloDetDescrMgr " << endreq; + return sc; + } + + sc = detStore()->retrieve(m_laronline_id,"LArOnlineID"); + if (sc.isFailure()) { + msg(MSG::ERROR) << "Unable to retrieve LArOnlineID from DetectorStore" + << endreq; + return StatusCode::FAILURE; + } + + + + return sc; +} + +StatusCode LArHVPathologyDbAlg::execute() +{ + msg(MSG::INFO) <<" in execute()" <<endreq; + + StatusCode sc = evtStore()->retrieve(m_evt); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Could not get event info " << endreq; + return sc; + } + + int nevt = m_evt->event_ID()->event_number(); + + if(m_writeCondObjs && nevt==1) { + msg(MSG::INFO) << "Creating conditions objects" << endreq; + + // Create cond objects + sc = createCondObjects(); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Could not create cond objects " << endreq; + m_writeCondObjs = false; + return sc; + } + } + + // Dump cond objects + sc = printCondObjects(); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Could not print out cond objects" << endreq; + return sc; + } + + return sc; +} + +StatusCode LArHVPathologyDbAlg::stop() +{ + msg(MSG::INFO) <<" in stop()" <<endreq; + StatusCode sc= StatusCode::SUCCESS; + + if(m_writeCondObjs) { + sc = registerCondObjects(); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Could not register objects" << endreq; + return sc; + } + else { + msg(MSG::INFO) << "Register OK" << endreq; + } + } + + return sc; +} + +StatusCode LArHVPathologyDbAlg::createCondObjects() +{ + msg(MSG::INFO) <<" in createCondObjects() " <<endreq; + + if(detStore()->contains<AthenaAttributeList>(m_folder)) { + msg(MSG::INFO) << "EMB Pathologies already in SG, skipping " <<endreq; + } + else { + // Read input file and construct LArHVPathologiesDb for given folder + std::ifstream infile; + infile.open(m_inpFile.value().c_str()); + + if(!infile.is_open()) { + msg(MSG::ERROR) << "Unable to open " << m_inpFile << " for reading" << endreq; + return StatusCode::FAILURE; + } + + char checkChar; + char commentSign('#'); + std::string commentLine(""), foldername(""); + unsigned int cellID; + unsigned short electInd, pathologyType; + + // Look for the folder name in the file + while(!infile.eof()) { + infile >> foldername; + if(foldername==m_folder.value()) + break; + } + + if(foldername!=m_folder.value()) { + msg(MSG::ERROR) << "Unable to find data for the folder " << m_folder + << " in the input file" << endreq; + return StatusCode::FAILURE; + } + else + msg(MSG::INFO) << "Found folder " << foldername << " in the input file" << endreq; + + // Get data corresponding to the folder and put it into LArHVPathologiesDb object + LArHVPathologiesDb pathologies; + + msg(MSG::INFO) << " start reading input file " << endreq; + while(!infile.eof()) { + // Number or string? + checkChar = static_cast<char> (infile.get()); + msg(MSG::INFO) << " checChar " << checkChar << endreq; + if(checkChar=='\n') + continue; + if((checkChar >= '0') && (checkChar <= '9')) { + // Number - read three values + infile.unget(); + std::vector<unsigned int> elecList; + elecList.reserve(2); + if (m_mode==0) { + infile >> cellID >> electInd >> pathologyType; + elecList.push_back(electInd); + } else { + unsigned int bec,pos_neg,FT,slot,channel,hvModule,hvLine; + infile >> bec >> pos_neg >> FT >> slot >> channel >> hvModule >> hvLine >> pathologyType; + msg(MSG::INFO) << " read " << bec << " " << pos_neg << " " << FT << " " << slot << " " << channel << " " << hvModule << " " << hvLine << " " << pathologyType << endreq; + HWIdentifier hwid = m_laronline_id->channel_Id(bec,pos_neg,FT,slot,channel); + Identifier id = m_cablingService->cnvToIdentifier( hwid); + cellID = (unsigned int)(id.get_identifier32().get_compact()); + elecList=getElectInd(id,hvModule,hvLine); + msg(MSG::INFO) << " cellId , elecList size " << cellID << " " << elecList.size() << endreq; + } + for (unsigned int i=0;i<elecList.size();i++) { + LArHVPathologiesDb::LArHVElectPathologyDb electPath; + electPath.cellID = cellID; + electPath.electInd = elecList[i]; + electPath.pathologyType = pathologyType; + pathologies.m_v.push_back(electPath); + msg(MSG::INFO) << "Created electrode pathology (" << cellID + << "," << elecList[i] + << "," << pathologyType << ")" << endreq; + } + } + else if(checkChar==commentSign) { + // Skip the comment + std::getline(infile,commentLine); + } + else { + // We found another folder. Stop parsing + break; + } + } + + infile.close(); + msg(MSG::INFO) << "Finished parsing input file" << endreq; + + AthenaAttributeList* attrlist = m_pathologyTool->hvPathology2AttrList(pathologies); + msg(MSG::INFO) << "Created Attribute List" << endreq; + + StatusCode sc = detStore()->record(attrlist,m_folder); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Could not record " << m_folder << endreq; + return sc; + } + else + msg(MSG::INFO) << "Recorded " << m_folder << endreq; + } + + return StatusCode::SUCCESS; +} + +StatusCode LArHVPathologyDbAlg::printCondObjects() +{ + msg(MSG::INFO) <<" in printCondObjects() " <<endreq; + + const AthenaAttributeList* attrlist; + StatusCode sc = detStore()->retrieve(attrlist,m_folder); + + if(sc.isFailure()) + msg(MSG::WARNING) << "Could not find object for " << m_folder << endreq; + else { + LArHVPathologiesDb* pathologyContainer = m_pathologyTool->attrList2HvPathology(*attrlist); + msg(MSG::INFO) << "Unpacked pathologies from Attribute List for " << m_folder << endreq; + + for(unsigned i=0; i<pathologyContainer->m_v.size(); ++i) { + LArHVPathologiesDb::LArHVElectPathologyDb electPath = pathologyContainer->m_v[i]; + msg(MSG::INFO) << "Got pathology for cell ID: " << electPath.cellID + << "(" << electPath.electInd + << "," << electPath.pathologyType << ") " << endreq; + } + delete pathologyContainer; + } + return sc; +} + +StatusCode LArHVPathologyDbAlg::registerCondObjects() +{ + msg(MSG::INFO) << "entering registerCondObject()" << endreq; + + std::string objname("AthenaAttributeList"); + + StatusCode sc = m_regSvc->registerIOV(objname, m_folder, m_outpTag); + if(!sc.isSuccess()) + msg(MSG::ERROR) << "Could not register (" << objname << ", " << m_outpTag << ") in IOV DB " << endreq; + else + msg(MSG::INFO) << "Successfully registered" << endreq; + + return sc; +} + +std::vector<unsigned int> LArHVPathologyDbAlg::getElectInd(const Identifier & id,unsigned int module, unsigned int line) +{ + + std::vector<unsigned int> list; + list.clear(); + int HVline = 1000*module + line; +// EM calo + if (m_larem_id->is_lar_em(id)) { +// LAr EMB + if (abs(m_larem_id->barrel_ec(id))==1 && m_larem_id->sampling(id) > 0) { + if (const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(m_calodetdescrmgr->get_element(id))) { + const EMBCellConstLink cell = embElement->getEMBCell(); + unsigned int nelec = cell->getNumElectrodes(); + for (unsigned int i=0;i<nelec;i++) { + const EMBHVElectrodeConstLink electrode = cell->getElectrode(i); + for (unsigned int igap=0;igap<2;igap++) { + if (electrode->hvLineNo(igap)==HVline) { + list.push_back(2*i+igap); + } + } + } + } + } +// LAr EMEC + if (abs(m_larem_id->barrel_ec(id))>1 && m_larem_id->sampling(id) > 0) { + if (const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(m_calodetdescrmgr->get_element(id))) { + const EMECCellConstLink cell = emecElement->getEMECCell(); + unsigned int nelec = cell->getNumElectrodes(); + for (unsigned int i=0;i<nelec;i++) { + const EMECHVElectrodeConstLink electrode = cell->getElectrode(i); + for (unsigned int igap=0;igap<2;igap++) { + if (electrode->hvLineNo(igap)==HVline) { + list.push_back(2*i+igap); + } + } + } + } + } +// EMBPS + if (abs(m_larem_id->barrel_ec(id))==1 && m_larem_id->sampling(id)==0) { + if (const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(m_calodetdescrmgr->get_element(id))) { + const EMBCellConstLink cell = embElement->getEMBCell(); + const EMBPresamplerHVModuleConstLink hvmodule = cell->getPresamplerHVModule (); + for (unsigned int igap=0;igap<2;igap++) { + if (hvmodule->hvLineNo(igap)==HVline) { + list.push_back(igap); + } + } + } + } +// EMECPS + if (abs(m_larem_id->barrel_ec(id))>1 && m_larem_id->sampling(id)==0) { + if (const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(m_calodetdescrmgr->get_element(id))) { + const EMECCellConstLink cell = emecElement->getEMECCell(); + const EMECPresamplerHVModuleConstLink hvmodule = cell->getPresamplerHVModule (); + for (unsigned int igap=0;igap<2;igap++) { + if (hvmodule->hvLineNo(igap)==HVline) { + list.push_back(igap); + } + } + } + } + } +//HEC + if (m_larhec_id->is_lar_hec(id)) { + if (const HECDetectorElement* hecElement = dynamic_cast<const HECDetectorElement*>(m_calodetdescrmgr->get_element(id))) { + const HECCellConstLink cell = hecElement->getHECCell(); + unsigned int nsubgaps = cell->getNumSubgaps(); + for (unsigned int i=0;i<nsubgaps;i++) { + const HECHVSubgapConstLink subgap = cell->getSubgap(i); + if (subgap->hvLineNo()==HVline) { + list.push_back(i); + } + } + } + } +//FCAL + if (m_larfcal_id->is_lar_fcal(id)) { + if (const FCALDetectorElement* fcalElement = dynamic_cast<const FCALDetectorElement*>(m_calodetdescrmgr->get_element(id))) { + const FCALTile* tile = fcalElement->getFCALTile(); + unsigned int nlines = tile->getNumHVLines(); + for (unsigned int i=0;i<nlines;i++) { + const FCALHVLineConstLink line2 = tile->getHVLine(i); + if (line2) { + if (line2->hvLineNo()==HVline) { + list.push_back(i); + } + } + } + } + } + + return list; + +} diff --git a/LArCalorimeter/LArCondUtils/src/LArHVToolDB.cxx b/LArCalorimeter/LArCondUtils/src/LArHVToolDB.cxx new file mode 100755 index 0000000000000000000000000000000000000000..c7e2ad0824480783cf5d2bdd61993cb8111b5038 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/src/LArHVToolDB.cxx @@ -0,0 +1,629 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "LArCondUtils/LArHVToolDB.h" +#include "GaudiKernel/IToolSvc.h" +#include "StoreGate/StoreGateSvc.h" +#include "LArElecCalib/ILArHVPathologyDbTool.h" +#include "LArRecConditions/LArHVPathologiesDb.h" +#include "CaloDetDescr/CaloDetectorElements.h" +#include "CaloIdentifier/LArEM_ID.h" +#include "CaloIdentifier/LArHEC_ID.h" +#include "CaloIdentifier/LArFCAL_ID.h" +#include "CaloIdentifier/CaloIdManager.h" +#include "CaloDetDescr/CaloDetDescrManager.h" +#include "LArReadoutGeometry/EMBCell.h" +#include "LArHV/EMBHVElectrodeConstLink.h" +#include "LArHV/EMBHVElectrode.h" +#include "LArHV/EMBPresamplerHVModuleConstLink.h" +#include "LArHV/EMBPresamplerHVModule.h" +#include "LArReadoutGeometry/EMECCell.h" +#include "LArHV/EMECHVElectrodeConstLink.h" +#include "LArHV/EMECHVElectrode.h" +#include "LArHV/EMECPresamplerHVModuleConstLink.h" +#include "LArHV/EMECPresamplerHVModule.h" +#include "LArReadoutGeometry/HECCell.h" +#include "LArHV/HECHVSubgapConstLink.h" +#include "LArHV/HECHVSubgap.h" +#include "LArReadoutGeometry/FCALTile.h" +#include "LArHV/FCALHVLineConstLink.h" +#include "LArHV/FCALHVLine.h" + +#include "LArHV/LArHVManager.h" + +#include "LArTools/LArHVCablingTool.h" +#include "LArIdentifier/LArElectrodeID.h" +#include "LArIdentifier/LArHVLineID.h" + +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" + +//#include <iostream> +#include <cmath> +#include <cstdlib> +#include "AthenaKernel/errorcheck.h" + + +const unsigned LArHVToolDB::m_nHVCoolChannels=453+4384; + +// constructor +LArHVToolDB::LArHVToolDB(const std::string& type, + const std::string& name, + const IInterface* parent) + : AthAlgTool(type,name,parent), + m_pathologyTool("LArHVPathologyDbTool"), + m_hvCablingTool("LArHVCablingTool") + { + + declareInterface< ILArHVTool >( this ); + m_DCSFolderNames.push_back(std::string("/LAR/DCS/HV/BARREl/I16")); + m_DCSFolderNames.push_back(std::string("/LAR/DCS/HV/BARREL/I8")); + declareProperty("DCSFolder",m_DCSFolderNames,"LAr HV DCS Folders"); + declareProperty("HVPathologiesFolder",m_HVPathologiesFolderName,"LAr HV Pathologies Folder"); +} + +// destructor +LArHVToolDB::~LArHVToolDB() +{ } + +StatusCode LArHVToolDB::LoadCalibration(IOVSVC_CALLBACK_ARGS_K( keys)) { + + std::set<size_t> DCSfolderIndices; + bool doPathology=false; + for (std::list<std::string>::const_iterator itr=keys.begin(); itr!=keys.end(); ++itr) { + ATH_MSG_DEBUG("Processing callback for SG key " << *itr); + if (*itr == m_HVPathologiesFolderName) { + doPathology=true; + } + else if(*itr == "/LAR/IdentifierOfl/HVLineToElectrodeMap") { //FIXME hardcoded foldername .The name is actually a jobO of LArHVCablingTool + msg(MSG::INFO) << "Received a callback on HV Cable Map. Need to (re)laod all HV DCS folders" << endreq; + for(size_t i=0;i<m_DCSFolderNames.size();++i) { + DCSfolderIndices.insert(i); + m_voltageCache[i].clear(); //Clear voltage cache + } + } + else { + for(size_t i=0;i<m_DCSFolderNames.size();++i) { + if (*itr==m_DCSFolderNames[i]) { + DCSfolderIndices.insert(i); + m_nUpdatesPerFolder[i].m_nCallbacks++; + } + } + } + } + if (DCSfolderIndices.size()) { + ATH_MSG_INFO("Received a callback for " << DCSfolderIndices.size() << " HV folders."); + if (fillUpdatedHVChannelsVec(DCSfolderIndices).isFailure()) { + msg(MSG::ERROR) << "Call to fillUpdatedHVChannelsVec failed." << endreq; + return StatusCode::FAILURE; + } + } + if (m_updatedElectrodes.size()>0) { + const LArHVManager *manager = NULL; + if (detStore()->retrieve(manager)==StatusCode::SUCCESS) { + manager->reset(); + } + } + + if (doPathology) { + msg(MSG::INFO) << " LArHVToolDB::LoadCalibration: Load HV pathology database " << endreq; + if (m_pathologyContainer) delete m_pathologyContainer; + if (detStore()->contains<AthenaAttributeList>(m_HVPathologiesFolderName)) { + if (m_pathologiesHandle.isValid()) { + m_pathologyContainer = m_pathologyTool->attrList2HvPathology((*m_pathologiesHandle)); + msg (MSG::INFO) << " Number of HV pathologies found " << m_pathologyContainer->m_v.size() << endreq; + for(unsigned i=0; i<m_pathologyContainer->m_v.size(); ++i) { + + LArHVPathologiesDb::LArHVElectPathologyDb electPath = m_pathologyContainer->m_v[i]; + Identifier id(electPath.cellID); + if (m_larem_id->is_lar_em(id)) { + IdentifierHash idHash = m_larem_id->channel_hash(id); + unsigned int index = (unsigned int)(idHash); + if (index<m_hasPathologyEM.size()) m_hasPathologyEM[index]=true; + } + if (m_larhec_id->is_lar_hec(id)) { + IdentifierHash idHash = m_larhec_id->channel_hash(id); + unsigned int index = (unsigned int)(idHash); + if (index<m_hasPathologyHEC.size()) m_hasPathologyHEC[index]=true; + } + if (m_larfcal_id->is_lar_fcal(id)) { + IdentifierHash idHash = m_larfcal_id->channel_hash(id); + unsigned int index = (unsigned int)(idHash); + if (index<m_hasPathologyFCAL.size()) m_hasPathologyFCAL[index]=true; + } + } + } + } + } + + return StatusCode::SUCCESS; + +} + + +StatusCode LArHVToolDB::finalize() { + for (size_t i=0;i<m_nUpdatesPerFolder.size();++i) { + msg(MSG::INFO) << "Folder: " << m_DCSFolderNames[i] + << ": # of Callbacks:" << m_nUpdatesPerFolder[i].m_nCallbacks + << ", # of actual voltage changes:" << m_nUpdatesPerFolder[i].m_nVoltageUpdates + << endreq; + } + if (m_pathologyContainer) delete m_pathologyContainer; + return StatusCode::SUCCESS; +} + + +// intialize +StatusCode LArHVToolDB::initialize(){ +// retrieve LArEM id helpers + CHECK(detStore()->retrieve(m_caloIdMgr)); + + m_larem_id = m_caloIdMgr->getEM_ID(); + m_larhec_id = m_caloIdMgr->getHEC_ID(); + m_larfcal_id = m_caloIdMgr->getFCAL_ID(); + +// retrieve CaloDetDescrMgr + CHECK(detStore()->retrieve(m_calodetdescrmgr)); + + // retrieve the LArElectrodeID helper + CHECK(detStore()->retrieve(m_electrodeID)); + + //retrieve the LArHVLineID helper + CHECK(detStore()->retrieve(m_hvLineID)); + +// register callback to Database folder + m_voltageCache.resize(m_DCSFolderNames.size()); + m_nUpdatesPerFolder.resize(m_DCSFolderNames.size()); + for (size_t i=0;i<m_DCSFolderNames.size();++i) { + const DataHandle<CondAttrListCollection> cHdl; + if ((detStore()->regFcn(&ILArHVTool::LoadCalibration,dynamic_cast<ILArHVTool*>(this),cHdl,m_DCSFolderNames[i])).isFailure()) { + msg(MSG::ERROR) << "cannot register callback to " << m_DCSFolderNames[i] << std::endl; + } + else + msg(MSG::INFO) << "Registered callback to DCS folder " << m_DCSFolderNames[i] << endreq; + } + + m_pathologyContainer = 0; + m_hasPathologyEM.resize(m_larem_id->channel_hash_max(),false); + m_hasPathologyHEC.resize(m_larhec_id->channel_hash_max(),false); + m_hasPathologyFCAL.resize(m_larfcal_id->channel_hash_max(),false); + + m_HVPathologiesFolderName = "/LAR/HVPathologiesOfl/Pathologies"; + if (detStore()->contains<AthenaAttributeList>( m_HVPathologiesFolderName)) { + StatusCode sc=detStore()->regFcn(&ILArHVTool::LoadCalibration,dynamic_cast<ILArHVTool*>(this),m_pathologiesHandle,m_HVPathologiesFolderName); + if (sc.isFailure()) + msg(MSG::ERROR) << "cannot register callback to " << m_HVPathologiesFolderName << endreq; + else + msg(MSG::INFO) << "registered callback to " << m_HVPathologiesFolderName << endreq; + } + else + msg(MSG::INFO) << " no information for HV pathology available " << endreq; + + + // Get HVPathology tool + StatusCode sc = m_pathologyTool.retrieve(); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Unable to initialize LArHVPathologyDbTool" << endreq; + return sc; + } + else { + msg(MSG::INFO) << "Retrieved LArHVPathologyDbTool" << endreq; + } + + + sc=m_hvCablingTool.retrieve(); + if(!sc.isSuccess()) { + msg(MSG::ERROR) << "Unable to retrieve LArHVCablingTool" << endreq; + return sc; + } + + + sc=detStore()->regFcn(&LArHVCablingTool::iovCallback,&(*m_hvCablingTool), + &ILArHVTool::LoadCalibration,dynamic_cast<ILArHVTool*>(this)); + if (!sc.isSuccess()) { + msg(MSG::ERROR) << "Unable to register callback on LArHVCablingTool::iovCallback" << endreq; + return sc; + } + else + msg(MSG::INFO) << "registered callback to LArHVCablingTool" << endreq; + return StatusCode::SUCCESS; +} + + +StatusCode LArHVToolDB::getHV(const Identifier& id, + std::vector< HV_t > & v ) +{ + std::vector< CURRENT_t> ihv; + return getPayload(id,v,ihv); +} + +StatusCode LArHVToolDB::getCurrent(const Identifier& id, + std::vector< CURRENT_t > & ihv ) +{ + std::vector< HV_t> v; + return getPayload(id,v,ihv); +} + + +StatusCode LArHVToolDB::getPayload(const Identifier& id, std::vector< HV_t > & v, std::vector< CURRENT_t > & ihv) +{ + + if (id==m_id) { + v = m_v; + ihv = m_i; + return StatusCode::SUCCESS; + } + + m_id = id; + + v.clear(); + ihv.clear(); + + std::vector<unsigned int> listElec; + +// check identifier in LAR + if (m_larem_id->is_lar_em(id) && m_larem_id->sampling(id) > 0) { +// LAr EMB + if (abs(m_larem_id->barrel_ec(id))==1) { + //std::cout << " in barrel " << m_larem_id->show_to_string(id) << std::endl; + unsigned int index = (unsigned int)(m_larem_id->channel_hash(id)); + bool hasPathology=false; + if (index<m_hasPathologyEM.size()) { + if (m_hasPathologyEM[index]) { + hasPathology=true; + listElec = getElecList(id); + } + } + const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(m_calodetdescrmgr->get_element(id)); + if (!embElement) std::abort(); + const EMBCellConstLink cell = embElement->getEMBCell(); + unsigned int nelec = cell->getNumElectrodes(); + //std::cout << " nelec " << nelec << std::endl; + unsigned int ngap = 2*nelec; + double wt = 1./ngap; + for (unsigned int i=0;i<nelec;i++) { + const EMBHVElectrodeConstLink electrode = cell->getElectrode(i); + //std::cout << "electrode: endcap index, eta index , phi index, sector index , electrode index " << electrode->getModule()->getSideIndex() << + // " " << electrode->getModule()->getEtaIndex() << " " << electrode->getModule()->getPhiIndex() << + // " " << electrode->getModule()->getSectorIndex() << " " << electrode->getElectrodeIndex() << std::endl; + for (unsigned int igap=0;igap<2;igap++) { + double hv; + double curr; + electrode->voltage_current(igap,hv,curr); + if (hasPathology) { + for (unsigned int ii=0;ii<listElec.size();ii++) { + if (listElec[ii]==(2*i+igap)) { + hv=0.; + curr=0.; + } + } + } + //std::cout << " hv value " << hv << std::endl; + //if (igap==1 && hv>1.) std::cout << " --- non zero value found for gap1 in barrel " << std::endl; + addHV(v,hv,wt); + addCurr(ihv,curr,wt); + + } + } + } +// LAr EMEC + else { + //std::cout << " in EMEC " << m_larem_id->show_to_string(id) << std::endl; + unsigned int index = (unsigned int)(m_larem_id->channel_hash(id)); + bool hasPathology=false; + if (index<m_hasPathologyEM.size()) { + if (m_hasPathologyEM[index]) { + hasPathology=true; + listElec = getElecList(id); + } + } + + const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(m_calodetdescrmgr->get_element(id)); + if (!emecElement) std::abort(); + const EMECCellConstLink cell = emecElement->getEMECCell(); + unsigned int nelec = cell->getNumElectrodes(); + //std::cout << " nelec " << nelec << std::endl; + unsigned int ngap = 2*nelec; + double wt = 1./ngap; + for (unsigned int i=0;i<nelec;i++) { + const EMECHVElectrodeConstLink electrode = cell->getElectrode(i); + // std::cout << "electrode: endcap index, eta index , phi index, sector index , electrode index " << electrode->getModule()->getSideIndex() << + // " " << electrode->getModule()->getEtaIndex() << " " << electrode->getModule()->getPhiIndex() << + // " " << electrode->getModule()->getSectorIndex() << " " << electrode->getElectrodeIndex() << std::endl; + for (unsigned int igap=0;igap<2;igap++) { + double hv; + double curr; + electrode->voltage_current(igap,hv,curr); + if (hasPathology) { + for (unsigned int ii=0;ii<listElec.size();ii++) { + if (listElec[ii]==(2*i+igap)) { + hv=0.; + curr=0.; + } + } + } + //std::cout << " hv value " << hv << std::endl; + //if (igap==1 && hv>1.) std::cout << " --- non zero value found for gap1 in endcap " << std::endl; + addHV(v,hv,wt); + addCurr(ihv,curr,wt); + } + } + + } + } +// LAr HEC + else if (m_larhec_id->is_lar_hec(id)) { + //std::cout << " in HEC " << std::endl; + unsigned int index = (unsigned int)(m_larhec_id->channel_hash(id)); + bool hasPathology=false; + if (index<m_hasPathologyHEC.size()) { + if (m_hasPathologyHEC[index]) { + hasPathology=true; + listElec = getElecList(id); + } + } + const HECDetectorElement* hecElement = dynamic_cast<const HECDetectorElement*>(m_calodetdescrmgr->get_element(id)); + if (!hecElement) std::abort(); + const HECCellConstLink cell = hecElement->getHECCell(); + unsigned int nsubgaps = cell->getNumSubgaps(); + double wt = 1./nsubgaps; + //std::cout << " nsubgaps " << nsubgaps << std::endl; + for (unsigned int i=0;i<nsubgaps;i++) { + const HECHVSubgapConstLink subgap = cell->getSubgap(i); + double hv; + double curr; + subgap->voltage_current(hv,curr); + //std::cout << " hv value " << hv << std::endl; + if (hasPathology) { + for (unsigned int ii=0;ii<listElec.size();ii++) { + if (listElec[ii]==i) { + hv=0.; + curr=0.; + } + } + } + + addHV(v,hv,wt); + addCurr(ihv,curr,wt); + } + + } +// LAr FCAL + else if (m_larfcal_id->is_lar_fcal(id)) { + //std::cout << " in FCAL " << std::endl; + unsigned int index = (unsigned int)(m_larfcal_id->channel_hash(id)); + bool hasPathology=false; + if (index<m_hasPathologyFCAL.size()) { + if (m_hasPathologyFCAL[index]) { + hasPathology=true; + listElec = getElecList(id); + } + } + const FCALDetectorElement* fcalElement = dynamic_cast<const FCALDetectorElement*>(m_calodetdescrmgr->get_element(id)); + if (!fcalElement) std::abort(); + const FCALTile* tile = fcalElement->getFCALTile(); + //std::cout << " --- in FCAL cell id " << m_larfcal_id->show_to_string(id) << std::endl; + //std::cout << " Side, Module, I,J index " << tile->getModule()->getEndcapIndex() << " " << tile->getModule()->getModuleIndex() + // << " " << tile->getIndexI() << " " << tile->getIndexJ() << std::endl; + unsigned int nlines = tile->getNumHVLines(); + unsigned int nlines_found=0; + for (unsigned int i=0;i<nlines;i++) { + const FCALHVLineConstLink line = tile->getHVLine(i); + if (line) nlines_found++; + } + //std::cout << " nlines " << nlines << " " << nlines_found << std::endl; + if (nlines_found>0) { + double wt = 1./nlines_found; + for (unsigned int i=0;i<nlines;i++) { + const FCALHVLineConstLink line = tile->getHVLine(i); + if (!line) continue; + //std::cout << " line " << line; + double hv; + double curr; + line->voltage_current(hv,curr); + if (hasPathology) { + for (unsigned int ii=0;ii<listElec.size();ii++) { + if (listElec[ii]==i) { + hv=0.; + curr=0.; + } + } + } + //std::cout << " hv value " << hv << std::endl; + addHV(v,hv,wt); + addCurr(ihv,curr,wt); + } + } + + } +// Presamplers + else if (m_larem_id->is_lar_em(id) && m_larem_id->sampling(id)==0) { + + if (abs(m_larem_id->barrel_ec(id))==1) { + + const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(m_calodetdescrmgr->get_element(id)); + if (!embElement) std::abort(); + const EMBCellConstLink cell = embElement->getEMBCell(); + + const EMBPresamplerHVModuleConstLink hvmodule = cell->getPresamplerHVModule (); + + double wt = 0.5; + for (unsigned int igap=0;igap<2;igap++) { + double hv; + double curr; + hvmodule->voltage_current(igap,hv,curr); + addHV(v,hv,wt); + addCurr(ihv,curr,wt); + } + + } + else { + + const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(m_calodetdescrmgr->get_element(id)); + if (!emecElement) std::abort(); + const EMECCellConstLink cell = emecElement->getEMECCell(); + + const EMECPresamplerHVModuleConstLink hvmodule = cell->getPresamplerHVModule (); + + double wt = 0.5; + for (unsigned int igap=0;igap<2;igap++) { + double hv; + double curr; + hvmodule->voltage_current(igap,hv,curr); + addHV(v,hv,wt); + addCurr(ihv,curr,wt); + } + + } + } + else { + msg(MSG::WARNING) << " cell neither in EM nor HEC nor FCAL !!!!! return empty HV " << endreq; + } + + m_v = v; + m_i = ihv; + + return StatusCode::SUCCESS; +} + +void LArHVToolDB::addHV(std::vector< HV_t > & v , double hv, double wt) +{ + bool found=false; + for (unsigned int i=0;i<v.size();i++) { + if (std::fabs(hv-v[i].hv) < 0.1) { + found=true; + v[i].weight += wt; + break; + } + } + if (!found) { + HV_t hh; + hh.hv = hv; + hh.weight = wt; + v.push_back(hh); + } // not already in the list +} + +void LArHVToolDB::addCurr(std::vector< CURRENT_t > & ihv , double current, double wt) +{ + bool found=false; + for (unsigned int i=0;i<ihv.size();i++) { + if (std::fabs(current-ihv[i].current) < 0.1) { + found=true; + ihv[i].weight += wt; + break; + } + } + if (!found) { + CURRENT_t ii; + ii.current = current; + ii.weight = wt; + ihv.push_back(ii); + } // not already in the list +} + +std::vector<unsigned int> LArHVToolDB::getElecList(const Identifier& id) +{ + std::vector<unsigned int> myList; + myList.clear(); + for(unsigned i=0; i<m_pathologyContainer->m_v.size(); ++i) { + LArHVPathologiesDb::LArHVElectPathologyDb electPath = m_pathologyContainer->m_v[i]; + if (electPath.cellID == (unsigned int)(id.get_identifier32().get_compact())) { + myList.push_back(electPath.electInd); + } + } + return myList; + +} + + + +StatusCode LArHVToolDB::fillUpdatedHVChannelsVec(const std::set<size_t>& folderIndices) { + m_updatedElectrodes.clear(); + + std::vector<unsigned> updatedHVLines; + //Loop over the list of DCS folders for with a callback has been fired + std::set<size_t>::const_iterator fldrIt=folderIndices.begin(); + std::set<size_t>::const_iterator fldrIt_e=folderIndices.end(); + for(;fldrIt!=fldrIt_e;++fldrIt) { + const size_t idx=*fldrIt; + //Get the internal cache and the AttributeListCollection for this folder + std::vector<std::pair<unsigned,float> >& voltageCache=m_voltageCache[idx]; + //if (!m_DCSHandles[idx].isValid()) { + // msg(MSG::ERROR) << "DataHandle for folder " << m_DCSFolderNames[idx] << " not valid!" << endreq; + // return StatusCode::FAILURE; + //} + const CondAttrListCollection* attrlist=NULL; //m_DCSHandles[idx].cptr(); + if (detStore()->retrieve(attrlist,m_DCSFolderNames[idx]).isFailure()) { + msg(MSG::ERROR) << "Failed to retrieve CondAttrListCollection with key " << m_DCSFolderNames[idx] << "." << endreq; + return StatusCode::FAILURE; + } + + const size_t cacheSize=voltageCache.size(); + if (!cacheSize) { + //First call, fill cache + updatedHVLines.reserve(m_nHVCoolChannels); + m_updatedElectrodes.reserve(m_electrodeID->electrodeHashMax()); + voltageCache.reserve(500); + CondAttrListCollection::const_iterator citr=attrlist->begin(); + CondAttrListCollection::const_iterator citr_e=attrlist->end(); + for(;citr!=citr_e;++citr) { + const unsigned chan=citr->first; + updatedHVLines.push_back(chan); //For the first callback, every HV channel will be marked as 'updated' + const coral::Attribute& attr=((citr)->second)["R_VMEAS"]; + float voltage=-999; + if (!attr.isNull()) voltage=attr.data<float>(); //Ignore NULL values + voltageCache.push_back(std::make_pair(chan,voltage)); + }//end loop over attributeListCollection + ATH_MSG_DEBUG("Filling cache for folder: " << m_DCSFolderNames[idx] <<". " << voltageCache.size() << " Channels."); + }//end if cachesize==0 + else { + //Cache already filled + size_t cacheIdx=0; + unsigned voltageHasChanged=0; + if (cacheIdx+attrlist->size() > cacheSize) { + msg(MSG::ERROR) << "Folder: " << m_DCSFolderNames[idx] + << ": Got more COOL channels than in previous callback (" << cacheSize << " -> " << cacheIdx+attrlist->size() << ")." + << endreq; + return StatusCode::FAILURE; + } + CondAttrListCollection::const_iterator citr=attrlist->begin(); + CondAttrListCollection::const_iterator citr_e=attrlist->end(); + for(;citr!=citr_e;++citr,++cacheIdx) { + std::pair<unsigned,float>& currChanCache=voltageCache[cacheIdx]; + if (currChanCache.first != citr->first) { + msg(MSG::ERROR) << "Folder: " << m_DCSFolderNames[idx] + << ": COOL channel in unexpected order! Got channel #" << citr->first << " expected #" << currChanCache.first + << endreq; + return StatusCode::FAILURE; + } + const coral::Attribute& attr=((citr)->second)["R_VMEAS"]; + if (attr.isNull()) continue; //Ignore NULL values + const float voltage=attr.data<float>(); + if (voltage!=currChanCache.second) { + updatedHVLines.push_back(currChanCache.first); + currChanCache.second=voltage; + voltageHasChanged=1; + } + }//end loop over AttibuteListCollection + m_nUpdatesPerFolder[idx].m_nVoltageUpdates+=voltageHasChanged; + ATH_MSG_DEBUG("Folder: " << m_DCSFolderNames[idx] << ": Found " << updatedHVLines.size() << " Channels with voltage changes so far."); + }//end else + }//end loop over folders + + + //Build vector of electrode IDs: + std::vector<unsigned>::const_iterator hvLineIt=updatedHVLines.begin(); + std::vector<unsigned>::const_iterator hvLineIt_e=updatedHVLines.end(); + for(;hvLineIt!=hvLineIt_e;++hvLineIt) { + const unsigned node=(*hvLineIt)/1000; + const unsigned line=(*hvLineIt)%1000; + HWIdentifier hvlineid=m_hvLineID->HVLineId(1,1,node,line); + const std::vector<HWIdentifier>& electrodeIdVec=m_hvCablingTool->getLArElectrodeIDvec(hvlineid); + m_updatedElectrodes.insert(m_updatedElectrodes.end(),electrodeIdVec.begin(),electrodeIdVec.end()); + } + + ATH_MSG_DEBUG("Number of electrodes with voltage change:" << m_updatedElectrodes.size() << " (max=" << m_electrodeID->electrodeHashMax() << ")"); + return StatusCode::SUCCESS; +} diff --git a/LArCalorimeter/LArCondUtils/src/LArHVToolMC.cxx b/LArCalorimeter/LArCondUtils/src/LArHVToolMC.cxx new file mode 100755 index 0000000000000000000000000000000000000000..744810661ecc3cc784a9aade6f6fdd8673118285 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/src/LArHVToolMC.cxx @@ -0,0 +1,322 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <stdlib.h> +#include <iostream> + +#include "LArCondUtils/LArHVToolMC.h" + +#include "GaudiKernel/IToolSvc.h" +#include "GaudiKernel/MsgStream.h" +#include "StoreGate/StoreGateSvc.h" + +#include "Identifier/Identifier.h" +#include "CaloIdentifier/CaloIdManager.h" +#include "CaloIdentifier/LArEM_ID.h" +#include "LArIdentifier/LArElectrodeID.h" + +#include "RDBAccessSvc/IRDBAccessSvc.h" +#include "RDBAccessSvc/IRDBRecord.h" +#include "RDBAccessSvc/IRDBRecordset.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" + +#include <iostream> +#include <cmath> + +// constructor +LArHVToolMC::LArHVToolMC(const std::string& type, + const std::string& name, + const IInterface* parent) + : AlgTool(type,name,parent), + m_readASCII(false) +{ + declareInterface< ILArHVTool >( this ); + declareProperty("readASCII",m_readASCII); +} + +// destructor +LArHVToolMC::~LArHVToolMC() +{ } + +// intialize +StatusCode LArHVToolMC::initialize() +{ + + MsgStream log(msgSvc(),name()); + + StatusCode sc = service("DetectorStore",m_detStore); + if(sc!=StatusCode::SUCCESS) return sc; + +// retrieve LArEM id helper + + sc = m_detStore->retrieve( m_caloIdMgr ); + if (sc.isFailure()) { + log << MSG::ERROR << "Unable to retrieve CaloIdMgr " << endreq; + return sc; + } + + m_larem_id = m_caloIdMgr->getEM_ID(); + + m_first=true; + + const LArElectrodeID* electrodeID; + + sc = m_detStore->retrieve(electrodeID); + if (sc.isFailure()) { + log << MSG::ERROR << "Unable to retrieve ElectrodeID helper" << endreq; + return sc; + } + + //Dummy implementation for MC. We assume that all electrodes had been update + m_updatedElectrodes.reserve(electrodeID->electrodeHashMax()); + for (unsigned i=0;i<electrodeID->electrodeHashMax();++i) { + m_updatedElectrodes.push_back(electrodeID->ElectrodeId(IdentifierHash(i))); + } + + return StatusCode::SUCCESS; +} + + + +StatusCode LArHVToolMC::getHV(const Identifier& id, + std::vector< HV_t > & v ) +{ + + if (m_first) { + this->InitHV(); + m_first=false; + } + + v.clear(); + +// check identifier in LAR + if (m_larem_id->is_lar_em(id)) { +// check identifier in barrel + if (abs(m_larem_id->barrel_ec(id))==1) { + int sampling=m_larem_id->sampling(id); + if (sampling>0) { + int region=m_larem_id->region(id); + int ieta=m_larem_id->eta(id); + int iphi=m_larem_id->phi(id); + int ietahv,iphi1,iphi2,ipm; +// ipm =0 for eta>0 1 for eta<0 + if (m_larem_id->barrel_ec(id)==1) ipm=0; + else ipm=1; + if (sampling==1 && region==0) { + iphi1=iphi*16; + iphi2=iphi1+16; + } + else { + iphi1=iphi*4; + iphi2=iphi1+4; + } + if (region==0) { + if (sampling==1) ietahv=ieta/64; + else if (sampling==2) ietahv=ieta/8; + else ietahv=ieta/4; + } + else ietahv=6; + double ngaps = 2.*(iphi2-iphi1); + + for (int iphihv=iphi1;iphihv<iphi2;iphihv++) { + for (int iside=0;iside<2;iside++) { + double hv=m_hv[ipm][iphihv][ietahv][iside]; + bool found=false; + for (unsigned int i=0;i<v.size();i++) { + if (std::fabs(hv-v[i].hv) < 0.1) { + found=true; + v[i].weight += 1./ngaps; + } + } + if (!found) { + HV_t hh; + hh.hv = hv; + hh.weight = 1./ngaps; + v.push_back(hh); + } // not already in the list + } // loop over gap size + } // loop over electrodes + } // in accordion + } // in barrel + } // in LAr + +// hack to return something for other calos + if (v.size()==0) { + HV_t hh; + hh.hv = 2000.; + hh.weight = 1.; + v.push_back(hh); + } + + return StatusCode::SUCCESS; +} + +StatusCode LArHVToolMC::getCurrent(const Identifier& /* id */, + std::vector< CURRENT_t > & v ) +{ + MsgStream log(msgSvc(),name()); + log << MSG::WARNING << " LArHVToolMC: getCurrent not implemented " << endreq; + CURRENT_t cu; + cu.current=0; + cu.weight=1.; + v.push_back(cu); + return StatusCode::SUCCESS; +} + +void LArHVToolMC::InitHV() +{ + bool setHandcoded=false; + double defaultHvVal = 2000.; + + if (!m_readASCII) { + IRDBAccessSvc *pAccessSvc; + StatusCode status = service("RDBAccessSvc",pAccessSvc); + if(status.isFailure()) + { + std::cout << "LArHVToolMC::InitHV() unable to get RDBAccess Service! Use default HV values\n"; + setHandcoded = true; + } + const AthenaAttributeList* keys = 0; + if (!setHandcoded) { + if (m_detStore->contains<AthenaAttributeList>("/LAR/HVBARREL/MAPINLINE")) { + status = m_detStore->retrieve(keys, "/LAR/HVBARREL/MAPINLINE"); + if(status.isFailure()) + { + std::cout << "LArHVToolMC::InitHV() unable to retrieve AthenaAttributeList! Use default HV values\n"; + setHandcoded = true; + } + } + else { + std::cout << "LArHVToolMC::InitHV() no HV map in DetStore. Use Dedault HV values\n"; + setHandcoded = true; + } + } + + std::string nodeName, tagName; + if (!setHandcoded) { + try + { + nodeName = (*keys)["HvBarrelNode"].data<std::string>(); + tagName = (*keys)["HvBarrelTag"].data<std::string>(); + } + catch(std::exception& e) + { + std::cout << e.what() << "\n"; + std::cout << " Use default HV values " << std::endl; + setHandcoded = true; + } + } + + if(!setHandcoded) + { + // retrieve the payload data + pAccessSvc->connect("LARHV"); + const IRDBRecordset* hvGlob; + hvGlob = pAccessSvc->getRecordset("HVBarrelGlob",tagName,nodeName,"LARHV"); + + if(hvGlob->size()>0) + defaultHvVal = (*hvGlob)[0]->getDouble("DEFAULTVAL"); + + std::cout << " read defaultHvVal from database " << defaultHvVal << std::endl; + } + + // set default values + std::cout << " defaultHvVal " << defaultHvVal <<std::endl; + for (int ipm=0;ipm<2;ipm++) { + for (int ielec=0;ielec<1024;ielec++) { + for (int ieta=0;ieta<7;ieta++) { + for (int iside=0;iside<2;iside++) { + m_hv[ipm][ielec][ieta][iside] = defaultHvVal; + } + } + } + } + + // apply imperfections + if(!setHandcoded) + { + const IRDBRecordset* hvVal; + hvVal = pAccessSvc->getRecordset("HVBarrelVal", tagName,nodeName,"LARHV"); + + for(unsigned int indx=0; indx<hvVal->size(); indx++) + { + const IRDBRecord* record = (*hvVal)[indx]; + int nZSide = record->getInt("ZSIDE"); + int nEtaReg = record->getInt("ETAREGION"); + int nGapSide = record->getInt("GAPSIDE"); + int nFirstElec = record->getInt("FIRSTELEC"); + int nLastElec = record->getInt("LASTELEC"); + double hvVal = record->getDouble("HVVALUE"); + + std::cout << " found pathological region " << nZSide << " " << nEtaReg << " " << nGapSide + << " " << nFirstElec << " " << nLastElec << " " << hvVal << std::endl; + + if(nFirstElec<=nLastElec) + for(int iel=nFirstElec; iel<=nLastElec; iel++) + m_hv[nZSide][iel][nEtaReg][nGapSide] = hvVal; + else + std::cerr << "LArBarrelCalculator::InitHV() nLastElec<nFirstElec for:\n" + << "Z Side = " << nZSide << "\n" + << "Eta Reg = " << nEtaReg << "\n" + << "Gap Side = " << nGapSide << "\n"; + } + pAccessSvc->disconnect("LARHV"); + } + + } + +// read from ASCII + else { + + // set default values + std::cout << " defaultHvVal " << defaultHvVal <<std::endl; + for (int ipm=0;ipm<2;ipm++) { + for (int ielec=0;ielec<1024;ielec++) { + for (int ieta=0;ieta<7;ieta++) { + for (int iside=0;iside<2;iside++) { + m_hv[ipm][ielec][ieta][iside] = defaultHvVal; + } + } + } + } + + std::string filename = "hv.txt"; + + FILE * fp = fopen(filename.c_str(),"r"); + char line[81]; + while (fgets(line,80,fp)) { + int nZSide,nEtaReg,nGapSide,nFirstElec,nLastElec; + float hvVal; + sscanf(&line[0],"%d%d%d%d%d%f",&nZSide,&nEtaReg,&nGapSide,&nFirstElec,&nLastElec,&hvVal); + + std::cout << " found pathological region " << nZSide << " " << nEtaReg << " " << nGapSide + << " " << nFirstElec << " " << nLastElec << " " << hvVal << std::endl; + + if(nFirstElec>=0 && nFirstElec<1024 && + nLastElec>=0 && nLastElec<1024 && + nZSide >= 0 && nZSide < 2 && + nEtaReg >= 0 && nEtaReg < 7 && + nGapSide >= 0 && nGapSide < 2 && + nFirstElec<=nLastElec) + { + for(int iel=nFirstElec; iel<=nLastElec; iel++) + m_hv[nZSide][iel][nEtaReg][nGapSide] = hvVal; + } + else + std::cerr << "LArBarrelCalculator::InitHV() bad input for:\n" + << "Z Side = " << nZSide << "\n" + << "Eta Reg = " << nEtaReg << "\n" + << "Gap Side = " << nGapSide << "\n"; + + } + fclose (fp); + + } + +} + +StatusCode LArHVToolMC::LoadCalibration(IOVSVC_CALLBACK_ARGS) +{ + return StatusCode::SUCCESS; +} diff --git a/LArCalorimeter/LArCondUtils/src/components/LArCondUtils_entries.cxx b/LArCalorimeter/LArCondUtils/src/components/LArCondUtils_entries.cxx new file mode 100755 index 0000000000000000000000000000000000000000..cd4d02d1ef6a0efed26520e2b830ac76cbae627b --- /dev/null +++ b/LArCalorimeter/LArCondUtils/src/components/LArCondUtils_entries.cxx @@ -0,0 +1,25 @@ +#include "LArCondUtils/LArFecLvTempDcsTool.h" +#include "LArCondUtils/LArHVToolMC.h" +#include "LArCondUtils/LArHVToolDB.h" +#include "LArCondUtils/LArFEBTempTool.h" +#include "LArCondUtils/LArHVPathologyDbAlg.h" +#include "LArCondUtils/LArHV2Ntuple.h" + +#include "GaudiKernel/DeclareFactoryEntries.h" + + +DECLARE_TOOL_FACTORY( LArFecLvTempDcsTool ) +DECLARE_TOOL_FACTORY( LArHVToolMC ) +DECLARE_TOOL_FACTORY( LArHVToolDB ) +DECLARE_TOOL_FACTORY( LArFEBTempTool ) +DECLARE_ALGORITHM_FACTORY( LArHVPathologyDbAlg ) +DECLARE_ALGORITHM_FACTORY( LArHV2Ntuple ) + +DECLARE_FACTORY_ENTRIES(LArCondUtils) { + DECLARE_TOOL( LArFecLvTempDcsTool ) + DECLARE_TOOL( LArHVToolMC ) + DECLARE_TOOL( LArHVToolDB ) + DECLARE_TOOL( LArFEBTempTool ) + DECLARE_ALGORITHM( LArHVPathologyDbAlg ) + DECLARE_ALGORITHM( LArHV2Ntuple ) +} diff --git a/LArCalorimeter/LArCondUtils/src/components/LArCondUtils_load.cxx b/LArCalorimeter/LArCondUtils/src/components/LArCondUtils_load.cxx new file mode 100755 index 0000000000000000000000000000000000000000..783462151e0bdb9aabdf06064db01fb9b0098b56 --- /dev/null +++ b/LArCalorimeter/LArCondUtils/src/components/LArCondUtils_load.cxx @@ -0,0 +1,3 @@ +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES(LArCondUtils)