ATLAS Offline Software
TRTStrawCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TRTStrawCondAlg.h"
7 
9  , ISvcLocator* pSvcLocator )
10  : ::AthReentrantAlgorithm(name, pSvcLocator)
11 {
12 }
13 
15 {
16  // Straw status
18 
19  // Register write handle
21 
22  // Initialize readCondHandle key
24 
25  // TRT ID helper
26  ATH_CHECK(detStore()->retrieve(m_trtId,"TRT_ID"));
27 
28  return StatusCode::SUCCESS;
29 }
30 
31 StatusCode 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 
128 int 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 
146 int 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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TRT_ID::layer_id
Identifier layer_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer) const
For an individual straw layer.
Definition: TRT_ID.h:500
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TRTStrawCondAlg::m_trtDetEleContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
Definition: TRTStrawCondAlg.h:33
TRT_ID::straw_max
int straw_max(const Identifier &id) const
Definition: TRT_ID.cxx:996
TRTCond::StrawStatusSummary
Definition: StrawStatusSummary.h:17
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
TRT_ID::straw_hash
IdentifierHash straw_hash(Identifier straw_id) const
straw hash from id - optimized
Definition: TRT_ID.h:768
TRTCalib_Extractor.det
det
Definition: TRTCalib_Extractor.py:36
TRTStrawCondAlg::TRTStrawCondAlg
TRTStrawCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRTStrawCondAlg.cxx:8
skel.it
it
Definition: skel.GENtoEVGEN.py:396
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TRT_ID::straw_layer_end
const_id_iterator straw_layer_end(void) const
Definition: TRT_ID.h:961
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TRTStrawCondAlg::findArrayLocalWheelIndex
int findArrayLocalWheelIndex(const int det, const int lay) const
Definition: TRTStrawCondAlg.cxx:146
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRTStrawCondAlg::m_strawWriteKey
SG::WriteCondHandleKey< TRTCond::AliveStraws > m_strawWriteKey
Definition: TRTStrawCondAlg.h:35
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
TRTStrawCondAlg::m_trtId
const TRT_ID * m_trtId
Definition: TRTStrawCondAlg.h:37
TRTCond::StrawStatusSummary::findStatus
bool findStatus(const IdentifierHash &hashID) const
Definition: StrawStatusSummary.cxx:20
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:884
TRT_BaseElement.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TRT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: TRT_ID.h:875
TRTStrawCondAlg::initialize
virtual StatusCode initialize() override
Definition: TRTStrawCondAlg.cxx:14
TRTStrawCondAlg::m_strawStatusSummaryKey
SG::ReadCondHandleKey< TRTCond::StrawStatusSummary > m_strawStatusSummaryKey
Definition: TRTStrawCondAlg.h:34
TRTStrawCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TRTStrawCondAlg.cxx:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
InDetDD::TRT_DetElementCollection::getDetectorElement
const TRT_BaseElement * getDetectorElement(const IdentifierHash &hash) const
Definition: TRT_DetElementCollection.cxx:11
merge.status
status
Definition: merge.py:17
TRT_ID::straw_layer_begin
const_id_iterator straw_layer_begin(void) const
Iterators over full set of straw_layer ids. Straw_layer ids are sorted.
Definition: TRT_ID.h:953
InDetDD::TRT_DetElementCollection
Class to hold collection of TRT detector elements.
Definition: TRT_DetElementCollection.h:28
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
TRTStrawCondAlg.h
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TRT_ID::straw_layer_hash
IdentifierHash straw_layer_hash(Identifier straw_layer_id) const
straw_layer hash from id - optimized
Definition: TRT_ID.h:750
TRTStrawCondAlg::findArrayTotalIndex
int findArrayTotalIndex(const int det, const int lay) const
Definition: TRTStrawCondAlg.cxx:128
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
TRT_ID::straw_id
Identifier straw_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Three ways of getting id for a single straw:
Definition: TRT_ID.h:581
Identifier
Definition: IdentifierFieldParser.cxx:14