Ok, glad the examples work! For your last case, the error is due to the fact that changing to class makes the methodC private in that class. You need to make it public.
Cheers,
Vincenzo
I find it weird that it works for code injected into the interpreter, but not for compiled classes. Could you please attach a minimal reproducer so that we can better diagnose (or debug) the issue?
As a (hacky) workaround, maybe you could define an inline member function on the C++ side that returns a pointer to the base object, as in
class TRestRawSignalEvent : public TRestEvent {
public:
// ...
TRestEvent *AsTRestEvent() { return static_cast<TRestEvent *>(this); }
};
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: TRestEvent* TRestRawSignalEvent::AsTRestEvent() =>
TypeError: unbound method TRestRawSignalEvent::AsTRestEvent must be called with a TRestRawSignalEvent instance as first argument
This snippet should be equivalent to what you are doing (based on your previous examples, corrected class names and also adding the latest AsTRestEvent method). But all the classes feature their methods in the public section in your own repository, so I still don’t understand what was your previous issue with using the private methods.
import ROOT
ROOT.gInterpreter.Declare("""
class TRestEvent {
public:
virtual void Initialize() = 0;
};
class TRestRawSignalEvent: public TRestEvent {
public:
void Initialize() final {}
TRestEvent *AsTRestEvent() { return static_cast<TRestEvent *>(this); }
};
class TRestRun{
public:
void SetInputEvent(TRestEvent *) {}
};
""")
rn = ROOT.TRestRun()
rawEv = ROOT.TRestRawSignalEvent()
rn.SetInputEvent(rawEv)
rn.SetInputEvent(rawEv.AsTRestEvent())
This fails as it is, what are the requirements to build the project? I’ve hit a couple issues, first I didn’t have a ROOT installation before running the cmake command and it complained. Then I sourced ROOT and now it complains that it can’t find TEveArrow.h.
I cannot build on ArchLinux due to notable changes in the GNU mpfr headers (using version 4.1.1). Could you provide us additional information about your build environment?
make -j install
[...]
[ 17%] generating: /home/vpadulan/Programs/framework/build/rootdict/CINT_TRestTask.cxx with /home/vpadulan/Programs/framework/source/framework/core/inc/TRestTask.h;/home/vpadulan/Programs/framework/build/rootdict/TRestTask_Linkdef.h
In file included from input_line_9:3:
In file included from /home/vpadulan/Programs/framework/source/framework/tools/inc/TRestComplex.h:27:
/home/vpadulan/Programs/framework/source/framework/tools/inc/mpreal.h:121:10: fatal error: 'mpfr.h' file not found
#include <mpfr.h>
^~~~~~~~
Ok, I looked a bit in to the problem and I think I found a quick fix that is now at a pending PR
It will be soon merged to master
I am also investigating the errors you got about the Eve libraries. If I disable REST_EVE I also get into troubles, the point is that we never got into this error because it seems that in our systems Eve libraries in ROOT are always active.
In the code as written, you are trying to pass a class through a pointer. Instead, an instance should be created from the class. E.g. rawEv = ROOT.TRestRawSignalEvent() if the class has a default constructor.
Ok, I was trying to create the rawEv instance without parenthesis. I.e. rawEv = ROOT.TRestRawSignalEvent, instead, using rawEv = ROOT.TRestRawSignalEvent() solved the problem!