BDSpillAccessor Class Reference
[BeamDataUtil]

Access per-spill info. More...

#include <BDSpillAccessor.h>

List of all members.

Public Member Functions

 ~BDSpillAccessor ()
const BeamMonSpillLoadSpill (TTimeStamp tts, int which=0)
const BeamMonSpillLoadSpill (VldTimeStamp vts, int which=0)

Static Public Member Functions

static BDSpillAccessorGet ()

Private Member Functions

 BDSpillAccessor ()
void SeekClosest (const VldTimeStamp &vts, const BeamMonSpill *&before, const BeamMonSpill *&after)
void TableSearch (DbiResultPtr< BeamMonSpill > &table, const VldTimeStamp &vts, const BeamMonSpill *&before, const BeamMonSpill *&after)
void CalibrateSpill (const BeamMonSpill *spill)

Private Attributes

DbiResultPtr< BeamMonSpill > * fPrevPtr
DbiResultPtr< BeamMonSpill > * fCenterPtr
DbiResultPtr< BeamMonSpill > * fNextPtr
DbiResultKey fResKey
bool fNeedNext
bool fNeedPrev

Static Private Attributes

static BDSpillAccessorfInstance = 0

Detailed Description

Access per-spill info.

This class provides easy access to the per-spill database table.

Note:
This has been heavily ripped from SpillTimeFinder (by N.Tagg).
Author:
(last to touch it)
Author
rhatcher
Version:
Revision
1.13
Date:
Date
2013/09/17 03:31:49

Contact: bv@bnl.gov

Created on: Fri Apr 29 16:12:21 2005

Id
BDSpillAccessor.h,v 1.13 2013/09/17 03:31:49 rhatcher Exp

Definition at line 39 of file BDSpillAccessor.h.


Constructor & Destructor Documentation

BDSpillAccessor::~BDSpillAccessor (  ) 

Definition at line 31 of file BDSpillAccessor.cxx.

References fCenterPtr, fNextPtr, and fPrevPtr.

00032 {
00033     if (fPrevPtr)   delete fPrevPtr;
00034     if (fCenterPtr) delete fCenterPtr;
00035     if (fNextPtr)   delete fNextPtr;
00036     fPrevPtr = fCenterPtr = fNextPtr = 0;
00037 }

BDSpillAccessor::BDSpillAccessor (  )  [private]

Definition at line 23 of file BDSpillAccessor.cxx.

Referenced by Get().

00024     : fPrevPtr(0)
00025     , fCenterPtr(new DbiResultPtr<BeamMonSpill>)
00026     , fNextPtr(0)
00027     , fNeedNext(true)
00028     , fNeedPrev(true)
00029 {
00030 }


Member Function Documentation

void BDSpillAccessor::CalibrateSpill ( const BeamMonSpill spill  )  [private]

Definition at line 181 of file BDSpillAccessor.cxx.

References BeamMonSpill::bits, BeamMonSpill::fHornCur, BeamMonSpill::fStatus, BeamMonSpill::fTortgt, BeamMonSpill::fTrtgtd, VldTimeStamp::GetSec(), and BeamMonSpill::SpillTime().

Referenced by LoadSpill().

