ATLAS Offline Software
SiDetectorElementStatusCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
11 
12 #include <map>
13 
14 namespace {
15  unsigned int computeSize(const std::vector<std::vector<unsigned short> > &vec2d) {
16  unsigned int total_size = sizeof(vec2d);
17  for (const std::vector<unsigned short> &vec : vec2d) {
18  total_size += sizeof(vec) + vec.size()*sizeof(unsigned short);
19  }
20  return total_size;
21  }
22 }
23 
24 namespace InDet {
25  SiDetectorElementStatusCondAlg::SiDetectorElementStatusCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
26  : ::AthReentrantAlgorithm(name, pSvcLocator)
27  {
28  }
29 
31  {
32  ATH_CHECK( m_condSummaryTool.empty() ? StatusCode::FAILURE : StatusCode::SUCCESS);
33  ATH_CHECK( m_condSummaryTool.retrieve());
35  return StatusCode::SUCCESS;
36  }
37 
38  StatusCode SiDetectorElementStatusCondAlg::execute(const EventContext& ctx) const
39  {
41  if (writeHandle.isValid()) {
42  return StatusCode::SUCCESS;
43  }
44 
45  // Start with infinite range and let the tool narrow it down.
46  writeHandle.addDependency (IOVInfiniteRange::infiniteMixed());
47 
48  auto detector_element_status= m_condSummaryTool->getDetectorElementStatus(ctx, &writeHandle);
49  const EventIDRange& range = writeHandle.getRange();
50  if (!range.start().isValid() || !range.stop().isValid()) {
51  ATH_MSG_FATAL("Invalid range for " << writeHandle.key() << " : " << range.start() << ".." << range.stop());
52  }
53  unsigned int total_size = computeSize( static_cast<const InDet::SiDetectorElementStatus *>(detector_element_status.get())->getBadCells() );
54  {
55  unsigned int expected;
56  do {
57  expected = m_maxSize;
58  } while (total_size > expected && !m_maxSize.compare_exchange_weak(expected, total_size,std::memory_order_release,std::memory_order_relaxed));
59  }
60  if (writeHandle.record( std::move(detector_element_status) ).isFailure()) {
61  ATH_MSG_FATAL("Could not record " << writeHandle.key() );
62  }
63  ATH_MSG_DEBUG( "SiDetectorElementStatus Recorded " << writeHandle.key() << " with Range : " << range );
64  return StatusCode::SUCCESS;
65  }
66 
68  {
69  ATH_MSG_DEBUG("Max badCell size " << m_maxSize);
70  return StatusCode::SUCCESS;
71  }
72 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
xAOD::short
short
Definition: Vertex_v1.cxx:165
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
SiDetectorElementStatusCondAlg.h
InDet::SiDetectorElementStatusCondAlg::m_maxSize
std::atomic< unsigned int > m_maxSize
Definition: SiDetectorElementStatusCondAlg.h:35
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
InDet::SiDetectorElementStatusCondAlg::SiDetectorElementStatusCondAlg
SiDetectorElementStatusCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SiDetectorElementStatusCondAlg.cxx:25
InDet::SiDetectorElementStatus::getBadCells
const std::vector< std::vector< unsigned short > > & getBadCells() const
Definition: SiDetectorElementStatus.h:120
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
WriteHandle.h
Handle class for recording to StoreGate.
InDet::SiDetectorElementStatusCondAlg::m_condSummaryTool
ToolHandle< IDetectorElementStatusTool > m_condSummaryTool
Definition: SiDetectorElementStatusCondAlg.h:32
InDet::SiDetectorElementStatus
Definition: SiDetectorElementStatus.h:62
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
InDet::SiDetectorElementStatusCondAlg::m_writeKey
SG::WriteCondHandleKey< InDet::SiDetectorElementStatus > m_writeKey
Definition: SiDetectorElementStatusCondAlg.h:34
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDet::SiDetectorElementStatusCondAlg::initialize
virtual StatusCode initialize() override final
Definition: SiDetectorElementStatusCondAlg.cxx:30
InDet::SiDetectorElementStatusCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: SiDetectorElementStatusCondAlg.cxx:38
IOVInfiniteRange.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SiDetectorElementCollection.h
SiDetectorElement.h
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
InDet::SiDetectorElementStatusCondAlg::finalize
virtual StatusCode finalize() override final
Definition: SiDetectorElementStatusCondAlg.cxx:67