ATLAS Offline Software
Loading...
Searching...
No Matches
SiRegSelCondAlg.cxx
Go to the documentation of this file.
1
13
14
15#include "GaudiKernel/EventIDRange.h"
17
18
21
24
25#include "SiRegSelCondAlg.h"
26
29#include <cmath>
30
31
32SiRegSelCondAlg::SiRegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
33 AthCondAlgorithm( name, pSvcLocator ),
34 m_managerName(""),
35 m_printTable(false)
36{
37 ATH_MSG_DEBUG( "SiRegSelCondAlg::SiRegSelCondAlg() " << name );
38 declareProperty( "PrintTable", m_printTable=false );
39 declareProperty( "ManagerName", m_managerName );
40}
41
42
43
44
46{
47 ATH_MSG_DEBUG("SiRegSelCondAlg::initialize() ");
48 ATH_CHECK(m_pixCablingKey.initialize(!m_pixCablingKey.empty()));
49 ATH_CHECK(m_sctCablingKey.initialize(!m_sctCablingKey.empty()));
50 m_useCabling = !m_pixCablingKey.empty() || !m_sctCablingKey.empty();
51 ATH_CHECK(m_detEleCollKey.initialize());
52 ATH_CHECK(m_tableKey.initialize());
53 ATH_MSG_INFO("SiRegSelCondAlg::initialize() " << m_tableKey );
54 return StatusCode::SUCCESS;
55}
56
57
58
59
60StatusCode SiRegSelCondAlg::execute(const EventContext& ctx) const
61{
62 ATH_MSG_DEBUG("SiRegSelCondAlg::execute() -- enter -- ");
63
65 ATH_MSG_DEBUG( "Creating region selector table " << m_tableKey );
66
68 // Do we have a valid Write Cond Handle for current time?
69 if (lutCondData.isValid()) {
75 ATH_MSG_DEBUG("CondHandle " << lutCondData.fullKey() << " is already valid." );
76 return StatusCode::SUCCESS;
77 }
78
81
82 std::unique_ptr<SG::ReadCondHandle<PixelCablingCondData> > pixCabling;
83 std::unique_ptr<SG::ReadCondHandle<SCT_CablingData> > sctCabling;
84
85 EventIDRange id_range;
86
87 ATH_MSG_DEBUG( "RegSelCondAlg:" << name() );
88
89 if(m_useCabling){
90
91 if (m_managerName=="SCT") { // SCT
92 sctCabling = std::make_unique<SG::ReadCondHandle<SCT_CablingData> >( m_sctCablingKey, ctx );
93 if( !sctCabling->range( id_range ) ) {
94 ATH_MSG_ERROR("Failed to retrieve validity range for " << sctCabling->key());
95 return StatusCode::FAILURE;
96 }
97 }
98 else if(m_managerName=="Pixel"){ // PIXEL
99
100 ATH_MSG_DEBUG( "RegSelCondAlg: " << name() << "\t" << m_pixCablingKey );
101 ATH_MSG_DEBUG( "RegSelCondAlg: " << ctx );
102 ATH_MSG_DEBUG( "RegSelCondAlg: " << id_range << "( initial range )" );
103
104 pixCabling = std::make_unique<SG::ReadCondHandle<PixelCablingCondData> >( m_pixCablingKey, ctx );
105 if( !pixCabling->range( id_range ) ) {
106 ATH_MSG_ERROR("Failed to retrieve validity range for " << pixCabling->key() << " : " << id_range );
107 return StatusCode::FAILURE;
108 }
109 ATH_MSG_DEBUG( "RegSelCondAlg: " << id_range << "( final range )" );
110 }
111
112 }
113
114 ATH_MSG_DEBUG( "RegSelCondAlg:" << name() << " done" );
115
116
117 std::unique_ptr<RegSelSiLUT> rd;
118
119 const bool isPixelLikeManager = (m_managerName == "Pixel" || m_managerName == "PLR");
120 if (isPixelLikeManager) {
121 rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::PIXEL);
122 } else {
123 rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::SCT);
124 }
125
126 // Get detector elements (=alignment) in condition store
127 const InDetDD::SiDetectorElementCollection* elements = nullptr;
129 if (detEle.isValid()) {
130 elements = detEle.retrieve();
131 }
132 if (elements==nullptr) {
133 ATH_MSG_ERROR("Failed to retrieve InDetDD::SiDetectorElementCollection for " << m_managerName);
134 return StatusCode::FAILURE;
135 }
136 // Since this condition algorithm for HLT, we want to run this only at the first event of a run.
137 // We do not take the intersect of ranges of cabling and detector elements.
138 // We use the range of cabling.
139
140 if(!m_useCabling){
141 if( !detEle.range( id_range ) ) {
142 ATH_MSG_ERROR("Failed to retrieve validity range for " << detEle.key() << " : " << id_range );
143 return StatusCode::FAILURE;
144 }
145 ATH_MSG_DEBUG( "RegSelCondAlg: " << id_range << "( final range )" );
146 }
147
148 for (const InDetDD::SiDetectorElement* element : *elements) {
149
150 if (element) {
151
152 IdentifierHash hashId = element->identifyHash();
153
154 ATH_MSG_VERBOSE( "Found element with HashId = " << hashId );
155
156 // new region selector detector element extent
157
158 double rMin, rMax, zMin, zMax, phiMin, phiMax;
159
160 rMin = element->rMin();
161 rMax = element->rMax();
162 zMin = element->zMin();
163 zMax = element->zMax();
164 phiMin = element->phiMin();
165 phiMax = element->phiMax();
166
167
168 int barrelEC = 0;
169 int layerDisk = 0;
170 uint32_t robId = 0;
171
172 // PLR uses its own detector type flag, but its offline helper inherits
173 // from PixelID and should follow the pixel-like RegionSelector path.
174 if (element->isPixel() || element->isPLR() || m_managerName == "PLR") {
175
176 const PixelID* pixelId = dynamic_cast<const PixelID*>(element->getIdHelper());
177 if ( pixelId!=nullptr ) {
178 barrelEC = pixelId->barrel_ec(element->identify());
179 // DBM is pixel-only. PLR is pixel-like for RegionSelector purposes,
180 // but it must not be filtered out by the DBM-specific barrel_ec cut.
181 if ( m_managerName != "PLR" && std::fabs(barrelEC)>3 ) continue;
182 layerDisk = pixelId->layer_disk(element->identify());
183 if(m_useCabling && pixCabling) robId=(*pixCabling)->find_entry_offrob(element->identify());
184 else robId = 0;
185 }
186 else {
187 ATH_MSG_ERROR("Could not get PIXEL_ID for " << element->getIdHelper() );
188 }
189
190 } else { // it's an SCT element
191
192 const SCT_ID* sctId = dynamic_cast<const SCT_ID*>(element->getIdHelper());
193 if ( sctId!=nullptr ) {
194 barrelEC = sctId->barrel_ec(element->identify());
195 layerDisk = sctId->layer_disk(element->identify());
196 // Avoid use of SCT_CablingTool. Instead of
197 // robId=m_sctCablingTool->getRobIdFromOfflineId(element->identify());
198 if(m_useCabling && sctCabling) robId = ((*sctCabling)->getOnlineIdFromHash(element->identifyHash())).rod();
199 else robId = 0;
200 }
201 else {
202 ATH_MSG_ERROR("Could not get SCT_ID for " << element->getIdHelper() );
203 }
204
205 }
206
207
208 // create module for lookup table
209
210 RegSelModule smod( zMin, zMax, rMin, rMax, phiMin, phiMax, layerDisk, barrelEC, robId, hashId );
211
212 rd->addModule( smod );
213
214 ATH_MSG_DEBUG( smod );
215
216 ATH_MSG_VERBOSE( "\t robId = " << robId
217 << " barrelEC = " << barrelEC
218 << ", layerDisk = " << layerDisk
219 << ", phiMin, phiMax = " << phiMin/CLHEP::degree << " " << phiMax/CLHEP::degree
220 << ", rMin = " << rMin/CLHEP::mm << " mm, rMax = " << rMax/CLHEP::mm << " mm" );
221
222 }
223 }
224
225
226 ATH_MSG_DEBUG( " initialising new map " );
227
228 rd->initialise();
229
230 // write out new new LUT to a file if need be
231 if ( m_printTable ) rd->write( name()+".map" );
232
233 IRegSelLUTCondData* rcd = new IRegSelLUTCondData( std::move(rd) );
234
235 try {
236 if( lutCondData.record( id_range, rcd ).isFailure() ) {
237 ATH_MSG_ERROR( "Could not record " << m_tableKey
238 << " " << lutCondData.key()
239 << " with range " << id_range );
240 return StatusCode::FAILURE;
241 }
242 ATH_MSG_INFO( "RegSelCondAlg LUT recorded: " << m_tableKey);
243 }
244 catch (...) {
245 ATH_MSG_ERROR("SiRegSelCondAlg::execute() failed to record table: " << m_tableKey);
246 return StatusCode::FAILURE;
247 }
248
249
250 ATH_MSG_DEBUG("SiRegSelCondAlg::execute() -- exit -- ");
251
252 return StatusCode::SUCCESS;
253}
254
255
256
257
258
259
260
261
262
263
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
RegSelCondData< IRegSelLUT > IRegSelLUTCondData
This is an Identifier helper class for the Pixel subdetector.
emacs: this is -*- c++ -*-
This is an Identifier helper class for the SCT subdetector.
emacs: this is -*- c++ -*-
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Base class for conditions algorithms.
This is a "hash" representation of an Identifier.
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
This is an Identifier helper class for the Pixel subdetector.
Definition PixelID.h:69
int layer_disk(const Identifier &id) const
Definition PixelID.h:602
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0).
Definition PixelID.h:595
This is an Identifier helper class for the SCT subdetector.
Definition SCT_ID.h:68
int layer_disk(const Identifier &id) const
Definition SCT_ID.h:687
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0).
Definition SCT_ID.h:681
const_pointer_type retrieve()
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
SG::ReadCondHandleKey< SCT_CablingData > m_sctCablingKey
Sadly the PIxel and SCT cabling are different classes so need both, even if only one is to be used.
std::string m_managerName
SG::ReadCondHandleKey< PixelCablingCondData > m_pixCablingKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_detEleCollKey
virtual StatusCode execute(const EventContext &ctx) const override
SiRegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteCondHandleKey< IRegSelLUTCondData > m_tableKey
Output conditions object.
virtual StatusCode initialize() override