Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2455)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2456)
@@ -1,4 +1,4 @@
                                                  -*-*- END OF LINE -*-*-
-  2003/11/03: Thomas Bretz
+ 2003/11/03: Thomas Bretz
   
    * manalysis/MMcPedestalCopy.[h,cc], manalysis/MMcPedestalNSBAdd.[h,cc]:
@@ -26,7 +26,16 @@
      - added comments to the data members
 
-
-
-  2003/10/31: Marcos Lopez
+   * mars.cc:
+     - added code for a possible use of a TGApplication
+       (in comments)
+
+   * merpp.cc, readraw.cc:
+     - unified with the other executables (StartUpMessage, etc)
+     - removed TROOT-object
+     - readraw.cc: added more functionality
+
+
+
+ 2003/10/31: Marcos Lopez
 
    * mhist/MFillH.cc:
@@ -51,5 +60,5 @@
 
 
-  2003/10/31: Thomas Bretz
+ 2003/10/31: Thomas Bretz
 
    * mars.cc:
@@ -60,5 +69,5 @@
 
 
-  2003/10/30: Antonio Stamerra
+ 2003/10/30: Antonio Stamerra
 
    * manalysis/MMcTriggerLvl2.[h,cc]
@@ -73,5 +82,5 @@
 
 
-  2003/10/30: Thomas Bretz
+ 2003/10/30: Thomas Bretz
 
    * manalysis/MCerPhotEvt.[h,cc]:
@@ -90,5 +99,5 @@
 
 
-  2003/10/29: Thomas Bretz
+ 2003/10/29: Thomas Bretz
   
    * manalysis/AnalysisLinkDef.h, manalysis/Makefile:
@@ -118,5 +127,5 @@
 
 
-  2003/10/28: Thomas Bretz
+ 2003/10/28: Thomas Bretz
   
    * macros/readCT1.C:
@@ -159,5 +168,5 @@
 
 
-  2003/10/28: Wolfgang Wittek
+ 2003/10/28: Wolfgang Wittek
 
    * manalysis/MCT1PadONOFF.cc
@@ -175,5 +184,5 @@
 
 
-  2003/10/26: Oscar Blanch Bigas
+ 2003/10/26: Oscar Blanch Bigas
 
    * mmc/MMcFadcHeader.[cc,h]
@@ -184,5 +193,5 @@
 
 
-  2003/10/24: Abelardo Moralejo
+ 2003/10/24: Abelardo Moralejo
 
    * manalysis/MMcPedestalRead.[cc,h]
@@ -197,5 +206,5 @@
 
 
-  2003/10/23: Abelardo Moralejo
+ 2003/10/23: Abelardo Moralejo
 
    * mhistmc/MHMcEnergyMigration.cc
@@ -207,5 +216,5 @@
 
 
-  2003/10/23: Thomas Bretz
+ 2003/10/23: Thomas Bretz
 
    * macros/star.C:
@@ -217,5 +226,5 @@
 
 
-  2003/10/22: Thomas Bretz
+ 2003/10/22: Thomas Bretz
   
    * mars.cc:
@@ -232,5 +241,5 @@
 
 
-  2003/10/21: Wolfgang Wittek
+ 2003/10/21: Wolfgang Wittek
 
   * manalysis/MMatrixLoop.[h,cc]
@@ -242,5 +251,5 @@
 
 
-  2003/10/20: Thomas Bretz
+ 2003/10/20: Thomas Bretz
 
    * mraw/MRawEvtPixelIter.[h,cc]:
@@ -331,5 +340,5 @@
 
 
-  2003/10/17: Oscar Blanch
+ 2003/10/17: Oscar Blanch
 
    * mmc/MMcFadcHeader.[cxx,hxx]:
@@ -348,5 +357,5 @@
 
 
-  2003/10/15: Thomas Bretz
+ 2003/10/15: Thomas Bretz
 
    * Makefile.conf.general:
