Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3182)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3183)
@@ -4,12 +4,69 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2004/02/14: Thomas Bretz
+
+   * manalysis/AnalysisLinkDef.h:
+     - added missing MCerPhotEvtIter
+
+   * merpp.cc:
+     - added possible usage of database
+
+   * star.cc:
+     - moved source code into new class MJStar - preliminary
+
+   * manalysis/MCerPhotPix.cc:
+     - updated class header
+     - fixed Print-output
+
+   * mbase/MAGIC.h:
+     - removed definition of MLog
+
+   * mbase/MArgs.h:
+     - removed include of MAGIC.h
+
+   * mbase/MLog.h:
+     - added extern definition of gLog
+
+   * mbase/MParContainer.[h,cc]:
+     - move body of constructors to source file
+
+   * mcalib/MCalibrate.cc, mcalib/MCalibrateData.cc,
+     mraw/MRawCrateArray.cc, mraw/MRawCrateData.cc,
+     mraw/MRawEvtData.cc, mraw/MRawEvtHeader.cc, mraw/MRawRead.cc,
+     mraw/MRawEvtPixelIter.cc, mraw/MRawFileWrite.cc:
+     - fixed documentation header
+
+   * mcalib/MMcCalibrationCalc.[h,cc]:
+     - fixed documentation header
+     - fixed usage of FindCreateObj and FindObject
+     - removed data member to count entries (use histogram instead)
+     - use TH1 function Integral instead of doing it manually
+
+   * mfilter/MFCosmics.cc:
+     - fixed documentation
+
+   * mimage/MHillas.cc, mimage/MImgCleanStd.cc,
+     mimage/MNewImagePar.[h,cc]:
+     - replaced for-loops by Iterators
+
+   * mraw/MRawFileRead.cc, mraw/MRawSocketRead.cc:
+     - fixed documentation header
+     - check return value of MRawRunHeader::ReadEvt
+
+   * mraw/mraw/MRawRunHeader.[h,cc]:
+     - fixed documentation header
+     - added return value to MRawRunHeader::ReadEvt
+     - added constant number for max format version - preliminary 
+       (should by a static data member)
+
+
 
  2004/02/16: Markus Gaug
 
-   * mcalib/Makefile
-   * mcalib/CalibLinkDef.h
-
-   * mcalib/MHCalibrationRelTimePix.[h,cc]
-   * mcalib/MHCalibrationRelTimeCam.[h,cc]
+   * mcalib/Makefile, mcalib/CalibLinkDef.h:
+     - added MHCalibrationRelTimePix
+
+   * mcalib/MHCalibrationRelTimePix.[h,cc],
+     mcalib/MHCalibrationRelTimeCam.[h,cc]:
      - new classes to fit and display the relative arrival times. 
      - filled from MArrivalTime	
@@ -23,8 +80,9 @@
 
 
+
  2004/02/14: Markus Gaug
 
-   * mcalib/Makefile
-   * mcalib/CalibLinkDef.h
+   * mcalib/Makefile, mcalib/CalibLinkDef.h:
+     - added MHCalibrationChargePINDiode
 
    * mcalib/MHCalibrationChargePINDiode.[h,cc]
@@ -62,5 +120,4 @@
    * macros/calibration.C 
      - changed pedestal displays accordingly
-
 
    * mjobs/MJPedestal.h
@@ -78,5 +135,4 @@
    * mcalib/MHGausEvent.[h,cc], mcalib/Makefile, mcalib/CalibLinkDef.h:
      - replaced by the improved version: MHGausEvents.[h,cc]
-
 
 
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotPix.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotPix.cc	(revision 3183)
@@ -16,8 +16,8 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
+!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Harald Kornmayer 1/2001
 !
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -31,11 +31,13 @@
 // Storage container for the signal in a pixel in number of photons.
 //
-// NOTE: This container is NOT ment for I/O. Write it to a file on your own
-//       risk!
+// NOTE: This container is NOT ment for I/O. Write it to a file on your
+//       own risk!
+//
+// fIsSaturated: boolean variable set to kTRUE whenever one or more of
+//               the low gain FADC slices of the pixel is in saturation.
 //
 // Version 2:
 // ----------
-// Added fIsSaturated, boolean variable set to kTRUE whenever one or more of 
-// the low gain FADC slices of the pixel is in saturation.
+//  - added fIsSaturated
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -67,5 +69,5 @@
     gLog << (fRing>0?"   Used ":" Unused ");
     gLog << (fIsCore?" Core ":"      ");
-    gLog << (fIsSaturated?" Saturated ":"Not Saturated");
-    gLog << "Nphot= " << fPhot << " Error(Nphot)=" << fErrPhot << endl;
+    gLog << (fIsSaturated?"   ":"Not") << " saturated";
+    gLog << " Nphot= " << fPhot << " Error(Nphot)=" << fErrPhot << endl;
 }
Index: trunk/MagicSoft/Mars/mbase/MAGIC.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MAGIC.h	(revision 3182)
+++ trunk/MagicSoft/Mars/mbase/MAGIC.h	(revision 3183)
@@ -44,16 +44,3 @@
 const Double_t kRad2Deg = 180.0/3.1415926535897932384626433832795028841971693993751;
 
-//
-// This is the definition of a global output stream, which by
-// default pipes all output to the stdout
-//
-
-#ifdef __LINUX__
-class MLog;
-#else
-#include "MLog.h"
 #endif
-
-R__EXTERN MLog gLog;
-
-#endif
Index: trunk/MagicSoft/Mars/mbase/MArgs.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MArgs.h	(revision 3182)
+++ trunk/MagicSoft/Mars/mbase/MArgs.h	(revision 3183)
@@ -1,8 +1,4 @@
 #ifndef MARS_MArgs
 #define MARS_MArgs
