SpillServerMonFinder Class Reference

#include <SpillServerMonFinder.h>

List of all members.

Classes

struct  Cleaner

Public Member Functions

virtual ~SpillServerMonFinder ()
Bool_t DataIsAvailable (const VldContext &context)
const SpillServerMonGetPreviousSpill (const VldContext &context)
const SpillServerMonGetNextSpill (const VldContext &context)
const SpillServerMonGetNearestSpill (const VldContext &context)
Int_t GetSpillTimeError (const VldContext &context, Bool_t usewindow=1, Double_t window=60.0)

Static Public Member Functions

static SpillServerMonFinderInstance ()

Private Member Functions

 SpillServerMonFinder ()
void FindClosestEntries (const VldContext &context, const SpillServerMon *&prevEntry, const SpillServerMon *&nextEntry)
void FindClosestEntries (DbiResultPtr< SpillServerMon > &table, const VldTimeStamp &timestamp, const SpillServerMon *&prevEntry, const SpillServerMon *&nextEntry)
Double_t GetTimeDifference (VldTimeStamp first, VldTimeStamp second)

Private Attributes

DbiResultPtr< SpillServerMonfCurrentTable
DbiResultPtr< SpillServerMon > * fPrevTable
DbiResultPtr< SpillServerMon > * fNextTable
SpillServerMon fLastQueryPrev
SpillServerMon fLastQueryNext
Int_t fTask

Static Private Attributes

static SpillServerMonFinderfMyInstance = 0

Friends

struct Cleaner

Detailed Description

Definition at line 10 of file SpillServerMonFinder.h.


Constructor & Destructor Documentation

SpillServerMonFinder::~SpillServerMonFinder (  )  [virtual]

Definition at line 55 of file SpillServerMonFinder.cxx.

References fNextTable, fPrevTable, Msg::kVerbose, and MSG.

00056 {
00057   MSG("SpillServerMon", Msg::kVerbose) << " *** SpillServerMonFinder::~SpillServerMonFinder() *** " << endl;
00058 
00059   if(fPrevTable) delete fPrevTable;
00060   if(fNextTable) delete fNextTable;
00061 }

SpillServerMonFinder::SpillServerMonFinder (  )  [private]

Definition at line 45 of file SpillServerMonFinder.cxx.

References Msg::kVerbose, and MSG.

00045                                            :
00046   fPrevTable(0),
00047   fNextTable(0),
00048   fLastQueryPrev(kDefaultSpillFD_EndOfTime),
00049   fLastQueryNext(kDefaultSpillFD_BeginningOfTime),
00050   fTask(0)
00051 {
00052   MSG("SpillServerMon", Msg::kVerbose) << " *** SpillServerMonFinder::SpillServerMonFinder() *** " << endl;
00053 }
  


Member Function Documentation

Bool_t SpillServerMonFinder::DataIsAvailable ( const VldContext context  ) 

Definition at line 63 of file SpillServerMonFinder.cxx.

References fCurrentTable, fTask, VldTimeStamp::GetSec(), VldRange::GetTimeEnd(), VldContext::GetTimeStamp(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), DbiValidityRec::IsGap(), Msg::kDebug, Msg::kVerbose, MSG, and DbiResultPtr< T >::NewQuery().

Referenced by DataQualityInterface::ProcessDetectorStatus().

00064 {
00065   MSG("SpillServerMon", Msg::kDebug) << " *** SpillServerMonFinder::DataIsAvailable(...) *** " << endl;
00066 
00067   // check whether there is a database entry covering this vldcontext  
00068 
00069   fCurrentTable.NewQuery(context,fTask);
00070 
00071   const DbiValidityRec* vldRec = fCurrentTable.GetValidityRec();
00072   const VldRange& vldRange = vldRec->GetVldRange();
00073   VldTimeStamp start = vldRange.GetTimeStart();
00074   VldTimeStamp end = vldRange.GetTimeEnd();
00075 
00076   MSG("SpillServerMon", Msg::kVerbose) << "   timestamp = " << context.GetTimeStamp().GetSec() << endl;  
00077   MSG("SpillServerMon", Msg::kVerbose) << "   range = " << start.GetSec() << "->" << end.GetSec() << endl;
00078 
00079   if ( vldRec->IsGap () ){
00080     MSG("SpillServerMon", Msg::kDebug) << "   NO data is available " << endl;
00081     return false;
00082   }
00083   else{
00084     MSG("SpillServerMon", Msg::kDebug) << "   data is available " << endl;
00085     return true;
00086   }
00087 }