00182 {
00183     // Apply corrections to the data pulled out of the batabase
00184     //
00185     // Apply corrections to tortgt
00186     // From Mary:
00187     // (Corrected for the new values from Sasha after he realised
00188     // that he had distributed the wrong numbers - 2005-11-16)
00189     //
00190     // Recommend only using TORTGT. There were several iterations of changes
00191     // applied to TOR101 in early June. It was recalibrated again on July 22
00192     // (-4.0%). TORTGT was changed only once - on July 26th.
00193     //
00194     // TORTGT calibrations (same calibrations apply to TRTGTD (20080313)):
00195     // --------------------
00196     // Before July 26th 2:17:41 GMT Doug Jensens calibrations indicate a
00197     // correction of -4.0% to the ACNET values of TORTGT.
00198     //
00199     // The period July 26th 2:17:41 GMT to August 1st 22:43:23 GMT is when the
00200     // Beam data process was applying the wrong ACNET hardware calibration. The
00201     // BDP correction is -12.6%. There is a further correction of -0.0 % based on
00202     // Doug Jensens studies = -12.6% total
00203     //
00204     // After August 1st 22:43:23 the only correction needed is Doug Jensen's
00205     // -0.0%.
00206     //
00207     BeamMonSpill* spill_cor = const_cast<BeamMonSpill*>(spill);
00208 
00209     // Avoid double calibration
00210     if (spill_cor->fStatus.bits.calibrated) return;
00211     spill_cor->fStatus.bits.calibrated = 1;
00212 
00213     int timesec = spill_cor->SpillTime().GetSec();
00214     double tortgt_cor = 1.0;
00215     double trtgtd_cor = 1.0;
00216     //  Before July 26th, 2005  2:17:41 UTC
00217     if (timesec < 1122344261) 
00218     {
00219       tortgt_cor = 0.96;
00220       trtgtd_cor = 0.96;
00221     }
00222     // After previous date but before Aug 1st 2005 22:43:23
00223     else if (timesec < 1122936203)
00224     { 
00225       tortgt_cor = 0.874;
00226       trtgtd_cor = 0.874;
00227     }
00228     // after previous date
00229     else 
00230     {
00231       tortgt_cor = 1.0;
00232       trtgtd_cor = 1.0;
00233     }
00234     //
00235     spill_cor->fTortgt *= tortgt_cor;
00236     spill_cor->fTrtgtd *= trtgtd_cor;
00237     //
00238     // Horn Current Calibrations
00239     // -------------------------
00240     // From Jim Hylen (2005-10-28):
00241     //   A -1.6% change applied to total horn current would be fine -
00242     //   the individual offsets etc. are pretty minor.
00243     //   So far there is no known time dependence.
00244     //
00245     // There was a miscommunication about the direction of the change,
00246     // the total horn current should be larger by 1.8%.  
00247     //
00248     double horcur_cor = 0.982;
00249     spill_cor->fHornCur /= horcur_cor;
00250 }    

BDSpillAccessor & BDSpillAccessor::Get (  )  [static]
const BeamMonSpill * BDSpillAccessor::LoadSpill ( VldTimeStamp  vts,
int  which = 0 
)

Definition at line 45 of file BDSpillAccessor.cxx.

References CalibrateSpill(), Msg::kDebug, MSG, SeekClosest(), and BeamMonSpill::SpillTime().

00046 {
00047     const BeamMonSpill *before=0, *after=0;
00048     this->SeekClosest(vts,before,after);
00049 
00050     // Apply corrections and calibrations
00051     //cout << "before: "  << before->fTortgt << endl;
00052     if (before) this->CalibrateSpill(before);
00053     //cout << "after: "  << before->fTortgt << endl;
00054     if (after) this->CalibrateSpill(after);
00055     
00056     if (which < 0) return before;
00057     if (which > 0) return after;
00058 
00059     if (!before) return after;
00060     if (!after) return before;
00061 
00062     VldTimeStamp vts_before = before->SpillTime();
00063     VldTimeStamp vts_after = after->SpillTime();
00064 
00065     MSG("BDU",Msg::kDebug)
00066        << vts_before << " " << vts << " " << vts_after << endl;
00067 
00068     if (vts - vts_before < vts_after - vts)
00069         return before;
00070     return after;
00071 
00072 }

const BeamMonSpill * BDSpillAccessor::LoadSpill ( TTimeStamp  tts,
int  which = 0 
)
void BDSpillAccessor::SeekClosest ( const VldTimeStamp vts,
const BeamMonSpill *&  before,
const BeamMonSpill *&  after 
) [private]

Definition at line 75 of file BDSpillAccessor.cxx.

References det, fCenterPtr, fNeedNext, fNeedPrev, fNextPtr, fPrevPtr, fResKey, DbiResultPtr< T >::GetKey(), DbiValidityRec::GetSeqNo(), VldRange::GetTimeEnd(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), DbiResultKey::IsEqualTo(), SimFlag::kData, Msg::kDebug, Msg::kError, Detector::kNear, MSG, DbiResultPtr< T >::NewQuery(), BeamMonSpill::SpillTime(), and TableSearch().

Referenced by LoadSpill().

