ATLAS Offline Software
DatabaseAccessTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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  IGeoModelSvc *geoModel;
29  ISvcLocator *svcLocator=Gaudi::svcLocator();
30  if (svcLocator->service ("GeoModelSvc",geoModel)!=StatusCode::SUCCESS) {
31  throw std::runtime_error ("Cannot locate GeoModelSvc!!");
32  }
33 
34  if (svcLocator->service("RDBAccessSvc",m_cw->pAccessSvc)!=StatusCode::SUCCESS) {
35  throw std::runtime_error ("Cannot locate RDBAccessSvc!!");
36  }
37 
38  // Obtain the geometry version information:
39 
40  std::string AtlasVersion = geoModel->atlasVersion();
41  std::string LArVersion = geoModel->LAr_VersionOverride();
42 
43  m_cw->detectorKey = LArVersion.empty() ? AtlasVersion : LArVersion;
44  m_cw->detectorNode = LArVersion.empty() ? "ATLAS" : "LAr";
45 
46 }
47 
49 {
50  delete m_cw;
51 }
52 
53 double DatabaseAccessTool::getDouble(const std::string & TableName,
54  const std::string & FallbackVersion,
55  const std::string & ColumnName) const {
56 
58 
59  IRDBRecordset_ptr rec = (m==m_cw->recMap.end()) ? m_cw->pAccessSvc->getRecordsetPtr(TableName,m_cw->detectorKey,m_cw->detectorNode): (*m).second;
60  if (rec->size()==0) {
61  rec = m_cw->pAccessSvc->getRecordsetPtr(TableName,FallbackVersion);
62  if (rec->size()==0) {
63  throw std::runtime_error((std::string("Cannot find the Table: ") + TableName).c_str());
64  }
65  }
66  double retval = (*rec)[0]->getDouble(ColumnName);
67  if (m==m_cw->recMap.end()) {
68  m_cw->recMap[TableName]=rec;
69  }
70  return retval;
71 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
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.
IGeoModelSvc
Definition: IGeoModelSvc.h:17
DatabaseAccessTool::getDouble
double getDouble(const std::string &TableName, const std::string &FallbackVersion, const std::string &ColumnName) const
Definition: DatabaseAccessTool.cxx:53
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
IGeoModelSvc::LAr_VersionOverride
virtual const std::string & LAr_VersionOverride() const =0
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:45
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:48
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::atlasVersion
virtual const std::string & atlasVersion() const =0
IGeoModelSvc.h