void SpillServerMonFinder::FindClosestEntries ( DbiResultPtr< SpillServerMon > &  table,
const VldTimeStamp timestamp,
const SpillServerMon *&  prevEntry,
const SpillServerMon *&  nextEntry 
) [private]

Definition at line 313 of file SpillServerMonFinder.cxx.

References DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), VldTimeStamp::GetSec(), SpillServerMon::GetSpillTime(), GetTimeDifference(), VldRange::GetTimeEnd(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), Msg::kDebug, Msg::kVerbose, Msg::kWarning, and MSG.

00314 {
00315   MSG("SpillServerMon", Msg::kDebug) << " *** SpillServerMonFinder::FindClosestEntriesInDb(...) *** " << endl;
00316 
00317   // Find the closest entries in the current table
00318   // or return null if there aren't any entries.
00319   
00320   prevEntry = 0;
00321   nextEntry = 0;
00322 
00323   const DbiValidityRec* vldRec = table.GetValidityRec();
00324 
00325   const VldRange&  vldRange = vldRec->GetVldRange();
00326   VldTimeStamp start = vldRange.GetTimeStart();
00327   VldTimeStamp end = vldRange.GetTimeEnd();
00328 
00329   if( table.GetNumRows() <=0 ){
00330     MSG("SpillServerMon",Msg::kWarning) << " This table has no rows " << endl;
00331   }
00332 
00333   double dt;
00334   double dtNeg=start.GetSec()-timestamp.GetSec()-1.0;
00335   double dtPos=end.GetSec()-timestamp.GetSec()+1.0;
00336 
00337   for(unsigned int i=0; i<table.GetNumRows(); i++){
00338     const SpillServerMon* entry = table.GetRow(i);
00339 
00340     dt = this->GetTimeDifference( timestamp, entry->GetSpillTime() );
00341 
00342     if( dt<=0.0 && dt>dtNeg ){
00343       dtNeg=dt; 
00344       prevEntry=entry;
00345     }
00346 
00347     if( dt>=0.0 && dt<dtPos ){
00348       dtPos=dt;
00349       nextEntry=entry;
00350     }
00351   }
00352 
00353   if( prevEntry ){
00354     MSG("SpillServerMon",Msg::kDebug) << " Db Search: Found previous entry at " << dtNeg << " seconds" << endl;
00355   }
00356   else{
00357     MSG("SpillServerMon",Msg::kVerbose) << " Db Search: No previous entry " << endl;
00358   }
00359 
00360   if( nextEntry ){
00361     MSG("SpillServerMon",Msg::kDebug) << " Db Search: Found next entry at +" << dtPos << " seconds" << endl;
00362   }
00363   else{
00364     MSG("SpillServerMon",Msg::kVerbose) << " Db Search: No next entry " << endl;
00365   }
00366 
00367   return;
00368 }

void SpillServerMonFinder::FindClosestEntries ( const VldContext context,
const SpillServerMon *&  prevEntry,
const SpillServerMon *&  nextEntry 
) [private]

Definition at line 185 of file SpillServerMonFinder.cxx.

References fCurrentTable, fLastQueryNext, fLastQueryPrev, fNextTable, Form(), fPrevTable, fTask, VldContext::GetDetector(), VldContext::GetSimFlag(), SpillServerMon::GetSpillTime(), VldRange::GetTimeEnd(), VldContext::GetTimeStamp(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), Dbi::kAnyTask, Msg::kDebug, kDefaultSpillFD_BeginningOfTime, kDefaultSpillFD_EndOfTime, Msg::kVerbose, Msg::kWarning, MSG, and DbiResultPtr< T >::NewQuery().

