/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id$
 * 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_DATA_STORE
#define ROO_ABS_DATA_STORE

#include "Rtypes.h"
#include "RooArgSet.h" 
#include "RooAbsData.h"
#include "TNamed.h"
#include <list>


class RooAbsArg ;
class RooArgList ;
class TIterator ;
class TTree ;

class RooAbsDataStore : public TNamed, public RooPrintable {
public:

  RooAbsDataStore() ; 
  RooAbsDataStore(const char* name, const char* title, const RooArgSet& vars) ; 
  RooAbsDataStore(const RooAbsDataStore& other, const char* newname=0) ; 
  RooAbsDataStore(const RooAbsDataStore& other, const RooArgSet& vars, const char* newname=0) ; 
  virtual RooAbsDataStore* clone(const char* newname=0) const = 0 ;
  virtual RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=0) const = 0 ;
  virtual ~RooAbsDataStore() ;

  // Write current row
  virtual Int_t fill() = 0 ;
  
  // Retrieve a row
  virtual const RooArgSet* get(Int_t index) const = 0 ;
  virtual const RooArgSet* get() const { return &_vars ; } 
  virtual Double_t weight() const = 0 ;

  virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const = 0 ;
  virtual void weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const = 0 ; 

  virtual Double_t weight(Int_t index) const = 0 ;

  virtual Bool_t isWeighted() const = 0 ;

  // Change observable name
  virtual Bool_t changeObservableName(const char* from, const char* to) =0 ;
  
  // Add one or more columns
  virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) = 0 ;
  virtual RooArgSet* addColumns(const RooArgList& varList) = 0 ;

  // Merge column-wise
  virtual RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) = 0 ;

  // Add rows 
  virtual void append(RooAbsDataStore& other)= 0 ;

  // General & bookkeeping methods
  virtual Bool_t valid() const = 0 ;
  virtual Int_t numEntries() const = 0 ;
  virtual Double_t sumEntries() const { return 0 ; } ;
  virtual void reset() = 0 ;

  // Buffer redirection routines used in inside RooAbsOptTestStatistics
  virtual void attachBuffers(const RooArgSet& extObs) = 0 ; 
  virtual void resetBuffers() = 0 ;

  virtual void setExternalWeightArray(Double_t* /*arrayWgt*/, Double_t* /*arrayWgtErrLo*/, Double_t* /*arrayWgtErrHi*/, Double_t* /*arraySumW2*/) {} ;

  // Printing interface (human readable)
  inline virtual void Print(Option_t *options= 0) const {
    // Print contents on stdout
    printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
  }

  virtual void printName(std::ostream& os) const ;
  virtual void printTitle(std::ostream& os) const ;
  virtual void printClassName(std::ostream& os) const ;
  virtual void printArgs(std::ostream& os) const ;
  virtual void printValue(std::ostream& os) const ;
  void printMultiline(std::ostream& os, Int_t content, Bool_t verbose, TString indent) const ;

  virtual Int_t defaultPrintContents(Option_t* opt) const ;
   

  // Constant term  optimizer interface
  virtual void cacheArgs(const RooAbsArg* cacheOwner, RooArgSet& varSet, const RooArgSet* nset=0, Bool_t skipZeroWeights=kFALSE) = 0 ;
  virtual const RooAbsArg* cacheOwner() = 0 ;
  virtual void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) = 0 ;
  virtual void setArgStatus(const RooArgSet& set, Bool_t active) = 0 ;
  const RooArgSet& cachedVars() const { return _cachedVars ; }
  virtual void resetCache() = 0 ;
  virtual void recalculateCache(const RooArgSet* /*proj*/, Int_t /*firstEvent*/, Int_t /*lastEvent*/, Int_t /*stepSize*/, Bool_t /* skipZeroWeights*/) {} ;

  virtual void setDirtyProp(Bool_t flag) { _doDirtyProp = flag ; }
  Bool_t dirtyProp() const { return _doDirtyProp ; }

  virtual void checkInit() const {} ;
  
  virtual Bool_t hasFilledCache() const { return kFALSE ; }
  
  virtual const TTree* tree() const { return 0 ; }
  virtual void dump() {} 

  virtual void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) = 0 ;

  virtual void forceCacheUpdate() {} ;
  
 protected:

  RooArgSet _vars ;
  RooArgSet _cachedVars ;
  TIterator *_iterator;    //! Iterator over dimension variables
  TIterator *_cacheIter ;  //! Iterator over cached variables

  Bool_t _doDirtyProp ;    // Switch do (de)activate dirty state propagation when loading a data point

  ClassDef(RooAbsDataStore,1) // Abstract Data Storage class
};


