ATLAS Offline Software
LArDetectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "LArReadoutGeometry/FCAL_ChannelMap.h"
6 
7 #include "LArDetectorToolNV.h"
8 #include "LArDetectorFactory.h"
11 #include "LArGeoRAL/RAL.h"
13 #include "GaudiKernel/IService.h"
14 #include "GaudiKernel/ISvcLocator.h"
15 #include "GaudiKernel/Bootstrap.h"
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/IMessageSvc.h"
18 #include "StoreGate/StoreGateSvc.h"
24 #include "GeoModelKernel/GeoAlignableTransform.h"
25 #include "GeoModelKernel/GeoGraphNode.h"
27 
29 
31 #include "GeoModelKernel/GeoFullPhysVol.h"
32 #include "GeoModelRead/ReadGeoModel.h"
33 #include "LArHV/LArHVManager.h"
34 
36 #include "SGTools/DataProxy.h"
37 
38 // Name of the folder for LAr Alignment information :
39 #define LAR_ALIGN "/LAR/Align"
40 
41 
43  , const std::string& name
44  , const IInterface* parent)
46  , m_barrelSaggingOn(false)
47  , m_barrelVisLimit(-1)
48  , m_fcalVisLimit(-1)
49  , m_buildBarrel(true)
50  , m_buildEndcap(true)
51  , m_applyAlignments(false)
52  , m_manager{nullptr}
53  , m_geometryConfig("FULL")
54  , m_EMECVariantInner("Wheel")
55  , m_EMECVariantOuter("Wheel")
56  , m_activateFT(true)
57  , m_enableMBTS(true)
58 {
59  declareProperty("SaggingBarrelAccordeon",m_barrelSaggingOn);
60  declareProperty("BarrelCellVisLimit", m_barrelVisLimit);
61  declareProperty("FCALVisLimit", m_fcalVisLimit);
62 
63  declareProperty("BuildBarrel", m_buildBarrel);
64  declareProperty("BuildEndcap", m_buildEndcap);
65  declareProperty("ApplyAlignments", m_applyAlignments);
66  declareProperty("GeometryConfig", m_geometryConfig);
67  declareProperty("EMECVariantInner", m_EMECVariantInner);
68  declareProperty("EMECVariantOuter", m_EMECVariantOuter);
69  declareProperty("ActivateFeedThrougs", m_activateFT);
70  declareProperty("EnableMBTS", m_enableMBTS);
71 }
72 
74 = default;
75 
77 {
78  if(m_detector) {
79  ATH_MSG_FATAL("LAr GeoModel description has already been built. LArDetectorToolNV::create() cannot be called more than once!");
80  return StatusCode::FAILURE;
81  }
82 
83  // Initialize the HV System:
84  LArHVManager* hvManager = new LArHVManager();;
85  ATH_CHECK(detStore()->record(hvManager,"LArHVManager"));
86 
87  // Get the detector configuration.
88  ServiceHandle<IGeoDbTagSvc> geoDbTag("GeoDbTagSvc",name());
89  ATH_CHECK(geoDbTag.retrieve());
90 
91  ServiceHandle<IRDBAccessSvc> accessSvc(geoDbTag->getParamSvcName(),name());
92  ATH_CHECK(accessSvc.retrieve());
93 
94  GeoModelIO::ReadGeoModel* sqliteReader = geoDbTag->getSqliteReader();
95  std::string detectorKey{""};
96  std::string detectorNode{""};
97 
98  if(!sqliteReader) {
99  // Geometry is constructed from the Geometry DB
100  std::string AtlasVersion = geoDbTag->atlasVersion();
101  std::string LArVersion = geoDbTag->LAr_VersionOverride();
102 
103  detectorKey = LArVersion.empty() ? AtlasVersion : LArVersion;
104  detectorNode = LArVersion.empty() ? "ATLAS" : "LAr";
105  ATH_MSG_INFO("Keys for LAr are " << detectorKey << " " << detectorNode);
106  ATH_MSG_INFO("Building LAr version " << geoDbTag->LAr_Version()
107  << " while ATLAS version is " << AtlasVersion);
108  }
109 
110  IRDBRecordset_ptr switchSet = accessSvc->getRecordsetPtr("LArSwitches", detectorKey, detectorNode);
111  if ((*switchSet).size()==0) {
112  ATH_MSG_ERROR("Unable to retrieve LArSwitches from Geometry DB");
113  return StatusCode::FAILURE;
114  }
115 
116  const IRDBRecord* switches = (*switchSet)[0];
117  m_barrelSaggingOn = switches->getInt("SAGGING");
118 
119  if (!switches->isFieldNull("BARREL_ON")) {
120  m_buildBarrel = switches->getInt("BARREL_ON");
121  }
122 
123  if (!switches->isFieldNull("ENDCAP_ON")) {
124  m_buildEndcap = switches->getInt("ENDCAP_ON");
125  }
126 
127  ATH_MSG_INFO("LAr Geometry Options:" );
128  ATH_MSG_INFO(" Sagging = " << (m_barrelSaggingOn ? "true" : "false"));
129  ATH_MSG_INFO(" Barrel = " << (m_buildBarrel ? "ON" : "OFF"));
130  ATH_MSG_INFO(" Endcap = " << (m_buildEndcap ? "ON" : "OFF"));
131 
132  // Locate the top level experiment node
133  GeoModelExperiment* theExpt = nullptr;
134  ATH_CHECK(detStore()->retrieve(theExpt,"ATLAS"));
135 
136  // testbeam=0 Atlas
137  int testbeam = 0;
138 
139  GeoIntrusivePtr<GeoPhysVol>world=theExpt->getPhysVol();
140  if(sqliteReader) {
141  // Geometry is constructed from SQLite file
142  LArGeo::LArDetectorFactoryLite theLArFactoryLite(detStore().operator->()
143  , accessSvc.operator->()
144  , sqliteReader
145  , hvManager);
146  theLArFactoryLite.setBarrelSagging(m_barrelSaggingOn);
147  theLArFactoryLite.create(world);
148  m_manager = theLArFactoryLite.getDetectorManager();
149 
150  std::unique_ptr<LArGeo::VDetectorParameters> params = std::make_unique<LArGeo::RAL>();
152  }
153  else {
154  // Geometry is constructed from the Geometry DB
155 
156  // testbeam=1 H8 test beam => build GeoModel in LArDetectorFactory
157  // testbeam=2 H6 test beam => don't build GeoModel in LArDetectorFactory
158  std::string LArTag = accessSvc->getChildTag("LAr",detectorKey,detectorNode);
159  if(LArTag.find("H8")!=std::string::npos) {
160  testbeam = 1 ;
161  }
162  else if(LArTag.find("H6")!=std::string::npos) {
163  testbeam = 2 ;
164  }
165 
166  LArGeo::LArDetectorFactory theLArFactory(detStore().operator->()
167  , hvManager
168  , testbeam
169  , m_geometryConfig=="FULL");
170 
171  theLArFactory.setBarrelSagging (m_barrelSaggingOn);
172  theLArFactory.setBarrelCellVisLimit (m_barrelVisLimit);
173  theLArFactory.setFCALVisLimit (m_fcalVisLimit);
174  theLArFactory.setBuildBarrel(m_buildBarrel);
175  theLArFactory.setBuildEndcap(m_buildEndcap);
176  theLArFactory.setEMECVariant(m_EMECVariantInner, m_EMECVariantOuter);
177  theLArFactory.setActivateFT(m_activateFT);
178  theLArFactory.setEnableMBTS(m_enableMBTS);
179 
180  theLArFactory.create(world);
181  m_manager = theLArFactory.getDetectorManager();
182  if(m_geometryConfig!="RECO") {
183  // Save RDB Recordsets if we are not inside reco job
184  LArGeo::VDetectorParameters::SetInstance(theLArFactory.moveParameters());
185  }
186  }
187 
188  ATH_CHECK(detStore()->record(m_manager,m_manager->getName()));
189  theExpt->addManager(m_manager);
190 
191  return StatusCode::SUCCESS;
192 }
193 
195 {
196  StoredPhysVol* storedPV{nullptr};
197  StatusCode status(StatusCode::SUCCESS);
198  std::vector<std::string> sgkeysFPV;
199  detStore()->keys<StoredPhysVol>(sgkeysFPV);
200  // First loop over all Full Physical volumes and initialize their global position informations
201  for (const std::string& stored : sgkeysFPV) {
202  status = detStore()->retrieve(storedPV,stored);
203  if(status.isFailure()) {
204  storedPV = nullptr;
205  continue;
206  }
207 
208  if(storedPV) {
209  storedPV->getPhysVol()->getAbsoluteTransform();
210  storedPV->getPhysVol()->getDefAbsoluteTransform();
211  }
212  }
213 
214  for (const std::string& stored : sgkeysFPV) {
215  status = detStore()->retrieve(storedPV,stored);
216  if(status.isFailure()) {
217  storedPV = nullptr;
218  continue;
219  }
220 
221  if(storedPV) {
222  storedPV->getPhysVol()->clear();
223  }
224  }
225 
226  // Release all Stored XF and Stored FPV from the detector store
227  std::vector<std::string> sgkeysAXF;
228  detStore()->keys<StoredAlignX>(sgkeysAXF);
229  for (const std::string& stored : sgkeysAXF) {
231  if(proxy) proxy->reset();
232  }
233 
234  // Release manager from the detector store
236  if(proxy) {
237  proxy->reset();
238  m_manager = nullptr;
239  }
240 
241  return StatusCode::SUCCESS;
242 }
243 
244 StatusCode LArDetectorToolNV::registerCallback ATLAS_NOT_THREAD_SAFE ()
245 {
246  // Return FAILURE if no callbacks have been registered
247  if(!m_applyAlignments) {
248  ATH_MSG_DEBUG("LAr alignments switched OFF");
249  return StatusCode::FAILURE;
250  }
251 
252  const DataHandle<DetCondKeyTrans> dckt;
253  StatusCode sc = detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool *>(this), dckt, LAR_ALIGN);
254  ATH_MSG_DEBUG( (sc.isSuccess() ? "Successfully registered" : "Registration failed for")
255  << " callback on DetCondKeyTrans with folder " << LAR_ALIGN);
256 
257  return sc;
258 }
259 
261 {
262  if(!m_applyAlignments) {
263  ATH_MSG_DEBUG("LAr alignments switched OFF");
264  return StatusCode::SUCCESS;
265  }
266 
267  if(m_manager==nullptr) {
268  ATH_MSG_ERROR(" LArDetDescrManager not created yet, cannot align !");
269  return StatusCode::FAILURE;
270  }
271 
272  if(detStore()->contains<DetCondKeyTrans>(LAR_ALIGN)) {
273  const DetCondKeyTrans* align{nullptr};
274  StatusCode sc = detStore()->retrieve(align, LAR_ALIGN);
275 
276  if(sc.isFailure()) {
277  ATH_MSG_ERROR(" Could not retrieve LAr DetCondKeyTrans ");
278  return sc;
279  }
280 
281  if(align==nullptr) {
282  ATH_MSG_ERROR("LAr DetCondKeyTrans ptr is null");
283  return StatusCode::FAILURE;
284  }
285 
286  ATH_MSG_DEBUG(" LAr DetCondKeyTrans retrieved ");
287  if(m_alignHelper.applyAlignments(detStore(),align,nullptr).isFailure()) {
288  ATH_MSG_ERROR("Failed to apply LAr alignments to GeoModel");
289  return StatusCode::FAILURE;
290  }
291  ATH_MSG_DEBUG("LAr Alignments applied successfully");
292  }
293  else {
294  ATH_MSG_DEBUG(" No LAr DetCondKeyTrans in SG, skipping align() ");
295  }
296 
297  return StatusCode::SUCCESS;
298 }
299 
IRDBRecord::getInt
virtual int getInt(const std::string &fieldName) const =0
Get int field value.
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
GeoModelExperiment::getPhysVol
GeoPhysVol * getPhysVol()
Destructor.
Definition: GeoModelExperiment.cxx:21
LArHVManager.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
LArDetectorToolNV::~LArDetectorToolNV
virtual ~LArDetectorToolNV()
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
LArGeo::VDetectorParameters::SetInstance
static void SetInstance(std::unique_ptr< VDetectorParameters >)
Definition: VDetectorParameters.cxx:24
DetCondKeyTrans
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
Definition: DetCondKeyTrans.h:27
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArDetectorToolNV::clear
virtual StatusCode clear() override
Definition: LArDetectorTool.cxx:194
LArDetectorToolNV::m_geometryConfig
std::string m_geometryConfig
Definition: LArDetectorToolNV.h:64
LArDetectorToolNV::m_alignHelper
LArAlignHelper m_alignHelper
Definition: LArDetectorToolNV.h:72
LArDetectorFactoryLite.h
StoredAlignX
Definition: StoredAlignX.h:23
LArDetectorToolNV::create
virtual StatusCode create() override
Definition: LArDetectorTool.cxx:76
GeoModelExperiment
Definition: GeoModelExperiment.h:32
StoredAlignX.h
LArDetectorToolNV::m_activateFT
bool m_activateFT
Definition: LArDetectorToolNV.h:69
IOVSVC_CALLBACK_ARGS
#define IOVSVC_CALLBACK_ARGS
short hand for IOVSvc call back argument list, to be used when no access to formal arguments is neede...
Definition: IOVSvcDefs.h:24
IGeoModelTool::align
virtual StatusCode align(IOVSVC_CALLBACK_ARGS)=0
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
RAL.h
StoredPhysVol
Definition: StoredPhysVol.h:27
GeoModelExperiment.h
LArDetectorToolNV::m_fcalVisLimit
int m_fcalVisLimit
Definition: LArDetectorToolNV.h:55
EventInfoWrite.AtlasVersion
AtlasVersion
Definition: EventInfoWrite.py:17
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
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
LArDetectorFactory.h
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
test_pyathena.parent
parent
Definition: test_pyathena.py:15
GeoModelTool
Definition: GeoModelTool.h:17
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DetCondKeyTrans.h
LArDetectorToolNV::m_buildBarrel
bool m_buildBarrel
Definition: LArDetectorToolNV.h:57
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
LArGeo::LArDetectorFactoryLite
LArDetectorFactoryLite is invoked by the LArDetectorTool when the GeoModel description of LAr calorim...
Definition: LArDetectorFactoryLite.h:33
CLHEPtoEigenConverter.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
VDetectorParameters.h
GeoModelTool::m_detector
GeoVDetectorManager * m_detector
Definition: GeoModelTool.h:36
LArAlignHelper::applyAlignments
StatusCode applyAlignments(const ServiceHandle< StoreGateSvc > &detStore, const DetCondKeyTrans *detCondKeyTrans, GeoAlignmentStore *alignmentStore) const
Definition: LArAlignHelper.cxx:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LArDetectorToolNV.h
Declaration of LArDetectorToolNV class.
DataHandle
an iterator over instances of a given type in StoreGateSvc. It d-casts and caches locally the pointed...
Definition: DataHandle.h:42
ATLAS_NOT_THREAD_SAFE
StatusCode LArDetectorToolNV::registerCallback ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: LArDetectorTool.cxx:244
LArDetectorToolNV::m_enableMBTS
bool m_enableMBTS
Definition: LArDetectorToolNV.h:70
LArDetectorToolNV::LArDetectorToolNV
LArDetectorToolNV(const std::string &type, const std::string &name, const IInterface *parent)
Definition: LArDetectorTool.cxx:42
GeoModelExperiment::addManager
void addManager(const GeoVDetectorManager *)
Definition: GeoModelExperiment.cxx:40
LArHVManager
This class provides access to the High Voltage throughout the LAr. High voltage conditions can also b...
Definition: LArHVManager.h:24
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
LArDetectorToolNV::m_EMECVariantOuter
std::string m_EMECVariantOuter
Definition: LArDetectorToolNV.h:67
IGeoModelTool
Definition: IGeoModelTool.h:12
IRDBRecord::isFieldNull
virtual bool isFieldNull(const std::string &fieldName) const =0
Check if the field value is NULL.
IRDBRecord
IRDBRecord is one record in the IRDBRecordset object.
Definition: IRDBRecord.h:27
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LArDetectorToolNV::m_manager
const LArDetectorManager * m_manager
Definition: LArDetectorToolNV.h:62
LArDetectorToolNV::m_barrelVisLimit
int m_barrelVisLimit
Definition: LArDetectorToolNV.h:54
LArDetectorToolNV::align
virtual StatusCode align(IOVSVC_CALLBACK_ARGS) override
Definition: LArDetectorTool.cxx:260
LAR_ALIGN
#define LAR_ALIGN
Definition: LArDetectorTool.cxx:39
merge.status
status
Definition: merge.py:17
LArGeo::LArDetectorFactory::setBarrelSagging
void setBarrelSagging(bool flag)
Definition: LArDetectorFactory.h:53
LArDetectorToolNV::m_applyAlignments
bool m_applyAlignments
Definition: LArDetectorToolNV.h:60
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
LArDetectorToolNV::m_buildEndcap
bool m_buildEndcap
Definition: LArDetectorToolNV.h:58
SG::DataProxy
Definition: DataProxy.h:45
LArDetectorToolNV::m_EMECVariantInner
std::string m_EMECVariantInner
Definition: LArDetectorToolNV.h:66
StoreGateSvc.h
LArGeo::LArDetectorFactory
LArDetectorFactory builds GeoModel description of LAr calorimeter by calling relevant 'Construction' ...
Definition: LArDetectorFactory.h:29
IGeoDbTagSvc.h
LArGeo::LArDetectorFactoryLite::setBarrelSagging
void setBarrelSagging(bool flag)
Definition: LArDetectorFactoryLite.h:51
StoredPhysVol.h
ServiceHandle< IGeoDbTagSvc >
LArDetectorToolNV::m_barrelSaggingOn
bool m_barrelSaggingOn
Definition: LArDetectorToolNV.h:53
DataProxy.h