Dictionary for enum class in ROOT-6

Hello, enum class (differently from enum) do not lives in the outer namespace. For example:

namespace global {
    enum class MyEnumClass { Red, Blue };
    enum MyEnum {One, Two};


why when I generate dictionary I get both in the same namespace, for example in python

global.Red  # why?
global.MyEnum  # this return int, why?
global.MyEnum.Red  # don't work


not following … I remember at some point there was a bug where are all enums were made available globally, but that was beyond them being available on the class name as well (I don’t recall further details; my brain is toast). That was for classes, not enum classes, though.

But specific to the example, the first code is not C++, the second code is not Python … so, could you send a specific, working, example that shows the problem?

Perhaps some answers will help already: MyEnum, the enum type, is represented as type int as that is how enums are represented (unsigned it would be better, but that doesn’t exist in Python). ‘MyEnum.Red’ should not work, as ‘Red’ is part of MyEnumClass. ‘Red’ lives at the namespace level as enum classes (a C++11 features) are not supported yet, so ‘MyEnumClass.Red’ would not currently work until an enum type is defined.

I have a bunch of e-mails from Danilo sitting and waiting for me to start tackling enums in ROOT6 (there’s quite a bit more to it). But have had zero time, unfortunately.


here the minimal (non-)working example:


namespace ns
  enum Color { Red, Green };
  enum class Flavor : char { Up, Down };  // underlying type is char
  enum class Orientation : long int { Down, Up };

void test();


#include "mylib.h"

void test()
  ns::Color color = ns::Red;
  ns::Flavor flavor = ns::Flavor::Up;
  // this does not work:
  // ns::Flavor flavor = ns::Up;

  if (color == 0) { }
  // this does not work:
  // if (flavor == 0) { }

import them in python

import ROOT; ROOT.gROOT.ProcessLine(".L mylib.cxx")

bug 1 (should be ROOT.char or something similar):

In [6]: ROOT.ns.Flavor
Out[6]: int

bug 2

In [8]: ROOT.ns.Flavor.Up
AttributeError                            Traceback (most recent call last)
<ipython-input-8-d7bfea300838> in <module>()
----> 1 ROOT.ns.Flavor.Up

AttributeError: type object 'int' has no attribute 'Up'

bug 3

In [10]: ROOT.ns.Up
Out[10]: 1

in particular this not only is not correct from the namespace point of view, but it is also ambiguos (ns::Flavor::Up or ns::Orientation::Up)

bug 4

In [11]: ROOT.ns.Up == 1   # should be ROOT.ns.Flavor.Up
Out[11]: True

Personally I think for simplicity it is ok to cast all enum, or scoped enum to int in python. But the namespace issue should be corrected.

I have move this to jira: sft.its.cern.ch/jira/browse/ROOT-7240


and I just assigned it to me. :slight_smile:

I’m under the gun from both the CHEP and Super Computing conferences. Will take a bit; sorry about that.