ATLAS Offline Software
SiRegSelCondAlg.cxx
Go to the documentation of this file.
1 
15 #include "GaudiKernel/EventIDRange.h"
17 
18 
21 
22 #include "InDetIdentifier/SCT_ID.h"
24 
25 #include "SiRegSelCondAlg.h"
26 
28 #include "RegSelLUT/RegSelSiLUT.h"
29 
30 
31 SiRegSelCondAlg::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() ");
51  ATH_CHECK(m_tableKey.initialize());
52  ATH_MSG_INFO("SiRegSelCondAlg::initialize() " << m_tableKey );
53  return StatusCode::SUCCESS;
54 }
55 
56 
57 
58 
59 StatusCode 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 
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
RegSelModule
Definition: RegSelModule.h:38
SiRegSelCondAlg.h
emacs: this is -*- c++ -*-
RegSelCondData
Definition: RegSelCondData.h:25
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
SiRegSelCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: SiRegSelCondAlg.cxx:59
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SiRegSelCondAlg::m_printTable
bool m_printTable
Definition: SiRegSelCondAlg.h:44
SiRegSelCondAlg::m_useCabling
bool m_useCabling
Definition: SiRegSelCondAlg.h:45
SiRegSelCondAlg::SiRegSelCondAlg
SiRegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SiRegSelCondAlg.cxx:31
SiRegSelCondAlg::initialize
virtual StatusCode initialize() override
Definition: SiRegSelCondAlg.cxx:44
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
SiRegSelCondAlg::m_managerName
std::string m_managerName
Definition: SiRegSelCondAlg.h:43
RegSelSiLUT.h
emacs: this is -*- c++ -*-
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:224
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
SiRegSelCondAlg::m_pixCablingKey
SG::ReadCondHandleKey< PixelCablingCondData > m_pixCablingKey
Definition: SiRegSelCondAlg.h:54
SiRegSelCondAlg::m_sctCablingKey
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.
Definition: SiRegSelCondAlg.h:51
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
RegSelSiLUT::write
void write(std::ostream &s=std::cout) const
Definition: RegSelSiLUT.cxx:543
RegSelSiLUT::initialise
void initialise()
Definition: RegSelSiLUT.cxx:110
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadCondHandle::retrieve
const_pointer_type retrieve()
Definition: ReadCondHandle.h:162
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
WriteCondHandle.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
RegSelSiLUT::SCT
@ SCT
Definition: RegSelSiLUT.h:45
SiRegSelCondAlg::m_detEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_detEleCollKey
Definition: SiRegSelCondAlg.h:57
IRegSelLUTCondData.h
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
RegSelSiLUT::PIXEL
@ PIXEL
Definition: RegSelSiLUT.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SiDetectorElementCollection.h
RegSelSiLUT::addModule
void addModule(RegSelModule &module)
Definition: RegSelSiLUT.h:71
SiDetectorElement.h
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
SCT_ID
Definition: SCT_ID.h:68
SiRegSelCondAlg::m_tableKey
SG::WriteCondHandleKey< IRegSelLUTCondData > m_tableKey
Output conditions object.
Definition: SiRegSelCondAlg.h:61
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
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
PixelID
Definition: PixelID.h:67
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
python.SystemOfUnits.degree
tuple degree
Definition: SystemOfUnits.py:106
IRegSelLUTCondData
RegSelCondData< IRegSelLUT > IRegSelLUTCondData
Definition: IRegSelLUTCondData.h:20