Logo ROOT   6.10/09
Reference Guide
RooCintUtils.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 // RooCintUtils is a namespace containing utility functions related
19 // to CINT interfacing
20 //
21 
22 #include "RooFit.h"
23 
24 #include "RooCintUtils.h"
25 
26 #include "RooMsgService.h"
27 #include "TInterpreter.h"
28 
29 #include <string.h>
30 #include <string>
31 #include <iostream>
32 
33 using namespace std ;
34 
35 
36 namespace RooCintUtils
37 {
38 
39  pair<list<string>,unsigned int> ctorArgs(const char* classname, UInt_t nMinArg)
40  {
41  // Utility function for RooFactoryWSTool. Return arguments of 'first' non-default, non-copy constructor of any RooAbsArg
42  // derived class. Only constructors that start with two 'const char*' arguments (for name and title) are considered
43  // The returned object contains
44 
45  Int_t nreq(0) ;
46  list<string> ret ;
47 
48  ClassInfo_t* cls = gInterpreter->ClassInfo_Factory(classname);
49  MethodInfo_t* func = gInterpreter->MethodInfo_Factory(cls);
50  while(gInterpreter->MethodInfo_Next(func)) {
51  ret.clear() ;
52  nreq=0 ;
53 
54  // Find 'the' constructor
55 
56  // Skip non-public methods
57  if (!(gInterpreter->MethodInfo_Property(func) & kIsPublic)) {
58  continue ;
59  }
60 
61  // Return type must be class name
62  if (string(classname) != gInterpreter->MethodInfo_TypeName(func)) {
63  continue ;
64  }
65 
66  // Skip default constructor
67  int nargs = gInterpreter->MethodInfo_NArg(func);
68  if (nargs==0 || nargs==gInterpreter->MethodInfo_NDefaultArg(func)) {
69  continue ;
70  }
71 
72  MethodArgInfo_t* arg = gInterpreter->MethodArgInfo_Factory(func);
73  while (gInterpreter->MethodArgInfo_Next(arg)) {
74  // Require that first two arguments are of type const char*
75  const char* argTypeName = gInterpreter->MethodArgInfo_TypeName(arg);
76  if (nreq<2 && ((string("char*") != argTypeName
77  && !(gInterpreter->MethodArgInfo_Property(arg) & kIsConstPointer))
78  && string("const char*") != argTypeName)) {
79  continue ;
80  }
81  ret.push_back(argTypeName) ;
82  if(!gInterpreter->MethodArgInfo_DefaultValue(arg)) nreq++ ;
83  }
84  gInterpreter->MethodArgInfo_Delete(arg);
85 
86  // Check that the number of required arguments is at least nMinArg
87  if (ret.size()<nMinArg) {
88  continue ;
89  }
90 
91  break;
92  }
93  gInterpreter->MethodInfo_Delete(func);
94  gInterpreter->ClassInfo_Delete(cls);
95  return pair<list<string>,unsigned int>(ret,nreq) ;
96  }
97 
98 
99  Bool_t isEnum(const char* classname)
100  {
101  // Returns true if given type is an enum
102  ClassInfo_t* cls = gInterpreter->ClassInfo_Factory(classname);
103  long property = gInterpreter->ClassInfo_Property(cls);
104  gInterpreter->ClassInfo_Delete(cls);
105  return (property&kIsEnum) ;
106  }
107 
108 
109  Bool_t isValidEnumValue(const char* typeName, const char* value)
110  {
111  // Returns true if given type is an enum
112 
113  // Chop type name into class name and enum name
114  char buf[256] ;
115  strlcpy(buf,typeName,256) ;
116  char* className = strtok(buf,":") ;
117 
118  // Chop any class name prefix from value
119  if (strrchr(value,':')) {
120  value = strrchr(value,':')+1 ;
121  }
122 
123  ClassInfo_t* cls = gInterpreter->ClassInfo_Factory(className);
124  DataMemberInfo_t* dm = gInterpreter->DataMemberInfo_Factory(cls);
125  while (gInterpreter->DataMemberInfo_Next(dm)) {
126  // Check if this data member represents an enum value
127  // there is no "const" with CLING
128  //if (string(Form("const %s",typeName))==gInterpreter->DataMemberInfo_TypeName(dm)) { // this for 5.34
129  if (string(Form("%s",typeName))==gInterpreter->DataMemberInfo_TypeName(dm)) {
130  if (string(value)==gInterpreter->DataMemberInfo_Name(dm)) {
131  gInterpreter->DataMemberInfo_Delete(dm);
132  gInterpreter->ClassInfo_Delete(cls);
133  return kTRUE ;
134  }
135  }
136  }
137  gInterpreter->DataMemberInfo_Delete(dm);
138  gInterpreter->ClassInfo_Delete(cls);
139  return kFALSE ;
140  }
141 }
142 
143 Bool_t RooCintUtils::isTypeDef(const char* trueName, const char* aliasName)
144 {
145  // Returns true if aliasName is a typedef for trueName
146  TypedefInfo_t* t = gInterpreter->TypedefInfo_Factory();
147  while(gInterpreter->TypedefInfo_Next(t)) {
148  if (string(trueName)==gInterpreter->TypedefInfo_TrueName(t)
149  && string(aliasName)==gInterpreter->TypedefInfo_Name(t)) {
150  gInterpreter->TypedefInfo_Delete(t);
151  return kTRUE ;
152  }
153  }
154  gInterpreter->TypedefInfo_Delete(t);
155  return kFALSE ;
156 }
157 
158 
159 std::string RooCintUtils::trueName(const char* aliasName)
160 {
161  // Returns the true type for a given typedef name.
162  TypedefInfo_t* t = gInterpreter->TypedefInfo_Factory();
163  while(gInterpreter->TypedefInfo_Next(t)) {
164  if (string(aliasName)==gInterpreter->TypedefInfo_Name(t)) {
165  std::string ret = trueName(string(gInterpreter->TypedefInfo_TrueName(t)).c_str()) ;
166  gInterpreter->TypedefInfo_Delete(t);
167  return ret;
168  }
169  }
170  gInterpreter->TypedefInfo_Delete(t);
171  return string(aliasName) ;
172 }
173 
Bool_t isValidEnumValue(const char *typeName, const char *value)
Bool_t isEnum(const char *typeName)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define gInterpreter
Definition: TInterpreter.h:499
STL namespace.
std::pair< std::list< std::string >, unsigned int > ctorArgs(const char *classname, UInt_t nMinArgs=0)
Bool_t isTypeDef(const char *trueName, const char *aliasName)
std::string trueName(const char *typeDefName)
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
const Bool_t kFALSE
Definition: RtypesCore.h:92
double func(double *x, double *p)
Definition: stressTF1.cxx:213
const Bool_t kTRUE
Definition: RtypesCore.h:91