// @(#)root/proofplayer:$Id$
// Author: G. Ganis   04/08/2010

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TProofOutputList                                                     //
//                                                                      //
// Derivation of TList with an overload of ls() and Print() allowing    //
// to filter out some of the variables.                                 //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TObjString.h"
#include "TProof.h"
#include "TProofOutputList.h"
#include "TRegexp.h"
#include "TString.h"

ClassImp(TProofOutputList)

//______________________________________________________________________________
TProofOutputList::TProofOutputList(const char *dontshow) : TList()
{
   // Constructor
   
   fDontShow = new TList();
   TString regs(dontshow), reg;
   Int_t from = 0;
   while (regs.Tokenize(reg, from, ",")) {
      fDontShow->Add(new TObjString(reg));
   }
}

//______________________________________________________________________________
TProofOutputList::~TProofOutputList()
{
   // Destructor
   
   fDontShow->SetOwner(kTRUE);
   SafeDelete(fDontShow);
}

//______________________________________________________________________________
void TProofOutputList::AttachList(TList *alist)
{
   // Attach to list 'alist'

   if (!alist) return;

   if (GetSize() > 0) Clear();

   TIter nxo(alist);
   TObject *obj = 0;
   while ((obj = nxo())) { Add(obj); }
   SetOwner(kFALSE);
}

//______________________________________________________________________________
void TProofOutputList::ls(Option_t *option) const
{
   // List the content of the list

   TString opt(option);
   opt.ToUpper();
   if (opt.BeginsWith("ALL")) {
      opt.Remove(0,3);
      TList::ls(opt);
   } else {
      TIter nxos(fDontShow);
      TObjString *os = 0;
      TList doShow;
      doShow.SetOwner(kFALSE);
      
      Bool_t hasmissing = kFALSE;
      TIter nxo(this);
      TObject *obj = 0;
      while ((obj = nxo())) {
         TString s = obj->GetName();
         if (s == kPROOF_MissingFiles) {
            TList *mf = dynamic_cast<TList *> (obj);
            if (mf && mf->GetSize() > 0) hasmissing = kTRUE;
         } else {
            nxos.Reset();
            Bool_t doadd = kTRUE;
            while ((os = (TObjString *) nxos())) {
               TRegexp rg(os->GetName(), kTRUE);
               if (s.Index(rg) != kNPOS) {
                  doadd = kFALSE;
                  break;
               }
            }
            if (doadd) doShow.Add(obj);
         }
      }
      doShow.ls(option);
      // Notify if missing files were found
      if (hasmissing)
         Printf(" +++ Missing files list not empty: use ShowMissingFiles to display it +++");
   }
   // Done
   return;
}


