ATLAS Offline Software
SqliteReadSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
13 #include "SqliteReadSvc.h"
14 #include "SqliteRecordset.h"
15 #include <sqlite3.h>
16 
17 #include "RDBQuery.h"
18 
19 SqliteReadSvc::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 
32 bool SqliteReadSvc::connect(const std::string& connName)
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 }
44 
45 bool SqliteReadSvc::disconnect(const std::string&)
46 {
47  // Dummy implementation
48  return true;
49 }
50 
51 bool SqliteReadSvc::shutdown(const std::string&)
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 }
60 
61 
63  , const std::string&
64  , const std::string&
65  , const std::string& )
66 {
67  ATH_MSG_DEBUG("Getting RecordsetPtr with key " << node);
68 
69  std::lock_guard<std::mutex> guard(m_recordsetMutex);
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 }
87 
88 std::unique_ptr<IRDBQuery> SqliteReadSvc::getQuery(const std::string& node
89  , const std::string& tag
90  , const std::string& tag2node
91  , const std::string& connName)
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 }
98 
99 std::string SqliteReadSvc::getChildTag(const std::string& childNode
100  , const std::string& parentTag
101  , const std::string& parentNode
102  , const std::string& )
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 }
108 
110  , const std::string& tag
111  , const std::string& )
112 {
113  ATH_MSG_DEBUG("getTagDetails for tag: " << tag);
114  ATH_MSG_WARNING("SqliteReadSvc::getTagDetails is a dummy method");
115  return;
116 }
SqliteReadSvc::getChildTag
std::string getChildTag(const std::string &childNode, const std::string &, const std::string &, const std::string &) override
Dummy overrider of the virtual function.
Definition: SqliteReadSvc.cxx:99
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SqliteRecordset.h
Declaration of the SqliteRecordset class.
SqliteReadSvc::m_db
sqlite3 * m_db
Definition: SqliteReadSvc.h:91
SqliteReadSvc::getTagDetails
void getTagDetails(RDBTagDetails &tagDetails, const std::string &tag, const std::string &) override
Dummy overrider of the virtual function.
Definition: SqliteReadSvc.cxx:109
SqliteReadSvc.h
Declaration of SqliteReadSvc class.
SqliteRecordset::getData
void getData(sqlite3 *db, const std::string &nodeName)
Constructs SQL query and retrieves data from the DB.
Definition: SqliteRecordset.cxx:25
SqliteReadSvc::getRecordsetPtr
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.
Definition: SqliteReadSvc.cxx:62
SqliteReadSvc::SqliteReadSvc
SqliteReadSvc(const std::string &name, ISvcLocator *svc)
Standard Service Constructor.
Definition: SqliteReadSvc.cxx:19
SqliteReadSvc::disconnect
bool disconnect(const std::string &) override
Dummy overrider of the virtual function.
Definition: SqliteReadSvc.cxx:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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:92
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
RDBQuery.h
SqliteReadSvc::m_recordsets
RecordsetPtrMap m_recordsets
Definition: SqliteReadSvc.h:90
SqliteReadSvc::connect
bool connect(const std::string &connName) override
Open the SQLite database This method has no effect if the connection has already been opened.
Definition: SqliteReadSvc.cxx:32
RDBTagDetails
coral::AttributeList RDBTagDetails
Definition: IRDBAccessSvc.h:29
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:51
SqliteReadSvc::getQuery
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)
Definition: SqliteReadSvc.cxx:88
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
SqliteReadSvc::finalize
StatusCode finalize() override
Definition: SqliteReadSvc.cxx:24
node
Definition: memory_hooks-stdcmalloc.h:74
SqliteReadSvc::m_sessionMutex
std::mutex m_sessionMutex
Definition: SqliteReadSvc.h:93