Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 859)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 860)
@@ -1,3 +1,26 @@
                                                                   -*-*- END -*-*-
+
+ 2001/07/09: Thomas Bretz
+ 
+   * mbase/MParList.cc:
+     - made handling of already existing containers in AddToList a bit 
+       more convinient
+     
+   * mbase/MTaskList.[h,cc]:
+     - added come comments
+     - made handling of already existing tasks in AddToList a bit 
+       more convinient
+     - Added name-argument to constructor
+     
+   * mraw/MRawFileRead.[cc, h]:
+     - move file-open check from constructor to PreProcess
+     - added variable for filename
+     
+   * mraw/MRawFileWrite.[cc,h]:
+     - moved fOut->Write from PostProcess to destructor
+     - removed PostProcess
+
+
+
  2001/07/06: Thomas Bretz
  
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 859)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 860)
@@ -4,10 +4,15 @@
  
     - Added a task to write a container to an Ascii file (MWriteAsciiFile)
+
+    - Added a task to write several container to a root file (MWriteRootFile)
     
-    - Added calculation of the Enegry Threshold
+    - Added calculation of the Enegry Threshold (MMcThresholdCalc)
     
-    - Added calculation of the collection area
+    - Added calculation of the collection area (MMcCollectionAreaCalc)
     
     - removed some bugs in the Hillas calculation
+    
+    - added filters to be able to control the task execution dependent on
+      a parameter (for example: the number of level 1 triggers in a MC-file)
     
  
Index: /trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 859)
+++ /trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 860)
@@ -57,5 +57,5 @@
 {
     *fName  = name  ? name  : "MParList";
-    *fTitle = title ? title : "List of Parameter Containers";
+    *fTitle = title ? title : "A list of Parameter Containers";
 
     //
@@ -100,5 +100,5 @@
 //  If 'where' is given, the object will be added after this.
 //
-Bool_t MParList::AddToList(MParContainer *obj, MParContainer *where)
+Bool_t MParList::AddToList(MParContainer *cont, MParContainer *where)
 {
     //
@@ -106,19 +106,41 @@
     //
 
-    if (!obj) return kTRUE;
-
-    *fLog << "Adding " << obj->GetName() << " to " << GetName() << "... " << flush;
-  //
-    //  check if it is in the list yet
-    //
-    if (fContainer.FindObject(obj))
+    if (!cont)
+        return kFALSE;
+
+    //
+    // Get Name of new container
+    //
+    const char *name = cont->GetName();
+
+    //
+    // Check if the new container is already existing in the list
+    //
+    const TObject *objn = fContainer.FindObject(name);
+    const TObject *objt = fContainer.FindObject(cont);
+
+    if (objn || objt)
     {
-        *fLog << dbginf << "Container already added" << endl;
-        return kTRUE;
+        //
+        // If the container is already in the list ignore it.
+        //
+        if (objt || objn==cont)
+        {
+            *fLog << dbginf << "Warning: Container '" << cont->GetName() << ", 0x" << (void*)cont;
+            *fLog << "' already existing in '" << GetName() << "'... ignoring." << endl;
+            return kTRUE;
+        }
+
+        //
+        // Otherwise add it to the list, but print a warning message
+        //
+        *fLog << dbginf << "Warning: Container with the same name '" << cont->GetName();
+        *fLog << "' already existing in '" << GetName() << "'." << endl;
+        *fLog << "You may not be able to get a pointer to container task by name." << endl;
     }
 
     //
     //  check if you want to add the new parameter container somewhere
-  //  special (in that case you specify "where") 
+    //  special (in that case you specify "where")
     //
     if (where)
@@ -126,10 +148,12 @@
         if (!fContainer.FindObject(where))
         {
-            *fLog << dbginf << "Cannot find parameter container after which the new one should be added!" << endl;
+            *fLog << dbginf << "Error: Cannot find parameter container after which the new one should be added!" << endl;
             return kFALSE;
         }
     }
 
-    fContainer.Add(obj);
+    *fLog << "Adding " << name << " to " << GetName() << "... " << flush;
+
+    fContainer.Add(cont);
     *fLog << "Done." << endl;
 
Index: /trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 859)
+++ /trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 860)
@@ -27,5 +27,19 @@
 // MTaskList                                                               //
 //                                                                         //
-// Collection of tasks to be processed in the eventloop                    //
+// Collection of tasks.                                                    //
+//                                                                         //
+// A tasklist is necessary to run the eventloop. It contains the scheduled //
+// tasks, which should be executed in your program.                        //
+//                                                                         //
+// To add a task use AddToList.                                            //
+//                                                                         //
+// The tasklist itself is a task, too. You can add a tasklist to another   //
+// tasklist. This makes sense, if you want to filter the execution of      //
+// more than one task of your tasklist using the same filter.              //
+//                                                                         //
+// The tasks in the list are idetified by their names. If more than one    //
+// task has the same name, the tasklist will still work correctly, but     //
+// you might run into trouble trying to get a pointer to a task by name    //
+// from the list.                                                          //
 //                                                                         //
 /////////////////////////////////////////////////////////////////////////////
@@ -47,8 +61,8 @@
 // this name in the parameter list (by MEvtLoop::SetParList)
 //
