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