ATLAS Offline Software
RegSelCondAlg_Tile.cxx
Go to the documentation of this file.
1 
15 #include "RegSelCondAlg_Tile.h"
16 
17 #include "GaudiKernel/EventIDRange.h"
19 
21 
23 
24 #include "eformat/SourceIdentifier.h"
25 
29 #include "CaloIdentifier/TileID.h"
31 #include "CaloDetDescr/CaloDetDescrElement.h"
32 
33 #include <cmath>
34 #include <iostream>
35 #include <string>
36 #include <memory>
37 
38 
39 RegSelCondAlg_Tile::RegSelCondAlg_Tile(const std::string& name, ISvcLocator* pSvcLocator):
40  AthReentrantAlgorithm( name, pSvcLocator ),
41  m_managerName(""),
42  m_printTable(false)
43 {
44  declareProperty( "ManagerName", m_managerName );
45  declareProperty( "PrintTable", m_printTable=false );
46 }
47 
48 
49 
50 
52  ATH_MSG_DEBUG("RegSelCondAlg_Tile::initialize() ");
54  ATH_CHECK(m_tableKey.initialize());
55  ATH_MSG_INFO("RegSelCondAlg_Tile::initialize() " << m_tableKey );
56  return StatusCode::SUCCESS;
57 }
58 
59 
60 
61 StatusCode RegSelCondAlg_Tile::execute(const EventContext& ctx) const {
62 
63  ATH_MSG_DEBUG("RegSelCondAlg_Tile::execute() -- enter -- ");
64 
66  ATH_MSG_DEBUG( "Creating region selector table " << m_tableKey );
67 
68 
70  if (lutCondData.isValid()) {
76  ATH_MSG_DEBUG("CondHandle " << lutCondData.fullKey() << " is already valid." );
77  return StatusCode::SUCCESS;
78  }
79 
81  if(!hid2RESrcID.isValid()) {
82  ATH_MSG_ERROR( "Do not have TileHid2RESrcID from key " << m_hid2RESrcIDKey.key() );
83  return StatusCode::FAILURE;
84  }
85 
86  EventIDRange id_range;
87 
88  if( !hid2RESrcID.range( id_range ) ) {
89  ATH_MSG_ERROR("Failed to retrieve validity range for " << hid2RESrcID.key());
90  return StatusCode::FAILURE;
91  }
92 
93 
94  ATH_MSG_INFO( "creating new Tile table" );
95 
97 
98  std::unique_ptr<IRegSelLUT> rd = createTable(*hid2RESrcID);
99 
100  if ( !rd ) return StatusCode::FAILURE;
101 
102  ATH_MSG_INFO( "Storing the new look up table " << m_tableKey );
103 
105 
106  IRegSelLUTCondData* rcd = new IRegSelLUTCondData( std::move(rd) );
107 
108  try {
113  if( lutCondData.record( id_range, rcd ).isFailure() ) {
114  ATH_MSG_ERROR( "Could not record " << m_tableKey
115  << " " << lutCondData.key()
116  << " with range " << id_range );
117  return StatusCode::FAILURE;
118  }
119  ATH_MSG_INFO( "RegSelCondAlg LUT recorded: " << m_tableKey);
120  }
121  catch (...) {
122  ATH_MSG_ERROR("RegSelCondAlg_Tile::execute() failed to record table: " << m_tableKey);
123  return StatusCode::FAILURE;
124  }
125 
126 
127  ATH_MSG_DEBUG("RegSelCondAlg_Tile::execute() -- exit -- ");
128 
129  return StatusCode::SUCCESS;
130 }
131 
132 
133 
134 
135 std::unique_ptr<RegSelectorMap> RegSelCondAlg_Tile::createTable(const TileHid2RESrcID* hid2re) const {
136 
137  std::unique_ptr<RegSelectorMap> lut(nullptr);
138 
141 
142 
143  // Get the TileID helper from the detector store
144  const TileID* tileID;
145  if (detStore()->retrieve(tileID, "TileID").isFailure()) {
146  ATH_MSG_ERROR( "Could not get TileID helper !");
147  return lut;
148  }
149 
150  // Get the TileHWID helper from the detector store
151  const TileHWID* tileHWID;
152  if (detStore()->retrieve(tileHWID, "TileHWID").isFailure()) {
153  ATH_MSG_ERROR( "Could not get TileHWID helper !");
154  return lut;
155  }
156 
157  // Get pointer to TileDetDescrManager
158  const TileDetDescrManager* tileMgr;
159  if (detStore()->retrieve(tileMgr).isFailure()) {
160  ATH_MSG_ERROR( "Unable to retrieve TileDetDescrManager from DetectorStore" );
161  return lut;
162  }
163 
164  std::unique_ptr<RegionSelectorLUT> ttLut = std::make_unique<RegionSelectorLUT>(256);
165 
166  enum Partition { Ancillary = 0, LBA = 1, LBC = 2, EBA = 3, EBC = 4 };
167 
168  // hard-coded etamin/etamax - ignoring slightly different positions of EBA end ENC partitions
169  // FIXME: this is very poor - the actual positions should come from the geometry, not be hard
171 
172  std::vector<double> etamin(TileCalibUtils::MAX_ROS);
173  etamin[LBA]=-0.1;
174  etamin[LBC]=-1.0;
175  etamin[EBA]=+0.708779;
176  etamin[EBC]=-1.60943;
177  std::vector<double> etamax(TileCalibUtils::MAX_ROS);
178  etamax[LBA]=+1.0;
179  etamax[LBC]=+0.1;
180  etamax[EBA]=+1.60943;
181  etamax[EBC]=-0.708779;
182 
183  // so presumably USE_CELL_PHI is not definied, so we don't want
185 
186 # if (defined USE_MODULE_PHI)
187 # else
188  double dphi = 2 * M_PI / TileCalibUtils::MAX_DRAWER; // 0.09817477;
189 # endif
190 
191  int sam = 0; // ?
192  int layer = 0; //?
193  int firstone = tileHWID->drawerIdx( tileHWID->drawer_id(LBA,0) ); // hash index of first real drawer (LBA01)
194  for (unsigned int ros = 0; ros < TileCalibUtils::MAX_ROS; ++ros) {
195  for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
196 
197  int hash = tileHWID->drawerIdx( tileHWID->drawer_id(ros,drawer) ) - firstone;
198  if (hash<0) continue;
199 
200  int coll = tileHWID->frag(ros, drawer);
201  int rod = hid2re->getRodID(coll);
202 
203  double etami = etamin[ros];
204  double etama = etamax[ros];
205 
206 # if (defined USE_MODULE_PHI)
207  // alternative approach
208  int section = (ros==LBA || ros==LBC) ? TileID::BARREL : TileID::EXTBAR;
209  int side = (ros==LBA || ros==EBA) ? TileID::POSITIVE : TileID::NEGATIVE;
210  Identifier moduleID = tileID->module_id(section,side,drawer);
211  CaloDetDescriptor *moduleDDE = tileMgr->get_module_element(moduleID);
212  double phimin = moduleDDE->calo_phi_min();
213  double phimax = moduleDDE->calo_phi_max();
214  if ( phimin < 0.0 ) {
215  phimin+=2*M_PI;
216  if ( phimax < phimin ) phimax+=2*M_PI;
217  }
218 # else
219  // OLD method - we can predict phi boundaries from module number
220  double phimin = drawer * dphi;
221  double phimax = (drawer+1) * dphi;
222 # endif
223 
224  ttLut->additem(etami,etama,phimin,phimax,sam,layer,hash,rod);
225 
226  }
227  }
228 
229 
235 
236  lut = std::make_unique<RegSelectorMap>();
237  lut->addLut( ttLut.get() );
238  lut->mountDataStruct();
239 
240  return lut;
241 }
242 
Tile_Base_ID::module_id
Identifier module_id(int section, int side, int module) const
Definition: Tile_Base_ID.cxx:505
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
RegSelCondData
Definition: RegSelCondData.h:25
RegSelCondAlg_Tile::m_hid2RESrcIDKey
SG::ReadCondHandleKey< TileHid2RESrcID > m_hid2RESrcIDKey
Definition: RegSelCondAlg_Tile.h:47
StateLessPT_NewConfig.Partition
Partition
Definition: StateLessPT_NewConfig.py:240
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
RegionSelectorLUT.h
RegSelCondAlg_Tile::m_managerName
std::string m_managerName
Definition: RegSelCondAlg_Tile.h:42
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
M_PI
#define M_PI
Definition: ActiveFraction.h:11
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
TileHWID::frag
int frag(const HWIdentifier &id) const
extract frag field from HW identifier
Definition: TileHWID.h:181
TileCalibUtils.h
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:224
RegSelCondAlg_Tile.h
emacs: this is -*- c++ -*-
CaloDetDescriptor::calo_phi_min
double calo_phi_min() const
'ideal' geometry: phi minimal
Definition: CaloDetDescriptor.h:568
CaloDetDescriptor::calo_phi_max
double calo_phi_max() const
'ideal' geometry: phi maximal
Definition: CaloDetDescriptor.h:573
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
Tile_Base_ID::BARREL
@ BARREL
Definition: Tile_Base_ID.h:48
Example_ReadSampleNoise.drawer
drawer
Definition: Example_ReadSampleNoise.py:39
ITkPixEncoding::lut
constexpr auto lut(Generator &&f)
Definition: ITkPixQCoreEncodingLUT.h:19
TileID.h
TileDetDescrManager.h
TileHid2RESrcID
This class provides conversion between fragment ID and RESrcID.
Definition: TileHid2RESrcID.h:28
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
TileCalibUtils::MAX_DRAWER
static const unsigned int MAX_DRAWER
Number of drawers in ROS 1-4.
Definition: TileCalibUtils.h:139
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TRT::Hit::side
@ side
Definition: HitInfo.h:83
TileHWID
Helper class for TileCal online (hardware) identifiers.
Definition: TileHWID.h:49
Tile_Base_ID::EXTBAR
@ EXTBAR
Definition: Tile_Base_ID.h:48
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:41
TileHWID.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TileHid2RESrcID::getRodID
uint32_t getRodID(int frag_id) const
make a ROD SrcID for a fragment ID
Definition: TileHid2RESrcID.cxx:464
RegSelCondAlg_Tile::createTable
virtual std::unique_ptr< RegSelectorMap > createTable(const TileHid2RESrcID *hid2re) const
Definition: RegSelCondAlg_Tile.cxx:135
TileDetDescrManager
Definition: TileDetDescrManager.h:33
TileID
Helper class for TileCal offline identifiers.
Definition: TileID.h:68
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
WriteCondHandle.h
TileDetDescrManager::get_module_element
CaloDetDescriptor * get_module_element(const IdentifierHash module_hash) const
Definition: TileDetDescrManager.h:137
Tile_Base_ID::POSITIVE
@ POSITIVE
Definition: Tile_Base_ID.h:56
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
RegSelCondAlg_Tile::RegSelCondAlg_Tile
RegSelCondAlg_Tile(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RegSelCondAlg_Tile.cxx:39
TileCalibUtils::MAX_ROS
static const unsigned int MAX_ROS
Number of ROSs
Definition: TileCalibUtils.h:138
maskDeadModules.ros
ros
Definition: maskDeadModules.py:35
RunTileMonitoring.rod
rod
Definition: RunTileMonitoring.py:134
RegSelCondAlg_Tile::m_printTable
bool m_printTable
Definition: RegSelCondAlg_Tile.h:44
RegSelCondAlg_Tile::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: RegSelCondAlg_Tile.cxx:61
TileHid2RESrcID.h
TileHWID::drawer_id
HWIdentifier drawer_id(int frag) const
ROS HWIdentifer.
Definition: TileHWID.cxx:186
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
TileHWID::drawerIdx
int drawerIdx(const HWIdentifier &id) const
construct drawer index from HW identifier
Definition: TileHWID.h:175
Tile_Base_ID::NEGATIVE
@ NEGATIVE
Definition: Tile_Base_ID.h:56
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TileRoI_Map.h
CaloDetDescriptor
This is a base class for LAr and Tile Descriptors The primary goal is to speed up loops over all the ...
Definition: CaloDetDescriptor.h:58
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
RegSelCondAlg_Tile::initialize
virtual StatusCode initialize() override
Definition: RegSelCondAlg_Tile.cxx:51
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
section
void section(const std::string &sec)
Definition: TestTriggerMenuAccess.cxx:22
LArCellBinning.etamin
etamin
Definition: LArCellBinning.py:137
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
RegionSelectorLUT::additem
void additem(const int hashId, const double etaMin, const double etaMax, const double phiMin, const double phiMax, const int layerDiskNumber, const int layerDiskPosition)
Definition: RegionSelectorLUT.cxx:125
IRegSelLUTCondData
RegSelCondData< IRegSelLUT > IRegSelLUTCondData
Definition: IRegSelLUTCondData.h:20
RegSelCondAlg_Tile::m_tableKey
SG::WriteCondHandleKey< IRegSelLUTCondData > m_tableKey
Output conditions object.
Definition: RegSelCondAlg_Tile.h:51