DcsRadonLevelFinder Class Reference

#include <DcsRadonLevelFinder.h>

List of all members.

Public Member Functions

 DcsRadonLevelFinder ()
 DcsRadonLevelFinder (VldTimeStamp start, VldTimeStamp end, Detector::Detector_t detector)
virtual ~DcsRadonLevelFinder ()
const std::vector< const
Dcs_Radon_Level * > 
GetRadonLevelTable () const
Float_t GetRadonLevel (VldContext context, Int_t numPoints=0)
Float_t GetRadonLevel (VldTimeStamp date, Detector::Detector_t detector, Int_t numPoints=0)
Bool_t HasGoodData (VldTimeStamp date, Detector::Detector_t detector) const
void NewQuery (VldTimeStamp start, VldTimeStamp end, Detector::Detector_t detector)

Static Public Member Functions

static DcsRadonLevelFinderInstance ()

Private Attributes

DbiResultPtr< Dcs_Radon_LevelfQueryResults
std::vector< const
Dcs_Radon_Level * > 
fRadonLevelTable
Detector::Detector_t fDetector
Bool_t IsGlobalVersion

Static Private Attributes

static DcsRadonLevelFinderfgDcsRadonLevelFinder = 0

Detailed Description

Id
DcsRadonLevelFinder.h,v 1.1 2009/06/02 21:24:56 nwest Exp

Definition at line 66 of file DcsRadonLevelFinder.h.


Constructor & Destructor Documentation

DcsRadonLevelFinder::DcsRadonLevelFinder (  ) 

Definition at line 37 of file DcsRadonLevelFinder.cxx.

Referenced by Instance().

00037                                          :
00038   fDetector(Detector::kNear),
00039   IsGlobalVersion(false) {
00040 
00041 }

DcsRadonLevelFinder::DcsRadonLevelFinder ( VldTimeStamp  start,
VldTimeStamp  end,
Detector::Detector_t  detector 
)

Definition at line 45 of file DcsRadonLevelFinder.cxx.

References NewQuery().

00045                                                                                                           :
00046   fDetector(Detector::kNear),
00047   IsGlobalVersion(false) {
00048   this->NewQuery(start,end,detector);
00049 
00050 }

virtual DcsRadonLevelFinder::~DcsRadonLevelFinder (  )  [inline, virtual]

Definition at line 73 of file DcsRadonLevelFinder.h.

00073 { };


Member Function Documentation

Float_t DcsRadonLevelFinder::GetRadonLevel ( VldTimeStamp  date,
Detector::Detector_t  detector,
Int_t  numPoints = 0 
)

Definition at line 79 of file DcsRadonLevelFinder.cxx.

References fRadonLevelTable, Dcs_Radon_Level::GetRadonLevel(), VldTimeStamp::GetSeconds(), Dcs_Radon_Level::GetTimeStamp(), HasGoodData(), IsGlobalVersion, Dcs_Radon_Level::IsValidEntry(), MAX_POINTS, NewQuery(), TIME_MARGIN, and TIME_WINDOW.

00079                                                                                                                     {
00080 
00081   //  Return the radon level in detector 'detector' at date 'date' or -999. if unable to get the value.
00082   //  If numPoints <= 0 do linear interpolation between the closest two points in time.
00083   //  If numPoints >  0 find average of the numPoints nearest points in time.
00084 
00085   // If the current data is no good perform a new query if permitted.
00086   if ( ! this->HasGoodData(date,detector) ) {
00087     // Privately owned objects are not automatically updated when the current data is no good.
00088     if ( ! IsGlobalVersion ) return -999.;
00089 
00090     // For the Singleton (public) object form a new query with the required date near the start of the
00091     // range in anticipation that future queries will use later dates.
00092     this->NewQuery(VldTimeStamp(date.GetSeconds() - 2*TIME_MARGIN),
00093                    VldTimeStamp(date.GetSeconds() + TIME_WINDOW),
00094                    detector);
00095     if ( ! this->HasGoodData(date,detector) ) return -999.;
00096   }
00097 
00098   // Collect data points near in time to the request date into a buffer.
00099   struct data_point {Float_t relative_time; Float_t level;};
00100 #define MAX_POINTS 50
00101   data_point buff[MAX_POINTS];
00102 
00103   if ( numPoints > MAX_POINTS ) numPoints = MAX_POINTS;
00104 
00105   // If interpolating use nearest 2 points.
00106   Bool_t interpolate = false;
00107   if ( numPoints <= 0 ) {
00108     interpolate = true;
00109     numPoints   = 2;
00110   }
00111 
00112   // Process rows of fRadonLevelTable until buff contains the nearest numPoints of data to required date.
00113   Bool_t tableFull = false;
00114   Int_t nextSlot   = 0; 
00115 
00116   Float_t required_time(date.GetSeconds());
00117   Int_t numRows(fRadonLevelTable.size());
00118 
00119   for (Int_t i_row = 0; i_row < numRows; ++i_row ) {
00120     const Dcs_Radon_Level& row(*fRadonLevelTable[i_row]);
00121     if ( ! row.IsValidEntry() ) continue;
00122     Float_t relative_time(row.GetTimeStamp().GetSeconds() - required_time);
00123 
00124     // Once the buffer is full, only continue to collect data if the 
00125     // current point is nearer that the one it is replacing.
00126     if ( tableFull && abs(buff[nextSlot].relative_time) < abs(relative_time) ) break;
00127     buff[nextSlot].relative_time = relative_time;
00128     buff[nextSlot].level         = row.GetRadonLevel();
00129     ++nextSlot;
00130     if ( nextSlot >=  numPoints ) {
00131       tableFull = true;
00132       nextSlot  = 0;
00133     }
00134 
00135   }
00136 
00137   // Determine the number of points in the buffer and deal with cases of 0 or 1 points
00138   if ( ! tableFull ) numPoints = nextSlot;
00139 
00140   if ( numPoints == 0 ) return -999.;
00141   if ( numPoints == 1 ) return buff[0].level;
00142 
00143   // Deal with 2 point interpolation.
00144   if ( interpolate ) {
00145     Float_t t1(buff[0].relative_time);
00146     Float_t t2(buff[1].relative_time);
00147     Float_t l1(buff[0].level);
00148     Float_t l2(buff[1].level);
00149     if ( t1 == t2 ) return (l1+l2)/2.;
00150     return (t1*l2 - t2*l1)/(t1-t2);
00151   }
00152 
00153   // Deal with average
00154   Float_t sum_l(0.);
00155   for (Int_t i_point = 0; i_point < numPoints; ++i_point ) sum_l += buff[i_point].level;
00156   return sum_l/numPoints;
00157 
00158 }

Float_t DcsRadonLevelFinder::GetRadonLevel ( VldContext  context,
Int_t  numPoints = 0 
)

Definition at line 64 of file DcsRadonLevelFinder.cxx.

References VldContext::GetDetector(), VldContext::GetSimFlag(), VldContext::GetTimeStamp(), SimFlag::kData, Detector::kFar, and Detector::kNear.

00064                                                                                         {
00065 
00066   // See: GetRadonLevel(VldTimeStamp date, Detector::Detector_t detector, Int_t numPoints = 0);
00067 
00068   VldTimeStamp date(context.GetTimeStamp());
00069   Detector::Detector_t detector(context.GetDetector());
00070   SimFlag::SimFlag_t simflag(context.GetSimFlag());
00071   // Only have tables for Near and Far data.
00072   if ( simflag !=  SimFlag::kData || ( detector != Detector::kNear && detector != Detector::kFar ) ) return -999.;
00073   return this->GetRadonLevel(date,detector,numPoints);
00074 
00075 }

const std::vector<const Dcs_Radon_Level*> DcsRadonLevelFinder::GetRadonLevelTable (  )  const [inline]

Definition at line 79 of file DcsRadonLevelFinder.h.

References fRadonLevelTable.

00079 {return fRadonLevelTable;}

Bool_t DcsRadonLevelFinder::HasGoodData ( VldTimeStamp  date,
Detector::Detector_t  detector 
) const

Definition at line 163 of file DcsRadonLevelFinder.cxx.

References fDetector, fRadonLevelTable, VldTimeStamp::GetSeconds(), and TIME_MARGIN.

Referenced by GetRadonLevel().

00163                                                                                             {
00164 
00165   //  Return true if the current fRadonLevelTable is can be used to satisfy query for supplied date and detector
00166 
00167   if ( detector != fDetector ) return false;
00168 
00169   Int_t numRows(fRadonLevelTable.size());
00170   if ( numRows < 1 )  return false;
00171   if (    fRadonLevelTable[0]->GetTimeStamp()         > VldTimeStamp(date.GetSeconds() - TIME_MARGIN)
00172        or fRadonLevelTable[numRows-1]->GetTimeStamp() < VldTimeStamp(date.GetSeconds() + TIME_MARGIN) )  return false;
00173   return true;
00174 
00175 }

DcsRadonLevelFinder * DcsRadonLevelFinder::Instance (  )  [static]

Definition at line 54 of file DcsRadonLevelFinder.cxx.

References DcsRadonLevelFinder(), fgDcsRadonLevelFinder, and IsGlobalVersion.

00054                                                    {
00055   if (! fgDcsRadonLevelFinder ) {
00056     fgDcsRadonLevelFinder = new DcsRadonLevelFinder();
00057     fgDcsRadonLevelFinder->IsGlobalVersion = true;
00058   }
00059   return fgDcsRadonLevelFinder;
00060 }

void DcsRadonLevelFinder::NewQuery ( VldTimeStamp  start,
VldTimeStamp  end,
Detector::Detector_t  detector 
)

Definition at line 179 of file DcsRadonLevelFinder.cxx.

References fDetector, fQueryResults, fRadonLevelTable, DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), SimFlag::kData, DbiSqlContext::kOverlaps, and DbiResultPtr< T >::NewQuery().

Referenced by DcsRadonLevelFinder(), and GetRadonLevel().

00179                                                                                                     {
00180 
00181   // Construct query.
00182   DbiSqlContext sqlContext(DbiSqlContext::kOverlaps,start,end,detector,SimFlag::kData);
00183 
00184   // Execute query.
00185   fQueryResults.NewQuery(sqlContext,0);
00186 
00187   // Perpare time ordered vector of pointers to the results.
00188   Int_t numRows(fQueryResults.GetNumRows());
00189   fRadonLevelTable.resize(numRows); 
00190   for (Int_t i_row = 0; i_row < numRows; ++i_row) fRadonLevelTable[i_row] = fQueryResults.GetRow(i_row);
00191   sort(fRadonLevelTable.begin(),fRadonLevelTable.end(),earlier());
00192 
00193   fDetector = detector;
00194 
00195 }


Member Data Documentation

Definition at line 98 of file DcsRadonLevelFinder.h.

Referenced by HasGoodData(), and NewQuery().

Definition at line 92 of file DcsRadonLevelFinder.h.

Referenced by Instance().

Definition at line 95 of file DcsRadonLevelFinder.h.

Referenced by NewQuery().

Definition at line 96 of file DcsRadonLevelFinder.h.

Referenced by GetRadonLevel(), GetRadonLevelTable(), HasGoodData(), and NewQuery().

Definition at line 101 of file DcsRadonLevelFinder.h.

Referenced by GetRadonLevel(), and Instance().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1