/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooAbsCollection.h,v 1.26 2007/08/09 19:55:47 wouter Exp $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_ABS_COLLECTION
#define ROO_ABS_COLLECTION

#include "TString.h"
#include "RooAbsArg.h"
#include "RooPrintable.h"
#include "RooLinkedList.h"
#include "RooCmdArg.h"
#include "RooLinkedListIter.h"
#include <string>

class RooAbsCollection : public TObject, public RooPrintable {
public:

  // Constructors, assignment etc.
  RooAbsCollection();
  RooAbsCollection(const char *name);
  virtual TObject* clone(const char* newname) const = 0 ;
  virtual TObject* create(const char* newname) const = 0 ;
  virtual TObject* Clone(const char* newname=0) const { 
    return clone(newname?newname:GetName()) ; 
  }
  virtual ~RooAbsCollection();

  // Create a copy of an existing list. New variables cannot be added
  // to a copied list. The variables in the copied list are independent
  // of the original variables.
  RooAbsCollection(const RooAbsCollection& other, const char *name="");
  RooAbsCollection& operator=(const RooAbsCollection& other);
  RooAbsCollection& assignValueOnly(const RooAbsCollection& other, Bool_t oneSafe=kFALSE) ;
  void assignFast(const RooAbsCollection& other, Bool_t setValDirty=kTRUE) ;

  // Copy list and contents (and optionally 'deep' servers)
  RooAbsCollection *snapshot(Bool_t deepCopy=kTRUE) const ;
  Bool_t snapshot(RooAbsCollection& output, Bool_t deepCopy=kTRUE) const ;

  // Hash table control
  void setHashTableSize(Int_t i) { 
    // Set size of internal hash table to i (should be a prime number)
    _list.setHashTableSize(i) ; 
  }
  Int_t getHashTableSize() const { 
    // Return size of internal hash table
    return _list.getHashTableSize() ; 
  }

  // List content management
  virtual Bool_t add(const RooAbsArg& var, Bool_t silent=kFALSE) ;
  virtual Bool_t addOwned(RooAbsArg& var, Bool_t silent=kFALSE);
  virtual RooAbsArg *addClone(const RooAbsArg& var, Bool_t silent=kFALSE) ;
  virtual Bool_t replace(const RooAbsArg& var1, const RooAbsArg& var2) ;
  virtual Bool_t remove(const RooAbsArg& var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
  virtual void removeAll() ;

  virtual Bool_t add(const RooAbsCollection& list, Bool_t silent=kFALSE) ;
  virtual Bool_t addOwned(const RooAbsCollection& list, Bool_t silent=kFALSE);
  virtual void   addClone(const RooAbsCollection& list, Bool_t silent=kFALSE);
  Bool_t replace(const RooAbsCollection &other);
  Bool_t remove(const RooAbsCollection& list, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;

  // Group operations on AbsArgs
  void setAttribAll(const Text_t* name, Bool_t value=kTRUE) ;

  // List search methods
  RooAbsArg *find(const char *name) const ;
  RooAbsArg *find(const RooAbsArg&) const ;

  Bool_t contains(const RooAbsArg& var) const { 
    // Returns true if object with same name as var is contained in this collection
    return (0 == find(var)) ? kFALSE:kTRUE; 
  }
  Bool_t containsInstance(const RooAbsArg& var) const { 
    // Returns true if var is contained in this collection
    return (0 == _list.FindObject(&var)) ? kFALSE:kTRUE; 
  }
  RooAbsCollection* selectByAttrib(const char* name, Bool_t value) const ;
  RooAbsCollection* selectCommon(const RooAbsCollection& refColl) const ;
  RooAbsCollection* selectByName(const char* nameList, Bool_t verbose=kFALSE) const ;
  Bool_t equals(const RooAbsCollection& otherColl) const ; 
  Bool_t overlaps(const RooAbsCollection& otherColl) const ;

  // export subset of THashList interface
  inline TIterator* createIterator(Bool_t dir = kIterForward) const { 
    // Create and return an iterator over the elements in this collection
    return _list.MakeIterator(dir); 
  }

  RooLinkedListIter iterator(Bool_t dir = kIterForward) const ;
  RooFIter fwdIterator() const { return RooFIter(&_list); }

  inline Int_t getSize() const { 
    // Return the number of elements in the collection
    return _list.GetSize(); 
  }
  inline RooAbsArg *first() const { 
    // Return the first element in this collection
    return (RooAbsArg*)_list.First(); 
  }

  inline virtual void Print(Option_t *options= 0) const {
    // Printing interface (human readable)
    printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
  }
  std::string contentsString() const ;


  virtual void printName(std::ostream& os) const ;
  virtual void printTitle(std::ostream& os) const ;
  virtual void printClassName(std::ostream& os) const ;
  virtual void printValue(std::ostream& os) const ;
  virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;

  virtual Int_t defaultPrintContents(Option_t* opt) const ;

  // Latex printing methods
  void printLatex(const RooCmdArg& arg1=RooCmdArg(), const RooCmdArg& arg2=RooCmdArg(),	
		  const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),	
		  const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),	
		  const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) const ;
  void printLatex(std::ostream& ofs, Int_t ncol, const char* option="NEYU", Int_t sigDigit=1, 
                  const RooLinkedList& siblingLists=RooLinkedList(), const RooCmdArg* formatCmd=0) const ;

