Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 851)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 852)
@@ -1,3 +1,49 @@
                                                                   -*-*- END -*-*-
+
+ 2001/06/20: Thomas Bretz
+ 
+   * macros/merpp.C:
+     - fixed type in comment
+     
+   * manalysis/MHillas.cc:
+     - fixed 'FIXME' comment
+   
+   * mbase/MWriteFile.[h,cc]:
+     - added
+  
+   * mbase/MWriteRootFile.[h,cc]:
+     - added
+   
+   * mbase/BaseLinkDef.h:
+     - Added MWriteFile
+     - Added MWriteRootFile
+   
+   * mbase/MEvtLoop.cc:
+     - fixed the counting in the eventloop
+     
+   * mbase/MWriteAsciiFile.[h,cc]:
+     - changed class that it is based on MWriteFile now
+   
+   * mbase/Makefile:
+     - added MWriteFile
+     - added MWriteRootFile
+   
+   * mhist/MFillHFadc.[h,cc]:
+     - added set for HasChanged (new PostProcess)
+   
+   * mhist/MFillHHillas.cc:
+     - added set for HasChanged (new PostProcess)
+   
+   * mhist/MFillHStarMap.cc:
+     - added set for HasChanged (new PostProcess)
+
+   * mhist/MHHillas.cc:
+     - Set kCanDelete to make sure, that the histograms are deleted
+       together with the canvas
+     
+   * mraw/MRawFileWrite.[h,cc]:
+     - changed the handling of opening, closing and checking file
+
+
 
  2001/06/13: Thomas Bretz
@@ -39,5 +85,4 @@
    * mraw/MRawEvtData.cc:
      - Set kCanDelete in Draw function
-   
 
 
Index: /trunk/MagicSoft/Mars/macros/merpp.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/merpp.C	(revision 851)
+++ /trunk/MagicSoft/Mars/macros/merpp.C	(revision 852)
@@ -30,5 +30,5 @@
     //
     // REMARK: Don't change the order of the two instantiations.
-    //         I don't have an idea why, but here it crashes to
+    //         I don't have an idea why, but here it crashes the
     //         Interpreter.
     //         (Using root 2.25/03, with Cint 5.14.50 on OSF1)
Index: /trunk/MagicSoft/Mars/manalysis/MHillas.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 852)
@@ -58,5 +58,5 @@
 
     Reset();
-    // FIXME: Initialization of values missing
+    // FIXME: (intelligent) initialization of values missing
 }
 
Index: /trunk/MagicSoft/Mars/manalysis/MHillasCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MHillasCalc.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/manalysis/MHillasCalc.cc	(revision 852)
@@ -60,5 +60,5 @@
 // (Hillas) container or create one.
 //
-Bool_t MHillasCalc::PreProcess( MParList *pList )
+Bool_t MHillasCalc::PreProcess(MParList *pList)
 {
     fCerPhotEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
Index: /trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 851)
+++ /trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 852)
@@ -29,5 +29,7 @@
 
 #pragma link C++ class MReadTree;
+#pragma link C++ class MWriteFile;
 #pragma link C++ class MWriteAsciiFile;
+#pragma link C++ class MWriteRootFile;
 
 #pragma link C++ class MArray;
Index: /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 852)
@@ -160,7 +160,9 @@
     //
     if (maxcnt<0)
-        while (fTaskList->Process() && ++dummy);
+        // process first and increment if sucessfull
+        while (fTaskList->Process()) dummy++;
     else
-        while (fTaskList->Process() && dummy--);
+        // check for number and break if unsuccessfull
+        while (dummy-- && fTaskList->Process());
 
     //
Index: /trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 852)
@@ -102,37 +102,37 @@
 Bool_t MParList::AddToList(MParContainer *obj, MParContainer *where)
 {
+    //
+    //  check if the object (you want to add) exists
+    //
+
+    if (!obj) return kTRUE;
+
+    *fLog << "Adding " << obj->GetName() << " to " << GetName() << "... " << flush;
   //
-  //  check if the object (you want to add) exists
-  //
-
-  if (!obj) return kTRUE;
-
-  *fLog << "Adding " << obj->GetName() << " to " << GetName() << "... " << flush;
-  //
-  //  check if it is in the list yet
-  //
-  if (fContainer.FindObject(obj))
-  {
-      *fLog << dbginf << "Container already added" << endl;
-      return kTRUE;
-  }
-
-  //
-  //  check if you want to add the new parameter container somewhere 
+    //  check if it is in the list yet
+    //
+    if (fContainer.FindObject(obj))
+    {
+        *fLog << dbginf << "Container already added" << endl;
+        return kTRUE;
+    }
+
+    //
+    //  check if you want to add the new parameter container somewhere
   //  special (in that case you specify "where") 
-  //  
-  if (where)
-  {
-      if (!fContainer.FindObject(where))
-      {
-          *fLog << dbginf << "Cannot find parameter container after which the new one should be added!" << endl;
-          return kFALSE;
-      }
-  }
-
-  fContainer.Add(obj);
-  *fLog << "Done." << endl;
-
-  return kTRUE;
+    //
+    if (where)
+    {
+        if (!fContainer.FindObject(where))
+        {
+            *fLog << dbginf << "Cannot find parameter container after which the new one should be added!" << endl;
+            return kFALSE;
+        }
+    }
+
+    fContainer.Add(obj);
+    *fLog << "Done." << endl;
+
+    return kTRUE;
 }
 
Index: /trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc	(revision 852)
@@ -64,4 +64,6 @@
     fNameFile      = filename;
     fNameContainer = contname;
+
+    fOut = new ofstream(fNameFile);
 }
 
@@ -80,4 +82,6 @@
     fNameFile      = filename;
     fNameContainer = cont->GetName();
