/*****************************************************************************
 * Project: RooFit                                                           *
 *                                                                           *
 * 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 ROOCACHEDREAL
#define ROOCACHEDREAL

#include "RooAbsCachedReal.h"
#include "RooRealProxy.h"
#include "RooAbsReal.h"


class RooCachedReal : public RooAbsCachedReal {
public:
  RooCachedReal() : _cacheSource(kFALSE) {
    // coverity[UNINIT_CTOR] 
  } 
  RooCachedReal(const char *name, const char *title, RooAbsReal& _func, const RooArgSet& cacheObs);
  RooCachedReal(const char *name, const char *title, RooAbsReal& _func);
  RooCachedReal(const RooCachedReal& other, const char* name=0) ;
  virtual TObject* clone(const char* newname) const { return new RooCachedReal(*this,newname); }
  virtual ~RooCachedReal() ;

  void setCdfBoundaries(Bool_t flag) { 
    // If flag is true the RooHistFunc that represent the cache histogram
    // will use special boundary conditions for use with cumulative distribution
    // functions: at the lower bound the function is forced to converge at zero and the upper 
    // bound is the function is forced to converge at 1.0
    _useCdfBoundaries = flag ; 
  }
  Bool_t getCdfBoundaries() const { 
    // If true the c.d.f boundary mode is active
    return _useCdfBoundaries ; 
  }

  Bool_t cacheSource() const { return _cacheSource ; }
  void setCacheSource(Bool_t flag) { _cacheSource = flag ; }

protected:

  virtual const char* inputBaseName() const { 
    // Return base name for caches, i.e. the name of the cached function
    return func.arg().GetName() ; 
  } ;
  virtual RooArgSet* actualObservables(const RooArgSet& nset) const ;
  virtual RooArgSet* actualParameters(const RooArgSet& nset) const ;
  virtual void fillCacheObject(FuncCacheElem& cacheFunc) const ;
  virtual Double_t evaluate() const { 
    // Dummy evaluate, it is never called
    return func ;
  }

  void operModeHook() ;

  virtual FuncCacheElem* createCache(const RooArgSet* nset) const ;

  virtual const char* payloadUniqueSuffix() const { return func.arg().aggregateCacheUniqueSuffix() ; }
  
  RooRealProxy func ;           // Proxy to function being cached
  RooSetProxy  _cacheObs ;      // Variables to be cached
  Bool_t _useCdfBoundaries ;    // Are c.d.f boundary conditions used by the RooHistFuncs?
  Bool_t _cacheSource ;         // Keep an attached clone of the source in the cache for fast operation

private:

  ClassDef(RooCachedReal,2) // P.d.f class that wraps another p.d.f and caches its output 

};
 
#endif
 RooCachedReal.h:1
 RooCachedReal.h:2
 RooCachedReal.h:3
 RooCachedReal.h:4
 RooCachedReal.h:5
 RooCachedReal.h:6
 RooCachedReal.h:7
 RooCachedReal.h:8
 RooCachedReal.h:9
 RooCachedReal.h:10
 RooCachedReal.h:11
 RooCachedReal.h:12
 RooCachedReal.h:13
 RooCachedReal.h:14
 RooCachedReal.h:15
 RooCachedReal.h:16
 RooCachedReal.h:17
 RooCachedReal.h:18
 RooCachedReal.h:19
 RooCachedReal.h:20
 RooCachedReal.h:21
 RooCachedReal.h:22
 RooCachedReal.h:23
 RooCachedReal.h:24
 RooCachedReal.h:25
 RooCachedReal.h:26
 RooCachedReal.h:27
 RooCachedReal.h:28
 RooCachedReal.h:29
 RooCachedReal.h:30
 RooCachedReal.h:31
 RooCachedReal.h:32
 RooCachedReal.h:33
 RooCachedReal.h:34
 RooCachedReal.h:35
 RooCachedReal.h:36
 RooCachedReal.h:37
 RooCachedReal.h:38
 RooCachedReal.h:39
 RooCachedReal.h:40
 RooCachedReal.h:41
 RooCachedReal.h:42
 RooCachedReal.h:43
 RooCachedReal.h:44
 RooCachedReal.h:45
 RooCachedReal.h:46
 RooCachedReal.h:47
 RooCachedReal.h:48
 RooCachedReal.h:49
 RooCachedReal.h:50
 RooCachedReal.h:51
 RooCachedReal.h:52
 RooCachedReal.h:53
 RooCachedReal.h:54
 RooCachedReal.h:55
 RooCachedReal.h:56
 RooCachedReal.h:57
 RooCachedReal.h:58
 RooCachedReal.h:59
 RooCachedReal.h:60
 RooCachedReal.h:61
 RooCachedReal.h:62
 RooCachedReal.h:63
 RooCachedReal.h:64
 RooCachedReal.h:65
 RooCachedReal.h:66
 RooCachedReal.h:67
 RooCachedReal.h:68
 RooCachedReal.h:69
 RooCachedReal.h:70
 RooCachedReal.h:71
 RooCachedReal.h:72
 RooCachedReal.h:73
 RooCachedReal.h:74
 RooCachedReal.h:75
 RooCachedReal.h:76
 RooCachedReal.h:77