  void setName(const char *name) {
    // Set name of collection
    _name= name; 
  }
  const char* GetName() const { 
    // Return namer of collection
    return _name.Data() ; 
  }
  Bool_t isOwning() const { 
    // Does collection own contents?
    return _ownCont ; 
  }

  Bool_t allInRange(const char* rangeSpec) const ;

  void dump() const ;

  void releaseOwnership() { _ownCont = kFALSE ; }
  void takeOwnership() { _ownCont = kTRUE ; }

  void sort(Bool_t ascend=kTRUE) { _list.Sort(ascend) ; }

protected:

  friend class RooMultiCatIter ;

  RooLinkedList _list ; // Actual object store

  Bool_t _ownCont;  // Flag to identify a list that owns its contents.
  TString _name;    // Our name.
  Bool_t _allRRV ; // All contents are RRV

  void safeDeleteList() ;

  // Support for snapshot method 
  Bool_t addServerClonesToList(const RooAbsArg& var) ;

  inline TNamed* structureTag() { if (_structureTag==0) makeStructureTag() ; return _structureTag ; }
  inline TNamed* typedStructureTag() { if (_typedStructureTag==0) makeTypedStructureTag() ; return _typedStructureTag ; }

  mutable TNamed* _structureTag ; //! Structure tag
  mutable TNamed* _typedStructureTag ; //! Typed structure tag
  
  inline void clearStructureTags() { _structureTag=0 ; _typedStructureTag = 0 ; }

  void makeStructureTag() ;
  void makeTypedStructureTag() ;
  
private:

  ClassDef(RooAbsCollection,2) // Collection of RooAbsArg objects
};

