#ifndef MARS_MSrcPosCalc
#define MARS_MSrcPosCalc

#ifndef MARS_MTask
#include "MTask.h"
#endif

#ifndef ROOT_TVector2
#include <TVector2.h>
#endif

class MObservatory;
class MPointingPos;
class MSrcPosCam;
class MGeomCam;
class MTime;
class MVector3;

class MSrcPosCalc : public MTask
{
private:
    enum {
        kIsOwner = BIT(14)
    };

    MObservatory *fObservatory;
    MPointingPos *fPointPos;
    MPointingPos *fSourcePos;
    MSrcPosCam   *fSrcPosCam;
    MSrcPosCam   *fSrcPosAnti;
    MGeomCam     *fGeom;
    MTime        *fTime;

    UShort_t fRunType;            //! Run Type to decide where to get pointing position from

    Bool_t fIsWobbleMode;

    // MSrcPosCalc
    void     SetSrcPos(TVector2 v) const;
    TVector2 CalcXYinCamera(const MVector3 &pos0, const MVector3 &pos) const;
    TString  GetRaDec(const MPointingPos &pos) const;
    Bool_t   GetCoordinate(TString str, Double_t &ret) const;
    void     FreeSourcePos();

    // MParContainer
    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);

    // MTask
    Bool_t ReInit(MParList *pList);
    Int_t  PreProcess(MParList *pList);
    Int_t  Process();

public:
    MSrcPosCalc(const char *name=NULL, const char *title=NULL);
    ~MSrcPosCalc() { FreeSourcePos(); }

    // MSrcPosCalc
    void SetSourcePos(MPointingPos *pos) { FreeSourcePos(); fSourcePos = pos; }
    void SetSourcePos(Double_t ra, Double_t dec);
    void SetOwner(Bool_t b=kTRUE) { b ? SetBit(kIsOwner) : ResetBit(kIsOwner); } // Make MSrcPosCalc owner of fSourcePos
    void SetWobbleMode(Bool_t b=kTRUE) { fIsWobbleMode = b; }

    ClassDef(MSrcPosCalc, 0) // Calculates the source position in the camera
};

#endif
