Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 6289)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 6346)
@@ -71,11 +71,12 @@
 #include "MLogManip.h"
 
-#include "MRawRunHeader.h"
+#include "MGeomCam.h"
 #include "MObservatory.h"
+#include "MPointingPos.h"
 #include "MSrcPosCam.h"
+
+#include "MAstro.h"
+#include "MVector3.h"
 #include "MAstroSky2Local.h"
-#include "MPointingPos.h"
-#include "MGeomCam.h"
-#include "MVector3.h"
 
 ClassImp(MSrcPosCalc);
@@ -88,9 +89,49 @@
 //
 MSrcPosCalc::MSrcPosCalc(const char *name, const char *title)
-    : fObservatory(0), fPointPos(0), fSourcePos(0), fSrcPosCam(0),
-    fGeom(0), fTime(0)
+    : fObservatory(NULL), fPointPos(NULL), fSourcePos(NULL), fSrcPosCam(NULL),
+    fGeom(NULL), fTime(NULL)
 {
     fName  = name  ? name  : "MSrcPosCalc";
-    fTitle = title ? title : "Derotates the source position in the camera";
+    fTitle = title ? title : "Calculates the source position in the camera";
+}
+
+// --------------------------------------------------------------------------
+//
+//  delete fSourcePos if kIsOwner
+//  set fSourcePos to NULL
+//
+void MSrcPosCalc::FreeSourcePos()
+{
+    if (fSourcePos && TestBit(kIsOwner))
+        delete fSourcePos;
+
+    fSourcePos = NULL;
+}
+
+// --------------------------------------------------------------------------
+//
+//  ra  [h]
+//  dec [deg]
+//
+void MSrcPosCalc::SetSourcePos(Double_t ra, Double_t dec)
+{
+    FreeSourcePos();
+
+    fSourcePos = new MPointingPos("MSourcePos");
+    fSourcePos->SetSkyPosition(ra, dec);
+
+    SetOwner();
+}
+
+// --------------------------------------------------------------------------
+//
+// Return ra/dec as string
+//
+TString MSrcPosCalc::GetRaDec(const MPointingPos &pos) const
+{
+    const TString rstr = MAstro::Angle2Coordinate(pos.GetRa());
+    const TString dstr = MAstro::Angle2Coordinate(pos.GetDec());
+
+    return Form("Ra=%sh Dec=%sdeg", rstr.Data(), dstr.Data());
 }
 
@@ -110,13 +151,16 @@
         return kFALSE;
 
-
-    fSourcePos = (MPointingPos*)pList->FindObject("MSourcePos", "MPointingPos");
     if (!fSourcePos)
     {
-        *fLog << warn << "MSourcePos [MPointPos] not found... The source position" << endl;
-        *fLog << warn << "set in MSrcPosCam (camera center if not set explicitely) will" << endl;
-        *fLog << warn << "be left unchanged, same for all events." << endl;
-        return kSKIP;
-    }
+        fSourcePos = (MPointingPos*)pList->FindObject("MSourcePos", "MPointingPos");
+        if (!fSourcePos)
+        {
+            *fLog << warn << "MSourcePos [MPointPos] not found... The source position" << endl;
+            *fLog << warn << "set in MSrcPosCam (camera center if not set explicitely) will" << endl;
+            *fLog << warn << "be left unchanged, same for all events." << endl;
+            return kSKIP;
+        }
+    }
+    // FIXME: Maybe we have to call FreeSourcePos in PostProcess()?
 
     fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
@@ -147,4 +191,8 @@
         return kFALSE;
     }
+
+    *fLog << inf;
+    *fLog << "Pointing Position: " << GetRaDec(*fPointPos)  << endl;
+    *fLog << "Source   Position: " << GetRaDec(*fSourcePos) << endl;
 
     return kTRUE;
@@ -246,2 +294,96 @@
   return kTRUE;
 }
+
+// --------------------------------------------------------------------------
+//
+// Convert a coordinate stored in str into a double, stored in ret.
+// Returns kTRUE on success, otherwise kFALSE
+//
+// Allowed formats are:
+//     12.5
+//    -12.5
+//    +12.5
+//  -12:30:00.0
+//   12:30:00.0
+//  +12:30:00.0
+//
+Bool_t MSrcPosCalc::GetCoordinate(TString str, Double_t &ret) const
+{
+    str = str.Strip(TString::kBoth);
+
+    if (str.First(':')<0)
+        return atof(str);
+
+    if (MAstro::Coordinate2Angle(str, ret))
+        return kTRUE;
+
+    *fLog << err << GetDescriptor() << endl;
+    *fLog << "Interpretation of Coordinate '" << str << "' not successfull... abort." << endl;
+    *fLog << "Corrdinate must have the format: '-12:30:00.0', '12:30:00.0' or '+12:30:00.0'" << endl;
+    return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Read the setup from a TEnv, eg:
+//   MSrcPosCalc.SourceRa:  ra
+//   MSrcPosCalc.SourceDec: dec
+//   MSrcPosCalc.SourcePos: ra dec
+//
+// For format of 'ra' and 'dec' see GetCoordinate()
+//
+// Coordinates are J2000.0
+//
+Int_t MSrcPosCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Double_t ra=0;
+    Double_t dec=0;
+
+    if (IsEnvDefined(env, prefix, "SourceRaDec", print))
+    {
+        TString str = GetEnvValue(env, prefix, "SourceRaDec", "");
+        str = str.Strip(TString::kBoth);
+
+        const Ssiz_t pos = str.First(' ');
+        if (pos<0)
+        {
+            *fLog << err << GetDescriptor() << "SourceRaDec empty... abort." << endl;
+            return kERROR;
+        }
+
+        if (!GetCoordinate(str(0, pos), ra))
+            return kERROR;
+        if (!GetCoordinate(str(pos+1, str.Length()), dec))
+            return kERROR;
+
+        SetSourcePos(ra, dec);
+        return kTRUE;
+    }
+
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "SourceRa", print))
+    {
+        TString str = GetEnvValue(env, prefix, "SourceRa", "");
+
+        if (!GetCoordinate(str, ra))
+            return kERROR;
+
+        rc = kTRUE;
+    }
+
+    if (IsEnvDefined(env, prefix, "SourceDec", print))
+    {
+        TString str = GetEnvValue(env, prefix, "SourceDec", "");
+
+        if (!GetCoordinate(str, dec))
+            return kERROR;
+
+        rc = kTRUE;
+    }
+
+    if (!rc)
+        return kFALSE;
+
+    SetSourcePos(ra, dec);
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h	(revision 6289)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h	(revision 6346)
@@ -20,4 +20,8 @@
 {
 private:
+    enum {
+        kIsOwner = BIT(14)
+    };
+
     MObservatory *fObservatory;
     MPointingPos *fPointPos;
@@ -27,6 +31,14 @@
     MTime        *fTime;
 
+    // MSrcPosCalc
     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
     Int_t PreProcess(MParList *pList);
     Int_t Process();
@@ -34,6 +46,12 @@
 public:
     MSrcPosCalc(const char *name=NULL, const char *title=NULL);
+    ~MSrcPosCalc() { FreeSourcePos(); }
 
-    ClassDef(MSrcPosCalc, 0) // Derotates the source position in the camera
+    // 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
+
+    ClassDef(MSrcPosCalc, 0) // Calculates the source position in the camera
 };
 