#endif
 RooAbsCollection.h:1
 RooAbsCollection.h:2
 RooAbsCollection.h:3
 RooAbsCollection.h:4
 RooAbsCollection.h:5
 RooAbsCollection.h:6
 RooAbsCollection.h:7
 RooAbsCollection.h:8
 RooAbsCollection.h:9
 RooAbsCollection.h:10
 RooAbsCollection.h:11
 RooAbsCollection.h:12
 RooAbsCollection.h:13
 RooAbsCollection.h:14
 RooAbsCollection.h:15
 RooAbsCollection.h:16
 RooAbsCollection.h:17
 RooAbsCollection.h:18
 RooAbsCollection.h:19
 RooAbsCollection.h:20
 RooAbsCollection.h:21
 RooAbsCollection.h:22
 RooAbsCollection.h:23
 RooAbsCollection.h:24
 RooAbsCollection.h:25
 RooAbsCollection.h:26
 RooAbsCollection.h:27
 RooAbsCollection.h:28
 RooAbsCollection.h:29
 RooAbsCollection.h:30
 RooAbsCollection.h:31
 RooAbsCollection.h:32
 RooAbsCollection.h:33
 RooAbsCollection.h:34
 RooAbsCollection.h:35
 RooAbsCollection.h:36
 RooAbsCollection.h:37
 RooAbsCollection.h:38
 RooAbsCollection.h:39
 RooAbsCollection.h:40
 RooAbsCollection.h:41
 RooAbsCollection.h:42
 RooAbsCollection.h:43
 RooAbsCollection.h:44
 RooAbsCollection.h:45
 RooAbsCollection.h:46
 RooAbsCollection.h:47
 RooAbsCollection.h:48
 RooAbsCollection.h:49
 RooAbsCollection.h:50
 RooAbsCollection.h:51
 RooAbsCollection.h:52
 RooAbsCollection.h:53
 RooAbsCollection.h:54
 RooAbsCollection.h:55
 RooAbsCollection.h:56
 RooAbsCollection.h:57
 RooAbsCollection.h:58
 RooAbsCollection.h:59
 RooAbsCollection.h:60
 RooAbsCollection.h:61
 RooAbsCollection.h:62
 RooAbsCollection.h:63
 RooAbsCollection.h:64
 RooAbsCollection.h:65
 RooAbsCollection.h:66
 RooAbsCollection.h:67
 RooAbsCollection.h:68
 RooAbsCollection.h:69
 RooAbsCollection.h:70
 RooAbsCollection.h:71
 RooAbsCollection.h:72
 RooAbsCollection.h:73
 RooAbsCollection.h:74
 RooAbsCollection.h:75
 RooAbsCollection.h:76
 RooAbsCollection.h:77
 RooAbsCollection.h:78
 RooAbsCollection.h:79
 RooAbsCollection.h:80
 RooAbsCollection.h:81
 RooAbsCollection.h:82
 RooAbsCollection.h:83
 RooAbsCollection.h:84
 RooAbsCollection.h:85
 RooAbsCollection.h:86
 RooAbsCollection.h:87
 RooAbsCollection.h:88
 RooAbsCollection.h:89
 RooAbsCollection.h:90
 RooAbsCollection.h:91
 RooAbsCollection.h:92
 RooAbsCollection.h:93
 RooAbsCollection.h:94
 RooAbsCollection.h:95
 RooAbsCollection.h:96
 RooAbsCollection.h:97
 RooAbsCollection.h:98
 RooAbsCollection.h:99
 RooAbsCollection.h:100
 RooAbsCollection.h:101
 RooAbsCollection.h:102
 RooAbsCollection.h:103
 RooAbsCollection.h:104
 RooAbsCollection.h:105
 RooAbsCollection.h:106
 RooAbsCollection.h:107
 RooAbsCollection.h:108
 RooAbsCollection.h:109
 RooAbsCollection.h:110
 RooAbsCollection.h:111
 RooAbsCollection.h:112
 RooAbsCollection.h:113
 RooAbsCollection.h:114
 RooAbsCollection.h:115
 RooAbsCollection.h:116
 RooAbsCollection.h:117
 RooAbsCollection.h:118
 RooAbsCollection.h:119
 RooAbsCollection.h:120
 RooAbsCollection.h:121
 RooAbsCollection.h:122
 RooAbsCollection.h:123
 RooAbsCollection.h:124
 RooAbsCollection.h:125
 RooAbsCollection.h:126
 RooAbsCollection.h:127
 RooAbsCollection.h:128
 RooAbsCollection.h:129
 RooAbsCollection.h:130
 RooAbsCollection.h:131
 RooAbsCollection.h:132
 RooAbsCollection.h:133
 RooAbsCollection.h:134
 RooAbsCollection.h:135
 RooAbsCollection.h:136
 RooAbsCollection.h:137
 RooAbsCollection.h:138
 RooAbsCollection.h:139
 RooAbsCollection.h:140
 RooAbsCollection.h:141
 RooAbsCollection.h:142
 RooAbsCollection.h:143
 RooAbsCollection.h:144
 RooAbsCollection.h:145
 RooAbsCollection.h:146
 RooAbsCollection.h:147
 RooAbsCollection.h:148
 RooAbsCollection.h:149
 RooAbsCollection.h:150
 RooAbsCollection.h:151
 RooAbsCollection.h:152
 RooAbsCollection.h:153
 RooAbsCollection.h:154
 RooAbsCollection.h:155
 RooAbsCollection.h:156
 RooAbsCollection.h:157
 RooAbsCollection.h:158
 RooAbsCollection.h:159
 RooAbsCollection.h:160
 RooAbsCollection.h:161
 RooAbsCollection.h:162
 RooAbsCollection.h:163
 RooAbsCollection.h:164
 RooAbsCollection.h:165
 RooAbsCollection.h:166
 RooAbsCollection.h:167
 RooAbsCollection.h:168
 RooAbsCollection.h:169
 RooAbsCollection.h:170
 RooAbsCollection.h:171
 RooAbsCollection.h:172
 RooAbsCollection.h:173
 RooAbsCollection.h:174
 RooAbsCollection.h:175
 RooAbsCollection.h:176
 RooAbsCollection.h:177
 RooAbsCollection.h:178
 RooAbsCollection.h:179
 RooAbsCollection.h:180
 RooAbsCollection.h:181
 RooAbsCollection.h:182
 RooAbsCollection.h:183
 RooAbsCollection.h:184
 RooAbsCollection.h:185
 RooAbsCollection.h:186
 RooAbsCollection.h:187
 RooAbsCollection.h:188
 RooAbsCollection.h:189
 RooAbsCollection.h:190
 RooAbsCollection.h:191