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
FairDbConfigStream.cxx
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file FairDbConfigStream.cxx
1
2
#include <sstream>
3
4
#include "
FairDbConf.h
"
5
#include "
FairDbMultConnector.h
"
6
#include "
FairDbConfigStream.h
"
7
#include "
FairDbFieldType.h
"
8
#include "
FairDbTableProxy.h
"
9
#include "
FairDbTableProxyRegistry.h
"
10
#include "
FairDbWriter.h
"
11
#include "
FairRegistry.h
"
12
13
ClassImp
(
FairDbConfigStream
)
14
15
16
ValContext
FairDbConfigStream
::fgDefaultContext(Detector::
kCal
,
17
SimFlag::
kData
,
18
ValTimeStamp
() );
19
20
21
FairDbConfigStream
::
FairDbConfigStream
() :
22
fCFSet(0),
23
fCFSetTable(),
24
fCFSetModified(),
25
fVRec(),
26
fConfigName(),
27
fSoftwName()
28
{
29
}
30
31
//.....................................................................
32
33
FairDbConfigStream::FairDbConfigStream
(
const
string
& SoftName,
34
const
std::string& ConfigName,
35
ValContext
vc,
36
FairDb::Task
task,
37
const
std::string& tableName) :
38
fCFSet(0),
39
fCFSetTable(tableName,vc,task),
40
fCFSetModified(),
41
fVRec(),
42
fConfigName(ConfigName),
43
fSoftwName(SoftName)
44
{
45
46
// Search for row matching software and configuration names.
47
int
rowNum =
fCFSetTable
.
GetNumRows
()-1;
48
while
( rowNum >= 0 ) {
49
fCFSet
=
fCFSetTable
.
GetRow
(rowNum);
50
if
(
fCFSet
->
GetParamValue
(0) ==
fSoftwName
51
&&
fCFSet
->
GetParamValue
(1) ==
fConfigName
) {
52
fVRec
= *
fCFSetTable
.
GetValidityRec
(
fCFSet
);
53
cout <<
"FairDbConfigStream for "
<<
fSoftwName
54
<<
","
<<
fConfigName
55
<<
" has validity rec: "
<<
fVRec
56
<<
" and aggregate no.: "
<<
fCFSet
->
GetAggregateNo
()
57
<< endl;
58
return
;
59
}
60
--rowNum;
61
}
62
63
// Cannot find matching row, leave configuration data as null
64
// and set up a validity rec that can be used if creating a
65
// new row.
66
67
fCFSet
= 0;
68
69
fVRec
.
SetDbNo
(0);
70
fVRec
.
SetTableProxy
(&
FairDbResultPtr<FairDbConfigSet>::GetTableProxy
(tableName));
71
ValTimeStamp
start
(1970,1,1,0,0,0);
72
ValTimeStamp
end(2038,1,1,0,0,0);
73
ValRange
vr(127,127,start,end,
"FairDbConfigStream"
);
74
fVRec
.
SetValRange
(vr);
75
cout <<
"FairDbConfigStream for "
<<
fSoftwName
76
<<
","
<<
fConfigName
77
<<
" has no existing entry; creating validity rec: "
<<
fVRec
<< endl;
78
79
}
80
81
82
FairDbConfigStream::~FairDbConfigStream
()
83
{
84
85
}
86
87
88
89
ostream&
operator<<
(ostream& os,
const
FairDbConfigStream
& cfStream)
90
{
91
92
93
const
FairDbConfigSet
* cfSet = cfStream.
GetConfigSet
();
94
95
if
( cfSet ) { os <<
"FairDbConfigSet contains: "
<< *cfSet << endl; }
96
else
{ os <<
"FairDbConfigSet is empty! "
<< endl; }
97
return
os;
98
}
99
100
101
const
FairDbConfigStream
&
FairDbConfigStream::operator>>
(
FairRegistry
* reg)
102
{
103
104
if
( ! reg ) {
return
*
this
; }
105
106
// Record the current state of reg and then clear it.
107
108
Bool_t keysLocked = reg->
KeysLocked
();
109
Bool_t valuesLocked = reg->
ValuesLocked
();
110
reg->
UnLockKeys
();
111
reg->
UnLockValues
();
112
reg->
Clear
();
113
114
// Use the owned FairDbConfigSet to fill reg.
115
116
if
(
fCFSet
) {
117
UInt_t numParams =
fCFSet
->
GetNumParams
();
118
119
// Handle configuration tables.
120
121
if
( numParams == 3 &&
fCFSet
->
GetParamName
(2) ==
"CONFIG_DATA"
) {
122
istringstream is(
fCFSet
->
GetParamValue
(2));
123
reg->
ReadStream
(is);
124
}
else
{
125
cout<<
"Attempting to fill FairRegistry from a table with "
126
<< numParams <<
" columns (should be 3) using column named "
127
<<
fCFSet
->
GetParamName
(2) <<
" (should be CONFIG_DATA)."
<< endl;
128
}
129
}
130
if
( keysLocked ) { reg->
LockKeys
(); }
131
if
( valuesLocked ) { reg->
LockValues
(); }
132
return
*
this
;
133
}
134
135
FairDbConfigStream
&
FairDbConfigStream::operator<<
(
const
FairRegistry
* reg)
136
{
137
138
if
(
fSoftwName
==
""
) {
139
cout <<
"Cannot fill (<<): No software name defined."
<< endl;
140
return
*
this
;
141
}
142
143
FairDbFieldType
stringType(
FairDb::kString
);
144
145
ostringstream os;
146
reg->
PrintStream
(os);
147
fCFSetModified
.
Clear
();
148
fCFSetModified
.
PushBack
(
"SOFTW_NAME"
,
fSoftwName
, stringType);
149
fCFSetModified
.
PushBack
(
"CONFIG_NAME"
,
fConfigName
, stringType);
150
fCFSetModified
.
PushBack
(
"CONFIG_DATA"
,os.str(), stringType);
151
if
(
fVRec
.
GetAggregateNo
() > 0 ) {
fCFSetModified
.
SetAggregateNo
(
fVRec
.
GetAggregateNo
()); }
152
fCFSet
= &
fCFSetModified
;
153
return
*
this
;
154
155
}
156
157
158
159
Bool_t
FairDbConfigStream::Write
(UInt_t dbNo,
160
const
std::string& logComment,
161
Bool_t localTest )
162
{
163
164
if
( !
fCFSet
) {
165
cout <<
"No configuration data to write out."
<< endl;
166
return
false
;
167
}
168
169
// If no aggregate number has been asigned so far, but fCFSet non-zero, then must
170
// be creating a new software/config combination with the data in fCFSetModified.
171
// Use a global seqno number (or local if localTest) to define a unique aggregate number.
172
int
requireGlobal = localTest ? -1 : 1;
173
if
(
fVRec
.
GetAggregateNo
() < 0 ) {
174
FairDbMultConnector
& cas =
FairDbTableProxyRegistry::Instance
().
GetMultConnector
();
175
Int_t aggNo = cas.
AllocateSeqNo
(
fVRec
.
GetTableProxy
()->
GetTableName
(),requireGlobal,dbNo);
176
if
( aggNo <=
FairDb::kMAXLOCALSEQNO
&& ! localTest ) {
177
cout <<
"Cannot write out configuration data: no authorising entry in cascade."
<< endl;
178
return
false
;
179
}
180
fVRec
.
SetAggregateNo
(aggNo);
181
fCFSetModified
.
SetAggregateNo
(aggNo);
182
cout <<
"Aggregate number: "
<< aggNo
183
<<
" allocated to entry "
<<
fSoftwName
184
<<
","
<<
fConfigName
185
<<
" in table "
<<
fVRec
.
GetTableProxy
()->
GetTableName
() << endl;
186
}
187
FairDbWriter<FairDbConfigSet>
writer(
fVRec
,dbNo,logComment);
188
writer.
SetRequireGlobalSeqno
(requireGlobal);
189
writer.
SetOverlayCreationDate
();
190
writer << *
fCFSet
;
191
return
writer.
Close
();
192
193
}
194
195
EicRoot
blob
master
dbase
dbInterface
FairDbConfigStream.cxx
Built by
Jin Huang
. updated:
Mon Jan 22 2024 12:43:33
using
1.8.2 with
EIC GitHub integration