ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooFactoryWSTool.h 30333 2009-09-21 15:39:17Z wouter $
 * 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_FACTORY_WS_TOOL
#define ROO_FACTORY_WS_TOOL

#include "RooArgSet.h"
#include "RooArgList.h"
#include <string>
#include <list>
#include <vector>
#include <stack>

class RooAbsReal ;
class RooAbsRealLValue ;
class RooAbsPdf ;
class RooWorkspace ;
class RooRealVar ;
class RooCategory ;
class RooAddPdf ;
class RooProdPdf ;
class RooSimultaneous ;
class RooDataHist ;
class RooDataSet ;
class RooAbsData ;
class RooFactoryWSToolSpec ;
class RooAbsCategoryLValue ;
class RooAbsCategory ;
class RooResolutionModel ;
class RooAddition ;
class RooProduct ;
class RooRealSumPdf ;

class RooFactoryWSTool : public TNamed, public RooPrintable {

public:

  // Constructors, assignment etc
  RooFactoryWSTool(RooWorkspace& ws) ;
  virtual ~RooFactoryWSTool() ;

  // --- low level factory interface ---

  // Create variables
  RooRealVar* createVariable(const char* name, Double_t xmin, Double_t xmax) ;
  RooCategory* createCategory(const char* name, const char* stateNameList=0) ;

  // Create functions and p.d.f.s (any RooAbsArg)
  RooAbsArg* createArg(const char* className, const char* objName, const char* varList) ;
  std::vector<std::string> ctorArgs(const char* className) ;

  // Create operator p.d.f.s
  RooAddPdf* add(const char *objName, const char* specList, Bool_t recursiveCoefs=kFALSE) ;
  RooRealSumPdf* amplAdd(const char *objName, const char* specList) ;
  RooProdPdf* prod(const char *objName, const char* pdfList) ;
  RooSimultaneous* simul(const char* objName, const char* indexCat, const char* pdfMap) ;

  // Create operator functions
  RooAddition* addfunc(const char *objName, const char* specList) ;
  RooProduct* prodfunc(const char *objName, const char* pdfList) ;

  RooWorkspace& ws() { return *_ws ; }

  // --- High level factory interface ---

  // Composite object construction language parser
  RooAbsArg* process(const char* expr) ;
  std::string processExpression(const char* expr) ;
  std::vector<std::string> splitFunctionArgs(const char* funcExpr) ;


  // --- Internal stuff that must be public so that CINT can access it ---

  // CINT constructor interface
  static RooAbsArg& as_ARG(UInt_t idx) { checkIndex(idx) ; return _of->_of->asARG(_of->_args[idx].c_str()) ; }

  static RooAbsPdf& as_PDF(UInt_t idx) { checkIndex(idx) ; return _of->asPDF(_of->_args[idx].c_str()) ; }
  static RooAbsReal& as_FUNC(UInt_t idx) { checkIndex(idx) ; return _of->asFUNC(_of->_args[idx].c_str()) ; }
  static RooRealVar& as_VAR(UInt_t idx) { checkIndex(idx) ; return _of->asVAR(_of->_args[idx].c_str()) ; }
  static RooAbsRealLValue& as_VARLV(UInt_t idx) { checkIndex(idx) ; return _of->asVARLV(_of->_args[idx].c_str()) ; }
  static RooResolutionModel& as_RMODEL(UInt_t idx) { checkIndex(idx) ; return _of->asRMODEL(_of->_args[idx].c_str()) ; }

  static RooCategory& as_CAT(UInt_t idx) { checkIndex(idx) ; return _of->asCAT(_of->_args[idx].c_str()) ; }
  static RooAbsCategoryLValue& as_CATLV(UInt_t idx) { checkIndex(idx) ; return _of->asCATLV(_of->_args[idx].c_str()) ; }
  static RooAbsCategory& as_CATFUNC(UInt_t idx) { checkIndex(idx) ; return _of->asCATFUNC(_of->_args[idx].c_str()) ; }

  static RooArgSet as_SET(UInt_t idx) { checkIndex(idx) ; return _of->asSET(_of->_args[idx].c_str()) ; }
  static RooArgList as_LIST(UInt_t idx) { checkIndex(idx) ; return _of->asLIST(_of->_args[idx].c_str()) ; }