00078 {
00079     Detector::Detector_t det = Detector::kNear;
00080     SimFlag::SimFlag_t simflag = SimFlag::kData;
00081     VldContext vc(det,simflag,vts);
00082 
00083     fCenterPtr->NewQuery(vc,0,true);
00084 
00085     if (! fResKey.IsEqualTo(fCenterPtr->GetKey()))
00086     {
00087        fNeedPrev = fNeedNext = true;
00088     }
00089     
00090     const DbiValidityRec* vr = fCenterPtr->GetValidityRec();
00091 
00092     VldTimeStamp beg = vr->GetVldRange().GetTimeStart();
00093     VldTimeStamp end = vr->GetVldRange().GetTimeEnd();
00094 
00095     before=after=0;
00096     this->TableSearch(*fCenterPtr,vts,before,after);
00097 
00098     if (before && after) return;
00099 
00100     MSG("BDU",Msg::kDebug)
00101         << vts << " not in center table, before @ " << (void*)before
00102         << " after @ " << (void*)after 
00103         << " seqno = " << vr->GetSeqNo() << endl;
00104 
00105     if (!before) {
00106        Detector::Detector_t det = Detector::kNear;
00107        SimFlag::SimFlag_t simflag = SimFlag::kData;
00108        VldContext vc(det,simflag,beg);
00109        if(!fPrevPtr || !fNeedPrev)
00110        {
00111           fPrevPtr = new DbiResultPtr<BeamMonSpill>();
00112        }
00113        fPrevPtr->NewQuery(vc,0,true);
00114               
00115        fNeedPrev = false;
00116        
00117        const BeamMonSpill* dummy=0;
00118        this->TableSearch(*fPrevPtr,vts,before,dummy);
00119        if(dummy)
00120        {
00121           MSG("BDU",Msg::kError)
00122              << "Found next time in previous table: "
00123              << dummy->SpillTime() << endl;
00124        }
00125        
00126     }
00127     if (!after){
00128        Detector::Detector_t det = Detector::kNear;
00129        SimFlag::SimFlag_t simflag = SimFlag::kData;
00130        VldContext vc(det,simflag,end);
00131        if(!fNextPtr || !fNeedNext)
00132        {
00133           fNextPtr = new DbiResultPtr<BeamMonSpill>();
00134        }
00135        fNextPtr->NewQuery(vc,0,true);
00136               
00137        fNeedNext = false;
00138        
00139        const BeamMonSpill* dummy=0;
00140        this->TableSearch(*fNextPtr,vts,dummy,after);
00141         if(dummy)
00142         {
00143            MSG("BDU",Msg::kError)
00144               << "Found previous time in next table: "
00145               << dummy->SpillTime() << endl;
00146         }
00147     }
00148     
00149 }

void BDSpillAccessor::TableSearch ( DbiResultPtr< BeamMonSpill > &  table,
const VldTimeStamp vts,
const BeamMonSpill *&  before,
const BeamMonSpill *&  after 
) [private]

Definition at line 151 of file BDSpillAccessor.cxx.

References DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), and BeamMonSpill::SpillTime().

Referenced by SeekClosest().

00155 {
00156     before = after = 0;
00157 
00158     int nrows = table.GetNumRows();
00159     if (nrows <= 0) return;
00160 
00161     double minneg = 1e10;
00162     double minpos = 1e10;
00163     for (int row = 0; row < nrows; ++row) {
00164         const BeamMonSpill* spill = table.GetRow(row);
00165         double dt = spill->SpillTime() - vts;
00166         if (dt <= 0) {
00167             if (-dt < minneg) {
00168                 minneg = -dt;
00169                 before = spill;
00170             }
00171         }
00172         else {
00173             if (dt < minpos) {
00174                 minpos = dt;
00175                 after = spill;
00176             }
00177         }
00178     }
00179 }


Member Data Documentation

Definition at line 83 of file BDSpillAccessor.h.

Referenced by SeekClosest(), and ~BDSpillAccessor().

Definition at line 41 of file BDSpillAccessor.h.

Referenced by Get().

Definition at line 85 of file BDSpillAccessor.h.

Referenced by SeekClosest().

Definition at line 85 of file BDSpillAccessor.h.

Referenced by SeekClosest().

Definition at line 83 of file BDSpillAccessor.h.

Referenced by SeekClosest(), and ~BDSpillAccessor().

Definition at line 83 of file BDSpillAccessor.h.

Referenced by SeekClosest(), and ~BDSpillAccessor().

Definition at line 84 of file BDSpillAccessor.h.

Referenced by SeekClosest().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1