Referenced by GetNearestSpill(), GetNextSpill(), and GetPreviousSpill().

00186 {
00187   MSG("SpillServerMon", Msg::kDebug) << " *** SpillServerMonFinder::FindClosestEntries(...) *** " << endl;
00188 
00189   prevEntry = 0;
00190   nextEntry = 0;
00191 
00192   VldTimeStamp timestamp = context.GetTimeStamp();
00193 
00194   // can we return the results of the last query?
00195   if( timestamp >= fLastQueryPrev.GetSpillTime() 
00196    && timestamp <= fLastQueryNext.GetSpillTime() ){
00197     MSG("SpillServerMon", Msg::kDebug) << " Returning same results as before... " << endl;
00198     prevEntry = &fLastQueryPrev;
00199     nextEntry = &fLastQueryNext;
00200     return;
00201   }
00202   
00203   // carry out a new search on the current table
00204   MSG("SpillServerMon", Msg::kDebug) << " Searching the database... " << endl;
00205   fCurrentTable.NewQuery(context,fTask);
00206   this->FindClosestEntries(fCurrentTable,timestamp,prevEntry,nextEntry);
00207 
00208   // need to go in search of a previous entry
00209   if( prevEntry==0 ){   
00210     MSG("SpillServerMon", Msg::kDebug) << " Need to find a previous entry... " << endl;
00211     const DbiValidityRec* vldRec = fCurrentTable.GetValidityRec();
00212     const VldRange& vldRange = vldRec->GetVldRange();
00213     VldTimeStamp newstarttime(vldRange.GetTimeStart());
00214     VldTimeStamp starttime(1556150400,0);
00215 
00216     while( prevEntry==0 && newstarttime<starttime){
00217       MSG("SpillServerMon",Msg::kVerbose) << " No previous entry yet..." << endl;      
00218       MSG("SpillServerMon",Msg::kVerbose) << "  ... try start time: " << newstarttime.AsString("s") << endl;
00219 
00220       starttime=newstarttime;
00221       const char* sqltxt = Form("(TIMEEND<='%s') and (TASK=%d) and (DETECTORMASK & %d) and (SIMMASK & %d) order by TIMEEND desc limit 1",
00222                               starttime.AsString("s"),
00223                               fTask,
00224                               context.GetDetector(),
00225                               context.GetSimFlag() );
00226       
00227 
00228       DbiSqlContext prevcontext(sqltxt);
00229       if(fPrevTable) {
00230         fPrevTable->NewQuery(prevcontext,Dbi::kAnyTask);
00231       } else {
00232         fPrevTable = new DbiResultPtr<SpillServerMon>("SPILLSERVERMON",prevcontext);
00233       }
00234 
00235       const SpillServerMon* temp;
00236       this->FindClosestEntries(*fPrevTable,timestamp,prevEntry,temp);
00237 
00238       if( prevEntry ){
00239         MSG("SpillServerMon",Msg::kVerbose)
00240           << " Found a previous entry" << endl;
00241         if( temp ) {
00242           MSG("SpillServerMon",Msg::kWarning)
00243             << " potential conflict... also found a next entry! " << endl;
00244         }
00245       }
00246       else{
00247         newstarttime = fPrevTable->GetValidityRec()->GetVldRange().GetTimeStart();   
00248       }
00249     }
00250 
00251     if( prevEntry==0 ){
00252       MSG("SpillServerMon", Msg::kWarning) << " can't find the previous entry, defaulting to the beginning of time! " << endl;
00253       prevEntry = &kDefaultSpillFD_BeginningOfTime;
00254     }
00255   }
00256 
00257   // need to go in search of the next entry
00258   if( nextEntry==0 ){
00259     MSG("SpillServerMon",Msg::kVerbose) << " Need to find a next entry..." << endl;
00260 
00261     const DbiValidityRec* vldRec = fCurrentTable.GetValidityRec();
00262     const VldRange& vldRange = vldRec->GetVldRange();
00263     VldTimeStamp newendtime(vldRange.GetTimeEnd());
00264     VldTimeStamp endtime(0,0);
00265   
00266     while( nextEntry==0 && newendtime>endtime ){
00267       MSG("SpillServerMon",Msg::kVerbose) << " No next entry yet... " << endl;
00268       MSG("SpillServerMon",Msg::kVerbose) << "  ...Try end time:" << newendtime.AsString("s") << endl;
00269 
00270       endtime = newendtime;
00271       const char* sqltxt = Form("(TIMESTART>='%s') and (TASK=%d) and (DETECTORMASK & %d) and (SIMMASK & %d) order by TIMESTART asc limit 1",
00272                               endtime.AsString("s"),
00273                               fTask,
00274                               context.GetDetector(),
00275                               context.GetSimFlag() );
00276 
00277       DbiSqlContext nextcontext(sqltxt);
00278       if(fNextTable) {
00279         fNextTable->NewQuery(nextcontext,Dbi::kAnyTask);
00280       } else {
00281         fNextTable = new DbiResultPtr<SpillServerMon>("SPILLSERVERMON",nextcontext);
00282       }
00283 
00284       const SpillServerMon* temp;
00285       this->FindClosestEntries(*fNextTable,timestamp,temp,nextEntry);
00286 
00287       if( nextEntry ){
00288         MSG("SpillServerMon",Msg::kVerbose) << " Found a next entry" << endl;
00289         if( temp ) {
00290           MSG("SpillServerMon",Msg::kWarning)
00291             << " potential conflict... also found a previous entry! " << endl;
00292         }
00293       }
00294       else{ 
00295         newendtime = fNextTable->GetValidityRec()->GetVldRange().GetTimeEnd();
00296       }
00297     }
00298 
00299     if( nextEntry==0 ){
00300       MSG("SpillServerMon", Msg::kWarning) << " can't find the next entry, defaulting to the end of time! " << endl;
00301       nextEntry = &kDefaultSpillFD_EndOfTime;
00302     }
00303   }
00304 
00305   // Store the results
00306   MSG("SpillServerMon",Msg::kVerbose) << " storing the results... " << endl;
00307   fLastQueryPrev = *prevEntry;
00308   fLastQueryNext = *nextEntry;
00309 
00310   return;
00311 }

