What is translated

What is covered has, so far, been motived by the twin driving forces of what I need for my projects and what is easy. If there are other requests for new things, please get in touch or leave a bug report!

Simple Types

  • int/unsigned
  • short / unsigned
  • long  / unsigned
  • long long / unsigned
  • bool
  • float
  • double

Pointers to these simple types are also supported, as well as vector’s of all the types (vectors are as of version 2). Note that a retuned pointer is very dangerous: the wrappers assume this is pointing to an array of pointers to the objects. However, it can’t tell how many objects there are in that array – so it hands back a special object that understands indexers (rtn[i]) – but it is up to you to know how many there are in there and carefully not go beyond the end of the array! When a pointer is an input argument, an array (like int[]) is the expected type.

ROOT Objects

The wrappers supply a .NET version of most ROOT objects (about 1300 of them in ROOT v5.28, for example). ROOT can return the C++ pointer to a ROOT object via multiple path’s (new, TDirectory::Get, etc.) and the wrappers make a good effort to make sure if the same pointer comes back you get the same .NET object to manipulate. If ROOT deletes the object from under you, the .NET wrappers will know about this and will throw an exception if you try to access that object.

  • Any method called “GetXXX” and “SetXXX” with no arguments is translated into a property. The property is called PRXXX (Version 2 and beyond it is called just XXX), and you can access it as a normal .NET property.
  • public data fields are also exposed as properties.

The translation does its best to deal with operator overloads. Most translate as you'd expect - "+", "_", "*", "/", "!", "&", "|", "^", ">>", and "<<". Some obviously can't translate - like the "*" dereferencing operator. The comparison operators, "==", "!=", ">", "<", etc. aren't currently dealt with pleasantly because there are extra restrictions on these in the .NET world to make sure that non-obvious operator semantics aren't introduced. That is for a future version. :-)

STL

Only the simplest STL is supported, and it isn’t supported as an object mapping.

  • [Version 2] vector<TObject> are translated for returned types (from a method or from a data field).
  • [Version 2] as noted above, vector<int>, etc., is also supported.
    • Translated as int[] or similar.
    • Note that the translation occurs up-front.

TIter and TCollection and sub-classes

[Version 2] NTIter, NTCollection, and anything that derives from them implement the interface IEnumerable<ROOTNET::Interface::NTObject>. This means that standard foreach loops work as well as LINQ (LINQ to objects). This allows you to write code similar to the following:

            var list = new ROOTNET.NTList();

            for (int i = 0; i < 10; i++)
            {
                var h = new ROOTNET.NTH1F("hi" + i.ToString(), "there", 10, 0.0, 30.0);
                h.Fill(15.0 + i);
                list.Add(h);
            }

            var iter = new ROOTNET.NTIter(list);
            foreach (var item in iter.Cast<ROOTNET.Interface.NTH1F>())
            {
                Console.WriteLine("See a guy (iter) with {0} entries... and name {1}", item.Entries, item.Name);
            }
            foreach (var item in list.Cast<ROOTNET.Interface.NTH1F>())
            {
                Console.WriteLine("See a guy (list) with {0} entries... and name {1}", item.Entries, item.Name);
            }
            var big = from h in list.Cast<ROOTNET.Interface.NTH1>()
                      where h.Mean > 20
                      select h.Mean;
            foreach (var item in big)
            {
                Console.WriteLine("Mean: {0}", item);
            }

Which generates the following output:

See a guy (iter) with 1 entries... and name hi0
See a guy (iter) with 1 entries... and name hi1
See a guy (iter) with 1 entries... and name hi2
See a guy (iter) with 1 entries... and name hi3
See a guy (iter) with 1 entries... and name hi4
See a guy (iter) with 1 entries... and name hi5
See a guy (iter) with 1 entries... and name hi6
See a guy (iter) with 1 entries... and name hi7
See a guy (iter) with 1 entries... and name hi8
See a guy (iter) with 1 entries... and name hi9
See a guy (list) with 1 entries... and name hi0
See a guy (list) with 1 entries... and name hi1
See a guy (list) with 1 entries... and name hi2
See a guy (list) with 1 entries... and name hi3
See a guy (list) with 1 entries... and name hi4
See a guy (list) with 1 entries... and name hi5
See a guy (list) with 1 entries... and name hi6
See a guy (list) with 1 entries... and name hi7
See a guy (list) with 1 entries... and name hi8
See a guy (list) with 1 entries... and name hi9
Mean: 21
Mean: 22
Mean: 23
Mean: 24

Note the use of the Cast operator. ROOT’s list collection classes are not templated, of course, and thus one must cast members of the list appropriately in order to use them correctly. For those not familiar, the last example is a very simple LINQ example.

This is the first attempt to make ROOT be a better .NET citizen. There is one other overly-ambitious project going on along these lines – but suggestions for more modifications along these lines are welcome – just add a feature request to the Issues page.

Last edited Aug 7, 2012 at 4:06 AM by gwatts, version 7

Comments

krishnateja Apr 27, 2013 at 6:10 AM 
How to save a h.ShowBackground(80, "") into another histo ?