Index: trunk/MagicSoft/Mars/mtemp/mifae/Changelog
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 4086)
+++ trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 4087)
@@ -23,8 +23,12 @@
      library/MSrcTranslate.cc
      - Assign the internal histogram a class-dependent name
+     - Add some log lines to trace the classes behaviour
+     - Remove function SearchForSrcPos
 
    * library/MSrcPosFromFile.[cc,h]
-     - Correct behaviour for not found runs.
+     - Correct behaviour for not found runs
+     - Keep latest good MSrcPosCam to fill for next events
      - Initialize pointers to NULL
+     - Fill also MDCA
 
 	
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc	(revision 4086)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc	(revision 4087)
@@ -30,4 +30,7 @@
 // It keeps a 2D histogram with the assigned positions, so that the same
 // distribution can be applied later to any data set (tipically the OFF data)
+// Classes inheritating MSrcPlace should override the ComputeNewSrcPosition() 
+// method and probably include a call to MsrcPlace::PreProcess in their
+// PreProcess method (see, e.g., MSrcPosFromFile or MSrcRotate classes)
 //
 //  Input Containers:
@@ -92,33 +95,4 @@
   if(fHistPos)
     delete fHistPos;
-}
-// -------------------------------------------------------------------------
-//
-// Look for/create the needed containers
-// Check whether RA and DEC have been initialized
-//
-Int_t MSrcPlace::SearchForSrcPos(MParList *pList)
-{
-    // look for/create MSrcPosCam
-  fSrcPos = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosName), "MSrcPosCam");
-  if (!fSrcPos)
-    {
-      *fLog << warn << AddSerialNumber(fSrcPosName) << " [MSrcPosCam] not found... creating default container." << endl;
-      fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosName));
-      if(!fSrcPos)
-	return kFALSE;
-    }
-
-  // look for/create MDCA
-  fDCA = (MDCA*)pList->FindObject(AddSerialNumber(fDCAName), "MDCA");
-  if (!fDCA)
-    {
-      *fLog << warn << AddSerialNumber(fDCAName) << " [MDCA] not found... creating default container." << endl;
-      fDCA = (MDCA*)pList->FindCreateObj("MDCA", AddSerialNumber(fDCAName));
-      if(!fDCA)
-	return kFALSE;
-    }
-
-  return kTRUE;
 }
 
@@ -146,9 +120,43 @@
 // -------------------------------------------------------------------------
 //
-// Look for needed containers
-//
-Int_t MSrcPlace::PreProcess(MParList* plist)
+// Look for needed containers.
+// Check processing mode and if histogram is filled in case kOff mode
+//
+Int_t MSrcPlace::PreProcess(MParList* pList)
 { 
-  return SearchForSrcPos(plist);
+    // look for/create MSrcPosCam
+  fSrcPos = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosName), "MSrcPosCam");
+  if (!fSrcPos)
+    {
+      *fLog << warn << AddSerialNumber(fSrcPosName) << " [MSrcPosCam] not found... creating default container." << endl;
+      fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosName));
+      if(!fSrcPos)
+	return kFALSE;
+    }
+
+  // look for/create MDCA
+  fDCA = (MDCA*)pList->FindObject(AddSerialNumber(fDCAName), "MDCA");
+  if (!fDCA)
+    {
+      *fLog << warn << AddSerialNumber(fDCAName) << " [MDCA] not found... creating default container." << endl;
+      fDCA = (MDCA*)pList->FindCreateObj("MDCA", AddSerialNumber(fDCAName));
+      if(!fDCA)
+	return kFALSE;
+    }
+
+  // check mode, look for a filled histogram in case kOff
+  if(fMode==kOn)
+    *fLog << inf << "MSrcPlace PreProcess Message: source postions will be stored in internal histo (" << fHistPos->GetName() << ")" << endl;
+  else
+    {
+      if(fHistPos->GetEntries())
+	*fLog << inf << "MSrcPlace PreProcess Message: source postions will be read from internal histo (" << fHistPos->GetName() << ")" << endl;
+      else
+	{
+	  *fLog << err << "MSrcPlace PreProcess Error: source postions attempted to be read from empty histo (" << fHistPos->GetName() << ")" << endl;
+	  return kFALSE;
+	}
+    }
+  return kTRUE;
 }
 
