ATLAS Offline Software
Loading...
Searching...
No Matches
DatabaseAccessTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include "GaudiKernel/ISvcLocator.h"
11#include "GaudiKernel/Bootstrap.h"
12#include <map>
13
15
16public:
17
19 std::string detectorKey;
20 std::string detectorNode;
21 std::map<std::string, IRDBRecordset_ptr> recMap;
22};
23
24
26 :m_cw(new Clockwork())
27{
28 ISvcLocator *svcLocator=Gaudi::svcLocator();
29 SmartIF<IGeoModelSvc> geoModel{svcLocator->service("GeoModelSvc")};
30 if (!geoModel.isValid()) {
31 throw std::runtime_error ("Cannot locate GeoModelSvc!!");
32 }
33
34 SmartIF<IRDBAccessSvc> rdbAccess{svcLocator->service("RDBAccessSvc")};
35 if(!rdbAccess.isValid()) {
36 throw std::runtime_error ("Cannot locate RDBAccessSvc!!");
37 }
38 m_cw->pAccessSvc = rdbAccess.get();
39
40 // Obtain the geometry version information:
41
42 std::string AtlasVersion = geoModel->atlasVersion();
43 std::string LArVersion = geoModel->LAr_VersionOverride();
44
45 m_cw->detectorKey = LArVersion.empty() ? AtlasVersion : LArVersion;
46 m_cw->detectorNode = LArVersion.empty() ? "ATLAS" : "LAr";
47
48}
49
54
55double DatabaseAccessTool::getDouble(const std::string & TableName,
56 const std::string & FallbackVersion,
57 const std::string & ColumnName) const {
58
59 std::map<std::string, IRDBRecordset_ptr>::iterator m=m_cw->recMap.find(TableName);
60
61 IRDBRecordset_ptr rec = (m==m_cw->recMap.end()) ? m_cw->pAccessSvc->getRecordsetPtr(TableName,m_cw->detectorKey,m_cw->detectorNode): (*m).second;
62 if (rec->size()==0) {
63 rec = m_cw->pAccessSvc->getRecordsetPtr(TableName,FallbackVersion);
64 if (rec->size()==0) {
65 throw std::runtime_error((std::string("Cannot find the Table: ") + TableName).c_str());
66 }
67 }
68 double retval = (*rec)[0]->getDouble(ColumnName);
69 if (m==m_cw->recMap.end()) {
70 m_cw->recMap[TableName]=std::move(rec);
71 }
72 return retval;
73}
Definition of the abstract IRDBAccessSvc interface.
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
std::map< std::string, IRDBRecordset_ptr > recMap
double getDouble(const std::string &TableName, const std::string &FallbackVersion, const std::string &ColumnName) const
IRDBAccessSvc is an abstract interface to the athena service that provides the following functionalit...
virtual unsigned int size() const =0