#endif
 RooAbsDataStore.h:1
 RooAbsDataStore.h:2
 RooAbsDataStore.h:3
 RooAbsDataStore.h:4
 RooAbsDataStore.h:5
 RooAbsDataStore.h:6
 RooAbsDataStore.h:7
 RooAbsDataStore.h:8
 RooAbsDataStore.h:9
 RooAbsDataStore.h:10
 RooAbsDataStore.h:11
 RooAbsDataStore.h:12
 RooAbsDataStore.h:13
 RooAbsDataStore.h:14
 RooAbsDataStore.h:15
 RooAbsDataStore.h:16
 RooAbsDataStore.h:17
 RooAbsDataStore.h:18
 RooAbsDataStore.h:19
 RooAbsDataStore.h:20
 RooAbsDataStore.h:21
 RooAbsDataStore.h:22
 RooAbsDataStore.h:23
 RooAbsDataStore.h:24
 RooAbsDataStore.h:25
 RooAbsDataStore.h:26
 RooAbsDataStore.h:27
 RooAbsDataStore.h:28
 RooAbsDataStore.h:29
 RooAbsDataStore.h:30
 RooAbsDataStore.h:31
 RooAbsDataStore.h:32
 RooAbsDataStore.h:33
 RooAbsDataStore.h:34
 RooAbsDataStore.h:35
 RooAbsDataStore.h:36
 RooAbsDataStore.h:37
 RooAbsDataStore.h:38
 RooAbsDataStore.h:39
 RooAbsDataStore.h:40
 RooAbsDataStore.h:41
 RooAbsDataStore.h:42
 RooAbsDataStore.h:43
 RooAbsDataStore.h:44
 RooAbsDataStore.h:45
 RooAbsDataStore.h:46
 RooAbsDataStore.h:47
 RooAbsDataStore.h:48
 RooAbsDataStore.h:49
 RooAbsDataStore.h:50
 RooAbsDataStore.h:51
 RooAbsDataStore.h:52
 RooAbsDataStore.h:53
 RooAbsDataStore.h:54
 RooAbsDataStore.h:55
 RooAbsDataStore.h:56
 RooAbsDataStore.h:57
 RooAbsDataStore.h:58
 RooAbsDataStore.h:59
 RooAbsDataStore.h:60
 RooAbsDataStore.h:61
 RooAbsDataStore.h:62
 RooAbsDataStore.h:63
 RooAbsDataStore.h:64
 RooAbsDataStore.h:65
 RooAbsDataStore.h:66
 RooAbsDataStore.h:67
 RooAbsDataStore.h:68
 RooAbsDataStore.h:69
 RooAbsDataStore.h:70
 RooAbsDataStore.h:71
 RooAbsDataStore.h:72
 RooAbsDataStore.h:73
 RooAbsDataStore.h:74
 RooAbsDataStore.h:75
 RooAbsDataStore.h:76
 RooAbsDataStore.h:77
 RooAbsDataStore.h:78
 RooAbsDataStore.h:79
 RooAbsDataStore.h:80
 RooAbsDataStore.h:81
 RooAbsDataStore.h:82
 RooAbsDataStore.h:83
 RooAbsDataStore.h:84
 RooAbsDataStore.h:85
 RooAbsDataStore.h:86
 RooAbsDataStore.h:87
 RooAbsDataStore.h:88
 RooAbsDataStore.h:89
 RooAbsDataStore.h:90
 RooAbsDataStore.h:91
 RooAbsDataStore.h:92
 RooAbsDataStore.h:93
 RooAbsDataStore.h:94
 RooAbsDataStore.h:95
 RooAbsDataStore.h:96
 RooAbsDataStore.h:97
 RooAbsDataStore.h:98
 RooAbsDataStore.h:99
 RooAbsDataStore.h:100
 RooAbsDataStore.h:101
 RooAbsDataStore.h:102
 RooAbsDataStore.h:103
 RooAbsDataStore.h:104
 RooAbsDataStore.h:105
 RooAbsDataStore.h:106
 RooAbsDataStore.h:107
 RooAbsDataStore.h:108
 RooAbsDataStore.h:109
 RooAbsDataStore.h:110
 RooAbsDataStore.h:111
 RooAbsDataStore.h:112
 RooAbsDataStore.h:113
 RooAbsDataStore.h:114
 RooAbsDataStore.h:115
 RooAbsDataStore.h:116
 RooAbsDataStore.h:117
 RooAbsDataStore.h:118
 RooAbsDataStore.h:119
 RooAbsDataStore.h:120
 RooAbsDataStore.h:121
 RooAbsDataStore.h:122
 RooAbsDataStore.h:123
 RooAbsDataStore.h:124
 RooAbsDataStore.h:125
 RooAbsDataStore.h:126
 RooAbsDataStore.h:127
 RooAbsDataStore.h:128
 RooAbsDataStore.h:129
 RooAbsDataStore.h:130
 RooAbsDataStore.h:131
 RooAbsDataStore.h:132
 RooAbsDataStore.h:133
 RooAbsDataStore.h:134