00001 #ifndef MAGNETICFIELDSVC_H 00002 #define MAGNETICFIELDSVC_H 00003 00004 // Include files 00005 #include <vector> 00006 #include <string> 00007 #include "CLHEP/Geometry/Vector3D.h" 00008 #include "CLHEP/Geometry/Point3D.h" 00009 #ifndef ENABLE_BACKWARDS_COMPATIBILITY 00010 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00011 typedef HepGeom::Point3D<double> HepPoint3D; 00012 typedef HepGeom::Vector3D<double> HepVector3D; 00013 #endif 00014 #include "MagneticField/ConnectionDB.h" 00015 00016 #ifndef BEAN 00017 #include "GaudiKernel/Service.h" 00018 //#include "GaudiKernel/IMagneticFieldSvc.h" 00019 #include "MagneticField/IMagneticFieldSvc.h" 00020 #include "GaudiKernel/IIncidentListener.h" 00021 using namespace CLHEP; 00022 00023 // Forward declarations 00024 template <class TYPE> class SvcFactory; 00025 00026 class IMagneticFieldSvc; 00027 class MucMagneticField; 00028 class IDataProviderSvc; 00029 #else 00030 class MucMagneticField; 00031 typedef bool StatusCode; 00032 #endif 00033 00040 #ifndef BEAN 00041 class MagneticFieldSvc : public Service, 00042 virtual public IMagneticFieldSvc, 00043 virtual public IIncidentListener { 00044 00045 protected: 00046 00050 MagneticFieldSvc( const std::string& name, ISvcLocator* svc ); 00051 00053 virtual ~MagneticFieldSvc(); 00054 00055 public: 00056 00058 virtual StatusCode initialize(); 00059 00060 void init_params(); 00061 00063 virtual StatusCode finalize(); 00064 00070 virtual StatusCode queryInterface( const InterfaceID& riid, 00071 void** ppvInterface ); 00072 00074 virtual const InterfaceID& type() const { return IMagneticFieldSvc::interfaceID(); }; 00075 00076 00077 // Incident handler 00078 void handle(const Incident&); 00079 00080 #else 00081 // -------------------------- BEAN ------------------------------------ 00082 class MagneticFieldSvc { 00083 00084 public: 00085 static MagneticFieldSvc* instance() { 00086 return (m_field) ? m_field : (m_field=new(std::nothrow)MagneticFieldSvc()); 00087 } 00088 00089 private: 00090 MagneticFieldSvc(); 00091 virtual ~MagneticFieldSvc(); 00092 00093 public: 00094 void SetPath(std::string new_path) {path = new_path;} 00095 std::string GetPath() {return path;} 00096 00097 void GridDistance( int gridDistance = 5) {m_gridDistance = gridDistance;} 00098 void RunMode( int runmode = 2) {m_runmode = runmode;} 00099 void IfRealField( bool ifRealField = true) {m_ifRealField = ifRealField;} 00100 void OutLevel( int outlevel = 1) {m_outlevel = outlevel;} 00101 00102 void Cur_SCQ1_55( double Cur_SCQ1_55 = 349.4) {m_Cur_SCQ1_55 = Cur_SCQ1_55;} 00103 void Cur_SCQ1_89( double Cur_SCQ1_89 = 426.2) {m_Cur_SCQ1_89 = Cur_SCQ1_89;} 00104 void Cur_SCQ2_10( double Cur_SCQ2_10 = 474.2) {m_Cur_SCQ2_10 = Cur_SCQ2_10;} 00105 00106 void UseDBFlag( bool useDB = true) {m_useDB = useDB;} 00107 00109 bool init_mucMagneticField(); 00110 virtual StatusCode initialize(); 00111 void init_params(int run); 00112 00113 // handler for new run 00114 void handle(int new_run); 00115 #endif 00116 00122 virtual StatusCode fieldVector( const HepPoint3D& xyz, 00123 HepVector3D& fvec ) const; 00124 00125 virtual StatusCode uniFieldVector( const HepPoint3D& xyz, 00126 HepVector3D& fvec ) const; 00127 00128 virtual double getReferField(); 00129 00130 virtual bool ifRealField() const; 00131 00132 00133 private: 00134 #ifndef BEAN 00136 friend class SvcFactory<MagneticFieldSvc>; 00137 #else 00138 static MagneticFieldSvc* m_field; 00139 #endif 00140 00142 void fieldGrid( const HepPoint3D& xyz, HepVector3D& fvec ) const; 00143 void fieldGrid_TE( const HepPoint3D& xyz, HepVector3D& fvec ) const; 00144 00145 StatusCode parseFile( ); 00146 StatusCode parseFile_TE( ); 00147 00148 std::string path; // path to data files 00149 00150 std::string m_filename; 00151 std::string m_filename_TE; 00152 int m_runmode; 00153 int m_gridDistance; 00154 int m_outlevel; 00155 double m_scale; 00156 00157 double m_Cur_SCQ1_55; 00158 double m_Cur_SCQ1_89; 00159 double m_Cur_SCQ2_10; 00160 00161 std::vector<double> m_Q; 00162 std::vector<double> m_P; 00163 std::vector<double> m_Q_TE; 00164 std::vector<double> m_P_TE; 00165 std::vector<double> m_Q_1; 00166 std::vector<double> m_P_1; 00167 std::vector<double> m_Q_2; 00168 std::vector<double> m_P_2; 00169 double m_Dxyz[3]; 00170 int m_Nxyz[3]; 00171 double m_max_FL[3]; 00172 double m_min_FL[3]; 00173 //for tof and emc 00174 double m_Dxyz_TE[3]; 00175 int m_Nxyz_TE[3]; 00176 double m_max_FL_TE[3]; 00177 double m_min_FL_TE[3]; 00178 00179 double m_zOffSet; 00180 double m_zOffSet_TE; 00181 MucMagneticField* m_Mucfield; 00182 double m_zfield; 00183 bool m_ifRealField; 00184 00185 //property 00186 bool m_useDB; 00187 00188 bool m_turnOffField; 00189 bool m_uniField; 00190 00191 #ifndef BEAN 00192 IDataProviderSvc* m_eventSvc; 00193 #endif 00194 00195 //database 00196 FieldDBUtil::ConnectionDB* m_connect_run; 00197 }; 00198 00199 #endif // MAGNETICFIELDSVC_H