Index: trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1346)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1348)
@@ -64,5 +64,5 @@
     virtual void   SetLogStream(MLog *lg) { fLog = lg; }
     virtual void   Reset() { }
-    virtual Bool_t IsReadyToSave()                   { return fReadyToSave; }
+    virtual Bool_t IsReadyToSave() const             { return fReadyToSave; }
     virtual void   SetReadyToSave(Bool_t flag=kTRUE) { fReadyToSave=flag; }
 
Index: trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc	(revision 1346)
+++ trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc	(revision 1348)
@@ -52,5 +52,9 @@
 #include <TClass.h>      // IsA
 #include <TMethodCall.h> // TMethodCall, AsciiWrite
-#include <TDataMember.h> // TDataMember, AsciiWrite
+
+#include "MDataList.h"   // MDataList
+#include "MDataChain.h"  // MDataChain
+#include "MDataValue.h"  // MDataValue
+#include "MDataMember.h" // MDataMember
 
 #include "MLog.h"
@@ -92,5 +96,5 @@
 
     if (contname)
-        AddContainer(contname);
+       AddContainer(contname);
 }
 
@@ -122,7 +126,5 @@
 MWriteAsciiFile::~MWriteAsciiFile()
 {
-    fContNames.SetOwner();
-    fMembers.SetOwner();
-
+    fAutoDel.SetOwner();
     delete fOut;
 }
@@ -130,88 +132,60 @@
 // --------------------------------------------------------------------------
 //
