ATLAS Offline Software
SCT_DCSConditionsTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // New SCT_DCSConditions Tool, based on existing tool in SCT_ConditionsAlgs
6 // A. R-Veronneau 26/02/08
7 
12 
13 #include "GaudiKernel/ThreadLocalContext.h"
14 
15 #include "SCT_IdConverter.h"
17 
19 const float SCT_DCSConditionsTool::s_defaultHV{-30.};
21 
22 SCT_DCSConditionsTool::SCT_DCSConditionsTool(const std::string& type, const std::string& name, const IInterface* parent) :
23  base_class(type, name, parent)
24 {
25 }
26 
28  if (detStore()->retrieve(m_pHelper,"SCT_ID").isFailure()) {
29  ATH_MSG_ERROR("SCT helper failed to retrieve ");
30  return StatusCode::FAILURE;
31  }
32 
33  // Read Cond Handle Keys
36 
37  const bool useState = (m_readAllDBFolders and m_returnHVTemp) or (not m_readAllDBFolders and not m_returnHVTemp);
39 
40  return StatusCode::SUCCESS;
41 }
42 
44  return StatusCode::SUCCESS;
45 }
46 
47 //Can report about the module as a whole or the wafer
50 }
51 
52 //returns the module ID (int), or returns -1 if not able to report
54  if (not canReportAbout(h)) return s_invalidId;
55 
56  Identifier moduleId;
57 
59  moduleId = elementId;
60  } else if (h==InDetConditions::SCT_SIDE) {
61  moduleId = m_pHelper->module_id(elementId);
62  } else if (h==InDetConditions::SCT_STRIP) {
63  Identifier waferId = m_pHelper->wafer_id(elementId);
64  moduleId = m_pHelper->module_id(waferId);
65  }
66  return moduleId;
67 }
68 
69 //Returns if element Id is good or bad
70 bool SCT_DCSConditionsTool::isGood(const Identifier& elementId, const EventContext& ctx, InDetConditions::Hierarchy h) const {
71  Identifier moduleId{getModuleID(elementId, h)};
72  if (not moduleId.is_valid()) return true; // not canreportabout
73 
75  const SCT_DCSStatCondData* condDataState{getCondDataState(ctx)};
76  if (condDataState==nullptr) return false; // no cond data
77  else if (condDataState->output(castId(moduleId))==0) return true; //No params are listed as bad
78  else return false;
79  } else {
80  return true;
81  }
82 }
83 
85  const EventContext& ctx{Gaudi::Hive::currentContext()};
86  return isGood(elementId, ctx, h);
87 }
88 
89 //Does the same for hashIds
90 bool SCT_DCSConditionsTool::isGood(const IdentifierHash& hashId, const EventContext& ctx) const {
91  Identifier waferId{m_pHelper->wafer_id(hashId)};
92  Identifier moduleId{m_pHelper->module_id(waferId)};
93  return isGood(moduleId, ctx, InDetConditions::SCT_MODULE);
94 }
95 
100  if (not condDataHandle.isValid()) {
101  ATH_MSG_ERROR("Failed to get " << m_condKeyState.key());
102  return;
103  }
104  if (whandle) {
105  whandle->addDependency (condDataHandle);
106  }
107  const SCT_DCSStatCondData* condDataState{ condDataHandle.cptr() };
108  if (condDataState==nullptr) return;
109  std::vector<bool> &status = element_status.getElementStatus();
110  if (status.empty()) {
111  status.resize(m_pHelper->wafer_hash_max(),true);
112  }
113  std::vector<InDet::ChipFlags_t> &chip_status = element_status.getElementChipStatus();
114  constexpr unsigned int N_CHIPS_PER_SIDE = 6;
115  constexpr unsigned int N_SIDES = 2;
116  constexpr InDet::ChipFlags_t all_flags_set = static_cast<InDet::ChipFlags_t>((1ul<<(N_CHIPS_PER_SIDE*N_SIDES)) - 1ul);
117  if (chip_status.empty()) {
118  chip_status.resize(status.size(), all_flags_set);
119  }
120  for ( const std::pair< const CondAttrListCollection::ChanNum, std::vector<std::string> > & dcs_state : condDataState->badChannelsMap() ) {
121  Identifier moduleId{ Identifier32{dcs_state.first} };
122  //find the corresponding hash
123  for (unsigned int side_i=0; side_i<2; ++side_i) {
124  Identifier waferId(m_pHelper->wafer_id(m_pHelper->barrel_ec (moduleId),
125  m_pHelper->layer_disk(moduleId),
126  m_pHelper->phi_module(moduleId),
127  m_pHelper->eta_module(moduleId),
128  side_i) );
129  const IdentifierHash hashId{m_pHelper->wafer_hash(waferId)};
130  status.at(hashId.value() ) = status.at(hashId.value() ) && dcs_state.second.empty();
131  chip_status.at(hashId.value()) = chip_status.at(hashId.value()) & ( dcs_state.second.empty() ? all_flags_set : 0 );
132  }
133  }
134  }
135 }
136 
138  const EventContext& ctx{Gaudi::Hive::currentContext()};
139  return isGood(hashId, ctx);
140 }
141 
143 
144 // some lame helper methods:
145 // returns HV (s_defaultHV(-30) if there is no information)
146 float SCT_DCSConditionsTool::modHV(const Identifier& elementId, const EventContext& ctx, InDetConditions::Hierarchy h) const {
147  Identifier moduleId{getModuleID(elementId, h)};
148  if (not moduleId.is_valid()) return s_defaultHV; // not canreportabout, return s_defaultHV(-30)
149 
150  const SCT_DCSFloatCondData* condDataHV{getCondDataHV(ctx)};
151  if (condDataHV==nullptr) return s_defaultHV; // no cond data
152 
153  float hvval{s_defaultHV};
154  if (condDataHV->getValue(castId(moduleId), hvval) and isGood(elementId, h)) {
155  return hvval;
156  }
157  return s_defaultHV; //didn't find the module, return s_defaultHV(-30)
158 }
159 
161  const EventContext& ctx{Gaudi::Hive::currentContext()};
162  return modHV(elementId, ctx, h);
163 }
164 
165 //Does the same for hashIds
166 float SCT_DCSConditionsTool::modHV(const IdentifierHash& hashId, const EventContext& ctx) const {
167  Identifier waferId{m_pHelper->wafer_id(hashId)};
168  Identifier moduleId{m_pHelper->module_id(waferId)};
169  return modHV(moduleId, ctx, InDetConditions::SCT_MODULE);
170 }
171 
172 float SCT_DCSConditionsTool::modHV(const IdentifierHash& hashId) const {
173  const EventContext& ctx{Gaudi::Hive::currentContext()};
174  return modHV(hashId, ctx);
175 }
176 
177 //Returns temp0 (s_defaultTemperature(-40) if there is no information)
178 float SCT_DCSConditionsTool::hybridTemperature(const Identifier& elementId, const EventContext& ctx, InDetConditions::Hierarchy h) const {
179  Identifier moduleId{getModuleID(elementId, h)};
180  if (not moduleId.is_valid()) return s_defaultTemperature; // not canreportabout
181 
182  const SCT_DCSFloatCondData* condDataTemp0{getCondDataTemp0(ctx)};
183  if (condDataTemp0==nullptr) return s_defaultTemperature; // no cond data
184 
185  float temperature{s_defaultTemperature};
186  if (condDataTemp0->getValue(castId(moduleId), temperature) and isGood(elementId, h)) {
187  return temperature;
188  }
189  return s_defaultTemperature;//didn't find the module, return -40.
190 }
191 
193  const EventContext& ctx{Gaudi::Hive::currentContext()};
194  return hybridTemperature(elementId, ctx, h);
195 }
196 
197 //Does the same for hashIds
198 float SCT_DCSConditionsTool::hybridTemperature(const IdentifierHash& hashId, const EventContext& ctx) const {
199  Identifier waferId{m_pHelper->wafer_id(hashId)};
200  Identifier moduleId{m_pHelper->module_id(waferId)};
201  return hybridTemperature(moduleId, ctx, InDetConditions::SCT_MODULE);
202 }
203 
205  const EventContext& ctx{Gaudi::Hive::currentContext()};
206  return hybridTemperature(hashId, ctx);
207 }
208 
209 //Returns temp0 + correction for Lorentz angle calculation (s_defaultTemperature(-40) if there is no information)
210 float SCT_DCSConditionsTool::sensorTemperature(const Identifier& elementId, const EventContext& ctx, InDetConditions::Hierarchy h) const {
211  Identifier moduleId{getModuleID(elementId, h)};
212  if (not moduleId.is_valid()) return s_defaultTemperature; // not canreportabout
213 
214  const SCT_DCSFloatCondData* condDataTemp0{getCondDataTemp0(ctx)};
215  if (condDataTemp0==nullptr) return s_defaultTemperature; // no cond data
216 
217  float temperature{s_defaultTemperature};
218  if (condDataTemp0->getValue(castId(moduleId), temperature) and isGood(elementId, h)) {
219  int bec{m_pHelper->barrel_ec(moduleId)};
220  if (bec==0) { // Barrel
221  return ( temperature + m_barrel_correction); //return the temp+correction
222  } else { // Endcaps
223  int modeta{m_pHelper->eta_module(moduleId)};
224  if (modeta==2) {
225  return (temperature + m_ecInner_correction); //return the temp+correction
226  } else {
227  return (temperature + m_ecOuter_correction); //return the temp+correction
228  }
229  }
230  }
231  return s_defaultTemperature; //didn't find the module, return s_defaultTemperature(-40).
232 }
233 
235  const EventContext& ctx{Gaudi::Hive::currentContext()};
236  return sensorTemperature(elementId, ctx, h);
237 }
238 
239 //Does the same for hashIds
240 float SCT_DCSConditionsTool::sensorTemperature(const IdentifierHash& hashId, const EventContext& ctx) const {
241  Identifier waferId{m_pHelper->wafer_id(hashId)};
242  Identifier moduleId{m_pHelper->module_id(waferId)};
243  return sensorTemperature(moduleId, ctx, InDetConditions::SCT_MODULE);
244 }
245 
247  const EventContext& ctx{Gaudi::Hive::currentContext()};
248  return sensorTemperature(hashId, ctx);
249 }
250 
252 
253 const SCT_DCSStatCondData*
254 SCT_DCSConditionsTool::getCondDataState(const EventContext& ctx) const {
256  return condData.retrieve();
257 }
258 
260 SCT_DCSConditionsTool::getCondDataHV(const EventContext& ctx) const {
262  return condData.retrieve();
263 }
264 
266 SCT_DCSConditionsTool::getCondDataTemp0(const EventContext& ctx) const {
268  return condData.retrieve();
269 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCT_DCSConditionsTool::m_condKeyHV
SG::ReadCondHandleKey< SCT_DCSFloatCondData > m_condKeyHV
Definition: SCT_DCSConditionsTool.h:90
Identifier32
Definition: Identifier32.h:25
SCT_DCSFloatCondData
Class for data object used in SCT_DCSConditions{HV,Temp}CondAlg, SCT_DCSConditionsTool,...
Definition: SCT_DCSFloatCondData.h:30
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
InDet::SiDetectorElementStatus::getElementStatus
const std::vector< bool > & getElementStatus() const
Definition: SiDetectorElementStatus.h:116
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SCT_DCSConditionsTool::m_barrel_correction
FloatProperty m_barrel_correction
Definition: SCT_DCSConditionsTool.h:86
SCT_DCSConditionsTool::s_invalidId
static const Identifier s_invalidId
Definition: SCT_DCSConditionsTool.h:93
SCT_DCSConditionsTool::m_condKeyState
SG::ReadCondHandleKey< SCT_DCSStatCondData > m_condKeyState
Definition: SCT_DCSConditionsTool.h:89
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
SCT_ConditionsTools::castId
unsigned int castId(const Identifier &identifier)
Definition: SCT_IdConverter.h:13
SCT_DCSConditionsTool::initialize
virtual StatusCode initialize() override
Definition: SCT_DCSConditionsTool.cxx:27
SCT_DetectorElementStatus.h
SCT_DCSConditionsTool::m_ecOuter_correction
FloatProperty m_ecOuter_correction
Definition: SCT_DCSConditionsTool.h:88
SCT::N_SIDES
constexpr unsigned int N_SIDES
Definition: SCT_ChipUtils.h:16
InDetConditions::Hierarchy
Hierarchy
Definition: InDetHierarchy.h:14
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
SCT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: SCT_ID.h:740
SCT_DCSConditionsTool::m_ecInner_correction
FloatProperty m_ecInner_correction
Definition: SCT_DCSConditionsTool.h:87
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SCT_ID::module_id
Identifier module_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: SCT_ID.h:416
SCT_DCSStatCondData
Classs for data object used in SCT_DCSConditionsStatCondAlg, SCT_DCSConditionsTool,...
Definition: SCT_DCSStatCondData.h:29
SCT_DCSConditionsTool::hybridTemperature
virtual float hybridTemperature(const Identifier &elementId, const EventContext &ctx, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
Definition: SCT_DCSConditionsTool.cxx:178
SCT_IdConverter.h
SCT_DCSConditionsTool::m_readAllDBFolders
BooleanProperty m_readAllDBFolders
Definition: SCT_DCSConditionsTool.h:84
SCT_DCSConditionsTool::finalize
virtual StatusCode finalize() override
Definition: SCT_DCSConditionsTool.cxx:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SCT_DCSConditionsTool::SCT_DCSConditionsTool
SCT_DCSConditionsTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: SCT_DCSConditionsTool.cxx:22
InDetConditions::SCT_MODULE
@ SCT_MODULE
Definition: InDetHierarchy.h:14
InDet::SiDetectorElementStatus
Definition: SiDetectorElementStatus.h:62
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SCT_DCSConditionsTool::modHV
virtual float modHV(const Identifier &elementId, const EventContext &ctx, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
Definition: SCT_DCSConditionsTool.cxx:146
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_DCSConditionsTool::canReportAbout
virtual bool canReportAbout(InDetConditions::Hierarchy h) const override
Return whether this service can report on the hierarchy level (e.g. module, chip.....
Definition: SCT_DCSConditionsTool.cxx:48
SCT_ID::wafer_hash
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition: SCT_ID.h:492
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:46
SCT_DCSConditionsTool::sensorTemperature
virtual float sensorTemperature(const Identifier &elementId, const EventContext &ctx, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
Definition: SCT_DCSConditionsTool.cxx:210
SCT_DCSConditionsTool::m_condKeyTemp0
SG::ReadCondHandleKey< SCT_DCSFloatCondData > m_condKeyTemp0
Definition: SCT_DCSConditionsTool.h:91
SCT_DCSConditionsTool::s_defaultHV
static const float s_defaultHV
Definition: SCT_DCSConditionsTool.h:94
CondAttrListCollection::ChanNum
unsigned int ChanNum
Definition: CondAttrListCollection.h:55
SCT_DCSConditionsTool::m_pHelper
const SCT_ID * m_pHelper
Definition: SCT_DCSConditionsTool.h:92
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
SCT_DCSConditionsTool::getCondDataTemp0
const SCT_DCSFloatCondData * getCondDataTemp0(const EventContext &ctx) const
Definition: SCT_DCSConditionsTool.cxx:266
SCT_DCSConditionsTool::isGood
virtual bool isGood(const Identifier &elementId, const EventContext &ctx, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
Summarise the result from the service as good/bad.
Definition: SCT_DCSConditionsTool.cxx:70
SCT_DCSConditionsTool::getCondDataState
const SCT_DCSStatCondData * getCondDataState(const EventContext &ctx) const
Definition: SCT_DCSConditionsTool.cxx:254
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:645
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SiDetectorElementCollection.h
SCT_DCSConditionsTool.h
Header file for the SCT_DCSConditionsTool class in package SCT_ConditionsTools.
h
SCT_DCSConditionsTool::getCondDataHV
const SCT_DCSFloatCondData * getCondDataHV(const EventContext &ctx) const
Definition: SCT_DCSConditionsTool.cxx:260
InDet::SiDetectorElementStatus::getElementChipStatus
const std::vector< ChipFlags_t > & getElementChipStatus() const
Definition: SiDetectorElementStatus.h:118
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
SCT_DCSConditionsTool::getDetectorElementStatus
virtual void getDetectorElementStatus(const EventContext &ctx, InDet::SiDetectorElementStatus &element_status, SG::WriteCondHandle< InDet::SiDetectorElementStatus > *whandle) const override
Definition: SCT_DCSConditionsTool.cxx:96
InDet::ChipFlags_t
unsigned short ChipFlags_t
Definition: SiDetectorElementStatus.h:60
SCT_DCSConditionsTool::m_returnHVTemp
BooleanProperty m_returnHVTemp
Definition: SCT_DCSConditionsTool.h:85
merge.status
status
Definition: merge.py:17
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
InDetConditions::SCT_STRIP
@ SCT_STRIP
Definition: InDetHierarchy.h:14
InDetConditions::SCT_SIDE
@ SCT_SIDE
Definition: InDetHierarchy.h:14
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
SCT_DCSConditionsTool::getModuleID
virtual Identifier getModuleID(const Identifier &elementId, InDetConditions::Hierarchy h) const
Definition: SCT_DCSConditionsTool.cxx:53
SCT_DCSConditionsTool::s_defaultTemperature
static const float s_defaultTemperature
Definition: SCT_DCSConditionsTool.h:95
SCT::N_CHIPS_PER_SIDE
constexpr unsigned int N_CHIPS_PER_SIDE
Definition: SCT_ChipUtils.h:15
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition: WriteCondHandle.h:275
Identifier
Definition: IdentifierFieldParser.cxx:14