const SpillServerMon & SpillServerMonFinder::GetNearestSpill ( const VldContext context  ) 

Definition at line 115 of file SpillServerMonFinder.cxx.

References FindClosestEntries(), SpillServerMon::GetSpillTime(), GetTimeDifference(), VldContext::GetTimeStamp(), Msg::kDebug, kDefaultSpillFD_BeginningOfTime, Msg::kVerbose, Msg::kWarning, and MSG.

Referenced by MadPIDAnalysis::CreatePAN(), NuExtraction::ExtractDataQuality(), ANtpInfoObjectFillerBeam::FillBeamInformation(), GetSpillTimeError(), DataUtil::IsGoodDataGPS(), DataQualityInterface::ProcessDetectorStatus(), and Anp::FillHeader::Run().

00116 {
00117   MSG("SpillServerMon", Msg::kDebug) << " *** SpillServerMonFinder::GetNearestSpill(...) *** " << endl;
00118 
00119   const SpillServerMon* prev;
00120   const SpillServerMon* next;
00121   this->FindClosestEntries(context,prev,next);
00122 
00123   if(prev && !next){
00124     MSG("SpillServerMon", Msg::kVerbose) << " no next entry, return previous entry " << endl;
00125     return *prev;
00126   }
00127 
00128   if(!prev && next){
00129     MSG("SpillServerMon", Msg::kVerbose) << " no previous entry, return next entry " << endl;
00130     return *next;
00131   }
00132 
00133   double dtNeg=-999.9;
00134   if(prev) dtNeg = this->GetTimeDifference( prev->GetSpillTime(),
00135                                             context.GetTimeStamp() );
00136  
00137   double dtPos=-999.9;
00138   if(next) dtPos = this->GetTimeDifference( context.GetTimeStamp(),
00139                                             next->GetSpillTime() );
00140 
00141   if( dtNeg>=0 && dtPos>=0 ){
00142     MSG("SpillServerMon", Msg::kVerbose) << " dtNeg=" << dtNeg << " dtPos=" << dtPos << endl;
00143     if( dtPos<=dtNeg ) return *next; else return *prev;
00144   }
00145 
00146   MSG("SpillServerMon", Msg::kWarning) << " can't find the nearest spill, moving back to the beginning of time! " << endl;
00147   return kDefaultSpillFD_BeginningOfTime;
00148 }

