ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PgPostBankBackupStorage.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PgPostBankBackupStorage.cc
1 
10 
11 #include "PgPostBankWrapper.h"
12 #include "PgPostCalBank.h"
13 
14 #include <pdbcalbase/PdbBankID.h>
15 #include <pdbcalbase/PdbCalBank.h>
16 #include <pdbcalbase/PdbClassMap.h>
17 
18 #include <phool/PHTimeStamp.h> // for PHTimeStamp
19 
20 #include <TNamed.h>
21 
22 #include <cassert>
23 #include <cstdlib>
24 #include <iostream>
25 #include <map>
26 #include <sstream>
27 #include <string>
28 
29 class PdbCalChan;
30 
31 using namespace std;
32 
34  : TNamed("NotAssigned", "NotAssigned")
35  , obj_classname("NotAssigned")
36 {
37  if (!b)
38  {
39  cout
40  << "PgPostBankBackupStorage::PgPostBankBackupStorage - Fatal Error - "
41  << "invalid bank" << endl;
42  exit(1);
43  }
44 
45  if (string(b->ClassName()) == string("PgPostBankWrapper"))
46  {
47  cout
48  << "PgPostBankBackupStorage::PgPostBankBackupStorage - Fatal Error - "
49  << "PgPostBankBackupStorage do not accept bank wrappers by design"
50  << endl;
51  exit(1);
52  }
53 
54  bank = b;
55 }
56 
58  : TNamed("NotAssigned", "NotAssigned")
59  , obj_classname("NotAssigned")
60  , bank(nullptr)
61 {
62 }
63 
65 {
66  if (bank)
67  delete bank;
68 }
69 
73 {
74  if (!isValid())
75  {
76  cout << "PgPostBankBackupStorage::createBank - ERROR - "
77  << "invalid content" << endl;
78 
79  return nullptr;
80  }
81 
82  PgPostCalBank *bw = nullptr;
83 
84  PdbCalBank *b_clone = static_cast<PdbCalBank *>(bank->Clone());
85  assert(b_clone);
86 
88  assert(classMap);
89 
90  if (obj_classname == "PgPostBankWrapper")
91  {
92  bw = new PgPostBankWrapper(b_clone);
93  assert(bw);
95  }
96  else if (obj_classname == "PgPostCalBank")
97  {
98  cout << "PgPostBankBackupStorage::createBank - WARNING - "
99  << "empty PgPostCalBank object is created for table "
100  << database_header.getTableName() << " where rid = "
101  << database_header.getRId() << endl;
102  bw = dynamic_cast<PgPostCalBank *>(b_clone);
103  assert(bw);
104  }
105  else if (classMap->find(get_obj_classname().c_str()) != classMap->end())
106  {
107  cout << "PgPostBankBackupStorage::createBank - WARNING - "
108  << "Direct stream of " << get_obj_classname()
109  << " object without wrapper in database, table "
110  << database_header.getTableName() << " where rid = "
111  << database_header.getRId() << endl;
112  bw = dynamic_cast<PgPostCalBank *>(b_clone);
113  assert(bw);
114  }
115  else
116  {
117  cout << "PgPostBankBackupStorage::createBank - ERROR - "
118  << "invalid obj_classname of " << obj_classname << " with bankID = "
119  << obj_header.getBankID() << endl;
120 
121  return nullptr;
122  }
123 
128  bw->setUserName(obj_header.getUserName().c_str());
129  bw->setTableName(obj_header.getTableName().c_str());
130 
131  return bw;
132 }
133 
134 string
136 {
137  stringstream o;
138  o << tableName << "_";
139  o.fill('0');
140  o.width(5);
141  o << rid;
142  o << "_";
143  o.width(1);
144  o << bankID;
145  o << "_" << insertTime.getTics();
146  o << "_" << startValTime.getTics();
147  o << "_" << endValTime.getTics();
148 
149  return o.str();
150 }
151 
152 void PgPostBankBackupStorage::BankHeader::Print(Option_t */*option*/) const
153 {
154  // TObject::Print(option);
155  cout << "ID = " << get_id_string() << " from user " << userName
156  << " and described as " << description << endl;
157 }
158 
160 {
161  assert(bw);
162 
164  if (string(bw->ClassName()) == string("PgPostBankWrapper"))
165  {
167  }
168  else if (string(bw->ClassName()) == string("PgPostCalBank"))
169  {
170  cout
171  << "PgPostBankBackupStorage::set_obj_info - WARNING - empty PgPostCalBank presented"
172  << bw->ClassName() << endl;
173  }
174  else if (classMap->find(bw->ClassName()) != classMap->end())
175  {
176  cout
177  << "PgPostBankBackupStorage::set_obj_info - WARNING - directly stream "
178  << bw->ClassName() << "without wrapper" << endl;
179  }
180  else
181  {
182  cout
183  << "PgPostBankBackupStorage::set_obj_info - ERROR - unknown object in database record: "
184  << bw->ClassName() << endl;
185  exit(1);
186  }
187 
188  obj_classname = bw->ClassName();
192  if (!bw->getDescription().empty())
194  if (!bw->getUserName().empty())
196  if (!bw->getTableName().empty())
198 }
199 
200 void PgPostBankBackupStorage::Print(Option_t *option) const
201 {
202  TNamed::Print(option);
203 
204  cout << "Database header : ";
205  database_header.Print(option);
206  cout << "Bank wrapper header : ";
207  obj_header.Print(option);
208 
209  assert(bank);
210  bank->print();
211 }
212 
214 {
215  SetName(database_header.get_id_string().c_str());
217 }
218 
219 size_t
221 {
222  return bank->getLength();
223 }
224 
225 PdbCalChan &
227 {
228  return bank->getEntry(pos);
229 }
230 
232 {
233  if (!bank)
234  {
235  cout << "PgPostBankBackupStorage::isValid - Failed - invalid bank pointer"
236  << endl;
237  return false;
238  }
239  if (string(bank->ClassName()) == string("PgPostBankWrapper"))
240  {
241  cout
242  << "PgPostBankBackupStorage::isValid - Failed - incorrect bank object"
243  << endl;
244  return false;
245  }
246 
248  {
249  cout << "PgPostBankBackupStorage::isValid - Failed - invalid bank id"
250  << endl;
251  return false;
252  }
254  {
255  cout << "PgPostBankBackupStorage::isValid - Failed - invalid rid" << endl;
256  return false;
257  }
258  if (database_header.getTableName() == "not assigned")
259  {
260  cout << "PgPostBankBackupStorage::isValid - Failed - invalid table name"
261  << endl;
262  return false;
263  }
264  if (obj_classname == "" or obj_classname == "NotAssigned")
265  {
266  cout << "PgPostBankBackupStorage::isValid - ERROR - "
267  << "invalid obj_classname = " << obj_classname << endl;
268 
269  return false;
270  }
271 
272  return true;
273 }