Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
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
9
#include "
PgPostBankBackupStorage.h
"
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
33
PgPostBankBackupStorage::PgPostBankBackupStorage
(
PdbCalBank
*
b
)
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
57
PgPostBankBackupStorage::PgPostBankBackupStorage
()
58
: TNamed(
"NotAssigned"
,
"NotAssigned"
)
59
, obj_classname(
"NotAssigned"
)
60
, bank(nullptr)
61
{
62
}
63
64
PgPostBankBackupStorage::~PgPostBankBackupStorage
()
65
{
66
if
(
bank
)
67
delete
bank
;
68
}
69
71
PgPostCalBank
*
72
PgPostBankBackupStorage::createBank
()
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
87
PdbClassMap<PdbCalBank>
*classMap =
PdbClassMap<PdbCalBank>::instance
();
88
assert
(classMap);
89
90
if
(
obj_classname
==
"PgPostBankWrapper"
)
91
{
92
bw =
new
PgPostBankWrapper
(b_clone);
93
assert
(bw);
94
bw->
setBankID
(
obj_header
.
getBankID
());
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
124
bw->
setInsertTime
(
obj_header
.
getInsertTime
());
125
bw->
setStartValTime
(
obj_header
.
getStartValTime
());
126
bw->
setEndValTime
(
obj_header
.
getEndValTime
());
127
bw->
setDescription
(
obj_header
.
getDescription
());
128
bw->
setUserName
(
obj_header
.
getUserName
());
129
bw->
setTableName
(
obj_header
.
getTableName
());
130
131
return
bw;
132
}
133
134
string
135
PgPostBankBackupStorage::BankHeader::get_id_string
()
const
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
159
void
PgPostBankBackupStorage::set_obj_info
(
const
PgPostCalBank
*bw)
160
{
161
assert
(bw);
162
163
PdbClassMap<PdbCalBank>
*classMap =
PdbClassMap<PdbCalBank>::instance
();
164
if
(
string
(bw->ClassName()) ==
string
(
"PgPostBankWrapper"
))
165
{
166
obj_header
.
setBankID
(bw->
getBankID
().
getInternalValue
());
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();
189
obj_header
.
setInsertTime
(bw->
getInsertTime
());
190
obj_header
.
setStartValTime
(bw->
getStartValTime
());
191
obj_header
.
setEndValTime
(bw->
getEndValTime
());
192
if
(!bw->
getDescription
().empty())
193
obj_header
.
setDescription
(bw->
getDescription
());
194
if
(!bw->
getUserName
().empty())
195
obj_header
.
setUserName
(bw->
getUserName
());
196
if
(!bw->
getTableName
().empty())
197
obj_header
.
setTableName
(bw->
getTableName
());
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
213
void
PgPostBankBackupStorage::format_name_title
()
214
{
215
SetName
(
database_header
.
get_id_string
().c_str());
216
SetTitle
(
database_header
.
getDescription
().c_str());
217
}
218
219
size_t
220
PgPostBankBackupStorage::getLength
()
const
221
{
222
return
bank
->
getLength
();
223
}
224
225
PdbCalChan
&
226
PgPostBankBackupStorage::getEntry
(
size_t
pos
)
227
{
228
return
bank
->
getEntry
(pos);
229
}
230
231
bool
PgPostBankBackupStorage::isValid
()
const
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
247
if
(
database_header
.
getBankID
() ==
BankHeader::INVALID_BANKID
)
248
{
249
cout <<
"PgPostBankBackupStorage::isValid - Failed - invalid bank id"
250
<< endl;
251
return
false
;
252
}
253
if
(
database_header
.
getRId
() ==
BankHeader::INVALID_BANKID
)
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
}
coresoftware
blob
master
offline
database
pdbcal
pg
PgPostBankBackupStorage.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:04
using
1.8.2 with
sPHENIX GitHub integration