00448 {
00449 //00450 // Purpose: Determine a suitable Creation Date so that this validity00451 // record, if written to the selected DB, will overlay00452 // correctly.00453 //00454 // Specification:-00455 // =============00456 //00457 // o Determine optimal Creation Date to overlay new data. See Program Notes.00458
00459 // Program Notes:-00460 // =============00461
00462
00463 // It is normal practice, particularly for calibration data, to have00464 // overlapping the validity records. Each time a new set of runs are00465 // processed the start time of the validity is set to the start time of00466 // the first run and the end time is set beyond the start time by an00467 // interval that characterises the stability of the constants. So long00468 // as a new set of constants is created before the end time is reached00469 // there will be no gap. Where there is an overlap the Creation Date is00470 // used to select the later constants on the basis that later is better.00471 // However, if reprocessing old data it is also normal practice to00472 // process recent data first and in this case the constants for earlier00473 // data get later creation dates and overlay works the wrong way. To00474 // solve this, the creation date is faked as follows:-00475 //00476 //00477 // 1. For new data i.e. data that does not overlay any existing data,00478 // the creation date is set to the validity start time.00479 //00480 // 2. For replacement data i.e. data that does overlay existing data,00481 // the creation date is set to be one minute greater than the Creation00482 // Date on the current best data.00483 //00484 // This scheme ensures that new data will overlay existing data at the 00485 // start of its validity but will be itself overlaid by data that has 00486 // a later start time (assuming validity record start times are more 00487 // than a few minutes apart)00488
00489
00490 // Create a context that corresponds to the start time of the validity00491 // range. Note that it is O.K. to use SimFlag and Detector masks 00492 // even though this could make the context ambiguous because the 00493 // context is only to be used to query the database and the SimFlag and 00494 // Detector values will be ORed against existing data so will match00495 // all possible data that this validity range could overlay which is00496 // just what we want.00497
00498 constVldRange& vr(vrec.GetVldRange());
00499 VldContext vc((Detector::Detector_t) vr.GetDetectorMask(),
00500 (SimFlag::SimFlag_t) vr.GetSimMask(),
00501 vr.GetTimeStart());
00502
00503 DbiConnectionMaintainercm(fCascader); //Stack object to hold connections00504
00505 // Build a complete set of effective validity records from the 00506 // selected database.00507 DbiValidityRecBuilder builder(fDBProxy,vc,vrec.GetTask(),dbNo);
00508
00509 // Pick up the validity record for the current aggregate.00510 constDbiValidityRec& vrecOvlay(builder.GetValidityRecFromAggNo(vrec.GetAggregateNo()));
00511
00512 // If its a gap i.e. nothing is overlayed, return the start time, otherwise00513 // return its Creation Date plus one minute.00514 VldTimeStamp ovlayTS(vr.GetTimeStart());
00515 if ( ! vrecOvlay.IsGap() ) {
00516 time_t overlaySecs = vrecOvlay.GetCreationDate().GetSec();
00517 ovlayTS = VldTimeStamp(overlaySecs + 60,0);
00518 }
00519
00520 MSG("Dbi",Msg::kDebug) << "Looking for overlay creation date for: "00521 << vrec << "found it would overlap: "00522 << vrecOvlay << " so overlay creation date set to "00523 << ovlayTS.AsString("s") << endl;
00524 return ovlayTS;
00525
00526 }