Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc	(revision 4075)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc	(revision 4084)
@@ -62,9 +62,10 @@
 // -------------------------------------------------------------------------
 //
-// Default constructor. The first (second) argument is the name of a container
+// Default constructor. The first argument is the name of the internal histo, 
+// the second (third) argument is the name of a container
 // containing the source position in the camera plain, MScrPosCam (MDCA).
 // The default is "MSrcPosCam" ("MDCA"). 
 //
-MSrcPlace::MSrcPlace(const char* srcPos, const char* dca, const char *name, const char *title)
+MSrcPlace::MSrcPlace(const char* histname, const char* srcPos, const char* dca, const char *name, const char *title)
   : fSrcPos(NULL), fDCA(NULL)
 {
@@ -76,8 +77,8 @@
 
     const Float_t cameraSize   = 600; //[mm]
-    const Float_t binPrecision =   1; //[mm] ~ 0.0033 deg
-
+    const Float_t binPrecision =   1; //[mm] ~ 0.0033 deg  
     const UInt_t nbins =  (UInt_t)(cameraSize*2/binPrecision);
-    fHistSrcPos = new TH2F("HistSrcPos","",nbins,-cameraSize,cameraSize,nbins,-cameraSize,cameraSize);
+    
+    fHistPos = new TH2F(histname,"",nbins,-cameraSize,cameraSize,nbins,-cameraSize,cameraSize);
 
     fMode=kOn;
@@ -89,5 +90,6 @@
 MSrcPlace::~MSrcPlace()
 {
-  delete fHistSrcPos;
+  if(fHistPos)
+    delete fHistPos;
 }
 // -------------------------------------------------------------------------
@@ -127,5 +129,5 @@
 void MSrcPlace::SavePosIntoHisto()
 {  
-  fHistSrcPos->Fill(fSrcPos->GetX(),fSrcPos->GetY());
+  fHistPos->Fill(fSrcPos->GetX(),fSrcPos->GetY());
 }
 // -------------------------------------------------------------------------
@@ -138,5 +140,5 @@
   Axis_t y;
   
-  fHistSrcPos->GetRandom2(x,y);
+  fHistPos->GetRandom2(x,y);
   fSrcPos->SetXY(x,y);
   fDCA->SetRefPoint(x,y);
@@ -147,5 +149,5 @@
 //
 Int_t MSrcPlace::PreProcess(MParList* plist)
-{  
+{ 
   return SearchForSrcPos(plist);
 }
@@ -183,9 +185,9 @@
   *fLog << inf << endl;
   *fLog << inf << "MSrcPlace::PostProcess Message: Created internal histogram with: ";
-  *fLog << inf << "Entries: " << fHistSrcPos->GetEntries() << endl;
-  *fLog << inf << "X projection mean: " << fHistSrcPos->ProjectionX()->GetMean() << endl;
-  *fLog << inf << "X projection rms:  " << fHistSrcPos->ProjectionX()->GetRMS() << endl;
-  *fLog << inf << "Y projection mean: " << fHistSrcPos->ProjectionY()->GetMean() << endl;
-  *fLog << inf << "Y projection rms:  " << fHistSrcPos->ProjectionY()->GetRMS() << endl;
+  *fLog << inf << "Entries: " << fHistPos->GetEntries() << endl;
+  *fLog << inf << "X projection mean: " << fHistPos->ProjectionX()->GetMean() << endl;
+  *fLog << inf << "X projection rms:  " << fHistPos->ProjectionX()->GetRMS() << endl;
+  *fLog << inf << "Y projection mean: " << fHistPos->ProjectionY()->GetMean() << endl;
+  *fLog << inf << "Y projection rms:  " << fHistPos->ProjectionY()->GetRMS() << endl;
   
   return kTRUE;
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h	(revision 4075)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h	(revision 4084)
@@ -22,5 +22,5 @@
   TString      fDCAName;     //  Name of the MDCA object
   
-  TH2F*        fHistSrcPos;  //  histogram of the used source positions
+  TH2F*        fHistPos;  //  histogram of the used source positions
   OnOffMode_t  fMode;        //  On/Off data mode (write/read to/from the histogram)
 
@@ -34,5 +34,6 @@
 
  public:
-  MSrcPlace(const char* src="MSrcPosCam", const char* dca="MDCA",
+  MSrcPlace(const char* histname="HistSrcPos",
+	    const char* src="MSrcPosCam", const char* dca="MDCA",
 	    const char* name=NULL, const char* title=NULL);
 
@@ -43,10 +44,9 @@
   void SetDCAName(TString name)    {fDCAName=name;}
 
-  OnOffMode_t GetMode()            {return fMode;}
-  TH2F*       GetPositionHisto()   {return fHistSrcPos;}
-  MSrcPosCam* GetSrcPosCam()       {return fSrcPos;}
-  MDCA*       GetDCA()             {return fDCA;}
-
-
+  OnOffMode_t   GetMode()            {return fMode;}
+  TH2F*         GetPositionHisto()   {return fHistPos;}
+  MSrcPosCam*   GetSrcPosCam()       {return fSrcPos;}
+  MDCA*         GetDCA()             {return fDCA;}
+  
   Int_t SearchForSrcPos(MParList *plist);
   virtual Int_t ComputeNewSrcPosition() {return kTRUE;}
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc	(revision 4075)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc	(revision 4084)
@@ -60,5 +60,5 @@
 //
 MSrcPosFromFile::MSrcPosFromFile(TString cardpath, OnOffMode_t mode, const char *name, const char *title)
-  : fRawRunHeader(NULL), fSourcePositionFilePath(cardpath)
+  : MSrcPlace(TString(gsDefName+"Hist").Data()), fRawRunHeader(NULL), fSourcePositionFilePath(cardpath)
 {
   fName  = name  ? name  : gsDefName.Data();
@@ -66,28 +66,44 @@
   SetMode(mode);
 
+  fRunList=0x0;
+  fRunSrcPos=0x0;
+  fRunMap=0x0;
+
   fLastRun = 0;
-  
+  fLastValidSrcPosCam=0x0;
+}
+// -------------------------------------------------------------------------
+//
+// Destructor
+//
+MSrcPosFromFile::~MSrcPosFromFile()
+{
+  if(fRunList)
+    delete [] fRunList;
+  if(fRunSrcPos)
+    delete [] fRunSrcPos;
+  if(fRunMap)
+    delete fRunMap;
+}
+
+// -------------------------------------------------------------------------
+//
+// Open and read the input file.
+Int_t MSrcPosFromFile::PreProcess(MParList *pList)
+{
   // Count the number of runs in the card with the source poistions
   ReadSourcePositionsFile(kCount);
   
-  fRunList = new Int_t[fNumRuns];
-  fRunSrcPos = new MSrcPosCam[fNumRuns];
-  fRunMap = new TExMap(fNumRuns);
+  if(!fRunList)
+    fRunList = new Int_t[fNumRuns];
+  if(!fRunSrcPos)
+    fRunSrcPos = new MSrcPosCam[fNumRuns];
+  if(!fRunMap)
+    fRunMap = new TExMap(fNumRuns);
   
   // Read card with the source poistions
   ReadSourcePositionsFile(kRead);
-}
-
-MSrcPosFromFile::~MSrcPosFromFile()
-{
-  delete [] fRunList;
-  delete [] fRunSrcPos;
-  delete fRunMap;
-}
-
-// -------------------------------------------------------------------------
-//
-Int_t MSrcPosFromFile::PreProcess(MParList *pList)
-{
+
+
   if(!SearchForSrcPos(pList))
     return kFALSE;
@@ -119,22 +135,28 @@
       Float_t y;
 	
+      *fLog << inf << "Source position for run " << run;
       if (srcpos)
 	{
+	  fLastValidSrcPosCam = srcpos;
 	  x = srcpos->GetX();
 	  y = srcpos->GetY();
+	}	    
+      else if(fLastValidSrcPosCam)
+	{
+	  x = fLastValidSrcPosCam->GetX();
+	  y = fLastValidSrcPosCam->GetY();
 	  
-	  GetSrcPosCam()->SetXY(x,y);
-		
-	  *fLog << inf << "Source position for run " << run;
-	  *fLog << inf << "\tX\t" << setprecision(3) << x;
-	  *fLog << inf << "\tY\t" << setprecision(3) << y << endl;
-	}	    
+	  *fLog << inf << " not found in file. Taking previous position: ";
+	}
       else
 	{
-	  *fLog << inf << "Source position for run " << run << " not found in file. ";
-	  *fLog << inf << "Taking previous position: ";
-	  *fLog << inf << "\tX\t" << setprecision(3) << x;
-	  *fLog << inf << "\tY\t" << setprecision(3) << y << endl;	  
+	  *fLog << err << "MSrcPosFromFile::ComputeNewSrcPosition error: no value for the first run. Don't know what values to take" << endl;
+	  return kFALSE;
 	}
+
+      GetSrcPosCam()->SetXY(x,y);
+      
+      *fLog << inf << "\tX\t" << setprecision(3) << x;
+      *fLog << inf << "\tY\t" << setprecision(3) << y << endl;      
     }
   
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h	(revision 4075)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h	(revision 4084)
@@ -24,4 +24,5 @@
     Int_t      *fRunList;
     MSrcPosCam *fRunSrcPos;
+    MSrcPosCam *fLastValidSrcPosCam;
     TExMap     *fRunMap;   // list of run numbers positions
 
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc	(revision 4075)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc	(revision 4084)
@@ -67,5 +67,5 @@
 //
 MSrcRotate::MSrcRotate(const char* srcPos, const char* dca, const char *name, const char *title)
-  : fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0)
+  : MSrcPlace(TString(gsDefName+"Hist").Data()), fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0)
 {
     fName  = name  ? name  : gsDefName.Data();
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc	(revision 4075)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc	(revision 4084)
@@ -66,5 +66,5 @@
 //
 MSrcTranslate::MSrcTranslate(const char* srcPos, const char* dca, const char *name, const char *title)
-  : fShiftX(0.), fShiftY(0.), fTranslationIsRelative(kTRUE)
+  : MSrcPlace(TString(gsDefName+"Hist").Data()), fShiftX(0.), fShiftY(0.), fTranslationIsRelative(kTRUE)
 {
     fName  = name  ? name  : gsDefName.Data();