-
-#ifndef MARS_MAGIC
-#include "MAGIC.h"
-#endif
 
 #ifndef ROOT_TNamed
Index: trunk/MagicSoft/Mars/mbase/MLog.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.h	(revision 3182)
+++ trunk/MagicSoft/Mars/mbase/MLog.h	(revision 3183)
@@ -201,3 +201,9 @@
 };
 
-#endif
+//
+// This is the definition of a global output stream, which by
+// default pipes all output to the stdout
+//
+R__EXTERN MLog gLog;
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 3183)
@@ -60,4 +60,14 @@
 using namespace std;
 
+MParContainer::MParContainer(const char *name, const char *title) :
+    fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE)
+{
+}
+
+MParContainer::MParContainer(const TString &name, const TString &title) :
+    fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE)
+{
+}
+
 // --------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 3182)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 3183)
@@ -12,5 +12,4 @@
 #include "MAGIC.h"
 #endif
-
 #ifndef ROOT_TObject
 #include <TObject.h>
@@ -28,4 +27,6 @@
 class TDataMember;
 class TMethodCall;
+
+class MLog;
 class MStatusDisplay;
 
@@ -60,6 +61,6 @@
     };
 
-    MParContainer(const char *name="", const char *title="") : fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE) {  }
-    MParContainer(const TString &name, const TString &title) : fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE) {  }
+    MParContainer(const char *name="", const char *title="");
+    MParContainer(const TString &name, const TString &title);
     MParContainer(const MParContainer &named);
     MParContainer& operator=(const MParContainer& rhs);
Index: trunk/MagicSoft/Mars/mcalib/MCalibrate.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 3183)
@@ -17,5 +17,5 @@
 !
 !   Author(s): Javier Lopez 12/2003 <mailto:jlopez@ifae.es>
-!   Modified by: Javier Rico  01/2004 <mailto:jrico@ifae.es>
+!   Author(s): Javier Rico  01/2004 <mailto:jrico@ifae.es>
 !
 !   Copyright: MAGIC Software Development, 2000-2004
Index: trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc	(revision 3183)
@@ -17,6 +17,6 @@
 !
 !   Author(s): Javier Lopez    12/2003 <mailto:jlopez@ifae.es>
-!   Modified by: Javier Rico   01/2004 <mailto:jrico@ifae.es>
-!              Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
+!   Author(s): Javier Rico     01/2004 <mailto:jrico@ifae.es>
+!   Author(s): Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2004
Index: trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 3183)
@@ -18,5 +18,5 @@
 !   Author(s): Abelardo Moralejo, 12/2003 <mailto:moralejo@pd.infn.it>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -65,12 +65,9 @@
 MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
 {
-  fName  = name  ? name  : "MMcCalibrationCalc";
-  fTitle = title ? title : "Calculate and write conversion factors into MCalibrationCam Container";
-
-  fADC2Phot = 0.;
-  fEvents = 0;
-
-  fHistRatio = new TH1F(AddSerialNumber("HistRatio"), "log10(fPassPhotCone/fSize)", 1500, -3., 3.);
-  fHistRatio->GetXaxis()->SetTitle("log_{10}(fPassPhotCone / fSize) (in photons/ADC count)");
+    fName  = name  ? name  : "MMcCalibrationCalc";
+    fTitle = title ? title : "Calculate and write conversion factors into MCalibrationCam Container";
+
+    fHistRatio = new TH1F(AddSerialNumber("HistRatio"), "log10(fPassPhotCone/fSize)", 1500, -3., 3.);
+    fHistRatio->SetXTitle("log_{10}(fPassPhotCone / fSize) [phot/ADC count]");
 }
 
@@ -83,12 +80,12 @@
 Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
 {
-  const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
-  if (!run)
-    {
-      *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
-      return kTRUE;
-    }
-
-  return  run->GetRunType() == kRTMonteCarlo;
+    const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!run)
+    {
+        *fLog << warn << "Warning - cannot check file type, MRawRunHeader not found." << endl;
+        return kTRUE;
+    }
+
+    return  run->GetRunType() == kRTMonteCarlo;
 }
 
