ATLAS Offline Software
Loading...
Searching...
No Matches
TRTStrawCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TRTStrawCondAlg.h"
7
8TRTStrawCondAlg::TRTStrawCondAlg(const std::string& name
9 , ISvcLocator* pSvcLocator )
10 : ::AthCondAlgorithm(name, pSvcLocator)
11{
12}
13
15{
16 // Straw status
18
19 // Register write handle
20 ATH_CHECK(m_strawWriteKey.initialize());
21
22 // Initialize readCondHandle key
23 ATH_CHECK(m_trtDetEleContKey.initialize());
24
25 // TRT ID helper
26 ATH_CHECK(detStore()->retrieve(m_trtId,"TRT_ID"));
27
28 return StatusCode::SUCCESS;
29}
30
31StatusCode TRTStrawCondAlg::execute(const EventContext &ctx) const
32{
33 ATH_MSG_DEBUG("execute " << name());
34
35 // ____________ Construct Write Cond Handle and check its validity ____________
36
38
39 // Do we have a valid Write Cond Handle for current time?
40 if(writeHandle.isValid()) {
41 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
42 << ". In theory this should not be called, but may happen"
43 << " if multiple concurrent events are being processed out of order.");
44
45 return StatusCode::SUCCESS;
46 }
47
48 // Read straw status summary
50 if (!strawStatusHandle.isValid()){
51 ATH_MSG_FATAL("No access to conditions " << strawStatusHandle.key());
52 return StatusCode::FAILURE;
53 }
54
55 EventIDRange range;
56 if (!strawStatusHandle.range(range)){
57 ATH_MSG_ERROR("Failed to get validity range of " << strawStatusHandle.key());
58 return StatusCode::FAILURE;
59 }
60
61 ATH_MSG_DEBUG("Retrieved " << strawStatusHandle.key() << " with validity " << range);
62
63 const TRTCond::StrawStatusSummary *statusSummary = {*strawStatusHandle};
64 if (statusSummary == nullptr) {
65 ATH_MSG_ERROR("Null pointer to the straw status summary container");
66 return StatusCode::FAILURE;
67 }
68
69 // ____________ Construct new Write Cond Object ____________
70 std::unique_ptr<TRTCond::AliveStraws> writeCdo{std::make_unique<TRTCond::AliveStraws>()};
71
73 const InDetDD::TRT_DetElementCollection* elements(trtDetEleHandle->getElements());
74 if (not trtDetEleHandle.isValid() or elements==nullptr) {
75 ATH_MSG_FATAL(m_trtDetEleContKey.fullKey() << " is not available.");
76 return StatusCode::FAILURE;
77 }
78
79 // ____________ Compute number of alive straws for Write Cond object ____________
80
81 for (std::vector<Identifier>::const_iterator it = m_trtId->straw_layer_begin(); it != m_trtId->straw_layer_end(); ++it ) {
82
83 // Make sure it is a straw_layer id
84 Identifier strawLayerId = m_trtId->layer_id(*it);
85 //Get hash Id
86 IdentifierHash hashId = m_trtId->straw_layer_hash(strawLayerId);
87
88 unsigned int nstraws = 0;
89 if (trtDetEleHandle.isValid()){
90 const InDetDD::TRT_BaseElement *el = elements->getDetectorElement(hashId);
91 if( !el ) continue;
92 nstraws = el->nStraws();
93 }
94 else{
95 nstraws = m_trtId->straw_max( *it) + 1; // There is a difference of 1 between both methods....
96 }
97 for (unsigned int i=0; i<nstraws ;i++) {
98 Identifier id = m_trtId->straw_id( *it, i);
99 int det = m_trtId->barrel_ec( id) ;
100 int lay = m_trtId->layer_or_wheel( id) ;
101 int phi = m_trtId->phi_module( id) ;
102 bool status = statusSummary->findStatus( m_trtId->straw_hash(id) );
103
104 if ( status ) {
105 ATH_MSG_VERBOSE(" The sector " << det << " " << lay << " " << phi << " has status " << status);
106 continue;
107 }
108
109 int i_total = findArrayTotalIndex(det, lay);
110 int i_wheel = findArrayLocalWheelIndex(det, lay);
111
112 writeCdo->update(i_total,i_wheel,phi);
113
114 }
115 }
116
117 // Record CDO
118 if (writeHandle.record(range, std::move(writeCdo)).isFailure()) {
119 ATH_MSG_ERROR("Could not record AliveStraws " << writeHandle.key()
120 << " with EventRange " << range
121 << " into Conditions Store");
122 return StatusCode::FAILURE;
123 }
124
125 return StatusCode::SUCCESS;
126}
127
128int TRTStrawCondAlg::findArrayTotalIndex(const int det, const int lay) const{
129 int arrayindex = 0; // to be reset below
130 // NOTE: Below, arrayindex starts at 1
131 // because index 0 is filled with TOTAL value.
132 if (det == -1) arrayindex = 1; // barrel side C
133 else if (det == -2) { // endcap side C
134 if (lay < 6) arrayindex = 2; // wheel A
135 else arrayindex = 3; // wheel B
136 }
137 else if (det == 1) arrayindex = 4; // barrel side A
138 else if (det == 2) { // endcap side A
139 if (lay < 6) arrayindex = 5; // wheel A
140 else arrayindex = 6; // wheel B
141 }
142 else ATH_MSG_WARNING(" detector value is: " << det << ", out of range -2, -1, 1, 2, so THIS IS NOT TRT!!!");
143 return arrayindex;
144 }
145
146int TRTStrawCondAlg::findArrayLocalWheelIndex(const int det, const int lay) const{
147 int arrayindex = 9; // to be reset below
148 if (det == -1) { // barrel side C
149 if (lay == 0) arrayindex = 0; // layer 0
150 else if (lay == 1) arrayindex = 1; // layer 1
151 else if (lay == 2) arrayindex = 2; // layer 2
152 }
153 else if (det == -2) { // endcap side C
154 for (int i=0; i<14; ++i){
155 if (lay==i) arrayindex=i+3;
156 }
157 }
158 else if (det == 1) { // barrel side A
159 if (lay == 0) arrayindex = 17; // layer 0
160 else if (lay == 1) arrayindex = 18; // layer 1
161 else if (lay == 2) arrayindex = 19; // layer 2
162 }
163 else if (det == 2) { // endcap side A
164 for (int i=0; i<14; ++i){
165 if (lay==i) arrayindex=i+20;
166 }
167 }
168 else ATH_MSG_WARNING(" detector value is: " << det << ", out of range -2, -1, 1, 2, so THIS IS NOT TRT!!!");
169 return arrayindex;
170 }
171
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
This is a "hash" representation of an Identifier.
Virtual base class of TRT readout elements.
Class to hold collection of TRT detector elements.
const TRT_BaseElement * getDetectorElement(const IdentifierHash &hash) const
bool range(EventIDRange &r)
const std::string & key() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
bool findStatus(const IdentifierHash &hashID) const
const TRT_ID * m_trtId
TRTStrawCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
int findArrayLocalWheelIndex(const int det, const int lay) const
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadCondHandleKey< TRTCond::StrawStatusSummary > m_strawStatusSummaryKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
virtual StatusCode initialize() override
SG::WriteCondHandleKey< TRTCond::AliveStraws > m_strawWriteKey
int findArrayTotalIndex(const int det, const int lay) const