ATLAS Offline Software
Loading...
Searching...
No Matches
SqliteReadSvc Class Referencefinal

SqliteReadSvc implementats IRDBAccessSvc interface for reading plain tables in the Geometry SQLite database. More...

#include <SqliteReadSvc.h>

Inheritance diagram for SqliteReadSvc:
Collaboration diagram for SqliteReadSvc:

Public Member Functions

 SqliteReadSvc (const std::string &name, ISvcLocator *svc)
 Standard Service Constructor.
StatusCode finalize () override
bool connect (const std::string &connName) override
 Open the SQLite database This method has no effect if the connection has already been opened.
bool disconnect (const std::string &) override
 Dummy overrider of the virtual function.
bool shutdown (const std::string &) override
 Closes the database connection.
IRDBRecordset_ptr getRecordsetPtr (const std::string &node, const std::string &, const std::string &, const std::string &) override
 Provides access to the Recordset object containing HVS-tagged data.
std::string getChildTag (const std::string &childNode, const std::string &, const std::string &, const std::string &) override
 Dummy overrider of the virtual function.
std::unique_ptr< IRDBQuerygetQuery (const std::string &node, const std::string &, const std::string &, const std::string &) override
 Dummy overrider of the virtual function (for now)
void getTagDetails (RDBTagDetails &tagDetails, const std::string &tag, const std::string &) override
 Dummy overrider of the virtual function.

Private Attributes

RecordsetPtrMap m_recordsets
sqlite3 * m_db {nullptr}
std::mutex m_sessionMutex

Detailed Description

SqliteReadSvc implementats IRDBAccessSvc interface for reading plain tables in the Geometry SQLite database.

Definition at line 40 of file SqliteReadSvc.h.

Constructor & Destructor Documentation

◆ SqliteReadSvc()

SqliteReadSvc::SqliteReadSvc ( const std::string & name,
ISvcLocator * svc )

Standard Service Constructor.

Definition at line 19 of file SqliteReadSvc.cxx.

20 : base_class(name,svc)
21{
22}

Member Function Documentation

◆ connect()

bool SqliteReadSvc::connect ( const std::string & connName)
override

Open the SQLite database This method has no effect if the connection has already been opened.

Parameters
connName[IN] path to the SQLite database file
Returns
success/failure

Definition at line 32 of file SqliteReadSvc.cxx.

33{
34 std::lock_guard<std::mutex> guard(m_sessionMutex);
35 if(!m_db) {
36 int res = sqlite3_open(connName.c_str(), &m_db);
37 if (res != SQLITE_OK) {
38 ATH_MSG_FATAL("Failed to open " << connName << ". " << sqlite3_errmsg(m_db));
39 return false;
40 }
41 }
42 return true;
43}
#define ATH_MSG_FATAL(x)
std::pair< std::vector< unsigned int >, bool > res
sqlite3 * m_db
std::mutex m_sessionMutex

◆ disconnect()

bool SqliteReadSvc::disconnect ( const std::string & )
override

Dummy overrider of the virtual function.

Returns
success/failure

Definition at line 45 of file SqliteReadSvc.cxx.

46{
47 // Dummy implementation
48 return true;
49}

◆ finalize()

StatusCode SqliteReadSvc::finalize ( )
override

Definition at line 24 of file SqliteReadSvc.cxx.

25{
26 m_recordsets.clear();
27 shutdown("");
28
29 return StatusCode::SUCCESS;
30}
RecordsetPtrMap m_recordsets
bool shutdown(const std::string &) override
Closes the database connection.

◆ getChildTag()

std::string SqliteReadSvc::getChildTag ( const std::string & childNode,
const std::string & parentTag,
const std::string & parentNode,
const std::string &  )
override

Dummy overrider of the virtual function.

Parameters
childNode[IN] the name of the table
Returns
the name of the table if exists, otherwise an empty string

Definition at line 99 of file SqliteReadSvc.cxx.

103{
104 ATH_MSG_DEBUG("getChildTag for " << childNode << " " << parentTag << " " << parentNode);
105 ATH_MSG_WARNING("SqliteReadSvc::getChildTag is a dummy method");
106 return std::string();
107}
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)

◆ getQuery()

std::unique_ptr< IRDBQuery > SqliteReadSvc::getQuery ( const std::string & node,
const std::string & tag,
const std::string & tag2node,
const std::string & connName )
override

Dummy overrider of the virtual function (for now)

Definition at line 88 of file SqliteReadSvc.cxx.

92{
93 ATH_MSG_DEBUG("getQuery (" << node << "," << tag << "," << tag2node << "," << connName << ")");
94 ATH_MSG_WARNING("SqliteReadSvc::getQuery is a dummy method");
95
96 return std::unique_ptr<IRDBQuery>();
97}

◆ getRecordsetPtr()

IRDBRecordset_ptr SqliteReadSvc::getRecordsetPtr ( const std::string & node,
const std::string & ,
const std::string & ,
const std::string &  )
override

Provides access to the Recordset object containing HVS-tagged data.

Parameters
node[IN] name of the table. Other input parameters are dummy
Returns
pointer to the recordset object

Definition at line 62 of file SqliteReadSvc.cxx.

66{
67 ATH_MSG_DEBUG("Getting RecordsetPtr with key " << node);
68
69 std::lock_guard<std::mutex> guard(m_sessionMutex);
70 if(!m_db) {
71 ATH_MSG_ERROR("Connection to the SQLite database not open. Returning empty recordset");
72 return IRDBRecordset_ptr(new SqliteRecordset());
73 }
74
75 auto itRecordset = m_recordsets.find(node);
76 if(itRecordset!=m_recordsets.end()) {
77 ATH_MSG_DEBUG("Reusing an existing recordset");
78 return itRecordset->second;
79 }
80
81 SqliteRecordset* recConcrete = new SqliteRecordset();
82 recConcrete->getData(m_db,node);
83 IRDBRecordset_ptr rec(recConcrete);
84 m_recordsets.emplace(node,rec);
85 return rec;
86}
#define ATH_MSG_ERROR(x)
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
void getData(sqlite3 *db, const std::string &nodeName)
Constructs SQL query and retrieves data from the DB.

◆ getTagDetails()

void SqliteReadSvc::getTagDetails ( RDBTagDetails & tagDetails,
const std::string & tag,
const std::string &  )
override

Dummy overrider of the virtual function.

Definition at line 109 of file SqliteReadSvc.cxx.

112{
113 ATH_MSG_DEBUG("getTagDetails for tag: " << tag);
114 ATH_MSG_WARNING("SqliteReadSvc::getTagDetails is a dummy method");
115 return;
116}

◆ shutdown()

bool SqliteReadSvc::shutdown ( const std::string & )
override

Closes the database connection.

Returns
success/failure

Definition at line 51 of file SqliteReadSvc.cxx.

52{
53 std::lock_guard<std::mutex> guard(m_sessionMutex);
54 if(m_db) {
55 sqlite3_close(m_db);
56 m_db = nullptr;
57 }
58 return true;
59}

Member Data Documentation

◆ m_db

sqlite3* SqliteReadSvc::m_db {nullptr}
private

Definition at line 91 of file SqliteReadSvc.h.

91{nullptr};

◆ m_recordsets

RecordsetPtrMap SqliteReadSvc::m_recordsets
private

Definition at line 90 of file SqliteReadSvc.h.

◆ m_sessionMutex

std::mutex SqliteReadSvc::m_sessionMutex
private

Definition at line 92 of file SqliteReadSvc.h.


The documentation for this class was generated from the following files: