ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
dqi::DatabaseConfig Class Reference

#include <DatabaseConfig.h>

Collaboration diagram for dqi::DatabaseConfig:

Public Member Functions

 DatabaseConfig (std::string connectionString, long runNumber)
 
nlohmann::json GetPayload (const std::string &tag)
 
bool IsConnected () const
 
void Disconnect ()
 

Private Member Functions

long GetRunNumber () const
 
nlohmann::json LoadPayload (const std::string &tag)
 
void Connect ()
 

Private Attributes

const std::string m_connectionString
 
const long m_runNumber {}
 
bool m_dbConnected {}
 
bool m_folderConnected {}
 
std::unordered_map< std::string, nlohmann::jsonm_jsonData
 
cool::IFolderPtr m_folder
 
cool::IDatabasePtr m_database
 

Detailed Description

Definition at line 15 of file DatabaseConfig.h.

Constructor & Destructor Documentation

◆ DatabaseConfig()

dqi::DatabaseConfig::DatabaseConfig ( std::string  connectionString,
long  runNumber 
)

Definition at line 20 of file DatabaseConfig.cxx.

22  : m_connectionString(std::move(connectionString))
23  , m_runNumber((runNumber << 32) + 1)
24  , m_dbConnected(false)
25  , m_folderConnected(false)
26 {
27 }

Member Function Documentation

◆ Connect()

void dqi::DatabaseConfig::Connect ( )
private

Definition at line 41 of file DatabaseConfig.cxx.

43 {
44  try {
45  cool::IDatabaseSvc& dbSvc = cool::DatabaseSvcFactory::databaseService();
46  m_database = dbSvc.openDatabase(m_connectionString, true);
47 
48  } catch (std::exception& e) {
49  std::cerr << "Unable to open database -> " << e.what() << '\n';
50  return;
51  }
52  m_dbConnected = true;
53  try {
54  m_folder= m_database->getFolder("/GLOBAL/DQM/REFERENCES");
55 
56  } catch (std::exception& e) {
57  std::cerr << "Unable loading folder for this tag/run-> " << e.what() << '\n';
58  return;
59  }
60  m_folderConnected = true;
61 }

◆ Disconnect()

void dqi::DatabaseConfig::Disconnect ( )

Definition at line 30 of file DatabaseConfig.cxx.

32 {
33  if(m_dbConnected) {
34  m_database->closeDatabase();
35  m_dbConnected = false;
36  m_folderConnected = false;
37  }
38 }

◆ GetPayload()

nlohmann::json dqi::DatabaseConfig::GetPayload ( const std::string &  tag)

Definition at line 64 of file DatabaseConfig.cxx.

66 {
68  Connect();
69  }
70  if(m_jsonData.find(tag) == m_jsonData.end()) {
71  return LoadPayload(tag);
72  }
73  return m_jsonData.at(tag);
74 }

◆ GetRunNumber()

long dqi::DatabaseConfig::GetRunNumber ( ) const
private

Definition at line 104 of file DatabaseConfig.cxx.

106 {
107  return m_runNumber;
108 }

◆ IsConnected()

bool dqi::DatabaseConfig::IsConnected ( ) const

Definition at line 97 of file DatabaseConfig.cxx.

99 {
101 }

◆ LoadPayload()

nlohmann::json dqi::DatabaseConfig::LoadPayload ( const std::string &  tag)
private

Definition at line 77 of file DatabaseConfig.cxx.

79 {
80  nlohmann::json jsonData;
82  try {
83  cool::IObjectPtr object = m_folder->findObject(GetRunNumber(), 1, tag);
84 
85  std::string data = object->payloadValue("jsonData");
86  jsonData = nlohmann::json::parse(data);
87  m_jsonData[tag] = jsonData;
88 
89  } catch (std::exception& e) {
90  std::cerr << "Error: Failed loading payload for this tag/run-> " << e.what() << '\n';
91  }
92  }
93  return jsonData;
94 }

Member Data Documentation

◆ m_connectionString

const std::string dqi::DatabaseConfig::m_connectionString
private

Definition at line 25 of file DatabaseConfig.h.

◆ m_database

cool::IDatabasePtr dqi::DatabaseConfig::m_database
private

Definition at line 33 of file DatabaseConfig.h.

◆ m_dbConnected

bool dqi::DatabaseConfig::m_dbConnected {}
private

Definition at line 28 of file DatabaseConfig.h.

◆ m_folder

cool::IFolderPtr dqi::DatabaseConfig::m_folder
private

Definition at line 32 of file DatabaseConfig.h.

◆ m_folderConnected

bool dqi::DatabaseConfig::m_folderConnected {}
private

Definition at line 29 of file DatabaseConfig.h.

◆ m_jsonData

std::unordered_map<std::string, nlohmann::json> dqi::DatabaseConfig::m_jsonData
private

Definition at line 31 of file DatabaseConfig.h.

◆ m_runNumber

const long dqi::DatabaseConfig::m_runNumber {}
private

Definition at line 26 of file DatabaseConfig.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
dqi::DatabaseConfig::m_folderConnected
bool m_folderConnected
Definition: DatabaseConfig.h:29
dqi::DatabaseConfig::m_database
cool::IDatabasePtr m_database
Definition: DatabaseConfig.h:33
json
nlohmann::json json
Definition: HistogramDef.cxx:9
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
dqi::DatabaseConfig::GetRunNumber
long GetRunNumber() const
Definition: DatabaseConfig.cxx:105
dqi::DatabaseConfig::m_connectionString
const std::string m_connectionString
Definition: DatabaseConfig.h:25
calibdata.exception
exception
Definition: calibdata.py:496
CaloNoise_fillDB.dbSvc
dbSvc
Definition: CaloNoise_fillDB.py:108
dqi::DatabaseConfig::m_dbConnected
bool m_dbConnected
Definition: DatabaseConfig.h:28
dqi::DatabaseConfig::Connect
void Connect()
Definition: DatabaseConfig.cxx:42
dqi::DatabaseConfig::m_folder
cool::IFolderPtr m_folder
Definition: DatabaseConfig.h:32
dqi::DatabaseConfig::LoadPayload
nlohmann::json LoadPayload(const std::string &tag)
Definition: DatabaseConfig.cxx:78
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
dqi::DatabaseConfig::m_jsonData
std::unordered_map< std::string, nlohmann::json > m_jsonData
Definition: DatabaseConfig.h:31
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
dqi::DatabaseConfig::m_runNumber
const long m_runNumber
Definition: DatabaseConfig.h:26