Using AddExec to modify/manipulate non static members of a c

Dear root experts

After implementing a member function of a class (ATEventDrawTask) that yields the coordinates of each bin of a TH2Poly by clicking on the pad plane, I find that, since the AddExec function is static, non-static members cannot be accessed (in principle).

What I want to do is to use the bin number provided by my AddExec function as argument of another non-static member of this class which belongs to a different class, called ATPad. This ATPad member is also used in other member functions of the class. This ATPad has in turn a member to find the correspondence between bin and real pad and then find an array containing the information (stored in a std::vector member of TPad) I want to plot into a TH1 histogram, that is placed into a TCanvas managed by a TEveEventManager.

Everything is working except the part where I have to make the “connection” between the AddExec result and the ATPad member call. Is there any way to do this?

Add Exec function:

void
ATEventDrawTask::SelectPad()
{
    int event = gPad->GetEvent();
    if (event != 11) return; //may be comment this line
    TObject *select = gPad->GetSelected();
    if (!select) return;
    if (select->InheritsFrom(TH2Poly::Class())) {
        TH2Poly *h = (TH2Poly*)select;
        gPad->GetCanvas()->FeedbackMode(kTRUE);
        int pyold = gPad->GetUniqueID();
        int px = gPad->GetEventX();
        int py = gPad->GetEventY();
        float uxmin = gPad->GetUxmin();
        float uxmax = gPad->GetUxmax();
        int pxmin = gPad->XtoAbsPixel(uxmin);
        int pxmax = gPad->XtoAbsPixel(uxmax);
        if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold);
        gVirtualX->DrawLine(pxmin,py,pxmax,py);
        gPad->SetUniqueID(py);
        Float_t upx = gPad->AbsPixeltoX(px);
        Float_t upy = gPad->AbsPixeltoY(py);
        Double_t x = gPad->PadtoX(upx);
        Double_t y = gPad->PadtoY(upy);
        Int_t bin = h->FindBin(x,y);
        const char *bin_name = h->GetBinName(bin);
        std::cout<<" Bin number selected : "<<bin<<" Bin name :"<<bin_name<<std::endl;
       
       
    }

AddExec call (fEventManager is the pointer to the TEveEventMAnager derived class)

fCvsPadPlane = fEventManager->GetCvsPadPlane();/
fCvsPadPlane->AddExec("ex","ATEventDrawTask::SelectPad()");

Another question is, how to put arguments into the AddExec function when this one is called foo->AddExec(“ex”,"MyClass::MyExec)).

Thank you very much in advance.
Best regards

Not sure to fully understand what you want to do…
Do you have a simple code example reproducing your problem ?

Hello:

I have solved the problem, but I just want to provide a better explanation in case anyone else needs to solve this, what I wanted to do is to draw a TH1 histogram when clicking in one of the bins of a TH2Poly. The point is that I needed to search in a TClonesArray for the information to be displayed in the TH1 (which must be a non static member of the main class), everything within the static function that allows to click on the TH2Poly.

The solution is to pass the TH1 (and the TCanvas) and the information stored in the TClonesArray (which is a class that contains the information of a single event) through the gROOT global pointer. This is an example:

fCvsPadWave = fEventManager->GetCvsPadWave();
fCvsPadWave->SetName("fCvsPadWave");
gROOT->GetListOfSpecials()->Add(fCvsPadWave);
fCvsPadPlane = fEventManager->GetCvsPadPlane();
fCvsPadPlane -> ToggleEventStatus();
fCvsPadPlane->AddExec("ex","ATEventDrawTask::SelectPad(\"fRawEvent\")");

fCvsPadWave is the TCanvas I want to pass. fCvsPadPlane is the TCanvas that contains the “clickable” TH2Poly. Both are coming from a TEveEventManager, but this is not important, it could be just a regular new object. The TH1 (which is not shown here) is also treated in the same way. Then:

ATEventDrawTask::SelectPad(const char *rawevt)
{
    int event = gPad->GetEvent();
    if (event != 11) return; //may be comment this line
    TObject *select = gPad->GetSelected();
    if (!select) return;
    if (select->InheritsFrom(TH2Poly::Class())) {
        TH2Poly *h = (TH2Poly*)select;
        gPad->GetCanvas()->FeedbackMode(kTRUE);
        ATRawEvent* tRawEvent = NULL;
        tRawEvent = (ATRawEvent*)gROOT->GetListOfSpecials()->FindObject(rawevt);
        ....
        TH1I* tPadWave = NULL;
        tPadWave = (TH1I*)gROOT->GetListOfSpecials()->FindObject("fPadWave");
        ....
}

I reduced the code because it is large and it does not provide any additional information. The ATRawEvent (retrieved from a TClonesArray) contains the info about the current event (number of pad/channels of the detector, charge, time…) and the tPadWave is a pointer to the previous fPadWave. Then I can manipulate them inside the AddExec associated function.

I really do not know if this is the smartest solution but it works.

Best regards
Yassid