ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
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. More...
 
StatusCode finalize () override
 
StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface) override
 
bool connect (const std::string &connName) override
 Open the SQLite database This method has no effect if the connection has already been opened. More...
 
bool disconnect (const std::string &) override
 Dummy overrider of the virtual function. More...
 
bool shutdown (const std::string &) override
 Closes the database connection. More...
 
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. More...
 
std::string getChildTag (const std::string &childNode, const std::string &, const std::string &, const std::string &) override
 Dummy overrider of the virtual function. More...
 
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) More...
 
void getTagDetails (RDBTagDetails &tagDetails, const std::string &tag, const std::string &) override
 Dummy overrider of the virtual function. More...
 
MsgStream & msg () const
 
MsgStream & msg (const MSG::Level lvl) const
 
bool msgLvl (const MSG::Level lvl) const
 

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Retrieve interface ID. More...
 

Private Attributes

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

Friends

class SvcFactory< SqliteReadSvc >
 

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.

21 {
22 }

Member Function Documentation

◆ connect()

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

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

Implements IRDBAccessSvc.

Definition at line 45 of file SqliteReadSvc.cxx.

46 {
47  std::lock_guard<std::mutex> guard(m_sessionMutex);
48  if(!m_db) {
49  int res = sqlite3_open(connName.c_str(), &m_db);
50  if (res != SQLITE_OK) {
51  ATH_MSG_FATAL("Failed to open " << connName << ". " << sqlite3_errmsg(m_db));
52  return false;
53  }
54  }
55  return true;
56 }

◆ disconnect()

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

Dummy overrider of the virtual function.

Returns
success/failure

Implements IRDBAccessSvc.

Definition at line 58 of file SqliteReadSvc.cxx.

59 {
60  // Dummy implementation
61  return true;
62 }

◆ 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 }

◆ getChildTag()

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

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

Implements IRDBAccessSvc.

Definition at line 112 of file SqliteReadSvc.cxx.

116 {
117  ATH_MSG_DEBUG("getChildTag for " << childNode << " " << parentTag << " " << parentNode);
118  ATH_MSG_WARNING("SqliteReadSvc::getChildTag is a dummy method");
119  return std::string();
120 }

◆ getQuery()

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

Dummy overrider of the virtual function (for now)

Implements IRDBAccessSvc.

Definition at line 101 of file SqliteReadSvc.cxx.

105 {
106  ATH_MSG_DEBUG("getQuery (" << node << "," << tag << "," << tag2node << "," << connName << ")");
107  ATH_MSG_WARNING("SqliteReadSvc::getQuery is a dummy method");
108 
109  return std::unique_ptr<IRDBQuery>();
110 }

◆ getRecordsetPtr()

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

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

Implements IRDBAccessSvc.

Definition at line 75 of file SqliteReadSvc.cxx.

79 {
80  ATH_MSG_DEBUG("Getting RecordsetPtr with key " << node);
81 
82  std::lock_guard<std::mutex> guard(m_recordsetMutex);
83  if(!m_db) {
84  ATH_MSG_ERROR("Connection to the SQLite database not open. Returning empty recordset");
85  return IRDBRecordset_ptr(new SqliteRecordset());
86  }
87 
88  auto itRecordset = m_recordsets.find(node);
89  if(itRecordset!=m_recordsets.end()) {
90  ATH_MSG_DEBUG("Reusing an existing recordset");
91  return itRecordset->second;
92  }
93 
94  SqliteRecordset* recConcrete = new SqliteRecordset();
95  recConcrete->getData(m_db,node);
96  IRDBRecordset_ptr rec(recConcrete);
97  m_recordsets.emplace(node,rec);
98  return rec;
99 }

◆ getTagDetails()

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

Dummy overrider of the virtual function.

Implements IRDBAccessSvc.

Definition at line 122 of file SqliteReadSvc.cxx.