//______________________________________________________________________________
void TProofOutputList::Print(Option_t *option) const
{
   // Print the content of the list
 
   TString opt(option);
   opt.ToUpper();
   if (opt.BeginsWith("ALL")) {
      opt.Remove(0,3);
      TList::Print(opt);
   } else {
      TIter nxos(fDontShow);
      TObjString *os = 0;
      TList doShow;
      doShow.SetOwner(kFALSE);
      
      Bool_t hasmissing = kFALSE;
      TIter nxo(this);
      TObject *obj = 0;
      while ((obj = nxo())) {
         TString s = obj->GetName();
         if (s == kPROOF_MissingFiles) {
            TList *mf = dynamic_cast<TList *> (obj);
            if (mf && mf->GetSize() > 0) hasmissing = kTRUE;
         } else {
            nxos.Reset();
            Bool_t doadd = kTRUE;
            while ((os = (TObjString *) nxos())) {
               TRegexp rg(os->GetName());
               if (s.Index(rg) != kNPOS) {;
                  doadd = kFALSE;
                  break;
               }
            }
            if (doadd) doShow.Add(obj);
         }
      }
      doShow.Print(option);
      // Notify if missing files were found
      if (hasmissing)
         Printf(" +++ Missing files list not empty: use ShowMissingFiles to display it +++");
   }
   // Done
   return;
}
 TProofOutputList.cxx:1
 TProofOutputList.cxx:2
 TProofOutputList.cxx:3
 TProofOutputList.cxx:4
 TProofOutputList.cxx:5
 TProofOutputList.cxx:6
 TProofOutputList.cxx:7
 TProofOutputList.cxx:8
 TProofOutputList.cxx:9
 TProofOutputList.cxx:10
 TProofOutputList.cxx:11
 TProofOutputList.cxx:12
 TProofOutputList.cxx:13
 TProofOutputList.cxx:14
 TProofOutputList.cxx:15
 TProofOutputList.cxx:16
 TProofOutputList.cxx:17
 TProofOutputList.cxx:18
 TProofOutputList.cxx:19
 TProofOutputList.cxx:20
 TProofOutputList.cxx:21
 TProofOutputList.cxx:22
 TProofOutputList.cxx:23
 TProofOutputList.cxx:24
 TProofOutputList.cxx:25
 TProofOutputList.cxx:26
 TProofOutputList.cxx:27
 TProofOutputList.cxx:28
 TProofOutputList.cxx:29
 TProofOutputList.cxx:30
 TProofOutputList.cxx:31
 TProofOutputList.cxx:32
 TProofOutputList.cxx:33
 TProofOutputList.cxx:34
 TProofOutputList.cxx:35
 TProofOutputList.cxx:36
 TProofOutputList.cxx:37
 TProofOutputList.cxx:38
 TProofOutputList.cxx:39
 TProofOutputList.cxx:40
 TProofOutputList.cxx:41
 TProofOutputList.cxx:42
 TProofOutputList.cxx:43
 TProofOutputList.cxx:44
 TProofOutputList.cxx:45
 TProofOutputList.cxx:46
 TProofOutputList.cxx:47
 TProofOutputList.cxx:48
 TProofOutputList.cxx:49
 TProofOutputList.cxx:50
 TProofOutputList.cxx:51
 TProofOutputList.cxx:52
 TProofOutputList.cxx:53
 TProofOutputList.cxx:54
 TProofOutputList.cxx:55
 TProofOutputList.cxx:56
 TProofOutputList.cxx:57
 TProofOutputList.cxx:58
 TProofOutputList.cxx:59
 TProofOutputList.cxx:60
 TProofOutputList.cxx:61
 TProofOutputList.cxx:62
 TProofOutputList.cxx:63
 TProofOutputList.cxx:64
 TProofOutputList.cxx:65
 TProofOutputList.cxx:66
 TProofOutputList.cxx:67
 TProofOutputList.cxx:68
 TProofOutputList.cxx:69
 TProofOutputList.cxx:70
 TProofOutputList.cxx:71
 TProofOutputList.cxx:72
 TProofOutputList.cxx:73
 TProofOutputList.cxx:74
 TProofOutputList.cxx:75
 TProofOutputList.cxx:76
 TProofOutputList.cxx:77
 TProofOutputList.cxx:78
 TProofOutputList.cxx:79
 TProofOutputList.cxx:80
 TProofOutputList.cxx:81
 TProofOutputList.cxx:82
 TProofOutputList.cxx:83
 TProofOutputList.cxx:84
 TProofOutputList.cxx:85
 TProofOutputList.cxx:86
 TProofOutputList.cxx:87
 TProofOutputList.cxx:88
 TProofOutputList.cxx:89
 TProofOutputList.cxx:90
 TProofOutputList.cxx:91
 TProofOutputList.cxx:92
 TProofOutputList.cxx:93
 TProofOutputList.cxx:94
 TProofOutputList.cxx:95
 TProofOutputList.cxx:96
 TProofOutputList.cxx:97
 TProofOutputList.cxx:98
 TProofOutputList.cxx:99
 TProofOutputList.cxx:100
 TProofOutputList.cxx:101
 TProofOutputList.cxx:102
 TProofOutputList.cxx:103
 TProofOutputList.cxx:104
 TProofOutputList.cxx:105
 TProofOutputList.cxx:106
 TProofOutputList.cxx:107
 TProofOutputList.cxx:108
 TProofOutputList.cxx:109
 TProofOutputList.cxx:110
 TProofOutputList.cxx:111
 TProofOutputList.cxx:112
 TProofOutputList.cxx:113
 TProofOutputList.cxx:114
 TProofOutputList.cxx:115
 TProofOutputList.cxx:116
 TProofOutputList.cxx:117
 TProofOutputList.cxx:118
 TProofOutputList.cxx:119
 TProofOutputList.cxx:120
 TProofOutputList.cxx:121
 TProofOutputList.cxx:122
 TProofOutputList.cxx:123
 TProofOutputList.cxx:124
 TProofOutputList.cxx:125
 TProofOutputList.cxx:126
 TProofOutputList.cxx:127
 TProofOutputList.cxx:128
 TProofOutputList.cxx:129
 TProofOutputList.cxx:130
 TProofOutputList.cxx:131
 TProofOutputList.cxx:132
 TProofOutputList.cxx:133
 TProofOutputList.cxx:134
 TProofOutputList.cxx:135
 TProofOutputList.cxx:136
 TProofOutputList.cxx:137
 TProofOutputList.cxx:138
 TProofOutputList.cxx:139
 TProofOutputList.cxx:140
 TProofOutputList.cxx:141
 TProofOutputList.cxx:142
 TProofOutputList.cxx:143
 TProofOutputList.cxx:144
 TProofOutputList.cxx:145
 TProofOutputList.cxx:146
 TProofOutputList.cxx:147
 TProofOutputList.cxx:148
 TProofOutputList.cxx:149
 TProofOutputList.cxx:150
 TProofOutputList.cxx:151
 TProofOutputList.cxx:152
 TProofOutputList.cxx:153
 TProofOutputList.cxx:154
 TProofOutputList.cxx:155
 TProofOutputList.cxx:156
 TProofOutputList.cxx:157