const SpillServerMon & SpillServerMonFinder::GetNextSpill ( const VldContext context  ) 

Definition at line 102 of file SpillServerMonFinder.cxx.

References FindClosestEntries(), Msg::kDebug, kDefaultSpillFD_EndOfTime, Msg::kWarning, and MSG.

Referenced by GetSpillTimeError().

00103 {
00104   MSG("SpillServerMon", Msg::kDebug) << " *** SpillServerMonFinder::GetNextSpill(...) *** " << endl;
00105 
00106   const SpillServerMon* prev;
00107   const SpillServerMon* next;
00108   this->FindClosestEntries(context,prev,next);
00109   if(next) return *next;
00110 
00111   MSG("SpillServerMon", Msg::kWarning) << " can't find the next spill, defaulting to the end of time! " << endl;
00112   return kDefaultSpillFD_EndOfTime;
00113 }

const SpillServerMon & SpillServerMonFinder::GetPreviousSpill ( const VldContext context  ) 

Definition at line 89 of file SpillServerMonFinder.cxx.

References FindClosestEntries(), Msg::kDebug, kDefaultSpillFD_BeginningOfTime, Msg::kWarning, and MSG.

Referenced by GetSpillTimeError().

00090 {
00091   MSG("SpillServerMon", Msg::kDebug) << " *** SpillServerMonFinder::GetPreviousSpill(...) *** " << endl;
00092 
00093   const SpillServerMon* prev;
00094   const SpillServerMon* next;
00095   this->FindClosestEntries(context,prev,next);
00096   if(prev) return *prev;
00097 
00098   MSG("SpillServerMon", Msg::kWarning) << " can't find the previous spill, defaulting to the beginning of time! " << endl;
00099   return kDefaultSpillFD_BeginningOfTime;
00100 }

Int_t SpillServerMonFinder::GetSpillTimeError ( const VldContext context,
Bool_t  usewindow = 1,
Double_t  window = 60.0 
)

Definition at line 150 of file SpillServerMonFinder.cxx.

References GetNearestSpill(), GetNextSpill(), GetPreviousSpill(), VldTimeStamp::GetSec(), SpillServerMon::GetSpillTimeError(), GetTimeDifference(), SpillServerMon::GetTimeStamp(), VldContext::GetTimeStamp(), Msg::kDebug, Msg::kVerbose, and MSG.

00151 {
00152   MSG("SpillServerMon", Msg::kDebug) << " *** SpillServerMonFinder::GetSpillTimeError(...) *** " << endl;
00153 
00154   if( usewindow ){
00155     // return largest GPS error within a time window
00156     // only use the previous/next spill (for now)
00157     Int_t gpserror = -999;
00158     Double_t gpswindow = window;
00159     if( gpswindow<5.0 ) gpswindow=5.0;
00160 
00161     const SpillServerMon& prev = this->GetPreviousSpill(context);
00162     MSG("SpillServerMon", Msg::kVerbose) << "  prev: time=" << prev.GetTimeStamp().GetSec() << ", delta=" << this->GetTimeDifference(context.GetTimeStamp(),prev.GetTimeStamp()) << ", error=" << prev.GetSpillTimeError() << endl;
00163     if( fabs(this->GetTimeDifference(context.GetTimeStamp(),prev.GetTimeStamp()))<gpswindow ){   
00164       if( prev.GetSpillTimeError()>gpserror ) gpserror = prev.GetSpillTimeError();
00165     }
00166 
00167     const SpillServerMon& next = this->GetNextSpill(context);
00168     MSG("SpillServerMon", Msg::kVerbose) << "  next: time=" << next.GetTimeStamp().GetSec() << ", delta=" << this->GetTimeDifference(context.GetTimeStamp(),next.GetTimeStamp()) << ", error=" << next.GetSpillTimeError() << endl;
00169     if( fabs(this->GetTimeDifference(context.GetTimeStamp(),next.GetTimeStamp()))<gpswindow ){  
00170       if( next.GetSpillTimeError()>gpserror ) gpserror = next.GetSpillTimeError();
00171     }
00172 
00173     return gpserror;
00174   }
00175 
00176   else{
00177     // use the nearest spill
00178     const SpillServerMon& near = this->GetNearestSpill(context);
00179     return near.GetSpillTimeError();
00180   }
00181 
00182   return -999;
00183 }

