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

#include <CalibHeadOperations.h>

Collaboration diagram for MuonCalib::CalibHeadOperations:

Public Member Functions

 CalibHeadOperations (CalibDbConnection &db_conn)
 
virtual ~CalibHeadOperations ()
 
int GetLatestHeadId ()
 
bool GetHeadInfo (int &head_id, int &lowrun, int &uprun, int &lowtime, int &uptime)
 
CalibDbConnectionGetDataConnection (int head_id=-1, bool write=false, const std::string &writer_connection="", const std::string &writer_user="", const std::string &writer_password="")
 

Private Attributes

CalibDbConnectionm_meta_connection
 

Detailed Description

Definition at line 21 of file CalibHeadOperations.h.

Constructor & Destructor Documentation

◆ CalibHeadOperations()

MuonCalib::CalibHeadOperations::CalibHeadOperations ( CalibDbConnection db_conn)

Definition at line 27 of file CalibHeadOperations.cxx.

27 : m_meta_connection(&db_conn) {}

◆ ~CalibHeadOperations()

MuonCalib::CalibHeadOperations::~CalibHeadOperations ( )
virtual

Definition at line 26 of file CalibHeadOperations.cxx.

26 {}

Member Function Documentation

◆ GetDataConnection()

CalibDbConnection * MuonCalib::CalibHeadOperations::GetDataConnection ( int  head_id = -1,
bool  write = false,
const std::string &  writer_connection = "",
const std::string &  writer_user = "",
const std::string &  writer_password = "" 
)

Definition at line 90 of file CalibHeadOperations.cxx.

91  {
92  if (head_id < 0) { head_id = GetLatestHeadId(); }
93  if (head_id < 0) return nullptr;
94  try {
96  coral::IQuery* query = m_meta_connection->GetQuery();
97  query->setRowCacheSize(1);
98  query->addToTableList("MDT_HEAD");
99  query->addToTableList("MDT_DATA_SCHEMA");
100  query->addToOutputList("MDT_DATA_SCHEMA.SCHEMA_NAME", "SCHEMA");
101  query->addToOutputList("MDT_DATA_SCHEMA.WRITER_ACCOUNT", "WRITER_ACCOUNT");
102  query->addToOutputList("MDT_DATA_SCHEMA.ACTIVE", "ACTIVE");
103  query->addToOutputList("MDT_DATA_SCHEMA.ARCHIVED", "ARCHIVED");
104  query->addToOutputList("MDT_DATA_SCHEMA.ARCHIVE_CONNECTION_STRING", "ARCHIVE_CONNECTION_STRING");
105  std::string condition = "MDT_HEAD.DATA_SCHEMA=MDT_DATA_SCHEMA.SCHEMA_NAME and MDT_HEAD.HEAD_ID=:hid";
106  coral::AttributeList conditionData;
107  conditionData.extend<int>("hid");
108  conditionData["hid"].data<int>() = head_id;
109  query->setCondition(condition, conditionData);
110  coral::ICursor& cursor = query->execute();
111  if (!cursor.next()) {
112  MsgStream log(Athena::getMessageSvc(), "CalibHeadOperations");
113  log << MSG::WARNING << "No information about head_id=" << head_id << " found!" << endmsg;
114  return nullptr;
115  }
116  const coral::AttributeList& al = cursor.currentRow();
117  if (write && !al["ACTIVE"].data<bool>()) {
118  MsgStream log(Athena::getMessageSvc(), "CalibHeadOperations");
119  log << MSG::WARNING << "Can only write to the active schema" << endmsg;
120  return nullptr;
121  }
122  if (al["ARCHIVED"].data<bool>()) {
123  return new CalibDbConnection(al["ARCHIVE_CONNECTION_STRING"].data<std::string>(), al["SCHEMA"].data<std::string>());
124  }
125  if (!write) {
126  CalibDbConnection* conn = new CalibDbConnection(m_meta_connection->GetConnectionString(), al["SCHEMA"].data<std::string>());
127  std::string user, passwd;
129  conn->SetLogin(user, passwd);
130  return conn;
131  }
132  CalibDbConnection* ret = new CalibDbConnection(writer_connection, al["SCHEMA"].data<std::string>());
133  ret->SetTargetUser(al["WRITER_ACCOUNT"].data<std::string>());
134  ret->SetLogin(writer_user, writer_password);
135  return ret;
136  } catch (coral::SchemaException& e) {
137  MsgStream log(Athena::getMessageSvc(), "CalibHeadOperations");
138  log << MSG::WARNING << "Schema exception : " << e.what() << endmsg;
139  return nullptr;
140  }
141  }

◆ GetHeadInfo()

bool MuonCalib::CalibHeadOperations::GetHeadInfo ( int &  head_id,
int &  lowrun,
int &  uprun,
int &  lowtime,
int &  uptime 
)

