ATLAS Offline Software
DetDescrDBEnvelopeSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // DetDescrDBEnvelopeSvc.cxx, (c) ATLAS Detector software
8 
9 // class header include
10 #include "DetDescrDBEnvelopeSvc.h"
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 
31 DetDescrDBEnvelopeSvc::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),
40  m_fallbackR(),
41  m_fallbackZ()
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 );
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++) {
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 
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.push_back( RZPair(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.push_back( RZPair(curR, curZ) );
290  }
291 
292  return StatusCode::SUCCESS;
293 }
294 
295 
DetDescrDBEnvelopeSvc::m_fallbackZ
FallbackDoubleVector m_fallbackZ[AtlasDetDescr::fNumAtlasRegions]
Definition: DetDescrDBEnvelopeSvc.h:99
AtlasDetDescr::fNumAtlasRegions
@ fNumAtlasRegions
Definition: AtlasRegion.h:39
beamspotman.r
def r
Definition: beamspotman.py:676
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
AtlasDetDescr::fAtlasForward
@ fAtlasForward
Definition: AtlasRegion.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
RZPairVector
std::vector< RZPair > RZPairVector
Definition: RZPair.h:18
DetDescrDBEnvelopeSvc::m_doFallback
bool m_doFallback
Definition: DetDescrDBEnvelopeSvc.h:97
DetDescrDBEnvelopeSvc::DetDescrDBEnvelopeSvc
DetDescrDBEnvelopeSvc(const std::string &name, ISvcLocator *svc)
public AthService constructor
Definition: DetDescrDBEnvelopeSvc.cxx:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AtlasDetDescr::AtlasRegionHelper::getName
static const char * getName(int region)
Definition: AtlasRegionHelper.cxx:13
DetDescrDBEnvelopeSvc::m_allowFallback
bool m_allowFallback
fallback solution, in case something goes wrong with the DB
Definition: DetDescrDBEnvelopeSvc.h:96
RZPair
std::pair< double, double > RZPair
Definition: RZPair.h:15
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
DetDescrDBEnvelopeSvc::finalize
StatusCode finalize()
AthService finalize method.
Definition: DetDescrDBEnvelopeSvc.cxx:173
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AtlasDetDescr::fAtlasMS
@ fAtlasMS
Definition: AtlasRegion.h:36
z
#define z
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
DetDescrDBEnvelopeSvc::m_atlasNode
std::string m_atlasNode
main DDDB node for the ATLAS detector
Definition: DetDescrDBEnvelopeSvc.h:83
DetDescrDBEnvelopeSvc::fallbackRZBoundary
StatusCode fallbackRZBoundary(FallbackDoubleVector &r, FallbackDoubleVector &z, RZPairVector &rzVec)
use the fallback approach (python arguments) to set the (r,z) values
Definition: DetDescrDBEnvelopeSvc.cxx:269
DetDescrDBEnvelopeSvc.h
DetDescrDBEnvelopeSvc::initialize
StatusCode initialize()
AthService initialize method.
Definition: DetDescrDBEnvelopeSvc.cxx:91
AtlasRegionHelper.h
FallbackDoubleVector
std::vector< double > FallbackDoubleVector
datatype used for fallback solution
Definition: DetDescrDBEnvelopeSvc.h:30
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AtlasDetDescr::fAtlasCavern
@ fAtlasCavern
Definition: AtlasRegion.h:37
DetDescrDBEnvelopeSvc::retrieveRZBoundaryOptionalFallback
StatusCode retrieveRZBoundaryOptionalFallback(std::string &dbNode, FallbackDoubleVector &r, FallbackDoubleVector &z, RZPairVector &rzVec)
retrieve and store the (r,z) values locally for the given DB node.
Definition: DetDescrDBEnvelopeSvc.cxx:181
DetDescrDBEnvelopeSvc::m_geoModelSvc
ServiceHandle< IGeoModelSvc > m_geoModelSvc
ATLAS GeoModel.
Definition: DetDescrDBEnvelopeSvc.h:80
AtlasDetDescr::fAtlasID
@ fAtlasID
Definition: AtlasRegion.h:33
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
AtlasDetDescr::fAtlasCalo
@ fAtlasCalo
Definition: AtlasRegion.h:35
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DetDescrDBEnvelopeSvc::m_node
std::string m_node[AtlasDetDescr::fNumAtlasRegions]
the names of the DB nodes for the respective AtlasRegion
Definition: DetDescrDBEnvelopeSvc.h:87
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DetDescrDBEnvelopeSvc::m_atlasVersionTag
std::string m_atlasVersionTag
Definition: DetDescrDBEnvelopeSvc.h:84
DetDescrDBEnvelopeSvc::m_rz
RZPairVector m_rz[AtlasDetDescr::fNumAtlasRegions]
internal (r,z) representation, one RZPairVector for each AtlasRegion
Definition: DetDescrDBEnvelopeSvc.h:90
DetDescrDBEnvelopeSvc::retrieveRZBoundary
StatusCode retrieveRZBoundary(std::string &node, RZPairVector &rzVec)
retrieve and store the (r,z) values locally for the given DB node
Definition: DetDescrDBEnvelopeSvc.cxx:211
DetDescrDBEnvelopeSvc::m_fallbackR
FallbackDoubleVector m_fallbackR[AtlasDetDescr::fNumAtlasRegions]
Definition: DetDescrDBEnvelopeSvc.h:98
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
DetDescrDBEnvelopeSvc::m_dbAccess
ServiceHandle< IRDBAccessSvc > m_dbAccess
the DetectorDescription database access method
Definition: DetDescrDBEnvelopeSvc.h:77
IGeoModelSvc.h
m_node
const GeoVPhysVol * m_node
Definition: MdtTubeLayer.cxx:64
DetDescrDBEnvelopeSvc::m_rposz
RZPairVector m_rposz[AtlasDetDescr::fNumAtlasRegions]
internal (r,z) representation for the positive z-side only, one RZPairVector for each AtlasRegion
Definition: DetDescrDBEnvelopeSvc.h:93
IGeoDbTagSvc.h
node
Definition: memory_hooks-stdcmalloc.h:74
AtlasDetDescr::fFirstAtlasRegion
@ fFirstAtlasRegion
Definition: AtlasRegion.h:31
IRDBRecordset::const_iterator
RecordsVector::const_iterator const_iterator
Definition: IRDBRecordset.h:52
DetDescrDBEnvelopeSvc::~DetDescrDBEnvelopeSvc
~DetDescrDBEnvelopeSvc()
Destructor.
Definition: DetDescrDBEnvelopeSvc.cxx:65
ServiceHandle< IGeoDbTagSvc >
DetDescrDBEnvelopeSvc::enableFallback
bool enableFallback()
enable fallback solution:
Definition: DetDescrDBEnvelopeSvc.cxx:73