Index: trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1969)
+++ trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 2002)
@@ -208,9 +208,9 @@
 Bool_t MWriteRootFile::GetContainer(MParList *pList)
 {
+    //
+    // loop over all branches which are 'marked' as branches to get written.
+    //
     MRootFileBranch *entry;
 
-    //
-    // loop over all branches which are 'marked' as branches to get written.
-    //
     TIter Next(&fBranches);
     while ((entry=(MRootFileBranch*)Next()))
@@ -274,4 +274,10 @@
             fTrees.AddLast(tree);
 
+            //
+            // If the tree does not already exist in the file mark this
+            // tree as a branch created by MWriteRootFile
+            //
+            entry->SetBit(kIsNewTree);
+
             gDirectory = save;
 
@@ -280,15 +286,17 @@
 
         //
+        // In case the file is opened as 'UPDATE' the tree may still not
+        // be in the list. Because it neither was created previously,
+        // nor this time, so the corresponding entries is marked as a
+        // single branch to be filled. --> Add it to the list of trees.
+        //
+        if (!fTrees.FindObject(tree))
+            fTrees.AddLast(tree);
+
+        //
         // 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
         //
-        TObject *obj;
-        TIter NextTree(&fTrees);
-        while ((obj=NextTree()))
-        {
-            if (obj == tree)
-                entry->SetTree((TTree*)obj);
-        }
+        entry->SetTree(tree);
 
         //
@@ -315,6 +323,4 @@
         branch = tree->Branch(branchname, cont->ClassName(), entry->GetAddress());
 
-        *fLog << "Created Branch " << cname << " of " << cont->ClassName() << "." << endl;
-
         //
         // If the branch couldn't be created we have a problem.
@@ -325,4 +331,11 @@
             return kFALSE;
         }
+
+        //
+        // Tell the entry also which branch belongs to it (this is necessary
+        // for branches belonging to already existing tree, UPDATE-mode)
+        //
+        entry->SetBranch(branch);
+        *fLog << "Created Branch " << cname << " of " << cont->ClassName() << "." << endl;
     }
     return kTRUE;
@@ -333,6 +346,11 @@
 // 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
+// All Trees which are marked to be filled are filled with all their
 // branches.
+// In case of a file opened in 'UPDATE' mode, single branches can be
+// filled, too. WARNING - for the moment there is no check whether
+// you filled the correct number of events into the branch, so that
+// each of the other branches in the tree has the correct corresponding
+// number of new entries in the new branch!
 // Be carefull: If only one container (corresponding to a branch) of a tree
 // has the write flag, all containers in this tree are filled!
@@ -362,5 +380,8 @@
         // the corresponding tree entry.
         //
-        b->GetTree()->SetBit(kFillTree);
+        if (b->TestBit(kIsNewTree))
+            b->GetTree()->SetBit(kFillTree);
+        else
+            b->GetBranch()->Fill();
     }
 
Index: trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h	(revision 1969)
+++ trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h	(revision 2002)
@@ -57,4 +57,5 @@
     void SetContainer(MParContainer *cont) { fContainer = cont; }
     void SetTree(TTree *tree)              { fTree = tree; }
+    void SetBranch(TBranch *branch)        { fBranch = branch; }
 
     ClassDef(MRootFileBranch, 1) // Storage container for MWriteRootFile to store TBranch informations
@@ -69,4 +70,6 @@
     TObjArray fTrees;     //!
 
+    //UInt_t fNumEvents; //! Number of events written in a run
+
     void        CheckAndWrite() const;
     Bool_t      IsFileOpen() const;
@@ -75,4 +78,9 @@
 
     void StreamPrimitive(ofstream &out) const;
+    //Bool_t ReInit(MParList *pList);
+
+    enum {
+        kIsNewTree = BIT(15)
+    };
 
 public:
