Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BDSpillAccessor Class Reference
[BeamDataUtil]

Access per-spill info. More...

#include <BDSpillAccessor.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

BDSpillAccessorGet ()

Private Member Functions

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

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
mdier
Version:
Revision
1.11
Date:
Date
2005/11/02 21:48:57
Contact: bv@bnl.gov

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

Id
BDSpillAccessor.h,v 1.11 2005/11/02 21:48:57 mdier Exp

Definition at line 37 of file BDSpillAccessor.h.


Constructor & Destructor Documentation

BDSpillAccessor::BDSpillAccessor  ) 
 

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 }

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 }


Member Function Documentation

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

Definition at line 175 of file BDSpillAccessor.cxx.

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

Referenced by LoadSpill().

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

BDSpillAccessor & BDSpillAccessor::Get  )  [static]
 

Definition at line 16 of file BDSpillAccessor.cxx.

References BDSpillAccessor(), and fInstance.

Referenced by ParticleBeamMonAna::ana(), BeamMonAna::Analyze(), BDLivePlot::BDLivePlot(), BDCheckDB::CheckSpill(), MadTVAnalysis::CreatePAN(), MadTestAnalysis::CreatePAN(), MadPIDAnalysis::CreatePAN(), MadMKAnalysis::CreatePAN(), MadDpAnalysis::CreatePAN(), MadAnalysis::CreatePAN(), BDataQualityModule::EndFile(), NuExtraction::ExtractBeamInfoDB(), ANtpInfoObjectFillerBeam::FillBeamInformation(), NtpBDLiteModule::FillNtpBDLite(), NtpMaker::FillSpillInfo(), DataQualityInterface::ProcessBeamStatus(), NueBeamMonModule::Reco(), Anp::FillHeader::Run(), StndBmsSpin::Scan(), STND_BMS::Scan(), BMS_STND::Scan(), and MadQuantities::ShowerValidation().

00017 {
00018     if (!fInstance) fInstance = new BDSpillAccessor();
00019     return *fInstance;
00020 }

const BeamMonSpill * BDSpillAccessor::LoadSpill VldTimeStamp  vts,
int  which = 0
 

Get the spill closest to the given VldTimeStamp.

Returns the BeamMonSpill nearest to the given time stamp or 0 if none could be found.

which < 0 returns the nearest spill before the given time which = 0 returns the nearest spill (same as LoadSpill) which > 0 returns the nearest spill after the given time

Definition at line 39 of file BDSpillAccessor.cxx.

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

Referenced by ParticleBeamMonAna::ana(), BeamMonAna::Analyze(), BDLivePlot::BDLivePlot(), BDCheckDB::CheckSpill(), MadTVAnalysis::CreatePAN(), MadTestAnalysis::CreatePAN(), MadPIDAnalysis::CreatePAN(), MadMKAnalysis::CreatePAN(), MadDpAnalysis::CreatePAN(), MadAnalysis::CreatePAN(), BDataQualityModule::EndFile(), NuExtraction::ExtractBeamInfoDB(), ANtpInfoObjectFillerBeam::FillBeamInformation(), NtpBDLiteModule::FillNtpBDLite(), NtpMaker::FillSpillInfo(), DataQualityInterface::ProcessBeamStatus(), NueBeamMonModule::Reco(), Anp::FillHeader::Run(), StndBmsSpin::Scan(), STND_BMS::Scan(), BMS_STND::Scan(), and MadQuantities::ShowerValidation().

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

void BDSpillAccessor::SeekClosest const VldTimeStamp vts,
const BeamMonSpill *&  before,
const BeamMonSpill *&  after
[private]
 

Definition at line 69 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(), MSG, DbiResultPtr< T >::NewQuery(), BeamMonSpill::SpillTime(), and TableSearch().

Referenced by LoadSpill().

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

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

Definition at line 145 of file BDSpillAccessor.cxx.

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

Referenced by SeekClosest().

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


Member Data Documentation

DbiResultPtr<BeamMonSpill> * BDSpillAccessor::fCenterPtr [private]
 

Definition at line 78 of file BDSpillAccessor.h.

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

BDSpillAccessor * BDSpillAccessor::fInstance = 0 [static, private]
 

Definition at line 14 of file BDSpillAccessor.cxx.

Referenced by Get().

bool BDSpillAccessor::fNeedNext [private]
 

Definition at line 80 of file BDSpillAccessor.h.

Referenced by SeekClosest().

bool BDSpillAccessor::fNeedPrev [private]
 

Definition at line 80 of file BDSpillAccessor.h.

Referenced by SeekClosest().

DbiResultPtr<BeamMonSpill> * BDSpillAccessor::fNextPtr [private]
 

Definition at line 78 of file BDSpillAccessor.h.

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

DbiResultPtr<BeamMonSpill>* BDSpillAccessor::fPrevPtr [private]
 

Definition at line 78 of file BDSpillAccessor.h.

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

DbiResultKey BDSpillAccessor::fResKey [private]
 

Definition at line 79 of file BDSpillAccessor.h.

Referenced by SeekClosest().


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 05:30:25 2009 for loon by  doxygen 1.3.9.1