ATLAS Offline Software
Loading...
Searching...
No Matches
DetDescrDBEnvelopeSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// DetDescrDBEnvelopeSvc.cxx, (c) ATLAS Detector software
8
9// class header include
11
12// framework includes
13#include "GaudiKernel/Bootstrap.h"
14#include "GaudiKernel/ISvcLocator.h"
15
16// CLHEP includes
17#include "CLHEP/Units/SystemOfUnits.h"
18
19// Database includes
22
23// AtlasDetDescr
25
26// GeoModel
29
31DetDescrDBEnvelopeSvc::DetDescrDBEnvelopeSvc(const std::string& name, ISvcLocator* svc) :
32 base_class(name,svc),
33 m_atlasNode("ATLAS"),
34 m_atlasVersionTag("AUTO"),
35 m_node(),
36 m_rz(),
37 m_rposz(),
38 m_allowFallback(false),
39 m_doFallback(false),
42{
43 declareProperty( "DBBeamPipeNode" , m_node[AtlasDetDescr::fAtlasForward]="BeamPipeEnvelope" );
44 declareProperty( "DBInDetNode" , m_node[AtlasDetDescr::fAtlasID]="InDetEnvelope" );
45 declareProperty( "DBCaloNode" , m_node[AtlasDetDescr::fAtlasCalo]="CaloEnvelope" );
46 declareProperty( "DBMSNode" , m_node[AtlasDetDescr::fAtlasMS]="MuonEnvelope" );
47 declareProperty( "DBCavernNode" , m_node[AtlasDetDescr::fAtlasCavern]="CavernEnvelope" );
48
49 // in case something goes wrong with the DB, the user can define
50 // fallback RZ values
51 declareProperty( "EnableFallback" , m_allowFallback );
52 declareProperty( "FallbackBeamPipeR" , m_fallbackR[AtlasDetDescr::fAtlasForward] );
53 declareProperty( "FallbackBeamPipeZ" , m_fallbackZ[AtlasDetDescr::fAtlasForward] );
54 declareProperty( "FallbackInDetR" , m_fallbackR[AtlasDetDescr::fAtlasID] );
55 declareProperty( "FallbackInDetZ" , m_fallbackZ[AtlasDetDescr::fAtlasID] );
56 declareProperty( "FallbackCaloR" , m_fallbackR[AtlasDetDescr::fAtlasCalo] );
57 declareProperty( "FallbackCaloZ" , m_fallbackZ[AtlasDetDescr::fAtlasCalo] );
58 declareProperty( "FallbackMuonR" , m_fallbackR[AtlasDetDescr::fAtlasMS] );
59 declareProperty( "FallbackMuonZ" , m_fallbackZ[AtlasDetDescr::fAtlasMS] );
60 declareProperty( "FallbackCavernR" , m_fallbackR[AtlasDetDescr::fAtlasCavern] );
61 declareProperty( "FallbackCavernZ" , m_fallbackZ[AtlasDetDescr::fAtlasCavern] );
62}
63
64
66{
67 // free memory
68 // TODO :)
69}
70
71
74{
75 // fallback solution is already enabled
76 if (m_doFallback) return true;
77
78 // fallback solution not enabled yet
79 if (m_allowFallback) {
80 ATH_MSG_INFO("Unable to retrieve envelope definitions from DDDB. Enabling Python-based fallback definitions.");
81 m_doFallback=true;
82 } else {
83 ATH_MSG_ERROR("Unable to retrieve envelope definitions from DDDB and Python-based fallback definitions are disabled.");
84 m_doFallback = false;
85 }
86
87 return m_doFallback;
88}
89
92{
93 ATH_MSG_INFO("Initializing ...");
94
95 // retrieve DataBase access service
96 ServiceHandle<IGeoDbTagSvc> geoDbTag("GeoDbTagSvc",name());
97 ATH_CHECK(geoDbTag.retrieve());
98
99 m_dbAccess.setName(geoDbTag->getParamSvcName());
100 if ( m_dbAccess.retrieve().isFailure()) {
101 ATH_MSG_ERROR("Could not locate RDBAccessSvc");
102 if ( !enableFallback()) return StatusCode::FAILURE;
103 }
104
105 // retrieve the GeoModelSvc
106 if ( !m_doFallback && (m_geoModelSvc.retrieve().isFailure()) ) {
107 ATH_MSG_ERROR("Could not locate GeoModelSvc");
108 if ( !enableFallback()) return StatusCode::FAILURE;
109 }
110
111
112 // (#) use the DB to retrieve the RZ values
113 if ( !m_doFallback) {
114 // geo model tag
115 m_atlasVersionTag = m_geoModelSvc->atlasVersion();
116 if( m_atlasVersionTag == "AUTO") m_atlasVersionTag = "ATLAS-00";
117
118 // cache the volume definitions locally
119 for ( int region = AtlasDetDescr::fFirstAtlasRegion; region < AtlasDetDescr::fNumAtlasRegions; region++) {
120 StatusCode sc = retrieveRZBoundaryOptionalFallback( m_node[region],
121 m_fallbackR[region],
122 m_fallbackZ[region],
123 m_rposz[region] );
124
125 if (sc.isFailure()) {
126 ATH_MSG_ERROR("Unable to retrieve subdetector envelope for detector region '" <<
128 return StatusCode::FAILURE;
129 }
130 }
131
132 }
133
134 // (#) or use the fallback solution right away
135 else {
136 // cache the volume definitions locally
137 for ( int region = AtlasDetDescr::fFirstAtlasRegion; region < AtlasDetDescr::fNumAtlasRegions; region++) {
138 StatusCode sc = fallbackRZBoundary( m_fallbackR[region], m_fallbackZ[region], m_rposz[region] );
139
140 if (sc.isFailure()) {
141 ATH_MSG_ERROR("Unable to retrieve sub-detector envelope in (r,z)-space for detector region '" <<
143 return StatusCode::FAILURE;
144 }
145 }
146 }
147
148 // mirror the RZPairs provided in m_rposz to describe all corner points
149 // in (r,z) space for each envelope volume
150 for ( int region = AtlasDetDescr::fFirstAtlasRegion; region < AtlasDetDescr::fNumAtlasRegions; region++) {
151 ATH_MSG_VERBOSE( "Envelope: positive-z region=" << region);
152 mirrorRZ( m_rposz[region], m_rz[region] );
153 }
154
155 // debugging output:
156 if (msgLvl(MSG::VERBOSE)) {
157 for ( int region = AtlasDetDescr::fFirstAtlasRegion; region < AtlasDetDescr::fNumAtlasRegions; region++) {
158 int numEntries = m_rz[region].size();
159 ATH_MSG_VERBOSE( "Envelope: complete region=" << region);
160 for ( int num = 0; num<numEntries; num++) {
161 ATH_MSG_VERBOSE(" pos=" << num << " r=" << m_rz[region][num].first << " z="<< m_rz[region][num].second);
162 }
163 }
164 }
165
166 ATH_MSG_INFO("Initialize successful.");
167
168 return StatusCode::SUCCESS;
169}
170
171
174{
175 return StatusCode::SUCCESS;
176}
177
184 RZPairVector &rzVec)
185{
186 // clear the output RZPairVector
187 rzVec.clear();
188
189 // try the DB approach to retrieve the (r,z) values
190 StatusCode sc = retrieveRZBoundary(dbNode, rzVec);
191
192 // if empty vector returned -> unsuccessfully read DDDB
193 if (sc.isFailure()) {
194 ATH_MSG_DEBUG("Will try reading Python-based envelope definition for '" << dbNode << "'.");
195
196 // try fallback approach
197 sc = enableFallback() ? fallbackRZBoundary(r, z, rzVec) : StatusCode::FAILURE;
198 if (sc.isFailure()) {
199 ATH_MSG_WARNING("Could not create envelope volume for '" << dbNode << "'.");
200 return StatusCode::FAILURE;
201 } else {
202 ATH_MSG_INFO("Sucessfully read Python-based envelope definition for '" << dbNode << "'.");
203 }
204 }
205
206 return StatusCode::SUCCESS;
207}
208
209
212 RZPairVector &rzVec)
213{
214 // clear the output RZPairVector
215 rzVec.clear();
216
217 // @TODO: implement checks and do output with the actual child tags taken
218 // some output about the used tags
219 //const std::string &detVersionTag = m_dbAccess->getChildTag( detNode /* child node */,
220 // m_atlasVersionTag /* parent tag */,
221 // m_atlasNode /* parent node */,
222 // false /*don't fetch data*/ );
223 //const std::string &parentVersionTag = m_dbAccess->getChildTag( parentNode,
224 // detVersionTag,
225 // detNode,
226 // false);
227 //const std::string &envVersionTag = m_dbAccess->getChildTag( envNode,
228 // parentVersionTag,
229 // parentNode,
230 // false );
231 //ATH_MSG_INFO( "DDDB tags used for envelope construction: "
232 // << m_atlasVersionTag << " / " << detVersionTag << " / "
233 // << parentVersionTag << " / " << envVersionTag );
234
235 // get a handle on the DB entries (don't delete, handeled internally)
236 IRDBRecordset_ptr envelopeRec = m_dbAccess->getRecordsetPtr( node,
238 m_atlasNode );
239
243
244
245 // entries in the database table
246 size_t numEntries = envelopeRec ? envelopeRec->size() : 0;
247 if ( !numEntries) {
248 ATH_MSG_INFO("No entries for table '" << node << "' in Detector Description Database (DDDB). Maybe you are using Python-based envelope definitions...");
249 return StatusCode::RECOVERABLE;
250 }
251
252 // retrieve data from the DB
253 IRDBRecordset::const_iterator recIt = envelopeRec->begin();
254 IRDBRecordset::const_iterator recEnd = envelopeRec->end();
255 for ( ; recIt!=recEnd; ++recIt) {
256
257 // read-in (r,z) duplet
258 double curR = (*recIt)->getDouble("R") * CLHEP::mm;
259 double curZ = (*recIt)->getDouble("Z") * CLHEP::mm;
260 // store (r,z) duplet locally
261 rzVec.emplace_back(curR, curZ );
262 }
263
264 return StatusCode::SUCCESS;
265}
266
267
271 RZPairVector &rzVec)
272{
273 unsigned short len = r.size();
274
275 // r and z vectors must have same length
276 if ( len != z.size() ) {
277 ATH_MSG_ERROR("Unable to construct fallback envelope definition in (r,z) space, as the provided r and z vectors have different length");
278 rzVec.clear();
279 return StatusCode::FAILURE;
280 }
281
282 // loop over the given pairs of (r,z) values
283 for ( unsigned short pos=0; pos<len; ++pos) {
284
285 // read-in (r,z) duplet
286 double curR = r[pos];
287 double curZ = z[pos];
288 // store (r,z) duplet locally
289 rzVec.emplace_back(curR, curZ );
290 }
291
292 return StatusCode::SUCCESS;
293}
294
295
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< double > FallbackDoubleVector
datatype used for fallback solution
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
static Double_t sc
std::vector< RZPair > RZPairVector
Definition RZPair.h:18
#define z
static const char * getName(int region)
bool enableFallback()
enable fallback solution:
DetDescrDBEnvelopeSvc(const std::string &name, ISvcLocator *svc)
public AthService constructor
ServiceHandle< IGeoModelSvc > m_geoModelSvc
ATLAS GeoModel.
StatusCode fallbackRZBoundary(FallbackDoubleVector &r, FallbackDoubleVector &z, RZPairVector &rzVec)
use the fallback approach (python arguments) to set the (r,z) values
StatusCode finalize()
AthService finalize method.
StatusCode retrieveRZBoundaryOptionalFallback(std::string &dbNode, FallbackDoubleVector &r, FallbackDoubleVector &z, RZPairVector &rzVec)
retrieve and store the (r,z) values locally for the given DB node.
bool m_allowFallback
fallback solution, in case something goes wrong with the DB
StatusCode initialize()
AthService initialize method.
std::string m_node[AtlasDetDescr::fNumAtlasRegions]
the names of the DB nodes for the respective AtlasRegion
FallbackDoubleVector m_fallbackR[AtlasDetDescr::fNumAtlasRegions]
ServiceHandle< IRDBAccessSvc > m_dbAccess
the DetectorDescription database access method
RZPairVector m_rposz[AtlasDetDescr::fNumAtlasRegions]
internal (r,z) representation for the positive z-side only, one RZPairVector for each AtlasRegion
StatusCode retrieveRZBoundary(std::string &node, RZPairVector &rzVec)
retrieve and store the (r,z) values locally for the given DB node
std::string m_atlasNode
main DDDB node for the ATLAS detector
FallbackDoubleVector m_fallbackZ[AtlasDetDescr::fNumAtlasRegions]
RZPairVector m_rz[AtlasDetDescr::fNumAtlasRegions]
internal (r,z) representation, one RZPairVector for each AtlasRegion
RecordsVector::const_iterator const_iterator
virtual const_iterator begin() const =0
virtual const_iterator end() const =0
virtual unsigned int size() const =0
Definition node.h:24
int r
Definition globals.cxx:22