ATLAS Offline Software
Loading...
Searching...
No Matches
DetDescrDBEnvelopeSvc.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// class header include
7
8// framework includes
9#include "GaudiKernel/Bootstrap.h"
10#include "GaudiKernel/ISvcLocator.h"
11
12// CLHEP includes
13#include "CLHEP/Units/SystemOfUnits.h"
14
15// Database includes
18
19// AtlasDetDescr
21
22// GeoModel
24
26DetDescrDBEnvelopeSvc::DetDescrDBEnvelopeSvc(const std::string& name, ISvcLocator* svc) :
27 base_class(name,svc)
28{
29}
30
32
35{
36 // fallback solution is already enabled
37 if (m_doFallback) return true;
38
39 // fallback solution not enabled yet
40 if (m_allowFallback) {
41 ATH_MSG_INFO("Unable to retrieve envelope definitions from DDDB. Enabling Python-based fallback definitions.");
42 m_doFallback=true;
43 } else {
44 ATH_MSG_ERROR("Unable to retrieve envelope definitions from DDDB and Python-based fallback definitions are disabled.");
45 m_doFallback = false;
46 }
47
48 return m_doFallback;
49}
50
53{
54 ATH_MSG_INFO("Initializing ...");
55
56 // retrieve DataBase access service
57 ServiceHandle<IGeoDbTagSvc> geoDbTag("GeoDbTagSvc",name());
58 ATH_CHECK(geoDbTag.retrieve());
59
60 m_dbAccess.setName(geoDbTag->getParamSvcName());
61 if ( m_dbAccess.retrieve().isFailure()) {
62 ATH_MSG_ERROR("Could not locate RDBAccessSvc");
63 if ( !enableFallback()) return StatusCode::FAILURE;
64 }
65
66 // retrieve the GeoModelSvc
67 if ( !m_doFallback && (m_geoModelSvc.retrieve().isFailure()) ) {
68 ATH_MSG_ERROR("Could not locate GeoModelSvc");
69 if ( !enableFallback()) return StatusCode::FAILURE;
70 }
71
72
73 // (#) use the DB to retrieve the RZ values
74 if ( !m_doFallback) {
75 // geo model tag
76 m_atlasVersionTag = m_geoModelSvc->atlasVersion();
77 if( m_atlasVersionTag == "AUTO") m_atlasVersionTag = "ATLAS-00";
78
79 // cache the volume definitions locally
80 for ( int region = AtlasDetDescr::fFirstAtlasRegion; region < AtlasDetDescr::fNumAtlasRegions; region++) {
81 StatusCode sc = retrieveRZBoundaryOptionalFallback( m_node[region].value(),
82 m_fallbackR[region].value(),
83 m_fallbackZ[region].value(),
84 m_rposz[region] );
85
86 if (sc.isFailure()) {
87 ATH_MSG_ERROR("Unable to retrieve subdetector envelope for detector region '" <<
89 return StatusCode::FAILURE;
90 }
91 }
92
93 }
94
95 // (#) or use the fallback solution right away
96 else {
97 // cache the volume definitions locally
98 for ( int region = AtlasDetDescr::fFirstAtlasRegion; region < AtlasDetDescr::fNumAtlasRegions; region++) {
99 StatusCode sc = fallbackRZBoundary( m_fallbackR[region].value(), m_fallbackZ[region].value(), m_rposz[region] );
100
101 if (sc.isFailure()) {
102 ATH_MSG_ERROR("Unable to retrieve sub-detector envelope in (r,z)-space for detector region '" <<
104 return StatusCode::FAILURE;
105 }
106 }
107 }
108
109 // mirror the RZPairs provided in m_rposz to describe all corner points
110 // in (r,z) space for each envelope volume
111 for ( int region = AtlasDetDescr::fFirstAtlasRegion; region < AtlasDetDescr::fNumAtlasRegions; region++) {
112 ATH_MSG_VERBOSE( "Envelope: positive-z region=" << region);
113 mirrorRZ( m_rposz[region], m_rz[region] );
114 }
115
116 // debugging output:
117 if (msgLvl(MSG::VERBOSE)) {
118 for ( int region = AtlasDetDescr::fFirstAtlasRegion; region < AtlasDetDescr::fNumAtlasRegions; region++) {
119 int numEntries = m_rz[region].size();
120 ATH_MSG_VERBOSE( "Envelope: complete region=" << region);
121 for ( int num = 0; num<numEntries; num++) {
122 ATH_MSG_VERBOSE(" pos=" << num << " r=" << m_rz[region][num].first << " z="<< m_rz[region][num].second);
123 }
124 }
125 }
126
127 ATH_MSG_INFO("Initialize successful.");
128
129 return StatusCode::SUCCESS;
130}
131
136 const FallbackDoubleVector &r,
137 const FallbackDoubleVector &z,
138 RZPairVector &rzVec)
139{
140 // clear the output RZPairVector
141 rzVec.clear();
142
143 // try the DB approach to retrieve the (r,z) values
144 StatusCode sc = retrieveRZBoundary(dbNode, rzVec);
145
146 // if empty vector returned -> unsuccessfully read DDDB
147 if (sc.isFailure()) {
148 ATH_MSG_DEBUG("Will try reading Python-based envelope definition for '" << dbNode << "'.");
149
150 // try fallback approach
151 sc = enableFallback() ? fallbackRZBoundary(r, z, rzVec) : StatusCode::FAILURE;
152 if (sc.isFailure()) {
153 ATH_MSG_WARNING("Could not create envelope volume for '" << dbNode << "'.");
154 return StatusCode::FAILURE;
155 } else {
156 ATH_MSG_INFO("Sucessfully read Python-based envelope definition for '" << dbNode << "'.");
157 }
158 }
159
160 return StatusCode::SUCCESS;
161}
162
163
165StatusCode DetDescrDBEnvelopeSvc::retrieveRZBoundary( const std::string &node,
166 RZPairVector &rzVec)
167{
168 // clear the output RZPairVector
169 rzVec.clear();
170
171 // @TODO: implement checks and do output with the actual child tags taken
172 // some output about the used tags
173 //const std::string &detVersionTag = m_dbAccess->getChildTag( detNode /* child node */,
174 // m_atlasVersionTag /* parent tag */,
175 // m_atlasNode /* parent node */,
176 // false /*don't fetch data*/ );
177 //const std::string &parentVersionTag = m_dbAccess->getChildTag( parentNode,
178 // detVersionTag,
179 // detNode,
180 // false);
181 //const std::string &envVersionTag = m_dbAccess->getChildTag( envNode,
182 // parentVersionTag,
183 // parentNode,
184 // false );
185 //ATH_MSG_INFO( "DDDB tags used for envelope construction: "
186 // << m_atlasVersionTag << " / " << detVersionTag << " / "
187 // << parentVersionTag << " / " << envVersionTag );
188
189 // get a handle on the DB entries (don't delete, handeled internally)
190 IRDBRecordset_ptr envelopeRec = m_dbAccess->getRecordsetPtr( node,
192 m_atlasNode );
193
197
198
199 // entries in the database table
200 size_t numEntries = envelopeRec ? envelopeRec->size() : 0;
201 if ( !numEntries) {
202 ATH_MSG_INFO("No entries for table '" << node << "' in Detector Description Database (DDDB). Maybe you are using Python-based envelope definitions...");
203 return StatusCode::RECOVERABLE;
204 }
205
206 // retrieve data from the DB
207 IRDBRecordset::const_iterator recIt = envelopeRec->begin();
208 IRDBRecordset::const_iterator recEnd = envelopeRec->end();
209 for ( ; recIt!=recEnd; ++recIt) {
210
211 // read-in (r,z) duplet
212 double curR = (*recIt)->getDouble("R") * CLHEP::mm;
213 double curZ = (*recIt)->getDouble("Z") * CLHEP::mm;
214 // store (r,z) duplet locally
215 rzVec.emplace_back(curR, curZ );
216 }
217
218 return StatusCode::SUCCESS;
219}
220
221
224 const FallbackDoubleVector &z,
225 RZPairVector &rzVec)
226{
227 unsigned short len = r.size();
228
229 // r and z vectors must have same length
230 if ( len != z.size() ) {
231 ATH_MSG_ERROR("Unable to construct fallback envelope definition in (r,z) space, as the provided r and z vectors have different length");
232 rzVec.clear();
233 return StatusCode::FAILURE;
234 }
235
236 // loop over the given pairs of (r,z) values
237 for ( unsigned short pos=0; pos<len; ++pos) {
238
239 // read-in (r,z) duplet
240 double curR = r[pos];
241 double curZ = z[pos];
242 // store (r,z) duplet locally
243 rzVec.emplace_back(curR, curZ );
244 }
245
246 return StatusCode::SUCCESS;
247}
248
249
#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)
~DetDescrDBEnvelopeSvc()
Destructor.
bool enableFallback()
enable fallback solution:
std::array< DoubleArrayProperty, AtlasDetDescr::fNumAtlasRegions > m_fallbackR
DetDescrDBEnvelopeSvc(const std::string &name, ISvcLocator *svc)
public AthService constructor
ServiceHandle< IGeoModelSvc > m_geoModelSvc
ATLAS GeoModel.
std::array< StringProperty, AtlasDetDescr::fNumAtlasRegions > m_node
the names of the DB nodes for the respective AtlasRegion
virtual StatusCode initialize() override
AthService initialize method.
StatusCode fallbackRZBoundary(const FallbackDoubleVector &r, const FallbackDoubleVector &z, RZPairVector &rzVec)
use the fallback approach (python arguments) to set the (r,z) values
StatusCode retrieveRZBoundaryOptionalFallback(const std::string &dbNode, const FallbackDoubleVector &r, const FallbackDoubleVector &z, RZPairVector &rzVec)
retrieve and store the (r,z) values locally for the given DB node.
StatusCode retrieveRZBoundary(const std::string &node, RZPairVector &rzVec)
retrieve and store the (r,z) values locally for the given DB node
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
std::string m_atlasNode
main DDDB node for the ATLAS detector
RZPairVector m_rz[AtlasDetDescr::fNumAtlasRegions]
internal (r,z) representation, one RZPairVector for each AtlasRegion
std::array< DoubleArrayProperty, AtlasDetDescr::fNumAtlasRegions > m_fallbackZ
Gaudi::Property< bool > m_allowFallback
fallback solution, in case something goes wrong with the DB
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