+
+    fOut = new ofstream(fNameFile);
 }
 
@@ -89,89 +93,44 @@
 MWriteAsciiFile::~MWriteAsciiFile()
 {
-    if (fOut)
-        delete fOut;
+    delete fOut;
 }
 
 // --------------------------------------------------------------------------
 //
-// Tries to open the given output file. And tries to get a pointer to the
-// instance of the container which should be written.
-// If the container has already the HasChanged flag it is immediatly written
-// to the output file.
+// Check if our container is ready for writing. If so write it.
 //
-Bool_t MWriteAsciiFile::PreProcess (MParList *pList)
+void MWriteAsciiFile::CheckAndWrite() const
+{
+    if (fContainer->HasChanged())
+        fContainer->AsciiWrite(*fOut);
+}
+
+// --------------------------------------------------------------------------
+//
+// Return open state of the file
+//
+Bool_t MWriteAsciiFile::IsFileOpen() const
+{
+    return (bool)(*fOut);
+}
+
+// --------------------------------------------------------------------------
+//
+// If the container is yet unknown and the name of it is known only, try
+// to get the container from the parameter list.
+//
+Bool_t MWriteAsciiFile::GetContainer(MParList *pList)
 {
     //
     // Try to find the container which should be stored.
     //
-    if (!fContainer)
-    {
-        fContainer = (MParContainer*)pList->FindObject(fNameContainer);
-        if (!fContainer)
-        {
-            *fLog << dbginf << "Cannot find parameter container '" << fContainer << "'." << endl;
-            return kFALSE;
-        }
-    }
+    if (fContainer)
+        return kTRUE;
 
-    //
-    // Try to open the output file
-    //
-    fOut = new ofstream(fNameFile);
+    fContainer = (MParContainer*)pList->FindObject(fNameContainer);
+    if (fContainer)
+        return kTRUE;
 
-    if (!(*fOut))
-    {
-        *fLog << dbginf << "Cannot open Ascii file '" << fNameFile << "' for writing." << endl;
-        return kFALSE;
-    }
-
-    *fLog << "Ascii file '" << fNameFile << "' opened for writing." << endl;
-
-    //
-    // write the container if it is already in changed state
-    //
-    if (fContainer->HasChanged())
-        fContainer->AsciiWrite(*fOut);
-
-    return kTRUE;
+    *fLog << dbginf << "Cannot find parameter container '" << fContainer << "'." << endl;
+    return kFALSE;
 }
