ATLAS Offline Software
PixelConditionsSummaryTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 
12 PixelConditionsSummaryTool::PixelConditionsSummaryTool(const std::string& type, const std::string& name, const IInterface* parent)
14  m_pixelID(nullptr)
15 {
16  m_isActiveStatus.emplace_back("OK");
17  m_isActiveStates.emplace_back("READY");
18 
19  declareProperty("IsActiveStatus", m_isActiveStatus);
20  declareProperty("IsActiveStates", m_isActiveStates);
21 }
22 
24 
26  ATH_MSG_DEBUG("PixelConditionsSummaryTool::initialize()");
27 
30 
31  bool useByteStream = (m_useByteStreamFEI4 || m_useByteStreamFEI3 || m_useByteStreamRD53);
33  ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
36  ATH_CHECK(m_pixelReadout.retrieve());
39  ATH_MSG_FATAL("The event data (PixelDetElStatusEventDataBaseKey) and cond data (PixelDetElStatusCondDataBaseKey) keys cannot be set at the same time.");
40  }
43 
45  for (unsigned int istate=0; istate<m_isActiveStates.size(); istate++) {
46  if (m_isActiveStates[istate]=="READY") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::READY); }
47  else if (m_isActiveStates[istate]=="ON") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::ON); }
48  else if (m_isActiveStates[istate]=="UNKNOWN") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::UNKNOWN); }
49  else if (m_isActiveStates[istate]=="TRANSITION") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::TRANSITION); }
50  else if (m_isActiveStates[istate]=="UNDEFINED") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::UNDEFINED); }
51  else if (m_isActiveStates[istate]=="DISABLED") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::DISABLED); }
52  else if (m_isActiveStates[istate]=="LOCKED_OUT") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::LOCKED_OUT); }
53  else if (m_isActiveStates[istate]=="OFF") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::OFF); }
54  else if (m_isActiveStates[istate]=="NOSTATE") { m_activeState.push_back(PixelDCSStateData::DCSModuleState::NOSTATE); }
55  else {
56  ATH_MSG_ERROR("No matching DCS state " << m_isActiveStates[istate] << " in DCSModuleState");
57  return StatusCode::FAILURE;
58  }
59  if (m_activeState.back()<0 || m_activeState.back()>31) {
60  ATH_MSG_FATAL("Logic error: status id too large. Cannot be represented by a bit");
61  return StatusCode::FAILURE;
62  }
63  m_activeStateMask |= (1u<<m_activeState.back());
64  }
65 
67  for (auto & isActiveStatus : m_isActiveStatus) {
68  if (isActiveStatus=="OK") { m_activeStatus.push_back(PixelDCSStatusData::DCSModuleStatus::OK); }
69  else if (isActiveStatus=="WARNING") { m_activeStatus.push_back(PixelDCSStatusData::DCSModuleStatus::WARNING); }
70  else if (isActiveStatus=="ERROR") { m_activeStatus.push_back(PixelDCSStatusData::DCSModuleStatus::ERROR); }
71  else if (isActiveStatus=="FATAL") { m_activeStatus.push_back(PixelDCSStatusData::DCSModuleStatus::FATAL); }
72  else if (isActiveStatus=="NOSTATUS") { m_activeStatus.push_back(PixelDCSStatusData::DCSModuleStatus::NOSTATUS); }
73  else {
74  ATH_MSG_ERROR("No matching DCS status " << isActiveStatus << " in DCSModuleStatus");
75  return StatusCode::FAILURE;
76  }
77  if (m_activeStatus.back()<0 || m_activeStatus.back()>31) {
78  ATH_MSG_FATAL("Logic error: status id too large. Cannot be represented by a bit");
79  return StatusCode::FAILURE;
80  }
81  m_activeStatusMask |= (1u<<m_activeStatus.back());
82  }
83 
84  return StatusCode::SUCCESS;
85 }
86 
88  bool useByteStream = (m_useByteStreamFEI4 || m_useByteStreamFEI3 || m_useByteStreamRD53);
89  if (!useByteStream || m_BSErrContReadKey.empty() ) {
90  return nullptr;
91  }
93  if (not idcErrCont.isValid()) { return nullptr; }
94  ATH_MSG_VERBOSE("PixelConditionsSummaryTool IDC Container fetched " << m_BSErrContReadKey.key());
95  return idcErrCont.cptr();
96 }
97 
99  IDCCacheEntry* cacheEntry = m_eventCache.get(ctx);
100  if (cacheEntry->needsUpdate(ctx)) {
101  const auto *idcErrContPtr = getContainer(ctx);
102  if (idcErrContPtr==nullptr) { // missing or not, the cache needs to be reset
103  cacheEntry->reset(ctx.evt(), nullptr);
104  }
105  else {
106  cacheEntry->reset(ctx.evt(), idcErrContPtr->cache());
107  }
108  ATH_MSG_VERBOSE("PixelConditionsSummaryTool Cache for the event reset " << cacheEntry->eventId << " with IDC container" << idcErrContPtr);
109  }
110  return cacheEntry;
111 }
112 
114  std::scoped_lock<std::mutex> lock{*m_cacheMutex.get(ctx)};
115  IDCCacheEntry* cacheEntry = getCacheEntry(ctx);
116  return cacheEntry;
117 }
118 
119 uint64_t PixelConditionsSummaryTool::getBSErrorWord(const IdentifierHash& moduleHash, const EventContext& ctx, const IInDetConditionsTool::IDCCacheEntry* cacheEntry) const {
120  return getBSErrorWord(moduleHash, moduleHash, ctx, cacheEntry);
121 }
122 
123 uint64_t PixelConditionsSummaryTool::getBSErrorWord(const IdentifierHash& moduleHash, const int index, const EventContext& ctx, const IInDetConditionsTool::IDCCacheEntry* cacheEntry) const {
124 
125  if (moduleHash>=m_pixelID->wafer_hash_max()) {
126  ATH_MSG_WARNING("invalid moduleHash : " << moduleHash << " exceed maximum hash id: " << m_pixelID->wafer_hash_max());
127  return 0;
128  }
129 
131  const InDetDD::SiDetectorElementCollection* elements(*pixelDetEleHandle);
132  if (not pixelDetEleHandle.isValid() or elements==nullptr) {
133  ATH_MSG_WARNING(m_pixelDetEleCollKey.fullKey() << " is not available.");
134  return 0;
135  }
136  const InDetDD::SiDetectorElement *element = elements->getDetectorElement(moduleHash);
137  const InDetDD::PixelModuleDesign *p_design = static_cast<const InDetDD::PixelModuleDesign*>(&element->design());
138 
142 
143  if (cacheEntry == nullptr){
144  std::scoped_lock<std::mutex> lock{*m_cacheMutex.get(ctx)};
145  cacheEntry=getCacheEntry(ctx);
146  }
147  const auto *idcCachePtr = cacheEntry->IDCCache;
148  if (idcCachePtr==nullptr) {
149  ATH_MSG_ERROR("PixelConditionsSummaryTool No cache! " );
150  return 0;
151  }
152  uint64_t word = (uint64_t)idcCachePtr->retrieve(index);
153  return word<m_missingErrorInfo ? word : 0;
154 }
155 
156 bool PixelConditionsSummaryTool::hasBSError(const IdentifierHash& moduleHash, const EventContext& ctx, const IInDetConditionsTool::IDCCacheEntry* cacheEntry) const {
157  uint64_t word = getBSErrorWord(moduleHash,ctx,cacheEntry);
158  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::TruncatedROB)) { return true; }
159  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MaskedROB)) { return true; }
160  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::Preamble)) { return true; }
161  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::TimeOut)) { return true; }
162  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::LVL1ID)) { return true; }
163  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::BCID)) { return true; }
164  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::Trailer)) { return true; }
165  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCLVL1IDEoECheck)) { return true; }
166  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCBCIDEoECheck)) { return true; }
167  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCLVL1IDCheck)) { return true; }
168  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCEoEOverflow)) { return true; }
169  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCHitOverflow)) { return true; }
170  return false;
171 }
172 
173 bool PixelConditionsSummaryTool::hasBSError(const IdentifierHash& moduleHash, Identifier pixid, const EventContext& ctx, const IInDetConditionsTool::IDCCacheEntry* cacheEntry) const {
174  if (hasBSError(moduleHash, ctx, cacheEntry)) { return true; }
175 
176  int maxHash = m_pixelID->wafer_hash_max();
177  Identifier moduleID = m_pixelID->wafer_id(pixid);
178  int chFE = m_pixelReadout->getFE(pixid, moduleID);
179  if (m_pixelReadout->getModuleType(moduleID)==InDetDD::PixelModuleType::IBL_3D) { chFE=0; }
180 
181  int indexFE = (1+chFE)*maxHash+static_cast<int>(moduleHash); // (FE_channel+1)*2048 + moduleHash
182  uint64_t word = getBSErrorWord(moduleHash,indexFE,ctx,cacheEntry);
183  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::Preamble)) { return true; }
184  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::TimeOut)) { return true; }
185  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::LVL1ID)) { return true; }
186  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::BCID)) { return true; }
187  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::Trailer)) { return true; }
188  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCLVL1IDEoECheck)) { return true; }
189  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCBCIDEoECheck)) { return true; }
190  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCLVL1IDCheck)) { return true; }
191  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCEoEOverflow)) { return true; }
192  if (PixelByteStreamErrors::hasError(word,PixelByteStreamErrors::MCCHitOverflow)) { return true; }
193  return false;
194 }
195 
196 bool PixelConditionsSummaryTool::isActive(const Identifier& /*elementId*/, const InDetConditions::Hierarchy /*h*/, const EventContext& /*ctx*/) const {
197  return true;
198 }
199 
200 bool PixelConditionsSummaryTool::isActive(const IdentifierHash& moduleHash, const EventContext& ctx) const {
201 
202  // The index array is defined in PixelRawDataProviderTool::SizeOfIDCInDetBSErrContainer()
203  // Here, 52736 is a separator beween error flags and isActive flags.
204  bool useByteStream = (m_useByteStreamFEI4 || m_useByteStreamFEI3 || m_useByteStreamRD53);
205  if (useByteStream && getBSErrorWord(moduleHash,moduleHash+52736,ctx)!=1) { return false; }
206 
208  bool isDCSActive = false;
209  for (int istate : m_activeState) {
210  if (istate==dcsstate_data->getModuleStatus(moduleHash)) { isDCSActive=true; }
211  }
212  if (!isDCSActive) { return false; }
213 
214  if (!m_condTDAQKey.empty() && SG::ReadCondHandle<PixelTDAQData>(m_condTDAQKey,ctx)->getModuleStatus(moduleHash)) { return false; }
215 
216  if (SG::ReadCondHandle<PixelDeadMapCondData>(m_condDeadMapKey,ctx)->getModuleStatus(moduleHash)) { return false; }
217 
218  return true;
219 }
220 
221 bool PixelConditionsSummaryTool::isActive(const IdentifierHash& moduleHash, const Identifier& elementId, const EventContext& ctx) const {
222 
223  // The index array is defined in PixelRawDataProviderTool::SizeOfIDCInDetBSErrContainer()
224  // Here, 52736 is a separator beween error flags and isActive flags.
225  bool useByteStream = (m_useByteStreamFEI4 || m_useByteStreamFEI3 || m_useByteStreamRD53);
226  if (useByteStream && getBSErrorWord(moduleHash,moduleHash+52736,ctx)!=1) { return false; }
227 
229  bool isDCSActive = false;
230  for (int istate : m_activeState) {
231  if (istate==dcsstate_data->getModuleStatus(moduleHash)) { isDCSActive=true; }
232  }
233  if (!isDCSActive) { return false; }
234 
235  if (!m_condTDAQKey.empty() && SG::ReadCondHandle<PixelTDAQData>(m_condTDAQKey,ctx)->getModuleStatus(moduleHash)) { return false; }
236 
237  if (SG::ReadCondHandle<PixelDeadMapCondData>(m_condDeadMapKey,ctx)->getModuleStatus(moduleHash)) { return false; }
238 
239  return checkChipStatus(moduleHash, elementId, ctx);
240 }
241 
242 double PixelConditionsSummaryTool::activeFraction(const IdentifierHash & /*moduleHash*/, const Identifier & /*idStart*/, const Identifier & /*idEnd*/, const EventContext& /*ctx*/) const {
243  return 1.0;
244 }
245 
246 bool PixelConditionsSummaryTool::isGood(const Identifier& elementId, const InDetConditions::Hierarchy h, const EventContext& ctx) const {
247  Identifier moduleID = m_pixelID->wafer_id(elementId);
248  IdentifierHash moduleHash = m_pixelID->wafer_hash(moduleID);
249 
250  if (hasBSError(moduleHash, ctx)) { return false; }
251 
253  bool isDCSActive = false;
254  for (int istate : m_activeState) {
255  if (istate==dcsstate_data->getModuleStatus(moduleHash)) { isDCSActive=true; }
256  }
257  if (!isDCSActive) { return false; }
258 
260  bool isDCSGood = false;
261  for (int activeStatus : m_activeStatus) {
262  if (activeStatus==dcsstatus_data->getModuleStatus(moduleHash)) { isDCSGood=true; }
263  }
264  if (!isDCSGood) { return false; }
265 
266  if (!m_condTDAQKey.empty() && SG::ReadCondHandle<PixelTDAQData>(m_condTDAQKey,ctx)->getModuleStatus(moduleHash)) { return false; }
267 
268  if (SG::ReadCondHandle<PixelDeadMapCondData>(m_condDeadMapKey, ctx)->getModuleStatus(moduleHash)) { return false; }
269 
271  if (!checkChipStatus(moduleHash, elementId,ctx)) { return false; }
272  if (hasBSError(moduleHash, elementId, ctx)) { return false; }
273  }
274 
275  return true;
276 }
277 
278 namespace {
279  inline void andStatus(const std::unordered_map<int, int> &status_map, unsigned int status_mask, std::vector<bool> &module_status) {
280  for (const std::pair<const int, int> &elm : status_map ) {
281  // set modules good if the module status passes the mask.
282  module_status.at(elm.first) = module_status.at(elm.first) && (status_mask & (1<<elm.second));
283  }
284  }
285  inline void andNotStatus(const std::unordered_map<int, int> &status_map, std::vector<bool> &module_status) {
286  for (const std::pair<const int, int> &elm : status_map ) {
287  // set modules good if the module status passes the mask.
288  module_status.at(elm.first) = module_status.at(elm.first) && (elm.second==0);
289  }
290  }
291  bool isBSError(uint64_t error, uint64_t max_error, uint64_t mask) {
292  return error<max_error && (error & mask);
293  }
294 }
295 
296 namespace {
299  if (!ret) {
300  throw std::runtime_error("Object is not of expected type InDet::PixelDetectorElementStatus");
301  }
302  return ret;
303  }
304 }
305 std::unique_ptr<InDet::SiDetectorElementStatus>
310  if (whandle) {
311  whandle->addDependency (input_element_status);
312  }
313  return std::make_unique<InDet::PixelDetectorElementStatus>(*castToDerived(input_element_status.cptr()));
314  }
315  else if (!m_pixelDetElStatusEventKey.empty()) {
317  return std::make_unique<InDet::PixelDetectorElementStatus>(*castToDerived(input_element_status.cptr()));
318  }
319  else {
321  if (not pixelDetEleHandle.isValid() ) {
322  std::stringstream msg;
323  msg << m_pixelDetEleCollKey.fullKey() << " is not available.";
324  throw std::runtime_error(msg.str());
325  }
326  if (whandle) {
327  whandle->addDependency (pixelDetEleHandle);
328  }
329  const InDetDD::SiDetectorElementCollection* elements(*pixelDetEleHandle);
330  return std::make_unique<InDet::PixelDetectorElementStatus>(*elements);
331  }
332 }
333 
334 std::unique_ptr<InDet::SiDetectorElementStatus>
337  std::unique_ptr<InDet::SiDetectorElementStatus> element_status( createDetectorElementStatus(ctx, whandle));
338  std::vector<bool> &status=element_status->getElementStatus();
339  status.resize(m_pixelID->wafer_hash_max(),
340  ((1<<0) & m_activeStateMask) // default value of PixelDCSStateData is 0
341  );
342  std::vector<InDet::ChipFlags_t> &chip_status=element_status->getElementChipStatus();
343  chip_status.resize(status.size(),0);
344 
345  // module state
346  {
348  andStatus(dcs_state_handle->moduleStatusMap(), m_activeStateMask, status);
349  if (whandle) {
350  whandle->addDependency (dcs_state_handle);
351  }
352  }
353  const bool active_only = m_activeOnly;
354  if (!active_only) {
356  andStatus(dcs_status_handle->moduleStatusMap(), m_activeStatusMask, status);
357  if (whandle) {
358  whandle->addDependency (dcs_status_handle);
359  }
360  }
361  if (!m_condTDAQKey.empty()) {
363  andNotStatus(tdaq_handle->moduleStatusMap(), status);
364  if (whandle) {
365  whandle->addDependency (tdaq_handle);
366  }
367  }
368  {
370  andNotStatus(dead_map_handle->moduleStatusMap(), status);
371  if (whandle) {
372  whandle->addDependency (dead_map_handle);
373  }
374 
375  const PixelDeadMapCondData *dead_map = dead_map_handle.cptr();
376  unsigned int element_i=0;
377  for (const InDetDD::SiDetectorElement *element : element_status->getDetectorElements()) {
378  if (status[element_i]) {
379  const InDetDD::PixelModuleDesign *p_design = static_cast<const InDetDD::PixelModuleDesign*>(&element->design());
380  InDetDD::PixelReadoutTechnology readout_technology = p_design->getReadoutTechnology();
381  unsigned int number_of_chips = readout_technology == InDetDD::PixelReadoutTechnology::FEI3 ? 2*p_design->numberOfCircuits() : p_design->numberOfCircuits();
382  InDet::ChipFlags_t chip_mask = (1ul<<number_of_chips)-1ul;
383  assert( chip_mask != 0 );
384  std::bitset<16> dead_chip_mask(dead_map->getChipStatus(element_i));
385  chip_status[element_i] = chip_mask & (~static_cast<InDet::ChipFlags_t>(dead_chip_mask.to_ulong()));
386  }
387  ++element_i;
388  }
389  }
390 
391 
392  static_assert( static_cast<unsigned int>(InDetDD::PixelReadoutTechnology::FEI4) < 32u) ;
393  static_assert( static_cast<unsigned int>(InDetDD::PixelReadoutTechnology::FEI3) < 32u) ;
394  static_assert( static_cast<unsigned int>(InDetDD::PixelReadoutTechnology::RD53) < 32u) ;
398  if (readout_technology_mask) {
399  if (whandle) {
400  ATH_MSG_ERROR("PixelConditionsSummaryTool not configured for use with conditions objects");
402  }
403  std::scoped_lock<std::mutex> lock{*m_cacheMutex.get(ctx)};
404  const IDCInDetBSErrContainer_Cache *idcCachePtr = nullptr;
405  idcCachePtr = getCacheEntry(ctx)->IDCCache;
406  if (idcCachePtr==nullptr) {
407  ATH_MSG_ERROR("PixelConditionsSummaryTool No cache! " );
408  }
409  else {
410 
423 
434 
435  // The index array is defined in PixelRawDataProviderTool::SizeOfIDCInDetBSErrContainer()
436  // Here, 52736 is a separator beween error flags and isActive flags.
437  unsigned int element_offset_i = (active_only ? 52736 : 0);
438 
439  unsigned int element_i=0;
440  unsigned int maxHash = m_pixelID->wafer_hash_max();
441  for (const InDetDD::SiDetectorElement *element : element_status->getDetectorElements()) {
442  const InDetDD::PixelModuleDesign *p_design = static_cast<const InDetDD::PixelModuleDesign*>(&element->design());
443  InDetDD::PixelReadoutTechnology readout_technology = p_design->getReadoutTechnology();
444  unsigned int readout_technology_flags = readout_technology_mask & Pixel::makeReadoutTechnologyBit(readout_technology);
445 
446  // set to false if has one of the considered errors and the readout technology is considered.
447  status.at(element_i) = status.at(element_i) && not ( readout_technology_flags
448  && ( !active_only
449  ? isBSError(static_cast<uint64_t>(idcCachePtr->retrieve(element_i)), m_missingErrorInfo, error_mask)
450  : idcCachePtr->retrieve(element_i+element_offset_i)!=1 ));
451 
452  // compute the status for the individual front-ends
453  if (status[element_i]) {
454  unsigned int number_of_chips = readout_technology == InDetDD::PixelReadoutTechnology::FEI3 ? 2*p_design->numberOfCircuits() : p_design->numberOfCircuits();
455  InDet::ChipFlags_t chip_mask = status[element_i] ? (1ul<<number_of_chips)-1ul : 0;
456  assert( chip_mask != 0 );
457  InDet::ChipFlags_t bs_status_flags = active_only ? chip_mask : 0;
458  if (!active_only) {
459  for (unsigned int chip_i =0; chip_i < number_of_chips; ++chip_i) {
460  // get bytestream error for chip
461  unsigned int indexFE = (1+chip_i)*maxHash + element_i; // (FE_channel+1)*2048 + moduleHash
462  InDet::ChipFlags_t chip_flag =not ( readout_technology_flags
463  && (isBSError(static_cast<uint64_t>(idcCachePtr->retrieve(indexFE)), m_missingErrorInfo, chip_error_mask)));
464  bs_status_flags |= (chip_flag << chip_i);
465  }
466  }
467  chip_status[element_i] &= (bs_status_flags & chip_mask);
468  }
469  else {
470  chip_status[element_i] = 0;
471  }
472  ++element_i;
473  }
474  }
475  }
476  return element_status;
477 }
478 
479 bool PixelConditionsSummaryTool::isGood(const IdentifierHash& moduleHash, const EventContext& ctx) const {
480 
481  if (hasBSError(moduleHash, ctx)) { return false; }
482 
484  bool isDCSActive = false;
485  for (int istate : m_activeState) {
486  if (istate==dcsstate_data->getModuleStatus(moduleHash)) { isDCSActive=true; }
487  }
488  if (!isDCSActive) { return false; }
489 
491  bool isDCSGood = false;
492  for (int activeStatus : m_activeStatus) {
493  if (activeStatus==dcsstatus_data->getModuleStatus(moduleHash)) { isDCSGood=true; }
494  }
495  if (!isDCSGood) { return false; }
496 
497  if (!m_condTDAQKey.empty() && SG::ReadCondHandle<PixelTDAQData>(m_condTDAQKey,ctx)->getModuleStatus(moduleHash)) { return false; }
498 
499  if (SG::ReadCondHandle<PixelDeadMapCondData>(m_condDeadMapKey, ctx)->getModuleStatus(moduleHash)) { return false; }
500 
501  return true;
502 }
503 
504 bool PixelConditionsSummaryTool::isGood(const IdentifierHash & moduleHash, const Identifier &elementId, const EventContext& ctx, const IInDetConditionsTool::IDCCacheEntry* cacheEntry) const {
505 
506  if (hasBSError(moduleHash, ctx, cacheEntry)) { return false; }
507 
509  bool isDCSActive = false;
510  for (int istate : m_activeState) {
511  if (istate==dcsstate_data->getModuleStatus(moduleHash)) { isDCSActive=true; }
512  }
513  if (!isDCSActive) { return false; }
514 
516  bool isDCSGood = false;
517  for (int activeStatus : m_activeStatus) {
518  if (activeStatus==dcsstatus_data->getModuleStatus(moduleHash)) { isDCSGood=true; }
519  }
520  if (!isDCSGood) { return false; }
521 
522  if (!m_condTDAQKey.empty() && SG::ReadCondHandle<PixelTDAQData>(m_condTDAQKey,ctx)->getModuleStatus(moduleHash)) { return false; }
523 
524  if (SG::ReadCondHandle<PixelDeadMapCondData>(m_condDeadMapKey, ctx)->getModuleStatus(moduleHash)) { return false; }
525 
526  if (!checkChipStatus(moduleHash, elementId, ctx)) { return false; }
527 
528  if (hasBSError(moduleHash, elementId, ctx, cacheEntry)) { return false; }
529 
530  return true;
531 }
532 
533 double PixelConditionsSummaryTool::goodFraction(const IdentifierHash & moduleHash, const Identifier & idStart, const Identifier & idEnd, const EventContext& ctx) const {
534 
535  if (!isGood(moduleHash, ctx)) { return 0.0; }
536 
537  Identifier moduleID = m_pixelID->wafer_id(moduleHash);
538 
539  int phiStart = m_pixelID->phi_index(idStart);
540  int etaStart = m_pixelID->eta_index(idStart);
541 
542  int phiEnd = m_pixelID->phi_index(idEnd);
543  int etaEnd = m_pixelID->eta_index(idEnd);
544 
545  double nTotal = (std::abs(phiStart-phiEnd)+1.0)*(std::abs(etaStart-etaEnd)+1.0);
546 
547  double nGood = 0.0;
549  for (int i=std::min(phiStart,phiEnd); i<=std::max(phiStart,phiEnd); i++) {
550  for (int j=std::min(etaStart,etaEnd); j<=std::max(etaStart,etaEnd); j++) {
551  if (checkChipStatus(moduleHash, m_pixelID->pixel_id(moduleID,i,j), ctx)) {
552  if (!hasBSError(moduleHash, m_pixelID->pixel_id(moduleID,i,j), ctx, cacheEntry)) { nGood++; }
553  }
554  }
555  }
556  return nGood/nTotal;
557 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixelFEUtils.h
python.StoreID.UNKNOWN
int UNKNOWN
Definition: StoreID.py:16
PixelDCSStatusData::moduleStatusMap
const IntConditions & moduleStatusMap() const
Definition: PixelDCSStatusData.h:25
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
PixelID::phi_index
int phi_index(const Identifier &id) const
Definition: PixelID.h:658
InDetDD::PixelReadoutTechnology
PixelReadoutTechnology
Definition: PixelReadoutDefinitions.h:34
InDet::SiDetectorElementStatus::getElementStatus
const std::vector< bool > & getElementStatus() const
Definition: SiDetectorElementStatus.h:116
max
#define max(a, b)
Definition: cfImp.cxx:41
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
InDetDD::PixelModuleDesign
Definition: PixelModuleDesign.h:48
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
PixelConditionsSummaryTool::checkChipStatus
bool checkChipStatus(IdentifierHash moduleHash, Identifier pixid, const EventContext &ctx) const
Definition: PixelConditionsSummaryTool.h:175
PixelConditionsSummaryTool::m_activeStatusMask
unsigned int m_activeStatusMask
mask in which each status is represented by a bit and for status values which are cnsidered active th...
Definition: PixelConditionsSummaryTool.h:89
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PixelConditionsSummaryTool::hasBSError
virtual bool hasBSError(const IdentifierHash &moduleHash, const EventContext &ctx, const IDCCacheEntry *cacheEntry=nullptr) const override final
Definition: PixelConditionsSummaryTool.cxx:156
IDCInDetBSErrContainer
IDC like storage for BS errors, TODO, customise implementation further so that we store int rather th...
Definition: IDCInDetBSErrContainer.h:19
IInDetConditionsTool::IDCCacheEntry::needsUpdate
bool needsUpdate(const EventContext &ctx) const
Definition: IInDetConditionsTool.h:42
PixelConditionsSummaryTool::getCacheEntry
IDCCacheEntry * getCacheEntry(const EventContext &ctx) const
Return cache for the current event If, for current slot, the cache is outdated it is retrieved from t...
Definition: PixelConditionsSummaryTool.cxx:98
python.Constants.ERROR
int ERROR
Definition: Control/AthenaCommon/python/Constants.py:18
Pixel::makeReadoutTechnologyBit
unsigned int makeReadoutTechnologyBit(InDetDD::PixelReadoutTechnology technology, unsigned int bit_val=1)
Create a word with a bit representing the given readout technology to the given value.
Definition: PixelFEUtils.h:60
PixelConditionsSummaryTool::m_isActiveStates
std::vector< std::string > m_isActiveStates
Definition: PixelConditionsSummaryTool.h:85
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
PixelConditionsSummaryTool::~PixelConditionsSummaryTool
virtual ~PixelConditionsSummaryTool()
InDetConditions::PIXEL_CHIP
@ PIXEL_CHIP
Definition: InDetHierarchy.h:15
PixelByteStreamErrors::MCCBCIDEoECheck
@ MCCBCIDEoECheck
Definition: PixelByteStreamErrors.h:15
InDetDD::PixelReadoutTechnology::FEI3
@ FEI3
PixelConditionsSummaryTool::getCacheEntryOut
virtual IDCCacheEntry * getCacheEntryOut(const EventContext &ctx) const override final
Definition: PixelConditionsSummaryTool.cxx:113
IInDetConditionsTool::IDCCacheEntry::reset
void reset(EventContext::ContextEvt_t evtId, const IDCInDetBSErrContainer_Cache *cache)
Definition: IInDetConditionsTool.h:37
InDetConditions::Hierarchy
Hierarchy
Definition: InDetHierarchy.h:14
PixelConditionsSummaryTool::isGood
virtual bool isGood(const Identifier &elementId, const InDetConditions::Hierarchy h, const EventContext &ctx) const override final
Definition: PixelConditionsSummaryTool.cxx:246
PixelByteStreamErrors::makeError
constexpr IDCInDetBSErrContainer::ErrorCode makeError(PixelErrorsEnum errType)
helper to be used in clients to fetch error information
Definition: PixelByteStreamErrors.h:21
PixelConditionsSummaryTool::getBSErrorWord
virtual uint64_t getBSErrorWord(const IdentifierHash &moduleHash, const EventContext &ctx, const IDCCacheEntry *cacheEntry=nullptr) const override final
Definition: PixelConditionsSummaryTool.cxx:119
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
PixelConditionsSummaryTool::m_condDCSStateKey
SG::ReadCondHandleKey< PixelDCSStateData > m_condDCSStateKey
Definition: PixelConditionsSummaryTool.h:101
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:364
PixelByteStreamErrors::TimeOut
@ TimeOut
Definition: PixelByteStreamErrors.h:13
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
IdentifiableValueCache::retrieve
T retrieve(size_t i)
Retrieve the Value stored in that hash.
Definition: IdentifiableValueCache.h:49
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
PixelConditionsSummaryTool.h
PixelConditionsSummaryTool::m_condDCSStatusKey
SG::ReadCondHandleKey< PixelDCSStatusData > m_condDCSStatusKey
Definition: PixelConditionsSummaryTool.h:104
InDetDD::PixelReadoutTechnology::RD53
@ RD53
PixelByteStreamErrors::BCID
@ BCID
Definition: PixelByteStreamErrors.h:13
PixelDetectorElementStatus.h
PixelConditionsSummaryTool::isActive
virtual bool isActive(const Identifier &elementId, const InDetConditions::Hierarchy h, const EventContext &ctx) const override final
Definition: PixelConditionsSummaryTool.cxx:196
InDet::PixelDetectorElementStatus
Event data to hold the status information for Pixel modules.
Definition: PixelDetectorElementStatus.h:14
IInDetConditionsTool::IDCCacheEntry::eventId
EventContext::ContextEvt_t eventId
Definition: IInDetConditionsTool.h:34
PixelConditionsSummaryTool::m_pixelDetElStatusEventKey
SG::ReadHandleKey< InDet::SiDetectorElementStatus > m_pixelDetElStatusEventKey
Definition: PixelConditionsSummaryTool.h:122
PixelID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: PixelID.h:387
PixelConditionsSummaryTool::m_BSErrContReadKey
SG::ReadHandleKey< IDCInDetBSErrContainer > m_BSErrContReadKey
Definition: PixelConditionsSummaryTool.h:116
PixelConditionsSummaryTool::m_activeStateMask
unsigned int m_activeStateMask
mask in which each state is represented by a bit and for states which are cnsidered active the corres...
Definition: PixelConditionsSummaryTool.h:88
PixelConditionsSummaryTool::m_useByteStreamFEI4
Gaudi::Property< bool > m_useByteStreamFEI4
Definition: PixelConditionsSummaryTool.h:92
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
UNDEFINED
@ UNDEFINED
Definition: sTGCenumeration.h:18
lumiFormat.i
int i
Definition: lumiFormat.py:85
PixelConditionsSummaryTool::initialize
virtual StatusCode initialize() override
Definition: PixelConditionsSummaryTool.cxx:25
InDet::SiDetectorElementStatus
Definition: SiDetectorElementStatus.h:62
PixelByteStreamErrors::Preamble
@ Preamble
Definition: PixelByteStreamErrors.h:13
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IDetectorElementStatusTool::getInvalidRange
static EventIDRange getInvalidRange()
Definition: IDetectorElementStatusTool.h:33
InDetDD::PixelModuleDesign::numberOfCircuits
int numberOfCircuits() const
Total number of circuits:
Definition: PixelModuleDesign.h:297
PixelConditionsSummaryTool::PixelConditionsSummaryTool
PixelConditionsSummaryTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: PixelConditionsSummaryTool.cxx:12
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
PixelByteStreamErrors::MCCLVL1IDEoECheck
@ MCCLVL1IDEoECheck
Definition: PixelByteStreamErrors.h:15
PixelTDAQData::moduleStatusMap
const IntConditions & moduleStatusMap() const
Definition: PixelTDAQData.h:25
test_pyathena.parent
parent
Definition: test_pyathena.py:15
PixelID::eta_index
int eta_index(const Identifier &id) const
Definition: PixelID.h:664
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PixelDeadMapCondData::getChipStatus
int getChipStatus(const int chanNum) const
Definition: PixelDeadMapCondData.cxx:31
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:45
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
PixelConditionsSummaryTool::m_pixelID
const PixelID * m_pixelID
Definition: PixelConditionsSummaryTool.h:82
python.Constants.WARNING
int WARNING
Definition: Control/AthenaCommon/python/Constants.py:17
python.compareNtuple.nGood
nGood
Definition: compareNtuple.py:55
PixelByteStreamErrors::MaskedROB
@ MaskedROB
Definition: PixelByteStreamErrors.h:14
PixelConditionsSummaryTool::m_activeState
std::vector< int > m_activeState
Definition: PixelConditionsSummaryTool.h:86
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
min
#define min(a, b)
Definition: cfImp.cxx:40
PixelConditionsSummaryTool::m_pixelReadout
ServiceHandle< InDetDD::IPixelReadoutManager > m_pixelReadout
Definition: PixelConditionsSummaryTool.h:113
PixelByteStreamErrors::MCCHitOverflow
@ MCCHitOverflow
Definition: PixelByteStreamErrors.h:15
PixelByteStreamErrors::MCCLVL1IDCheck
@ MCCLVL1IDCheck
Definition: PixelByteStreamErrors.h:15
PixelConditionsSummaryTool::m_condTDAQKey
SG::ReadCondHandleKey< PixelTDAQData > m_condTDAQKey
Definition: PixelConditionsSummaryTool.h:107
PixelConditionsSummaryTool::activeFraction
virtual double activeFraction(const IdentifierHash &moduleHash, const Identifier &idStart, const Identifier &idEnd, const EventContext &ctx) const override final
Definition: PixelConditionsSummaryTool.cxx:242
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
PixelByteStreamErrors::MCCEoEOverflow
@ MCCEoEOverflow
Definition: PixelByteStreamErrors.h:15
PixelDCSStateData::getModuleStatus
int getModuleStatus(const int chanNum) const
Definition: PixelDCSStateData.cxx:11
PixelConditionsSummaryTool::m_pixelDetElStatusCondKey
SG::ReadCondHandleKey< InDet::SiDetectorElementStatus > m_pixelDetElStatusCondKey
Definition: PixelConditionsSummaryTool.h:124
PixelDCSStateData::moduleStatusMap
const IntConditions & moduleStatusMap() const
Definition: PixelDCSStateData.h:28
InDet::SiDetectorElementStatus::getDetectorElements
const std::vector< InDetDD::SiDetectorElement * > & getDetectorElements() const
Definition: SiDetectorElementStatus.h:94
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:907
InDetDD::PixelReadoutTechnology::FEI4
@ FEI4
InDetDD::PixelModuleDesign::getReadoutTechnology
PixelReadoutTechnology getReadoutTechnology() const
Definition: PixelModuleDesign.h:368
SiDetectorElement.h
PixelConditionsSummaryTool::goodFraction
virtual double goodFraction(const IdentifierHash &moduleHash, const Identifier &idStart, const Identifier &idEnd, const EventContext &ctx) const override final
Definition: PixelConditionsSummaryTool.cxx:533
PixelDCSStatusData::getModuleStatus
int getModuleStatus(const int chanNum) const
Definition: PixelDCSStatusData.cxx:11
h
PixelConditionsSummaryTool::getContainer
const IDCInDetBSErrContainer * getContainer(const EventContext &ctx) const
Obtains container form the SG, if it is missing it will complain (hard-coded 3 times per job) and ret...
Definition: PixelConditionsSummaryTool.cxx:87
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PixelModuleDesign.h
InDet::SiDetectorElementStatus::getElementChipStatus
const std::vector< ChipFlags_t > & getElementChipStatus() const
Definition: SiDetectorElementStatus.h:118
PixelConditionsSummaryTool::getDetectorElementStatus
virtual std::unique_ptr< InDet::SiDetectorElementStatus > getDetectorElementStatus(const EventContext &ctx, SG::WriteCondHandle< InDet::SiDetectorElementStatus > *whandle) const override
get the module and chip status of Si detector elements
Definition: PixelConditionsSummaryTool.cxx:335
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
PixelID::pixel_id
Identifier pixel_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int phi_index, int eta_index) const
For an individual pixel.
Definition: PixelID.h:432
PixelConditionsSummaryTool::m_condDeadMapKey
SG::ReadCondHandleKey< PixelDeadMapCondData > m_condDeadMapKey
Definition: PixelConditionsSummaryTool.h:110
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
PixelConditionsSummaryTool::createDetectorElementStatus
std::unique_ptr< InDet::SiDetectorElementStatus > createDetectorElementStatus(const EventContext &ctx, SG::WriteCondHandle< InDet::SiDetectorElementStatus > *whandle) const
Create a new detector element status element container.
Definition: PixelConditionsSummaryTool.cxx:306
PixelConditionsSummaryTool::m_useByteStreamFEI3
Gaudi::Property< bool > m_useByteStreamFEI3
Definition: PixelConditionsSummaryTool.h:95
InDet::ChipFlags_t
unsigned short ChipFlags_t
Definition: SiDetectorElementStatus.h:60
PixelDeadMapCondData
Definition: PixelDeadMapCondData.h:11
merge.status
status
Definition: merge.py:17
PixelByteStreamErrors.h
PixelConditionsSummaryTool::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: PixelConditionsSummaryTool.h:119
PixelConditionsSummaryTool::m_useByteStreamRD53
Gaudi::Property< bool > m_useByteStreamRD53
Definition: PixelConditionsSummaryTool.h:98
PixelConditionsSummaryTool::m_missingErrorInfo
const uint64_t m_missingErrorInfo
Definition: PixelConditionsSummaryTool.h:129
AthAlgTool
Definition: AthAlgTool.h:26
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
InDetDD::SiDetectorElement::design
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
PixelConditionsSummaryTool::m_activeOnly
Gaudi::Property< bool > m_activeOnly
Definition: PixelConditionsSummaryTool.h:127
error
Definition: IImpactPoint3dEstimator.h:70
InDetDD::PixelModuleType::IBL_3D
@ IBL_3D
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
IdentifiableValueCache
This class is to provide an event wide MT container for concurrent storing of basic types,...
Definition: IdentifiableValueCache.h:19
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:15
PixelByteStreamErrors::TruncatedROB
@ TruncatedROB
Definition: PixelByteStreamErrors.h:14
PixelByteStreamErrors::Trailer
@ Trailer
Definition: PixelByteStreamErrors.h:13
IInDetConditionsTool::IDCCacheEntry::IDCCache
const IDCInDetBSErrContainer_Cache * IDCCache
Definition: IInDetConditionsTool.h:35
PixelConditionsSummaryTool::m_activeStatus
std::vector< int > m_activeStatus
Definition: PixelConditionsSummaryTool.h:87
IInDetConditionsTool::IDCCacheEntry
Definition: IInDetConditionsTool.h:33
PixelConditionsSummaryTool::m_isActiveStatus
std::vector< std::string > m_isActiveStatus
Definition: PixelConditionsSummaryTool.h:84
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition: WriteCondHandle.h:275
PixelDeadMapCondData::moduleStatusMap
const IntConditions & moduleStatusMap() const
Definition: PixelDeadMapCondData.h:19
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:67
PixelByteStreamErrors::LVL1ID
@ LVL1ID
Definition: PixelByteStreamErrors.h:13
Identifier
Definition: IdentifierFieldParser.cxx:14