@@ -402,5 +411,5 @@
 
 
-  2003/10/05: Abelardo Moralejo
+ 2003/10/05: Abelardo Moralejo
 
    * macros/star.C:
@@ -410,5 +419,5 @@
 
 
-  2003/10/04: Thomas Bretz
+ 2003/10/04: Thomas Bretz
 
    * macros/MagicHillas.C, macros/pedestalvstime.C, macros/pixfirerate.C,
@@ -456,5 +465,5 @@
 
 
-  2003/10/02: Thomas Bretz
+ 2003/10/02: Thomas Bretz
 
    * mraw/MRawEvtData.cc:
@@ -463,5 +472,5 @@
 
 
-  2003/10/01: Nicola Galante
+ 2003/10/01: Nicola Galante
 
    * mhistmc/MHMcTriggerLvl2.[h,cc]:
@@ -478,5 +487,5 @@
 
 
-  2003/09/30: Robert Wagner
+ 2003/09/30: Robert Wagner
 
    * mfileio/MCT1ReadPreProc.cc
@@ -486,5 +495,5 @@
 
 
-  2003/09/29: Nicola Galante & Antonio Stamerra
+ 2003/09/29: Nicola Galante & Antonio Stamerra
 
    * mmc/MMcTrig.cxx:
Index: /trunk/MagicSoft/Mars/mars.cc
===================================================================
--- /trunk/MagicSoft/Mars/mars.cc	(revision 2455)
+++ /trunk/MagicSoft/Mars/mars.cc	(revision 2456)
@@ -1,3 +1,2 @@
-#include <TROOT.h>
 #include <TApplication.h>
 
@@ -16,4 +15,28 @@
 
 using namespace std;
+/*
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
+#include <TRootGuiFactory.h>
+#include <TPluginManager.h>
+void InitGuiFactory()
+{
+    if (gROOT->IsBatch())
+        gROOT->SetBatch(kFALSE);
+
+    //
+    // Must be loaded by hand, because it is not loaded by TGApplication.
+    // We could also use TApplication instead, but TApplication doesn't
+    // deal with the DISPLAY variable in a convient way.
+    //
+    TPluginHandler *h;
+    if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", "root")))
+    {
+        if (h->LoadPlugin() == -1)
+            return;
+        gGuiFactory = (TGuiFactory*)h->ExecPlugin(0);
+    }
+}
+#endif
+*/
 
 // **********************************************************************
