ATLAS Offline Software
Loading...
Searching...
No Matches
LArDetectorTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "LArReadoutGeometry/FCAL_ChannelMap.h"
6
7#include "LArDetectorToolNV.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"
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)
45 : GeoModelTool(type,name,parent)
46{
47}
48
50= default;
51
53{
54 if(m_detector) {
55 ATH_MSG_FATAL("LAr GeoModel description has already been built. LArDetectorToolNV::create() cannot be called more than once!");
56 return StatusCode::FAILURE;
57 }
58
59 // Initialize the HV System:
60 LArHVManager* hvManager = new LArHVManager();;
61 ATH_CHECK(detStore()->record(hvManager,"LArHVManager"));
62
63 // Get the detector configuration.
64 ServiceHandle<IGeoDbTagSvc> geoDbTag("GeoDbTagSvc",name());
65 ATH_CHECK(geoDbTag.retrieve());
66
67 ServiceHandle<IRDBAccessSvc> accessSvc(geoDbTag->getParamSvcName(),name());
68 ATH_CHECK(accessSvc.retrieve());
69
70 GeoModelIO::ReadGeoModel* sqliteReader = geoDbTag->getSqliteReader();
71 std::string detectorKey{""};
72 std::string detectorNode{""};
73
74 if(!sqliteReader) {
75 // Geometry is constructed from the Geometry DB
76 std::string AtlasVersion = geoDbTag->atlasVersion();
77 std::string LArVersion = geoDbTag->LAr_VersionOverride();
78
79 detectorKey = LArVersion.empty() ? AtlasVersion : LArVersion;
80 detectorNode = LArVersion.empty() ? "ATLAS" : "LAr";
81 ATH_MSG_INFO("Keys for LAr are " << detectorKey << " " << detectorNode);
82 ATH_MSG_INFO("Building LAr version " << geoDbTag->LAr_Version()
83 << " while ATLAS version is " << AtlasVersion);
84 }
85
86 IRDBRecordset_ptr switchSet = accessSvc->getRecordsetPtr("LArSwitches", detectorKey, detectorNode);
87 if ((*switchSet).size()==0) {
88 ATH_MSG_ERROR("Unable to retrieve LArSwitches from Geometry DB");
89 return StatusCode::FAILURE;
90 }
91
92 const IRDBRecord* switches = (*switchSet)[0];
93 m_barrelSaggingOn = switches->getInt("SAGGING");
94
95 if (!switches->isFieldNull("BARREL_ON")) {
96 m_buildBarrel = switches->getInt("BARREL_ON");
97 }
98
99 if (!switches->isFieldNull("ENDCAP_ON")) {
100 m_buildEndcap = switches->getInt("ENDCAP_ON");
101 }
102
103 ATH_MSG_INFO("LAr Geometry Options:" );
104 ATH_MSG_INFO(" Sagging = " << (m_barrelSaggingOn ? "true" : "false"));
105 ATH_MSG_INFO(" Barrel = " << (m_buildBarrel ? "ON" : "OFF"));
106 ATH_MSG_INFO(" Endcap = " << (m_buildEndcap ? "ON" : "OFF"));
107
108 // Locate the top level experiment node
109 GeoModelExperiment* theExpt = nullptr;
110 ATH_CHECK(detStore()->retrieve(theExpt,"ATLAS"));
111
112 // testbeam=0 Atlas
113 int testbeam = 0;
114
115 GeoIntrusivePtr<GeoPhysVol>world=theExpt->getPhysVol();
116 if(sqliteReader) {
117 // Geometry is constructed from SQLite file
118 LArGeo::LArDetectorFactoryLite theLArFactoryLite(detStore().operator->()
119 , accessSvc.operator->()
120 , sqliteReader
121 , hvManager);
122 theLArFactoryLite.setBarrelSagging(m_barrelSaggingOn);
123 theLArFactoryLite.create(world);
124 m_manager = theLArFactoryLite.getDetectorManager();
125
126 std::unique_ptr<LArGeo::VDetectorParameters> params = std::make_unique<LArGeo::RAL>();
128 }
129 else {
130 // Geometry is constructed from the Geometry DB
131
132 // testbeam=1 H8 test beam => build GeoModel in LArDetectorFactory
133 // testbeam=2 H6 test beam => don't build GeoModel in LArDetectorFactory
134 std::string LArTag = accessSvc->getChildTag("LAr",detectorKey,detectorNode);
135 if(LArTag.find("H8")!=std::string::npos) {
136 testbeam = 1 ;
137 }
138 else if(LArTag.find("H6")!=std::string::npos) {
139 testbeam = 2 ;
140 }
141
142 LArGeo::LArDetectorFactory theLArFactory(detStore().operator->()
143 , hvManager
144 , testbeam
145 , m_geometryConfig=="FULL");
146
147 theLArFactory.setBarrelSagging (m_barrelSaggingOn);
149 theLArFactory.setFCALVisLimit (m_fcalVisLimit);
150 theLArFactory.setBuildBarrel(m_buildBarrel);
151 theLArFactory.setBuildEndcap(m_buildEndcap);
153 theLArFactory.setActivateFT(m_activateFT);
154 theLArFactory.setEnableMBTS(m_enableMBTS);
155
156 theLArFactory.create(world);
157 m_manager = theLArFactory.getDetectorManager();
158 if(m_geometryConfig!="RECO") {
159 // Save RDB Recordsets if we are not inside reco job
161 }
162 }
163
164 ATH_CHECK(detStore()->record(m_manager,m_manager->getName()));
165 theExpt->addManager(m_manager);
166
167 return StatusCode::SUCCESS;
168}
169
171{
172 StoredPhysVol* storedPV{nullptr};
173 StatusCode status(StatusCode::SUCCESS);
174 std::vector<std::string> sgkeysFPV;
175 detStore()->keys<StoredPhysVol>(sgkeysFPV);
176 // First loop over all Full Physical volumes and initialize their global position informations
177 for (const std::string& stored : sgkeysFPV) {
178 status = detStore()->retrieve(storedPV,stored);
179 if(status.isFailure()) {
180 storedPV = nullptr;
181 continue;
182 }
183
184 if(storedPV) {
185 storedPV->getPhysVol()->getAbsoluteTransform();
186 storedPV->getPhysVol()->getDefAbsoluteTransform();
187 }
188 }
189
190 for (const std::string& stored : sgkeysFPV) {
191 status = detStore()->retrieve(storedPV,stored);
192 if(status.isFailure()) {
193 storedPV = nullptr;
194 continue;
195 }
196
197 if(storedPV) {
198 storedPV->getPhysVol()->clear();
199 }
200 }
201
202 // Release all Stored XF and Stored FPV from the detector store
203 std::vector<std::string> sgkeysAXF;
204 detStore()->keys<StoredAlignX>(sgkeysAXF);
205 for (const std::string& stored : sgkeysAXF) {
206 SG::DataProxy* proxy = detStore()->proxy(ClassID_traits<StoredAlignX>::ID(),stored);
207 if(proxy) proxy->reset();
208 }
209
210 // Release manager from the detector store
211 SG::DataProxy* proxy = detStore()->proxy(ClassID_traits<LArDetectorManager>::ID(),m_manager->getName());
212 if(proxy) {
213 proxy->reset();
214 m_manager = nullptr;
215 }
216
217 return StatusCode::SUCCESS;
218}
219
221{
222 if(!m_applyAlignments) {
223 ATH_MSG_DEBUG("LAr alignments switched OFF");
224 return StatusCode::SUCCESS;
225 }
226
227 if(!m_manager) {
228 ATH_MSG_ERROR(" LArDetDescrManager not created yet, cannot align !");
229 return StatusCode::FAILURE;
230 }
231
232 if(detStore()->contains<DetCondKeyTrans>(LAR_ALIGN)) {
233 const DetCondKeyTrans* align{nullptr};
234 ATH_CHECK(detStore()->retrieve(align, LAR_ALIGN));
235 ATH_MSG_DEBUG(" LAr DetCondKeyTrans retrieved ");
236 if(m_alignHelper.applyAlignments(detStore(),align,nullptr).isFailure()) {
237 ATH_MSG_ERROR("Failed to apply LAr alignments to GeoModel");
238 return StatusCode::FAILURE;
239 }
240 ATH_MSG_DEBUG("LAr Alignments applied successfully");
241 }
242 else {
243 ATH_MSG_DEBUG(" No LAr DetCondKeyTrans in SG, skipping align() ");
244 }
245
246 return StatusCode::SUCCESS;
247}
248
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
Definition of the abstract IRDBAccessSvc interface.
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
#define LAR_ALIGN
Declaration of LArDetectorToolNV class.
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
GeoPhysVol * getPhysVol()
Destructor.
void addManager(const GeoVDetectorManager *)
GeoVDetectorManager * m_detector
IRDBRecord is one record in the IRDBRecordset object.
Definition IRDBRecord.h:27
virtual bool isFieldNull(const std::string &fieldName) const =0
Check if the field value is NULL.
virtual int getInt(const std::string &fieldName) const =0
Get int field value.
virtual ~LArDetectorToolNV()
LArDetectorToolNV(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode create() override
Gaudi::Property< std::string > m_geometryConfig
Gaudi::Property< bool > m_buildEndcap
virtual StatusCode align() override
Gaudi::Property< std::string > m_EMECVariantInner
virtual StatusCode clear() override
Gaudi::Property< int > m_barrelVisLimit
Gaudi::Property< std::string > m_EMECVariantOuter
Gaudi::Property< bool > m_barrelSaggingOn
const LArDetectorManager * m_manager
Gaudi::Property< bool > m_enableMBTS
Gaudi::Property< bool > m_activateFT
Gaudi::Property< bool > m_applyAlignments
LArAlignHelper m_alignHelper
Gaudi::Property< bool > m_buildBarrel
Gaudi::Property< int > m_fcalVisLimit
LArDetectorFactoryLite is invoked by the LArDetectorTool when the GeoModel description of LAr calorim...
virtual void create(GeoPhysVol *world) override
virtual const LArDetectorManager * getDetectorManager() const override
LArDetectorFactory builds GeoModel description of LAr calorimeter by calling relevant 'Construction' ...
void setFCALVisLimit(int maxCell)
std::unique_ptr< LArGeo::VDetectorParameters > moveParameters()
virtual void create(GeoPhysVol *world) override
void setEMECVariant(const std::string &inner, const std::string &outer)
void setBarrelCellVisLimit(int maxCell)
virtual const LArDetectorManager * getDetectorManager() const override
static void SetInstance(std::unique_ptr< VDetectorParameters >)
This class provides access to the High Voltage throughout the LAr.
GeoFullPhysVol * getPhysVol()
Destructor.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114