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 #include "AliMUONPainterRegistry.h"
20 #include "AliMUONPainterMatrix.h"
21 #include "AliMUONVTrackerData.h"
22 #include "AliMUONVTrackerDataMaker.h"
26 #include <THashList.h>
27 #include <TObjArray.h>
29 #include <Riostream.h>
31 ///\class AliMUONPainterRegistry
33 /// Registry for AliMUONVPainter related stuff : painter data sources
34 /// and painter matrices
36 ///\author Laurent Aphecetche, Subatech
39 ClassImp(AliMUONPainterRegistry)
42 AliMUONPainterRegistry* AliMUONPainterRegistry::fgInstance(0x0);
44 //_____________________________________________________________________________
45 AliMUONPainterRegistry::AliMUONPainterRegistry() : TObject(),
46 fDataSources(new TObjArray),
47 fPainterMatrices(new TObjArray),
48 fDataReaders(new TObjArray),
54 fDataSources->SetOwner(kTRUE);
55 fPainterMatrices->SetOwner(kTRUE);
56 fDataReaders->SetOwner(kTRUE);
59 //_____________________________________________________________________________
60 AliMUONPainterRegistry::~AliMUONPainterRegistry()
64 delete fPainterMatrices;
68 //_____________________________________________________________________________
69 AliMUONVTrackerDataMaker*
70 AliMUONPainterRegistry::DataReader(Int_t i) const
72 /// Get one data source
73 if ( i >= 0 && i <= fDataReaders->GetLast() )
75 return static_cast<AliMUONVTrackerDataMaker*>(fDataReaders->At(i));
79 AliError(Form("Index out of bounds : %d / %d",i,fDataReaders->GetLast()+1));
84 //_____________________________________________________________________________
86 AliMUONPainterRegistry::DataSource(Int_t i) const
88 /// Get one data source
89 if ( i >= 0 && i <= fDataSources->GetLast() )
91 return static_cast<AliMUONVTrackerData*>(fDataSources->At(i));
95 AliError(Form("Index out of bounds : %d / %d",i,fDataSources->GetLast()+1));
100 //_____________________________________________________________________________
102 AliMUONPainterRegistry::DataReaderWasRegistered(AliMUONVTrackerDataMaker* data)
104 /// A new reader source was registered
105 Long_t param[] = { (Long_t)data };
107 Emit("DataReaderWasRegistered(AliMUONVTrackerDataMaker*)",param);
110 //_____________________________________________________________________________
112 AliMUONPainterRegistry::DataReaderWasUnregistered(AliMUONVTrackerDataMaker* data)
114 /// A data reader was unregistered
115 Long_t param[] = { (Long_t)data };
117 Emit("DataReaderWasUnregistered(AliMUONVTrackerDataMaker*)",param);
121 //_____________________________________________________________________________
123 AliMUONPainterRegistry::DataSourceWasRegistered(AliMUONVTrackerData* data)
125 /// A new data source was registered
126 Long_t param[] = { (Long_t)data };
128 Emit("DataSourceWasRegistered(AliMUONVTrackerData*)",param);
131 //_____________________________________________________________________________
133 AliMUONPainterRegistry::DataSourceWasUnregistered(AliMUONVTrackerData* data)
135 /// A data source was unregistered
136 Long_t param[] = { (Long_t)data };
138 Emit("DataSourceWasUnregistered(AliMUONVTrackerData*)",param);
142 //_____________________________________________________________________________
144 AliMUONPainterRegistry::FindDataSource(const char* name) const
146 /// Find a data source by name
147 return static_cast<AliMUONVTrackerData*>(fDataSources->FindObject(name));
150 //_____________________________________________________________________________
152 AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
154 /// Get the index of a given painterMatrix
155 return fPainterMatrices->IndexOf(group);
158 //_____________________________________________________________________________
160 AliMUONPainterRegistry::FindIndexOf(AliMUONVTrackerData* data) const
162 /// Get the index of a given data
163 return fDataSources->IndexOf(data);
166 //_____________________________________________________________________________
167 AliMUONPainterMatrix*
168 AliMUONPainterRegistry::FindPainterMatrix(const char* name) const
170 /// Get a painterMatrix by name
171 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
174 //_____________________________________________________________________________
176 AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
178 /// A painterMatrix was chosen from the history menu
180 AliDebug(1,Form("i=%d",i));
182 TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
184 AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
186 PainterMatrixWantToShow(group);
189 //_____________________________________________________________________________
190 AliMUONPainterRegistry*
191 AliMUONPainterRegistry::Instance()
193 /// Get unique instance of this class
194 if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
198 //_____________________________________________________________________________
199 AliMUONPainterMatrix*
200 AliMUONPainterRegistry::PainterMatrix(Int_t i) const
202 /// Get one painter matrix
203 if ( i >= 0 && i <= fPainterMatrices->GetLast() )
205 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
209 AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
214 //_____________________________________________________________________________
216 AliMUONPainterRegistry::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
218 /// A given paintermatrix want to appear on screen
219 Long_t param[] = { (Long_t)group };
221 Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);
224 //_____________________________________________________________________________
226 AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
228 /// Add a matrix to the history
230 if ( !fHistoryMenu && fMenuBar )
232 fHistoryMenu = new TGPopupMenu(gClient->GetRoot());
233 TGPopupMenu* before = 0x0; //FIXME: could try to find a place where to put it (e.g. before Help ?)
235 fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
237 fHistoryMenu->Connect("Activated(Int_t)",
238 "AliMUONPainterRegistry",this,
239 "HistoryMenuActivated(Int_t)");
241 AliDebug(1,Form("HistoryMenu create at %x",fHistoryMenu));
246 TIter next(fHistoryMenu->GetListOfEntries());
249 while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
251 if ( e->GetUserData() == group )
253 fHistoryMenu->DeleteEntry(e);
258 e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
260 fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
264 AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
268 //_____________________________________________________________________________
270 AliMUONPainterRegistry::PainterMatrixWasRegistered(AliMUONPainterMatrix* group)
272 /// A new painter matrix was registered
273 Long_t param[] = { (Long_t)group };
275 Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
278 //_____________________________________________________________________________
280 AliMUONPainterRegistry::PainterMatrixWasUnregistered(AliMUONPainterMatrix* group)
282 /// A painter matrix was unregistered
283 Long_t param[] = { (Long_t)group };
285 Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
288 //_____________________________________________________________________________
290 AliMUONPainterRegistry::Print(Option_t* opt) const
296 cout << "Number of data sources = " << NumberOfDataSources() << endl;
297 cout << "Number of data readers = " << NumberOfDataReaders() << endl;
298 cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
300 if ( sopt.Contains("FULL") || sopt.Contains("READER") )
302 TIter next(fDataReaders);
303 AliMUONVTrackerDataMaker* reader;
305 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
311 if ( sopt.Contains("FULL") || sopt.Contains("DATA") )
313 TIter next(fDataSources);
314 AliMUONVTrackerData* data;
316 while ( ( data = static_cast<AliMUONVTrackerData*>(next()) ) )
322 if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
324 TIter next(fPainterMatrices);
325 AliMUONPainterMatrix* matrix;
327 while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
335 //_____________________________________________________________________________
337 AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
339 /// group is adopted, i.e. the registry becomes the owner of it.
340 fPainterMatrices->AddLast(group);
342 PainterMatrixWasRegistered(group);
344 return fPainterMatrices->IndexOf(group);
347 //_____________________________________________________________________________
349 AliMUONPainterRegistry::Register(AliMUONVTrackerData* data)
351 /// data is adopted, i.e. the registry becomes the owner of it.
352 fDataSources->AddLast(data);
353 DataSourceWasRegistered(data);
356 //_____________________________________________________________________________
358 AliMUONPainterRegistry::Register(AliMUONVTrackerDataMaker* reader)
360 /// reader is adopted, i.e. the registry becomes the owner of it.
361 fDataReaders->AddLast(reader);
362 DataReaderWasRegistered(reader);
363 Register(reader->Data());
364 reader->SetOwner(kFALSE); // important so data it not deleted twice
367 //_____________________________________________________________________________
369 AliMUONPainterRegistry::NumberOfDataReaders() const
371 /// The number of data readers we handle
372 return fDataReaders->GetLast()+1;
375 //_____________________________________________________________________________
377 AliMUONPainterRegistry::NumberOfDataSources() const
379 /// The number of data soures we handle
380 return fDataSources->GetLast()+1;
383 //_____________________________________________________________________________
385 AliMUONPainterRegistry::NumberOfPainterMatrices() const
387 /// The number of painter matrices we handle
388 return fPainterMatrices->GetLast()+1;
391 //_____________________________________________________________________________
393 AliMUONPainterRegistry::Unregister(AliMUONVTrackerData* data)
395 /// Unregister some data
397 if (!data) return kFALSE;
399 DataSourceWasUnregistered(data);
401 TObject* o = fDataSources->Remove(data);
408 AliError(Form("Could not unregister data named %s title %s",data->GetName(),
414 //_____________________________________________________________________________
416 AliMUONPainterRegistry::Unregister(AliMUONVTrackerDataMaker* reader)
418 /// Unregister some reader
420 if (!reader) return kFALSE;
422 DataReaderWasUnregistered(reader);
424 TObject* o = fDataReaders->Remove(reader);
431 AliError(Form("Could not unregister data named %s title %s",reader->GetName(),
432 reader->GetTitle()));
437 //_____________________________________________________________________________
439 AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
441 /// Unregister some matrix
443 if (!group) return kFALSE;
445 PainterMatrixWasUnregistered(group);
447 TObject* o = fPainterMatrices->Remove(group);
454 AliError(Form("Could not unregister group named %s",group->GetName()));