00001
00008
00009
00010 #include "GaudiKernel/Service.h"
00011 #include "GaudiKernel/MsgStream.h"
00012 #include "GaudiKernel/SvcFactory.h"
00013 #include "GaudiKernel/Property.h"
00014
00015
00016 #include "facilities/Util.h"
00017 #include "facilities/Timestamp.h"
00018
00019 #include "astro/GPS.h"
00020
00021
00027
00028 static const InterfaceID IID_IOrbitSvc("OrbitSvc", 0, 0);
00029
00030
00031 class OrbitSvc : virtual public Service {
00032 public:
00033 OrbitSvc(const std::string& name, ISvcLocator* pSvcLocator);
00034
00035
00036
00037
00038
00040 virtual StatusCode initialize ();
00041
00043 virtual StatusCode finalize ();
00044
00046 virtual StatusCode queryInterface( const InterfaceID& riid, void** ppvUnknown );
00047
00048 private:
00049
00050 StringArrayProperty m_pointingHistory;
00051 DoubleArrayProperty m_pointingDirection;
00052 DoubleProperty m_zenithTheta;
00053 DoubleProperty m_rocking_angle;
00054
00055 };
00056
00057
00058
00059 static const SvcFactory<OrbitSvc> Factory;
00060 const ISvcFactory& OrbitSvcFactory = Factory;
00061
00062
00064 OrbitSvc::OrbitSvc(const std::string& name, ISvcLocator* svc)
00065 : Service(name,svc)
00066 {
00067
00068 declareProperty("PointingHistory", m_pointingHistory);
00069 declareProperty("pointingDirection", m_pointingDirection);
00070 declareProperty("zenithTheta", m_zenithTheta=-99);
00071 declareProperty("rocking_angle", m_rocking_angle=0);
00072
00073
00074
00075 }
00076
00078 StatusCode OrbitSvc::initialize(){
00079 StatusCode sc = StatusCode::SUCCESS;
00080 MsgStream log(msgSvc(), name());
00081 using astro::GPS;
00082
00083
00084 setProperties();
00085
00086
00087
00088 if(! m_pointingHistory.value().empty()){
00089 std::string filename(m_pointingHistory.value()[0]);
00090 facilities::Util::expandEnvVar(&filename);
00091 double offset = 0;
00092 bool horizontalflag(false);
00093 if( m_pointingHistory.value().size()>1){
00094 std::string field(m_pointingHistory.value()[1]);
00095 if(! field.empty() ) {
00096 facilities::Timestamp jt(m_pointingHistory.value()[1]);
00097 offset = (astro::JulianDate(jt.getJulian())-astro::JulianDate::missionStart())*astro::JulianDate::secondsPerDay;
00098 }
00099 }
00100
00101 if( m_pointingHistory.value().size()>2){
00102 std::string field(m_pointingHistory.value()[2]);
00103 horizontalflag =! field.empty();
00104 }
00105 log << MSG::INFO << "Loading Pointing History File : " << filename
00106 << " with MET offset "<< offset << endreq;
00107 if( horizontalflag){
00108 log << MSG::INFO << "Will override x-direction to be horizontal"<<endreq;
00109 }
00110
00111 astro::GPS::instance()->setPointingHistoryFile(filename, offset, horizontalflag);
00112 }
00113 else if( m_pointingDirection.value().size()==2 ) {
00114
00115 double ra(m_pointingDirection.value()[0]), dec(m_pointingDirection.value()[1]);
00116 astro::GPS::instance()->setPointingDirection(astro::SkyDir(ra, dec));
00117 log << MSG::INFO << "set to point at ra,dec= " << ra << ", "<<dec << endreq;
00118
00119 }else if( m_zenithTheta>=0) {
00120
00121
00122 GPS::instance()->setRockType(GPS::EXPLICIT);
00123 GPS::instance()->rockingDegrees(m_zenithTheta);
00124
00125 log << MSG::INFO << "set to zenith angle " << m_zenithTheta << " degrees" << endreq;
00126 }else if(m_rocking_angle >0 ){
00127
00128
00129
00130 GPS::instance()->setRockType(GPS::ONEPERORBIT);
00131 GPS::instance()->rockingDegrees(m_zenithTheta);
00132 log << MSG::INFO << "Once per orbit rocking Angle: " << m_rocking_angle << " degrees" << endreq;
00133
00134 }
00135
00136
00137 return sc;
00138 }
00139
00141 StatusCode OrbitSvc::queryInterface(const InterfaceID& riid, void** ppvInterface) {
00142 if ( IID_IOrbitSvc.versionMatch(riid) ) {
00143 *ppvInterface = (OrbitSvc*)this;
00144 } else {
00145 return Service::queryInterface(riid, ppvInterface);
00146 }
00147
00148 addRef();
00149 return SUCCESS;
00150 }
00151
00152 StatusCode OrbitSvc::finalize()
00153 {
00154 return StatusCode::SUCCESS;
00155 }
00156