EIC Software
Reference for
EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
FairDbResult.h
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file FairDbResult.h
1
#ifndef FAIRDBRESULT_H
2
#define FAIRDBRESULT_H
3
#include <map>
4
#include <string>
5
using
std::string;
6
#include <list>
7
#include <iosfwd>
8
#include <vector>
9
#include <algorithm>
10
11
#include "TObject.h"
12
#include "TString.h"
13
14
#include "
FairDb.h
"
15
#include "
FairDbValidityRec.h
"
16
#include "
FairDbRowStream.h
"
17
#include "
ValTimeStamp.h
"
18
#include "
FairDbExceptionLog.h
"
19
20
21
22
//------------------------- Result Key --------------------------------//
23
24
class
FairDbResultKey
;
25
std::ostream&
operator<<
(std::ostream& os,
const
FairDbResultKey
& key);
26
27
class
FairDbResultKey
:
public
TObject
28
{
29
30
public
:
31
32
using
TObject::Compare;
33
34
// Constructors and destructors.
35
FairDbResultKey
(
const
FairDbResultKey
* that = 0);
36
FairDbResultKey
(std::string tableName,
37
std::string rowName,
38
UInt_t seqno,
39
ValTimeStamp
ts);
40
virtual
~FairDbResultKey
();
41
42
std::string
AsString
()
const
;
43
Float_t
Compare
(
const
FairDbResultKey
* that)
const
;
44
static
const
FairDbResultKey
*
45
GetEmptyKey
() {
return
&
fgEmptyKey
; }
46
Int_t
GetNumVrecs
()
const
{
return
fNumVRecKeys
; }
47
std::string
GetTableRowName
()
const
;
48
Bool_t
IsEqualTo
(
const
FairDbResultKey
* that)
const
{
49
return
this->
Compare
(that) == 1.;
50
}
51
52
// State changing member functions
53
54
void
AddVRecKey
(UInt_t seqno,
ValTimeStamp
ts);
55
56
// push this put to the public: portion so that rootcint dict compiles
57
struct
VRecKey
{
58
VRecKey
() :
SeqNo
(0),
CreationDate
() {}
59
VRecKey
(UInt_t seqno,
ValTimeStamp
ts) :
SeqNo
(seqno),
CreationDate
(ts) {}
60
UInt_t
SeqNo
;
61
ValTimeStamp
CreationDate
;
62
};
63
64
private
:
65
66
static
FairDbResultKey
fgEmptyKey
;
67
std::string
fTableName
;
68
std::string
fRowName
;
69
std::list<FairDbResultKey::VRecKey>
fVRecKeys
;
70
Int_t
fNumVRecKeys
;
71
72
ClassDef(
FairDbResultKey
,1)
73
74
};
75
76
//---------------------- Result Set-------------------------------------//
77
class
FairDbString
;
78
class
FairDbStatement
;
79
class
FairDbTableMetaData
;
80
class
FairDbTableProxy
;
81
class
TSQLStatement;
82
class
ValTimeStamp
;
83
84
85
class
FairDbResultSet
:
public
FairDbRowStream
86
{
87
public
:
88
89
// Constructors and destructors.
90
FairDbResultSet
(
FairDbStatement
* stmtDb,
91
const
FairDbString
& sql,
92
const
FairDbTableMetaData
* metaData,
93
const
FairDbTableProxy
* tableProxy,
94
UInt_t dbNo,
95
const
string
& fillOpts =
""
);
96
virtual
~FairDbResultSet
();
97
98
// State testing member functions
99
Bool_t
CurColExists
()
const
;
100
string
CurColString
()
const
;
101
string
CurColValue
()
const
{
LoadCurValue
();
return
fValString
;}
102
UInt_t
CurRowNum
()
const
{
return
fCurRow
;}
103
UInt_t
GetDbNo
()
const
{
return
fDbNo
; }
104
FairDb::DbTypes
GetDBType
()
const
{
return
fDbType
; }
105
string
GetFillOpts
()
const
{
return
fFillOpts
;}
106
const
FairDbTableProxy
*
GetTableProxy
()
const
{
return
fTableProxy
; }
109
Bool_t
IsBeforeFirst
()
const
{
return
false
; };
110
Bool_t
IsExhausted
()
const
{
return
fExhausted
; }
111
void
RowAsCsv
(
string
& row)
const
;
112
113
// State changing member functions
114
115
FairDbResultSet
&
operator>>
(Bool_t& dest);
116
FairDbResultSet
&
operator>>
(Char_t& dest);
117
FairDbResultSet
&
operator>>
(Short_t& dest);
118
FairDbResultSet
&
operator>>
(UShort_t& dest);
119
FairDbResultSet
&
operator>>
(Int_t& dest);
120
FairDbResultSet
&
operator>>
(UInt_t& dest);
121
FairDbResultSet
&
operator>>
(Long_t& dest);
122
FairDbResultSet
&
operator>>
(ULong_t& dest);
123
FairDbResultSet
&
operator>>
(Float_t& dest);
124
FairDbResultSet
&
operator>>
(Double_t& dest);
125
FairDbResultSet
&
operator>>
(
string
& dest);
126
FairDbResultSet
&
operator>>
(
ValTimeStamp
& dest);
127
128
Bool_t
FetchRow
();
129
130
private
:
131
132
string
&
AsString
(
FairDb::DataTypes
type);
133
Bool_t
LoadCurValue
()
const
;
134
TString
GetStringFromTSQL
(Int_t col)
const
;
135
Int_t
fCurRow
;
136
UInt_t
fDbNo
;
137
FairDb::DbTypes
fDbType
;
138
FairDbStatement
*
fStatement
;
139
TSQLStatement*
fTSQLStatement
;
140
Bool_t
fExhausted
;
141
const
FairDbTableProxy
*
fTableProxy
;
142
mutable
string
fValString
;
143
string
fFillOpts
;
144
145
FairDbResultSet
(
const
FairDbResultSet
&);
146
FairDbResultSet
operator=
(
const
FairDbResultSet
&);
147
148
ClassDef(
FairDbResultSet
,0)
//ResultSet from Query to database table
149
150
};
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//------------------------- Main Result class ---------------------------//
165
166
typedef
std::map<UInt_t,const FairDbTableRow*>
IndexToRow_t
;
167
168
class
DbBinaryFile;
169
class
DbTableRow;
170
class
ValContext
;
171
172
class
FairDbResult
;
173
FairDbBinaryFile
&
operator<<
(
FairDbBinaryFile
& bf,
const
FairDbResult
& res);
174
FairDbBinaryFile
&
operator>>
(
FairDbBinaryFile
& bf,
FairDbResult
& res);
175
176
class
FairDbResult
177
{
178
179
public
:
180
181
// Constructors and destructors.
182
FairDbResult
(
FairDbResultSet
* resultSet = 0,
183
const
FairDbValidityRec
* vrec = 0,
184
const
string
& sqlQualifiers =
""
);
185
// FairDbResult& operator=(const FairDbResult&);
186
FairDbResult
(
const
FairDbResult
&);
187
virtual
~FairDbResult
();
188
189
// State testing member functions
190
191
virtual
Bool_t
CanReuse
()
const
{
return
fCanReuse
; }
192
virtual
Bool_t
CanSave
()
const
{
return
kTRUE; }
193
virtual
void
Connect
()
const
{ ++
fNumClients
; }
194
virtual
FairDbResultKey
*
CreateKey
()
const
= 0;
195
virtual
void
Disconnect
()
const
{ --
fNumClients
; }
196
Int_t
GetID
()
const
{
return
fID
; }
197
virtual
const
FairDbResultKey
*
GetKey
()
const
;
198
virtual
UInt_t
GetNumAggregates
()
const
=0;
199
virtual
UInt_t
GetNumClients
()
const
{
200
return
fNumClients
;
201
}
202
virtual
UInt_t
GetNumRows
()
const
=0;
203
const
string
&
GetSqlQualifiers
()
const
{
return
fSqlQualifiers
; }
204
virtual
const
FairDbTableRow
*
GetTableRow
(UInt_t rowNum)
const
=0;
205
virtual
const
FairDbTableRow
*
GetTableRowByIndex
(UInt_t index)
const
;
206
virtual
const
FairDbValidityRec
&
GetValidityRec
(
207
const
FairDbTableRow
* row = 0)
const
{
208
return
GetValidityRecGlobal
();
209
}
210
virtual
const
FairDbValidityRec
&
GetValidityRecGlobal
()
const
{
211
return
fEffVRec
;
212
}
213
Bool_t
IsExtendedContext
()
const
{
214
return
this->
GetSqlQualifiers
() !=
""
;
215
}
216
virtual
Bool_t
Owns
(
const
FairDbTableRow
* table)
const
{
return
kFALSE; }
217
Bool_t
ResultsFromDb
()
const
{
return
fResultsFromDb
; }
218
virtual
const
string
&
TableName
()
const
{
return
fTableName
; }
219
220
virtual
Bool_t
CanDelete
(
const
FairDbResult
* res = 0);
221
222
virtual
Bool_t
Satisfies
(
const
ValContext
& vc,
223
const
FairDb::Task
& task);
224
virtual
Bool_t
Satisfies
(
const
string
&) {
return
kFALSE;}
225
virtual
Bool_t
Satisfies
(
const
FairDbValidityRec
&,
226
const
string
& =
""
) {
return
kFALSE;}
227
228
virtual
void
DeRegisterKey
();
229
virtual
void
RegisterKey
();
230
231
virtual
void
Streamer
(
FairDbBinaryFile
&
file
);
232
virtual
void
SetCanReuse
(Bool_t reuse) {
fCanReuse
= reuse ; }
233
void
CaptureExceptionLog
(UInt_t startFrom);
234
protected
:
235
void
SetResultsFromDb
() {
fResultsFromDb
= kTRUE; }
236
void
BuildLookUpTable
()
const
;
237
Bool_t
LookUpBuilt
()
const
{
return
fIndexKeys
.size() > 0; }
238
virtual
void
SetTableName
(
const
string
& tableName) {
239
fTableName
= tableName;
240
}
241
virtual
void
SetValidityRec
(
const
FairDbValidityRec
& vRec) {
242
fEffVRec
= vRec;
243
}
244
245
246
247
248
private
:
249
250
Int_t
fID
;
251
Bool_t
fCanReuse
;
252
FairDbValidityRec
fEffVRec
;
253
mutable
IndexToRow_t
fIndexKeys
;
254
const
FairDbResultKey
*
fKey
;
255
Bool_t
fResultsFromDb
;
256
mutable
Int_t
fNumClients
;
257
string
fTableName
;
258
string
fSqlQualifiers
;
259
static
Int_t
fgLastID
;
260
FairDbExceptionLog
fExceptionLog
;
261
262
ClassDef(
FairDbResult
,0)
//Abstract base representing query result
263
264
};
265
266
267
268
//------------------------------- Result Aggregat ---------------------//
269
270
class
FairDbCache
;
271
class
FairDbBinaryFile
;
272
class
FairDbProxy
;
273
class
FairDbTableRow
;
274
class
FairDbValidityRecBuilder
;
275
276
class
FairDbResultAgg
:
public
FairDbResult
277
{
278
public
:
279
// Only some Satisfies methods are overriden so include base class ones.
280
using
FairDbResult::Satisfies
;
281
282
// Constructors and destructors.
283
FairDbResultAgg
(
const
string
& tableName =
"Unknown"
,
284
const
FairDbTableRow
* tableRow = 0,
285
FairDbCache
* cache = 0,
286
const
FairDbValidityRecBuilder
* vrecBuilder = 0,
287
const
FairDbProxy
* proxy=0,
288
const
string
& sqlQualifiers =
""
);
289
virtual
~FairDbResultAgg
();
290
291
// State testing member functions
292
293
virtual
FairDbResultKey
*
CreateKey
()
const
;
294
virtual
UInt_t
GetNumAggregates
()
const
{
295
return
1 +
fResults
.size();
296
};
297
virtual
UInt_t
GetNumRows
()
const
{
298
return
fSize
;
299
}
300
virtual
const
FairDbTableRow
*
GetTableRow
(UInt_t row)
const
;
301
virtual
const
FairDbValidityRec
&
GetValidityRec
(
302
const
FairDbTableRow
* row=0)
const
;
303
304
// State changing member functions.
305
virtual
Bool_t
Satisfies
(
const
string
& sqlQualifiers);
306
virtual
void
Streamer
(
FairDbBinaryFile
& bf);
307
308
309
private
:
310
std::vector<const FairDbResult*>
fResults
;
311
std::vector<const FairDbTableRow*>
fRowKeys
;
312
UInt_t
fSize
;
313
314
ClassDef(
FairDbResultAgg
,0)
// Results table of aggregated data.
315
316
};
317
318
319
320
321
322
//---------------------- Result Non Aggregat ----------------------------//
323
324
class
FairDbResultNonAgg
:
public
FairDbResult
325
{
326
public
:
327
328
// Only some Satisfies methods are overriden so include base class ones.
329
using
FairDbResult::Satisfies
;
330
331
332
// Constructors and destructors.
333
FairDbResultNonAgg
(
FairDbResultSet
* resultSet = 0,
334
const
FairDbTableRow
* tableRow = 0,
335
const
FairDbValidityRec
* vrec = 0,
336
Bool_t dropSeqNo = kTRUE,
337
const
string
& sqlQualifiers =
""
);
338
virtual
~FairDbResultNonAgg
();
339
340
341
342
virtual
FairDbResultKey
*
CreateKey
()
const
;
343
virtual
UInt_t
GetNumAggregates
()
const
{
return
1; }
344
virtual
UInt_t
GetNumRows
()
const
{
345
return
fRows
.size();
346
}
347
virtual
const
FairDbTableRow
*
GetTableRow
(UInt_t rowNum)
const
;
348
virtual
const
FairDbTableRow
*
GetTableRowByIndex
(UInt_t index)
const
;
349
350
virtual
Bool_t
Owns
(
const
FairDbTableRow
* row )
const
;
351
Bool_t
Satisfies
(
const
FairDbValidityRec
& vrec,
352
const
string
& sqlQualifiers =
""
);
353
virtual
void
Streamer
(
FairDbBinaryFile
&
file
);
354
355
private
:
356
357
void
DebugCtor
()
const
;
358
359
std::vector<FairDbTableRow*>
fRows
;
360
Char_t*
fBuffer
;
361
362
FairDbResultNonAgg
(
const
FairDbResultNonAgg
&);
363
FairDbResultNonAgg
operator=
(
const
FairDbResultNonAgg
&);
364
365
ClassDef(
FairDbResultNonAgg
,0)
// Non-aggregated data
366
367
};
368
369
370
371
#endif // FAIRDBRESULT_H
EicRoot
blob
master
dbase
dbInterface
FairDbResult.h
Built by
Jin Huang
. updated:
Mon Jan 22 2024 12:43:33
using
1.8.2 with
EIC GitHub integration