@@ -183,12 +191,14 @@
 Int_t MSrcPlace::PostProcess()
 {
-  *fLog << inf << endl;
-  *fLog << inf << "MSrcPlace::PostProcess Message: Created internal histogram with: ";
-  *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;
-  
+  if(fMode==kOn)
+    {
+      *fLog << inf << endl;
+      *fLog << inf << "MSrcPlace::PostProcess Message: Created internal histogram with: " << 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 4086)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h	(revision 4087)
@@ -25,11 +25,12 @@
   OnOffMode_t  fMode;        //  On/Off data mode (write/read to/from the histogram)
 
-  virtual Int_t PreProcess(MParList *plist);
+  void  SavePosIntoHisto();
+  void  ReadPosFromHisto();
+
   virtual Int_t Process();
   virtual Int_t PostProcess();
 
-  void  SavePosIntoHisto();
-  void  ReadPosFromHisto();
-
+ protected:
+  virtual Int_t PreProcess(MParList *plist);
 
  public:
@@ -49,5 +50,4 @@
   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 4086)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc	(revision 4087)
@@ -42,4 +42,5 @@
 #include "MRawRunHeader.h"
 #include "MSrcPosCam.h"
+#include "MDCA.h"
 
 #include "MLog.h"
@@ -92,19 +93,21 @@
 Int_t MSrcPosFromFile::PreProcess(MParList *pList)
 {
-  // Count the number of runs in the card with the source poistions
-  ReadSourcePositionsFile(kCount);
-  
-  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);
-
-
-  if(!SearchForSrcPos(pList))
+  if(GetMode()==MSrcPlace::kOn)
+    {
+      // Count the number of runs in the card with the source poistions
+      ReadSourcePositionsFile(kCount);
+      
+      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);
+    }
+
+  if(!MSrcPlace::PreProcess(pList))
     return kFALSE;
   
@@ -131,34 +134,30 @@
       fLastRun=run;
       MSrcPosCam* srcpos = (MSrcPosCam*)fRunMap->GetValue(run);
-      
-      Float_t x;
-      Float_t y;
-	
+
       *fLog << inf << "Source position for run " << run;
-      if (srcpos)
+
+      if(srcpos)
+	fLastValidSrcPosCam = srcpos;
+      else
+	*fLog << inf << " not found in file. Taking previous position: ";
+
+      if(fLastValidSrcPosCam)
 	{
-	  fLastValidSrcPosCam = srcpos;
-	  x = srcpos->GetX();
-	  y = srcpos->GetY();
-	}	    
-      else if(fLastValidSrcPosCam)
-	{
-	  x = fLastValidSrcPosCam->GetX();
-	  y = fLastValidSrcPosCam->GetY();
-	  
-	  *fLog << inf << " not found in file. Taking previous position: ";
+	  *fLog << inf << "\tX\t" << setprecision(3) << fLastValidSrcPosCam->GetX();
+	  *fLog << inf << "\tY\t" << setprecision(3) << fLastValidSrcPosCam->GetY() << endl;      
 	}
-      else
-	{
-	  *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;      
-    }
-  
+    }
+
+  if(fLastValidSrcPosCam)
+    {
+      GetSrcPosCam()->SetXY(fLastValidSrcPosCam->GetX(),fLastValidSrcPosCam->GetY());
+      GetDCA()->SetRefPoint(fLastValidSrcPosCam->GetX(),fLastValidSrcPosCam->GetY());
+    }
+  else
+    {
+      *fLog << err << "MSrcPosFromFile::ComputeNewSrcPosition error: no value for the first run. Don't know what values to take" << endl;
+      return kFALSE;
+    }
+
   return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc	(revision 4086)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc	(revision 4087)
@@ -83,5 +83,5 @@
 Int_t MSrcRotate::PreProcess(MParList *pList)
 {
-  if(!SearchForSrcPos(pList))
+  if(!MSrcPlace::PreProcess(pList))
     return kFALSE;
   
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc	(revision 4086)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc	(revision 4087)
@@ -28,5 +28,6 @@
 // Task to translate the position of the source, starting from previous source
 // position (fTranslationIsRelative=kTRUE) or from camera center 
-// (fTranslationIsRelative=kFALSE)
+// (fTranslationIsRelative=kFALSE). This task allows you to modify the position
+// of the source in an event-by-event basis
 //
 //  Input Containers:
@@ -82,5 +83,5 @@
 {
   // look for/create MSrcPosCam and DCA
-  if(!SearchForSrcPos(pList))
+  if(!MSrcPlace::PreProcess(pList))
     return kFALSE;
 
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.h	(revision 4086)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.h	(revision 4087)
@@ -24,5 +24,5 @@
   virtual Int_t ComputeNewSrcPosition();
 
-  ClassDef(MSrcTranslate, 0) // task to rotate the position of the source as a function of Azimuth and Zenith angles
+  ClassDef(MSrcTranslate, 0) // task to set the position of the source within the camera in an event by event basis
 };
 
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard	(revision 4086)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard	(revision 4087)
@@ -1,5 +1,5 @@
 
 // Maximun number of on and off events to be processed)
-NEVENTS 99999999
+NEVENTS 20000
 
 // Input file name pattern
