ATLAS Offline Software
Loading...
Searching...
No Matches
SqliteReadSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
12
13#include "SqliteReadSvc.h"
14#include "SqliteRecordset.h"
15#include <sqlite3.h>
16
17#include "RDBQuery.h"
18
19SqliteReadSvc::SqliteReadSvc(const std::string& name, ISvcLocator* svc)
20 : base_class(name,svc)
21{
22}
23
25{
26 m_recordsets.clear();
27 shutdown("");
28
29 return StatusCode::SUCCESS;
30}
31
32bool SqliteReadSvc::connect(std::string_view connName)
33{
34 std::lock_guard<std::mutex> guard(m_sessionMutex);
35 const std::string connNameStr{connName};
36 if(!m_db) {
37 int res = sqlite3_open(connNameStr.c_str(), &m_db);
38 if (res != SQLITE_OK) {
39 ATH_MSG_FATAL("Failed to open " << connName << ". " << sqlite3_errmsg(m_db));
40 return false;
41 }
42 }
43 return true;
44}
45
46bool SqliteReadSvc::disconnect(std::string_view)
47{
48 // Dummy implementation
49 return true;
50}
51
52bool SqliteReadSvc::shutdown(std::string_view)
53{
54 std::lock_guard<std::mutex> guard(m_sessionMutex);
55 if(m_db) {
56 sqlite3_close(m_db);
57 m_db = nullptr;
58 }
59 return true;
60}
61
62
64 , std::string_view
65 , std::string_view
66 , std::string_view )
67{
68 ATH_MSG_DEBUG("Getting RecordsetPtr with key " << node);
69
70 std::lock_guard<std::mutex> guard(m_sessionMutex);
71 if(!m_db) {
72 ATH_MSG_ERROR("Connection to the SQLite database not open. Returning empty recordset");
74 }
75
76 auto itRecordset = m_recordsets.find(node);
77 if(itRecordset!=m_recordsets.end()) {
78 ATH_MSG_DEBUG("Reusing an existing recordset");
79 return itRecordset->second;
80 }
81 const std::string nodeStr{node};
82 SqliteRecordset* recConcrete = new SqliteRecordset();
83 recConcrete->getData(m_db,nodeStr);
84 IRDBRecordset_ptr rec(recConcrete);
85 m_recordsets.emplace(nodeStr,rec);
86 return rec;
87}
88
89std::unique_ptr<IRDBQuery> SqliteReadSvc::getQuery(const std::string& node
90 , const std::string& tag
91 , const std::string& tag2node
92 , const std::string& connName)
93{
94 ATH_MSG_DEBUG("getQuery (" << node << "," << tag << "," << tag2node << "," << connName << ")");
95 ATH_MSG_WARNING("SqliteReadSvc::getQuery is a dummy method");
96
97 return std::unique_ptr<IRDBQuery>();
98}
99
100std::string SqliteReadSvc::getChildTag(const std::string& childNode
101 , const std::string& parentTag
102 , const std::string& parentNode
103 , const std::string& )
104{
105 ATH_MSG_DEBUG("getChildTag for " << childNode << " " << parentTag << " " << parentNode);
106 ATH_MSG_WARNING("SqliteReadSvc::getChildTag is a dummy method");
107 return std::string();
108}
109
111 , const std::string& tag
112 , const std::string& )
113{
114 ATH_MSG_DEBUG("getTagDetails for tag: " << tag);
115 ATH_MSG_WARNING("SqliteReadSvc::getTagDetails is a dummy method");
116 return;
117}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
coral::AttributeList RDBTagDetails
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
std::pair< std::vector< unsigned int >, bool > res
Declaration of SqliteReadSvc class.
Declaration of the SqliteRecordset class.
std::string getChildTag(const std::string &childNode, const std::string &, const std::string &, const std::string &) override
Dummy overrider of the virtual function.
RecordsetPtrMap m_recordsets
bool connect(std::string_view connName) override
Open the SQLite database This method has no effect if the connection has already been opened.
SqliteReadSvc(const std::string &name, ISvcLocator *svc)
Standard Service Constructor.
StatusCode finalize() override
bool shutdown(std::string_view connName) override
Closes the database connection.
IRDBRecordset_ptr getRecordsetPtr(std::string_view node, std::string_view tag, std::string_view tag2node, std::string_view connName) override
Provides access to the Recordset object containing HVS-tagged data.
sqlite3 * m_db
std::mutex m_sessionMutex
void getTagDetails(RDBTagDetails &tagDetails, const std::string &tag, const std::string &) override
Dummy overrider of the virtual function.
bool disconnect(std::string_view connName) override
Dummy overrider of the virtual function.
std::unique_ptr< IRDBQuery > getQuery(const std::string &node, const std::string &, const std::string &, const std::string &) override
Dummy overrider of the virtual function (for now).
SqliteRecordset implements IRDBRecordset interface.
void getData(sqlite3 *db, const std::string &nodeName)
Constructs SQL query and retrieves data from the DB.
Definition node.h:24