@@ -99,36 +96,36 @@
 Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
 {
-
-  fCalCam = (MCalibrationCam*) pList->FindObject(AddSerialNumber("MCalibrationCam"));
-
-  if ( !fCalCam )
-    {
-      *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MCalibrationCam") << "... aborting." << endl;
-      return kFALSE;
-    }
-
-  fHillas = (MHillas*) pList->FindCreateObj(AddSerialNumber("MHillas"));
-  if ( !fHillas)
-    {
-      *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MHillas") << "... aborting." << endl;
-      return kFALSE;
-    }
-
-  fNew = (MNewImagePar*) pList->FindCreateObj(AddSerialNumber("MNewImagePar"));
-  if ( !fNew)
-    {
-      *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MNewImagePar") << "... aborting." << endl;
-      return kFALSE;
-    }
-
-  fMcEvt = (MMcEvt*) pList->FindCreateObj(AddSerialNumber("MMcEvt"));
-  if ( !fMcEvt)
-    {
-      *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MMcEvt") << "... aborting." << endl;
-      return kFALSE;
-    }
-
-  return kTRUE;
-
+    fHistRatio->Reset();
+    fADC2Phot = 0;
+
+    fCalCam = (MCalibrationCam*) pList->FindObject(AddSerialNumber("MCalibrationCam"));
+    if (!fCalCam)
+    {
+        *fLog << err << AddSerialNumber("MCalibrationCam") << "not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fHillas = (MHillas*) pList->FindObject(AddSerialNumber("MHillas"));
+    if ( !fHillas)
+    {
+        *fLog << err << AddSerialNumber("MHillas") << "not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fNew = (MNewImagePar*)pList->FindObject(AddSerialNumber("MNewImagePar"));
+    if (!fNew)
+    {
+        *fLog << err << AddSerialNumber("MNewImagePar") << "not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fMcEvt = (MMcEvt*) pList->FindObject(AddSerialNumber("MMcEvt"));
+    if (!fMcEvt)
+    {
+        *fLog << err << AddSerialNumber("MMcEvt") << "not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
 }
 
@@ -144,36 +141,36 @@
   //
   if (!CheckRunType(pList))
-    {
-      *fLog << err << dbginf << "This is no MC file... aborting." << endl;
+  {
+      *fLog << err << "MMcCalibrationCalc can only used with MC files... aborting." << endl;
       return kFALSE;
-    }
+  }
 
   //
   // Now check the existence of all necessary containers.
   //
-
   fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
-  if ( ! fGeom )
-    {
-      *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MGeomCam") << "... aborting." << endl;
+  if (!fGeom)
+  {
+      *fLog << err << AddSerialNumber("MGeomCam") << " mot found... aborting." << endl;
       return kFALSE;
-    }
+  }
 
   fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
   if (!fHeaderFadc)
-    {
-      *fLog << err << dbginf << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
+  {
+      *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
       return kFALSE;
-    }
+  }
 
   for (UInt_t ipix = 0; ipix < fGeom->GetNumPixels(); ipix++)
-    {
+  {
       if (fHeaderFadc->GetPedestalRmsHigh(ipix) > 0 ||
-	  fHeaderFadc->GetPedestalRmsLow(ipix) > 0 )
-	{
-	  *fLog << err << endl << endl << dbginf << "You are trying to calibrate the data using a Camera file produced with added noise. Please use a noiseless file for calibration. Aborting..." << endl << endl;
+	  fHeaderFadc->GetPedestalRmsLow(ipix)  > 0 )
+      {
+          *fLog << err << "Trying to calibrate the data using a Camera file produced with added noise." << endl;
+          *fLog << "Please use a noiseless file for calibration... aborting." << endl << endl;
 	  return kFALSE;
-	}
-    }
+      }
+  }
 
   return kTRUE;
@@ -187,76 +184,73 @@
 Int_t MMcCalibrationCalc::Process()
 {
-
-  //
-  // Exclude events with some saturated pixel
-  //
-  if ( fNew->GetNumSaturatedPixels() > 0 )
+    //
+    // Exclude events with some saturated pixel
+    //
+    if (fNew->GetNumSaturatedPixels()>0)
+        return kTRUE;
+
+    //
+    // Exclude events with low Size (larger fluctuations)
+    // FIXME? The present cut (1000 "inner-pixel-counts") is somehow
+    // arbitrary. Might it be optimized?
+    //
+    if (fHillas->GetSize()<1000)
+        return kTRUE;
+
+    fADC2Phot += fMcEvt->GetPassPhotCone()/fHillas->GetSize();
+
+    fHistRatio->Fill(TMath::Log10(fMcEvt->GetPassPhotCone()/fHillas->GetSize()));
+
     return kTRUE;
-
-  //
-  // Exclude events with low Size (larger fluctuations)
-  // FIXME? The present cut (1000 "inner-pixel-counts") is somehow arbitrary. 
-  // Might it be optimized? 
-  //
-  if ( fHillas->GetSize() < 1000 )
+}
+
+// --------------------------------------------------------------------------
+//
+// Fill the MCalibrationCam object
+//
+Int_t MMcCalibrationCalc::PostProcess()
+{
+    const Stat_t n = fHistRatio->GetEntries();
+    if (n<1)
+    {
+        *fLog << err << "No events read... aborting." << endl;
+        return kFALSE;
+    }
+
+    fADC2Phot /= n;
+
+    //
+    // For the calibration we no longer use the mean,
+    // but the peak of the distribution:
+    //
+    const Int_t reach = 2;
+
+    Stat_t summax = 0;
+    Int_t  mode   = 0;
+
+    // FIXME: Is this necessary? We could use GetMaximumBin instead..
+    for (Int_t ibin = 1+reach; ibin <= fHistRatio->GetNbinsX()-reach; ibin++)
+    {
+        const Stat_t sum = fHistRatio->Integral(ibin-reach, ibin+reach);
+
+        if (sum <= summax)
+            continue;
+
+        summax = sum;
+        mode = ibin;
+    }
+
+    fADC2Phot = TMath::Power(10, fHistRatio->GetBinCenter(mode));
+
+    const Int_t num = fCalCam->GetSize();
+    for (int i=0; i<num; i++)
+    {
+        MCalibrationPix &calpix = (*fCalCam)[i];
+
+        const Float_t factor = fADC2Phot*calpix.GetMeanConversionBlindPixelMethod();
+
+        calpix.SetConversionBlindPixelMethod(factor, 0., 0.);
+    }
+
     return kTRUE;
-
-  fADC2Phot += fMcEvt->GetPassPhotCone() / fHillas->GetSize();
-  fEvents ++;
-
-  fHistRatio->Fill(log10(fMcEvt->GetPassPhotCone()/fHillas->GetSize()));
-
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Fill the MCalibrationCam object
-//
-Int_t MMcCalibrationCalc::PostProcess()
-{
-
-  if (fEvents > 0)
-    fADC2Phot /= fEvents;
-  else
-    {
-      *fLog << err << dbginf << "No events were read! Aborting." << endl;
-      return kFALSE;
-    }
-
-  //
-  // For the calibration we no longer use the mean, but thepeak of the distribution:
-  //
-
-  Float_t summax = 0.;
-  Int_t mode = 0;
-  Int_t reach = 2;
-  for (Int_t ibin = 1+reach; ibin <= fHistRatio->GetNbinsX()-reach; ibin++)
-    {
-      Float_t sum = 0;
-      for(Int_t k = ibin-reach; k <= ibin+reach; k++)
-	sum += fHistRatio->GetBinContent(k);
-      if (sum > summax)
-	{
-	  summax = sum;
-	  mode = ibin;
-	}
-    }
-
-  fADC2Phot = pow(10., fHistRatio->GetXaxis()->GetBinCenter(mode));
-
-  const int num = fCalCam->GetSize();
-  
-  for (int i=0; i<num; i++)
-    {
-      MCalibrationPix &calpix = (*fCalCam)[i];
-
-      Float_t factor =  fADC2Phot*calpix.GetMeanConversionBlindPixelMethod();
-
-      calpix.SetConversionBlindPixelMethod(factor, 0., 0.);
-      
-    }
-
-  return kTRUE;
-
-}
+}
Index: trunk/MagicSoft/Mars/mfilter/MFCosmics.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFCosmics.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mfilter/MFCosmics.cc	(revision 3183)
@@ -33,13 +33,4 @@
 //   the outer pixels have some defect).
 //
-//   ProProcess:  Search for MPedestalCam, MExtractedSignalCam
-//               
-//   ReInit:      Initialize number of used FADC slices
-//
-//   Process:     if fMaxEmptyPixels pixels lower than 3 pedRMS, 
-//                the event is supposed to 
-//                be a cosmic and kContinue is returned
-//
-//
 //  Input Containers:
 //   MRawEvtData
@@ -120,6 +111,5 @@
 // --------------------------------------------------------------------------
 //
-// The ReInit searches the following input containers for information:
-//  - MExtractedSignalCam
+// Initialize number of used FADC slices
 //
 Bool_t MFCosmics::ReInit(MParList *pList)
Index: trunk/MagicSoft/Mars/mimage/MHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillas.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mimage/MHillas.cc	(revision 3183)
@@ -188,10 +188,8 @@
 Int_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
 {
-    const UInt_t npixevt = evt.GetNumPixels();
-
-    //
-    // sanity check
-    //
-    if (npixevt < 3)
+    //
+    // sanity check 1
+    //
+    if (evt.GetNumPixels()<3)
         return 1;
 
@@ -209,16 +207,13 @@
     fSize  = 0;
 
-    Int_t numused = 0;
-
-    for (UInt_t i=0; i<npixevt; i++)
+    MCerPhotPix *pix = 0;
+
+    TIter Next(evt);
+    UInt_t numused = 0;
+    while ((pix=(MCerPhotPix*)Next()))
     {
-        const MCerPhotPix &pix = evt[i];
-
-        if (!pix.IsPixelUsed())
-            continue;
-
-        const MGeomPix &gpix = geom[pix.GetPixId()];
-
-        const Float_t nphot = pix.GetNumPhotons();
+        const MGeomPix &gpix = geom[pix->GetPixId()];
+
+        const Float_t nphot = pix->GetNumPhotons();
 
         fSize  += nphot;		             // [counter]
@@ -230,5 +225,5 @@
 
     //
-    // sanity checks
+    // sanity check 2
     //
     if (fSize==0)
@@ -238,4 +233,7 @@
     fMeanY /= fSize;                                 // [mm]
 
+    //
+    // sanity check 3
+    //
     if (numused<3)
         return 3;
@@ -254,17 +252,13 @@
     Double_t corryy=0;                               // [m^2]
 
-    for (UInt_t i=0; i<npixevt; i++)
+    Next.Reset();
+    while ((pix=(MCerPhotPix*)Next()))
     {
-        const MCerPhotPix &pix = evt[i];
-
-        if (!pix.IsPixelUsed())
-            continue;
-
-        const MGeomPix &gpix = geom[pix.GetPixId()];
+        const MGeomPix &gpix = geom[pix->GetPixId()];
 
         const Float_t dx = gpix.GetX() - fMeanX;     // [mm]
         const Float_t dy = gpix.GetY() - fMeanY;     // [mm]
 
-        const Float_t nphot = pix.GetNumPhotons();   // [#phot]
+        const Float_t nphot = pix->GetNumPhotons();  // [#phot]
 
         corrxx += nphot * dx*dx;                     // [mm^2]
@@ -297,18 +291,18 @@
     const Double_t d0    = corryy - corrxx;
     const Double_t d1    = corrxy*2;
-    const Double_t d2    = d0 + sqrt(d0*d0 + d1*d1);
+    const Double_t d2    = d0 + TMath::Sqrt(d0*d0 + d1*d1);
     const Double_t tand  = d2 / d1;
     const Double_t tand2 = tand*tand;
 
-    fDelta = atan(tand);
+    fDelta = TMath::ATan(tand);
 
     const Double_t s2 = tand2+1;
-    const Double_t s  = sqrt(s2);
+    const Double_t s  = TMath::Sqrt(s2);
 
     fCosDelta =  1.0/s;   // need these in derived classes
     fSinDelta = tand/s;   // like MHillasExt
 
-    Double_t axis1 = (tand2*corryy + d2 + corrxx)/s2/fSize;
-    Double_t axis2 = (tand2*corrxx - d2 + corryy)/s2/fSize;
+    const Double_t axis1 = (tand2*corryy + d2 + corrxx)/s2/fSize;
+    const Double_t axis2 = (tand2*corrxx - d2 + corryy)/s2/fSize;
 
     //
@@ -320,6 +314,6 @@
     // very small numbers can get negative by rounding
     //
-    fLength = axis1<0 ? 0 : sqrt(axis1);  // [mm]
-    fWidth  = axis2<0 ? 0 : sqrt(axis2);  // [mm]
+    fLength = axis1<0 ? 0 : TMath::Sqrt(axis1);  // [mm]
+    fWidth  = axis2<0 ? 0 : TMath::Sqrt(axis2);  // [mm]
 
     SetReadyToSave();
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 3183)
@@ -329,5 +329,4 @@
 void MImgCleanStd::CleanStep1()
 {
-    const Int_t entries = fEvt->GetNumPixels();
     const TArrayD &data = fData->GetData();
 
@@ -335,12 +334,12 @@
     // check the number of all pixels against the noise level and
     // set them to 'unused' state if necessary
-    // 
-    for (Int_t i=0; i<entries; i++ )
-    {
-        MCerPhotPix &pix = (*fEvt)[i];
-
-        if (data[pix.GetPixId()] <= fCleanLvl1)
-            pix.SetPixelUnused();
-    }
+    //
+    MCerPhotPix *pix;
+
+    // Loop over all pixels
+    MCerPhotEvtIter Next(fEvt, kFALSE);
+    while ((pix=static_cast<MCerPhotPix*>(Next())))
+        if (data[pix->GetPixId()] <= fCleanLvl1)
+            pix->SetPixelUnused();
 }
 
@@ -351,40 +350,14 @@
 //  neighbors).
 //
-//  Takes the maximum pixel id from CleanStep1 as an argument
-//
 void MImgCleanStd::CleanStep2()
 {
-    const Int_t entries = fEvt->GetNumPixels();
-
-    //
-    // In the worst case we have to loop 6 times 577 times, to
-    // catch the behaviour of all next neighbors. Here we can gain
-    // much by using an array instead of checking through all pixels
-    // (MCerPhotEvt::IsPixelUsed) all the time.
-    //
-    // We allocate the array ourself because the TArrays always do
-    // range check which slows down the access to the array
-    // by 25-50%
-    //
-    Byte_t *ispixused = new Byte_t[fCam->GetNumPixels()];
-    memset(ispixused, 0, sizeof(Byte_t)*fCam->GetNumPixels());
-
-    for (Int_t i=0; i<entries; i++)
-    {
-        const MCerPhotPix &pix = (*fEvt)[i];
-        ispixused[pix.GetPixId()] = pix.IsPixelUsed() ? 1 : 0 ;
-   }
-
-    for (Int_t i=0; i<entries; i++)
-    {
-        // get entry i from list
-        MCerPhotPix &pix = (*fEvt)[i];
-
-	// get pixel id of this entry
-        const Int_t idx = pix.GetPixId();
-
-	// check if pixel is in use, if not goto next pixel in list
-	if (ispixused[idx] == 0)
-            continue;
+    MCerPhotPix *pix;
+
+    // Loop over used pixels only
+    TIter Next(*fEvt);
+    while ((pix=static_cast<MCerPhotPix*>(Next())))
+    {
+        // get pixel id of this entry
+        const Int_t idx = pix->GetPixId();
  
         // check for 'used' neighbors of this pixel
@@ -400,5 +373,5 @@
 
 	    // when you find an used neighbor, break the loop
-            if (ispixused[idx2] == 1)
+            if (fEvt->IsPixelUsed(idx2))
             {
                 hasNeighbor = kTRUE;
@@ -408,19 +381,13 @@
 
 	if (hasNeighbor == kFALSE)
-            pix.SetPixelUnused();
-    }
-
-    delete ispixused;
+            pix->SetPixelUnused();
+    }
 
     //
     // now we declare all pixels that survive as CorePixels
     //
-    for (Int_t i=0; i<entries; i++)
-    {
-        MCerPhotPix &pix = (*fEvt)[i];
-
-        if (pix.IsPixelUsed())
-            pix.SetPixelCore();
-    }
+    Next.Reset();
+    while ((pix=static_cast<MCerPhotPix*>(Next())))
+        pix->SetPixelCore();
 } 
 
@@ -440,5 +407,5 @@
         const Int_t idx2 = gpix.GetNeighbor(j);
 
-	if (!fEvt->GetPixById(idx2) || !fEvt->IsPixelCore(idx2))
+	if (!fEvt->IsPixelCore(idx2))
             continue;
 
@@ -459,7 +426,10 @@
 void MImgCleanStd::CleanStep4(UShort_t r, MCerPhotPix &pix)
 {
-  // Skip events that have already a defined status;
-	if( pix.GetRing()!= 0)
-	  return;
+    //
+    // Skip events that have already a defined status;
+    //
+    if (pix.GetRing() != 0)
+        return;
+
     //
     // check if the pixel's next neighbor is a used pixel.
@@ -478,7 +448,6 @@
 
         MCerPhotPix *npix = fEvt->GetPixById(idx2);
-
         if (!npix || !npix->IsPixelUsed() || npix->GetRing()>r-1 ) 
-	continue;
+            continue;
 
         pix.SetRing(r);
@@ -495,29 +464,27 @@
 void MImgCleanStd::CleanStep3()
 {
-    const Int_t entries = fEvt->GetNumPixels();
     const TArrayD &data = fData->GetData();
 
     for (UShort_t r=1; r<fCleanRings+1; r++)
     {
-        for (Int_t i=0; i<entries; i++)
+        MCerPhotPix *pix;
+
+        // Loop over all pixels
+        MCerPhotEvtIter NextAll(fEvt, kFALSE);
+        while ((pix=static_cast<MCerPhotPix*>(NextAll())))
         {
-            //
-            // get pixel as entry il from list
-            //
-            MCerPhotPix &pix = (*fEvt)[i];
-
             //
             // if pixel is a core pixel go to the next pixel
             //
-            if (pix.IsPixelCore())
+            if (pix->IsPixelCore())
                 continue;
 
-            if (data[pix.GetPixId()] <= fCleanLvl2)
+            if (data[pix->GetPixId()] <= fCleanLvl2)
                 continue;
 
             if (r==1)
-                CleanStep3b(pix);
+                CleanStep3b(*pix);
             else
-                CleanStep4(r, pix);
+                CleanStep4(r, *pix);
         }
     }
Index: trunk/MagicSoft/Mars/mimage/MNewImagePar.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 3183)
@@ -18,5 +18,5 @@
 !   Author(s): Wolfgang Wittek 03/2003 <mailto:wittek@mppmu.mpg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -31,8 +31,10 @@
 // fLeakage1 ratio: (photons in most outer ring of pixels) over fSize
 // fLeakage2 ratio: (photons in the 2 outer rings of pixels) over fSize
+// fNumSaturatedPixels: number of pixels in which at least one slice
+//                      of the low gain FADC was saturated.
 //
 // Version 2:
-// Added fNumSaturatedPixels: number of pixels in which at least one slice
-// of the low gain FADC was saturated.
+// ----------
+//  - added fNumSaturatedPixels
 // 
 /////////////////////////////////////////////////////////////////////////////
@@ -106,9 +108,18 @@
         const MCerPhotPix &pix = evt[i];
 
+        // count saturated pixels
 	if (pix.IsPixelSaturated())
-	  fNumSaturatedPixels++;
+            fNumSaturatedPixels++;
 
+        // skip unused pixels
         if (!pix.IsPixelUsed())
             continue;
+
+        // count used and core pixels
+        if (pix.IsPixelCore())
+            fNumCorePixels++;
+
+        // count used pixels
+        fNumUsedPixels++;
 
         const Int_t pixid = pix.GetPixId();
@@ -125,12 +136,4 @@
         if (gpix.IsInOuterRing())
            edgepix2 += nphot;
-
-        //
-        // count used and core pixels
-        //
-        if (pix.IsPixelCore())
-            fNumCorePixels++;
-
-        fNumUsedPixels++;
 
         //
@@ -172,3 +175,4 @@
     *fLog << " - Used Pixels    [#]   = " << fNumUsedPixels << " Pixels" << endl;
     *fLog << " - Core Pixels    [#]   = " << fNumCorePixels << " Pixels" << endl;
+    *fLog << " - Sat. Pixels    [#]   = " << fNumSaturatedPixels << " Pixels" << endl;
 }
Index: trunk/MagicSoft/Mars/mimage/MNewImagePar.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MNewImagePar.h	(revision 3182)
+++ trunk/MagicSoft/Mars/mimage/MNewImagePar.h	(revision 3183)
@@ -13,14 +13,13 @@
 {
 private:
-    Float_t fLeakage1;      // (photons in most outer ring of pixels) over fSize
-    Float_t fLeakage2;      // (photons in the 2 outer rings of pixels) over fSize
+    Float_t fLeakage1;           // (photons in most outer ring of pixels) over fSize
+    Float_t fLeakage2;           // (photons in the 2 outer rings of pixels) over fSize
 
-    Float_t fConc;          // [ratio] concentration ratio: sum of the two highest pixels / fSize
-    Float_t fConc1;         // [ratio] concentration ratio: sum of the highest pixel / fSize
+    Float_t fConc;               // [ratio] concentration ratio: sum of the two highest pixels / fSize
+    Float_t fConc1;              // [ratio] concentration ratio: sum of the highest pixel / fSize
 
-    Short_t fNumUsedPixels; // Number of pixels which survived the image cleaning
-    Short_t fNumCorePixels; // number of core pixels
-
-    Short_t fNumSaturatedPixels; // number of saturated pixels
+    Short_t fNumUsedPixels;      // Number of pixels which survived the image cleaning
+    Short_t fNumCorePixels;      // number of core pixels
+    Short_t fNumSaturatedPixels; // number of pixels with saturating lo-gains
 
 public:
@@ -29,12 +28,12 @@
     void Reset();
 
-    Float_t GetLeakage1() const    { return fLeakage1; }
-    Float_t GetLeakage2() const    { return fLeakage2; }
+    Float_t GetLeakage1() const { return fLeakage1; }
+    Float_t GetLeakage2() const { return fLeakage2; }
 
-    Float_t GetConc() const        { return fConc; }
-    Float_t GetConc1() const       { return fConc1; }
+    Float_t GetConc() const  { return fConc;  }
+    Float_t GetConc1() const { return fConc1; }
 
-    Int_t GetNumUsedPixels() const { return fNumUsedPixels; }
-    Int_t GetNumCorePixels() const { return fNumCorePixels; }
+    Short_t GetNumUsedPixels() const { return fNumUsedPixels; }
+    Short_t GetNumCorePixels() const { return fNumCorePixels; }
 
     Short_t GetNumSaturatedPixels() const { return fNumSaturatedPixels; }
@@ -49,29 +48,2 @@
 
 #endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: trunk/MagicSoft/Mars/mraw/MRawCrateArray.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawCrateArray.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawCrateArray.cc	(revision 3183)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
Index: trunk/MagicSoft/Mars/mraw/MRawCrateData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawCrateData.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawCrateData.cc	(revision 3183)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 3183)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 3183)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Author(s): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 3183)
@@ -19,5 +19,5 @@
 !   Author(s): Markus Gaus 10/2002 <mailto:markus@ifae.es>
 !
-!   Copyright: MAGIC Software Development, 2000-2002
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 3183)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -148,5 +148,7 @@
     // Read RUN HEADER (see specification) from input stream
     //
-    fRawRunHeader->ReadEvt(*fIn);
+    if (!fRawRunHeader->ReadEvt(*fIn))
+        return kFALSE;
+
     if (!(*fIn))
     {
@@ -154,6 +156,6 @@
         return kFALSE;
     }
-    if (fRawRunHeader->GetMagicNumber()!=kMagicNumber)
-        return kFALSE;
+    //if (fRawRunHeader->GetMagicNumber()!=kMagicNumber)
+    //    return kFALSE;
 
     fRawRunHeader->Print();
Index: trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 3183)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
Index: trunk/MagicSoft/Mars/mraw/MRawRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRead.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawRead.cc	(revision 3183)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Author(s): Thomas Bretz 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 3183)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Author(s): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -101,5 +101,5 @@
 // Read in one run header from the binary file
 //
-void MRawRunHeader::ReadEvt(istream& fin)
+Bool_t MRawRunHeader::ReadEvt(istream& fin)
 {
     //
@@ -116,5 +116,5 @@
     {
         *fLog << err << "Error: Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
-        return;
+        return kFALSE;
     }
 
@@ -125,6 +125,9 @@
 
     fin.read((char*)&fFormatVersion,    2);     // Total=4
-    if (fFormatVersion>2)
-        *fLog << warn << "WARNING - Format version V" << fFormatVersion << " unknown!" << endl;
+    if (fFormatVersion>kMaxFormatVersion)
+    {
+        *fLog << err << "WARNING - File vormat V" << fFormatVersion << " not implemented!" << endl;
+        return kFALSE;
+    }
 
     fin.read((char*)&fSoftVersion,      2);     // Total=6
@@ -165,4 +168,6 @@
     fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
     fin.read((char*)&dummy, 16);
+
+    return kTRUE;
 }
 
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 3183)
@@ -17,5 +17,6 @@
 // Magic number to detect the magic file type
 //
