# Ruby extension and TMVA

**URL:** <https://root-forum.cern.ch/t/ruby-extension-and-tmva/18708>\
**Category:** TMVA\
**Created:** [January 19, 2015, 9:15pm UTC](https://root-forum.cern.ch/t/ruby-extension-and-tmva/18708 "2015-01-19T21:15:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![idt209](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/idt209/32/11738_2.png) [@idt209](https://root-forum.cern.ch/u/idt209)\
**Post date:** [January 19, 2015, 9:15pm UTC](https://root-forum.cern.ch/t/ruby-extension-and-tmva/18708/1 "2015-01-19T21:15:46Z")

</div>

Hi,

Does anyone know if ROOT’s Ruby extension module supports access to TMVA? I couldn’t find any example on

[root.cern.ch/root/html534/guide … onRuby.pdf](https://root.cern.ch/root/html534/guides/users-guide/ROOTUsersGuideChapters/PythonRuby.pdf)

or

[root.cern.ch/svn/root/trunk/tutorials/ruby/](https://root.cern.ch/svn/root/trunk/tutorials/ruby/)

but was hoping it would be possible.

Thanks,  
Don

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [January 20, 2015, 8:36am UTC](https://root-forum.cern.ch/t/ruby-extension-and-tmva/18708/2 "2015-01-20T08:36:46Z")

</div>

Hi Don,

the Ruby bindings are rather general: if dictionaries are available for a set of C++ entities (and they are for TMVA), these entites are available to Ruby.  
Unfortunately no tutorial was provided which mixed Ruby and TMVA yet.

Best,  
Danilo

---

<div class="post-metadata">

**Author:** ![idt209](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/idt209/32/11738_2.png) [@idt209](https://root-forum.cern.ch/u/idt209)\
**Post date:** [January 22, 2015, 1:39pm UTC](https://root-forum.cern.ch/t/ruby-extension-and-tmva/18708/3 "2015-01-22T13:39:40Z")

</div>

Thanks Danilo. Would you happen to have a quick example (even a one-liner) on how to access TMVA’s entities? I’m having trouble understanding how Ruby handles the TMVA namespace:

```auto
$ irb
irb(main):001:0> require '/usr/lib/root/libRuby'
=> true
irb(main):002:0> TTree
=> TTree
irb(main):003:0> TTree.ancestors
=> [TTree, DRRAbstractClass, Object, Kernel, BasicObject]
irb(main):004:0> TMVA::Factory
Warning in <TClass::TClass>: no dictionary for class TMVA is available
NameError: uninitialized constant TMVA
	from (irb):4:in `const_missing'
	from (irb):4
	from /usr/bin/irb:12:in `<main>'
irb(main):005:0> TMVA
Warning in <TClass::TClass>: no dictionary for class TMVA is available
NameError: uninitialized constant TMVA
	from (irb):5:in `const_missing'
	from (irb):5
	from /usr/bin/irb:12:in `<main>'
```

Thanks!

---

<div class="post-metadata">

**Author:** ![idt209](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/idt209/32/11738_2.png) [@idt209](https://root-forum.cern.ch/u/idt209)\
**Post date:** [January 24, 2015, 9:33pm UTC](https://root-forum.cern.ch/t/ruby-extension-and-tmva/18708/4 "2015-01-24T21:33:38Z")

</div>

I am able now to fetch the TMVA::Factory class by directly calling DRRAbstractClass’s const\_missing method (see snippet below). I’m not sure why the Ruby binding is otherwise tripping over the scope operator.

However, I have a separate issue now. The constructor of TMVA::Factory is expecting arguments of types (TString, TFile\*, TString). However, in Ruby, I only know how to pass over strings of type char\* and TString\*:

```auto
$ irb
irb(main):001:0> require '/usr/lib/root/libRuby'
=> true
irb(main):002:0> outfile = TFile.new("/tmp/outfile.root", "recreate")
=> #<TFile:0x00000001d42e10>
irb(main):003:0> DRRAbstractClass.const_missing("TMVA::Factory")
=> TMVA::Factory
irb(main):004:0> DRRAbstractClass.const_missing("TMVA::Factory").new("jobname", outfile, "V")
ArgumentError: You provided an unknown prototype (char*,TFile*,char*) for (TMVA::Factory#TMVA::Factory).
	from (irb):4:in `initialize'
	from (irb):4:in `new'
	from (irb):4
	from /usr/bin/irb:12:in `<main>'
irb(main):005:0> jobname = TString.new("jobname")
=> #<TString:0x00000001d074c8>
irb(main):006:0> options = TString.new("V")
=> #<TString:0x00000001cff2a0>
irb(main):007:0> DRRAbstractClass.const_missing("TMVA::Factory").new(jobname, outfile, options)
ArgumentError: You provided an unknown prototype (TString*,TFile*,TString*) for (TMVA::Factory#TMVA::Factory).
	from (irb):7:in `initialize'
	from (irb):7:in `new'
	from (irb):7
	from /usr/bin/irb:12:in `<main>'
irb(main):008:0> 
```

Is there a way to cast the arguments to the appropriate type (TString)?

---

<div class="post-metadata">

**Author:** ![elathan](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e56c9b/32.png) [@elathan](https://root-forum.cern.ch/u/elathan)\
**Post date:** [January 27, 2015, 9:12am UTC](https://root-forum.cern.ch/t/ruby-extension-and-tmva/18708/5 "2015-01-27T09:12:50Z")

</div>

IIRC, passing some arguments using C++ references was never supported. Have a look at B.9 here: ftp://root.cern.ch/root/RubyRoot.pdf

Best,  
-Elias

---

<div class="post-metadata">

**Author:** ![idt209](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/idt209/32/11738_2.png) [@idt209](https://root-forum.cern.ch/u/idt209)\
**Post date:** [January 31, 2015, 4:09pm UTC](https://root-forum.cern.ch/t/ruby-extension-and-tmva/18708/6 "2015-01-31T16:09:41Z")

</div>

Thanks Elias. That’s too bad, I hope the Ruby extension will have support for this scenario in a future release. Having access to TMVA via Ruby would be really great!

Don
