1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// \class AliMUONPainterPlotSelector
20 /// Widget to select which data to plot for painters
22 /// \author Laurent Aphecetche
24 /// See AliMUONPainterInterfaceHelper for an important implementation note
25 /// about our use of TGButtonGroup
28 #include "AliMUONPainterPlotSelector.h"
30 #include "AliMUONPainterGroup.h"
31 #include "AliMUONPainterInterfaceHelper.h"
32 #include "AliMUONPainterMatrix.h"
33 #include "AliMUONPainterDataRegistry.h"
34 #include "AliMUONVPainter.h"
35 #include "AliMUONVTrackerData.h"
37 #include <Riostream.h>
39 #include <TGButtonGroup.h>
40 #include <TObjArray.h>
41 #include <TObjString.h>
44 ClassImp(AliMUONPainterPlotSelector)
47 const char* AliMUONPainterPlotSelector::fgkDefaultSourceName = "none";
49 //_____________________________________________________________________________
50 AliMUONPainterPlotSelector::AliMUONPainterPlotSelector(const TGWindow* window, UInt_t w, UInt_t h)
51 : TGCompositeFrame(window,w,h,kHorizontalFrame),
53 fDataSourceNames(0x0),
54 fDataSourceDimensions(0x0),
55 fDimensionButtonMap(new TMap),
61 fTypes = new TGButtonGroup(this,"Plot");
63 fDataSourceNames = new TGButtonGroup(this,"Sources");
65 AliMUONPainterDataRegistry* reg = AliMUONPainterDataRegistry::Instance();
67 reg->Connect("DataSourceWasRegistered(AliMUONVTrackerData*)",
68 "AliMUONPainterPlotSelector",
70 "DataSourceWasRegistered(AliMUONVTrackerData*)");
72 reg->Connect("DataSourceWasUnregistered(AliMUONVTrackerData*)",
73 "AliMUONPainterPlotSelector",
75 "DataSourceWasUnregistered(AliMUONVTrackerData*)");
77 AliMUONPainterInterfaceHelper::AddRadioButton(*fDataSourceNames,
82 CreateDimensionButtons(fgkDefaultSourceName);
84 fDataSourceDimensions = new TGButtonGroup(this,0,3,5,0,"Dimensions");
86 for ( Int_t i = 0; i < reg->NumberOfDataSources(); ++i )
88 AliMUONVTrackerData* data = reg->DataSource(i);
89 DataSourceWasRegistered(data);
92 fDataSourceNames->Connect("Clicked(Int_t)","AliMUONPainterPlotSelector",
94 "SourceButtonWasClicked(Int_t)");
97 AddFrame(fDataSourceNames);
98 AddFrame(fDataSourceDimensions);
101 //_____________________________________________________________________________
102 AliMUONPainterPlotSelector::~AliMUONPainterPlotSelector()
107 //_____________________________________________________________________________
109 AliMUONPainterPlotSelector::BackupDimensionButtons()
111 /// Backup the dimension button group
113 TString name = fDataSourceDimensions->GetTitle();
115 AliDebug(1,Form("name %s",name.Data()));
117 if ( name != fgkDefaultSourceName )
119 TGButtonGroup* group = static_cast<TGButtonGroup*>(fDimensionButtonMap->GetValue(name));
122 AliError(Form("Did not find group %s",name.Data()));
126 AliMUONPainterInterfaceHelper::Copy(*fDataSourceDimensions,*group);
131 fDataSourceDimensions->Disconnect("Clicked(Int_t)",
133 "DimensionButtonWasClicked(Int_t)");
137 //_____________________________________________________________________________
139 AliMUONPainterPlotSelector::CreateDimensionButtons(const char* dataSourceName)
141 /// Create the dimension button group for a given data source
143 AliDebug(1,Form("Creating dimension buttons for dataSource %s",dataSourceName));
145 AliMUONVTrackerData* data = AliMUONPainterDataRegistry::Instance()->DataSource(dataSourceName);
147 TGButtonGroup* bg = new TGButtonGroup(this,0,3,5,0,dataSourceName);
151 for ( Int_t i = 0; i < data->NumberOfDimensions(); ++i )
153 AliMUONPainterInterfaceHelper::AddRadioButton(*bg,
154 data->DimensionName(i),
155 reinterpret_cast<void*>(i));
159 fDimensionButtonMap->Add(new TObjString(dataSourceName),bg);
161 AliDebug(1,Form("bg is %p Count=%d",bg,bg->GetCount()));
162 StdoutToAliDebug(1,AliMUONPainterInterfaceHelper::Dump(*bg));
164 bg->Connect("Clicked(Int_t)","AliMUONPainterPlotSelector",this,
165 "DimensionButtonWasClicked(Int_t)");
168 //_____________________________________________________________________________
170 AliMUONPainterPlotSelector::CreateTypeButtons(const TObjArray& types)
172 /// Create the type button group
174 AliMUONPainterInterfaceHelper::ClearButtons(*fTypes);
176 TIter nextType(&types);
179 while ( ( str = static_cast<TObjString*>(nextType()) ) )
181 AliMUONPainterInterfaceHelper::AddRadioButton(*fTypes,str->String());
184 fTypes->Connect("Clicked(Int_t)","AliMUONPainterPlotSelector",this,
185 "TypeButtonWasClicked(Int_t)");
190 //_____________________________________________________________________________
192 AliMUONPainterPlotSelector::DataSourceWasChanged()
194 /// Data source was changed
195 DataSourceWasChanged(fCurrentType.Data(),fCurrentData,fCurrentDimension);
198 //_____________________________________________________________________________
200 AliMUONPainterPlotSelector::DataSourceWasChanged(const char* type,
201 AliMUONVTrackerData* data,
204 /// Emit a signal to tell data source was changed
205 AliDebug(1,Form("type=%s data=%s (%s)",
207 ( data ? data->GetName() : "" ),
208 ( ( data && dataIndex >= 0 ) ? data->DimensionName(dataIndex).Data() :
213 Long_t param[] = { (Long_t)type, (Long_t)data,
216 Emit("DataSourceWasChanged(const char*,AliMUONVTrackerData*,Int_t)",param);
219 //_____________________________________________________________________________
221 AliMUONPainterPlotSelector::DataSourceWasRegistered(AliMUONVTrackerData* data)
223 /// A new data source has been registered : add it to the interface
225 AliDebug(1,Form("Registering %s",data->GetName()));
227 AliMUONPainterInterfaceHelper::AddRadioButton(*fDataSourceNames,
231 data->Connect("NumberOfEventsChanged()",
232 "AliMUONPainterPlotSelector",
234 "NumberOfEventsChanged()");
236 CreateDimensionButtons(data->GetName());
238 fDataSourceNames->Show();
243 //_____________________________________________________________________________
245 AliMUONPainterPlotSelector::NumberOfEventsChanged()
247 /// Change the tool tip of the corresponding data source button
249 // find first the sender of the signal
251 // AliMUONVTrackerData* data = reinterpret_cast<AliMUONVTrackerData*>(gTQSender);
253 // TGButton* button = AliMUONPainterInterfaceHelper::FindButtonByUserData(*fDataSourceNames,data);
257 // button->SetToolTipText(Form("%d events",data->NumberOfEvents()),250);
261 //_____________________________________________________________________________
263 AliMUONPainterPlotSelector::DataSourceWasUnregistered(AliMUONVTrackerData* data)
265 /// A data source has been unregistered : remove it from the interface
267 TGButton* button = AliMUONPainterInterfaceHelper::FindButtonByUserData(*fDataSourceNames,data);
269 TGButton* bd = AliMUONPainterInterfaceHelper::FindDownButton(*fDataSourceNames);
273 // selected data source is the one we are removing...
274 // revert to "none" before actually removing it.
275 SourceButtonWasClicked(1);
278 AliMUONPainterInterfaceHelper::RemoveButton(*fDataSourceNames,button);
280 // do not forget to re-connect things
281 fDataSourceNames->Connect("Clicked(Int_t)","AliMUONPainterPlotSelector",
283 "SourceButtonWasClicked(Int_t)");
286 TObject* o = fDimensionButtonMap->Remove(new TObjString(data->GetName()));
290 AliError("Remove failed. Please check");
293 fDataSourceNames->Show();
298 //_____________________________________________________________________________
300 AliMUONPainterPlotSelector::DimensionButtonWasClicked(Int_t id)
302 /// One dim button was clicked
304 AliDebug(1,Form("id=%d",id));
306 TGTextButton* button = (TGTextButton*)fDataSourceDimensions->GetButton(id);
308 SetCurrentDimension(reinterpret_cast<Long_t>(button->GetUserData()));
310 if ( fCurrentDimension >= 0 )
312 AliMUONPainterInterfaceHelper::SetState(*fTypes,kTRUE);
313 AliMUONPainterInterfaceHelper::Select(*fTypes,fCurrentType.Data(),kFALSE);
317 AliDebug(1,Form("fCurrentDimension=%ld fCurrentData=%p fCurrentType=%s",
318 fCurrentDimension,fCurrentData,fCurrentType.Data()));
320 DataSourceWasChanged();
323 //_____________________________________________________________________________
325 AliMUONPainterPlotSelector::ResetDimensionButtonMap()
327 /// Reset the button group map
329 TIter next(fDimensionButtonMap);
332 while ( ( str = static_cast<TObjString*>(next()) ) )
334 TGButtonGroup* bg = static_cast<TGButtonGroup*>(fDimensionButtonMap->GetValue(str->String()));
335 AliMUONPainterInterfaceHelper::Unselect(*bg,"*");
339 //_____________________________________________________________________________
341 AliMUONPainterPlotSelector::RestoreDimensionButtons(const char* dataSourceName,
342 Bool_t updateCurrentDimension)
344 /// Restore (i.e. contrary of Backup) a given dimension button group
346 AliDebug(1,Form("name %s",dataSourceName));
347 TGButtonGroup* group = static_cast<TGButtonGroup*>(fDimensionButtonMap->GetValue(dataSourceName));
349 AliMUONPainterInterfaceHelper::Copy(*group,*fDataSourceDimensions);
351 fDataSourceDimensions->Connect("Clicked(Int_t)",
352 "AliMUONPainterPlotSelector",this,
353 "DimensionButtonWasClicked(Int_t)");
355 if ( updateCurrentDimension )
357 TGButton* button = AliMUONPainterInterfaceHelper::FindDownButton(*fDataSourceDimensions);
360 SetCurrentDimension(reinterpret_cast<Long_t>(button->GetUserData()));
364 SetCurrentDimension(-1);
368 fDataSourceDimensions->Show();
371 //_____________________________________________________________________________
373 AliMUONPainterPlotSelector::SetCurrentData(AliMUONVTrackerData* data)
375 /// Set the current data pointer
376 AliDebug(1,Form("fCurrentData %p -> %p",fCurrentData,data));
380 //_____________________________________________________________________________
382 AliMUONPainterPlotSelector::SetCurrentDimension(Long_t i)
384 /// Set the current dimension
385 AliDebug(1,Form("fCurrentDimension %ld -> %ld",fCurrentDimension,i));
386 fCurrentDimension = i;
389 //_____________________________________________________________________________
391 AliMUONPainterPlotSelector::SetCurrentType(const char* type)
393 /// Set the current type
394 AliDebug(1,Form("fCurrentType %s -> %s",fCurrentType.Data(),type));
398 //_____________________________________________________________________________
400 AliMUONPainterPlotSelector::SourceButtonWasClicked(Int_t id)
402 /// A source button was clicked
403 AliDebug(1,Form("BEGIN id %d fCurrentDimension=%ld fCurrentData=%p fCurrentType=%s",
405 fCurrentDimension,fCurrentData,fCurrentType.Data()));
407 BackupDimensionButtons();
409 TGButton* button = fDataSourceNames->GetButton(id);
412 AliError(Form("Could not get DataSource button id=%d",id));
413 StdoutToAliDebug(1,AliMUONPainterInterfaceHelper::Dump(*fDataSourceNames));
414 button->GetUserData(); // to trigger a crash so gdb is possible ;-)
417 AliMUONVTrackerData* data = reinterpret_cast<AliMUONVTrackerData*>(button->GetUserData());
419 TString name = data ? data->GetName() : fgkDefaultSourceName;
421 RestoreDimensionButtons(name,kTRUE);
424 fCurrentDimension >= 0 &&
425 fCurrentDimension < (Long_t)(data->NumberOfDimensions()) )
427 AliMUONPainterInterfaceHelper::SetState(*fTypes,kTRUE);
431 AliMUONPainterInterfaceHelper::SetState(*fTypes,kFALSE);
434 SetCurrentData(data);
438 fDataSourceNames->Show();
439 fDataSourceDimensions->Show();
445 AliDebug(1,Form("END fCurrentDimension=%ld fCurrentData=%p fCurrentType=%s",
446 fCurrentDimension,fCurrentData,fCurrentType.Data()));
448 DataSourceWasChanged();
451 //_____________________________________________________________________________
453 AliMUONPainterPlotSelector::TypeButtonWasClicked(Int_t id)
455 /// A type button was clicked
456 AliDebug(1,Form("fCurrentDimension=%ld fCurrentData=%p",
457 fCurrentDimension,fCurrentData));
459 TGTextButton* button = (TGTextButton*)fTypes->GetButton(id);
460 SetCurrentType(button->GetTitle());
462 AliDebug(1,Form("fCurrentType=%s",fCurrentType.Data()));
464 DataSourceWasChanged();
467 //_____________________________________________________________________________
468 void AliMUONPainterPlotSelector::Update(const AliMUONPainterMatrix& painterMatrix)
470 /// Update ourselves from a new painter matrix
476 SetCurrentDimension(-1);
478 AliMUONPainterInterfaceHelper::Unselect(*fDataSourceNames,"*");
479 AliMUONPainterInterfaceHelper::Unselect(*fDataSourceDimensions,"*");
481 ResetDimensionButtonMap();
484 types.SetOwner(kTRUE);
485 painterMatrix.GetTypes(types);
486 CreateTypeButtons(types);
488 if ( painterMatrix.Size() > 0 )
490 AliMUONVPainter* painter = painterMatrix.Painter(painterMatrix.Size()-1);
492 AliMUONPainterGroup* plotterGroup = painter->PlotterGroup();
496 // the group have some data to plot, so update our internal pointers
498 SetCurrentData(plotterGroup->Data());
499 SetCurrentDimension(plotterGroup->DataIndex());
500 SetCurrentType(plotterGroup->Type());
504 AliDebug(1,Form("After update type=%s data=%p dim=%ld",
505 fCurrentType.Data(),fCurrentData,fCurrentDimension));
507 // the *order* of the 3 following lines is *very* important
509 AliDebug(1,"Will update source buttons");
510 UpdateSourceButton();
511 AliDebug(1,"Will update dimension buttons");
512 UpdateDimensionButton();
513 AliDebug(1,"Will update type buttons");
519 AliDebug(1,Form("END fCurrentType=%s fCurrentData=%p fCurrentDimension=%ld",
520 fCurrentType.Data(),fCurrentData,
524 //_____________________________________________________________________________
526 AliMUONPainterPlotSelector::UpdateDimensionButton()
528 /// Update the dim buttons
530 TGTextButton* button = static_cast<TGTextButton*>
531 (AliMUONPainterInterfaceHelper::FindButtonByUserData(*fDataSourceDimensions,
532 reinterpret_cast<void*>(fCurrentDimension)));
536 // set this button as "ON"
537 AliMUONPainterInterfaceHelper::Select(*fDataSourceDimensions,button->GetTitle());
541 AliMUONPainterInterfaceHelper::Unselect(*fDataSourceDimensions,"*");
544 fDataSourceDimensions->Show();
547 //_____________________________________________________________________________
549 AliMUONPainterPlotSelector::UpdateSourceButton()
551 /// Update the source buttons
553 TGTextButton* button = static_cast<TGTextButton*>
554 (AliMUONPainterInterfaceHelper::FindButtonByUserData(*fDataSourceNames,
559 AliMUONPainterInterfaceHelper::Select(*fDataSourceNames,button->GetTitle());
561 RestoreDimensionButtons(button->GetTitle(),kFALSE);
564 fDataSourceNames->Show();
567 //_____________________________________________________________________________
569 AliMUONPainterPlotSelector::UpdateTypeButton()
571 /// Update the type buttons
573 AliDebug(1,Form("fCurrentType=%s",fCurrentType.Data()));
577 AliMUONPainterInterfaceHelper::SetState(*fTypes,kFALSE);
581 // disable levels that cannot be handled by this data
582 TGTextButton* padButton = static_cast<TGTextButton*>
583 (AliMUONPainterInterfaceHelper::FindButtonByName(*fTypes,"PAD"));
586 padButton->SetEnabled(fCurrentData->IsChannelLevelEnabled());
588 TGTextButton* manuButton = static_cast<TGTextButton*>
589 (AliMUONPainterInterfaceHelper::FindButtonByName(*fTypes,"MANU"));
592 manuButton->SetEnabled(fCurrentData->IsManuLevelEnabled());
597 TGTextButton* button = static_cast<TGTextButton*>
598 (AliMUONPainterInterfaceHelper::FindButtonByName(*fTypes,fCurrentType));
602 AliMUONPainterInterfaceHelper::Select(*fTypes,button->GetTitle());
606 AliMUONPainterInterfaceHelper::Unselect(*fTypes,"*");