-const UShort_t kMagicNumber = 0xc0c0;
+const UShort_t kMagicNumber      = 0xc0c0;
+const Byte_t   kMaxFormatVersion =      3;
 
 //
@@ -106,5 +107,5 @@
     void Print(Option_t *t=NULL) const;
 
-    void ReadEvt(istream& fin);
+    Bool_t ReadEvt(istream& fin);
 
     ClassDef(MRawRunHeader, 2)	// storage container for general info
Index: trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc	(revision 3183)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -220,12 +220,9 @@
     //
     fLog->SetNullOutput();
-    fRawRunHeader->ReadEvt(*fIn);
+    const Bool_t rc = fRawRunHeader->ReadEvt(*fIn);
     fLog->SetNullOutput(kFALSE);
 
-    if (fRawRunHeader->GetMagicNumber()!=kMagicNumber && fRawRunHeader->GetMagicNumber()!=kMagicNumber+1)
-    {
-        *fLog << err << "Error: Wrong Magic Number (0x" << hex << fRawRunHeader->GetMagicNumber() << "): Not a Magic File!" << endl;
-        return kFALSE;
-    }
+    if (!rc)
+        return kFALSE;
 
     if (fRunNumber!=fRawRunHeader->GetRunNumber())
Index: trunk/MagicSoft/Mars/star.cc
===================================================================
--- trunk/MagicSoft/Mars/star.cc	(revision 3182)
+++ trunk/MagicSoft/Mars/star.cc	(revision 3183)
@@ -71,4 +71,212 @@
 }
 