  static RooAbsData& as_DATA(UInt_t idx) { checkIndex(idx) ; return _of->asDATA(_of->_args[idx].c_str()) ; }
  static RooDataHist& as_DHIST(UInt_t idx) { checkIndex(idx) ; return _of->asDHIST(_of->_args[idx].c_str()) ; }
  static RooDataSet& as_DSET(UInt_t idx) { checkIndex(idx) ; return _of->asDSET(_of->_args[idx].c_str()) ; }

  static TObject& as_OBJ(UInt_t idx) { checkIndex(idx) ; return _of->asOBJ(_of->_args[idx].c_str()) ; }

  static const char* as_STRING(UInt_t idx) { checkIndex(idx) ; return _of->asSTRING(_of->_args[idx].c_str()) ; }
  static Int_t as_INT(UInt_t idx) { checkIndex(idx) ; return _of->asINT(_of->_args[idx].c_str()) ; }
  static Double_t as_DOUBLE(UInt_t idx) { checkIndex(idx) ; return _of->asDOUBLE(_of->_args[idx].c_str()) ; }
  static Int_t as_INT(UInt_t idx, Int_t defVal) { checkIndex(idx) ;   if (idx>_of->_args.size()-1) return defVal ; return _of->asINT(_of->_args[idx].c_str()) ; }
  static Double_t as_DOUBLE(UInt_t idx, Double_t defVal) { checkIndex(idx) ;   if (idx>_of->_args.size()-1) return defVal ; return _of->asDOUBLE(_of->_args[idx].c_str()) ; }

  RooAbsArg& asARG(const char*) ;

  RooAbsPdf& asPDF(const char*) ;
  RooAbsReal& asFUNC(const char*) ;
  RooRealVar& asVAR(const char*) ;
  RooAbsRealLValue& asVARLV(const char*) ;
  RooResolutionModel& asRMODEL(const char*) ;

  RooCategory& asCAT(const char*) ;
  RooAbsCategoryLValue& asCATLV(const char*) ;
  RooAbsCategory& asCATFUNC(const char*) ;

  RooArgSet asSET(const char*) ; 
  RooArgList asLIST(const char*) ; 

  RooAbsData& asDATA(const char*) ;
  RooDataHist& asDHIST(const char*) ;
  RooDataSet& asDSET(const char*) ;

  TObject& asOBJ(const char*) ;

  const char* asSTRING(const char*) ;
  Int_t asINT(const char*) ;
  Double_t asDOUBLE(const char*) ;
  
  class IFace {
  public:
    virtual ~IFace() {} ;
    virtual std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) = 0 ;
  } ;

  class SpecialsIFace : public IFace {
  public:
    virtual ~SpecialsIFace() {} ;
    std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) ;    
  } ;

  static void registerSpecial(const char* typeName, RooFactoryWSTool::IFace* iface) ;

  void logError() { _errorCount++ ; }

protected:

  std::string varTag(std::string& func, std::vector<std::string>& args) ;

  std::stack<std::string> _autoNamePrefix ; 
  std::map<std::string,std::string> _typeAliases ;

  static void checkIndex(UInt_t index) ;

  
  std::string processCompositeExpression(const char* arg) ;
  std::string processSingleExpression(const char* arg) ;
  std::string processListExpression(const char* arg) ;
  std::string processAliasExpression(const char* arg) ;

  std::string processCreateVar(std::string& func, std::vector<std::string>& args) ;
  std::string processCreateArg(std::string& func, std::vector<std::string>& args) ;
  std::string processMetaArg(std::string& func, std::vector<std::string>& args) ;

  TClass* resolveClassName(const char* className) ;

  // CINT constructor interface back end
  static RooFactoryWSTool* _of ;
  std::vector<std::string> _args ;    

  // Hooks for other tools
  static std::map<std::string,IFace*>& hooks() ;
  static std::map<std::string,IFace*>* _hooks ;

  RooWorkspace* _ws ; //! Associated workspace

  void clearError() { _errorCount = 0 ; }
  Int_t errorCount() { return _errorCount ; }

  Int_t _errorCount ; // Error counter for a given expression processing

  RooFactoryWSTool(const RooFactoryWSTool&) ;

  ClassDef(RooFactoryWSTool,0) // RooFit class code and instance factory 
} ;



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