StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EventControlPanel.C
1 //*-- Author : Valery Fine 14/08/01 (E-mail: fine@bnl.gov)
2 //
3 // Copyright (C) Valery Fine, Brookhaven National Laboratory, 1999. All right reserved
4 //
5 // $Id: EventControlPanel.C,v 1.6 2001/09/17 00:05:24 perev Exp $
6 //
7 
9 //
10 // This macro generates a Controlbar panel:
11 // begin_html <P ALIGN=CENTER> <IMG SRC="gif/EventControlPanel.gif" ></P> end_html
12 //
13 // To execute an item, click with the left mouse button.
14 //
15 // Just start this macro wheneven you want:
16 //
17 // From Root/Cint macro:
18 // --------------------
19 // .x EventControlPanel.C
20 // .L EventControlPanel.C
21 // or
22 // gROOT->LoadMacro("EventControlPanel.C");
23 //
24 // From the compiled C++ code:
25 // --------------------
26 // gROOT->LoadMacro("EventControlPanel.C");
27 //
28 // After that one may "click" <4 views> button to get from the single "view"
29 // the expanded view as follows:
30 // begin_html <P ALIGN=CENTER> <IMG SRC="gif/FourStarView.gif" ></P> end_html
31 // To cutomize the default bar the dirived class with the custom void UserBar()
32 // method can be done.
33 // TControlBar *Bar(){ return fBar;}
34 // method can be used.
35 //
36 // Example:
37 // TControlBar *myBar = __aa__.Bar();
38 // myBar->AddButton("My custom","printf(\"here is my custom action\n\");","To add your own action replace the second parameter");
39 //
40 // Note: If you don't like what it does make your private copy
41 // ==== change it with your favorite text editor and load it right
42 // away.
43 // NO EXTRA STEP like : compilation, linking, loading required
44 //
46 
48 //
49 // PadControl panel is the set of the static methods to control
50 // TView of any "current" TPad with some "primitive"
51 // operation:
52 //
54 
55 class StChain;
56 class StMaker;
57 class StEventDisplayMaker;
58 class StEventDisplayInfo;
60 public:
61 
62  TGMainFrame *fBar;
63  TGLayoutHints *fL1;
64 
65 static StMaker *fgChain;
66 static StEventDisplayMaker *fgDispMk;
67 static TGMainFrame *fgBar;
68 static StEventDisplayInfo *fgHlp;
69 private:
70  Int_t fNum;
71  TList *fGarb;
72 
73 protected:
74 
75 
76 //_______________________________________________________________________________________
77  TGTextButton *AddButt(const Char_t *buttonName, const Char_t *command)
78  {
79  TGTextButton *tb = new TGTextButton(fBar,buttonName,command);
80  fGarb->Add(tb);
81  int col = (fNum&1)*2;
82  int row = (fNum/2)*2;
83  fNum++;
84  UInt_t uHintsNam = kLHintsCenterY | kLHintsFillX;
85  TGTableLayoutHints *hi = new TGTableLayoutHints(col,col+1,row,row+1
86  ,uHintsNam,10,10,10);
87  fGarb->Add(hi);
88 
89  fBar->AddFrame(tb,hi);
90  Show();
91  return tb;
92  }
93 
94 
95 public:
97  {
98  fgChain = 0; fgDispMk=0; fgHlp = 0; fNum=0;
99  fGarb = new TList;
100  TClass *kl = gROOT->GetClass("StChain");
101  if (kl && kl->GetClassInfo())
102  {
103  fgChain = StMaker::GetChain();
104  fgDispMk = (StEventDisplayMaker*)fgChain->GetMaker("EventDisplay");
105  }
106 
107  Build();
108  }
109 
110 //_______________________________________________________________________________________
111  void Build(){
112 //
113  const char *listEvents[] = {
114  "dst/point" ,"dst/point(id_track,position[0]:position[1]:charge)",
115  "dst/primtrk" ,"dst/primtrk" ,
116  "dst/globtrk" ,"dst/globtrk" ,
117  "dst/vertex" ,"dst/vertex(vtx_id,x:y:z)" ,
118  "All Used Hits" ,"StEvent(All Used Hits)" ,
119  "All Unused Hits" ,"StEvent(All Unused Hits)" ,
120  "TPC Used Hits" ,"StEvent(Tpc Used Hits)" ,
121  "TPC Unused Hits" ,"StEvent(Tpc Unused Hits)" ,
122  "FTPC Used Hits" ,"StEvent(Ftpc Used Hits)" ,
123  "FTPC Unused Hits" ,"StEvent(Ftpc Unused Hits)" ,
124  "SVT Used Hits" ,"StEvent(Svt Used Hits)" ,
125  "SVT Unused Hits" ,"StEvent(Svt Unused Hits)" ,
126  "SSD Used Hits" ,"StEvent(Ssd Used Hits)" ,
127  "SSD Unused Hits" ,"StEvent(Ssd Unused Hits)" ,
128  "RICH Used Hits" ,"StEvent(Rich Used Hits)" ,
129  "RICH Unused Hits" ,"StEvent(Rich Unused Hits)" ,
130  "EMC Used Hits" ,"StEvent(Emc Used Hits)" ,
131  "EMC Unused Hits" ,"StEvent(Emc Unused Hits)" ,
132  "TOF Used Hits" ,"StEvent(Tof Used Hits)" ,
133  "TOF Unused Hits" ,"StEvent(Tof Unused Hits)" ,
134  "All Tracks", ,"StEvent(All Tracks)" ,
135  "All Track Hits" ,"StEvent(All Track Hits)" ,
136  "Primary Tracks" ,"StEvent(Primary Tracks)" ,
137  "Primary Track Hits" ,"StEvent(Primary Track Hits)" ,
138  "Kink Tracks" ,"StEvent(Kink Tracks)" ,
139  "Kink Track Hits" ,"StEvent(Kink Track Hits)" ,
140  "V0 Tracks" ,"StEvent(V0 Tracks)" ,
141  "V0 Track Hits" ,"StEvent(V0 Track Hits)" ,
142  "Xi Tracks" ,"StEvent(Xi Tracks)" ,
143  "Xi Track Hits" ,"StEvent(Xi Track Hits)" ,
144  0};
145 
146  fBar = new TGMainFrame(gClient->GetRoot(), 250,550);
147  fBar->SetWindowName("EventControl");
148  TGTableLayout *lay = new TGTableLayout(fBar,40,4,0,0);
149  fBar->SetLayoutManager(lay);
150  fgBar = fBar;
151 
152 
153 
154  int i;
155  char cbuf[200];
156  for (i=0;listEvents[i];i+=2) {
157  TGTextButton *button = AddButt(listEvents[i],"");
158  sprintf(cbuf,"StEventControlPanel::ToggleDisplayName(\"%s\",(TGTextButton*)%p)"
159  ,listEvents[i+1],button);
160  button->SetCommand(cbuf);
161  }
162 
163  AddButt("Show selections", "StEventControlPanel::PrintNames();");
164  Refresh();
165  Show();
166 }
167 //_______________________________________________________________________________________
169 {
170  fGarb->Delete();
171  delete fGarb;
172  delete fBar;
173 }
174 
175 //_______________________________________________________________________________________
176 static void PrintNames()
177 {
178  if (!fgDispMk) return;
179  TList *tl = fgDispMk->GetNameList();
180  if (!fgHlp) new StEventDisplayInfo(&fgHlp, "Draw Selections", 200, 100);
181  TListIter nextOne(tl);
182  TObject *n=0;
183  int nk=0;
184  while ((n=nextOne())) {
185  if (nk) {fgHlp->AddText(n->GetName());}
186  else {fgHlp->SetText(n->GetName());}
187  nk=1;
188  }
189  fgHlp->Popup();
190 }
191 //_______________________________________________________________________________________
192 void Refresh()
193 {
194  if (!fgDispMk) return;
195  TList *tl = fgDispMk->GetNameList();
196  if (!tl) return;
197  TGButton *but=0;TObject *n=0;
198  TList *frameList = fBar->GetList();
199  TListIter nextFrame(frameList);
200  TGFrameElement *fe=0;
201  while ((fe=(TGFrameElement*)nextFrame())) {
202  but = (TGButton*)fe->fFrame;
203  TListIter nextOne(tl);
204  while ((n=nextOne())) {
205  if (strchr(n->GetName(),'(')==0) continue;
206  if (strstr(but->GetCommand(),n->GetName())) break; }
207  int state = (n) ? kButtonDown:kButtonUp;
208  but->SetState(state);
209  }
210  Show();
211 }
212 //_______________________________________________________________________________________
213 static void ToggleDisplayName(const char *name,TGTextButton *button)
214 {
215  if (!fgDispMk) return;
216  TList *lis = fgDispMk->GetNameList();
217  if (!lis || !(lis->FindObject(name))) {
218  fgDispMk->AddName(name);
219  button->SetState(kButtonDown);
220  } else {
221  fgDispMk->RemoveName(name);
222  button->SetState(kButtonUp);
223  }
224 }
225 //_______________________________________________________________________________________
226  TGTextButton *AddFilter(TObject *filter)
227 {
228  char cbuf[100];
229  sprintf(cbuf,"((StFilterABC*)%p)->Update();",filter);
230  printf("AddFilter: %s::%s\n",filter->GetName(),cbuf);
231  return AddButt(filter->GetName(), cbuf);
232 }
233 
234 
235 //_______________________________________________________________________________________
236  void Show()
237 {
238  // Show group of buttons.
239 
240  fBar->MapSubwindows();
241  fBar->Layout();
242 // Resize(GetLayoutManager()->GetDefaultSize());
243  fBar->MapWindow();
244  fBar->MapRaised();
245 // fClient->NeedRedraw(this);
246 }
247 };
248 
249 StEventControlPanel __StEventControlPanel__;
250 
251