00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef ROO_FACTORY_WS_TOOL
00018 #define ROO_FACTORY_WS_TOOL
00019
00020 #include "RooArgSet.h"
00021 #include "RooArgList.h"
00022 #include <string>
00023 #include <list>
00024 #include <vector>
00025 #include <stack>
00026
00027 class RooAbsReal ;
00028 class RooAbsRealLValue ;
00029 class RooAbsPdf ;
00030 class RooWorkspace ;
00031 class RooRealVar ;
00032 class RooCategory ;
00033 class RooAddPdf ;
00034 class RooProdPdf ;
00035 class RooSimultaneous ;
00036 class RooDataHist ;
00037 class RooDataSet ;
00038 class RooAbsData ;
00039 class RooFactoryWSToolSpec ;
00040 class RooAbsCategoryLValue ;
00041 class RooAbsCategory ;
00042 class RooResolutionModel ;
00043 class RooAddition ;
00044 class RooProduct ;
00045 class RooRealSumPdf ;
00046
00047 class RooFactoryWSTool : public TNamed, public RooPrintable {
00048
00049 public:
00050
00051
00052 RooFactoryWSTool(RooWorkspace& ws) ;
00053 virtual ~RooFactoryWSTool() ;
00054
00055
00056
00057
00058 RooRealVar* createVariable(const char* name, Double_t xmin, Double_t xmax) ;
00059 RooCategory* createCategory(const char* name, const char* stateNameList=0) ;
00060
00061
00062 RooAbsArg* createArg(const char* className, const char* objName, const char* varList) ;
00063 std::vector<std::string> ctorArgs(const char* className) ;
00064
00065
00066 RooAddPdf* add(const char *objName, const char* specList, Bool_t recursiveCoefs=kFALSE) ;
00067 RooRealSumPdf* amplAdd(const char *objName, const char* specList) ;
00068 RooProdPdf* prod(const char *objName, const char* pdfList) ;
00069 RooSimultaneous* simul(const char* objName, const char* indexCat, const char* pdfMap) ;
00070
00071
00072 RooAddition* addfunc(const char *objName, const char* specList) ;
00073 RooProduct* prodfunc(const char *objName, const char* pdfList) ;
00074
00075 RooWorkspace& ws() { return *_ws ; }
00076
00077
00078
00079
00080 RooAbsArg* process(const char* expr) ;
00081 std::string processExpression(const char* expr) ;
00082 std::vector<std::string> splitFunctionArgs(const char* funcExpr) ;
00083
00084
00085
00086
00087
00088 static RooAbsArg& as_ARG(UInt_t idx) { checkIndex(idx) ; return _of->_of->asARG(_of->_args[idx].c_str()) ; }
00089
00090 static RooAbsPdf& as_PDF(UInt_t idx) { checkIndex(idx) ; return _of->asPDF(_of->_args[idx].c_str()) ; }
00091 static RooAbsReal& as_FUNC(UInt_t idx) { checkIndex(idx) ; return _of->asFUNC(_of->_args[idx].c_str()) ; }
00092 static RooRealVar& as_VAR(UInt_t idx) { checkIndex(idx) ; return _of->asVAR(_of->_args[idx].c_str()) ; }
00093 static RooAbsRealLValue& as_VARLV(UInt_t idx) { checkIndex(idx) ; return _of->asVARLV(_of->_args[idx].c_str()) ; }
00094 static RooResolutionModel& as_RMODEL(UInt_t idx) { checkIndex(idx) ; return _of->asRMODEL(_of->_args[idx].c_str()) ; }
00095
00096 static RooCategory& as_CAT(UInt_t idx) { checkIndex(idx) ; return _of->asCAT(_of->_args[idx].c_str()) ; }
00097 static RooAbsCategoryLValue& as_CATLV(UInt_t idx) { checkIndex(idx) ; return _of->asCATLV(_of->_args[idx].c_str()) ; }
00098 static RooAbsCategory& as_CATFUNC(UInt_t idx) { checkIndex(idx) ; return _of->asCATFUNC(_of->_args[idx].c_str()) ; }
00099
00100 static RooArgSet as_SET(UInt_t idx) { checkIndex(idx) ; return _of->asSET(_of->_args[idx].c_str()) ; }
00101 static RooArgList as_LIST(UInt_t idx) { checkIndex(idx) ; return _of->asLIST(_of->_args[idx].c_str()) ; }
00102
00103 static RooAbsData& as_DATA(UInt_t idx) { checkIndex(idx) ; return _of->asDATA(_of->_args[idx].c_str()) ; }
00104 static RooDataHist& as_DHIST(UInt_t idx) { checkIndex(idx) ; return _of->asDHIST(_of->_args[idx].c_str()) ; }
00105 static RooDataSet& as_DSET(UInt_t idx) { checkIndex(idx) ; return _of->asDSET(_of->_args[idx].c_str()) ; }
00106
00107 static TObject& as_OBJ(UInt_t idx) { checkIndex(idx) ; return _of->asOBJ(_of->_args[idx].c_str()) ; }
00108
00109 static const char* as_STRING(UInt_t idx) { checkIndex(idx) ; return _of->asSTRING(_of->_args[idx].c_str()) ; }
00110 static Int_t as_INT(UInt_t idx) { checkIndex(idx) ; return _of->asINT(_of->_args[idx].c_str()) ; }
00111 static Double_t as_DOUBLE(UInt_t idx) { checkIndex(idx) ; return _of->asDOUBLE(_of->_args[idx].c_str()) ; }
00112 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()) ; }
00113 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()) ; }
00114
00115 RooAbsArg& asARG(const char*) ;
00116
00117 RooAbsPdf& asPDF(const char*) ;
00118 RooAbsReal& asFUNC(const char*) ;
00119 RooRealVar& asVAR(const char*) ;
00120 RooAbsRealLValue& asVARLV(const char*) ;
00121 RooResolutionModel& asRMODEL(const char*) ;
00122
00123 RooCategory& asCAT(const char*) ;
00124 RooAbsCategoryLValue& asCATLV(const char*) ;
00125 RooAbsCategory& asCATFUNC(const char*) ;
00126
00127 RooArgSet asSET(const char*) ;
00128 RooArgList asLIST(const char*) ;
00129
00130 RooAbsData& asDATA(const char*) ;
00131 RooDataHist& asDHIST(const char*) ;
00132 RooDataSet& asDSET(const char*) ;
00133
00134 TObject& asOBJ(const char*) ;
00135
00136 const char* asSTRING(const char*) ;
00137 Int_t asINT(const char*) ;
00138 Double_t asDOUBLE(const char*) ;
00139
00140 class IFace {
00141 public:
00142 virtual ~IFace() {} ;
00143 virtual std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) = 0 ;
00144 } ;
00145
00146 class SpecialsIFace : public IFace {
00147 public:
00148 virtual ~SpecialsIFace() {} ;
00149 std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) ;
00150 } ;
00151
00152 static void registerSpecial(const char* typeName, RooFactoryWSTool::IFace* iface) ;
00153
00154 void logError() { _errorCount++ ; }
00155
00156 protected:
00157
00158 Bool_t checkSyntax(const char* arg) ;
00159
00160 std::string varTag(std::string& func, std::vector<std::string>& args) ;
00161
00162 std::stack<std::string> _autoNamePrefix ;
00163 std::map<std::string,std::string> _typeAliases ;
00164
00165 static void checkIndex(UInt_t index) ;
00166
00167
00168 std::string processCompositeExpression(const char* arg) ;
00169 std::string processSingleExpression(const char* arg) ;
00170 std::string processListExpression(const char* arg) ;
00171 std::string processAliasExpression(const char* arg) ;
00172
00173 std::string processCreateVar(std::string& func, std::vector<std::string>& args) ;
00174 std::string processCreateArg(std::string& func, std::vector<std::string>& args) ;
00175 std::string processMetaArg(std::string& func, std::vector<std::string>& args) ;
00176
00177 TClass* resolveClassName(const char* className) ;
00178
00179
00180 static RooFactoryWSTool* _of ;
00181 std::vector<std::string> _args ;
00182
00183
00184 static std::map<std::string,IFace*>& hooks() ;
00185 static std::map<std::string,IFace*>* _hooks ;
00186
00187 RooWorkspace* _ws ;
00188
00189 void clearError() { _errorCount = 0 ; }
00190 Int_t errorCount() { return _errorCount ; }
00191
00192 Int_t _errorCount ;
00193
00194 RooFactoryWSTool(const RooFactoryWSTool&) ;
00195
00196 ClassDef(RooFactoryWSTool,0)
00197 } ;
00198
00199
00200
00201 #endif