ATLAS Offline Software
Loading...
Searching...
No Matches
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
14namespace {
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
24namespace InDet {
25 SiDetectorElementStatusCondAlg::SiDetectorElementStatusCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
26 : ::AthCondAlgorithm(name, pSvcLocator)
27 {
28 }
29
31 {
32 ATH_CHECK( m_condSummaryTool.empty() ? StatusCode::FAILURE : StatusCode::SUCCESS);
33 ATH_CHECK( m_condSummaryTool.retrieve());
34 ATH_CHECK( m_writeKey.initialize());
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.
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
Handle class for recording to StoreGate.
Base class for conditions algorithms.
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
SiDetectorElementStatusCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteCondHandleKey< InDet::SiDetectorElementStatus > m_writeKey
virtual StatusCode execute(const EventContext &ctx) const override final
ToolHandle< IDetectorElementStatusTool > m_condSummaryTool
const std::vector< std::vector< unsigned short > > & getBadCells() const
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Primary Vertex Finder.