-MTaskList::MTaskList(const char *title)
-{
-    *fName  = "MTaskList";
-    *fTitle = title ? title : "List for Tasks";
+MTaskList::MTaskList(const char *name, const char *title)
+{
+    *fName  = name  ? name  : "MTaskList";
+    *fTitle = title ? title : "A list for tasks to be executed";
 }
 
@@ -95,21 +109,41 @@
 Bool_t MTaskList::AddToList(MTask *task, const char *type, MTask *where)
 {
+    // FIXME: We agreed to put the task into list in an ordered way.
+
+    //
+    // Sanity check
+    //
     if (!task)
-        return kTRUE;
-
+        return kFALSE;
+
+    //
+    // Get Name of new task
+    //
     const char *name = task->GetName();
 
-    // FIXME: We agreed to put the task into list in an ordered way.
-
-    if (fTasks.FindObject(task))
-    {
-        *fLog << dbginf << "Task already existing." << endl;
-        return kTRUE;
-    }
-
-    if (fTasks.FindObject(name))
-    {
-        *fLog << dbginf << "'" << name << "' exists in List already." << endl;
-        return kTRUE;
+    //
+    // Check if the new task is already existing in the list
+    //
+    const TObject *objn = fTasks.FindObject(name);
+    const TObject *objt = fTasks.FindObject(task);
+
+    if (objn || objt)
+    {
+        //
+        // If the task is already in the list ignore it.
+        //
+        if (objt || objn==task)
+        {
+            *fLog << dbginf << "Warning: Task '" << task->GetName() << ", 0x" << (void*)task;
+            *fLog << "' already existing in '" << GetName() << "'... ignoring." << endl;
+            return kTRUE;
+        }
+
+        //
+        // Otherwise add it to the list, but print a warning message
+        //
+        *fLog << dbginf << "Warning: Task with the same name '" << task->GetName();
+        *fLog << "' already existing in '" << GetName() << "'." << endl;
+        *fLog << "You may not be able to get a pointer to this task by name." << endl;
     }
 
@@ -118,5 +152,5 @@
         if (!fTasks.FindObject(where))
         {
-            *fLog << dbginf << "Cannot find task after which the new task should be scheduled!" << endl;
+            *fLog << dbginf << "Error: Cannot find task after which the new task should be scheduled!" << endl;
             return kFALSE;
         }
Index: /trunk/MagicSoft/Mars/mbase/MTaskList.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 859)
+++ /trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 860)
@@ -28,5 +28,5 @@
 
 public:
-    MTaskList(const char *title=NULL);
+    MTaskList(const char *name=NULL, const char *title=NULL);
 
     MTaskList(MTaskList &ts);
Index: /trunk/MagicSoft/Mars/mmain/MEvtDisp.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MEvtDisp.cc	(revision 859)
+++ /trunk/MagicSoft/Mars/mmain/MEvtDisp.cc	(revision 860)
@@ -33,7 +33,7 @@
 
 enum {
-  M_BUT_DISP1_EVT, 
-  M_BUT_DISP1_PED, 
-  M_BUT_DISP1_CAL, 
+  M_BUT_DISP1_EVT,
+  M_BUT_DISP1_PED,
+  M_BUT_DISP1_CAL
 };
 
Index: /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.h	(revision 859)
+++ /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.h	(revision 860)
@@ -14,6 +14,6 @@
 {
 private:
-    MMcEvt  *fMcEvt;
-    MMcTrig *fMcTrig;
+    const MMcEvt  *fMcEvt;
+    const MMcTrig *fMcTrig;
 
     MHMcCollectionArea *fCollArea;
Index: /trunk/MagicSoft/Mars/mraw/MRawFileRead.cc
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 859)
+++ /trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 860)
@@ -97,8 +97,6 @@
     // open the input stream
     //
+    fFileName = fname;
     fIn = new ifstream(fname);
-
-    if (!(*fIn))
-        *fLog << "Error: Trying to open file '" << fname << "'" << endl;
 }
 
@@ -131,6 +129,12 @@
 {
     //
-    // remember the pointer to the parameter list fur further usage
-    //
+    // first of all check if opening the file in the constructor was
+    // successfull
+    //
+    if (!(*fIn))
+    {
+        *fLog << "Error: Cannot open file '" << fFileName << "'" << endl;
+        return kFALSE;
+    }
 
     //
Index: /trunk/MagicSoft/Mars/mraw/MRawFileRead.h
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 859)
+++ /trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 860)
@@ -24,4 +24,5 @@
     MTime          *fRawEvtTime;    // raw evt time information container to fill from file
 
+    TString         fFileName;
     ifstream       *fIn;            //! buffered input stream (file to read from)
 
Index: /trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 859)
+++ /trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 860)
@@ -77,6 +77,9 @@
 {
     //
-    // delete instance, this laso does a fOut->Close()
-    //
+    // delete instance, this also does a fOut->Close()
+    //
+    if (fOut->IsOpen())
+        fOut->Write();
+
     delete fOut;
 }
@@ -104,5 +107,5 @@
     if (!fOut->IsOpen())
     {
-        *fLog << dbginf << "Cannot open file '" << fOut->GetName() << "'" << endl;
+        *fLog << dbginf << "Error: Cannot open file '" << fOut->GetName() << "'" << endl;
         return kFALSE;
     }
@@ -200,5 +203,5 @@
     //
     const UShort_t type = fRawEvtHeader->GetTrigType();
-
+    cout << "W" << flush;
     //
     // writa data to the tree. the tree is choosen by the type of the event
@@ -225,17 +228,2 @@
 }
 
-
-// --------------------------------------------------------------------------
-//
-// Close the TFile object and delete it.
-//
-Bool_t MRawFileWrite::PostProcess()
-{
-    //
-    // empty data stream
-    //
-    fOut->Write();
-
-    return kTRUE;
-}
-
Index: /trunk/MagicSoft/Mars/mraw/MRawFileWrite.h
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawFileWrite.h	(revision 859)
+++ /trunk/MagicSoft/Mars/mraw/MRawFileWrite.h	(revision 860)
@@ -43,5 +43,4 @@
     Bool_t PreProcess(MParList *pList);
     Bool_t Process();
-    Bool_t PostProcess();
 
     ClassDef(MRawFileWrite, 0)	// Task to write the raw data containers to a root file
