Logo ROOT  
Reference Guide
RooFactoryWSTool.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 /**
18 \file RooFactoryWSTool.cxx
19 \class RooFactoryWSTool
20 \ingroup Roofitcore
21 
22 RooFactoryWSTool is a class similar to TTree::MakeClass() that generates
23 skeleton code for RooAbsPdf and RooAbsReal functions given
24 a list of input parameter names. The factory can also compile
25 the generated code on the fly, and on request also
26 instantiate the objects.
27 
28 It interprets all expressions for RooWorkspace::factory(const char*).
29 **/
30 
31 #include "RooFit.h"
32 
33 #include "RooFactoryWSTool.h"
34 #include "RooAbsReal.h"
35 #include "RooAbsCategory.h"
36 #include "RooArgList.h"
37 #include "RooRealVar.h"
38 #include "RooCategory.h"
39 #include "RooMsgService.h"
40 #include "RooWorkspace.h"
41 #include "TInterpreter.h"
42 #include "TEnum.h"
43 #include "RooAbsPdf.h"
44 #include <fstream>
45 #include "strtok.h"
46 #include "strlcpy.h"
47 #include "RooGlobalFunc.h"
48 #include "RooDataSet.h"
49 #include "RooDataHist.h"
50 #include "RooAddPdf.h"
51 #include "RooProdPdf.h"
52 #include "RooSimultaneous.h"
53 #include "RooFFTConvPdf.h"
54 #include "RooNumConvPdf.h"
55 #include "RooResolutionModel.h"
56 #include "RooProduct.h"
57 #include "RooAddition.h"
58 #include "RooChi2Var.h"
59 #include "RooNLLVar.h"
60 #include "RooRealSumPdf.h"
61 #include "RooConstVar.h"
62 #include "RooDerivative.h"
63 #include "RooStringVar.h"
64 #include "TROOT.h"
65 
66 using namespace RooFit ;
67 using namespace std ;
68 
69 #define BUFFER_SIZE 64000
70 
72 ;
73 
75 map<string,RooFactoryWSTool::IFace*>* RooFactoryWSTool::_hooks=0 ;
76 
77 static Int_t init();
78 
79 static Int_t dummy = init() ;
80 
81 static Int_t init()
82 {
84 
85  // Operator p.d.f.s
87  RooFactoryWSTool::registerSpecial("RSUM",iface) ;
88  RooFactoryWSTool::registerSpecial("ASUM",iface) ;
89  RooFactoryWSTool::registerSpecial("PROD",iface) ;
90  RooFactoryWSTool::registerSpecial("SIMUL",iface) ;
91  RooFactoryWSTool::registerSpecial("EXPR",iface) ;
92  RooFactoryWSTool::registerSpecial("FCONV",iface) ;
93  RooFactoryWSTool::registerSpecial("NCONV",iface) ;
94 
95  // Operator functions
97  RooFactoryWSTool::registerSpecial("prod",iface) ;
98  RooFactoryWSTool::registerSpecial("expr",iface) ;
99  RooFactoryWSTool::registerSpecial("nconv",iface) ;
100 
101  // Test statistics
102  RooFactoryWSTool::registerSpecial("nll",iface) ;
103  RooFactoryWSTool::registerSpecial("chi2",iface) ;
104  RooFactoryWSTool::registerSpecial("profile",iface) ;
105 
106  // Integration and derivation
107  RooFactoryWSTool::registerSpecial("int",iface) ;
108  RooFactoryWSTool::registerSpecial("deriv",iface) ;
109  RooFactoryWSTool::registerSpecial("cdf",iface) ;
110  RooFactoryWSTool::registerSpecial("PROJ",iface) ;
111 
112  // Miscellaneous
113  RooFactoryWSTool::registerSpecial("dataobs",iface) ;
114  RooFactoryWSTool::registerSpecial("set",iface) ;
115 
116  (void) dummy;
117  return 0 ;
118 }
119 
120 
121 #ifndef _WIN32
122 #include <strings.h>
123 #endif
124 
125 
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 
129 RooFactoryWSTool::RooFactoryWSTool(RooWorkspace& inws) : _ws(&inws), _errorCount(0), _autoClassPostFix("")
130 
131 {
132  // Default constructor
133 }
134 
135 
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Destructor
139 
141 {
142 }
143 
144 
145 
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// Low-level factory interface for creating a RooRealVar with a given range and initial value
149 
151 {
152  // First check if variable already exists
153  if (_ws->var(name)) {
154  coutE(ObjectHandling) << "RooFactoryWSTool::createFactory() ERROR: variable with name '" << name << "' already exists" << endl ;
155  logError() ;
156  return 0 ;
157  }
158 
159  // Create variable
160  RooRealVar var(name,name,xmin,xmax) ;
161 
162  // Put in workspace
163  if (_ws->import(var,Silence())) logError() ;
164 
165  return _ws->var(name) ;
166 }
167 
168 
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Low-level factory interface for creating a RooCategory with a given list of state names. The State name list
172 /// can be of the form 'name1,name2,name3' or of the form 'name1=id1,name2=id2,name3=id3'
173 
174 RooCategory* RooFactoryWSTool::createCategory(const char* name, const char* stateNameList)
175 {
176  // Create variable
177  RooCategory cat(name,name) ;
178 
179  // Add listed state names
180  if (stateNameList) {
181  const size_t tmpSize = strlen(stateNameList)+1;
182  char *tmp = new char[tmpSize] ;
183  strlcpy(tmp,stateNameList,tmpSize) ;
184  char* save ;
185  char* tok = R__STRTOK_R(tmp,",",&save) ;
186  while(tok) {
187  char* sep = strchr(tok,'=') ;
188  if (sep) {
189  *sep = 0 ;
190  Int_t id = atoi(sep+1) ;
191  cat.defineType(tok,id) ;
192  *sep = '=' ;
193  } else {
194  cat.defineType(tok) ;
195  }
196  tok = R__STRTOK_R(0,",",&save) ;
197  }
198  delete[] tmp ;
199  }
200 
201  cat.setStringAttribute("factory_tag",Form("%s[%s]",name,stateNameList)) ;
202 
203  // Put in workspace
204  if (_ws->import(cat,Silence())) logError() ;
205 
206  return _ws->cat(name) ;
207 }
208 
209 namespace {
210  static bool isEnum(const char* classname) {
211  // Returns true if given type is an enum
212  ClassInfo_t* cls = gInterpreter->ClassInfo_Factory(classname);
213  long property = gInterpreter->ClassInfo_Property(cls);
214  gInterpreter->ClassInfo_Delete(cls);
215  return (property&kIsEnum);
216  }
217 
218 
219  static bool isValidEnumValue(const char* enumName, const char* enumConstantName) {
220  // Returns true if given type is an enum
221 
222  if (!enumName) return false;
223 
224  auto theEnum = TEnum::GetEnum(enumName);
225  if (!enumName) return false;
226 
227  // Attempt 1: Enum constant name as is
228  if (theEnum->GetConstant(enumConstantName)) return true;
229  // Attempt 2: Remove the scope preceding the enum constant name
230  auto tmp = strstr(enumConstantName, "::");
231  if (tmp) {
232  auto enumConstantNameNoScope = tmp+2;
233  if (theEnum->GetConstant(enumConstantNameNoScope)) return true;
234  }
235 
236  return false;
237  }
238 
239  static pair<list<string>,unsigned int> ctorArgs(const char* classname, UInt_t nMinArg) {
240  // Utility function for RooFactoryWSTool. Return arguments of 'first' non-default, non-copy constructor of any RooAbsArg
241  // derived class. Only constructors that start with two 'const char*' arguments (for name and title) are considered
242  // The returned object contains
243 
244  Int_t nreq(0);
245  list<string> ret;
246 
247  ClassInfo_t* cls = gInterpreter->ClassInfo_Factory(classname);
248  MethodInfo_t* func = gInterpreter->MethodInfo_Factory(cls);
249  while(gInterpreter->MethodInfo_Next(func)) {
250  ret.clear();
251  nreq=0;
252 
253  // Find 'the' constructor
254 
255  // Skip non-public methods
256  if (!(gInterpreter->MethodInfo_Property(func) & kIsPublic)) {
257  continue;
258  }
259 
260  // Return type must be class name
261  if (string(classname) != gInterpreter->MethodInfo_TypeName(func)) {
262  continue;
263  }
264 
265  // Skip default constructor
266  int nargs = gInterpreter->MethodInfo_NArg(func);
267  if (nargs==0 || nargs==gInterpreter->MethodInfo_NDefaultArg(func)) {
268  continue;
269  }
270 
271  MethodArgInfo_t* arg = gInterpreter->MethodArgInfo_Factory(func);
272  while (gInterpreter->MethodArgInfo_Next(arg)) {
273  // Require that first two arguments are of type const char*
274  const char* argTypeName = gInterpreter->MethodArgInfo_TypeName(arg);
275  if (nreq<2 && ((string("char*") != argTypeName
276  && !(gInterpreter->MethodArgInfo_Property(arg) & kIsConstPointer))
277  && string("const char*") != argTypeName)) {
278  continue ;
279  }
280  ret.push_back(argTypeName) ;
281  if(!gInterpreter->MethodArgInfo_DefaultValue(arg)) nreq++;
282  }
283  gInterpreter->MethodArgInfo_Delete(arg);
284 
285  // Check that the number of required arguments is at least nMinArg
286  if (ret.size()<nMinArg) {
287  continue;
288  }
289 
290  break;
291  }
292  gInterpreter->MethodInfo_Delete(func);
293  gInterpreter->ClassInfo_Delete(cls);
294  return pair<list<string>,unsigned int>(ret,nreq);
295  }
296 }
297 
298 ////////////////////////////////////////////////////////////////////////////////
299 /// Low-level factory interface for creating a RooAbsPdf of a given class with a given list of input variables
300 /// The variable list varList should be of the form "a,b,c" where the interpretation of the argument is
301 /// dependent on the p.d.f. Set and List arguments can be passed by substituting a single argument with
302 /// the form (a,b,c), i.e. one can set varList to "x,(a0,a1,a2)" to pass a RooAbsReal and a RooArgSet as arguments.
303 
304 RooAbsArg* RooFactoryWSTool::createArg(const char* className, const char* objName, const char* varList)
305 {
306  // Find class in ROOT class table
307  TClass* tc = resolveClassName(className);
308  if (!tc) {
309  coutE(ObjectHandling) << "RooFactoryWSTool::createArg() ERROR class " << className << " not found in factory alias table, nor in ROOT class table" << endl;
310  logError();
311  return 0;
312  }
313 
314  className = tc->GetName();
315 
316  // Check that class inherits from RooAbsPdf
317  if (!tc->InheritsFrom(RooAbsArg::Class())) {
318  coutE(ObjectHandling) << "RooFactoryWSTool::createArg() ERROR class " << className << " does not inherit from RooAbsArg" << endl;
319  logError();
320  return 0;
321  }
322 
323  _args.clear();
324  string tmp(varList);
325  size_t blevel = 0, end_tok, start_tok = 0;
326  bool litmode = false;
327  for (end_tok = 0; end_tok < tmp.length(); end_tok++) {
328  // Keep track of opening and closing brackets
329  if (tmp[end_tok]=='{' || tmp[end_tok]=='(' || tmp[end_tok]=='[') blevel++;
330  if (tmp[end_tok]=='}' || tmp[end_tok]==')' || tmp[end_tok]==']') blevel--;
331 
332  // Keep track of string literals
333  if (tmp[end_tok]=='"' || tmp[end_tok]=='\'') litmode = !litmode;
334 
335  // If we encounter a comma at zero bracket level
336  // push the current substring from start_tok to end_tok
337  // and start the next token
338  if (litmode == false && blevel == 0 && tmp[end_tok] == ',') {
339  _args.push_back(tmp.substr(start_tok, end_tok - start_tok));
340  start_tok = end_tok+1;
341  }
342  }
343  _args.push_back(tmp.substr(start_tok, end_tok));
344 
345  // Try CINT interface
346  pair<list<string>,unsigned int> ca = ctorArgs(className,_args.size()+2) ;
347  if (ca.first.size()==0) {
348  coutE(ObjectHandling) << "RooFactoryWSTool::createArg() ERROR no suitable constructor found for class " << className << endl ;
349  logError() ;
350  return 0 ;
351  }
352 
353 
354  // Check if number of provided args is in valid range (add two to accomodate name and title strings)
355  if (_args.size()+2<ca.second || _args.size()+2>ca.first.size()) {
356  if (ca.second==ca.first.size()) {
357  coutE(ObjectHandling) << "RooFactoryWSTool::createArg() ERROR number of arguments provided (" << _args.size() << ") for class is invalid, " << className
358  << " expects " << ca.first.size()-2 << endl ;
359  logError() ;
360  } else {
361  coutE(ObjectHandling) << "RooFactoryWSTool::createArg() ERROR number of arguments provided (" << _args.size() << ") for class is invalid " << className
362  << " expect number between " << ca.second-2 << " and " << ca.first.size()-2 << endl ;
363  logError() ;
364  }
365  return 0 ;
366  }
367 
368  // Now construct CINT constructor spec, start with mandatory name and title args
369  string cintExpr(Form("new %s(\"%s\",\"%s\"",className,objName,objName)) ;
370 
371  // Install argument in static data member to be accessed below through static CINT interface functions
372  _of = this ;
373 
374 
375  try {
376  Int_t i(0) ;
377  list<string>::iterator ti = ca.first.begin() ; ++ti ; ++ti ;
378  for (vector<string>::iterator ai = _args.begin() ; ai != _args.end() ; ++ai,++ti,++i) {
379  if ((*ti)=="RooAbsReal&" || (*ti)=="const RooAbsReal&") {
381  cintExpr += Form(",RooFactoryWSTool::as_FUNC(%d)",i) ;
382  } else if ((*ti)=="RooAbsArg&" || (*ti)=="const RooAbsArg&") {
384  cintExpr += Form(",RooFactoryWSTool::as_ARG(%d)",i) ;
385  } else if ((*ti)=="RooRealVar&" || (*ti)=="const RooRealVar&") {
387  cintExpr += Form(",RooFactoryWSTool::as_VAR(%d)",i) ;
388  } else if ((*ti)=="RooAbsRealLValue&" || (*ti)=="const RooAbsRealLValue&") {
390  cintExpr += Form(",RooFactoryWSTool::as_VARLV(%d)",i) ;
391  } else if ((*ti)=="RooCategory&" || (*ti)=="const RooCategory&") {
393  cintExpr += Form(",RooFactoryWSTool::as_CAT(%d)",i) ;
394  } else if ((*ti)=="RooAbsCategory&" || (*ti)=="const RooAbsCategory&") {
396  cintExpr += Form(",RooFactoryWSTool::as_CATFUNC(%d)",i) ;
397  } else if ((*ti)=="RooAbsCategoryLValue&" || (*ti)=="const RooAbsCategoryLValue&") {
399  cintExpr += Form(",RooFactoryWSTool::as_CATLV(%d)",i) ;
400  } else if ((*ti)=="RooAbsPdf&" || (*ti)=="const RooAbsPdf&") {
402  cintExpr += Form(",RooFactoryWSTool::as_PDF(%d)",i) ;
403  } else if ((*ti)=="RooResolutionModel&" || (*ti)=="const RooResolutionModel&") {
405  cintExpr += Form(",RooFactoryWSTool::as_RMODEL(%d)",i) ;
406  } else if ((*ti)=="RooAbsData&" || (*ti)=="const RooAbsData&") {
408  cintExpr += Form(",RooFactoryWSTool::as_DATA(%d)",i) ;
409  } else if ((*ti)=="RooDataSet&" || (*ti)=="const RooDataSet&") {
411  cintExpr += Form(",RooFactoryWSTool::as_DSET(%d)",i) ;
412  } else if ((*ti)=="RooDataHist&" || (*ti)=="const RooDataHist&") {
414  cintExpr += Form(",RooFactoryWSTool::as_DHIST(%d)",i) ;
415  } else if ((*ti)=="const RooArgSet&") {
417  cintExpr += Form(",RooFactoryWSTool::as_SET(%d)",i) ;
418  } else if ((*ti)=="const RooArgList&") {
420  cintExpr += Form(",RooFactoryWSTool::as_LIST(%d)",i) ;
421  } else if ((*ti)=="const char*") {
423  cintExpr += Form(",RooFactoryWSTool::as_STRING(%d)",i) ;
424  } else if ((*ti)=="Int_t" || (*ti)=="int" || (*ti)=="Bool_t" || (*ti)=="bool") {
426  cintExpr += Form(",RooFactoryWSTool::as_INT(%d)",i) ;
427  } else if ((*ti)=="Double_t") {
429  cintExpr += Form(",RooFactoryWSTool::as_DOUBLE(%d)",i) ;
430  } else if (isEnum(ti->c_str())) {
431 
432  string qualvalue ;
433  if (_args[i].find(Form("%s::",className)) != string::npos) {
434  qualvalue = _args[i].c_str() ;
435  } else {
436  qualvalue = Form("%s::%s",className,_args[i].c_str()) ;
437  }
438  if (isValidEnumValue(ti->c_str(),qualvalue.c_str())) {
439  cintExpr += Form(",(%s)%s",ti->c_str(),qualvalue.c_str()) ;
440  } else {
441  throw string(Form("Supplied argument %s does not represent a valid state of enum %s",_args[i].c_str(),ti->c_str())) ;
442  }
443  } else {
444  // Check if generic object store has argument of given name and type
446 
447  // Strip argument type to bare type (i.e. const X& -> X)
448  string btype ;
449  if (ti->find("const ")==0) {
450  btype = ti->c_str()+6 ;
451  } else {
452  btype = *ti ;
453  }
454  if (btype.find("&")) {
455  btype.erase(btype.size()-1,btype.size()) ;
456  }
457 
458  // If btype if a typedef, substitute it by the true type name
459  btype = string(TEnum::GetEnum(btype.c_str())->GetName());
460 
461  if (obj.InheritsFrom(btype.c_str())) {
462  cintExpr += Form(",(%s&)RooFactoryWSTool::as_OBJ(%d)",ti->c_str(),i) ;
463  } else {
464  throw string(Form("Required argument with name %s of type '%s' is not in the workspace",_args[i].c_str(),ti->c_str())) ;
465  }
466  }
467  }
468  cintExpr += ") ;" ;
469  } catch (const string &err) {
470  coutE(ObjectHandling) << "RooFactoryWSTool::createArg() ERROR constructing " << className << "::" << objName << ": " << err << endl ;
471  logError() ;
472  return 0 ;
473  }
474 
475  cxcoutD(ObjectHandling) << "RooFactoryWSTool::createArg() Construct expression is " << cintExpr << endl ;
476 
477  // Call CINT to perform constructor call. Catch any error thrown by argument conversion method
478  RooAbsArg* arg = (RooAbsArg*) gROOT->ProcessLineFast(cintExpr.c_str()) ;
479 
480  if (arg) {
481  if (string(className)=="RooGenericPdf") {
482  arg->setStringAttribute("factory_tag",Form("EXPR::%s(%s)",objName,varList)) ;
483  } else if (string(className)=="RooFormulaVar") {
484  arg->setStringAttribute("factory_tag",Form("expr::%s(%s)",objName,varList)) ;
485  } else {
486  arg->setStringAttribute("factory_tag",Form("%s::%s(%s)",className,objName,varList)) ;
487  }
488  if (_ws->import(*arg,Silence())) logError() ;
489  RooAbsArg* ret = _ws->arg(objName) ;
490  delete arg ;
491  return ret ;
492  } else {
493  coutE(ObjectHandling) << "RooFactoryWSTool::createArg() ERROR in CINT constructor call to create object" << endl ;
494  logError() ;
495  return 0 ;
496  }
497 }
498 
499 ////////////////////////////////////////////////////////////////////////////////
500 
501 RooAddPdf* RooFactoryWSTool::add(const char *objName, const char* specList, Bool_t recursiveCoefs)
502 {
503  // Spec list is of form a*A,b*B,c*C,D [ *d]
504 
505  RooArgList pdfList ;
506  RooArgList coefList ;
507  RooArgList pdfList2 ;
508 
509  try {
510 
511  char buf[BUFFER_SIZE] ;
512  strlcpy(buf,specList,BUFFER_SIZE) ;
513  char* save ;
514  char* tok = R__STRTOK_R(buf,",",&save) ;
515  while(tok) {
516  char* star=strchr(tok,'*') ;
517  if (star) {
518  *star=0 ;
519  pdfList.add(asPDF(star+1)) ;
520  coefList.add(asFUNC(tok)) ;
521  } else {
522  pdfList2.add(asPDF(tok)) ;
523  }
524  tok = R__STRTOK_R(0,",",&save) ;
525  }
526  pdfList.add(pdfList2) ;
527 
528  } catch (const string &err) {
529  coutE(ObjectHandling) << "RooFactoryWSTool::add(" << objName << ") ERROR creating RooAddPdf: " << err << endl ;
530  logError() ;
531  return 0 ;
532  }
533 
534  RooAddPdf* pdf = new RooAddPdf(objName,objName,pdfList,coefList,recursiveCoefs) ;
535  pdf->setStringAttribute("factory_tag",Form("SUM::%s(%s)",objName,specList)) ;
536  if (_ws->import(*pdf,Silence())) logError() ;
537  return (RooAddPdf*) _ws->pdf(objName) ;
538 }
539 
540 
541 ////////////////////////////////////////////////////////////////////////////////
542 
543 RooRealSumPdf* RooFactoryWSTool::amplAdd(const char *objName, const char* specList)
544 {
545  // Spec list is of form a*A,b*B,c*C,D [ *d]
546 
547  RooArgList amplList ;
548  RooArgList coefList ;
549  RooArgList amplList2 ;
550 
551  try {
552 
553  char buf[BUFFER_SIZE] ;
554  strlcpy(buf,specList,BUFFER_SIZE) ;
555  char* save ;
556  char* tok = R__STRTOK_R(buf,",",&save) ;
557  while(tok) {
558  char* star=strchr(tok,'*') ;
559  if (star) {
560  *star=0 ;
561  amplList.add(asFUNC(star+1)) ;
562  coefList.add(asFUNC(tok)) ;
563  } else {
564  amplList2.add(asFUNC(tok)) ;
565  }
566  tok = R__STRTOK_R(0,",",&save) ;
567  }
568  amplList.add(amplList2) ;
569 
570  } catch (const string &err) {
571  coutE(ObjectHandling) << "RooFactoryWSTool::add(" << objName << ") ERROR creating RooRealSumPdf: " << err << endl ;
572  logError() ;
573  return 0 ;
574  }
575 
576  RooRealSumPdf* pdf = new RooRealSumPdf(objName,objName,amplList,coefList,(amplList.getSize()==coefList.getSize())) ;
577  pdf->setStringAttribute("factory_tag",Form("ASUM::%s(%s)",objName,specList)) ;
578  if (_ws->import(*pdf,Silence())) logError() ;
579  return (RooRealSumPdf*) _ws->pdf(objName) ;
580 }
581 
582 
583 ////////////////////////////////////////////////////////////////////////////////
584 
585 RooProdPdf* RooFactoryWSTool::prod(const char *objName, const char* pdfList)
586 {
587  _of = this ;
588 
589  // Separate conditional and non-conditional p.d.f terms
590  RooLinkedList cmdList ;
591  string regPdfList="{" ;
592  char buf[BUFFER_SIZE] ;
593  strlcpy(buf,pdfList,BUFFER_SIZE) ;
594  char* save ;
595  char* tok = R__STRTOK_R(buf,",",&save) ;
596  while(tok) {
597  char *sep = strchr(tok,'|') ;
598  if (sep) {
599  // Conditional term
600  *sep=0 ;
601  sep++ ;
602 
603  // |x is conditional on x, |~x is conditional on all but x
604  Bool_t invCond(kFALSE) ;
605  if (*sep=='~') {
606  invCond=kTRUE ;
607  sep++ ;
608  }
609 
610  try {
611  cmdList.Add(Conditional(asSET(tok),asSET(sep),!invCond).Clone()) ;
612  } catch (const string &err) {
613  coutE(ObjectHandling) << "RooFactoryWSTool::prod(" << objName << ") ERROR creating RooProdPdf Conditional argument: " << err << endl ;
614  logError() ;
615  return 0 ;
616  }
617 
618  } else {
619  // Regular term
620  if (regPdfList.size()>1) {
621  regPdfList += "," ;
622  }
623  regPdfList += tok ;
624  }
625  tok = R__STRTOK_R(0,",",&save) ;
626  }
627  regPdfList += "}" ;
628 
629  RooProdPdf* pdf = 0 ;
630  try {
631  pdf = new RooProdPdf(objName,objName,asSET(regPdfList.c_str()),cmdList) ;
632  } catch (const string &err) {
633  coutE(ObjectHandling) << "RooFactoryWSTool::prod(" << objName << ") ERROR creating RooProdPdf input set of regular p.d.f.s: " << err << endl ;
634  logError() ;
635  pdf = 0 ;
636  }
637  cmdList.Delete() ;
638 
639  if (pdf) {
640  pdf->setStringAttribute("factory_tag",Form("PROD::%s(%s)",objName,pdfList)) ;
641  if (_ws->import(*pdf,Silence())) logError() ;
642  delete pdf ;
643  return (RooProdPdf*) _ws->pdf(objName) ;
644  } else {
645  return 0 ;
646  }
647 }
648 
649 
650 
651 ////////////////////////////////////////////////////////////////////////////////
652 
653 RooSimultaneous* RooFactoryWSTool::simul(const char* objName, const char* indexCat, const char* pdfMap)
654 {
655  map<string,RooAbsPdf*> theMap ;
656  // Add p.d.f. to index state mappings
657  char buf[BUFFER_SIZE] ;
658  strlcpy(buf,pdfMap,BUFFER_SIZE) ;
659  char* save ;
660  char* tok = R__STRTOK_R(buf,",",&save) ;
661  while(tok) {
662  char* eq = strchr(tok,'=') ;
663  if (!eq) {
664  coutE(ObjectHandling) << "RooFactoryWSTool::simul(" << objName << ") ERROR creating RooSimultaneous::" << objName
665  << " expect mapping token of form 'state=pdfName', but found '" << tok << "'" << endl ;
666  logError() ;
667  return 0 ;
668  } else {
669  *eq = 0 ;
670 
671  try {
672  theMap[tok] = &asPDF(eq+1) ;
673  } catch (const string &err ) {
674  coutE(ObjectHandling) << "RooFactoryWSTool::simul(" << objName << ") ERROR creating RooSimultaneous: " << err << endl ;
675  logError() ;
676  }
677  }
678  tok = R__STRTOK_R(0,",",&save) ;
679  }
680 
681 
682  // Create simultaneous p.d.f.
683  RooSimultaneous* pdf(0) ;
684  try {
685  pdf = new RooSimultaneous(objName,objName,theMap,asCATLV(indexCat)) ;
686  } catch (const string &err) {
687  coutE(ObjectHandling) << "RooFactoryWSTool::simul(" << objName << ") ERROR creating RooSimultaneous::" << objName << " " << err << endl ;
688  logError() ;
689  }
690 
691  // Import p.d.f into workspace
692  pdf->setStringAttribute("factory_tag",Form("SIMUL::%s(%s,%s)",objName,indexCat,pdfMap)) ;
693  if (_ws->import(*pdf,Silence())) logError() ;
694  return (RooSimultaneous*) _ws->pdf(objName) ;
695 }
696 
697 
698 
699 
700 ////////////////////////////////////////////////////////////////////////////////
701 
702 RooAddition* RooFactoryWSTool::addfunc(const char *objName, const char* specList)
703 {
704  RooArgList sumlist1 ;
705  RooArgList sumlist2 ;
706 
707  try {
708 
709  char buf[BUFFER_SIZE] ;
710  strlcpy(buf,specList,BUFFER_SIZE) ;
711  char* save ;
712  char* tok = R__STRTOK_R(buf,",",&save) ;
713  while(tok) {
714  char* star=strchr(tok,'*') ;
715  if (star) {
716  *star=0 ;
717  sumlist2.add(asFUNC(star+1)) ;
718  sumlist1.add(asFUNC(tok)) ;
719  } else {
720  sumlist1.add(asFUNC(tok)) ;
721  }
722  tok = R__STRTOK_R(0,",",&save) ;
723  }
724 
725  } catch (const string &err) {
726  coutE(ObjectHandling) << "RooFactoryWSTool::addfunc(" << objName << ") ERROR creating RooAddition: " << err << endl ;
727  logError() ;
728  return 0 ;
729  }
730 
731  if (sumlist2.getSize()>0 && (sumlist1.getSize()!=sumlist2.getSize())) {
732  coutE(ObjectHandling) << "RooFactoryWSTool::addfunc(" << objName << ") ERROR creating RooAddition: syntax error: either all sum terms must be products or none" << endl ;
733  logError() ;
734  return 0 ;
735  }
736 
737 
738  RooAddition* sum ;
739  if (sumlist2.getSize()>0) {
740  sum = new RooAddition(objName,objName,sumlist1,sumlist2) ;
741  } else {
742  sum = new RooAddition(objName,objName,sumlist1) ;
743  }
744 
745  sum->setStringAttribute("factory_tag",Form("sum::%s(%s)",objName,specList)) ;
746  if (_ws->import(*sum,Silence())) logError() ;
747  delete sum ;
748  return (RooAddition*) _ws->pdf(objName) ;
749 
750 }
751 
752 
753 
754 
755 ////////////////////////////////////////////////////////////////////////////////
756 
757 RooProduct* RooFactoryWSTool::prodfunc(const char *objName, const char* pdfList)
758 {
759  return (RooProduct*) createArg("RooProduct",objName,Form("{%s}",pdfList)) ;
760 }
761 
762 
763 
764 
765 
766 ////////////////////////////////////////////////////////////////////////////////
767 /// Create a RooFit object from the given expression.
768 ///
769 /// <table>
770 /// <tr><th> Creating variables <th>
771 /// <tr><td> `x[-10,10]` <td> Create variable x with given range and put it in workspace
772 /// <tr><td> `x[3,-10,10]` <td> Create variable x with given range and initial value and put it in workspace
773 /// <tr><td> `x[3]` <td> Create variable x with given constant value
774 /// <tr><td> `<numeric literal>` <td> Numeric literal expressions (0.5, -3 etc..) are converted to a RooConst(<numeric literal>)
775 /// wherever a RooAbsReal or RooAbsArg argument is expected
776 /// <tr><th> Creating categories <th>
777 /// <tr><td> `c[lep,kao,nt1,nt2]` <td> Create category c with given state names
778 /// <tr><td> `tag[B0=1,B0bar=-1]` <td> Create category tag with given state names and index assignments
779 /// <tr><th> Creating functions and p.d.f.s <th>
780 /// <tr><td> `MyPdf::g(x,m,s)` <td> Create p.d.f or function of type MyPdf with name g with argument x,m,s
781 /// Interpretation and number of arguments are mapped to the constructor arguments of the class
782 /// (after the name and title).
783 /// <tr><td> `MyPdf(x,m,s)` <td> As above, but with an implicitly defined (unique) object name
784 /// <tr><th> Creating sets and lists (to be used as inputs above) <th>
785 /// <tr><td> `{a,b,c}` <td> Create RooArgSet or RooArgList (as determined by context) from given contents
786 /// </table>
787 ///
788 ///
789 /// Objects that are not created, are assumed to exist in the workspace
790 /// Object creation expressions as shown above can be nested, e.g. one can do
791 /// ```
792 /// RooGaussian::g(x[-10,10],m[0],3)
793 /// ```
794 /// to create a p.d.f and its variables in one go. This nesting can be applied recursively e.g.
795 /// ```
796 /// SUM::model( f[0.5,0,1] * RooGaussian::g( x[-10,10], m[0], 3] ),
797 /// RooChebychev::c( x, {a0[0.1],a1[0.2],a2[-0.3]} ))
798 /// ```
799 /// creates the sum of a Gaussian and a Chebychev and all its variables.
800 ///
801 ///
802 /// A seperate series of operator meta-type exists to simplify the construction of composite expressions
803 /// meta-types in all capitals (SUM) create p.d.f.s, meta types in lower case (sum) create
804 /// functions.
805 ///
806 /// <table>
807 /// <tr><th> Expression <th> Effect
808 /// <tr><td> `SUM::name(f1*pdf1,f2*pdf2,pdf3]` <td> Create sum p.d.f name with value f1*pdf1+f2*pdf2+(1-f1-f2)*pdf3
809 /// <tr><td> `RSUM::name(f1*pdf1,f2*pdf2,pdf3]` <td> Create recursive sum p.d.f. name with value f1*pdf1 + (1-f1)(f2*pdf2 + (1-f2)pdf3)
810 /// <tr><td> `ASUM::name(f1*amp1,f2*amp2,amp3]` <td> Create sum p.d.f. name with value f1*amp1+f2*amp2+(1-f1-f2)*amp3 where amplX are amplitudes of type RooAbsReal
811 /// <tr><td> `sum::name(a1,a2,a3]` <td> Create sum function with value a1+a2+a3
812 /// <tr><td> `sum::name(a1*b1,a2*b2,a3*b 3]` <td> Create sum function with value a1*b1+a2*b2+a3*b3
813 /// <tr><td> `PROD::name(pdf1,pdf2]` <td> Create product of p.d.f with 'name' with given input p.d.fs
814 /// <tr><td> `PROD::name(pdf1|x,pdf2]` <td> Create product of conditional p.d.f. pdf1 given x and pdf2
815 /// <tr><td> `prod::name(a,b,c]` <td> Create production function with value a*b*c
816 /// <tr><td> `SIMUL::name(cat,a=pdf1,b=pdf2]` <td> Create simultaneous p.d.f index category cat. Make pdf1 to state a, pdf2 to state b
817 /// <tr><td> `EXPR::name(<expr>,var,...]` <td> Create a generic p.d.f that interprets the given expression
818 /// <tr><td> `expr::name(<expr>,var,...] ` <td> Create a generic function that interprets the given expression
819 /// </table>
820 ///
821 /// The functionality of high-level object creation tools like RooSimWSTool, RooCustomizer and RooClassFactory
822 /// is also interfaced through meta-types in the factory.
823 /// <table>
824 /// <tr><th> Interface to %RooSimWSTool <th>
825 /// <tr><td> `SIMCLONE::name( modelPdf, $ParamSplit(...), $ParamSplitConstrained(...), $Restrict(...) ]`
826 /// <td> Clone-and-customize modelPdf according to ParamSplit and ParamSplitConstrained()
827 /// specifications and return a RooSimultaneous p.d.f. of all built clones
828 ///
829 /// <tr><td> `MSIMCLONE::name( masterIndex, $AddPdf(mstate1, modelPdf1, $ParamSplit(...)), $AddPdf(mstate2,modelPdf2),...) ]`
830 /// <td> Clone-and-customize multiple models (modelPdf1,modelPdf2) according to ParamSplit and
831 /// ParamSplitConstrained() specifications and return a RooSimultaneous p.d.f. of all built clones,
832 /// using the specified master index to map prototype p.d.f.s to master states
833 /// <tr><th> Interface to %RooCustomizer <th>
834 /// <tr><td> `EDIT::name( orig, substNode=origNode), ... ]` <td> Create a clone of input object orig, with the specified replacements operations executed
835 /// <tr><td> `EDIT::name( orig, origNode=$REMOVE(), ... ]` <td> Create clone of input removing term origNode from all PROD() terms that contained it
836 /// <tr><td> `EDIT::name( orig, origNode=$REMOVE(prodname,...), ... ]` <td> As above, but restrict removal of origNode to PROD term(s) prodname,...
837 ///
838 ///
839 /// <tr><th> Interface to %RooClassFactory <th>
840 /// <tr><td> `CEXPR::name(<expr>,var,...]` <td> Create a custom compiled p.d.f that evaluates the given expression
841 /// <tr><td> `cexpr::name(<expr>,var,...]` <td> Create a custom compiled function that evaluates the given expression
842 ///
843 ///
844 /// <tr><td> `$MetaType(...)` <td> Meta argument that does not result in construction of an object but is used logically organize
845 /// input arguments in certain operator p.d.f. constructions. The defined meta arguments are context dependent.
846 /// The only meta argument that is defined globally is `$Alias(typeName,aliasName)` to
847 /// define aliases for type names. For the definition of meta arguments in operator p.d.f.s
848 /// see the definitions below.
849 /// </table>
851 {
852 
853 // cout << "RooFactoryWSTool::process() " << expr << endl ;
854 
855  // First perform basic syntax check
856  if (checkSyntax(expr)) {
857  return 0 ;
858  }
859 
860  // Allocate work buffer
861  char* buf = new char[strlen(expr)+1] ;
862 
863  // Copy to buffer while absorbing white space and newlines
864  char* buftmp = buf ;
865  while(*expr) {
866  if (!isspace(*expr)) {
867  *buftmp = *expr ;
868  buftmp++ ;
869  }
870  expr++ ;
871  }
872  *buftmp=0 ;
873 
874 
875  // Clear error count and start a transaction in the workspace
876  clearError() ;
877  ws().startTransaction() ;
878 
879  // Process buffer
880  string out ;
881  try {
882  out = processExpression(buf) ;
883  } catch (const string &error) {
884  coutE(ObjectHandling) << "RooFactoryWSTool::processExpression() ERROR in parsing: " << error << endl ;
885  logError() ;
886  }
887 
888  // If there were no errors commit the transaction, cancel it otherwise
889  if (errorCount()>0) {
890  coutE(ObjectHandling) << "RooFactoryWSTool::processExpression() ERRORS detected, transaction to workspace aborted, no objects committed" << endl ;
891  ws().cancelTransaction() ;
892  } else {
893  ws().commitTransaction() ;
894  }
895 
896 
897  // Delete buffer
898  delete[] buf ;
899 
900  return out.size() ? ws().arg(out.c_str()) : 0 ;
901 }
902 
903 
904 
905 
906 ////////////////////////////////////////////////////////////////////////////////
907 /// Process a single high-level expression or list of
908 /// expressions. The returned string a the reduced expression where
909 /// all inline object creations have been executed and substituted
910 /// with the name of the created object
911 ///
912 /// e.g. 'RooGaussian::g(x,m,s)' --> 'g'
913 /// '{x(-10,10),s} --> '{x,s}'
914 
915 std::string RooFactoryWSTool::processExpression(const char* token)
916 {
917  // Delegate handling to list processor if token starts with {, otherwise
918  // call single expression processor
919  if (string(token).find("$Alias(")==0) {
920  processAliasExpression(token) ;
921  }
922 
923  if (token[0]=='{') {
924  // Process token as list if it starts with '{'
925  return processListExpression(token) ;
926  } else {
927  // Process token as single item otherwise
928  return processCompositeExpression(token) ;
929  }
930 }
931 
932 
933 
934 ////////////////////////////////////////////////////////////////////////////////
935 /// Process a single composite expression
936 ///
937 /// e.g. 'A=RooGaussian::g[x,m,s]' --> 'A=g'
938 /// e.g. 'f[0,1]*RooGaussian::g[x,m,s]' --> 'f*g'
939 /// e.g. 'RooGaussian::g(x,y,s)|x' --> g|x'
940 /// e.g. '$MetaArg(RooGaussian::g[x,m,s],blah)' --> '$MetaArg(g,blah)'
941 
942 std::string RooFactoryWSTool::processCompositeExpression(const char* token)
943 {
944  // Allocate and fill work buffer
945  const size_t bufBaseSize = strlen(token)+1;
946  char* buf_base = new char[bufBaseSize] ;
947  char* buf = buf_base ;
948  strlcpy(buf,token,bufBaseSize) ;
949  char* p = buf ;
950 
951  list<string> singleExpr ;
952  list<char> separator ;
953  Int_t blevel(0) ;
954  Bool_t litmode(kFALSE) ;
955  while(*p) {
956 
957  // Keep track of opening and closing brackets
958  if (*p=='{' || *p=='(' || *p=='[') blevel++ ;
959  if (*p=='}' || *p==')' || *p==']') blevel-- ;
960 
961  // Keep track of string literals
962  if (*p=='"' || *p=='\'') litmode = !litmode ;
963 
964  // If we are zero-bracket level and encounter a |, store
965  // the remainder of the string as suffix and exit loop
966  if (!litmode && blevel==0 && ( (*p)=='=' || (*p) == '|' || (*p) == '*')) {
967  separator.push_back(*p) ;
968  *p=0 ;
969  singleExpr.push_back(buf) ;
970  buf = p+1 ;
971  }
972  p++ ;
973  }
974  if (*buf) {
975  singleExpr.push_back(buf) ;
976  }
977  if (singleExpr.size()==1) {
978  string ret = processSingleExpression(token) ;
979  delete[] buf_base ;
980  return ret ;
981  }
982 
983  string ret ;
984  list<char>::iterator ic = separator.begin() ;
985  for (list<string>::iterator ii = singleExpr.begin() ; ii!=singleExpr.end() ; ++ii) {
986  ret += processSingleExpression(ii->c_str()) ;
987  if (ic != separator.end()) {
988  ret += *ic ;
989  ++ic ;
990  }
991  }
992 
993  delete[] buf_base ;
994  return ret ;
995 }
996 
997 
998 
999 ////////////////////////////////////////////////////////////////////////////////
1000 /// Process a single high-level expression. The returned string a the reduced
1001 /// expression where all inline object creations have been executed and substituted
1002 /// with the name of the created object
1003 ///
1004 /// e.g. 'RooGaussian::g(x,m,s)' --> 'g'
1005 /// e.g. 'x[-10,10]' --> 'x'
1006 
1007 std::string RooFactoryWSTool::processSingleExpression(const char* arg)
1008 {
1009  // Handle empty strings here
1010  if (strlen(arg)==0) {
1011  return string("") ;
1012  }
1013 
1014  // Handle string literal case
1015  if (arg[0]=='\'' || arg[0]=='"') {
1016  return string(arg) ;
1017  }
1018 
1019  // Allocate and fill work buffer
1020  const size_t bufSize = strlen(arg)+1;
1021  char* buf = new char[bufSize] ;
1022  strlcpy(buf,arg,bufSize) ;
1023  char* bufptr = buf ;
1024 
1025  string func,prefix ;
1026  vector<string> args ;
1027 
1028  // Process token into arguments
1029  char* save ;
1030  char* tmpx = R__STRTOK_R(buf,"([",&save) ;
1031  func = tmpx ? tmpx : "" ;
1032  char* p = R__STRTOK_R(0,"",&save) ;
1033 
1034  // Return here if token is fundamental
1035  if (!p) {
1036  delete[] buf ;
1037  return arg ;
1038  }
1039 
1040 
1041  char* tok = p ;
1042  Int_t blevel=0 ;
1043  Bool_t litmode(kFALSE) ;
1044  while(*p) {
1045 
1046  // Keep track of opening and closing brackets
1047  if (*p=='{' || *p=='(' || *p=='[') blevel++ ;
1048  if (*p=='}' || *p==')' || *p==']') blevel-- ;
1049 
1050  // Keep track of string literals
1051  if (*p=='"' || *p=='\'') litmode = !litmode ;
1052 
1053 
1054  // If we encounter a comma at zero bracket level
1055  // finalize the current token as a completed argument
1056  // and start the next token
1057  if (!litmode && blevel==0 && ((*p)==',')) {
1058  *p = 0 ;
1059  args.push_back(tok) ;
1060  tok = p+1 ;
1061  }
1062 
1063  p++ ;
1064  }
1065 
1066  // If the last character was a closing bracket, kill
1067  // it in the buffer
1068  if (p>bufptr && (*(p-1)==')'||*(p-1)==']')) {
1069  *(p-1)=0 ;
1070  }
1071 
1072  // Finalize last token as argument
1073  string tmp = tok ;
1074 
1075  // If there is a suffix left in the work buffer attach it to
1076  // this argument
1077  p = R__STRTOK_R(0,"",&save) ;
1078  if (p) tmp += p ;
1079  args.push_back(tmp) ;
1080 
1081  // Delete the work buffer
1082  delete[] buf ;
1083 
1084  // If function contains :: then call createArg to process this arg, otherwise
1085  // call createVariable
1086  string ret ;
1087 
1088  // Determine type of leading bracket
1089  char lb = ' ' ;
1090  for(const char* pp=arg ; *pp!=0 ; pp++) {
1091  if (*pp=='(' || *pp=='[' || *pp=='{') {
1092  lb = *pp ;
1093  break ;
1094  }
1095  }
1096 
1097  if (strstr(func.c_str(),"::")) {
1098  if (lb=='(') {
1099  // Create function argument with instance name
1100  ret= processCreateArg(func,args) ;
1101  } else {
1102  coutE(ObjectHandling) << "RooFactoryWSTool::processSingleExpression(" << arg << "): ERROR: Syntax error: Class::Instance must be followed by (...)" << endl ;
1103  logError() ;
1104  }
1105  } else if (func[0]!='$'){
1106  if (lb=='[') {
1107  // Create variable argument
1108  ret= processCreateVar(func,args) ;
1109  } else if (lb=='(') {
1110 
1111  // Create function argument with autoname
1112  string autoname ;
1113  if (!_autoNamePrefix.empty()) {
1114  // If we're inside a function creation call to a higher level object, use its
1115  // name as base for the autoname
1116  autoname = (Form("%s::%s",func.c_str(),_autoNamePrefix.top().c_str())) ;
1117  } else {
1118  // Otherwise find a free global_%d name
1119  static Int_t globCounter = 0 ;
1120  while(true) {
1121  autoname = Form("gobj%d",globCounter) ;
1122  globCounter++ ;
1123  if (!ws().arg(autoname.c_str())) {
1124  break ;
1125  }
1126  }
1127  autoname = Form("%s::%s",func.c_str(),autoname.c_str()) ;
1128  }
1129  ret= processCreateArg(autoname,args) ;
1130  } else {
1131  coutE(ObjectHandling) << "RooFactoryWSTool::processSingleExpression(" << arg << "): ERROR: Syntax error: expect either Class(...) or Instance[...]" << endl ;
1132  logError() ;
1133  }
1134  } else {
1135  if (lb=='(') {
1136  // Process meta function (compile arguments, but not meta-function itself)
1137  ret= processMetaArg(func,args) ;
1138  } else {
1139  coutE(ObjectHandling) << "RooFactoryWSTool::processSingleExpression(" << arg << "): ERROR: Syntax error: $MetaClass must be followed by (...)" << endl ;
1140  logError() ;
1141  }
1142  }
1143 
1144  // Return reduced token with suffix
1145  return ret ;
1146 }
1147 
1148 
1149 ////////////////////////////////////////////////////////////////////////////////
1150 /// Process a list of high-level expression. The returned string a the reduced
1151 /// expression list where all inline object creations have been executed and substituted
1152 /// with the name of the created object
1153 ///
1154 /// E.g. '{x(-10,10),s} --> '{x,s}'
1155 
1157 {
1158  // Allocate and fill work buffer
1159  const size_t bufSize = strlen(arg)+1;
1160  char* buf = new char[bufSize] ;
1161  strlcpy(buf,arg,bufSize) ;
1162 
1163  vector<string> args ;
1164 
1165  // Start running pointer at position 1 to skip opening bracket
1166  char* tok = buf+1 ;
1167  char* p = buf+1 ;
1168 
1169  // Processing look
1170  Int_t level(0) ;
1171  while(*p) {
1172 
1173  // Track bracketing level
1174  if (*p=='{' || *p=='(' || *p=='[') level++ ;
1175  if (*p=='}' || *p==')' || *p==']') level-- ;
1176 
1177 
1178  // If we encounter a comma at zero bracket level
1179  // finalize the current token as a completed argument
1180  // and start the next token
1181  if (level==0 && ((*p)==',')) {
1182  *p = 0 ;
1183  args.push_back(tok) ;
1184  tok = p+1 ;
1185  }
1186 
1187  p++ ;
1188  }
1189 
1190  // Finalize token as last argument
1191  if (p>buf && *(p-1)=='}') {
1192  *(p-1)=0 ;
1193  }
1194  args.push_back(tok) ;
1195 
1196  // Delete work buffer
1197  delete[] buf ;
1198 
1199  // Process each argument in list and construct reduced
1200  // expression to be returned
1201  string ret("{") ;
1202  vector<string>::iterator iter = args.begin() ;
1203  Int_t i(0) ;
1204  while(iter!= args.end()) {
1205  if (strlen(ret.c_str())>1) ret += "," ;
1206  if (!_autoNamePrefix.empty()) {
1207  _autoNamePrefix.push(Form("%s%d",_autoNamePrefix.top().c_str(),i+1)) ;
1208  }
1209  ret += processSingleExpression(iter->c_str()) ;
1210  if (!_autoNamePrefix.empty()) {
1211  _autoNamePrefix.pop() ;
1212  }
1213  ++iter ;
1214  i++ ;
1215  }
1216  ret += "}" ;
1217 
1218  return ret ;
1219 }
1220 
1221 
1222 
1223 ////////////////////////////////////////////////////////////////////////////////
1224 /// Parse token
1225 
1227 {
1228  vector<string> args = splitFunctionArgs(token) ;
1229  if (args.size()!=2) {
1230  coutE(ObjectHandling) << "RooFactorWSTool::processAliasExpression() ERROR $Alias() takes exactly two arguments, " << args.size() << " args found" << endl ;
1231  logError() ;
1232  return string() ;
1233  }
1234 
1235  // Insert alias in table
1236  _typeAliases[args[1]] = args[0] ;
1237 
1238  return string() ;
1239 }
1240 
1241 
1242 
1243 
1244 ////////////////////////////////////////////////////////////////////////////////
1245 
1247 {
1248  // First do recursive alias expansion
1249  while (true) {
1250  map<string,string>::iterator item = _typeAliases.find(className) ;
1251 
1252  // If an alias is found, recurse
1253  if (item != _typeAliases.end()) {
1254  className = item->second.c_str() ;
1255  } else {
1256  break ;
1257  }
1258  }
1259 
1260  // Now find dealiased class in ROOT class table
1261  TClass* tc = TClass::GetClass(className,kTRUE,kTRUE) ;
1262 
1263  // If its not there, try prefixing with Roo
1264  if (!tc) {
1265  tc = TClass::GetClass(Form("Roo%s",className)) ;
1266  if (!tc) {
1267  coutE(ObjectHandling) << "RooFactoryWSTool::createArg() ERROR class " << className << " not defined in ROOT class table" << endl ;
1268  logError() ;
1269  return 0 ;
1270  }
1271  }
1272  return tc ;
1273 }
1274 
1275 
1276 
1277 ////////////////////////////////////////////////////////////////////////////////
1278 
1279 string RooFactoryWSTool::varTag(string& func, vector<string>& args)
1280 {
1281  string ret ;
1282  ret += func ;
1283  ret += "[" ;
1284  for (vector<string>::iterator iter = args.begin() ; iter!=args.end() ; ++iter) {
1285  if (iter!=args.begin()) {
1286  ret += "," ;
1287  }
1288  ret += *iter ;
1289  }
1290  ret += "]" ;
1291  return ret ;
1292 }
1293 
1294 
1295 
1296 
1297 ////////////////////////////////////////////////////////////////////////////////
1298 /// Glue function between high-level syntax and low-level factory call to createVariable:
1299 /// Process a parsed call to create a variable named 'func'
1300 ///
1301 /// If initial token is non-numeric, a RooCategory will be created, and the args are interpreted
1302 /// as either state names or 'name=id' assignments. Otherwise a RooRealvar is created and the
1303 /// arg list is interpreted as follows:
1304 /// If list has two args, these are interpreted as xmin,xmax
1305 /// If list has three args, these are interpreted as xinit,xmin,xmax
1306 /// If list has one arg, this is interpreted as xinit and the variable is set as constant
1307 
1308 string RooFactoryWSTool::processCreateVar(string& func, vector<string>& args)
1309 {
1310 
1311  // Determine if first arg is numeric
1312  string first = *(args.begin()) ;
1313  if (isdigit(first[0]) || first[0]=='.' || first[0]=='+' || first[0]=='-') {
1314 
1315  // Create a RooRealVar
1316  vector<string>::iterator ai = args.begin() ;
1317  if (args.size()==1) {
1318 
1319  // One argument, create constant variable with given value
1320  Double_t xinit = atof((ai)->c_str()) ;
1321  cxcoutD(ObjectHandling) << "CREATE variable " << func << " xinit = " << xinit << endl ;
1322  RooRealVar tmp(func.c_str(),func.c_str(),xinit) ;
1323  tmp.setStringAttribute("factory_tag",varTag(func,args).c_str()) ;
1324  if (_ws->import(tmp,Silence())) {
1325  logError() ;
1326  }
1327 
1328  } else if (args.size()==2) {
1329 
1330  // Two arguments, create variable with given range
1331  Double_t xlo = atof((ai++)->c_str()) ;
1332  Double_t xhi = atof(ai->c_str()) ;
1333  cxcoutD(ObjectHandling) << "CREATE variable " << func << " xlo = " << xlo << " xhi = " << xhi << endl ;
1334  RooRealVar tmp(func.c_str(),func.c_str(),xlo,xhi) ;
1335  tmp.setStringAttribute("factory_tag",varTag(func,args).c_str()) ;
1336  if (_ws->import(tmp,Silence())) {
1337  logError() ;
1338  }
1339 
1340  } else if (args.size()==3) {
1341 
1342  // Three arguments, create variable with given initial value and range
1343  Double_t xinit = atof((ai++)->c_str()) ;
1344  Double_t xlo = atof((ai++)->c_str()) ;
1345  Double_t xhi = atof(ai->c_str()) ;
1346  cxcoutD(ObjectHandling) << "CREATE variable " << func << " xinit = " << xinit << " xlo = " << xlo << " xhi = " << xhi << endl ;
1347  RooRealVar tmp(func.c_str(),func.c_str(),xinit,xlo,xhi) ;
1348  tmp.setStringAttribute("factory_tag",varTag(func,args).c_str()) ;
1349  if (_ws->import(tmp,Silence())) {
1350  logError() ;
1351  }
1352  }
1353  } else {
1354 
1355  // Create a RooAbsCategory
1356  string allStates ;
1357  for (vector<string>::iterator ai = args.begin() ; ai!=args.end() ; ++ai) {
1358  if (allStates.size()>0) {
1359  allStates += "," ;
1360  }
1361  allStates += *ai ;
1362  }
1363  createCategory(func.c_str(),allStates.c_str()) ;
1364 
1365  }
1366  return func ;
1367 }
1368 
1369 
1370 ////////////////////////////////////////////////////////////////////////////////
1371 /// Glue function between high-level syntax and low-level factory call to createArg:
1372 /// Process a parsed call to create a p.d.f named func
1373 ///
1374 /// The func arg is interpreted as ClassName::ObjectName and the arglist is passed
1375 /// verbatim to createArg. The received arglist is expected to be fully reduced (i.e.
1376 /// all inline object creations must have been compiled)
1377 
1378 string RooFactoryWSTool::processCreateArg(string& func, vector<string>& args)
1379 {
1380  // Allocate and fill work buffer
1381  char buf[BUFFER_SIZE] ;
1382  strlcpy(buf,func.c_str(),BUFFER_SIZE) ;
1383 
1384  // Split function part in class name and instance name
1385  char* save ;
1386  const char *className = R__STRTOK_R(buf,":",&save) ;
1387  const char *instName = R__STRTOK_R(0,":",&save) ;
1388  if (!className) className = "";
1389  if (!instName) instName = "" ;
1390 
1391  // Concatenate list of args into comma separated string
1392  char pargs[BUFFER_SIZE] ;
1393  pargs[0] = 0 ;
1394  vector<string>::iterator iter = args.begin() ;
1395  vector<string> pargv ;
1396  Int_t iarg(0) ;
1397  while(iter!=args.end()) {
1398  if (strlen(pargs)>0) strlcat(pargs,",",BUFFER_SIZE) ;
1399  _autoNamePrefix.push(Form("%s_%d",instName,iarg+1)) ;
1400  string tmp = processExpression(iter->c_str()) ;
1401  _autoNamePrefix.pop() ;
1402  strlcat(pargs,tmp.c_str(),BUFFER_SIZE) ;
1403  pargv.push_back(tmp) ;
1404  ++iter ;
1405  iarg++ ;
1406  }
1407 
1408  // Look up if func is a special
1409  for (map<string,IFace*>::iterator ii=hooks().begin() ; ii!=hooks().end() ; ++ii) {
1410  }
1411  if (hooks().find(className) != hooks().end()) {
1412  IFace* iface = hooks()[className] ;
1413  return iface->create(*this, className,instName,pargv) ;
1414  }
1415 
1416  createArg(className,instName,pargs) ;
1417 
1418  return string(instName) ;
1419 }
1420 
1421 
1422 
1423 ////////////////////////////////////////////////////////////////////////////////
1424 /// Concatenate list of args into comma separated string
1425 
1426 std::string RooFactoryWSTool::processMetaArg(std::string& func, std::vector<std::string>& args)
1427 {
1428  char pargs[BUFFER_SIZE] ;
1429  pargs[0] = 0 ;
1430  vector<string>::iterator iter = args.begin() ;
1431  vector<string> pargv ;
1432  while(iter!=args.end()) {
1433  if (strlen(pargs)>0) strlcat(pargs,",",BUFFER_SIZE) ;
1434  string tmp = processExpression(iter->c_str()) ;
1435  strlcat(pargs,tmp.c_str(),BUFFER_SIZE) ;
1436  pargv.push_back(tmp) ;
1437  ++iter ;
1438  }
1439 
1440  string ret = func+"("+pargs+")" ;
1441  return ret ;
1442 }
1443 
1444 
1445 
1446 
1447 ////////////////////////////////////////////////////////////////////////////////
1448 /// Allocate and fill work buffer
1449 
1450 vector<string> RooFactoryWSTool::splitFunctionArgs(const char* funcExpr)
1451 {
1452  const size_t bufSize = strlen(funcExpr)+1;
1453  char* buf = new char[bufSize] ;
1454  strlcpy(buf,funcExpr,bufSize) ;
1455  char* bufptr = buf ;
1456 
1457  string func ;
1458  vector<string> args ;
1459 
1460  // Process token into arguments
1461  char* save ;
1462  char* tmpx = R__STRTOK_R(buf,"(",&save) ;
1463  func = tmpx ? tmpx : "" ;
1464  char* p = R__STRTOK_R(0,"",&save) ;
1465 
1466  // Return here if token is fundamental
1467  if (!p) {
1468  delete[] buf ;
1469  return args ;
1470  }
1471 
1472  char* tok = p ;
1473  Int_t blevel=0 ;
1474  Bool_t litmode(kFALSE) ;
1475  while(*p) {
1476 
1477  // Keep track of opening and closing brackets
1478  if (*p=='{' || *p=='(' || *p=='[') blevel++ ;
1479  if (*p=='}' || *p==')' || *p==']') blevel-- ;
1480 
1481  // Keep track of string literals
1482  if (*p=='"' || *p=='\'') litmode = !litmode ;
1483 
1484 
1485  // If we encounter a comma at zero bracket level
1486  // finalize the current token as a completed argument
1487  // and start the next token
1488  if (!litmode && blevel==0 && ((*p)==',')) {
1489  *p = 0 ;
1490  args.push_back(tok) ;
1491  tok = p+1 ;
1492  }
1493 
1494  p++ ;
1495  }
1496 
1497  // If the last character was a closing bracket, kill
1498  // it in the buffer
1499  if (p>bufptr && *(p-1)==')') {
1500  *(p-1)=0 ;
1501  }
1502 
1503  // Finalize last token as argument
1504  string tmp = tok ;
1505 
1506  // If there is a suffix left in the work buffer attach it to
1507  // this argument
1508  p = R__STRTOK_R(0,"",&save) ;
1509  if (p) tmp += p ;
1510  args.push_back(tmp) ;
1511 
1512  // Delete the work buffer
1513  delete[] buf ;
1514 
1515  return args ;
1516 }
1517 
1518 
1519 
1520 
1521 
1522 ////////////////////////////////////////////////////////////////////////////////
1523 /// Perform basic syntax on given factory expression. If function returns
1524 /// true syntax errors are found.
1525 
1527 {
1528  // Count parentheses
1529  Int_t nParentheses(0), nBracket(0), nAccolade(0) ;
1530  const char* ptr = arg ;
1531  while(*ptr) {
1532  if (*ptr=='(') nParentheses++ ;
1533  if (*ptr==')') nParentheses-- ;
1534  if (*ptr=='[') nBracket++ ;
1535  if (*ptr==']') nBracket-- ;
1536  if (*ptr=='{') nAccolade++ ;
1537  if (*ptr=='}') nAccolade-- ;
1538  ptr++ ;
1539  }
1540  if (nParentheses!=0) {
1541  coutE(ObjectHandling) << "RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nParentheses>0?"(":")") << "' in expression" << endl ;
1542  return kTRUE ;
1543  }
1544  if (nBracket!=0) {
1545  coutE(ObjectHandling) << "RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nBracket>0?"[":"]") << "' in expression" << endl ;
1546  return kTRUE ;
1547  }
1548  if (nAccolade!=0) {
1549  coutE(ObjectHandling) << "RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nAccolade>0?"{":"}") << "' in expression" << endl ;
1550  return kTRUE ;
1551  }
1552  return kFALSE ;
1553 }
1554 
1555 
1556 
1557 ////////////////////////////////////////////////////////////////////////////////
1558 
1560 {
1561  if (idx>_of->_args.size()-1) {
1562  throw string(Form("Need argument number %d, but only %d args are provided",idx,(Int_t)_of->_args.size())) ;
1563  }
1564 }
1565 
1566 
1567 
1568 ////////////////////////////////////////////////////////////////////////////////
1569 /// CINT constructor interface, return constructor string argument #idx as RooAbsArg reference found in workspace
1570 
1572  {
1573  // If arg is a numeric string, make a RooConst() of it here
1574  if (arg[0]=='.' || arg[0]=='+' || arg[0] == '-' || isdigit(arg[0])) {
1575  return RooConst(atof(arg)) ;
1576  }
1577 
1578  // Otherwise look it up by name in the workspace
1579  RooAbsArg* rarg = ws().arg(arg) ;
1580  if (!rarg) {
1581  throw string(Form("RooAbsArg named %s not found",arg)) ;
1582  }
1583  return *rarg ;
1584 }
1585 
1586 
1587 
1588 ////////////////////////////////////////////////////////////////////////////////
1589 /// CINT constructor interface, return constructor string argument #idx as RooAbsReal reference found in workspace
1590 
1592 {
1593  // If arg is a numeric string, make a RooConst() of it here
1594  if (arg[0]=='.' || arg[0]=='+' || arg[0] == '-' || isdigit(arg[0])) {
1595  return RooConst(atof(arg)) ;
1596  }
1597 
1598  RooAbsArg* rarg = ws().arg(arg) ;
1599  if (!rarg) {
1600  throw string(Form("RooAbsReal named %s not found",arg)) ;
1601  }
1602  RooAbsReal* real = dynamic_cast<RooAbsReal*>(rarg) ;
1603  if (!real) {
1604  throw string(Form("Object named %s is not of type RooAbsReal",arg)) ;
1605  }
1606  return *real ;
1607 }
1608 
1609 
1610 
1611 ////////////////////////////////////////////////////////////////////////////////
1612 /// CINT constructor interface, return constructor string argument #idx as RooAbsRealLValue reference found in workspace
1613 
1615 {
1616  // If arg is a numeric string, throw error as lvalue is required
1617  if (arg[0]=='.' || arg[0]=='+' || arg[0] == '-' || isdigit(arg[0])) {
1618  throw string(Form("Numeric literal provided for argument (%s), but lvalue is required",arg)) ;
1619  }
1620 
1621  RooAbsArg* rarg = ws().arg(arg) ;
1622  if (!rarg) {
1623  throw string(Form("RooAbsRealLValue named %s not found",arg)) ;
1624  }
1625  RooAbsRealLValue* reallv = dynamic_cast<RooAbsRealLValue*>(rarg) ;
1626  if (!reallv) {
1627  throw string(Form("Object named %s is not of type RooAbsRealLValue",arg)) ;
1628  }
1629  return *reallv ;
1630 }
1631 
1632 
1633 
1634 ////////////////////////////////////////////////////////////////////////////////
1635 /// CINT constructor interface, return constructor string argument #idx as RooRealVar reference found in workspace
1636 
1638 {
1639  RooRealVar* var = ws().var(arg) ;
1640  if (!var) {
1641  throw string(Form("RooRealVar named %s not found",arg)) ;
1642  }
1643  return *var ;
1644 }
1645 
1646 
1647 
1648 
1649 ////////////////////////////////////////////////////////////////////////////////
1650 /// CINT constructor interface, return constructor string argument #idx as RooAbsPdf reference found in workspace
1651 
1653 {
1654  RooAbsPdf* pdf = ws().pdf(arg) ;
1655  if (!pdf) {
1656  throw string(Form("RooAbsPdf named %s not found",arg)) ;
1657  }
1658  return *pdf ;
1659 }
1660 
1661 
1662 
1663 
1664 ////////////////////////////////////////////////////////////////////////////////
1665 /// CINT constructor interface, return constructor string argument #idx as RooResolutionModel reference found in workspace
1666 
1668 {
1669  RooAbsArg* rarg = ws().arg(arg) ;
1670  if (!rarg) {
1671  throw string(Form("RooResolutionModel named %s not found",arg)) ;
1672  }
1673  RooResolutionModel * rmodel = dynamic_cast<RooResolutionModel*>(rarg) ;
1674  if (!rmodel) {
1675  throw string(Form("Object named %s is not of type RooResolutionModel",arg)) ;
1676  }
1677  return *rmodel ;
1678 }
1679 
1680 
1681 
1682 
1683 ////////////////////////////////////////////////////////////////////////////////
1684 /// CINT constructor interface, return constructor string argument #idx as RooAbsCategory reference found in workspace
1685 
1687 {
1688  RooAbsArg* rarg = ws().arg(arg) ;
1689  if (!rarg) {
1690  throw string(Form("RooAbsCategory named %s not found",arg)) ;
1691  }
1692  RooAbsCategory* catf = dynamic_cast<RooAbsCategory*>(rarg) ;
1693  if (!catf) {
1694  throw string(Form("Object named %s is not of type RooAbsCategory",arg)) ;
1695  }
1696  return *catf ;
1697 }
1698 
1699 
1700 
1701 ////////////////////////////////////////////////////////////////////////////////
1702 /// CINT constructor interface, return constructor string argument #idx as RooAbsCategoryLValue reference found in workspace
1703 
1705 {
1706  RooAbsArg* rarg = ws().arg(arg) ;
1707  if (!rarg) {
1708  throw string(Form("RooAbsCategoryLValue named %s not found",arg)) ;
1709  }
1710 
1711  RooAbsCategoryLValue* catlv = dynamic_cast<RooAbsCategoryLValue*>(rarg) ;
1712  if (!catlv) {
1713  throw string(Form("Object named %s is not of type RooAbsCategoryLValue",arg)) ;
1714  }
1715  return *catlv ;
1716 }
1717 
1718 
1719 
1720 ////////////////////////////////////////////////////////////////////////////////
1721 /// CINT constructor interface, return constructor string argument #idx as RooCategory reference found in workspace
1722 
1724 {
1725  RooCategory* cat = ws().cat(arg) ;
1726  if (!cat) {
1727  throw string(Form("RooCategory named %s not found",arg)) ;
1728  }
1729  return *cat ;
1730 }
1731 
1732 
1733 
1734 
1735 
1736 ////////////////////////////////////////////////////////////////////////////////
1737 /// CINT constructor interface, return constructor string argument #idx as RooArgSet of objects found in workspace
1738 
1740 {
1741  char tmp[BUFFER_SIZE] ;
1742  strlcpy(tmp,arg,BUFFER_SIZE) ;
1743 
1744  RooArgSet s ;
1745 
1746  // If given object is not of {,,,} form, interpret given string as name of defined set
1747  if (arg[0]!='{') {
1748  // cout << "asSet(arg='" << arg << "') parsing as defined set" << endl ;
1749  const RooArgSet* defSet = ws().set(arg) ;
1750  if (defSet) {
1751  // cout << "found defined set: " << *defSet << endl ;
1752  s.add(*defSet) ;
1753  return s ;
1754  }
1755  }
1756 
1757  char* save ;
1758  char* tok = R__STRTOK_R(tmp,",{}",&save) ;
1759  int i(0);
1760  while(tok) {
1761 
1762  // If arg is a numeric string, make a RooConst() of it here
1763  if (tok[0]=='.' || tok[0]=='+' || tok[0] == '-' || isdigit(tok[0])) {
1764  s.add(RooConst(atof(tok))) ;
1765  } else if (tok[0] == '\'') {
1766  tok[strlen(tok) - 1] = 0;
1767  RooStringVar *sv = new RooStringVar(Form("string_set_item%03d", i++), "string_set_item", tok + 1);
1768  s.add(*sv);
1769  } else {
1770  RooAbsArg* aarg = ws().arg(tok) ;
1771  if (aarg) {
1772  s.add(*aarg) ;
1773  } else {
1774  throw string(Form("RooAbsArg named %s not found",tok)) ;
1775  }
1776  }
1777  tok = R__STRTOK_R(0,",{}",&save) ;
1778  }
1779 
1780  return s ;
1781 }
1782 
1783 
1784 
1785 ////////////////////////////////////////////////////////////////////////////////
1786 /// CINT constructor interface, return constructor string argument #idx as RooArgList of objects found in workspace
1787 
1789 {
1790  char tmp[BUFFER_SIZE] ;
1791  strlcpy(tmp,arg,BUFFER_SIZE) ;
1792 
1793  RooArgList l ;
1794  char* save ;
1795  char* tok = R__STRTOK_R(tmp,",{}",&save) ;
1796  while(tok) {
1797 
1798  // If arg is a numeric string, make a RooConst() of it here
1799  if (tok[0]=='.' || tok[0]=='+' || tok[0] == '-' || isdigit(tok[0])) {
1800  l.add(RooConst(atof(tok))) ;
1801  } else if (tok[0] == '\'') {
1802  tok[strlen(tok) - 1] = 0;
1803  RooStringVar *sv = new RooStringVar("listarg", "listarg", tok + 1);
1804  l.add(*sv);
1805  } else {
1806  RooAbsArg* aarg = ws().arg(tok) ;
1807  if (aarg) {
1808  l.add(*aarg) ;
1809  } else {
1810  throw string(Form("RooAbsArg named %s not found",tok)) ;
1811  }
1812  }
1813  tok = R__STRTOK_R(0,",{}",&save) ;
1814  }
1815 
1816  return l ;
1817 }
1818 
1819 
1820 
1821 ////////////////////////////////////////////////////////////////////////////////
1822 /// CINT constructor interface, return constructor string argument #idx as RooAbsData object found in workspace
1823 
1825 {
1826  RooAbsData* data = ws().data(arg) ;
1827  if (!data) {
1828  throw string(Form("RooAbsData named %s not found",arg)) ;
1829  }
1830  return *data ;
1831 }
1832 
1833 
1834 
1835 ////////////////////////////////////////////////////////////////////////////////
1836 /// CINT constructor interface, return constructor string argument #idx as RooDataHist object found in workspace
1837 
1839 {
1840  RooAbsData* data = ws().data(arg) ;
1841  if (!data) {
1842  throw string(Form("RooAbsData named %s not found",arg)) ;
1843  }
1844  RooDataHist* hist = dynamic_cast<RooDataHist*>(data) ;
1845  if (!hist) {
1846  throw string(Form("Dataset named %s is not of type RooDataHist",arg)) ;
1847  }
1848  return *hist ;
1849 }
1850 
1851 
1852 ////////////////////////////////////////////////////////////////////////////////
1853 /// CINT constructor interface, return constructor string argument #idx as RooDataSet object found in workspace
1854 
1856 {
1857  RooAbsData* data = ws().data(arg) ;
1858  if (!data) {
1859  throw string(Form("RooAbsData named %s not found",arg)) ;
1860  }
1861  RooDataSet* dset = dynamic_cast<RooDataSet*>(data) ;
1862  if (!dset) {
1863  throw string(Form("Dataset named %s is not of type RooDataSet",arg)) ;
1864  }
1865  return *dset ;
1866 }
1867 
1868 
1869 
1870 ////////////////////////////////////////////////////////////////////////////////
1871 
1873 {
1874  TObject* obj = ws().obj(arg) ;
1875  if (!obj) {
1876  throw string(Form("Object named %s not found",arg)) ;
1877  }
1878  return *obj ;
1879 }
1880 
1881 
1882 
1883 ////////////////////////////////////////////////////////////////////////////////
1884 /// CINT constructor interface, return constructor string argument #idx as const char*
1885 
1886 const char* RooFactoryWSTool::asSTRING(const char* arg)
1887 {
1888  static vector<string> cbuf(10) ;
1889  static unsigned int cbuf_idx = 0 ;
1890 
1891  // Handle empty string case: return null pointer
1892  if (arg==0 || strlen(arg)==0) {
1893  return 0 ;
1894  }
1895 
1896  // Fill cyclical buffer entry with quotation marked stripped version of string literal
1897  // and return pointer to stripped buffer
1898  cbuf[cbuf_idx].clear() ;
1899  const char* p = arg+1 ;
1900  while(*p && (*p) != '"' && (*p) !='\'' ) {
1901  cbuf[cbuf_idx] += *(p++) ;
1902  }
1903  const char* ret = cbuf[cbuf_idx].c_str() ;
1904 
1905  // Increment buffer pointer by one
1906  cbuf_idx++ ;
1907  if (cbuf_idx==cbuf.size()) cbuf_idx=0 ;
1908 
1909  return ret ;
1910 }
1911 
1912 
1913 ////////////////////////////////////////////////////////////////////////////////
1914 /// CINT constructor interface, return constructor string argument #idx as Int_t
1915 
1917 {
1918  return atoi(arg) ;
1919 }
1920 
1921 
1922 ////////////////////////////////////////////////////////////////////////////////
1923 /// CINT constructor interface, return constructor string argument #idx as Double_t
1924 
1926 {
1927  return atof(arg) ;
1928 }
1929 
1930 
1931 ////////////////////////////////////////////////////////////////////////////////
1932 /// Register foreign special objects in factory
1933 
1935 {
1936  hooks()[typeName] = iface ;
1937 }
1938 
1939 
1940 
1941 ////////////////////////////////////////////////////////////////////////////////
1942 
1943 std::map<std::string,RooFactoryWSTool::IFace*>& RooFactoryWSTool::hooks()
1944 {
1945  if (_hooks) return *_hooks ;
1946  _hooks = new map<string,IFace*> ;
1947  return *_hooks ;
1948 }
1949 
1950 
1951 
1952 ////////////////////////////////////////////////////////////////////////////////
1953 /// Concatenate list of args into comma separated string
1954 
1955 std::string RooFactoryWSTool::SpecialsIFace::create(RooFactoryWSTool& ft, const char* typeName, const char* instName, std::vector<std::string> args)
1956 {
1957  char pargs[BUFFER_SIZE] ;
1958  pargs[0] = 0 ;
1959  vector<string>::iterator iter = args.begin() ;
1960  vector<string> pargv ;
1961  while(iter!=args.end()) {
1962  if (strlen(pargs)>0) strlcat(pargs,",",BUFFER_SIZE) ;
1963  string tmp = ft.processExpression(iter->c_str()) ;
1964  strlcat(pargs,tmp.c_str(),BUFFER_SIZE) ;
1965  pargv.push_back(tmp) ;
1966  ++iter ;
1967  }
1968 
1969  // Handling of special operator pdf class names
1970  string cl(typeName) ;
1971  if (cl=="SUM") {
1972 
1973  // SUM::name[a*A,b*B,C]
1974  ft.add(instName,pargs,kFALSE) ;
1975 
1976  } else if (cl=="RSUM") {
1977 
1978  // RSUM::name[a*A,b*B,C]
1979  ft.add(instName,pargs,kTRUE) ;
1980 
1981  } else if (cl=="ASUM") {
1982 
1983  // ASUM::name[a*A,b*B,C]
1984  ft.amplAdd(instName,pargs) ;
1985 
1986  } else if (cl=="PROD") {
1987 
1988  // PROD::name[A,B,C]
1989  ft.prod(instName,pargs) ;
1990 
1991  } else if (cl=="SIMUL") {
1992 
1993  // PROD::name[cat,state=Pdf,...]
1994  if (pargv.size()>1) {
1995  ft.simul(instName,pargv[0].c_str(),strchr(pargs,',')+1) ;
1996  } else {
1997  throw string(Form("Need at least two arguments in call to SIMUL::%s, have %d: %s",instName,(Int_t)pargv.size(),pargs)) ;
1998  }
1999 
2000  } else if (cl=="EXPR") {
2001 
2002  // EXPR::name['expr',var,var,...]
2003  if (args.size()<=2) {
2004  ft.createArg("RooGenericPdf",instName,pargs) ;
2005  } else {
2006  char genargs[BUFFER_SIZE] ;
2007  strlcpy(genargs,args[0].c_str(),BUFFER_SIZE) ;
2008  strlcat(genargs,",{",BUFFER_SIZE) ;
2009  for (UInt_t i=1 ; i<args.size() ; i++) {
2010  if (i!=1) strlcat(genargs,",",BUFFER_SIZE) ;
2011  strlcat(genargs,args[i].c_str(),BUFFER_SIZE) ;
2012  }
2013  strlcat(genargs,"}",BUFFER_SIZE) ;
2014  ft.createArg("RooGenericPdf",instName,genargs) ;
2015  }
2016 
2017  } else if (cl=="FCONV") {
2018 
2019  // FCONV::name[var,pdf1,pdf2]
2020  ft.createArg("RooFFTConvPdf",instName,pargs) ;
2021 
2022  } else if (cl=="NCONV") {
2023 
2024  // NCONV::name[var,pdf1,pdf2]
2025  ft.createArg("RooNumConvPdf",instName,pargs) ;
2026 
2027  } else if (cl=="sum") {
2028 
2029  // sum::name[a,b,c]
2030  ft.addfunc(instName,pargs) ;
2031 
2032  } else if (cl=="prod") {
2033 
2034  // prod::name[a,b,c]
2035  ft.prodfunc(instName,pargs) ;
2036 
2037  } else if (cl=="expr") {
2038 
2039  // expr::name['expr',var,var,...]
2040  if (args.size()<=2) {
2041  ft.createArg("RooFormulaVar",instName,pargs) ;
2042  } else {
2043  char genargs[BUFFER_SIZE] ;
2044  strlcpy(genargs,args[0].c_str(),BUFFER_SIZE) ;
2045  strlcat(genargs,",{",BUFFER_SIZE) ;
2046  for (UInt_t i=1 ; i<args.size() ; i++) {
2047  if (i!=1) strlcat(genargs,",",BUFFER_SIZE) ;
2048  strlcat(genargs,args[i].c_str(),BUFFER_SIZE) ;
2049  }
2050  strlcat(genargs,"}",BUFFER_SIZE) ;
2051  ft.createArg("RooFormulaVar",instName,genargs) ;
2052  }
2053 
2054  } else if (cl=="nconv") {
2055 
2056  // nconv::name[var,pdf1,pdf2]
2057  ft.createArg("RooNumConvolution",instName,pargs) ;
2058 
2059  } else if (cl=="nll") {
2060 
2061  // nll::name[pdf,data]
2062  RooNLLVar nll(instName,instName,ft.asPDF(pargv[0].c_str()),ft.asDATA(pargv[1].c_str())) ;
2063  if (ft.ws().import(nll,Silence())) ft.logError() ;
2064 
2065  } else if (cl=="chi2") {
2066 
2067  // chi2::name[pdf,data]
2068  RooChi2Var nll(instName,instName,ft.asPDF(pargv[0].c_str()),ft.asDHIST(pargv[1].c_str())) ;
2069  if (ft.ws().import(nll,Silence())) ft.logError() ;
2070 
2071  } else if (cl=="profile") {
2072 
2073  // profile::name[func,vars]
2074  ft.createArg("RooProfileLL",instName,pargs) ;
2075 
2076  } else if (cl=="dataobs") {
2077 
2078  // dataobs::name[dset,func]
2079  RooAbsArg* funcClone = static_cast<RooAbsArg*>(ft.asARG(pargv[1].c_str()).clone(instName)) ;
2080  RooAbsArg* arg = ft.asDSET(pargv[0].c_str()).addColumn(*funcClone) ;
2081  if (!ft.ws().fundArg(arg->GetName())) {
2082  if (ft.ws().import(*arg,Silence())) ft.logError() ;
2083  }
2084  delete funcClone ;
2085 
2086  } else if (cl=="int") {
2087 
2088  // int::name[func,intobs]
2089  // int::name[func,intobs|range]
2090  // int::name[func,intobs,normobs]
2091  // int::name[func,intobs|range,normobs]
2092 
2093  if (pargv.size()<2 || pargv.size()>3) {
2094  throw string(Form("int::%s, requires 2 or 3 arguments, have %d arguments",instName,(Int_t)pargv.size())) ;
2095  }
2096 
2097  RooAbsReal& func = ft.asFUNC(pargv[0].c_str()) ;
2098 
2099  char buf[256] ;
2100  strlcpy(buf,pargv[1].c_str(),256) ;
2101  char* save ;
2102  const char* intobs = R__STRTOK_R(buf,"|",&save) ;
2103  if (!intobs) intobs="" ;
2104 
2105  const char* range = R__STRTOK_R(0,"",&save) ;
2106  if (!range) range="" ;
2107 
2108  RooAbsReal* integral = 0 ;
2109  if (pargv.size()==2) {
2110  if (range && strlen(range)) {
2111  integral = func.createIntegral(ft.asSET(intobs),Range(range)) ;
2112  } else {
2113  integral = func.createIntegral(ft.asSET(intobs)) ;
2114  }
2115  } else {
2116  if (range && strlen(range)) {
2117  integral = func.createIntegral(ft.asSET(intobs),Range(range),NormSet(ft.asSET(pargv[2].c_str()))) ;
2118  } else {
2119  integral = func.createIntegral(ft.asSET(intobs),NormSet(ft.asSET(pargv[2].c_str()))) ;
2120  }
2121  }
2122 
2123  integral->SetName(instName) ;
2124  if (ft.ws().import(*integral,Silence())) ft.logError() ;
2125 
2126  } else if (cl=="deriv") {
2127 
2128  // derive::name[func,obs,order]
2129 
2130  if (pargv.size()<2 || pargv.size()>3) {
2131  throw string(Form("deriv::%s, requires 2 or 3 arguments, have %d arguments",instName,(Int_t)pargv.size())) ;
2132  }
2133 
2134  RooAbsReal& func = ft.asFUNC(pargv[0].c_str()) ;
2135 
2136  RooAbsReal* derivative(0) ;
2137  if (pargv.size()==2) {
2138  derivative = func.derivative(ft.asVAR(pargv[1].c_str()),1) ;
2139  } else {
2140  derivative = func.derivative(ft.asVAR(pargv[1].c_str()),ft.asINT(pargv[2].c_str())) ;
2141  }
2142 
2143  derivative->SetName(instName) ;
2144  if (ft.ws().import(*derivative,Silence())) ft.logError() ;
2145 
2146  } else if (cl=="cdf") {
2147 
2148  // cdf::name[pdf,obs,extranormobs]
2149 
2150  if (pargv.size()<2 || pargv.size()>3) {
2151  throw string(Form("cdf::%s, requires 2 or 3 arguments, have %d arguments",instName,(Int_t)pargv.size())) ;
2152  }
2153 
2154  RooAbsPdf& pdf = ft.asPDF(pargv[0].c_str()) ;
2155 
2156  RooAbsReal* cdf(0) ;
2157  if (pargv.size()==2) {
2158  cdf = pdf.createCdf(ft.asSET(pargv[1].c_str())) ;
2159  } else {
2160  cdf = pdf.createCdf(ft.asSET(pargv[1].c_str()),ft.asSET(pargv[2].c_str())) ;
2161  }
2162 
2163  cdf->SetName(instName) ;
2164  if (ft.ws().import(*cdf,Silence())) ft.logError() ;
2165 
2166 
2167  } else if (cl=="PROJ") {
2168 
2169  // PROJ::name(pdf,intobs)
2170  if (pargv.size()!=2) {
2171  throw string(Form("PROJ::%s, requires 2 arguments, have %d arguments",instName,(Int_t)pargv.size())) ;
2172  }
2173 
2174  RooAbsPdf& pdf = ft.asPDF(pargv[0].c_str()) ;
2175  RooAbsPdf* projection = pdf.createProjection(ft.asSET(pargv[1].c_str())) ;
2176  projection->SetName(instName) ;
2177 
2178  if (ft.ws().import(*projection,Silence())) ft.logError() ;
2179 
2180  } else if (cl=="set") {
2181 
2182  // set::name(arg,arg,...)
2183  if (ft.ws().defineSet(instName,pargs)) {
2184  ft.logError() ;
2185  return string(instName) ;
2186  }
2187 
2188  } else {
2189 
2190  throw string(Form("RooFactoryWSTool::SpecialsIFace::create() ERROR: Unknown meta-type %s",typeName)) ;
2191 
2192  }
2193  return string(instName) ;
2194 }
2195 
2196 
2198 {
2199  return _of ;
2200 }
2201 
RooFactoryWSTool::asRMODEL
RooResolutionModel & asRMODEL(const char *)
CINT constructor interface, return constructor string argument #idx as RooResolutionModel reference f...
Definition: RooFactoryWSTool.cxx:1667
RooWorkspace::data
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
Definition: RooWorkspace.cxx:1368
RooFactoryWSTool::processAliasExpression
std::string processAliasExpression(const char *arg)
Parse token.
Definition: RooFactoryWSTool.cxx:1226
l
auto * l
Definition: textangle.C:4
ROOT::TMetaUtils::propNames::separator
static const std::string separator("@@@")
RooWorkspace.h
RooFactoryWSTool::as_DOUBLE
static Double_t as_DOUBLE(UInt_t idx)
Definition: RooFactoryWSTool.h:110
RooFactoryWSTool::asDATA
RooAbsData & asDATA(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsData object found in wor...
Definition: RooFactoryWSTool.cxx:1824
first
Definition: first.py:1
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooStringVar.h
RooAbsReal.h
Range
Ta Range(0, 0, 1, 1)
RooFactoryWSTool::process
RooAbsArg * process(const char *expr)
Create a RooFit object from the given expression.
Definition: RooFactoryWSTool.cxx:850
RooMsgService.h
RooAddPdf
Definition: RooAddPdf.h:32
RooAbsData
Definition: RooAbsData.h:46
RooFactoryWSTool::asDSET
RooDataSet & asDSET(const char *)
CINT constructor interface, return constructor string argument #idx as RooDataSet object found in wor...
Definition: RooFactoryWSTool.cxx:1855
RooFit.h
RooSimultaneous.h
RooFactoryWSTool::asARG
RooAbsArg & asARG(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsArg reference found in w...
Definition: RooFactoryWSTool.cxx:1571
RooFactoryWSTool::_typeAliases
std::map< std::string, std::string > _typeAliases
Definition: RooFactoryWSTool.h:165
RooFactoryWSTool::as_ARG
static RooAbsArg & as_ARG(UInt_t idx)
Definition: RooFactoryWSTool.h:87
RooFactoryWSTool::processCreateVar
std::string processCreateVar(std::string &func, std::vector< std::string > &args)
Glue function between high-level syntax and low-level factory call to createVariable: Process a parse...
Definition: RooFactoryWSTool.cxx:1308
RooFactoryWSTool::_args
std::vector< std::string > _args
Definition: RooFactoryWSTool.h:184
RooFactoryWSTool::as_FUNC
static RooAbsReal & as_FUNC(UInt_t idx)
Definition: RooFactoryWSTool.h:90
RooAbsReal::createIntegral
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:561
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
RooFactoryWSTool::asFUNC
RooAbsReal & asFUNC(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsReal reference found in ...
Definition: RooFactoryWSTool.cxx:1591
xmax
float xmax
Definition: THbookFile.cxx:95
RooFactoryWSTool::asDHIST
RooDataHist & asDHIST(const char *)
CINT constructor interface, return constructor string argument #idx as RooDataHist object found in wo...
Definition: RooFactoryWSTool.cxx:1838
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooAbsPdf::createCdf
RooAbsReal * createCdf(const RooArgSet &iset, const RooArgSet &nset=RooArgSet())
Create a cumulative distribution function of this p.d.f in terms of the observables listed in iset.
Definition: RooAbsPdf.cxx:3390
RooFactoryWSTool::asCAT
RooCategory & asCAT(const char *)
CINT constructor interface, return constructor string argument #idx as RooCategory reference found in...
Definition: RooFactoryWSTool.cxx:1723
RooFactoryWSTool::as_RMODEL
static RooResolutionModel & as_RMODEL(UInt_t idx)
Definition: RooFactoryWSTool.h:93
RooArgList
Definition: RooArgList.h:21
RooFactoryWSTool::as_LIST
static RooArgList as_LIST(UInt_t idx)
Definition: RooFactoryWSTool.h:100
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:558
RooResolutionModel.h
RooFactoryWSTool::checkSyntax
Bool_t checkSyntax(const char *arg)
Perform basic syntax on given factory expression.
Definition: RooFactoryWSTool.cxx:1526
RooAbsArg::SetName
void SetName(const char *name)
Set the name of the TNamed.
Definition: RooAbsArg.cxx:2218
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
RooFactoryWSTool::~RooFactoryWSTool
virtual ~RooFactoryWSTool()
Destructor.
Definition: RooFactoryWSTool.cxx:140
RooFactoryWSTool::_hooks
static std::map< std::string, IFace * > * _hooks
Definition: RooFactoryWSTool.h:188
Int_t
int Int_t
Definition: RtypesCore.h:45
RooChi2Var
Definition: RooChi2Var.h:25
RooFactoryWSTool::as_DHIST
static RooDataHist & as_DHIST(UInt_t idx)
Definition: RooFactoryWSTool.h:103
RooAddPdf.h
RooWorkspace::startTransaction
Bool_t startTransaction()
Open an import transaction operations.
Definition: RooWorkspace.cxx:1042
RooAbsReal
Definition: RooAbsReal.h:61
RooFactoryWSTool::_ws
RooWorkspace * _ws
Definition: RooFactoryWSTool.h:190
RooFactoryWSTool::SpecialsIFace::create
std::string create(RooFactoryWSTool &ft, const char *typeName, const char *instanceName, std::vector< std::string > args)
Concatenate list of args into comma separated string.
Definition: RooFactoryWSTool.cxx:1955
RooFactoryWSTool::ws
RooWorkspace & ws()
Definition: RooFactoryWSTool.h:74
RooFactoryWSTool::as_INT
static Int_t as_INT(UInt_t idx)
Definition: RooFactoryWSTool.h:109
RooFactoryWSTool::RooFactoryWSTool
RooFactoryWSTool(RooWorkspace &ws)
Definition: RooFactoryWSTool.cxx:129
RooFactoryWSTool::errorCount
Int_t errorCount()
Definition: RooFactoryWSTool.h:193
RooWorkspace::set
const RooArgSet * set(const char *name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
Definition: RooWorkspace.cxx:977
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
RooDataSet.h
RooCategory::defineType
bool defineType(const std::string &label)
Define a state with given name.
Definition: RooCategory.cxx:208
RooNLLVar.h
bool
RooChi2Var.h
RooNumConvPdf.h
RooFactoryWSTool::as_CATFUNC
static RooAbsCategory & as_CATFUNC(UInt_t idx)
Definition: RooFactoryWSTool.h:97
RooFactoryWSTool::createCategory
RooCategory * createCategory(const char *name, const char *stateNameList=0)
Low-level factory interface for creating a RooCategory with a given list of state names.
Definition: RooFactoryWSTool.cxx:174
RooFactoryWSTool::asPDF
RooAbsPdf & asPDF(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsPdf reference found in w...
Definition: RooFactoryWSTool.cxx:1652
RooWorkspace::import
Bool_t import(const RooAbsArg &arg, 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 RooCmdArg &arg9=RooCmdArg())
Import a RooAbsArg object, e.g.
Definition: RooWorkspace.cxx:361
TROOT.h
RooFactoryWSTool::as_OBJ
static TObject & as_OBJ(UInt_t idx)
Definition: RooFactoryWSTool.h:106
RooAbsCategory
Definition: RooAbsCategory.h:38
RooFactoryWSTool::of
static RooFactoryWSTool * of()
Definition: RooFactoryWSTool.cxx:2197
RooFactoryWSTool::asVARLV
RooAbsRealLValue & asVARLV(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsRealLValue reference fou...
Definition: RooFactoryWSTool.cxx:1614
RooAbsArg::clone
virtual TObject * clone(const char *newname=0) const =0
RooFactoryWSTool::as_SET
static RooArgSet as_SET(UInt_t idx)
Definition: RooFactoryWSTool.h:99
RooFactoryWSTool::registerSpecial
static void registerSpecial(const char *typeName, RooFactoryWSTool::IFace *iface)
Register foreign special objects in factory.
Definition: RooFactoryWSTool.cxx:1934
RooAbsArg::setStringAttribute
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
Definition: RooAbsArg.cxx:291
RooFactoryWSTool::asSET
RooArgSet asSET(const char *)
CINT constructor interface, return constructor string argument #idx as RooArgSet of objects found in ...
Definition: RooFactoryWSTool.cxx:1739
RooProduct
Definition: RooProduct.h:30
RooDataHist
Definition: RooDataHist.h:39
RooFactoryWSTool::splitFunctionArgs
std::vector< std::string > splitFunctionArgs(const char *funcExpr)
Allocate and fill work buffer.
Definition: RooFactoryWSTool.cxx:1450
RooFactoryWSTool
Definition: RooFactoryWSTool.h:47
TClass::InheritsFrom
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4772
RooFactoryWSTool.h
RooResolutionModel
Definition: RooResolutionModel.h:26
RooDerivative.h
RooProdPdf.h
xmin
float xmin
Definition: THbookFile.cxx:95
RooFactoryWSTool::processCompositeExpression
std::string processCompositeExpression(const char *arg)
Process a single composite expression.
Definition: RooFactoryWSTool.cxx:942
TEnum.h
RooFit
Definition: RooCFunction1Binding.h:29
RooAbsPdf.h
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooDataHist.h
RooAbsReal::derivative
RooDerivative * derivative(RooRealVar &obs, Int_t order=1, Double_t eps=0.001)
Return function representing first, second or third order derivative of this function.
Definition: RooAbsReal.cxx:4252
RooFactoryWSTool::createVariable
RooRealVar * createVariable(const char *name, Double_t xmin, Double_t xmax)
Low-level factory interface for creating a RooRealVar with a given range and initial value.
Definition: RooFactoryWSTool.cxx:150
RooFactoryWSTool::processMetaArg
std::string processMetaArg(std::string &func, std::vector< std::string > &args)
Concatenate list of args into comma separated string.
Definition: RooFactoryWSTool.cxx:1426
TNamed::Clone
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:74
RooWorkspace::cat
RooCategory * cat(const char *name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
Definition: RooWorkspace.cxx:1304
RooNLLVar
Definition: RooNLLVar.h:27
RooLinkedList
Definition: RooLinkedList.h:35
RooFactoryWSTool::asLIST
RooArgList asLIST(const char *)
CINT constructor interface, return constructor string argument #idx as RooArgList of objects found in...
Definition: RooFactoryWSTool.cxx:1788
RooWorkspace::obj
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
Definition: RooWorkspace.cxx:2106
RooAddition
Definition: RooAddition.h:27
RooWorkspace::pdf
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
Definition: RooWorkspace.cxx:1277
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:437
RooFactoryWSTool::as_CAT
static RooCategory & as_CAT(UInt_t idx)
Definition: RooFactoryWSTool.h:95
RooAddition.h
RooFactoryWSTool::simul
RooSimultaneous * simul(const char *objName, const char *indexCat, const char *pdfMap)
Definition: RooFactoryWSTool.cxx:653
RooFactoryWSTool::processListExpression
std::string processListExpression(const char *arg)
Process a list of high-level expression.
Definition: RooFactoryWSTool.cxx:1156
TClass::GetClass
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2925
RooCategory.h
RooLinkedList::Add
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
RooFactoryWSTool::resolveClassName
TClass * resolveClassName(const char *className)
Definition: RooFactoryWSTool.cxx:1246
RooFit::ObjectHandling
@ ObjectHandling
Definition: RooGlobalFunc.h:68
RooWorkspace::cancelTransaction
Bool_t cancelTransaction()
Cancel an ongoing import transaction.
Definition: RooWorkspace.cxx:1062
RooFactoryWSTool::clearError
void clearError()
Associated workspace.
Definition: RooFactoryWSTool.h:192
RooRealVar.h
RooFactoryWSTool::checkIndex
static void checkIndex(UInt_t index)
Definition: RooFactoryWSTool.cxx:1559
RooFactoryWSTool::asCATFUNC
RooAbsCategory & asCATFUNC(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsCategory reference found...
Definition: RooFactoryWSTool.cxx:1686
RooProduct.h
RooWorkspace::fundArg
RooAbsArg * fundArg(const char *name) const
Return fundamental (i.e.
Definition: RooWorkspace.cxx:1354
void
typedef void((*Func_t)())
RooFactoryWSTool::createArg
RooAbsArg * createArg(const char *className, const char *objName, const char *varList)
Low-level factory interface for creating a RooAbsPdf of a given class with a given list of input vari...
Definition: RooFactoryWSTool.cxx:304
RooFactoryWSTool::asINT
Int_t asINT(const char *)
CINT constructor interface, return constructor string argument #idx as Int_t.
Definition: RooFactoryWSTool.cxx:1916
unsigned int
RooConstVar.h
RooFactoryWSTool::amplAdd
RooRealSumPdf * amplAdd(const char *objName, const char *specList)
Definition: RooFactoryWSTool.cxx:543
RooGlobalFunc.h
RooWorkspace::commitTransaction
Bool_t commitTransaction()
Definition: RooWorkspace.cxx:1084
RooFactoryWSTool::IFace
Definition: RooFactoryWSTool.h:139
dummy
static Int_t dummy
Definition: RooFactoryWSTool.cxx:79
sum
static long int sum(long int i)
Definition: Factory.cxx:2272
RooFactoryWSTool::varTag
std::string varTag(std::string &func, std::vector< std::string > &args)
Definition: RooFactoryWSTool.cxx:1279
RooFit::NormSet
RooCmdArg NormSet(const RooArgSet &nset)
Definition: RooGlobalFunc.cxx:256
RooFit::Conditional
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
Definition: RooGlobalFunc.cxx:225
RooWorkspace
Definition: RooWorkspace.h:43
RooFactoryWSTool::IFace::create
virtual std::string create(RooFactoryWSTool &ft, const char *typeName, const char *instanceName, std::vector< std::string > args)=0
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAbsCategory.h
RooFactoryWSTool::as_DSET
static RooDataSet & as_DSET(UInt_t idx)
Definition: RooFactoryWSTool.h:104
RooAbsPdf::createProjection
virtual RooAbsPdf * createProjection(const RooArgSet &iset)
Return a p.d.f that represent a projection of this p.d.f integrated over given observables.
Definition: RooAbsPdf.cxx:3352
RooStringVar
Definition: RooStringVar.h:23
kIsEnum
@ kIsEnum
Definition: TDictionary.h:68
RooCategory
Definition: RooCategory.h:27
init
static Int_t init()
Definition: RooFactoryWSTool.cxx:81
RooFactoryWSTool::processSingleExpression
std::string processSingleExpression(const char *arg)
Process a single high-level expression.
Definition: RooFactoryWSTool.cxx:1007
TInterpreter.h
TClass
Definition: TClass.h:80
TObject
Definition: TObject.h:37
RooFactoryWSTool::as_VARLV
static RooAbsRealLValue & as_VARLV(UInt_t idx)
Definition: RooFactoryWSTool.h:92
RooFactoryWSTool::_of
static RooFactoryWSTool * _of
Definition: RooFactoryWSTool.h:183
RooFactoryWSTool::as_PDF
static RooAbsPdf & as_PDF(UInt_t idx)
Definition: RooFactoryWSTool.h:89
RooFactoryWSTool::as_DATA
static RooAbsData & as_DATA(UInt_t idx)
Definition: RooFactoryWSTool.h:102
RooWorkspace::arg
RooAbsArg * arg(const char *name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
Definition: RooWorkspace.cxx:1323
RooFactoryWSTool::_autoNamePrefix
std::stack< std::string > _autoNamePrefix
Definition: RooFactoryWSTool.h:164
RooFactoryWSTool::SpecialsIFace
Definition: RooFactoryWSTool.h:145
name
char name[80]
Definition: TGX11.cxx:110
kIsPublic
@ kIsPublic
Definition: TDictionary.h:74
RooFFTConvPdf.h
BUFFER_SIZE
#define BUFFER_SIZE
Definition: RooFactoryWSTool.cxx:69
RooFactoryWSTool::prod
RooProdPdf * prod(const char *objName, const char *pdfList)
Definition: RooFactoryWSTool.cxx:585
RooWorkspace::var
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
Definition: RooWorkspace.cxx:1295
RooDataSet
Definition: RooDataSet.h:33
RooFactoryWSTool::asCATLV
RooAbsCategoryLValue & asCATLV(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsCategoryLValue reference...
Definition: RooFactoryWSTool.cxx:1704
RooFactoryWSTool::asVAR
RooRealVar & asVAR(const char *)
CINT constructor interface, return constructor string argument #idx as RooRealVar reference found in ...
Definition: RooFactoryWSTool.cxx:1637
RooAbsArg
Definition: RooAbsArg.h:73
TEnum::GetEnum
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
Definition: TEnum.cxx:143
RooFactoryWSTool::add
RooAddPdf * add(const char *objName, const char *specList, Bool_t recursiveCoefs=kFALSE)
Definition: RooFactoryWSTool.cxx:501
RooAbsPdf
Definition: RooAbsPdf.h:40
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooFactoryWSTool::addfunc
RooAddition * addfunc(const char *objName, const char *specList)
Definition: RooFactoryWSTool.cxx:702
RooFit::Silence
RooCmdArg Silence(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:260
RooFactoryWSTool::processCreateArg
std::string processCreateArg(std::string &func, std::vector< std::string > &args)
Glue function between high-level syntax and low-level factory call to createArg: Process a parsed cal...
Definition: RooFactoryWSTool.cxx:1378
RooFactoryWSTool::prodfunc
RooProduct * prodfunc(const char *objName, const char *pdfList)
Definition: RooFactoryWSTool.cxx:757
RooSimultaneous
Definition: RooSimultaneous.h:37
RooAbsCategoryLValue
Definition: RooAbsCategoryLValue.h:25
RooRealSumPdf.h
Class
void Class()
Definition: Class.C:29
RooFactoryWSTool::logError
void logError()
Definition: RooFactoryWSTool.h:153
RooRealVar
Definition: RooRealVar.h:35
ROOT::Math::detail::sep
@ sep
Definition: GenVectorIO.h:55
RooFactoryWSTool::hooks
static std::map< std::string, IFace * > & hooks()
Definition: RooFactoryWSTool.cxx:1943
RooAbsRealLValue
Definition: RooAbsRealLValue.h:31
RooProdPdf
Definition: RooProdPdf.h:33
RooFactoryWSTool::asOBJ
TObject & asOBJ(const char *)
Definition: RooFactoryWSTool.cxx:1872
RooArgList.h
kIsConstPointer
@ kIsConstPointer
Definition: TDictionary.h:88
RooRealSumPdf
Definition: RooRealSumPdf.h:25
RooFactoryWSTool::as_CATLV
static RooAbsCategoryLValue & as_CATLV(UInt_t idx)
Definition: RooFactoryWSTool.h:96
RooFactoryWSTool::as_STRING
static const char * as_STRING(UInt_t idx)
Definition: RooFactoryWSTool.h:108
RooFactoryWSTool::asDOUBLE
Double_t asDOUBLE(const char *)
CINT constructor interface, return constructor string argument #idx as Double_t.
Definition: RooFactoryWSTool.cxx:1925
RooFactoryWSTool::processExpression
std::string processExpression(const char *expr)
Process a single high-level expression or list of expressions.
Definition: RooFactoryWSTool.cxx:915
RooFactoryWSTool::as_VAR
static RooRealVar & as_VAR(UInt_t idx)
Definition: RooFactoryWSTool.h:91
RooLinkedList::Delete
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
Definition: RooLinkedList.cxx:587
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
RooArgSet
Definition: RooArgSet.h:28
cxcoutD
#define cxcoutD(a)
Definition: RooMsgService.h:81
RooFactoryWSTool::asSTRING
const char * asSTRING(const char *)
CINT constructor interface, return constructor string argument #idx as const char*.
Definition: RooFactoryWSTool.cxx:1886
gROOT
#define gROOT
Definition: TROOT.h:406
int
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341
RooWorkspace::defineSet
Bool_t defineSet(const char *name, const RooArgSet &aset, Bool_t importMissing=kFALSE)
Define a named RooArgSet with given constituents.
Definition: RooWorkspace.cxx:855