00001
00002
00003 #include "DbiDetector.hxx"
00004 #include "DbiSimFlag.hxx"
00005 #include "TDbiBinaryFile.hxx"
00006 #include "TDbiInRowStream.hxx"
00007 #include "TDbiOutRowStream.hxx"
00008 #include "TDbiValidityRec.hxx"
00009 #include <TSK_DBI_Log.hxx>
00010 #include <MsgFormat.h>
00011 using std::endl;
00012 #include "TVldRange.hxx"
00013 #include "TVldTimeStamp.hxx"
00014
00015 #include "TString.h"
00016
00017 #include <sstream>
00018 #include <iostream>
00019
00020 ClassImp(TDbiValidityRec)
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "TDbiResultSetHandle.tpl"
00031 template class TDbiResultSetHandle<TDbiValidityRec>;
00032
00033
00034
00035
00036
00037
00038 ostream& operator<<(ostream& os, const TDbiValidityRec& vRec) {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 const TVldRange& range(vRec.GetVldRange());
00062
00063 ostringstream os2;
00064 os2 << "SeqNo: " << vRec.GetSeqNo()
00065 << " AggNo: " << vRec.GetAggregateNo()
00066 << " DbNo: " << vRec.GetDbNo();
00067 if ( vRec.IsGap() ) os2 << " (gap)";
00068 os2 << " TVldRange: |"
00069 << setprecision(3) << std::ios::hex << setfill ('0') << "0x" << setw(3) << range.GetDetectorMask() << "|"
00070 << "0x" << setw(3) << range.GetSimMask() << "|"
00071 << " " << range.GetTimeStart().AsString("s") << " .. "
00072 << range.GetTimeEnd().AsString("s")
00073 << " Epoch: " << vRec.GetEpoch()
00074 << " Task: " << vRec.GetTask()
00075 << " from: " << range.GetDataSource();
00076 os << os2.str();
00077 return os;
00078
00079 }
00080
00081
00082
00083
00084
00085
00086
00087 void TDbiValidityRec::AndTimeWindow(const TVldTimeStamp& startOther,
00088 const TVldTimeStamp& endOther) {
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 TVldTimeStamp start = fVldRange.GetTimeStart();
00113 TVldTimeStamp end = fVldRange.GetTimeEnd();
00114
00115 SetTimeWindow( start > startOther ? start : startOther,
00116 end < endOther ? end : endOther );
00117 }
00118
00119
00120
00121 TDbiValidityRec::TDbiValidityRec(Int_t dbNo,Bool_t isGap) :
00122
00123 fAggregateNo(-2),
00124 fDbNo(dbNo),
00125 fIsGap(isGap),
00126 fTask(0),
00127 fSeqNo(0),
00128 fTableProxy(0),
00129 fEpoch(0),
00130 fReality(0)
00131 {
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 SK_DBI_Trace( "Creating TDbiValidityRec" << " ");
00157 }
00158
00159
00160 TDbiValidityRec::TDbiValidityRec(const TDbiValidityRec& from) : TDbiTableRow(from)
00161 {
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 SK_DBI_Trace( "Creating TDbiValidityRec" << " ");
00186
00187 *this = from;
00188
00189 }
00190
00191
00192 TDbiValidityRec::TDbiValidityRec(const TVldRange& range,
00193 TDbi::Task task,
00194 Int_t aggNo,
00195 UInt_t seqNo,
00196 Int_t dbNo,
00197 Bool_t isGap,
00198 TVldTimeStamp time,
00199 UInt_t epoch) :
00200 fAggregateNo(aggNo),
00201 fCreationDate(time),
00202 fDbNo(dbNo),
00203 fIsGap(isGap),
00204 fTask(task),
00205 fSeqNo(seqNo),
00206 fTableProxy(0),
00207 fVldRange(range),
00208 fEpoch(epoch),
00209 fReality(0)
00210 {
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 SK_DBI_Trace( "Creating TDbiValidityRec" << " ");
00243 }
00244
00245
00246
00247 TDbiValidityRec::~TDbiValidityRec() {
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 SK_DBI_Trace( "Destroying TDbiValidityRec" << " ");
00272
00273 }
00274
00275
00276
00277 void TDbiValidityRec::Fill(TDbiInRowStream& rs,
00278 const TDbiValidityRec* ) {
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 TVldTimeStamp start, end;
00303 Int_t detMask, simMask;
00304
00305
00306
00307 fTableProxy = rs.GetTableProxy();
00308 fDbNo = rs.GetDbNo();
00309
00310
00311
00312 rs >> fSeqNo >> start >> end;
00313
00314 if ( rs.HasEpoch() ) rs >> fEpoch >> fReality;
00315 else fEpoch = fReality = 0;
00316
00317 rs >> detMask >> simMask >> fTask
00318 >> fAggregateNo >> fCreationDate >> fInsertDate;
00319
00320 fIsGap = kFALSE;
00321
00322 TVldRange vr(detMask, simMask, start, end, "From Database");
00323 fVldRange = vr;
00324
00325 SK_DBI_Verbose( "TDbiValidityRec for row " << rs.CurRowNum()
00326 << ": " << fVldRange.AsString()
00327 << " seq num: " << fSeqNo
00328 << " agg no: " << fAggregateNo
00329 << " task: " << " ");
00330 }
00331
00332
00333
00334 std::string TDbiValidityRec::GetL2CacheName() const {
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 return TDbiValidityRec::GetL2CacheName(this->GetSeqNo(),
00345 this->GetSeqNo(),
00346 this->GetCreationDate());
00347
00348 }
00349
00350
00351 std::string TDbiValidityRec::GetL2CacheName(UInt_t seqLo,
00352 UInt_t seqHi,
00353 TVldTimeStamp ts) {
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 ostringstream oss;
00372 oss << seqLo << "_";
00373 if ( seqLo != seqHi ) oss << seqHi << "_";
00374 oss << ts.AsString("s");
00375 std::string str(oss.str());
00376
00377 int i = str.size();
00378 while ( i-- ) if ( str[i] == ' ' ) str[i] = '_';
00379 return str;
00380
00381 }
00382
00383
00384
00385 Bool_t TDbiValidityRec::HasExpired(const TDbiValidityRec& other) const {
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 const TVldRange& otherVR =other.GetVldRange();
00411
00412 return
00413 ( other.GetTask() == fTask
00414 && ( otherVR.GetDetectorMask() & fVldRange.GetDetectorMask() )
00415 && ( otherVR.GetSimMask() & fVldRange.GetSimMask() )
00416 && ( otherVR.GetTimeStart() >= fVldRange.GetTimeEnd()
00417 || otherVR.GetTimeEnd() <= fVldRange.GetTimeStart() )
00418 );
00419
00420 }
00421
00422
00423
00424 Bool_t TDbiValidityRec::HasExpired(const TVldContext& vc,
00425 const TDbi::Task& task) const {
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 TVldTimeStamp ts = vc.GetTimeStamp();
00445 const TVldRange& vr = this->GetVldRange();
00446
00447 return
00448 ( task == this->GetTask()
00449 && ( vc.GetDetector() & vr.GetDetectorMask() )
00450 && ( vc.GetSimFlag() & vr.GetSimMask() )
00451 && ( ts >= vr.GetTimeEnd()
00452 || ts < vr.GetTimeStart() )
00453 );
00454
00455 }
00456
00457
00458
00459
00460 Bool_t TDbiValidityRec::IsCompatible(const TVldContext& vc,
00461 const TDbi::Task& task) const {
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 SK_DBI_Debug( " TDbiValidityRec::IsCompatible : tasks:"
00485 << task << "," << fTask
00486 << " is compat: " << fVldRange.IsCompatible(vc) << " "
00487 << " range " << fVldRange.AsString() << " "
00488 << " context " << vc.AsString() << " ");
00489
00490 return task == fTask && fVldRange.IsCompatible(vc);
00491
00492 }
00493
00494
00495
00496
00497 Bool_t TDbiValidityRec::IsHigherPriority(const TDbiValidityRec& that,
00498 Bool_t useCreationDate) const {
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 if ( useCreationDate) return fCreationDate > that.fCreationDate;
00511
00512 if ( fEpoch != that.fEpoch ) return fEpoch > that.fEpoch;
00513 if ( fVldRange.GetTimeStart() != that.fVldRange.GetTimeStart() )
00514 return fVldRange.GetTimeStart() > that.fVldRange.GetTimeStart();
00515 return fInsertDate > that.fInsertDate;
00516
00517 }
00518
00519
00520
00521
00522 void TDbiValidityRec::SetTimeWindow(const TVldTimeStamp& start,
00523 const TVldTimeStamp& end) {
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 TVldRange range(fVldRange.GetDetectorMask(),
00548 fVldRange.GetSimMask(),
00549 start,
00550 end,
00551 fVldRange.GetDataSource() );
00552 fVldRange = range;
00553
00554 }
00555
00556
00557
00558 void TDbiValidityRec::Store(TDbiOutRowStream& ors,
00559 const TDbiValidityRec* ) const {
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 ors << fSeqNo
00586 << fVldRange.GetTimeStart()
00587 << fVldRange.GetTimeEnd();
00588 if ( ors.HasEpoch() ) ors << fEpoch << fReality;
00589 ors << fVldRange.GetDetectorMask()
00590 << fVldRange.GetSimMask()
00591 << fTask
00592 << fAggregateNo
00593 << fCreationDate
00594 << fInsertDate;
00595 }
00596
00597
00598 void TDbiValidityRec::Streamer(TDbiBinaryFile& file) {
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609 if ( file.IsReading() ) {
00610 file >> fAggregateNo
00611 >> fCreationDate
00612 >> fEpoch
00613 >> fReality
00614 >> fDbNo
00615 >> fInsertDate
00616 >> fIsGap
00617 >> fTask
00618 >> fSeqNo
00619 >> fVldRange;
00620 fTableProxy = 0;
00621 }
00622 else if ( file.IsWriting() ) {
00623 file << fAggregateNo
00624 << fCreationDate
00625 << fEpoch
00626 << fReality
00627 << fDbNo
00628 << fInsertDate
00629 << fIsGap
00630 << fTask
00631 << fSeqNo
00632 << fVldRange;
00633 }
00634 }
00635
00636
00637
00638 void TDbiValidityRec::Trim(const TVldTimeStamp& queryTime,
00639 const TDbiValidityRec& other) {
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690 if ( fAggregateNo != other.fAggregateNo || other.IsGap() ) return;
00691
00692
00693
00694
00695 if ( ! IsGap() ) return;
00696
00697 TVldTimeStamp start = fVldRange.GetTimeStart();
00698 TVldTimeStamp end = fVldRange.GetTimeEnd();
00699 TVldTimeStamp startOther = other.GetVldRange().GetTimeStart();
00700 TVldTimeStamp endOther = other.GetVldRange().GetTimeEnd();
00701
00702
00703
00704
00705 if ( startOther <= queryTime && endOther > queryTime ) {
00706 if ( start < startOther ) start = startOther;
00707 if ( end > endOther ) end = endOther;
00708 *this = other;
00709 SetTimeWindow(start,end);
00710 }
00711
00712
00713
00714 else {
00715
00716 if ( endOther <= queryTime ) {
00717 if ( start < endOther ) SetTimeWindow(endOther,end);
00718 }
00719 else if ( startOther > queryTime ) {
00720 if ( end > startOther ) SetTimeWindow(start, startOther);
00721 }
00722 }
00723
00724 }
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757