ATLAS Offline Software
DatabaseAccessTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
16 public:
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 
51 {
52  delete m_cw;
53 }
54 
55 double DatabaseAccessTool::getDouble(const std::string & TableName,
56  const std::string & FallbackVersion,
57  const std::string & ColumnName) const {
58 
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]=rec;
71  }
72  return retval;
73 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
IRDBAccessSvc::getRecordsetPtr
virtual IRDBRecordset_ptr getRecordsetPtr(const std::string &node, const std::string &tag, const std::string &tag2node="", const std::string &connName="ATLASDD")=0
Provides access to the Recordset object containing HVS-tagged data.
DatabaseAccessTool::getDouble
double getDouble(const std::string &TableName, const std::string &FallbackVersion, const std::string &ColumnName) const
Definition: DatabaseAccessTool.cxx:55
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
DatabaseAccessTool::Clockwork::recMap
std::map< std::string, IRDBRecordset_ptr > recMap
Definition: DatabaseAccessTool.cxx:21
LArCellBinning_test.retval
def retval
Definition: LArCellBinning_test.py:112
DatabaseAccessTool::Clockwork::detectorKey
std::string detectorKey
Definition: DatabaseAccessTool.cxx:19
EventInfoWrite.AtlasVersion
AtlasVersion
Definition: EventInfoWrite.py:17
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
DatabaseAccessTool::Clockwork::detectorNode
std::string detectorNode
Definition: DatabaseAccessTool.cxx:20
IRDBAccessSvc
IRDBAccessSvc is an abstract interface to the athena service that provides the following functionalit...
Definition: IRDBAccessSvc.h:42
DatabaseAccessTool::DatabaseAccessTool
DatabaseAccessTool()
Definition: DatabaseAccessTool.cxx:25
DatabaseAccessTool::Clockwork::pAccessSvc
IRDBAccessSvc * pAccessSvc
Definition: DatabaseAccessTool.cxx:18
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
DatabaseAccessTool.h
DatabaseAccessTool::~DatabaseAccessTool
~DatabaseAccessTool()
Definition: DatabaseAccessTool.cxx:50
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
DatabaseAccessTool::Clockwork
Definition: DatabaseAccessTool.cxx:14
DatabaseAccessTool::m_cw
Clockwork * m_cw
Definition: DatabaseAccessTool.h:40
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
IGeoModelSvc.h
python.SystemOfUnits.m
float m
Definition: SystemOfUnits.py:106