ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PgPostBankWrapper.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PgPostBankWrapper.cc
1 #include "PgPostBankWrapper.h"
2 #include "PgPostApplication.h"
4 
5 #include <pdbcalbase/PdbBankID.h> // for PdbBankID
6 #include <pdbcalbase/PdbCalBank.h> // for PdbCalBank
7 
8 #include <phool/phool.h>
9 #include <phool/PHTimeStamp.h>
10 
11 #include <RDBC/TSQLConnection.h>
12 #include <RDBC/TSQLPreparedStatement.h>
13 
14 #include <unistd.h> // for sleep
15 #include <cstdlib>
16 #include <iostream>
17 #include <sstream>
18 
19 
20 using namespace std;
21 
23  : bank(nullptr)
24 {
25 }
26 
28 {
29  bank = b;
31 }
32 
34 {
35  delete bank;
37 }
38 
40 {
41  bankID.print();
42  cout << "Insert : " << insertTime << endl;
43  cout << "StartVal : " << startValTime << endl;
44  cout << "EndVal : " << endValTime << endl;
45  cout << "Calibration Description : " << description << endl;
46  cout << "User Name = " << userName << endl;
47 }
48 
50 {
51  if (bank)
52  {
54  TSQLConnection *con = ap->getConnection();
55 
56  ostringstream sqlcmd;
57  sqlcmd << "insert into " << ((*this).getTableName())
58  << " values(?,?,?,?,?,?,?);";
59  cout << "query: " << sqlcmd.str() << endl;
60  TSQLPreparedStatement *pstmt = con->PrepareStatement(sqlcmd.str().c_str());
61  pstmt->SetInt(1, ((*this).getBankID()).getInternalValue());
62  pstmt->SetLong(2, ((*this).getInsertTime()).getTics());
63  pstmt->SetLong(3, ((*this).getStartValTime()).getTics());
64  pstmt->SetLong(4, ((*this).getEndValTime()).getTics());
65  pstmt->SetString(5, ((*this).getDescription()));
66  pstmt->SetString(6, ((*this).getUserName()));
67  pstmt->SetObject(7, this);
68  int res = 0;
69  res = pstmt->ExecuteUpdate();
70  con->Commit();
71  if (res == 0)
72  {
73  cout << PHWHERE << "DATABASE: commit to " << tableName << " failed" << endl;
74  cout << "Make sure you commit to the master database on phnxdb2.phenix.bnl.gov" << endl;
75  cout << "and that " << tableName << " exists in the master database" << endl;
76  exit(1);
77  }
78  cout << "Committed " << res << " row, sleeping 1 sec to make sure we have distinct insert times" << endl;
79  // entries are distinguished by insert time. If one commits a lot at once one has multiple
80  // entries for the same insert time (we can commit ~4/sec). This sleep 1 second just forces
81  // the insert time to be unique.
82  sleep(1);
83  return res;
84  }
85  else
86  {
87  cout << "Bank is a nullptr pointer" << endl;
88  return 0;
89  }
90 }