Re: TControlBar in a class (fwd)

From: Panos Christakoglou <Panos.Christakoglou_at_cern.ch>
Date: Thu, 18 Aug 2005 09:36:34 +0200


Ilka Antcheva wrote:

> Hi Panos,
>
> Please see the attached macro cbar1.C as an example. You can have a
> TControlBar as a data member in your class set to 0 in the class
> constructor and created in the method ShowResults(). Please note,
> gROOT->Reset() should not be used in a named script or a compiled
> program.
>
> Best regards, Ilka
>
>> Dear all,
>>
>> suppose I have a class with two methods (apart from the constructor
>> etc):
>>
>> void MyClass::PrintEventStats()
>> void MyClass::ShowResults()
>>
>> Inside the Show method I create a TControlBar object with several
>> buttons such as "Event stats", "Show analysis cuts" etc. Each of
>> these buttons is supposed to call some other method of the same
>> class. Let's say that the "Event stats" button should call the
>> PrinEventStats method. Inside the class this is implemented as follows:
>>
>> void MyClass::ShowResults()
>> {
>> gROOT->Reset();
>> TControlBar *menu1 = new TControlBar("vertical","Event Cuts",10,10);
>> menu1->AddButton("Event
>> statistics","MyClass::PrintEventStats()","Displays the event
>> statistics");
>> .
>> .
>> .
>> menu1->Show();
>>
>> gROOT->SaveContext();
>> }
>>
>> It compiles, I load the .so, create a MyClass object but when I press
>> the "Event stats" button I get a segmentation violation.
>>
>> Any ideas on what to put in the action?
>>
>> Cheers,
>> Panos
>>
>> ps: If I use menu1->AddButton("Event
>> statistics","PrintEventStats()","Displays the event statistics") I
>> get that the fuction is not defined.
>>
>>
>------------------------------------------------------------------------
>
>#include <TControlBar.h>
>
>
>class MyClass : public TObject {
>
>protected:
> TControlBar *fControlBar; // control bar
>
>public:
> MyClass();
> virtual ~MyClass();
>
> void Build();
> void PrintEventStats();
> void CreateEventStats();
> void ShowResults();
>
> ClassDef(MyClass,0)
>};
>
>MyClass::MyClass(){
>
> fControlBar = 0;
> ShowResults();
>}
>
>MyClass::~MyClass(){
> if (fControlBar) delete fControlBar;
>}
>
>void MyClass::Build(){
>
> fControlBar = new TControlBar("vertical", "MyBar"); // Orientation & title.
>
> fControlBar->AddButton("CreateEventStats", "MyClass::CreateEventStats()", "Calls CreateEventStats");
> fControlBar->AddButton("PrintEventStats", "MyClass::PrintEventStats()", "Calls PrintEventStats");
> fControlBar->AddButton("Quit", ".q", "Quits ROOT");
> fControlBar->Show();
>}
>
>void MyClass::PrintEventStats(){
>
> printf("In PrintEventStats()\n");
>}
>
>void MyClass::CreateEventStats(){
>
> printf("In CreateEventStats()\n");
>}
>
>void MyClass::ShowResults(){
>
> Build();
> printf("In ShowResults() buid the Control Bar\n");
>}
>
>void cbar1() {
> new MyClass();
>}
>
>

Dear Ilka,

thank you for your answer.
I've tried what you suggested and it works up to the moment you just print a simple line in the MyClass::PrintEventStats() method. But if you then try to print a parameter in this method, such as fNumberOfAcceptedEvents that is defined as protected in the header and takes its value from another method such as MyClass::IsAccepted(), then the session crashes generating a segmentation violation.

In the attached file you can see the modified class that you sent me in order to have a better idea on what exactly I'm talking about.

Do you have any idea?

Best regards,
Panos

-- 
=====================================
Panos Christakoglou
PH Division
CERN CH-1211 Geneva 23
Switzerland

E-mail: Panos.Christakoglou_at_cern.ch
Tel: +41.22.767.1995
=====================================


  • text/x-c++src attachment: test.C
Received on Thu Aug 18 2005 - 09:33:44 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:11 MET