Definition at line 51 of file CalibHeadOperations.cxx.

51  {
52  if (head_id < 0) { head_id = GetLatestHeadId(); }
53  if (head_id < 0) {
54  MsgStream log(Athena::getMessageSvc(), "CalibHeadOperations");
55  log << MSG::WARNING << "CalibHeadOperations::GetHeadInfo: Cannot get latest head id" << endmsg;
56  return -1;
57  }
58  try {
60  coral::IQuery* query = m_meta_connection->GetQuery();
61  query->addToTableList("MDT_HEAD");
62  query->addToOutputList("LOWRUN");
63  query->addToOutputList("UPRUN");
64  query->addToOutputList("LOWTIME");
65  query->addToOutputList("UPTIME");
66  std::string condition = "HEAD_ID=:hid";
67  coral::AttributeList conditionData;
68  conditionData.extend<int>("hid");
69  conditionData["hid"].data<int>() = head_id;
70  query->setCondition(condition, conditionData);
71  coral::ICursor& cursor = query->execute();
72  if (!cursor.next()) {
73  MsgStream log(Athena::getMessageSvc(), "CalibHeadOperations");
74  log << MSG::WARNING << "No information about head_id=" << head_id << " found!" << endmsg;
75  return false;
76  }
77  const coral::AttributeList& al = cursor.currentRow();
78  lowrun = al["LOWRUN"].data<int>();
79  uprun = al["UPRUN"].data<int>();
80  lowtime = al["LOWTIME"].data<int>();
81  uptime = al["UPTIME"].data<int>();
82  return true;
83  } catch (coral::SchemaException& e) {
84  MsgStream log(Athena::getMessageSvc(), "CalibHeadOperations");
85  log << MSG::WARNING << "Schema exception : " << e.what() << endmsg;
86  return false;
87  }
88  }

◆ GetLatestHeadId()

int MuonCalib::CalibHeadOperations::GetLatestHeadId ( )

Definition at line 29 of file CalibHeadOperations.cxx.

29  {
30  try {
32  coral::IQuery* query = m_meta_connection->GetQuery();
33  query->setRowCacheSize(1);
34  query->addToTableList("MDT_HEAD");
35  query->addToOutputList("max(HEAD_ID)", "max_head_id");
36  coral::ICursor& cursor = query->execute();
37  if (!cursor.next()) {
38  MsgStream log(Athena::getMessageSvc(), "CalibHeadOperations");
39  log << MSG::WARNING << "Query for head_id failed!" << endmsg;
40  return -1;
41  }
42  const coral::AttributeList& al = cursor.currentRow();
43  return static_cast<int>(al["max_head_id"].data<double>());
44  } catch (coral::SchemaException& e) {
45  MsgStream log(Athena::getMessageSvc(), "CalibHeadOperations");
46  log << MSG::WARNING << "Schema exception : " << e.what() << endmsg;
47  return -1;
48  }
49  }

Member Data Documentation

◆ m_meta_connection

CalibDbConnection* MuonCalib::CalibHeadOperations::m_meta_connection
private

Definition at line 37 of file CalibHeadOperations.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
checkCorrelInHIST.conn
conn
Definition: checkCorrelInHIST.py:25
calibdata.uptime
uptime
Definition: calibdata.py:36
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
query
Definition: query.py:1
MuonCalib::CalibHeadOperations::GetLatestHeadId
int GetLatestHeadId()
Definition: CalibHeadOperations.cxx:29
MuonCalib::CalibDbConnection::GetQuery
coral::IQuery * GetQuery()
Definition: CalibDbConnection.cxx:136
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
calibdata.uprun
uprun
Definition: calibdata.py:34
python.ByteStreamConfig.write
def write
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:248
MuonCalib::CalibDbConnection::OpenTransaction
void OpenTransaction()
Definition: CalibDbConnection.cxx:99
MuonCalib::CalibHeadOperations::m_meta_connection
CalibDbConnection * m_meta_connection
Definition: CalibHeadOperations.h:37
calibdata.head_id
head_id
Definition: calibdata.py:29
MuonCalib::CalibDbConnection::GetConnectionString
const std::string & GetConnectionString() const
Definition: CalibDbConnection.h:38
WriteBchToCool.user
user
Definition: WriteBchToCool.py:76
MuonCalib::CalibDbConnection::GetLogin
void GetLogin(std::string &username, std::string &password) const
Definition: CalibDbConnection.h:34
query_example.cursor
cursor
Definition: query_example.py:21
calibdata.lowrun
lowrun
Definition: calibdata.py:33
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
DeMoUpdate.passwd
passwd
Definition: DeMoUpdate.py:46
calibdata.lowtime
lowtime
Definition: calibdata.py:35