ATLAS Offline Software
Loading...
Searching...
No Matches
LArDetectorTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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 , m_barrelSaggingOn(false)
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);
173 theLArFactory.setFCALVisLimit (m_fcalVisLimit);
174 theLArFactory.setBuildBarrel(m_buildBarrel);
175 theLArFactory.setBuildEndcap(m_buildEndcap);
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
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) {
230 SG::DataProxy* proxy = detStore()->proxy(ClassID_traits<StoredAlignX>::ID(),stored);
231 if(proxy) proxy->reset();
232 }
233
234 // Release manager from the detector store
235 SG::DataProxy* proxy = detStore()->proxy(ClassID_traits<LArDetectorManager>::ID(),m_manager->getName());
236 if(proxy) {
237 proxy->reset();
238 m_manager = nullptr;
239 }
240
241 return StatusCode::SUCCESS;
242}
243
244StatusCode LArDetectorToolNV::align(IOVSVC_CALLBACK_ARGS)
245{
246 if(!m_applyAlignments) {
247 ATH_MSG_DEBUG("LAr alignments switched OFF");
248 return StatusCode::SUCCESS;
249 }
250
251 if(m_manager==nullptr) {
252 ATH_MSG_ERROR(" LArDetDescrManager not created yet, cannot align !");
253 return StatusCode::FAILURE;
254 }
255
257 const DetCondKeyTrans* align{nullptr};
258 StatusCode sc = detStore()->retrieve(align, LAR_ALIGN);
259
260 if(sc.isFailure()) {
261 ATH_MSG_ERROR(" Could not retrieve LAr DetCondKeyTrans ");
262 return sc;
263 }
264
265 if(align==nullptr) {
266 ATH_MSG_ERROR("LAr DetCondKeyTrans ptr is null");
267 return StatusCode::FAILURE;
268 }
269
270 ATH_MSG_DEBUG(" LAr DetCondKeyTrans retrieved ");
271 if(m_alignHelper.applyAlignments(detStore(),align,nullptr).isFailure()) {
272 ATH_MSG_ERROR("Failed to apply LAr alignments to GeoModel");
273 return StatusCode::FAILURE;
274 }
275 ATH_MSG_DEBUG("LAr Alignments applied successfully");
276 }
277 else {
278 ATH_MSG_DEBUG(" No LAr DetCondKeyTrans in SG, skipping align() ");
279 }
280
281 return StatusCode::SUCCESS;
282}
283
#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...
#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
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.
static Double_t sc
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.
std::string m_EMECVariantOuter
virtual ~LArDetectorToolNV()
LArDetectorToolNV(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode create() override
virtual StatusCode clear() override
const LArDetectorManager * m_manager
LArAlignHelper m_alignHelper
std::string m_EMECVariantInner
std::string m_geometryConfig
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
::StatusCode StatusCode
StatusCode definition for legacy code.