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

SpillTimeFinder.h

Go to the documentation of this file.
00001 #ifndef SPILLTIMEFINDER_H
00002 #define SPILLTIMEFINDER_H
00003 
00004 #include "Configurable/CfgPromptConfigurable.h"
00005 #include "DatabaseInterface/DbiResultPtr.h"
00006 #include "SpillTimeND.h"
00007 #include "SpillTimeCalibration.h"
00008 #include <TObject.h>
00009 
00010 class SpillTimeFinder : public CfgPromptConfigurable, public TObject {
00011  public:
00012   static SpillTimeFinder& Instance();
00013   
00014   // Get the best match to a spill. Use context to 
00015   // find out whether we're making an inquiry about the ND or the FD.
00016   //
00017   // Note: to get the correct answer, use the default max_search.
00018   // To get an answer quickly, use a value of the maximum window that
00019   // you care about (i.e. 10.0 = don't bother looking for spills more than 10 seconds
00020   // away).  The result may be correct, but will be larger than your limit.
00021   // 
00022   Bool_t DataIsAvailable( const VldContext& context );
00023 
00024   const SpillTimeND& GetRecentSpill(const VldContext& context);
00025   const SpillTimeND& GetNextSpill(const VldContext& context);
00026   const SpillTimeND& GetNearestSpill(const VldContext& context);
00027 
00028   VldTimeStamp GetTimeOfRecentSpill(const VldContext& cx);
00029   VldTimeStamp GetTimeOfNextSpill(const VldContext& cx);
00030   VldTimeStamp GetTimeOfNearestSpill(const VldContext& cx);
00031 
00032   Double_t GetTimeToRecentSpill(const VldContext& cx);
00033   Double_t GetTimeToNextSpill(const VldContext& cx);
00034   Double_t GetTimeToNearestSpill(const VldContext& cx);
00035 
00036   VldTimeStamp GetLastQueryRangeBeg() { return fLastQueryRangeBeg; };
00037   VldTimeStamp GetLastQueryRangeEnd() { return fLastQueryRangeEnd; };
00038 
00039 
00040   SpillTimeFinder(); // Constructor
00041   virtual ~SpillTimeFinder(); // dtor
00042 
00043  private:
00044   virtual void ConfigModified();
00045  
00046 
00047   // What all the others use:
00048   void FindClosestEntries(const VldContext& inContext,
00049                           const SpillTimeND* &outPrev,
00050                           const SpillTimeND* &outNext
00051                           ); // Return rows closest to context.
00052 
00053   void FindBestRows(DbiResultPtr<SpillTimeND> &table,
00054                     const VldTimeStamp& time, 
00055                     const SpillTimeND* &outPrev,
00056                     const SpillTimeND* &outNext); // Searches current table with binary search.
00057 
00058 
00059   Double_t GetOffset(const VldContext& context, Int_t task); //Return time offset between ND and FD
00060   Double_t GetOffsetNDNuToFDNu(const VldContext& context); //Return time offset between ND and FD
00061   Double_t GetOffsetKickerToNDNu(const VldContext& context); //Return time offset between ND and Kicker
00062   Double_t GetOffsetSgateToNDNu(const VldContext& context); //Return time offset between ND and Kicker
00063   Double_t GetTimeDifference(const VldTimeStamp& t1, const VldTimeStamp& v2);
00064 
00065   void ResetCache();
00066 
00067   DbiResultPtr<SpillTimeND> fCurrentTable;
00068   DbiResultPtr<SpillTimeND>* fPrevTable;
00069   DbiResultPtr<SpillTimeND>* fNextTable;
00070 
00071   DbiResultPtr<SpillTimeCalibration> fCalibrationNDNuToFDNu;
00072   DbiResultPtr<SpillTimeCalibration> fCalibrationKickerToNDNu;
00073   DbiResultPtr<SpillTimeCalibration> fCalibrationSgateToNDNu;
00074 
00075   // last query info:
00076   SpillTimeND fLastQueryPrev;
00077   SpillTimeND fLastQueryNext;
00078   VldTimeStamp fLastQueryRangeBeg;
00079   VldTimeStamp fLastQueryRangeEnd;
00080 
00081   // Configuration:
00082   Int_t fTask;
00083 
00084   // This section sets up the singleton machinery.
00085   // Cleaner struct used to clean up singleton at end of job
00086   struct Cleaner {
00087     void UseMe() { }                  // Dummy method to quiet compiler
00088     ~Cleaner() {
00089       if (SpillTimeFinder::fgInstance != 0) {
00090         delete SpillTimeFinder::fgInstance;
00091         SpillTimeFinder::fgInstance = 0;
00092       } }
00093   };
00094   friend struct Cleaner;
00095   static SpillTimeFinder* fgInstance;
00096   
00097   
00098   
00099   ClassDef(SpillTimeFinder,0)
00100 };
00101 
00102 inline Double_t SpillTimeFinder::GetTimeToRecentSpill(const VldContext& cx)
00103 {
00104   return GetTimeDifference(GetTimeOfRecentSpill(cx),cx.GetTimeStamp()); 
00105 }
00106 
00107 inline Double_t SpillTimeFinder::GetTimeToNextSpill(const VldContext& cx)    
00108 {
00109   return GetTimeDifference(GetTimeOfNextSpill(cx),cx.GetTimeStamp()); 
00110 }
00111 
00112 inline Double_t SpillTimeFinder::GetTimeToNearestSpill(const VldContext& cx)
00113 {
00114   return GetTimeDifference(GetTimeOfNearestSpill(cx),cx.GetTimeStamp()); 
00115 }
00116 
00117 
00118 
00119 #endif

Generated on Mon Feb 15 11:07:38 2010 for loon by  doxygen 1.3.9.1