+class MJStar : public MParContainer
+{
+private:
+    TString fInputFile;
+    TString fOutputFile;
+
+    Bool_t fIsUpdate;
+    Byte_t fComprLevel;
+
+    Byte_t fSerialIdx;
+
+    Bool_t CheckFiles()
+    {
+        if (fOutputFile.IsNull())
+        {
+            fOutputFile = fInputFile;
+
+            if (fOutputFile.EndsWith(".raw"))
+                fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
+
+            if (fOutputFile.EndsWith(".rep"))
+                fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
+
+            if (fOutputFile.EndsWith(".txt"))
+                fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
+        }
+
+        if (fInputFile.IsNull())
+        {
+            *fLog << err << "Sorry, no input file." << endl;
+            return kFALSE;
+        }
+
+        if (fOutputFile.IsNull())
+        {
+            *fLog << err << "Sorry, no output file." << endl;
+            return kFALSE;
+        }
+
+        if (!fInputFile.EndsWith(".root"))
+            fInputFile += ".root";
+
+        if (!fOutputFile.EndsWith(".root"))
+            fOutputFile += ".root";
+
+        //
+        // check whether the given files are OK.
+        //
+        if (gSystem->AccessPathName(fInputFile, kFileExists))
+        {
+            *fLog << err << "Sorry, the input file '" << fInputFile << "' doesn't exist." << endl;
+            return kFALSE;
+        }
+
+        if (!gSystem->AccessPathName(fOutputFile, kFileExists))
+        {
+            if (fIsUpdate)
+                gLog << warn << "Warning: File doesn't '" << fOutputFile << "' exist... recreating." << endl;
+        }
+
+        if (fIsUpdate || gSystem->AccessPathName(fOutputFile, kFileExists))
+            if (!gSystem->AccessPathName(fOutputFile, kWritePermission))
+        {
+            gLog << err << "Sorry, you don't have write permission for '" << fOutputFile << "'." << endl;
+            return kFALSE;
+        }
+        return kTRUE;
+    }
+
+public:
+    MJStar(const char *name=0, const char *title=0)
+        : fIsUpdate(kFALSE), fComprLevel(1), fSerialIdx(0)
+    {
+        fName  = name;
+        fTitle = title;
+    }
+
+    void SetInputFile(const char *f)  { fInputFile  = f; }
+    void SetOutputFile(const char *f) { fOutputFile = f; }
+    void SetSerialIdx(Byte_t i)       { fSerialIdx  = i; }
+    void SetComprLevel(Byte_t l)      { fComprLevel = l; }
+    void SetUpdate(Bool_t u=kTRUE)    { fIsUpdate   = u; }
+
+    Bool_t Process()
+    {
+        if (!CheckFiles())
+            return kFALSE;
+
+        //
+        // Create a empty Parameter List and an empty Task List
+        // The tasklist is identified in the eventloop by its name
+        //
+        MParList plist;
+
+        MTaskList tlist;
+        plist.AddToList(&tlist);
+
+        // PRELIMINARY:
+        /*
+         MReportDrive rep;
+         plist.AddToList(&rep);
+         MPointingPos pos;
+         plist.AddToList(&pos);
+         */
+
+        //
+        // Now setup the tasks and tasklist:
+        // ---------------------------------
+        //
+        MReadMarsFile read("Events", fInputFile);
+        read.DisableAutoScheme();
+
+        MGeomApply        apply;
+        MMcPedestalCopy   pcopy;
+        MMcPedestalNSBAdd pnsb;
+
+        //MPointingPosCalc  pcalc;
+
+        MCerPhotCalc      ncalc;
+        MCerPhotAnal2     nanal;
+
+        MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);
+        MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);
+
+        ncalc.SetFilter(&f1);
+        nanal.SetFilter(&f2);
+
+        MBlindPixelCalc   blind;
+        MSigmabarCalc     sgcal;
+        //MFillH            fills("MHSigmaTheta",  "", "FillSigmaTheta");
+        //MFillH            fillb("MHBlindPixels", "", "FillBlindPixels");
+        MImgCleanStd      clean;
+        MHillasCalc       hcalc;
+        MHillasSrcCalc    scalc; // !!Preliminary!! Will be removed later!
+        MWriteRootFile    write(fOutputFile, fIsUpdate?"UPDATE":"RECREATE", "Star output", fComprLevel);
+
+        tlist.AddToList(&read);
+        tlist.AddToList(&f1);
+        tlist.AddToList(&f2);
+        tlist.AddToList(&apply);
+        tlist.AddToList(&pcopy);
+        tlist.AddToList(&pnsb);
+        //tlist.AddToList(&pcalc);
+        tlist.AddToList(&ncalc);
+        tlist.AddToList(&nanal);
+        tlist.AddToList(&blind);
+        tlist.AddToList(&sgcal);
+        //tlist.AddToList(&fills);
+        //tlist.AddToList(&fillb);
+        tlist.AddToList(&clean);
+        tlist.AddToList(&hcalc);
+        tlist.AddToList(&scalc);
+        tlist.AddToList(&write);
+
+        //
+        // Set the serial number for all tasks in the current tasklist
+        //
+        tlist.SetSerialNumber(fSerialIdx);
+
+        //
+        // Setup tasks
+        //
+        blind.SetUseInterpolation();
+
+        write.AddContainer(write.AddSerialNumber("MMcEvt"),       "Events", kFALSE);
+        write.AddContainer(write.AddSerialNumber("MSigmabar"),    "Events");
+        write.AddContainer(write.AddSerialNumber("MHillas"),      "Events");
+        write.AddContainer(write.AddSerialNumber("MHillasExt"),   "Events");
+        write.AddContainer(write.AddSerialNumber("MHillasSrc"),   "Events");
+        write.AddContainer(write.AddSerialNumber("MNewImagePar"), "Events");
+        write.AddContainer(write.AddSerialNumber("MSrcPosCam"),   "RunHeaders");
+        //write.AddContainer(write.AddSerialNumber("MHSigmaTheta"), "RunHeaders");
+        if (!fIsUpdate)
+        {
+            write.AddContainer("MRawRunHeader", "RunHeaders");
+            write.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
+        }
+
+        //
+        // Create and set up the eventloop
+        //
+        MEvtLoop evtloop;
+        evtloop.SetParList(&plist);
+
+        //
+        // Execute your analysis
+        //
+        if (!evtloop.Eventloop())
+        {
+            gLog << err << "ERROR: Star eventloop failed!" << endl;
+            return kFALSE;
+        }
+
+        tlist.PrintStatistics();
+
+        //plist.FindObject("MHSigmaTheta")->Write();
+        //plist.FindObject("MHBlindPixels")->Write();
+
+        gLog << all << "Star finished successfull!" << endl;
+
+        return kTRUE;
+    }
+//    ClassDef(MJStar, 0)
+};
+
+//ClassImp(MJStar);
+
+
 int main(const int argc, char **argv)
 {
@@ -102,4 +310,29 @@
 
     //
+    // Initialize Non-GUI (batch) mode
+    //
+    gROOT->SetBatch();
+
+    MArray::Class()->IgnoreTObjectStreamer();
+    MParContainer::Class()->IgnoreTObjectStreamer();
+
+    MJStar star;
+    star.SetInputFile(arg.GetArgumentStr(0));
+    star.SetOutputFile(arg.GetArgumentStr(1));
+    star.SetComprLevel(kComprlvl);
+    star.SetSerialIdx(kTelIndex);
+    star.SetUpdate(kUpdate);
+
+    if (!star.Process())
+    {
+        gLog << err << "Star failed!" << endl;
+        return -1;
+    }
+
+    gLog << inf << "Star finished successfull!" << endl;
+
+    return 0;
+/*
+    //
     // This is to make argv[i] more readable inside the code
     //
@@ -114,9 +347,4 @@
 
     //
-    // Initialize Non-GUI (batch) mode
-    //
-    gROOT->SetBatch();
-
-    //
     // check whether the given files are OK.
     //
@@ -140,7 +368,4 @@
         }
 
-    MArray::Class()->IgnoreTObjectStreamer();
-    MParContainer::Class()->IgnoreTObjectStreamer();
-
     //
     // Create a empty Parameter List and an empty Task List
@@ -153,10 +378,8 @@
 
     // PRELIMINARY:
-    /*
-     MReportDrive rep;
-     plist.AddToList(&rep);
-     MPointingPos pos;
-     plist.AddToList(&pos);
-     */
+    // MReportDrive rep;
+    // plist.AddToList(&rep);
+    // MPointingPos pos;
+    // plist.AddToList(&pos);
 
     //
@@ -255,3 +478,4 @@
     gLog << all << "Star finished successfull!" << endl;
     return 0;
+    */
 }
