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