Index: trunk/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- trunk/Mars/mfileio/MWriteRootFile.cc	(revision 17764)
+++ trunk/Mars/mfileio/MWriteRootFile.cc	(revision 17867)
@@ -213,4 +213,8 @@
     Init(name, title);
 
+    const Bool_t hasrule = fSplitRule.BeginsWith("s/") && fSplitRule.EndsWith("/");
+    if (!hasrule)
+        fSplitRule = "";
+
     //
     // Open a TFile in dummy mode! This is necessary to be able to create
@@ -218,5 +222,6 @@
     // a valid file. (Stupid workaround - but does a good job)
     //
-    fOut = OpenFile("/dev/null", option, ftitle, comp);
+    const TString fname = hasrule ? "/dev/null" : rule;
+    fOut = OpenFile(fname, option, ftitle, comp);
 }
 
@@ -393,5 +398,5 @@
 // is the name of the tree.
 //
-void MWriteRootFile::AddContainer(const char *cname, const char *tname, Bool_t must)
+void MWriteRootFile::AddContainer(const char *cname, const char *tname, Bool_t must, Long64_t max)
 {
     if (!fOut && !tname)
@@ -412,5 +417,5 @@
     // add the entry to the list.
     //
-    MRootFileBranch *entry = new MRootFileBranch(AddSerialNumber(cname), tname, must);
+    MRootFileBranch *entry = new MRootFileBranch(AddSerialNumber(cname), tname, must, max);
     fBranches.AddLast(entry);
 
@@ -429,5 +434,5 @@
 // is the name of the tree.
 //
-void MWriteRootFile::AddContainer(MParContainer *cont, const char *tname, Bool_t must)
+void MWriteRootFile::AddContainer(MParContainer *cont, const char *tname, Bool_t must, Long64_t max)
 {
     if (!fOut && !tname)
@@ -449,5 +454,5 @@
     // add the entry to the list.
     //
-    MRootFileBranch *entry = new MRootFileBranch(cont, tname, must);
+    MRootFileBranch *entry = new MRootFileBranch(cont, tname, must, max);
     fBranches.AddLast(entry);
 }
@@ -712,4 +717,7 @@
             continue;
 
+        if (b->GetMaxEntries()==b->GetTree()->GetEntries())
+            continue;
+
         //
         // If the write flag of the branch entry is set, set the write flag of
Index: trunk/Mars/mfileio/MWriteRootFile.h
===================================================================
--- trunk/Mars/mfileio/MWriteRootFile.h	(revision 17764)
+++ trunk/Mars/mfileio/MWriteRootFile.h	(revision 17867)
@@ -25,4 +25,5 @@
 
     Bool_t         fMust;
+    Long64_t       fMaxEntries;
 
     void Init(const char *name, Bool_t must)
@@ -33,5 +34,5 @@
 
 public:
-    MRootFileBranch() : fTree(NULL), fBranch(NULL), fContainer(NULL), fMust(0)
+    MRootFileBranch() : fTree(NULL), fBranch(NULL), fContainer(NULL), fMust(0), fMaxEntries(0)
     {
         Init(NULL, kFALSE);
@@ -39,6 +40,6 @@
     }
 
-    MRootFileBranch(const char *cname, const char *tname=NULL, Bool_t must=kFALSE)
-        : fTree(NULL), fBranch(NULL), fContainer(NULL), fMust(0)
+    MRootFileBranch(const char *cname, const char *tname=NULL, Bool_t must=kFALSE, Long64_t max=-1)
+        : fTree(NULL), fBranch(NULL), fContainer(NULL), fMust(0), fMaxEntries(max)
     {
         Init(tname, must);
@@ -46,6 +47,6 @@
     }
 
-    MRootFileBranch(MParContainer *cont, const char *tname=NULL, Bool_t must=kFALSE)
-        : fTree(NULL), fBranch(NULL), fMust(0)
+    MRootFileBranch(MParContainer *cont, const char *tname=NULL, Bool_t must=kFALSE, Long64_t max=-1)
+        : fTree(NULL), fBranch(NULL), fMust(0), fMaxEntries(max)
     {
         Init(tname, must);
@@ -54,10 +55,11 @@
     }
 
-    TTree         *GetTree() const      { return fTree; }
-    MParContainer *GetContainer() const { return fContainer; }
-    void          *GetAddress()         { return &fContainer; }
-    TBranch       *GetBranch() const    { return fBranch; }
-    const char    *GetContName() const  { return fTitle; }
-    Bool_t         MustHave() const     { return fMust; }
+    TTree         *GetTree() const       { return fTree; }
+    MParContainer *GetContainer() const  { return fContainer; }
+    void          *GetAddress()          { return &fContainer; }
+    TBranch       *GetBranch() const     { return fBranch; }
+    const char    *GetContName() const   { return fTitle; }
+    Bool_t         MustHave() const      { return fMust; }
+    Long64_t         GetMaxEntries() const { return fMaxEntries; }
 
     void SetContainer(MParContainer *cont) { fContainer = cont; }
@@ -129,6 +131,6 @@
     ~MWriteRootFile();
 
-    void AddContainer(const char *cname,   const char *tname=NULL, Bool_t must=kTRUE);
-    void AddContainer(MParContainer *cont, const char *tname=NULL, Bool_t must=kTRUE);
+    void AddContainer(const char *cname,   const char *tname=NULL, Bool_t must=kTRUE, Long64_t max=-1);
+    void AddContainer(MParContainer *cont, const char *tname=NULL, Bool_t must=kTRUE, Long64_t max=-1);
     void AddCopySource(const char *tname, const char *bname=NULL, Bool_t force=kTRUE);
     void AddCopySource(const char *tname, Bool_t force)
