#include <DcsRadonLevelFinder.h>
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 | |
| DcsRadonLevelFinder * | Instance () |
Private Attributes | |
| DbiResultPtr< Dcs_Radon_Level > | fQueryResults |
| std::vector< const Dcs_Radon_Level * > | fRadonLevelTable |
| Detector::Detector_t | fDetector |
| Bool_t | IsGlobalVersion |
Static Private Attributes | |
| DcsRadonLevelFinder * | fgDcsRadonLevelFinder = 0 |
DcsUser
To access the standard Singleton:-
DcsRadonLevelFinder& rlf(*DcsRadonLevelFinder::Instance());
Then to get the radon level for the current VldContext context:-
Float_t radon_level = rlf.GetRadonLevel(context); or Float_t radon_level = rlf.GetRadonLevel(context,numPoints);
The first method does a linear interpolation between the nearest two points. The second does an average of the nearest numPoints (<=50) points.
Both methods return -999. if unable to get a level.
To get all the radon level entries e.g. for Near detector April 2009:-
rlf.NewQuery(VldTimeStamp(2009,4,1,0,0,0),VldTimeStamp(2009,5,1,0,0,0),Detector::kNear);
const std::vector<const Dcs_Radon_Level*>& RadonLevels = rlf.GetRadonLevelTable();
for (UInt_t elem=0; elem < RadonLevels.size(); ++elem) { const Dcs_Radon_Level rl(*RadonLevels[elem]); std::cout << "Time: " << rl.GetTimeStamp() << " Level: " << rl.GetRadonLevel() << std::endl; }
The table is ordered in increasing time but may contain invalid levels (= -999.) This is an artifact of the way the data is obtained.
Users that want to own a set of results from the table should create their own DcsRadonLevelFinder
e.g. DcsRadonLevelFinder myRadonLevels(start_date,end_date,Detector::kNear)
This behaves exactly like the Singleton except that the method GetRadonLevel never performs a new query, the call NewQuery must be used explicitly.
Contact: n.west1@physics.ox.ac.uk
Definition at line 66 of file DcsRadonLevelFinder.h.
|
|
Definition at line 37 of file DcsRadonLevelFinder.cxx. References kNear. Referenced by Instance(). 00037 : 00038 fDetector(Detector::kNear), 00039 IsGlobalVersion(false) { 00040 00041 }
|
|
||||||||||||||||
|
Definition at line 45 of file DcsRadonLevelFinder.cxx. References kNear, and NewQuery(). 00045 : 00046 fDetector(Detector::kNear), 00047 IsGlobalVersion(false) { 00048 this->NewQuery(start,end,detector); 00049 00050 }
|
|
|
Definition at line 73 of file DcsRadonLevelFinder.h. 00073 { };
|
|
||||||||||||||||
|
Definition at line 79 of file DcsRadonLevelFinder.cxx. References abs(), fRadonLevelTable, Dcs_Radon_Level::GetRadonLevel(), VldTimeStamp::GetSeconds(), Dcs_Radon_Level::GetTimeStamp(), HasGoodData(), Dcs_Radon_Level::IsValidEntry(), and NewQuery(). 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 }
|
|
||||||||||||
|
Definition at line 64 of file DcsRadonLevelFinder.cxx. References VldContext::GetDetector(), VldContext::GetSimFlag(), and VldContext::GetTimeStamp(). 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 }
|
|
|
Definition at line 79 of file DcsRadonLevelFinder.h. 00079 {return fRadonLevelTable;}
|
|
||||||||||||
|
Definition at line 163 of file DcsRadonLevelFinder.cxx. References fRadonLevelTable, and VldTimeStamp::GetSeconds(). 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 }
|
|
|
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 }
|
|
||||||||||||||||
|
Definition at line 179 of file DcsRadonLevelFinder.cxx. References fDetector, fQueryResults, fRadonLevelTable, DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), 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 }
|
|
|
Definition at line 98 of file DcsRadonLevelFinder.h. Referenced by NewQuery(). |
|
|
Definition at line 23 of file DcsRadonLevelFinder.cxx. 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(), HasGoodData(), and NewQuery(). |
|
|
Definition at line 101 of file DcsRadonLevelFinder.h. Referenced by Instance(). |
1.3.9.1