@@ -42,4 +65,5 @@
 static void Usage()
 {
+    gLog << all << endl;
     gLog << "Sorry the usage is:" << endl;
     gLog << "   mars [-v#]" << endl << endl;
@@ -58,16 +82,4 @@
 
     StartUpMessage();
-
-    TApplication app("MarsApp", &argc, argv);
-    if (gROOT->IsBatch() || !gClient)
-    {
-        gLog << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
-        return 1;
-    }
-    /*
-     TGApplication app("MarsApp", &argc, argv);
-     if (gROOT->IsBatch())
-        gROOT->SetBatch(kFALSE);
-     */
 
     //
@@ -111,8 +123,26 @@
 
     //
+    // initialise ROOT
+    //
+    TApplication app("Mars", &argc, argv);
+    if (gROOT->IsBatch() || !gClient)
+    {
+        gLog << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
+        return 1;
+    }
+
+    //
     // Swtich of TObjectStreamer in our base classes derived from TObject
     //
     MArray::Class()->IgnoreTObjectStreamer();
     MParContainer::Class()->IgnoreTObjectStreamer();
+
+    /*
+    TGApplication app("Mars", &argc, argv);
+
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
+    InitGuiFactory();
+#endif
+    */
 
 #ifdef HAVE_XPM
Index: /trunk/MagicSoft/Mars/merpp.cc
===================================================================
--- /trunk/MagicSoft/Mars/merpp.cc	(revision 2455)
+++ /trunk/MagicSoft/Mars/merpp.cc	(revision 2456)
@@ -36,6 +36,22 @@
 //////////////////////////////////////////////////////////////////////////////
 
-void Usage()
+static void StartUpMessage()
 {
+    gLog << all << endl;
+
+    //                1         2         3         4         5
+    //       12345678901234567890123456789012345678901234567890
+    gLog << "==================================================" << endl;
+    gLog << "                MERPP - MARS V" << MARSVER          << endl;
+    gLog << "     MARS - Merging and Preprocessing Program"      << endl;
+    gLog << "            Compiled on <" << __DATE__ << ">"       << endl;
+    gLog << "               Using ROOT v" << ROOTVER             << endl;
+    gLog << "==================================================" << endl;
+    gLog << endl;
+}
+
+static void Usage()
+{
+    gLog << all << endl;
     gLog << "Sorry the usage is:" << endl;
     gLog << "   merpp [-a0] [-vn] [-cn] inputfile[.raw] [outputfile[.root]]" << endl << endl;
@@ -43,5 +59,5 @@
     gLog << "     ouput file:   Merpped root file." << endl;
     gLog << "     -a0: Do not use Ansii codes." << endl;
-    gLog << "     -cn: Compression level n=1..9 [default=1]" << endl;
+    gLog << "     -cn: Compression level n=1..9 [default=2]" << endl;
     gLog << "     -vn: Verbosity level n [default=2]" << endl << endl;
 }
@@ -49,13 +65,10 @@
 int main(const int argc, const char **argv)
 {
+    StartUpMessage();
+
+    //
+    // Evaluate arguments
+    //
     MArgs arg(argc, argv);
-
-    gLog << "==================================================" << endl ;
-    gLog << "                   MERPP v0.1" << endl;
-    gLog << "      MARS Merging and Preprocessing Program" << endl ;
-    gLog << "            Compiled on <" << __DATE__ << ">" << endl ;
-    gLog << "               Using ROOT v" << ROOTVER << endl ;
-    gLog << "==================================================" << endl ;
-    gLog << endl;
 
     //
@@ -84,10 +97,4 @@
     TString kNameout = arg.GetArgumentStr(1);
 
-    //
-    //     initialize ROOT  (this is obligatory here)
-    //
-    TROOT merpp("merpp", "Mars - Merging and Preprocessing Program");
-    merpp.SetBatch();
-
     if (!kNamein.EndsWith(".raw"))
         kNamein += ".raw";
@@ -98,4 +105,9 @@
     if (!kNameout.EndsWith(".root"))
         kNameout += ".root";
+
+    //
+    // Initialize Non-GUI (batch) mode
+    //
+    gROOT->SetBatch();
 
     //
Index: /trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 2455)
+++ /trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 2456)
@@ -184,6 +184,6 @@
             if (manip)
                 *fLog << ' ';
-            *fLog << flush;
         }
+        *fLog << flush;
 
         if (!(l<nLoPix && (*fLoGainPixId)[l]==(*fHiGainPixId)[i]))
@@ -199,6 +199,7 @@
             if (manip)
                 *fLog << ' ';
-            *fLog << flush;
         }
+
+        *fLog << flush;
         l++;
     }
Index: /trunk/MagicSoft/Mars/readraw.cc
===================================================================
--- /trunk/MagicSoft/Mars/readraw.cc	(revision 2455)
+++ /trunk/MagicSoft/Mars/readraw.cc	(revision 2456)
@@ -10,4 +10,7 @@
 
 #include "MLog.h"
+#include "MLogManip.h"
+
+#include "MArgs.h"
 #include "MTime.h"
 #include "MRawRunHeader.h"
@@ -25,7 +28,35 @@
 //
 // This is an demonstration how to read in a merpped root file
+// This is a demonstration how to use root, not how you should
+// read a merpped file!
 //
 /////////////////////////////////////////////////////////////////////////////
 
