11 #include "RConfigOptions.h"
30 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
33 #define RFLOAT_VALUE(v) (RFLOAT(v)->value)
36 #define RARRAY_LEN(s) (RARRAY(s)->len)
45 #if defined(linux) || defined(sun)
49 #if ((R__RUBY_MAJOR<1) || (R__RUBY_MAJOR==1)&&(R__RUBY_MINOR<=8))
50 # define rb_frame_this_func rb_frame_last_func
59 VALUE arr = rb_ary_new();
65 while ((rro =
next()))
68 rb_iv_set (o,
"__rr__", Data_Wrap_Struct (
cTObject, 0, 0, rro));
69 rb_iv_set (o,
"__rr_class__",
87 VALUE arr = rb_ary_new();
89 for (
int i = 0; i < a->
GetSize(); i++)
90 rb_ary_push (arr, INT2NUM(a->
At(i)));
98 VALUE arr = rb_ary_new();
100 for (
int i = 0; i < a->
GetSize(); i++)
101 rb_ary_push (arr, INT2NUM(a->
At(i)));
109 VALUE arr = rb_ary_new();
111 for (
int i = 0; i < a->
GetSize(); i++)
112 rb_ary_push (arr, INT2NUM(a->
At(i)));
120 VALUE arr = rb_ary_new();
122 for (
int i = 0; i < a->
GetSize(); i++)
123 rb_ary_push (arr, INT2NUM(a->
At(i)));
131 VALUE arr = rb_ary_new();
133 for (
int i = 0; i < a->
GetSize(); i++)
134 rb_ary_push (arr, rb_float_new(a->
At(i)));
142 VALUE arr = rb_ary_new();
144 for (
int i = 0; i < a->
GetSize(); i++)
145 rb_ary_push (arr, rb_float_new(a->
At(i)));
153 VALUE arr = rb_ary_new();
156 for (
int i = 0; i < sc->
GetSize(); i++)
159 rb_iv_set (o,
"__rr__", Data_Wrap_Struct (
cTObject, 0, 0, sc->
At(i)));
160 rb_ary_push (arr, o);
170 q == 0 ? res = Qfalse : res = Qtrue;
188 info = rr_tf1_table[i];
196 rb_warn(
"Ruby user defined function has not been registered for %s (%p).",
202 VALUE vx = rb_ary_new2 (n);
203 VALUE vpar = rb_ary_new2 (n);
204 for (
int i = 0; i <
n; i++)
206 rb_ary_push (vx, rb_float_new(x[i]));
207 rb_ary_push (vpar, rb_float_new(par[i]));
210 double res = NUM2DBL(rb_funcall (rb_cObject, info->
id, 2, vx, vpar));
218 info->
name = strdup(name);
236 info = rr_tf2_table[i];
244 rb_warn(
"Ruby user defined function has not been registered for %s (%p).",
250 VALUE vx = rb_ary_new2 (n);
251 VALUE vpar = rb_ary_new2 (n);
252 for (
int i = 0; i <
n; i++)
254 rb_ary_push (vx, rb_float_new(x[i]));
255 rb_ary_push (vpar, rb_float_new(par[i]));
258 double res = NUM2DBL(rb_funcall (rb_cObject, info->
id, 2, vx, vpar));
266 info->
name = strdup(name);
283 rb_iv_set (o,
"__rr_class__", rb_str_new2(
"TSystem"));
294 rb_iv_set (o,
"__rr_class__", rb_str_new2(
"TRandom"));
305 rb_iv_set (o,
"__rr_class__", rb_str_new2(
"TBenchmark"));
315 rb_iv_set (o,
"__rr__", Data_Wrap_Struct(
cTObject, 0, 0,
gPad));
316 rb_iv_set (o,
"__rr_class__", rb_str_new2(
"TPad"));
326 rb_iv_set (o,
"__rr__", Data_Wrap_Struct(
cTObject, 0, 0,
gStyle));
327 rb_iv_set (o,
"__rr_class__", rb_str_new2(
"TStyle"));
338 rb_iv_set (o,
"__rr_class__", rb_str_new2(
"TDirectory"));
349 rb_iv_set (o,
"__rr__", Data_Wrap_Struct(
cTObject, 0, 0,
gROOT));
350 rb_iv_set (o,
"__rr_class__", rb_str_new2(
"TROOT"));
362 rb_iv_set (o,
"__rr_class__", rb_str_new2(
"TApplication"));
367 static VALUE
via (VALUE
self, VALUE ameth, VALUE bmeth, VALUE parms)
369 if (TYPE(ameth) != T_SYMBOL &&
370 TYPE(bmeth) != T_SYMBOL &&
371 TYPE(parms) != T_HASH)
373 rb_fatal (
"rr-via: Please call TObject#via with sym, sym, hash.");
377 VALUE keys = rb_funcall(parms, rb_intern(
"keys"), 0);
380 VALUE key = rb_ary_entry (keys, i);
381 rb_funcall (
self, rb_to_id (ameth), 2, key, rb_hash_aref (parms, key));
383 rb_funcall(
self, rb_to_id(bmeth), 0);
393 Data_Get_Struct(rb_iv_get (
self,
"__rr__"),
TObject, o);
419 for (
int i = 0; i < nargs; i++)
421 VALUE arg = rb_ary_entry (inargs, i+
offset);
425 if (f) f->SetArg((
Long_t) NUM2INT(arg));
426 if (cproto) strlcat(cproto,
"int", cproto_size);
429 if (f) f->SetArg(NUM2DBL(arg));
430 if (cproto) strlcat(cproto,
"double", cproto_size);
433 if (f) f->SetArg((
Long_t) StringValuePtr(arg));
434 if (cproto) strlcat(cproto,
"char*", cproto_size);
444 arr[j] = NUM2DBL(rb_ary_entry (arg, j));
447 if (cproto) strlcat(cproto,
"double*", cproto_size);
450 v = rb_iv_get (arg,
"__rr__");
453 Data_Get_Struct (v,
TObject, ptr);
454 if (f) f->SetArg((
Long_t) ptr);
456 VALUE tmp = rb_iv_get (arg,
"__rr_class__");
457 strlcat(cproto, StringValuePtr(tmp), cproto_size);
458 if( ((reference_map>>ntobjects)&0
x1) ) {
459 strlcat(cproto,
"*", cproto_size);
461 strlcat(cproto,
"&", cproto_size);
470 if ((i + 1 < nargs) && (nargs != 1) && cproto)
471 strlcat(cproto,
",", cproto_size);
484 G__MethodInfo *minfo = 0;
490 UInt_t bitmap_end =
static_cast<UInt_t>( 0x1 << nobjects );
493 minfo =
new G__MethodInfo(klass->GetMethod(methname, cproto, &dummy_offset));
498 if( nobjects > 0 && !(minfo->IsValid()) ) {
499 for(
UInt_t reference_map=0
x1; reference_map < bitmap_end; reference_map++) {
500 cproto[0] =
static_cast<char>( 0 );
501 drr_map_args2 (inargs, cproto, cproto_size, 0, offset, reference_map);
502 minfo =
new G__MethodInfo(klass->GetMethod(methname, cproto, &dummy_offset));
503 if (minfo->IsValid())
522 char *realtype = strdup(ret), *
t = realtype;
534 *(
t - plevel) =
'\0';
536 if (!strncmp(
t - 3,
"int", 3) ||
537 !strncmp(
t - 4,
"long", 4))
540 if (!strncmp(
t - 6,
"double", 6) ||
541 !strncmp(
t - 5,
"float", 5))
544 if (!strncmp(
t - 5,
"char", 4))
547 if (!strncmp(
t - 4,
"void", 4))
550 if (!strncmp(
t - 4,
"bool", 4))
559 type = (
Ektype)(type + 5);
620 static VALUE
drr_as(VALUE
self, VALUE klass)
630 char *
name = StringValuePtr(klass);
631 if (!rb_const_defined (rb_cObject, rb_intern(name)))
634 k = rb_path2class (name);
637 rb_iv_set (v,
"__rr__", rb_iv_get(
self,
"__rr__"));
638 rb_iv_set (v,
"__rr_class__", klass);
641 rb_raise( rb_eArgError,
"No TClass found for %s. Is this a Root type?", StringValuePtr(klass) );
646 static VALUE
drr_init(
int argc, VALUE argv[], VALUE
self)
649 char *classname = (
char*) rb_obj_classname(
self);
650 char cproto[1024] =
"";
654 rb_scan_args (argc, argv,
"0*", &inargs);
656 G__CallFunc*
func =
new G__CallFunc();
657 G__ClassInfo klass(classname);
666 G__MethodInfo minfo(klass.GetMethod(classname, cproto, &offset));
668 func->SetFunc(minfo);
670 rb_raise( rb_eArgError,
"You provided an unknown prototype (%s) for (%s#%s).",
671 cproto, classname, classname);
673 addr = func->ExecInt((
void*)((
Long_t)0 + offset));
674 rb_iv_set(
self,
"__rr__", Data_Wrap_Struct(
cTObject, 0, 0, (
TObject *)addr));
675 rb_iv_set(
self,
"__rr_class__", rb_str_new2 (classname));
682 static VALUE
drr_return(
int rtype,
Long_t value_address,
double dvalue_address, VALUE
self)
689 vret = INT2NUM(value_address);
692 vret = rb_float_new(dvalue_address);
695 vret = rb_str_new2((
char *)value_address);
698 vret =
rr_bool((
bool)value_address);
710 rb_iv_set(res,
"__rr__", Data_Wrap_Struct(
cTObject, 0, 0, (
TObject*)value_address));
711 rb_iv_set(res,
"__rr_class__", rb_str_new2 (((
TObject*)(value_address))->
ClassName()));
730 char *
name = (
char*) rb_id2name (rb_to_id(klass));
741 return rb_funcall(
self,rb_intern(
"__drr_orig_const_missing"),1,klass);
748 char cproto[1024] =
"";
755 char * methname = (
char*) rb_id2name (rb_to_id(argv[0]));
756 char * classname = (
char *) rb_class2name(
self);
758 rb_scan_args (argc, argv,
"0*", &inargs);
761 G__CallFunc*
func =
new G__CallFunc;
762 G__ClassInfo *klass =
new G__ClassInfo (classname);
763 G__MethodInfo *minfo = 0;
771 minfo =
new G__MethodInfo(klass->GetMethod(methname, cproto, &offset));
772 if (minfo->IsValid())
773 func->SetFunc(*minfo);
775 rb_raise( rb_eArgError,
"You provided an unknown prototype (%s) for (%s#%s).",
776 cproto, classname, methname);
782 address = func->ExecInt((
void*)(offset));
784 dbladdr = func->ExecDouble((
void*)(offset));
786 VALUE ret =
drr_return(rtype, address, dbladdr,
self);
801 char *methname, *classname ;
805 char cproto[1024] =
"";
809 methname = (
char*) rb_id2name (rb_to_id(argv[0]));
810 VALUE tmp = rb_iv_get (
self,
"__rr_class__");
811 classname = StringValuePtr(tmp);
814 rb_scan_args (argc, argv,
"0*", &inargs);
817 VALUE rklass = rb_class_of (
self);
819 G__CallFunc *
func =
new G__CallFunc();
820 G__ClassInfo *klass =
new G__ClassInfo (classname);
821 G__MethodInfo *minfo = 0;
829 minfo =
new G__MethodInfo(klass->GetMethod(methname, cproto, &offset));
830 if (minfo->IsValid())
831 func->SetFunc(*minfo);
833 rb_raise( rb_eArgError,
"You provided an unknown prototype (%s) for (%s#%s).",
834 cproto, classname, methname);
840 entry->
name = strdup(methname);
841 entry->
cproto = strdup(cproto);
848 if (!rb_cvar_defined (rklass, rb_intern(
"@@__func_table__")))
851 Data_Get_Struct(rb_cv_get(rklass,
"@@__func_table__"),
struct drr_func_cache, cache);
855 rb_cv_set (rklass,
"@@__func_table__",
856 Data_Wrap_Struct(
cTObject, 0, 0, cache));
859 address = func->ExecInt((
void*)((
Long_t)caller + offset));
861 dbladdr = func->ExecDouble((
void*)((
Long_t)caller + offset));
876 char cproto[1024] =
"";
879 rklass = rb_class_of (
self);
883 rb_scan_args (argc, argv,
"0*", &inargs);
892 Data_Get_Struct (rb_cv_get(rklass,
"@@__func_table__"),
struct drr_func_cache, cache);
900 func->SetFuncProto (entry->
klass, methname, cproto, &offset);
909 rb_warn (
"Proto conflict with cache. Expected %s, but found no match for %s", cproto, methname);
914 address = func->ExecInt((
void*)((
Long_t)caller + offset));
916 dbladdr = func->ExecDouble((
void*)((
Long_t)caller + offset));
926 #if defined(linux) || defined(sun)
927 dlopen(
"libCint.so", RTLD_GLOBAL | RTLD_LAZY );
928 dlopen(
"libCore.so", RTLD_GLOBAL | RTLD_LAZY );
929 dlopen(
"libGpad.so", RTLD_GLOBAL | RTLD_LAZY );
930 dlopen(
"libGraf.so", RTLD_GLOBAL | RTLD_LAZY );
931 dlopen(
"libMatrix.so", RTLD_GLOBAL | RTLD_LAZY );
932 dlopen(
"libHist.so", RTLD_GLOBAL | RTLD_LAZY );
933 dlopen(
"libTree.so", RTLD_GLOBAL | RTLD_LAZY );
934 dlopen(
"libGraf3d.so", RTLD_GLOBAL | RTLD_LAZY );
935 dlopen(
"libGeom.so", RTLD_GLOBAL | RTLD_LAZY );
952 rb_define_method (rb_cObject,
"via",
VALUEFUNC(
via), 3);
956 rb_eval_string(
"Object.instance_eval { alias __drr_orig_const_missing const_missing }");
Double_t At(Int_t i) const
double rr_ctf1_fcn(double *x, double *par)
void init_global_enums(void)
void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
VALUE rr_seqcollection_new(TSeqCollection *sc)
R__EXTERN TStyle * gStyle
void drr_find_method_prototype(G__ClassInfo *klass, char *methname, VALUE inargs, char *cproto, int cproto_size, Long_t offset)
static TF1 * GetCurrent()
Static function returning the current function being processed.
struct drr_func_entry * entry
static VALUE drr_const_missing(VALUE self, VALUE klass)
struct drr_func_entry * drr_func_cache_find(struct drr_func_cache *cache, char *name)
static VALUE rr_gstyle(void)
int drr_parse_ret_type(const char *ret)
Array of floats (32 bits per element).
struct drr_func_cache * drr_func_cache_init(struct drr_func_entry *entry)
R__EXTERN TApplication * gApplication
Array of integers (32 bits per element).
VALUE rr_arrayd_new(const TArrayD *a)
Sequenceable collection abstract base class.
TObject * drr_grab_object(VALUE self)
VALUE rr_ary_new(TList *l)
std::map< std::string, std::string >::const_iterator iter
void drr_set_method_args(VALUE inargs, G__CallFunc *func, Long_t offset=1)
const std::string ClassName(PyObject *pyobj)
Retrieve the class name from the given python object (which may be just an instance of the class)...
static VALUE rr_to_ary(VALUE self)
void drr_func_cache_push(struct drr_func_cache *cache, struct drr_func_entry *entry)
Short_t At(Int_t i) const
VALUE rr_arrayc_new(const TArrayC *a)
VALUE rr_arrayi_new(const TArrayI *a)
UInt_t drr_map_args2(VALUE inargs, char *cproto, int cproto_size, G__CallFunc *f, Long_t offset=1, UInt_t reference_map=0x0)
static VALUE drr_method_missing(int argc, VALUE argv[], VALUE self)
static VALUE rr_gapplication(void)
static VALUE rr_gsystem(void)
R__EXTERN TSystem * gSystem
Array of shorts (16 bits per element).
void rr_register_ctf1_fcn(char *name, ID id)
R__EXTERN TBenchmark * gBenchmark
virtual const char * ClassName() const
Returns name of class to which the object belongs.
ClassInfo_t * GetClassInfo() const
Array of longs (32 or 64 bits per element).
static VALUE drr_as(VALUE self, VALUE klass)
static VALUE drr_singleton_missing(int argc, VALUE argv[], VALUE self)
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
static VALUE drr_generic_method(int argc, VALUE argv[], VALUE self)
A 2-Dim function with parameters.
R__EXTERN TRandom * gRandom
struct drr_func_cache * last
#define rb_frame_this_func
struct drr_func_cache * next
virtual Int_t GetSize() const
static const double x1[5]
static VALUE rr_gpad(void)
double func(double *x, double *p)
static VALUE via(VALUE self, VALUE ameth, VALUE bmeth, VALUE parms)
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.
Float_t At(Int_t i) const
Array of doubles (64 bits per element).
virtual TObject * At(Int_t idx) const =0
Mother of all ROOT objects.
static VALUE rr_gdirectory(void)
VALUE rr_arrays_new(const TArrayS *a)
void drr_func_entry_free(struct drr_func_entry *entry)
VALUE rr_arrayl_new(const TArrayL *a)
void rr_register_ctf2_fcn(char *name, ID id)
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
static VALUE rr_groot(void)
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
static VALUE rr_grandom(void)
virtual Int_t GetNpar() const
#define RRGRAB(fromobj, type, toobj)
static VALUE drr_return(int rtype, Long_t value_address, double dvalue_address, VALUE self)
double rr_ctf2_fcn(double *x, double *par)
static VALUE drr_init(int argc, VALUE argv[], VALUE self)
static VALUE rr_gbenchmark(void)
VALUE rr_arrayf_new(const TArrayF *a)
Array of chars or bytes (8 bits per element).