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 AthReentrantAlgorithm( 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 if ( m_managerName=="Pixel" ) rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::PIXEL);
119 else rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::SCT);
120
121 // Get detector elements (=alignment) in condition store
122 const InDetDD::SiDetectorElementCollection* elements = nullptr;
124 if (detEle.isValid()) {
125 elements = detEle.retrieve();
126 }
127 if (elements==nullptr) {
128 ATH_MSG_ERROR("Failed to retrieve InDetDD::SiDetectorElementCollection for " << m_managerName);
129 return StatusCode::FAILURE;
130 }
131 // Since this condition algorithm for HLT, we want to run this only at the first event of a run.
132 // We do not take the intersect of ranges of cabling and detector elements.
133 // We use the range of cabling.
134
135 if(!m_useCabling){
136 if( !detEle.range( id_range ) ) {
137 ATH_MSG_ERROR("Failed to retrieve validity range for " << detEle.key() << " : " << id_range );
138 return StatusCode::FAILURE;
139 }
140 ATH_MSG_DEBUG( "RegSelCondAlg: " << id_range << "( final range )" );
141 }
142
143 for (const InDetDD::SiDetectorElement* element : *elements) {
144
145 if (element) {
146
147 IdentifierHash hashId = element->identifyHash();
148
149 ATH_MSG_VERBOSE( "Found element with HashId = " << hashId );
150
151 // new region selector detector element extent
152
153 double rMin, rMax, zMin, zMax, phiMin, phiMax;
154
155 rMin = element->rMin();
156 rMax = element->rMax();
157 zMin = element->zMin();
158 zMax = element->zMax();
159 phiMin = element->phiMin();
160 phiMax = element->phiMax();
161
162
163 int barrelEC = 0;
164 int layerDisk = 0;
165 uint32_t robId = 0;
166
167 if (element->isPixel()) {
168
169 const PixelID* pixelId = dynamic_cast<const PixelID*>(element->getIdHelper());
170 if ( pixelId!=nullptr ) {
171 barrelEC = pixelId->barrel_ec(element->identify());
172 if ( std::fabs(barrelEC)>3 ) continue; // skip DBM modules
173 layerDisk = pixelId->layer_disk(element->identify());
174 if(m_useCabling) robId=(*pixCabling)->find_entry_offrob(element->identify());
175 else robId = 0;
176 }
177 else {
178 ATH_MSG_ERROR("Could not get PIXEL_ID for " << element->getIdHelper() );
179 }
180
181 } else { // it's an SCT element
182
183 const SCT_ID* sctId = dynamic_cast<const SCT_ID*>(element->getIdHelper());
184 if ( sctId!=nullptr ) {
185 barrelEC = sctId->barrel_ec(element->identify());
186 layerDisk = sctId->layer_disk(element->identify());
187 // Avoid use of SCT_CablingTool. Instead of
188 // robId=m_sctCablingTool->getRobIdFromOfflineId(element->identify());
189 if(m_useCabling) robId = ((*sctCabling)->getOnlineIdFromHash(element->identifyHash())).rod();
190 else robId = 0;
191 }
192 else {
193 ATH_MSG_ERROR("Could not get SCT_ID for " << element->getIdHelper() );
194 }
195
196 }
197
198
199 // create module for lookup table
200
201 RegSelModule smod( zMin, zMax, rMin, rMax, phiMin, phiMax, layerDisk, barrelEC, robId, hashId );
202
203 rd->addModule( smod );
204
205 ATH_MSG_DEBUG( smod );
206
207 ATH_MSG_VERBOSE( "\t robId = " << robId
208 << " barrelEC = " << barrelEC
209 << ", layerDisk = " << layerDisk
210 << ", phiMin, phiMax = " << phiMin/CLHEP::degree << " " << phiMax/CLHEP::degree
211 << ", rMin = " << rMin/CLHEP::mm << " mm, rMax = " << rMax/CLHEP::mm << " mm" );
212
213 }
214 }
215
216
217 ATH_MSG_DEBUG( " initialising new map " );
218
219 rd->initialise();
220
221 // write out new new LUT to a file if need be
222 if ( m_printTable ) rd->write( name()+".map" );
223
224 IRegSelLUTCondData* rcd = new IRegSelLUTCondData( std::move(rd) );
225
226 try {
227 if( lutCondData.record( id_range, rcd ).isFailure() ) {
228 ATH_MSG_ERROR( "Could not record " << m_tableKey
229 << " " << lutCondData.key()
230 << " with range " << id_range );
231 return StatusCode::FAILURE;
232 }
233 ATH_MSG_INFO( "RegSelCondAlg LUT recorded: " << m_tableKey);
234 }
235 catch (...) {
236 ATH_MSG_ERROR("SiRegSelCondAlg::execute() failed to record table: " << m_tableKey);
237 return StatusCode::FAILURE;
238 }
239
240
241 ATH_MSG_DEBUG("SiRegSelCondAlg::execute() -- exit -- ");
242
243 return StatusCode::SUCCESS;
244}
245
246
247
248
249
250
251
252
253
254
255
#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)
An algorithm that can be simultaneously executed in multiple threads.
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:67
int layer_disk(const Identifier &id) const
Definition PixelID.h:607
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition PixelID.h:600
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