-// Check if the containers are ready for writing. If so write them.
-// The containers are written in one line, one after each other.
-// If not all containers are written (because of the IsReadyToSave-flag)
-// a warning message is print.
-//
-void MWriteAsciiFile::CheckAndWrite() const
-{
-    Bool_t written = kFALSE;
-
-    MParContainer *cont = NULL;
-
-    Int_t num = fContainer.GetEntries();
-
-    TIter NextCont(&fContainer);
-    TIter NextMemb(&fMembers);
-
-    while ((cont=(MParContainer*)NextCont()))
-    {
-        const MScale *memb = (MScale*)NextMemb();
-
-        if (!cont->IsReadyToSave())
-            continue;
-
-        if (memb->GetTitle()[0]=='\0')
-        {
-            if (!cont->AsciiWrite(*fOut))
-                continue;
-        }
-        else
-        {
-            if (!cont->WriteDataMember(*fOut, memb->GetTitle(), memb->GetScale()))
-                continue;
-        }
-
-        written = kTRUE;
-
-        num--;
-    }
-
-    if (!written)
+// Return open state of the file
+//
+Bool_t MWriteAsciiFile::IsFileOpen() const
+{
+    return (bool)(*fOut);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add a rule to be written as a column to the ascii file.
+// For more information about rules see MDataChain.
+//
+void MWriteAsciiFile::AddRule(const char *rule)
+{
+    MDataChain *chain = new MDataChain(rule);
+    fList.Add(chain);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add another container (by pointer) to be written to the ascii file.
+// The container will be output one after each other in one line.
+// If you want to write only one data member of the container
+// specify the name of the data member (eg. fAlpha) Make sure,
+// that a "GetteMethod" for this data type exists (strip the f and
+// replace it by Get)
+// If you specify a single data member you can add a scale-factor which
+// is (in case of the data member being a floating point value) multiplied
+// with the data member value. This is usefull if you are want to
+// change the scale (unit) of a data member for writing (eg.
+// writing degrees for the hillas parameters instead of the internally
+// used millimeters)
+//
+void MWriteAsciiFile::AddContainer(MParContainer *cont, const TString member, Double_t scale)
+{
+    if (member.IsNull())
+    {
+        fList.Add(cont);
         return;
-
-    *fOut << endl;
-
-    if (num!=0)
-        *fLog << warn << "Warning - given number of containers doesn't fit number of written containers." << endl;
-}
-
-// --------------------------------------------------------------------------
-//
-// Return open state of the file
-//
-Bool_t MWriteAsciiFile::IsFileOpen() const
-{
-    return (bool)(*fOut);
-}
-
-// --------------------------------------------------------------------------
-//
-// Tries to get all containers from the ParList which were given by name
-// adds them to the list of pointers to the container which should be
-// written to the ascii file.
-//
-Bool_t MWriteAsciiFile::GetContainer(MParList *pList)
-{
-    MScale *obj = NULL;
-
-    TIter Next(&fContNames);
-
-    while ((obj=(MScale*)Next()))
-    {
-        const char *name = obj->GetName();
-
-        MParContainer *cont = (MParContainer*)pList->FindObject(name, "MParContainer");
-        if (!cont)
-        {
-            *fLog << err << dbginf << "Cannot find parameter container '" << name << "'." << endl;
-            return kFALSE;
-        }
-
-        AddContainer(cont, obj->GetTitle(), obj->GetScale());
-    }
-
-    return kTRUE;
+    }
+
+    MData *data = new MDataMember(cont, member);
+
+    if (scale!=1)
+    {
+        MDataList  *list = new MDataList('*');
+        MDataValue *val  = new MDataValue(scale);
+
+        list->SetOwner();
+        list->AddToList(data);
+        list->AddToList(val);
+
+        data = list;
+    }
+    fList.Add(data);
+    fAutoDel.Add(data);
 }
 
@@ -231,53 +205,115 @@
 // used millimeters)
 //
-void MWriteAsciiFile::AddContainer(const char *cname, const char *member, Double_t scale)
-{
-    MScale *name = new MScale(cname, member, scale);
-    fContNames.AddLast(name);
-
-    if (member && member[0])
-        AddToBranchList(Form("%s.%s", cname, member));
-}
-
-// --------------------------------------------------------------------------
-//
-// Add another container (by pointer) to be written to the ascii file.
-// The container will be output one after each other in one line.
-// If you want to write only one data member of the container
-// specify the name of the data member (eg. fAlpha) Make sure,
-// that a "GetteMethod" for this data type exists (strip the f and
-// replace it by Get)
-// If you specify a single data member you can add a scale-factor which
-// is (in case of the data member being a floating point value) multiplied
-// with the data member value. This is usefull if you are want to
-// change the scale (unit) of a data member for writing (eg.
-// writing degrees for the hillas parameters instead of the internally
-// used millimeters)
-//
-void MWriteAsciiFile::AddContainer(MParContainer *cont, const char *member, Double_t scale)
-{
-    fContainer.AddLast(cont);
-
-    MScale *name = new MScale("", member, scale);
-    fMembers.AddLast(name);
-}
-
-/*
-Bool_t MWriteAsciiFile::PreProcess(MParList *plist)
-{
-    MDataChain *chain=NULL;
+void MWriteAsciiFile::AddContainer(const TString cont, const TString member, Double_t scale)
+{
+    if (member.IsNull())
+    {
+        TNamed *name = new TNamed(cont, cont);
+        fList.Add(name);
+        fAutoDel.Add(name);
+        return;
+    }
+
+    MData *data = new MDataMember(Form("%s.%s", (const char*)cont, (const char*)member));
+    if (scale!=1)
+    {
+        MDataList  *list = new MDataList('*');
+        MDataValue *val  = new MDataValue(scale);
+
+        list->SetOwner();
+        list->AddToList(data);
+        list->AddToList(val);
+
+        data = list;
+    }
+    fList.Add(data);
+    fAutoDel.Add(data);
+}
+
+// --------------------------------------------------------------------------
+//
+// Tries to get all containers from the ParList which were given by name
+// adds them to the list of pointers to the container which should be
+// written to the ascii file.
+//
+Bool_t MWriteAsciiFile::GetContainer(MParList *plist)
+{
+    TObject *obj=NULL;
 
     TIter Next(&fList);
-    while (((MDataChain*)chain=Next()))
-        if (!chain->PreProcess(plist))
+    while ((obj=Next()))
+    {
+        //
+        // MData is the highest class in the inheritance tree
+        //
+        if (obj->IsA()->InheritsFrom(MData::Class()))
+        {
+            if (!((MData*)obj)->PreProcess(plist))
+                return kFALSE;
+            continue;
+        }
+
+        //
+        // MParContainer is the next class in the inheritance tree
+        //
+        if (obj->IsA()->InheritsFrom(MParContainer::Class()))
+            continue;
+
+        //
+        // It is neither a MData nor a MParContainer, it must be a TNamed
+        //
+        TObject *o = plist->FindObject(obj->GetName());
+        if (!o)
             return kFALSE;
 
-    return MWriteFile::PreProcess(plist);
-}
-
-void MWriteAsciiFile::Add(const char *rule)
-{
-    MDataChain *chain = new MDataChain(rule);
-    fList.Add(chain);
-}
-*/
+        fList[fList.IndexOf(obj)] = o;
+    }
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Check if the containers are ready for writing. If so write them.
+// The containers are written in one line, one after each other.
+// If not all containers are written (because of the IsReadyToSave-flag)
+// a warning message is print.
+//
+void MWriteAsciiFile::CheckAndWrite() const
+{
+    Bool_t written = kFALSE;
+
+    MParContainer *obj = NULL;
+
+    Int_t num = fList.GetEntries();
+
+    *fLog << all << "CHECK&WRITE " << num << endl;
+
+    TIter Next(&fList);
+    while ((obj=(MParContainer*)Next()))
+    {
+        *fLog << all << endl << obj->IsA()->GetName() << ": 0..." << flush;
+
+        if (!obj->IsReadyToSave())
+            continue;
+
+        *fLog << all << "1..." << flush;
+
+        if (!obj->AsciiWrite(*fOut))
+            continue;
+
+        *fLog << all << "2..." << flush;
+
+        written = kTRUE;
+
+        num--;
+    }
+
+    if (!written)
+        return;
+
+    *fOut << endl;
+
+    if (num!=0)
+        *fLog << warn << "Warning - given number of objects doesn't fit number of written objects." << endl;
+}
+
Index: trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h	(revision 1346)
+++ trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h	(revision 1348)
@@ -9,27 +9,16 @@
 #endif
 
+class MData;
+
 class MWriteAsciiFile : public MWriteFile
 {
 private:
-    class MScale : public TNamed
-    {
-    private:
-        Double_t fScale;
-    public:
-        MScale(const char *name, const char *title, Double_t scale)
-            : TNamed(name, title), fScale(scale) {}
-        Double_t GetScale() const { return fScale; }
-    };
+    ofstream *fOut;     //! ascii file
 
-    ofstream *fOut;
+    TString fNameFile;  // name of the ascii file
 
-    TObjArray fContNames;
-    TObjArray fContainer;
-    TObjArray fMembers;
+    TObjArray fList;    // list of rules and containers to be written
+    TObjArray fAutoDel; //! List of object to be deleted in the destructor
 
-    TString fNameFile;
-/*
-    TList fList;
-*/
     virtual void   CheckAndWrite() const;
     virtual Bool_t IsFileOpen() const;
@@ -46,11 +35,8 @@
     ~MWriteAsciiFile();
 
-    void AddContainer(const char *cname, const char *member="", Double_t scale=1);
-    void AddContainer(MParContainer *cont, const char *member="", Double_t scale=1);
+    void AddContainer(const TString cname, const TString member="", Double_t scale=1);
+    void AddContainer(MParContainer *cont, const TString member="", Double_t scale=1);
 
-    /*
-     Bool_t PreProcess(MParList *plist);
-     void Add(const char *rule);
-     */
+    void AddRule(const char *rule);
 
     ClassDef(MWriteAsciiFile, 0) // Class to write one container to an ascii file
Index: trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbase/Makefile	(revision 1346)
+++ trunk/MagicSoft/Mars/mbase/Makefile	(revision 1348)
@@ -20,5 +20,5 @@
 # @endcode 
 
-INCLUDES = -I. -I../mraw -I../MRawFormat -I../mmc
+INCLUDES = -I. -I../mraw -I../MRawFormat -I../mmc -I../mdata
 
 # @code 
