Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 :
16 : // $Id$
17 :
18 : /// \class AliMUONPainterPlotSelector
19 : ///
20 : /// Widget to select which data to plot for painters
21 : ///
22 : /// \author Laurent Aphecetche
23 : ///
24 : /// See AliMUONPainterInterfaceHelper for an important implementation note
25 : /// about our use of TGButtonGroup
26 : ///
27 :
28 : #include "AliMUONPainterPlotSelector.h"
29 :
30 : #include "AliMUONPainterGroup.h"
31 : #include "AliMUONPainterInterfaceHelper.h"
32 : #include "AliMUONPainterMatrix.h"
33 : #include "AliMUONPainterDataRegistry.h"
34 : #include "AliMUONVPainter.h"
35 : #include "AliMUONVTrackerData.h"
36 : #include "AliLog.h"
37 : #include <Riostream.h>
38 : #include <TGButton.h>
39 : #include <TGButtonGroup.h>
40 : #include <TObjArray.h>
41 : #include <TObjString.h>
42 :
43 : ///\cond CLASSIMP
44 12 : ClassImp(AliMUONPainterPlotSelector)
45 : ///\endcond
46 :
47 : const char* AliMUONPainterPlotSelector::fgkDefaultSourceName = "none";
48 :
49 : //_____________________________________________________________________________
50 : AliMUONPainterPlotSelector::AliMUONPainterPlotSelector(const TGWindow* window, UInt_t w, UInt_t h)
51 0 : : TGCompositeFrame(window,w,h,kHorizontalFrame),
52 0 : fTypes(0x0),
53 0 : fDataSourceNames(0x0),
54 0 : fDataSourceDimensions(0x0),
55 0 : fDimensionButtonMap(new TMap),
56 0 : fCurrentType(""),
57 0 : fCurrentData(0x0),
58 0 : fCurrentDimension(-1)
59 0 : {
60 : /// ctor
61 0 : fTypes = new TGButtonGroup(this,"Plot");
62 :
63 0 : fDataSourceNames = new TGButtonGroup(this,"Sources");
64 :
65 0 : AliMUONPainterDataRegistry* reg = AliMUONPainterDataRegistry::Instance();
66 :
67 0 : reg->Connect("DataSourceWasRegistered(AliMUONVTrackerData*)",
68 : "AliMUONPainterPlotSelector",
69 : this,
70 : "DataSourceWasRegistered(AliMUONVTrackerData*)");
71 :
72 0 : reg->Connect("DataSourceWasUnregistered(AliMUONVTrackerData*)",
73 : "AliMUONPainterPlotSelector",
74 : this,
75 : "DataSourceWasUnregistered(AliMUONVTrackerData*)");
76 :
77 0 : AliMUONPainterInterfaceHelper::AddRadioButton(*fDataSourceNames,
78 0 : fgkDefaultSourceName,
79 : 0x0,
80 : kTRUE);
81 :
82 0 : CreateDimensionButtons(fgkDefaultSourceName);
83 :
84 0 : fDataSourceDimensions = new TGButtonGroup(this,0,3,5,0,"Dimensions");
85 :
86 0 : for ( Int_t i = 0; i < reg->NumberOfDataSources(); ++i )
87 : {
88 0 : AliMUONVTrackerData* data = reg->DataSource(i);
89 0 : DataSourceWasRegistered(data);
90 : }
91 :
92 0 : fDataSourceNames->Connect("Clicked(Int_t)","AliMUONPainterPlotSelector",
93 : this,
94 : "SourceButtonWasClicked(Int_t)");
95 :
96 0 : AddFrame(fTypes);
97 0 : AddFrame(fDataSourceNames);
98 0 : AddFrame(fDataSourceDimensions);
99 0 : }
100 :
101 : //_____________________________________________________________________________
102 0 : AliMUONPainterPlotSelector::~AliMUONPainterPlotSelector()
103 0 : {
104 : /// dtor
105 0 : }
106 :
107 : //_____________________________________________________________________________
108 : void
109 : AliMUONPainterPlotSelector::BackupDimensionButtons()
110 : {
111 : /// Backup the dimension button group
112 :
113 0 : TString name = fDataSourceDimensions->GetTitle();
114 :
115 0 : if ( name != fgkDefaultSourceName )
116 : {
117 0 : TGButtonGroup* group = static_cast<TGButtonGroup*>(fDimensionButtonMap->GetValue(name));
118 0 : if (!group)
119 : {
120 0 : AliError(Form("Did not find group %s",name.Data()));
121 : }
122 : else
123 : {
124 0 : AliMUONPainterInterfaceHelper::Copy(*fDataSourceDimensions,*group);
125 : }
126 :
127 0 : }
128 :
129 0 : fDataSourceDimensions->Disconnect("Clicked(Int_t)",
130 0 : this,
131 : "DimensionButtonWasClicked(Int_t)");
132 0 : }
133 :
134 :
135 : //_____________________________________________________________________________
136 : void
137 : AliMUONPainterPlotSelector::CreateDimensionButtons(const char* dataSourceName)
138 : {
139 : /// Create the dimension button group for a given data source
140 :
141 0 : AliMUONVTrackerData* data = AliMUONPainterDataRegistry::Instance()->DataSource(dataSourceName);
142 :
143 0 : TGButtonGroup* bg = new TGButtonGroup(this,0,3,5,0,dataSourceName);
144 :
145 0 : if ( data )
146 : {
147 0 : for ( Int_t i = 0; i < data->NumberOfDimensions(); ++i )
148 : {
149 0 : AliMUONPainterInterfaceHelper::AddRadioButton(*bg,
150 0 : data->DimensionName(i),
151 0 : reinterpret_cast<void*>(i));
152 : }
153 0 : }
154 :
155 0 : fDimensionButtonMap->Add(new TObjString(dataSourceName),bg);
156 :
157 0 : bg->Connect("Clicked(Int_t)","AliMUONPainterPlotSelector",this,
158 : "DimensionButtonWasClicked(Int_t)");
159 0 : }
160 :
161 : //_____________________________________________________________________________
162 : void
163 : AliMUONPainterPlotSelector::CreateTypeButtons(const TObjArray& types)
164 : {
165 : /// Create the type button group
166 :
167 0 : AliMUONPainterInterfaceHelper::ClearButtons(*fTypes);
168 :
169 0 : TIter nextType(&types);
170 : TObjString* str;
171 :
172 0 : while ( ( str = static_cast<TObjString*>(nextType()) ) )
173 : {
174 0 : AliMUONPainterInterfaceHelper::AddRadioButton(*fTypes,str->String());
175 : }
176 :
177 0 : fTypes->Connect("Clicked(Int_t)","AliMUONPainterPlotSelector",this,
178 : "TypeButtonWasClicked(Int_t)");
179 :
180 0 : fTypes->Show();
181 0 : }
182 :
183 : //_____________________________________________________________________________
184 : void
185 : AliMUONPainterPlotSelector::DataSourceWasChanged()
186 : {
187 : /// Data source was changed
188 0 : DataSourceWasChanged(fCurrentType.Data(),fCurrentData,fCurrentDimension);
189 0 : }
190 :
191 : //_____________________________________________________________________________
192 : void
193 : AliMUONPainterPlotSelector::DataSourceWasChanged(const char* type,
194 : AliMUONVTrackerData* data,
195 : Int_t dataIndex)
196 : {
197 : /// Emit a signal to tell data source was changed
198 :
199 0 : UpdateTypeButton();
200 :
201 0 : Long_t param[] = { (Long_t)type, (Long_t)data,
202 0 : (Long_t)dataIndex };
203 :
204 0 : Emit("DataSourceWasChanged(const char*,AliMUONVTrackerData*,Int_t)",param);
205 0 : }
206 :
207 : //_____________________________________________________________________________
208 : void
209 : AliMUONPainterPlotSelector::DataSourceWasRegistered(AliMUONVTrackerData* data)
210 : {
211 : /// A new data source has been registered : add it to the interface
212 :
213 0 : AliMUONPainterInterfaceHelper::AddRadioButton(*fDataSourceNames,
214 0 : data->GetName(),
215 0 : data);
216 :
217 0 : data->Connect("NumberOfEventsChanged()",
218 : "AliMUONPainterPlotSelector",
219 0 : this,
220 : "NumberOfEventsChanged()");
221 :
222 0 : CreateDimensionButtons(data->GetName());
223 :
224 0 : fDataSourceNames->Show();
225 :
226 0 : Layout();
227 0 : }
228 :
229 : //_____________________________________________________________________________
230 : void
231 : AliMUONPainterPlotSelector::NumberOfEventsChanged()
232 : {
233 : /// Change the tool tip of the corresponding data source button
234 :
235 : // find first the sender of the signal
236 :
237 : // AliMUONVTrackerData* data = reinterpret_cast<AliMUONVTrackerData*>(gTQSender);
238 : //
239 : // TGButton* button = AliMUONPainterInterfaceHelper::FindButtonByUserData(*fDataSourceNames,data);
240 : //
241 : // if (button)
242 : // {
243 : // button->SetToolTipText(Form("%d events",data->NumberOfEvents()),250);
244 : // }
245 0 : }
246 :
247 : //_____________________________________________________________________________
248 : void
249 : AliMUONPainterPlotSelector::DataSourceWasUnregistered(AliMUONVTrackerData* data)
250 : {
251 : /// A data source has been unregistered : remove it from the interface
252 :
253 0 : TGButton* button = AliMUONPainterInterfaceHelper::FindButtonByUserData(*fDataSourceNames,data);
254 :
255 0 : TGButton* bd = AliMUONPainterInterfaceHelper::FindDownButton(*fDataSourceNames);
256 :
257 0 : if ( bd == button )
258 : {
259 : // selected data source is the one we are removing...
260 : // revert to "none" before actually removing it.
261 0 : SourceButtonWasClicked(1);
262 0 : }
263 :
264 0 : AliMUONPainterInterfaceHelper::RemoveButton(*fDataSourceNames,button);
265 :
266 : // do not forget to re-connect things
267 0 : fDataSourceNames->Connect("Clicked(Int_t)","AliMUONPainterPlotSelector",
268 0 : this,
269 : "SourceButtonWasClicked(Int_t)");
270 :
271 :
272 0 : TObject* o = fDimensionButtonMap->Remove(new TObjString(data->GetName()));
273 :
274 0 : if (!o)
275 : {
276 0 : AliError("Remove failed. Please check");
277 0 : }
278 :
279 0 : fDataSourceNames->Show();
280 :
281 0 : Layout();
282 0 : }
283 :
284 : //_____________________________________________________________________________
285 : void
286 : AliMUONPainterPlotSelector::DimensionButtonWasClicked(Int_t id)
287 : {
288 : /// One dim button was clicked
289 :
290 0 : TGTextButton* button = (TGTextButton*)fDataSourceDimensions->GetButton(id);
291 :
292 0 : SetCurrentDimension(reinterpret_cast<Long_t>(button->GetUserData()));
293 :
294 0 : if ( fCurrentDimension >= 0 )
295 : {
296 0 : AliMUONPainterInterfaceHelper::SetState(*fTypes,kTRUE);
297 0 : AliMUONPainterInterfaceHelper::Select(*fTypes,fCurrentType.Data(),kFALSE);
298 0 : fTypes->Show();
299 0 : }
300 :
301 0 : DataSourceWasChanged();
302 0 : }
303 :
304 : //_____________________________________________________________________________
305 : void
306 : AliMUONPainterPlotSelector::ResetDimensionButtonMap()
307 : {
308 : /// Reset the button group map
309 :
310 0 : TIter next(fDimensionButtonMap);
311 : TObjString* str;
312 :
313 0 : while ( ( str = static_cast<TObjString*>(next()) ) )
314 : {
315 0 : TGButtonGroup* bg = static_cast<TGButtonGroup*>(fDimensionButtonMap->GetValue(str->String()));
316 0 : AliMUONPainterInterfaceHelper::Unselect(*bg,"*");
317 : }
318 0 : }
319 :
320 : //_____________________________________________________________________________
321 : void
322 : AliMUONPainterPlotSelector::RestoreDimensionButtons(const char* dataSourceName,
323 : Bool_t updateCurrentDimension)
324 : {
325 : /// Restore (i.e. contrary of Backup) a given dimension button group
326 :
327 0 : TGButtonGroup* group = static_cast<TGButtonGroup*>(fDimensionButtonMap->GetValue(dataSourceName));
328 :
329 0 : AliMUONPainterInterfaceHelper::Copy(*group,*fDataSourceDimensions);
330 :
331 0 : fDataSourceDimensions->Connect("Clicked(Int_t)",
332 0 : "AliMUONPainterPlotSelector",this,
333 : "DimensionButtonWasClicked(Int_t)");
334 :
335 0 : if ( updateCurrentDimension )
336 : {
337 0 : TGButton* button = AliMUONPainterInterfaceHelper::FindDownButton(*fDataSourceDimensions);
338 0 : if ( button )
339 : {
340 0 : SetCurrentDimension(reinterpret_cast<Long_t>(button->GetUserData()));
341 0 : }
342 : else
343 : {
344 0 : SetCurrentDimension(-1);
345 : }
346 0 : }
347 :
348 0 : fDataSourceDimensions->Show();
349 0 : }
350 :
351 : //_____________________________________________________________________________
352 : void
353 : AliMUONPainterPlotSelector::SetCurrentData(AliMUONVTrackerData* data)
354 : {
355 : /// Set the current data pointer
356 0 : fCurrentData = data;
357 0 : }
358 :
359 : //_____________________________________________________________________________
360 : void
361 : AliMUONPainterPlotSelector::SetCurrentDimension(Long_t i)
362 : {
363 : /// Set the current dimension
364 0 : fCurrentDimension = i;
365 0 : }
366 :
367 : //_____________________________________________________________________________
368 : void
369 : AliMUONPainterPlotSelector::SetCurrentType(const char* type)
370 : {
371 : /// Set the current type
372 0 : fCurrentType = type;
373 0 : }
374 :
375 : //_____________________________________________________________________________
376 : void
377 : AliMUONPainterPlotSelector::SourceButtonWasClicked(Int_t id)
378 : {
379 : /// A source button was clicked
380 :
381 0 : BackupDimensionButtons();
382 :
383 0 : TGButton* button = fDataSourceNames->GetButton(id);
384 0 : if ( !button )
385 : {
386 0 : AliFatal(Form("Could not get DataSource button id=%d",id));
387 0 : }
388 :
389 0 : AliMUONVTrackerData* data = reinterpret_cast<AliMUONVTrackerData*>(button->GetUserData());
390 :
391 0 : TString name = data ? data->GetName() : fgkDefaultSourceName;
392 :
393 0 : RestoreDimensionButtons(name,kTRUE);
394 :
395 0 : if ( data != 0 &&
396 0 : fCurrentDimension >= 0 &&
397 0 : fCurrentDimension < (Long_t)(data->NumberOfDimensions()) )
398 : {
399 0 : AliMUONPainterInterfaceHelper::SetState(*fTypes,kTRUE);
400 : }
401 : else
402 : {
403 0 : AliMUONPainterInterfaceHelper::SetState(*fTypes,kFALSE);
404 : }
405 :
406 0 : SetCurrentData(data);
407 :
408 0 : UpdateTypeButton();
409 :
410 0 : fDataSourceNames->Show();
411 0 : fDataSourceDimensions->Show();
412 0 : fTypes->Show();
413 :
414 0 : Resize();
415 0 : Layout();
416 :
417 0 : DataSourceWasChanged();
418 0 : }
419 :
420 : //_____________________________________________________________________________
421 : void
422 : AliMUONPainterPlotSelector::TypeButtonWasClicked(Int_t id)
423 : {
424 : /// A type button was clicked
425 0 : TGTextButton* button = (TGTextButton*)fTypes->GetButton(id);
426 0 : SetCurrentType(button->GetTitle());
427 0 : DataSourceWasChanged();
428 0 : }
429 :
430 : //_____________________________________________________________________________
431 : void AliMUONPainterPlotSelector::Update(const AliMUONPainterMatrix& painterMatrix)
432 : {
433 : /// Update ourselves from a new painter matrix
434 :
435 0 : SetCurrentType("");
436 0 : SetCurrentData(0x0);
437 0 : SetCurrentDimension(-1);
438 :
439 0 : AliMUONPainterInterfaceHelper::Unselect(*fDataSourceNames,"*");
440 0 : AliMUONPainterInterfaceHelper::Unselect(*fDataSourceDimensions,"*");
441 :
442 0 : ResetDimensionButtonMap();
443 :
444 0 : TObjArray types;
445 0 : types.SetOwner(kTRUE);
446 0 : painterMatrix.GetTypes(types);
447 0 : CreateTypeButtons(types);
448 :
449 0 : if ( painterMatrix.Size() > 0 )
450 : {
451 0 : AliMUONVPainter* painter = painterMatrix.Painter(painterMatrix.Size()-1);
452 :
453 0 : AliMUONPainterGroup* plotterGroup = painter->PlotterGroup();
454 :
455 0 : if ( plotterGroup )
456 : {
457 : // the group have some data to plot, so update our internal pointers
458 : // to reflect that
459 0 : SetCurrentData(plotterGroup->Data());
460 0 : SetCurrentDimension(plotterGroup->DataIndex());
461 0 : SetCurrentType(plotterGroup->Type());
462 : }
463 0 : }
464 :
465 : // the *order* of the 3 following lines is *very* important
466 :
467 0 : UpdateSourceButton();
468 0 : UpdateDimensionButton();
469 0 : UpdateTypeButton();
470 :
471 0 : Resize();
472 0 : Layout();
473 0 : }
474 :
475 : //_____________________________________________________________________________
476 : void
477 : AliMUONPainterPlotSelector::UpdateDimensionButton()
478 : {
479 : /// Update the dim buttons
480 :
481 0 : TGTextButton* button = static_cast<TGTextButton*>
482 0 : (AliMUONPainterInterfaceHelper::FindButtonByUserData(*fDataSourceDimensions,
483 0 : reinterpret_cast<void*>(fCurrentDimension)));
484 :
485 0 : if ( button )
486 : {
487 : // set this button as "ON"
488 0 : AliMUONPainterInterfaceHelper::Select(*fDataSourceDimensions,button->GetTitle());
489 0 : }
490 : else
491 : {
492 0 : AliMUONPainterInterfaceHelper::Unselect(*fDataSourceDimensions,"*");
493 : }
494 :
495 0 : fDataSourceDimensions->Show();
496 0 : }
497 :
498 : //_____________________________________________________________________________
499 : void
500 : AliMUONPainterPlotSelector::UpdateSourceButton()
501 : {
502 : /// Update the source buttons
503 :
504 0 : TGTextButton* button = static_cast<TGTextButton*>
505 0 : (AliMUONPainterInterfaceHelper::FindButtonByUserData(*fDataSourceNames,
506 0 : fCurrentData));
507 :
508 0 : if ( button )
509 : {
510 0 : AliMUONPainterInterfaceHelper::Select(*fDataSourceNames,button->GetTitle());
511 :
512 0 : RestoreDimensionButtons(button->GetTitle(),kFALSE);
513 0 : }
514 :
515 0 : fDataSourceNames->Show();
516 0 : }
517 :
518 : //_____________________________________________________________________________
519 : void
520 : AliMUONPainterPlotSelector::UpdateTypeButton()
521 : {
522 : /// Update the type buttons
523 :
524 0 : if (!fCurrentData)
525 : {
526 0 : AliMUONPainterInterfaceHelper::SetState(*fTypes,kFALSE);
527 0 : }
528 : else
529 : {
530 : // disable levels that cannot be handled by this data
531 0 : TGTextButton* padButton = static_cast<TGTextButton*>
532 0 : (AliMUONPainterInterfaceHelper::FindButtonByName(*fTypes,"PAD"));
533 0 : if (padButton)
534 : {
535 0 : padButton->SetEnabled(fCurrentData->IsChannelLevelEnabled());
536 0 : }
537 0 : TGTextButton* manuButton = static_cast<TGTextButton*>
538 0 : (AliMUONPainterInterfaceHelper::FindButtonByName(*fTypes,"MANU"));
539 0 : if (manuButton)
540 : {
541 0 : manuButton->SetEnabled(fCurrentData->IsManuLevelEnabled());
542 0 : }
543 0 : TGTextButton* busPatchButton = static_cast<TGTextButton*>
544 0 : (AliMUONPainterInterfaceHelper::FindButtonByName(*fTypes,"BUSPATCH"));
545 0 : if (busPatchButton)
546 : {
547 0 : busPatchButton->SetEnabled(fCurrentData->IsBusPatchLevelEnabled());
548 0 : }
549 0 : TGTextButton* pcbButton = static_cast<TGTextButton*>
550 0 : (AliMUONPainterInterfaceHelper::FindButtonByName(*fTypes,"PCB"));
551 0 : if (pcbButton)
552 : {
553 0 : pcbButton->SetEnabled(fCurrentData->IsPCBLevelEnabled());
554 0 : }
555 :
556 : }
557 :
558 0 : TGTextButton* button = static_cast<TGTextButton*>
559 0 : (AliMUONPainterInterfaceHelper::FindButtonByName(*fTypes,fCurrentType));
560 :
561 0 : if ( button )
562 : {
563 0 : AliMUONPainterInterfaceHelper::Select(*fTypes,button->GetTitle());
564 0 : }
565 : else
566 : {
567 0 : AliMUONPainterInterfaceHelper::Unselect(*fTypes,"*");
568 : }
569 :
570 :
571 0 : fTypes->Show();
572 0 : }
573 :
|