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

CoilTools.h

Go to the documentation of this file.
00001 #ifndef COILTOOLS_H
00002 #define COILTOOLS_H
00003 
00004 #include <Validity/VldTimeStamp.h>
00005 #include <Validity/VldContext.h>
00006 #include <Conventions/Detector.h>
00007 
00008 // explicit includes (private data for caching)
00009 #include <DatabaseInterface/DbiResultPtr.h>
00010 #include <DcsUser/BfldDbiCoilState.h>
00011 #include <DcsUser/Dcs_Mag_Near.h>
00012 
00013 #include <map>
00014 #include <utility>
00015 
00016 class CoilTools {
00017  public:
00018   // Singleton access
00019   static CoilTools& Instance();
00020 
00021   // Distill the raw DCS magnet tables
00022   static void Distill(VldTimeStamp start,
00023                       VldTimeStamp end,
00024                       Int_t sm, 
00025                       Float_t curr,
00026                       Detector::Detector_t NearOrFar);
00027   // For incremental additions to the DB, get the starting point
00028   static Int_t GetLast(VldTimeStamp start,  
00029                        Int_t sm,  
00030                        VldTimeStamp *LastTime,
00031                        Float_t *LastCurr,
00032                        Detector::Detector_t NearOrFar);
00033   // Set up MsgService parameters
00034   static void FixFormat();
00035 
00036   // Query DB, return true if coil state is deemed "okay"
00037   static Bool_t IsOK(const VldContext& vldc);
00038   static Bool_t IsOK(VldTimeStamp now, Detector::Detector_t det);
00039 
00040   // Query DB, return true if coil was run in reverse current direction
00041   static Bool_t IsReverse(const VldContext& vldc);
00042   static Bool_t IsReverse(VldTimeStamp now, Detector::Detector_t det);
00043 
00044   // Query DB, return coil current(s)
00045   static std::pair<Float_t,Float_t> CoilCurrent(const VldContext& vldc);
00046 
00047   // Query DB, return coil limits for IsOK
00048   static std::pair<Float_t,Float_t> CoilCurrentLimits(const VldContext& vldc);
00049 
00050   // make general case accessible
00051   // in case users need access to other fields
00052   const BfldDbiCoilState* GetCoilState(const VldContext& vldc, int ism=1);
00053   const Dcs_Mag_Near*     GetMagNear(const VldContext& vldc);
00054 
00055   // Put a row into the distilled table
00056   static void Write(VldTimeStamp start,  
00057                     VldTimeStamp end,  
00058                     Int_t sm,  
00059                     Float_t curr,
00060                     UInt_t status,
00061                     Detector::Detector_t det);
00062 
00063   // Configurables for local caching
00064   // not static functions - use CoilTools::Instance().f()
00065   void SetWindow(Int_t wsec) 
00066   { fWindow = max(wsec,60); ClearCaches(); } // min 60 seconds
00067   void SetTask(Int_t task)
00068   { fTask   = task; ClearCaches(); }
00069   void ClearCaches()
00070   { fExtendedRangeCoilState = VldRange(); 
00071     fLocalRangeCoilState    = VldRange(); 
00072     fExtendedRangeMagNear   = VldRange(); 
00073     fLocalRangeMagNear      = VldRange();
00074   }
00075 
00076   // helper function
00077   static int GetNCoils(const VldContext& vldc);
00078 
00079  private:
00080 
00081   // Figure out a status to write, prepare to do so
00082   static void WriteRow(VldTimeStamp start,  
00083                        VldTimeStamp end,  
00084                        Int_t sm,  
00085                        Float_t curr,
00086                        Detector::Detector_t NearOrFar);
00087   // Make sure we are at one of the two places with a real coil
00088   static void CheckNearOrFar(Detector::Detector_t NearOrFar);
00089 
00090   // special handlers
00091   Bool_t IsCoilStateOK(const VldContext& vldc);
00092   Bool_t IsCoilStateReverse(const VldContext& vldc);
00093   Bool_t IsMagNearOK(const VldContext& vldc);
00094   Bool_t IsMagNearReverse(const VldContext& vldc);
00095 
00096   // Constructors and destructors (private because it's a singleton)
00097   CoilTools(); 
00098   virtual ~CoilTools() { }; 
00099 
00100   // Setup the singleton machinery
00101   struct Cleaner {
00102     void UseMe() { }  // Dummy method to quiet compiler
00103     ~Cleaner() {
00104       if ( CoilTools::fgInstance != 0 ) {
00105         delete CoilTools::fgInstance;
00106         CoilTools::fgInstance = 0;
00107       }
00108     }
00109   };
00110   friend struct Cleaner;
00111   static CoilTools* fgInstance;  // the one-and-only instance
00112 
00113   // helper templated functions
00114   template <class T> 
00115     void ExtendedQuery(const VldContext& vldc,
00116                        DbiResultPtr<T>& resultPtr, VldRange& resultRange);
00117   template <class T>
00118     void LocalQuery(const VldContext& vldc, DbiResultPtr<T>& extResPtr,
00119                     std::map<int, const T*>& resultAggMap,
00120                     VldRange& resultRange);
00121 
00122   Int_t                          fWindow;
00123   Int_t                          fTask;
00124 
00125   // private data for caching purposes
00126 
00127   DbiResultPtr<BfldDbiCoilState>         fDRPCoilState;
00128   VldRange                               fExtendedRangeCoilState;
00129   VldRange                               fLocalRangeCoilState;
00130   std::map<int, const BfldDbiCoilState*> fCoilStateSet; // ref ptrs only
00131 
00132   DbiResultPtr<Dcs_Mag_Near>             fDRPMagNear;
00133   VldRange                               fExtendedRangeMagNear;
00134   VldRange                               fLocalRangeMagNear;
00135   std::map<int, const Dcs_Mag_Near*>     fMagNearSet;  // ref ptrs only
00136 
00137   ClassDef(CoilTools,0)
00138 
00139 };
00140 
00141 #endif  // COILTOOLS_H

Generated on Mon Feb 15 11:06:32 2010 for loon by  doxygen 1.3.9.1