+static void StartUpMessage()
+{
+    gLog << all << endl;
+
+    //                1         2         3         4         5
+    //       12345678901234567890123456789012345678901234567890
+    gLog << "==================================================" << endl;
+    gLog << "              ReadRaw - MARS V" << MARSVER          << endl;
+    gLog << "       MARS - Read and print raw data files"        << endl;
+    gLog << "            Compiled on <" << __DATE__ << ">"       << endl;
+    gLog << "               Using ROOT v" << ROOTVER             << endl;
+    gLog << "==================================================" << endl;
+    gLog << endl;
+}
+
+static void Usage()
+{
+    gLog << all << endl;
+    gLog << "Sorry the usage is:" << endl;
+    gLog << "   readraw [-vn] [-dec] [-a0] inputfile[.root]" << endl << endl;
+    gLog << "     input file:   Magic DAQ binary file." << endl;
+    gLog << "     -a0: Do not use Ansii codes." << endl;
+    gLog << "     -vn: Verbosity level n [default=2]" << endl;
+    gLog << "     -d1: print data in decimal values" << endl;
+}
+
 void EnableBranch(TTree *t, TString name, void *ptr)
 {
@@ -37,34 +68,51 @@
 }
 
-int main(const int argc, const char **argv)
-{
-    gLog << "==================================================" << endl;
-    gLog << "                   ReadRaw v0.1                   " << endl;
-    gLog << "       MARS - Read and print raw data file        " << endl;
-    gLog << "            Compiled on <" << __DATE__ << ">" << endl;
-    gLog << "==================================================" << endl;
-    gLog << endl;
+int main(int argc, const char **argv)
+{
+    StartUpMessage();
+
+    //
+    // Evaluate arguments
+    //
+    MArgs arg(argc, argv);
+
+    //
+    // Set verbosity to highest level.
+    //
+    gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
+
+    if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
+        gLog.SetNoColors();
+
+    const bool kDecimal = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
 
     //
     // check for the right usage of the program
     //
-    if (argc!=2)
-    {
-        gLog << "Sorry the usage is:" << endl;
-        gLog << "   readraw inputfile" << endl << endl;
+    if (arg.GetNumArguments()!=1)
+    {
+        Usage();
         return -1;
     }
 
     //
-    //     initialize ROOT  (this is obligatory here)
-    //
-    TROOT simple("readraw","Mars - Read and print raw data file");
+    // This is to make argv[i] more readable insidethe code
+    //
+    TString kNamein = arg.GetArgumentStr(0);
+  
+    if (!kNamein.EndsWith(".root"))
+        kNamein += ".root";
+
+    //
+    // Initialize Non-GUI (batch) mode
+    //
+    gROOT->SetBatch();
 
     //
     // check whether the given files are OK.
     //
-    if (gSystem->AccessPathName(argv[1], kFileExists))
-    {
-        gLog << "Sorry, the file '" << argv[1] << "' doesn't exist." << endl;
+    if (gSystem->AccessPathName(kNamein, kFileExists))
+    {
+        gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
         return -1;
     }
@@ -73,6 +121,6 @@
     //  open the file
     //
-    gLog << " Open the file '" << argv[1] << "'" << endl;
-    TFile input(argv[1], "READ");
+    gLog << " Open the file '" << kNamein << "'" << endl;
+    TFile input(kNamein, "READ");
 
     //
@@ -127,5 +175,5 @@
     // loop over all entries 
     //
-    Int_t nent = (Int_t)evttree->GetEntries();
+    const Int_t nent = (Int_t)evttree->GetEntries();
 
     gLog << endl;
@@ -153,11 +201,11 @@
             evtcrate->Print();
         if (evtdata)
-            evtdata->Print();
+            evtdata->Print(kDecimal?"dec":"hex");
+
+        gLog << endl;
     } 
     
-    //   end of small readin program 
+    // end of small readin program
 
     return 0;
 }
-
-
