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