Member function pointers in CINT / PyROOT / reflex

Hello,

I am trying to instantiate a class that uses member function pointers in CINT and PyROOT after creating a dictionary for it. Is this possible? Please find the class definition below and the reflex file attached.

Thank you in advance,
Bruno

namespace HggReader {
  class HggD3PDCutFlow;
  typedef bool (HggD3PDCutFlow::*HGGc0)(void);
  typedef bool (HggD3PDCutFlow::*HGGc1)(int);

  class HggCut
  {
  public:
    HggCut() : name(""), onEvent(0), onPair(0), onPhoton(0) {};
    HggCut(std::string n, HGGc0 a, HGGc1 b = 0, HGGc1 c = 0) : name(n), onEvent(a), onPair(b), onPhoton(c) {};
    virtual ~HggCut() {};
    std::string name;
    // Pointers to HGGD3PDCutFlow cuts
    HGGc0 onEvent;
    HGGc1 onPair, onPhoton;
  };
}

root [0] HggCut c1 Error: class,struct,union or type bool(HggReader not defined {CINTEX dictionary translator}:-1: Error: class,struct,union or type bool(HggReader not defined {CINTEX dictionary translator}:-1: Error: class,struct,union or type bool(HggReader not defined {CINTEX dictionary translator}:-1: Error: class,struct,union or type bool(HggReader not defined {CINTEX dictionary translator}:-1: Error: class,struct,union or type bool(HggReader not defined {CINTEX dictionary translator}:-1: Error: class,struct,union or type bool(HggReader not defined {CINTEX dictionary translator}:-1:
HGGReader_rflx.cxx (620 KB)

Bruno,

Reflex supports them, but PyROOT does not. Is on my TODO list. Dunno about CINT, I’ll let Axel field that. :slight_smile:

Cheers,
Wim

Thanks Wim. Let’s wait to hear about CINT.

Cheers,
Bruno

Hi,

Your example works fine when the dictionary is generated via rootcint.

Philippe.

Hi Philippe,

Thanks, indeed it seems to work. Now I see a difference between interactive and compiled code when testing a null pointer. Do you understand or maybe there is error on what I am doing?

Thanks again,
Bruno

Interactively:

root [0] gSystem->Load("HggCut_h.so");
root [1] HGGc0 c0; 
root [2] cout << (c0 == 0) << endl;
0

While the compiled code gives:

root [0] .L test_HggCut.C+             
Info in <TUnixSystem::ACLiC>: creating shared library /home/blenzi/teste/./test_HggCut_C.so
In file included from /home/blenzi/teste/test_HggCut_C_ACLiC_dict.h:34,
                 from /home/blenzi/teste/test_HggCut_C_ACLiC_dict.cxx:16:
/home/blenzi/teste/./HggCut.h: In function ‘void test_HggCut()’:
/home/blenzi/teste/./HggCut.h:15: warning: ‘c0.bool (HggD3PDCutFlow::*)()::__delta’ may be used uninitialized in this function
/home/blenzi/teste/./test_HggCut.C:10: note: ‘c0.bool (HggD3PDCutFlow::*)()::__delta’ was declared here
/home/blenzi/teste/./HggCut.h:15: warning: ‘c0.bool (HggD3PDCutFlow::*)()::__pfn’ may be used uninitialized in this function
/home/blenzi/teste/./test_HggCut.C:10: note: ‘c0.bool (HggD3PDCutFlow::*)()::__pfn’ was declared here
/home/blenzi/teste/./HggCut.h:15: warning: ‘c1.bool (HggD3PDCutFlow::*)(int)::__delta’ may be used uninitialized in this function
/home/blenzi/teste/./test_HggCut.C:11: note: ‘c1.bool (HggD3PDCutFlow::*)(int)::__delta’ was declared here
/home/blenzi/teste/./HggCut.h:15: warning: ‘c1.bool (HggD3PDCutFlow::*)(int)::__pfn’ may be used uninitialized in this function
/home/blenzi/teste/./test_HggCut.C:11: note: ‘c1.bool (HggD3PDCutFlow::*)(int)::__pfn’ was declared here
root [1] test_HggCut()
1
1
1
1

test_HggCut.C (516 Bytes)
HggCut.h (1.71 KB)

Hi,

root [1] HGGc0 c0; Since c0 is not initialized, the value should be considered random …

Cheers,
Philippe.

Hi,

You are right, sorry. What I want is actually to instantiate a “null” HggCut (with null pointers to member functions):

HGGc0 c0 = 0; 
HGGc1 c1 = 0;
HggCut C0("test", c0, c1, c1);
HggCut C2("test0", (HGGc0) 0, (HGGc1) 0, (HGGc1) 0);

But the comparision still yields false interactively:

root [1] HGGc0 c0 = (HGGc0) 0;        
root [2] c0 == 0                      
(int)0
root [3] HGGc1 c1 = 0;
root [4] HggCut C0("test", c0, c1, c1);
root [5] cout << (C0.onEvent == 0) << endl;
0

And if I try to instantiate HggCut interactively casting a null pointer it crashes without giving a message:

root [6] HggCut a("test", (HGGc0) 0, (HGGc1) 0, (HGGc1) 0)

 *** Break *** segmentation violation
Root > 

Thanks again,
Bruno

Hi Bruno,

The comparison and assignment of member function pointer to zero is fixed in revision 39322 of the trunk.

Cheers,
Philippe.

Hi Bruno,

And the constructor segfault is fixed by revision 39323.

Cheers,
Philippe.