Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

PtValsAlg.cxx

Go to the documentation of this file.
00001 
00008 // Include files
00009 // Gaudi system includes
00010 #include "GaudiKernel/MsgStream.h"
00011 #include "GaudiKernel/AlgFactory.h"
00012 #include "GaudiKernel/Algorithm.h"
00013 #include "GaudiKernel/Property.h"
00014 #include "GaudiKernel/SmartDataPtr.h"
00015 
00016 // Event for access to time
00017 #include "Event/TopLevel/EventModel.h"
00018 #include "Event/TopLevel/Event.h"
00019 
00020 // stuff for exposure info (not really MC)
00021 #include "Event/TopLevel/MCEvent.h"
00022 #include "Event/MonteCarlo/Exposure.h"
00023 
00024 // to write a Tree with pointing info
00025 #include "ntupleWriterSvc/INTupleWriterSvc.h"
00026 
00027 
00028 #include "facilities/Util.h"
00029 #include "facilities/Timestamp.h"
00030 
00031 #include "astro/JulianDate.h"
00032 #include "astro/GPS.h"
00033 
00034 //
00035 #include "AnalysisNtuple/PointingInfo.h"
00036 
00037 namespace { // anonymous namespace for file-global
00038     astro::GPS* gps(0);  // pointer to relevant GPS entry
00039 }
00040 
00041 using namespace AnalysisNtuple;
00042 
00052 class PtValsAlg : public Algorithm {
00053 public:
00054     PtValsAlg(const std::string& name, ISvcLocator* pSvcLocator);
00055 
00056     StatusCode initialize();
00057     StatusCode execute();
00058     StatusCode finalize();
00059 
00060 
00061 private: 
00062     PointingInfo m_pointingInfo;
00063 
00064     StringProperty m_root_tree;
00065     StringArrayProperty m_pointingHistory;
00066 
00067     INTupleWriterSvc* m_rootTupleSvc;
00068     IDataProviderSvc* m_pEventSvc;
00069 
00070     astro::PointingHistory* m_history;
00071     bool m_horizontal;
00072     bool m_fillNtuple;
00073 
00074 };
00075 //------------------------------------------------------------------------
00076 
00077 
00078 static const AlgFactory<PtValsAlg>  Factory;
00079 const IAlgFactory& PtValsAlgFactory = Factory;
00080 
00081 //------------------------------------------------------------------------
00083 PtValsAlg::PtValsAlg(const std::string& name, ISvcLocator* pSvcLocator)
00084 :Algorithm(name, pSvcLocator) , m_horizontal(false)
00085 {
00086     // declare properties with setProperties calls
00087 
00088     declareProperty("pointing_info_tree_name",  m_root_tree="MeritTuple");
00089     // doublet, filename and launch date
00090     declareProperty("PointingHistory",   m_pointingHistory); 
00091     declareProperty("FillNtuple",        m_fillNtuple=true);
00092 
00093 }
00094 //------------------------------------------------------------------------
00096 StatusCode PtValsAlg::initialize(){
00097     StatusCode  sc = StatusCode::SUCCESS;
00098     MsgStream log(msgSvc(), name());
00099     // Use the Job options service to set the Algorithm's parameters
00100     setProperties();
00101 
00102     // get a pointer to RootTupleSvc
00103     if( (service("RootTupleSvc", m_rootTupleSvc, true) ). isFailure() ) {
00104         log << MSG::ERROR << " RootTupleSvc is not available" << endreq;
00105         m_rootTupleSvc=0;
00106         sc = StatusCode::FAILURE;
00107     } else if( !m_root_tree.value().empty() ) {   
00108      
00109           if(m_fillNtuple) m_pointingInfo.setPtTuple(m_rootTupleSvc, m_root_tree.value()); 
00110     }
00111 
00112 
00113     // get the GPS instance: 
00114 
00115     gps = astro::GPS::instance();
00116 
00117     //set the input file to be used as the pointing database, if used
00118     if( m_pointingHistory.value().empty()){
00119         log << MSG::WARNING << "No history file specified, using default" << endreq;
00120     }else{
00121         std::string filename(m_pointingHistory.value()[0]);
00122         facilities::Util::expandEnvVar(&filename);
00123         double offset = 0;
00124         std::string jStr;
00125         if( m_pointingHistory.value().size()>1){
00126             std::string field(m_pointingHistory.value()[1]);
00127             if(! field.empty() ) { // allow null string
00128                 facilities::Timestamp jt(m_pointingHistory.value()[1]);
00129                 offset = (astro::JulianDate(jt.getJulian())
00130                     - astro::JulianDate::missionStart())
00131                     *astro::JulianDate::secondsPerDay;
00132                 astro::JulianDate jDate(astro::JulianDate(jt.getJulian()));
00133                 jStr = jDate.getGregorianDate();
00134             }
00135         }
00136 
00137         if( m_pointingHistory.value().size()>2){
00138             std::string field(m_pointingHistory.value()[2]);
00139             m_horizontal =! field.empty();
00140         }
00141         log << MSG::INFO << "Loading Pointing History File : " << filename <<endreq;
00142         if( offset>0 ){
00143             log << MSG::INFO   << " with MET offset " ;
00144             log.precision(12);
00145             log << offset << " ";
00146             log.precision(6);
00147             log << jStr << endreq;
00148         }
00149         if( m_horizontal){
00150             log << MSG::INFO 
00151                 << "   Will override x-direction to be horizontal"<<endreq;
00152         }
00153         gps->setPointingHistoryFile(filename, offset, m_horizontal);
00154     }
00155 
00156 
00157 
00158     IDataProviderSvc* eventsvc = 0;
00159     sc = serviceLocator()->service( "EventDataSvc", eventsvc, true );
00160     if(sc.isFailure()){
00161         log << MSG::ERROR << "Could not find EventDataSvc" << std::endl;
00162         return sc;
00163     }
00164     m_pEventSvc = eventsvc;
00165    
00166     return sc;
00167 }
00168 
00169 //------------------------------------------------------------------------
00171 StatusCode PtValsAlg::execute()
00172 {
00173     StatusCode  sc = StatusCode::SUCCESS;
00174     MsgStream   log( msgSvc(), name() );
00175     //
00176     // Purpose: set tuple items
00177  
00178    SmartDataPtr<Event::EventHeader> header(m_pEventSvc, EventModel::EventHeader);
00179 
00180    // get event time from header or merit 
00181    // and look up position info from the history  
00182 
00183    double etime;
00184 
00185    if(header==0) {
00186        void* ptr;
00187        m_rootTupleSvc->getItem(m_root_tree,"PtTime",ptr);
00188        etime = *reinterpret_cast<double*>(ptr);
00189    } else {
00190        etime = header->time();
00191    }
00192     gps->time(etime);
00193 
00194     // and create the tuple
00195     if (m_fillNtuple) m_pointingInfo.execute( *gps );
00196     
00197     return StatusCode::SUCCESS;
00198 }
00199 
00200 //------------------------------------------------------------------------
00202 StatusCode PtValsAlg::finalize(){
00203     StatusCode  sc = StatusCode::SUCCESS;
00204     return sc;
00205 }
00206 
00207 
00208 

Generated on Mon Dec 1 20:09:05 2008 by doxygen 1.3.3