Double_t SpillServerMonFinder::GetTimeDifference ( VldTimeStamp  first,
VldTimeStamp  second 
) [private]

Definition at line 370 of file SpillServerMonFinder.cxx.

References MuELoss::e, VldTimeStamp::GetNanoSec(), and VldTimeStamp::GetSec().

Referenced by FindClosestEntries(), GetNearestSpill(), and GetSpillTimeError().

00371 {
00372   return  ( second.GetSec()-first.GetSec() )
00373     + 1.0e-9*( second.GetNanoSec()-first.GetNanoSec() );
00374 }

SpillServerMonFinder & SpillServerMonFinder::Instance ( void   )  [static]

Definition at line 17 of file SpillServerMonFinder.cxx.

References Msg::kDebug, Msg::kFatal, MSG, and SpillServerMonFinder::Cleaner::UseMe().

Referenced by MadPIDAnalysis::CreatePAN(), NuExtraction::ExtractDataQuality(), ANtpInfoObjectFillerBeam::FillBeamInformation(), DataUtil::IsGoodDataGPS(), DataQualityInterface::ProcessDetectorStatus(), and Anp::FillHeader::Run().

00018 {
00019   MSG("SpillServerMon", Msg::kDebug) << " *** SpillServerMonFinder::Instance() *** " << endl;
00020 
00021   // Cleaner destructor calls SpillServerMonFinder dtor
00022   static Cleaner cleaner;
00023 
00024   // create singleton instance of spillfinder
00025   if(!fMyInstance){
00026     MSG("SpillServerMon", Msg::kDebug) << "  Creating new instance of SpillServerMonFinder " << endl;
00027     cleaner.UseMe();
00028     fMyInstance = new SpillServerMonFinder();
00029   }
00030 
00031   // die if finder hasn't actually been created
00032   if(!fMyInstance){
00033     MSG("SpillServerMon", Msg::kFatal) << "  No SpillServerMonFinder Instance - aagghhh, I'm going to die!!!." << endl;
00034     assert(fMyInstance);
00035   }
00036 
00037   // can do re-setting here
00038   if(fMyInstance){
00039 
00040   }
00041   
00042   return *fMyInstance;
00043 }  


Friends And Related Function Documentation

friend struct Cleaner [friend]

Definition at line 58 of file SpillServerMonFinder.h.


Member Data Documentation

Definition at line 39 of file SpillServerMonFinder.h.

Referenced by DataIsAvailable(), and FindClosestEntries().

Definition at line 44 of file SpillServerMonFinder.h.

Referenced by FindClosestEntries().

Definition at line 43 of file SpillServerMonFinder.h.

Referenced by FindClosestEntries().

Definition at line 59 of file SpillServerMonFinder.h.

Referenced by SpillServerMonFinder::Cleaner::~Cleaner().

Definition at line 41 of file SpillServerMonFinder.h.

Referenced by FindClosestEntries(), and ~SpillServerMonFinder().

Definition at line 40 of file SpillServerMonFinder.h.

Referenced by FindClosestEntries(), and ~SpillServerMonFinder().

Int_t SpillServerMonFinder::fTask [private]

Definition at line 46 of file SpillServerMonFinder.h.

Referenced by DataIsAvailable(), and FindClosestEntries().


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

Generated on 20 Jul 2017 for loon by  doxygen 1.6.1