125 {
126  ATH_MSG_DEBUG("getTagDetails for tag: " << tag);
127  ATH_MSG_WARNING("SqliteReadSvc::getTagDetails is a dummy method");
128  return;
129 }

◆ interfaceID()

static const InterfaceID& SqliteReadSvc::interfaceID ( )
inlinestatic

Retrieve interface ID.

Definition at line 52 of file SqliteReadSvc.h.

52 { return IID_IRDBAccessSvc; }

◆ msg() [1/2]

MsgStream& AthCommonMsg< Service >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24  {
25  return this->msgStream();
26  }

◆ msg() [2/2]

MsgStream& AthCommonMsg< Service >::msg ( const MSG::Level  lvl) const
inlineinherited

Definition at line 27 of file AthCommonMsg.h.

27  {
28  return this->msgStream(lvl);
29  }

◆ msgLvl()

bool AthCommonMsg< Service >::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30  {
31  return this->msgLevel(lvl);
32  }

◆ queryInterface()

StatusCode SqliteReadSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvInterface 
)
override

Definition at line 32 of file SqliteReadSvc.cxx.

33 {
34  if (IID_IRDBAccessSvc == riid) {
35  *ppvInterface = (IRDBAccessSvc*)this;
36  }
37  else {
38  return AthService::queryInterface(riid, ppvInterface);
39  }
40 
41  addRef();
42  return StatusCode::SUCCESS;
43 }

◆ shutdown()

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

Closes the database connection.

Returns
success/failure

Implements IRDBAccessSvc.

Definition at line 64 of file SqliteReadSvc.cxx.

65 {
66  std::lock_guard<std::mutex> guard(m_sessionMutex);
67  if(m_db) {
68  sqlite3_close(m_db);
69  m_db = nullptr;
70  }
71  return true;
72 }

Friends And Related Function Documentation

◆ SvcFactory< SqliteReadSvc >

friend class SvcFactory< SqliteReadSvc >
friend

Definition at line 47 of file SqliteReadSvc.h.

Member Data Documentation

◆ m_db

sqlite3* SqliteReadSvc::m_db {nullptr}
private

Definition at line 97 of file SqliteReadSvc.h.

◆ m_recordsetMutex

std::mutex SqliteReadSvc::m_recordsetMutex
private

Definition at line 98 of file SqliteReadSvc.h.

◆ m_recordsets

RecordsetPtrMap SqliteReadSvc::m_recordsets
private

Definition at line 96 of file SqliteReadSvc.h.

◆ m_sessionMutex

std::mutex SqliteReadSvc::m_sessionMutex
private

Definition at line 99 of file SqliteReadSvc.h.


The documentation for this class was generated from the following files:
AthService::AthService
AthService()
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SqliteReadSvc::m_db
sqlite3 * m_db
Definition: SqliteReadSvc.h:97
SqliteRecordset::getData
void getData(sqlite3 *db, const std::string &nodeName)
Constructs SQL query and retrieves data from the DB.
Definition: SqliteRecordset.cxx:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IRDBAccessSvc
IRDBAccessSvc is an abstract interface to the athena service that provides the following functionalit...
Definition: IRDBAccessSvc.h:45
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
SqliteReadSvc::m_recordsetMutex
std::mutex m_recordsetMutex
Definition: SqliteReadSvc.h:98
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
SqliteReadSvc::m_recordsets
RecordsetPtrMap m_recordsets
Definition: SqliteReadSvc.h:96
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SqliteRecordset
SqliteRecordset implements IRDBRecordset interface. It is a container of records read from an SQLite ...
Definition: SqliteRecordset.h:31
SqliteReadSvc::shutdown
bool shutdown(const std::string &) override
Closes the database connection.
Definition: SqliteReadSvc.cxx:64
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
node
Definition: memory_hooks-stdcmalloc.h:74
SqliteReadSvc::m_sessionMutex
std::mutex m_sessionMutex
Definition: SqliteReadSvc.h:99