TDbiConfigStream.cxx
Go to the documentation of this file.00001
00002
00003 #include <sstream>
00004
00005
00006
00007 #include "TDbiConfigStream.hxx"
00008 #include "TDbiFieldType.hxx"
00009 #include "TDbiTableProxy.hxx"
00010 #include "TDbiDatabaseManager.hxx"
00011 #include "TDbiWriter.hxx"
00012 #include <TSK_DBI_Log.hxx>
00013 #include <MsgFormat.h>
00014 #include "TDbiRegistry.hxx"
00015 #include "TDbiCfg.hxx"
00016 #include "TDbiCascader.hxx"
00017 using std::endl;
00018 ClassImp(TDbiConfigStream)
00019
00020
00021
00022
00023
00024 TVldContext TDbiConfigStream::fgDefaultContext(DbiDetector::kNear,
00025 DbiSimFlag::kData,
00026 TVldTimeStamp() );
00027
00028
00029
00030
00031
00032
00033
00034
00035 TDbiConfigStream::TDbiConfigStream() :
00036 fCFSet(0)
00037 {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 SK_DBI_Debug( "Creating TDbiConfigStream" << " ");
00061 }
00062
00063
00064
00065 TDbiConfigStream::TDbiConfigStream(const string& SoftName,
00066 const std::string& ConfigName,
00067 TVldContext vc,
00068 TDbi::Task task,
00069 const std::string& tableName) :
00070 fCFSet(0),
00071 fCFSetTable(tableName,vc,task),
00072 fConfigName(ConfigName),
00073 fSoftwName(SoftName)
00074 {
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 SK_DBI_Debug( "Creating TDbiConfigStream" << " ");
00107
00108
00109 int rowNum = fCFSetTable.GetNumRows()-1;
00110 while ( rowNum >= 0 ) {
00111 fCFSet = fCFSetTable.GetRow(rowNum);
00112 if ( fCFSet->GetParamValue(0) == fSoftwName
00113 && fCFSet->GetParamValue(1) == fConfigName ) {
00114 fVRec = *fCFSetTable.GetValidityRec(fCFSet);
00115 SK_DBI_Log( "TDbiConfigStream for " << fSoftwName
00116 << "," << fConfigName
00117 << " has validity rec: " << fVRec
00118 << " and aggregate no.: " << fCFSet->GetAggregateNo()
00119 << " ");
00120 return;
00121 }
00122 --rowNum;
00123 }
00124
00125
00126
00127
00128
00129 fCFSet = 0;
00130
00131 fVRec.SetDbNo(0);
00132 fVRec.SetTableProxy(&TDbiResultSetHandle<TDbiConfigSet>::GetTableProxy(tableName));
00133 TVldTimeStamp start(1970,1,1,0,0,0);
00134 TVldTimeStamp end(2038,1,1,0,0,0);
00135 TVldRange vr(127,127,start,end,"TDbiConfigStream");
00136 fVRec.SetVldRange(vr);
00137 SK_DBI_Log( "TDbiConfigStream for " << fSoftwName
00138 << "," << fConfigName
00139 << " has no existing entry; creating validity rec: " << fVRec << " ");
00140
00141 }
00142
00143
00144
00145 TDbiConfigStream::~TDbiConfigStream() {
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 SK_DBI_Debug( "Destroying TDbiConfigStream" << " ");
00170
00171 }
00172
00173
00174
00175
00176 ostream& operator<<(ostream& os, const TDbiConfigStream& cfStream) {
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 const TDbiConfigSet* cfSet = cfStream.GetConfigSet();
00201
00202 if ( cfSet ) os << "TDbiConfigSet contains: " << *cfSet << endl;
00203 else os << "TDbiConfigSet is empty! " << endl;
00204 return os;
00205 }
00206
00207
00208
00209 const TDbiConfigStream& TDbiConfigStream::operator>>(TDbiRegistry* reg) {
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 if ( ! reg ) return *this;
00234
00235
00236
00237 Bool_t keysLocked = reg->KeysLocked();
00238 Bool_t valuesLocked = reg->ValuesLocked();
00239 reg->UnLockKeys();
00240 reg->UnLockValues();
00241 reg->Clear();
00242
00243
00244
00245 if ( fCFSet ) {
00246 UInt_t numParams = fCFSet->GetNumParams();
00247
00248
00249
00250 if ( numParams == 3 && fCFSet->GetParamName(2) == "CONFIG_DATA" ) {
00251 istringstream is(fCFSet->GetParamValue(2));
00252 reg->ReadStream(is);
00253 }
00254 else {
00255 SK_DBI_Severe( "Attempting to fill TDbiRegistry from a table with "
00256 << numParams << " columns (should be 3) using column named "
00257 << fCFSet->GetParamName(2) << " (should be CONFIG_DATA)." << " ");
00258 }
00259 }
00260 if ( keysLocked ) reg->LockKeys();
00261 if ( valuesLocked ) reg->LockValues();
00262 return *this;
00263 }
00264
00265
00266 TDbiConfigStream& TDbiConfigStream::operator<<(const TDbiRegistry* reg) {
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 if ( fSoftwName == "" ) {
00287 SK_DBI_Severe( "Cannot fill (<<): No software name defined." << " ");
00288 return *this;
00289 }
00290
00291 TDbiFieldType stringType(TDbi::kString);
00292
00293 ostringstream os;
00294 reg->PrintStream(os);
00295 fCFSetModified.Clear();
00296 fCFSetModified.PushBack("SOFTW_NAME", fSoftwName, stringType);
00297 fCFSetModified.PushBack("CONFIG_NAME",fConfigName, stringType);
00298 fCFSetModified.PushBack("CONFIG_DATA",os.str(), stringType);
00299 if ( fVRec.GetAggregateNo() > 0 ) fCFSetModified.SetAggregateNo( fVRec.GetAggregateNo());
00300 fCFSet = &fCFSetModified;
00301 return *this;
00302
00303 }
00304
00305
00306
00307
00308 Bool_t TDbiConfigStream::Write(UInt_t dbNo,
00309 const std::string& logComment,
00310 Bool_t localTest ) {
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 if ( ! fCFSet ) {
00326 SK_DBI_Severe( "No configuration data to write out." << " ");
00327 return false;
00328 }
00329
00330
00331
00332
00333 int requireGlobal = localTest ? -1 : 1;
00334 if ( fVRec.GetAggregateNo() < 0 ) {
00335 TDbiCascader& cas = TDbiDatabaseManager::Instance().GetCascader();
00336 Int_t aggNo = cas.AllocateSeqNo(fVRec.GetTableProxy()->GetTableName(),requireGlobal,dbNo);
00337 if ( aggNo <= TDbi::kMAXLOCALSEQNO && ! localTest ) {
00338 SK_DBI_Severe( "Cannot write out configuration data: no authorising entry in cascade." << " ");
00339 return false;
00340 }
00341 fVRec.SetAggregateNo(aggNo);
00342 fCFSetModified.SetAggregateNo(aggNo);
00343 SK_DBI_Debug( "Aggregate number: " << aggNo
00344 << " allocated to entry " << fSoftwName
00345 << "," << fConfigName
00346 << " in table " << fVRec.GetTableProxy()->GetTableName() << " ");
00347 }
00348 TDbiWriter<TDbiConfigSet> writer(fVRec,dbNo,logComment);
00349 writer.SetRequireGlobalSeqno(requireGlobal);
00350 writer.SetOverlayCreationDate();
00351 writer << *fCFSet;
00352 return writer.Close();
00353
00354 }
00355
00356
00357