-
-// --------------------------------------------------------------------------
-//
-// Checks if the HasChanged flag of the output container is set. If it is set
-// the container is instructed to write itself to the ascii file.
-// (By calling its memberfunction AsciiWrite. You find the Prototype in
-// MParContainer)
-//
-Bool_t MWriteAsciiFile::Process()
-{
-    if (fContainer->HasChanged())
-        fContainer->AsciiWrite(*fOut);
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// If the output container has the HasChanged flag set, it is written to the
-// output file (eg. this could be some calculated result)
-// If the output file object exists, delete it. (The file is closed
-// automatically in the corresponding destructor)
-//
-Bool_t MWriteAsciiFile::PostProcess()
-{
-    //
-    // check if the container changed state is set
-    //
-    if (fContainer->HasChanged())
-        fContainer->AsciiWrite(*fOut);
-
-    //
-    // delete (close) file
-    //
-    delete fOut;
-    fOut = NULL;
-
-    return kTRUE;
-}
-
Index: /trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h	(revision 851)
+++ /trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h	(revision 852)
@@ -2,9 +2,9 @@
 #define MWRITEASCIIFILE_H
 
-#ifndef MTASK_H
-#include "MTask.h"
+#ifndef MWRITEFILE_H
+#include "MWriteFile.h"
 #endif
 
-class MWriteAsciiFile : public MTask
+class MWriteAsciiFile : public MWriteFile //MTask
 {
 private:
@@ -16,4 +16,10 @@
     MParContainer *fContainer;
 
+    virtual void   CheckAndWrite() const;
+    virtual Bool_t IsFileOpen() const;
+    virtual Bool_t GetContainer(MParList *pList);
+    virtual const char *GetFileName() const { return fNameFile; }
+
+
 public:
     MWriteAsciiFile(const char *filename, const char *contname,
@@ -23,8 +29,4 @@
     ~MWriteAsciiFile();
 
-    Bool_t PreProcess(MParList *pList);
-    Bool_t Process();
-    Bool_t PostProcess();
-
     ClassDef(MWriteAsciiFile, 0)	// Class to write one container to an ascii file
 };
Index: /trunk/MagicSoft/Mars/mbase/MWriteFile.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MWriteFile.cc	(revision 852)
+++ /trunk/MagicSoft/Mars/mbase/MWriteFile.cc	(revision 852)
@@ -0,0 +1,110 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  06/2001 (tbretz@uni-sw.gwdg.de)
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MWriteFile                                                              //
+//                                                                         //
+// This is a base class for writing tasks. If you want to implement        //
+// writing out parameter containers in a new file format, this is a good   //
+// starting point.                                                         //
+// The class defines a generalized interface between writing out data in   //
+// an eventloop and your file format.                                      //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MWriteFile.h"
+
+#include <fstream.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+ClassImp(MWriteFile)
+
+// --------------------------------------------------------------------------
+//
+// Tries to open the given output file.
+// The derived class should retrieve needed containers from the parameter
+// list.
+// instance of the container which should be written.
+// If the container has already the HasChanged flag it is immediatly written
+// to the output file.
+//
+Bool_t MWriteFile::PreProcess(MParList *pList)
+{
+    //
+    // test whether file is now open or not
+    //
+    if (!IsFileOpen())
+    {
+        *fLog << dbginf << "Cannot open file '" << GetFileName() << "'" << endl;
+        return kFALSE;
+    }
+
+    *fLog << "File '" << GetFileName() << "' open for writing." << endl;
+
+    //
+    // Get the containers (pointers) from the parameter list you want to write
+    //
+    if (!GetContainer(pList))
+        return kFALSE;
+
+    //
+    // write the container if it is already in changed state
+    //
+    CheckAndWrite();
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Checks if the HasChanged flag of the output container is set. If it is set
+// the container should be written to the output.
+//
+Bool_t MWriteFile::Process()
+{
+    CheckAndWrite();
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Checks if the HasChanged flag of the output container is set. If it is set
+// the container should be written to the output.
+//
+Bool_t MWriteFile::PostProcess()
+{
+    //
+    // check if the container changed state is set
+    //
+    CheckAndWrite();
+
+    return kTRUE;
+}
+
Index: /trunk/MagicSoft/Mars/mbase/MWriteFile.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MWriteFile.h	(revision 852)
+++ /trunk/MagicSoft/Mars/mbase/MWriteFile.h	(revision 852)
@@ -0,0 +1,27 @@
+#ifndef MWRITEFILE_H
+#define MWRITEFILE_H
+
+#ifndef MTASK_H
+#include "MTask.h"
+#endif
+
+class TFile;
+
+class MWriteFile : public MTask
+{
+private:
+    virtual Bool_t IsFileOpen() const = 0;
+    virtual void CheckAndWrite() const = 0;
+    virtual Bool_t GetContainer(MParList *pList) = 0;
+    virtual const char *GetFileName() const = 0;
+
+public:
+
+    virtual Bool_t PreProcess(MParList *pList);
+    virtual Bool_t Process();
+    virtual Bool_t PostProcess();
+
+    ClassDef(MWriteFile, 0)	// Class to write one container to an ascii file
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mbase/MWriteRootFile.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MWriteRootFile.cc	(revision 852)
+++ /trunk/MagicSoft/Mars/mbase/MWriteRootFile.cc	(revision 852)
@@ -0,0 +1,376 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  06/2001 (tbretz@uni-sw.gwdg.de)
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MWriteRootFile                                                          //
+//                                                                         //
+// This is a writer to store several containers to a root file.            //
+// The containers are added with AddContainer.                             //
+// To understand how it works, see base class MWriteFile                   //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MWriteRootFile.h"
+
+#include <TFile.h>
+#include <TTree.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+ClassImp(MWriteRootFile)
+
+// --------------------------------------------------------------------------
+//
+// Specify the name of the root file. You can also give an option ("UPDATE"
+// and "RECREATE" would make sense only) as well as the file title and
+// compression factor. To a more detaild description of the options see
+// TFile.
+//
+MWriteRootFile::MWriteRootFile(const char *fname,
+                               const Option_t *opt,
+                               const char *ftitle,
+                               const Int_t comp,
+                               const char *name,
+                               const char *title)
+{
+    *fName  = name  ? name  : "MWriteRootFile";
+    *fTitle = title ? title : "Task which writes a root-output file";
+
+    //
+    // Set the Arrays the owner of its entries. This means, that the
+    // destructor of the arrays will delete all its entries.
+    //
+    fBranches.SetOwner();
+    fTrees.SetOwner();
+
+    //
+    // Open the rootfile
+    //
+    fOut = new TFile(fname, opt, ftitle, comp);
+}
+
+// --------------------------------------------------------------------------
+//
+// Prints some statistics about the file to the screen. And closes the file
+// properly.
+//
+MWriteRootFile::~MWriteRootFile()
+{
+    //
+    // Print some statistics to the looging out.
+    //
+    Print();
+
+    //
+    // If the file is still open (no error) write the keys. This is necessary
+    // for appearance of the all trees and branches.
+    //
+    if (IsFileOpen())
+        fOut->Write();
+
+    //
+    // Delete the file. This'll also close the file (if open)
+    //
+    delete fOut; 
+}
+
+// --------------------------------------------------------------------------
+//
+// Prints all trees with the actually number of written entries to log-out.
+//
+void MWriteRootFile::Print(Option_t *)
+{
+    *fLog << "File: " << GetFileName() << endl;
+    *fLog << "--------------------------------------------------" << endl;
+
+    MRootFileTree *entry;
+
+    //
+    // Loop over all tree entries
+    //
+    TObjArrayIter Next(&fTrees);
+    while ((entry=(MRootFileTree*)Next()))
+    {
+        //
+        // Print out the name and the number of actually written entries.
+        //
+        *fLog << entry->GetTree()->GetName() << ": \t";
+        *fLog << entry->GetNumEntries() << " entries." << endl;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Add a new Container to list of containers which should be written to the
+// file. Give the name of the container which will identify the container
+// in the parameterlist. tname is the name of the tree to which the
+// container should be written (Remark: one tree can hold more than one
+// container). The default is the same name as the container name.
+// You can slso specify a title for the tree. This is only
+// used the first time this tree in 'mentioned'. As default the title
+// is the name of the tree.
+//
+void MWriteRootFile::AddContainer(const char *cname, const char *tname, const char *ttitle)
+{
+    //
+    // create a new entry in the list of branches to write and
+    // add the entry to the list.
+    //
+    MRootFileBranch *entry = new MRootFileBranch(cname, tname, ttitle);
+    fBranches.AddLast(entry);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add a new Container to list of containers which should be written to the
+// file. Give the pointer to the container. tname is the name of the tree to
+// which the container should be written (Remark: one tree can hold more than
+// one container). The default is the same name as the container name.
+// You can slso specify a title for the tree. This is only
+// used the first time this tree in 'mentioned'. As default the title
+// is the name of the tree.
+//
+void MWriteRootFile::AddContainer(MParContainer *cont, const char *tname,
+                                  const char *ttitle)
+{
+    //
+    // create a new entry in the list of branches to write and
+    // add the entry to the list.
+    //
+    MRootFileBranch *entry = new MRootFileBranch(cont, tname, ttitle);
+    fBranches.AddLast(entry);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add a new Container to list of containers which should be written to the
+// file. Give the pointer to the container. tname is the name of the tree to
+// which the container should be written (Remark: one tree can hold more than
+// one container). The default is the same name as the container name.
+// You can slso specify a title for the tree. This is only
+// used the first time this tree in 'mentioned'. As default the title
+// is the name of the tree.
+//
+Bool_t MWriteRootFile::GetContainer(MParList *pList)
+{
+    MRootFileBranch *entry;
+
+    //
+    //
+    // loop over all branches which are 'marked' as branches to get written.
+    TObjArrayIter Next(&fBranches);
+    while ((entry=(MRootFileBranch*)Next()))
+    {
+        //
+        // Get the pointer to the container. If the pointer is NULL it seems,
+        // that the user identified the container by name.
+        //
+        MParContainer *cont = entry->GetContainer();
+        if (!cont)
+        {
+            //
+            // Get the name and try to find a container with this name
+            // in the parameter list.
+            //
+            const char *cname = entry->GetContName();
+            cont = (MParContainer*)pList->FindObject(cname);
+            if (!cont)
+            {
+                //
+                // No corresponding container is found
+                //
+                *fLog << dbginf << "Cannot find parameter container '" << cname << "'." << endl;
+                return kFALSE;
+            }
+            //
+            // The container is found. Put the pointer into the entry.
+            //
+            entry->SetContainer(cont);
+        }
+
+        //
+        // Get container name, tree name and tree title of this entry.
+        //
+        const char *cname  = cont->GetName();
+        const char *tname  = entry->GetTreeName();
+        const char *ttitle = entry->GetTreeTitle();
+
+        //
+        // if the tree name is NULL this idetifies it to use the default:
+        // the container name.
+        //
+        if (!tname)
+            tname = cname;
+
+        //
+        // Check if the tree is already existing (part of the file)
+        //
+        TTree *tree = (TTree*)fOut->Get(tname);
+        if (!tree)
+        {
+            //
+            // if the tree doesn't exist create a new tree. Use the tree
+            // name as title if title is NULL
+            //
+            tree = new TTree(tname, ttitle ? ttitle : tname);
+
+            //
+            // Create a new entry in the list of trees, which are stored to
+            // the file. Add it to the list.
+            //
+            MRootFileTree *entry = new MRootFileTree(tree);
+            fTrees.AddLast(entry);
+
+            *fLog << "Created Tree " << tname << "." << endl;
+        }
+
+        //
+        // Now we have a valid tree. Search the list of trees for this tree
+        // (either it is already there, or we created and add it previously)
+        // Add a pointer to the entry in the tree list to this branch-entry
+        //
+        MRootFileTree *loop;
+        TObjArrayIter NextTree(&fTrees);
+        while ((loop=(MRootFileTree*)NextTree()))
+        {
+            if (loop->GetTree() == tree)
+                entry->SetTree(loop);
+        }
+
+        //
+        // Try to get the branch from the file. 
+        // If the branch already exists the user specified one branch twice.
+        //
+        TBranch *branch = tree->GetBranch(cname);
+        if (branch)
+        {
+            *fLog << dbginf << "Branch '" << cname << "' is already existing." << endl;
+            return kFALSE;
+        }
+
+        //
+        // Create a new branch in the actual tree. The branch has the name
+        // container name. The type of the container is given by the
+        // ClassName entry in the container. The Address is the address of a
+        // pointer to the container (gotten from the branch entry). As
+        // Basket size we specify a (more or less) common default value.
+        // The containers should be written in Splitlevel=1
+        //
+        branch = tree->Branch(cname, cont->ClassName(), entry->GetAddress(), 32000, 1);
+
+        *fLog << "Created Branch " << cname << " of " << cont->ClassName() << "." << endl;
+
+        //
+        // If the branch couldn't be created we have a problem.
+        //
+        if (!branch)
+        {
+            *fLog << dbginf << "Unable to create branch '" << cname << "'." << endl;
+            return kFALSE;
+        }
+    }
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Checks all given containers (branch entries) for the write flag.
+// If the write flag is set the corresponding Tree is marked to get filled.
+// All Trees which are marked to be filled are filled with the corresponding
+// branches.
+// Be carefull: If only one container (corresponding to a branch) of a tree
+// has the write flag, all containers in this tree are filled!
+//
+void MWriteRootFile::CheckAndWrite() const
+{
+    TObject *obj;
+
+    //
+    // Loop over all branch entries
+    //
+    TObjArrayIter NextBranch(&fBranches);
+    while ((obj=NextBranch()))
+    {
+        MRootFileBranch *entry = (MRootFileBranch*)obj;
+
+        //
+        // Check for the Write flag
+        //
+        if (!entry->GetContainer()->HasChanged())
+            continue;
+
+        //
+        // If the write flag of the branch entry is set, set the write flag of
+        // the corresponding tree entry.
+        //
+        entry->GetTree()->SetWriteFlag();
+    }
+
+    //
+    // Loop over all tree entries
+    //
+    TObjArrayIter NextTree(&fTrees);
+    while ((obj=NextTree()))
+    {
+        MRootFileTree *entry = (MRootFileTree*)obj;
+
+        //
+        // Check the write flag of the tree
+        //
+        if (!entry->HasWriteFlag())
+            continue;
+
+        //
+        // If the write flag is set, fill the tree (with the corrasponding
+        // branches/containers), delete the write flag and increase the number
+        // of written/filled entries.
+        //
+        entry->GetTree()->Fill();
+        entry->DelWriteFlag();
+        (*entry)++;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// return open state of the root file.
+//
+Bool_t MWriteRootFile::IsFileOpen() const
+{
+    return fOut->IsOpen();
+}
+
+// --------------------------------------------------------------------------
+//
+// return name of the root-file
+//
+const char *MWriteRootFile::GetFileName() const
+{
+    return fOut->GetName();
+}
+
Index: /trunk/MagicSoft/Mars/mbase/MWriteRootFile.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MWriteRootFile.h	(revision 852)
+++ /trunk/MagicSoft/Mars/mbase/MWriteRootFile.h	(revision 852)
@@ -0,0 +1,104 @@
+#ifndef MWRITEROOTFILE_H
+#define MWRITEROOTFILE_H
+
+#ifndef MWriteFile_H
+#include "MWriteFile.h"
+#endif
+#ifndef ROOT_TObjArray
+#include <TObjArray.h>
+#endif
+
+class TFile;
+class TTree;
+class TBranch;
+
+class MRootFileTree : public TObject
+{
+private:
+    TTree         *fTree;
+    Bool_t         fWriteFlag;
+    ULong_t        fNumEntries;
+
+public:
+    MRootFileTree(TTree *tree) : fTree(tree), fWriteFlag(kFALSE), fNumEntries(0) {}
+    TTree *GetTree() const { return fTree; }
+    Bool_t HasWriteFlag() const { return fWriteFlag; }
+    ULong_t GetNumEntries() const { return fNumEntries; }
+    void operator++(int) { fNumEntries++; }
+    void SetWriteFlag() { fWriteFlag = kTRUE; }
+    void DelWriteFlag() { fWriteFlag = kFALSE; }
+};
+
+class MRootFileBranch : public TObject
+{
+private:
+    MRootFileTree *fTree;
+    TBranch       *fBranch;
+    MParContainer *fContainer;
+    TString       *fContName;
+    TString       *fTreeName;
+    TString       *fTreeTitle;
+
+public:
+    MRootFileBranch(const char *cname, const char *tname=NULL, const char *ttitle=NULL)
+        : fTree(NULL), fBranch(NULL), fContainer(NULL)
+    {
+        fContName  = new TString(cname);
+        fTreeName  = tname ? new TString(tname) : NULL;
+        fTreeTitle = ttitle ? new TString(ttitle) : NULL;
+    }
+
+    MRootFileBranch(MParContainer *cont, const char *tname=NULL, const char *ttitle=NULL)
+        : fTree(NULL), fBranch(NULL), fContName(NULL)
+    {
+        fContainer = cont;
+        fTreeName  = tname ? new TString(tname) : NULL;
+        fTreeTitle = ttitle ? new TString(ttitle) : NULL;
+    }
+
+        MRootFileTree *GetTree() const { return fTree; }
+    MParContainer *GetContainer() const { return fContainer; }
+    void *GetAddress() { return &fContainer; }
+    TBranch *GetBranch() const          { return fBranch; }
+    const char *GetContName() const     { return fContName  ? (const char*)(*fContName)  : NULL; }
+    const char *GetTreeName() const     { return fTreeName  ? (const char*)(*fTreeName)  : NULL; }
+    const char *GetTreeTitle() const    { return fTreeTitle ? (const char*)(*fTreeTitle) : NULL; }
+
+    void SetContainer(MParContainer *cont) { fContainer = cont; }
+    void SetTree(MRootFileTree *tree) { fTree = tree; }
+
+};
+
+class MWriteRootFile : public MWriteFile
+{
+private:
+    TFile *fOut;
+
+    TObjArray fBranches;
+    TObjArray fTrees;
+
+    void        CheckAndWrite() const;
+    Bool_t      IsFileOpen() const;
+    Bool_t      GetContainer(MParList *pList);
+    const char *GetFileName() const;
+
+public:
+    MWriteRootFile(const char *fname,
+                   const Option_t *opt="RECREATE",
+                   const char *ftitle="Unnamed",
+                   const Int_t comp=9,
+                   const char *name=NULL,
+                   const char *title=NULL);
+    ~MWriteRootFile();
+
+    void Print(Option_t *t=NULL);
+
+    void AddContainer(const char *cname,
+                      const char *tname=NULL, const char *ttitle=NULL);
+    void AddContainer(MParContainer *cont,
+                      const char *tname=NULL, const char *ttitle=NULL);
+
+    ClassDef(MWriteRootFile, 0)	// Class to write one container to an ascii file
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mbase/Makefile	(revision 851)
+++ /trunk/MagicSoft/Mars/mbase/Makefile	(revision 852)
@@ -38,5 +38,7 @@
            MEvtLoop.cc \
            MReadTree.cc \
+           MWriteFile.cc \
            MWriteAsciiFile.cc \
+           MWriteRootFile.cc \
 	   MArray.cc \
 	   MArrayB.cc \
Index: /trunk/MagicSoft/Mars/mhist/MFillHFadc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillHFadc.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mhist/MFillHFadc.cc	(revision 852)
@@ -108,4 +108,9 @@
 
     return kTRUE;
+}
 
+Bool_t MFillHFadc::PostProcess()
+{
+    fHistos->SetHasChanged();
+    return kTRUE;
 }
Index: /trunk/MagicSoft/Mars/mhist/MFillHFadc.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillHFadc.h	(revision 851)
+++ /trunk/MagicSoft/Mars/mhist/MFillHFadc.h	(revision 852)
@@ -14,17 +14,18 @@
 class MRawEvtData;
 
-class MFillHFadc : public MTask {
- private:
-  MRawEvtData *fRawEvtData; // The raw event data from which the spektrum is created
-  MHFadcCam   *fHistos ;    // The histogram container into which holds the spektrum
+class MFillHFadc : public MTask
+{
+private:
+    MRawEvtData *fRawEvtData; // The raw event data from which the spektrum is created
+    MHFadcCam   *fHistos ;    // The histogram container into which holds the spektrum
 
- public:   
-  MFillHFadc (const char *name=NULL, const char *title=NULL); 
+public:
+    MFillHFadc (const char *name=NULL, const char *title=NULL);
 
-  Bool_t PreProcess(MParList *pList);
-  Bool_t Process() ;
-  
-  ClassDef(MFillHFadc, 0)  // Task to fill the fadc data into histograms
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+    Bool_t PostProcess();
 
+    ClassDef(MFillHFadc, 0)  // Task to fill the fadc data into histograms
 };
     
Index: /trunk/MagicSoft/Mars/mhist/MFillHHillas.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillHHillas.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mhist/MFillHHillas.cc	(revision 852)
@@ -72,2 +72,8 @@
     return kTRUE;
 } 
+
+Bool_t MFillHHillas::PostProcess()
+{
+    fHistos->SetHasChanged();
+    return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/mhist/MFillHHillas.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillHHillas.h	(revision 851)
+++ /trunk/MagicSoft/Mars/mhist/MFillHHillas.h	(revision 852)
@@ -23,5 +23,6 @@
 
   Bool_t PreProcess(MParList *pList);
-  Bool_t Process() ;
+  Bool_t Process();
+  Bool_t PostProcess();
   
   ClassDef(MFillHHillas, 0) // Task to fill the Hillas parameters into histograms
Index: /trunk/MagicSoft/Mars/mhist/MFillHStarMap.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillHStarMap.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mhist/MFillHStarMap.cc	(revision 852)
@@ -73,2 +73,9 @@
     return kTRUE;
 } 
+
+Bool_t MFillHStarMap::PostProcess()
+{
+    fHistos->SetHasChanged();
+
+    return kTRUE;
+} 
Index: /trunk/MagicSoft/Mars/mhist/MFillHStarMap.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillHStarMap.h	(revision 851)
+++ /trunk/MagicSoft/Mars/mhist/MFillHStarMap.h	(revision 852)
@@ -23,5 +23,6 @@
 
   Bool_t PreProcess(MParList *pList);
-  Bool_t Process() ;
+  Bool_t Process();
+  Bool_t PostProcess();
   
   ClassDef(MFillHStarMap, 0) // Task to fill a 2-dim histogram by the Hillas parameters
Index: /trunk/MagicSoft/Mars/mhist/MHHillas.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHillas.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mhist/MHHillas.cc	(revision 852)
@@ -74,10 +74,14 @@
 
     c->cd(1);
+    fAlpha->SetBit(kCanDelete);
     fAlpha->Draw();
     c->cd(2);
+    fLength->SetBit(kCanDelete);
     fLength->Draw();
     c->cd(3);
+    fDist->SetBit(kCanDelete);
     fDist->Draw();
     c->cd(4);
+    fWidth->SetBit(kCanDelete);
     fWidth->Draw();
 
Index: /trunk/MagicSoft/Mars/mmontecarlo/MCollArea.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmontecarlo/MCollArea.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mmontecarlo/MCollArea.cc	(revision 852)
@@ -17,5 +17,5 @@
 !
 !   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
-!   Author(s): Thomas Bretz  12/2000 (tbretz@uni-sw.gwdg.de)
+!              Thomas Bretz  12/2000 (tbretz@uni-sw.gwdg.de)
 !
 !   Copyright: MAGIC Software Development, 2000-2001
@@ -35,67 +35,67 @@
 MCollArea::MCollArea(const char *name, const char *title) 
 { 
-  //
-  //   default constructor
-  //
+    //
+    //   default constructor
+    //
 
-  //   initialize the histogram for the distribution r vs E 
-  // 
-  //   we set the energy range from 1 Gev to 10000 GeV (in log 5 orders
-  //   of magnitude) and for each order we take 10 subdivision --> 50 xbins
-  //
-  //   we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
+    //   initialize the histogram for the distribution r vs E
+    //
+    //   we set the energy range from 1 Gev to 10000 GeV (in log 5 orders
+    //   of magnitude) and for each order we take 10 subdivision --> 50 xbins
+    //
+    //   we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
 
   
-  *fName  = name  ? name  : "MCollArea";
-  *fTitle = title ? title : "Data to Calculate Coll-Area";
-  
-  
-  fHistAll = new TH2D("collAreaAll", "all showers - Radius vs log(E) distribution", 
-		      50, 0., 5., 
-		      50, 0., 500. ) ;
-  
-  fHistSel = new TH2D("collAreaSel", "selected showers - Radius vs log(E) distribution", 
-		      50, 0., 5., 
-		      50, 0., 500. ) ; 
+    *fName  = name  ? name  : "MCollArea";
+    *fTitle = title ? title : "Data to Calculate Coll-Area";
 
-  fHistCol = new TH1D("collArea", "Collection Area",
-                      50, 0., 5.) ;
-  
-} 
+
+    fHistAll = new TH2D("collAreaAll", "all showers - Radius vs log(E) distribution",
+                        50, 0., 5.,
+                        50, 0., 500. ) ;
+
+    fHistSel = new TH2D("collAreaSel", "selected showers - Radius vs log(E) distribution",
+                        50, 0., 5.,
+                        50, 0., 500. ) ;
+
+    fHistCol = new TH1D("collArea", "Collection Area",
+                        50, 0., 5.) ;
+
+}
 
 MCollArea::~MCollArea()
-{ 
-  delete fHistAll ; 
-  delete fHistSel ; 
-  delete fHistCol ;
-} 
+{
+    delete fHistAll ;
+    delete fHistSel ;
+    delete fHistCol ;
+}
 
 void MCollArea::FillAll(Float_t log10E, Float_t radius)
-{ 
-  fHistAll->Fill(log10E, radius ) ; 
-} 
+{
+    fHistAll->Fill(log10E, radius ) ;
+}
 
 void MCollArea::FillSel(Float_t log10E, Float_t radius)
-{ 
-  fHistSel->Fill(log10E, radius ) ; 
-} 
+{
+    fHistSel->Fill(log10E, radius ) ;
+}
 
-void MCollArea::DrawAll() 
-{ 
-  fHistAll->Draw() ; 
-} 
+void MCollArea::DrawAll()
+{
+    fHistAll->Draw() ;
+}
 
-void MCollArea::DrawSel() 
-{ 
-  fHistSel->Draw() ; 
-} 
+void MCollArea::DrawSel()
+{
+    fHistSel->Draw() ;
+}
 
-void MCollArea::Draw(Option_t* option) 
-{ 
-  fHistCol->Draw(option) ;
-} 
+void MCollArea::Draw(Option_t* option)
+{
+    fHistCol->Draw(option) ;
+}
 
 void MCollArea::CalcEfficiency()
-{ 
+{
     // Description!
 
@@ -114,19 +114,10 @@
             const Float_t Nall = fHistAll->GetCellContent(ix, iy);
 
-            if ( Nall <= 0 ) {
-                // cout << ix << " " << iy << endl ;
+            if (Nall <= 0)
                 continue;
-            }
 
             const Double_t eff = N / Nall ;
             const Double_t err = sqrt(Nall + Nall*N - N*N - N) / (Nall*Nall);
-            /*
-             cout << ix << " " << iy
-             << " N " << N
-             << " Nall " << Nall
-             << " effi  " << eff
-             << " error " << err
-             << endl ;
-             */
+
             fHistSel->SetCellContent(ix, iy, eff);
             fHistSel->SetCellError(ix, iy, err);
Index: /trunk/MagicSoft/Mars/mmontecarlo/MCollAreaTrigger.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmontecarlo/MCollAreaTrigger.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mmontecarlo/MCollAreaTrigger.cc	(revision 852)
@@ -17,5 +17,5 @@
 !
 !   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
-!   Author(s): Thomas Bretz  12/2000 (tbretz@uni-sw.gwdg.de)
+!              Thomas Bretz  12/2000 (tbretz@uni-sw.gwdg.de)
 !
 !   Copyright: MAGIC Software Development, 2000-2001
@@ -26,11 +26,13 @@
 #include "MCollAreaTrigger.h"
 
+#include "MParList.h"
+
 #include "MLog.h"
 #include "MLogManip.h"
-#include "MParList.h"
 
-#include "MCollArea.h"
-#include "MMcEvt.hxx" 
+#include "MMcEvt.hxx"
 #include "MMcTrig.hxx" 
+
+#include "MHMcCollectionArea.h"
 
 ClassImp(MCollAreaTrigger)
@@ -38,33 +40,32 @@
 MCollAreaTrigger::MCollAreaTrigger (const char *name, const char *title)
 {
-  *fName  = name  ? name  : "MCollAreaTrigger";
-  *fTitle = title ? title : "Task to calc the collection area ";
+    *fName  = name  ? name  : "MCollAreaTrigger";
+    *fTitle = title ? title : "Task to calc the collection area ";
 } 
-
 
 Bool_t MCollAreaTrigger::PreProcess (MParList *pList)
 {
-  // connect the raw data with this task
-  
-  fMcEvt  = (MMcEvt*)pList->FindObject("MMcEvt") ;
-  if (!fMcEvt) { 
-    *fLog << dbginf << "MMcEvt not found... exit." << endl;
-    return kFALSE;
-  } 
+    // connect the raw data with this task
 
-  fMcTrig = (MMcTrig*)pList->FindObject("MMcTrig") ;
-  if (!fMcTrig) { 
-    *fLog << dbginf << "MMcTrig not found... exit." << endl;
-    return kFALSE;
-  } 
+    fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
+    if (!fMcEvt)
+    {
+        *fLog << dbginf << "MMcEvt not found... exit." << endl;
+        return kFALSE;
+    }
 
-  fCollArea = (MCollArea*)pList->FindCreateObj("MCollArea") ; 
-  if (!fCollArea)
-    return kFALSE;
+    fMcTrig = (MMcTrig*)pList->FindObject("MMcTrig");
+    if (!fMcTrig)
+    {
+        *fLog << dbginf << "MMcTrig not found... exit." << endl;
+        return kFALSE;
+    }
 
-  return kTRUE ; 
+    fCollArea = (MHMcCollectionArea*)pList->FindCreateObj("MHMcCollectionArea");
+    if (!fCollArea)
+        return kFALSE;
 
-} 
-
+    return kTRUE;
+}
 
 Bool_t MCollAreaTrigger::Process () 
@@ -75,5 +76,4 @@
     fCollArea->FillAll(energy, impact);
 
-
     if (fMcTrig->GetFirstLevel() <= 0)
         return kTRUE;
@@ -81,15 +81,14 @@
     fCollArea->FillSel(energy, impact);
 
-    return kTRUE ;
+    return kTRUE;
 }
 
 Bool_t MCollAreaTrigger::PostProcess () 
 { 
-  // 
-  //   do the calculation of the effectiv area
-  //
+    //
+    //   do the calculation of the effectiv area
+    //
+    fCollArea->CalcEfficiency();
 
-  fCollArea->CalcEfficiency() ;
-
-  return kTRUE ; 
+    return kTRUE;
 }
Index: /trunk/MagicSoft/Mars/mmontecarlo/MCollAreaTrigger.h
===================================================================
--- /trunk/MagicSoft/Mars/mmontecarlo/MCollAreaTrigger.h	(revision 851)
+++ /trunk/MagicSoft/Mars/mmontecarlo/MCollAreaTrigger.h	(revision 852)
@@ -1,4 +1,4 @@
-#ifndef MCOLLAREATRIGGER_H
-#define MCOLLAREATRIGGER_H
+#ifndef MMCCOLLECTIONAREACALC_H
+#define MMCCOLLECTIONAREACALC_H
 
 #ifndef MTASK_H
@@ -7,23 +7,24 @@
 
 class MParList;
-class MMcEvt ; 
-class MMcTrig ; 
-class MCollArea;
+class MMcEvt;
+class MMcTrig;
+class MHMcCollectionArea;
 
-class MCollAreaTrigger : public MTask {
- private:
-  MMcEvt          *fMcEvt    ; //!
-  MMcTrig         *fMcTrig   ; //!
-  MCollArea       *fCollArea ; //!
+class MMcCollectionAreaCalc : public MTask
+{
+private:
+    MMcEvt  *fMcEvt;
+    MMcTrig *fMcTrig;
 
- public:   
-  MCollAreaTrigger (const char *name=NULL, const char *title=NULL); 
+    MHMcCollectionArea *fCollArea;
 
-  Bool_t PreProcess(MParList *pList);
-  Bool_t Process() ;
-  Bool_t PostProcess() ;
-  
-  ClassDef(MCollAreaTrigger, 0)	// Task to fill the collection area histograms
+public:
+    MMcCollectionAreaCalc(const char *name=NULL, const char *title=NULL);
 
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process() ;
+    Bool_t PostProcess() ;
+
+    ClassDef(MMcCollectionAreaCalc, 0) // Task to calculate the collection area histogram
 };
 
Index: /trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 851)
+++ /trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 852)
@@ -53,6 +53,8 @@
 // Default constructor. It opens the output file (root-file)
 //
-MRawFileWrite::MRawFileWrite(const char *fname, Option_t *opt,
-                             const char *ftitle, Int_t comp,
+MRawFileWrite::MRawFileWrite(const char *fname,
+                             const Option_t *opt,
+                             const char *ftitle,
+                             const Int_t comp,
                              const char *name, const char *title)
 {
@@ -60,20 +62,18 @@
     *fTitle = title ? title : "Write task to write DAQ root files";
 
-    // FIXME: move file open to preproc!
-
     //
     // Open a rootfile
     //
     fOut = new TFile(fname, opt, ftitle, comp);
-
-    //
-    // test whether file is now open or not
-    //
-    if (!fOut->IsOpen())
-    {
-        *fLog << "MRawFileWrite::MRawFileWrite: ERROR: Cannot open file '";
-        *fLog << fname << "'" << endl;
-    }
-}
+}
+
+MRawFileWrite::~MRawFileWrite()
+{
+    //
+    // delete instance, this laso does a fOut->Close()
+    //
+    delete fOut;
+}
+
 
 // --------------------------------------------------------------------------
@@ -94,4 +94,13 @@
 {
     //
+    // test whether file is now open or not
+    //
+    if (!fOut->IsOpen())
+    {
+        *fLog << dbginf << "Cannot open file '" << fOut->GetName() << "'" << endl;
+        return kFALSE;
+    }
+
+    //
     // remember the pointer to the parameter list fur further usage
     //
@@ -105,5 +114,5 @@
     if (!fRawEvtHeader)
     {
-        *fLog << "MRawFileWrite::PreProcess - ERROR: MRawEvtHeader not found... aborting." << endl;
+        *fLog << dbginf << "MRawEvtHeader not found... aborting." << endl;
         return kFALSE;
     }
@@ -112,5 +121,5 @@
     if (!fRawEvtData)
     {
-        *fLog << "MRawFileWrite::PreProcess - ERROR: MRawEvtData not found... aborting." << endl;
+        *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
         return kFALSE;
     }
@@ -119,5 +128,5 @@
     if (!fRawCrateArray)
     {
-        *fLog << "MRawFileWrite::PreProcess - ERROR: MRawCrateArray not found... aborting." << endl;
+        *fLog << dbginf << "MRawCrateArray not found... aborting." << endl;
         return kFALSE;
     }
@@ -126,5 +135,5 @@
     if (!fRawEvtTime)
     {
-        *fLog << "MRawFileWrite::PreProcess - WARNING: MRawEvtTime not found... aborting." << endl;
+        *fLog << dbginf << "MRawEvtTime not found... aborting." << endl;
         return kFALSE;
     }
@@ -133,5 +142,5 @@
     if (!fRawRunHeader)
     {
-        *fLog << "MRawFileWrite::PreProcess - ERROR: MRawRunHeader not found... aborting." << endl;
+        *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
         return kFALSE;
     }
@@ -222,14 +231,4 @@
     fOut->Write();
 
-    //
-    // close root file
-    //
-    fOut->Close();
-
-    //
-    // delete instance
-    //
-    delete fOut;
-
     return kTRUE;
 }
Index: /trunk/MagicSoft/Mars/mraw/MRawFileWrite.h
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawFileWrite.h	(revision 851)
+++ /trunk/MagicSoft/Mars/mraw/MRawFileWrite.h	(revision 852)
@@ -35,8 +35,9 @@
 public:
     MRawFileWrite(const char *fname,
-                  Option_t *opt="UPDATE",
+                  const Option_t *opt="UPDATE",
                   const char *ftitle="Unnamed",
-                  Int_t comp=9,
+                  const Int_t comp=9,
                   const char *name=NULL, const char *title=NULL);
+    ~MRawFileWrite();
 
     Bool_t PreProcess(MParList *pList);
