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(), TQObject(),
46 fPainterMatrices(new TObjArray),
47 fDataMakers(new TObjArray),
51 fZombies(new TObjArray)
54 fPainterMatrices->SetOwner(kTRUE);
55 fDataMakers->SetOwner(kTRUE);
56 fZombies->SetOwner(kTRUE);
59 //_____________________________________________________________________________
60 AliMUONPainterRegistry::~AliMUONPainterRegistry()
63 delete fPainterMatrices;
67 //_____________________________________________________________________________
68 AliMUONVTrackerDataMaker*
69 AliMUONPainterRegistry::DataMaker(Int_t i) const
71 /// Get one data source
72 if ( i >= 0 && i <= fDataMakers->GetLast() )
74 return static_cast<AliMUONVTrackerDataMaker*>(fDataMakers->At(i));
78 AliError(Form("Index out of bounds : %d / %d",i,fDataMakers->GetLast()+1));
83 //_____________________________________________________________________________
85 AliMUONPainterRegistry::DataSource(Int_t i) const
87 /// Get one data source
89 AliMUONVTrackerDataMaker* maker = DataMaker(i);
90 if ( maker ) return maker->Data();
94 //_____________________________________________________________________________
96 AliMUONPainterRegistry::DataMakerWasRegistered(AliMUONVTrackerDataMaker* data)
98 /// A new reader source was registered
99 Long_t param[] = { (Long_t)data };
101 Emit("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",param);
104 //_____________________________________________________________________________
106 AliMUONPainterRegistry::DataMakerWasUnregistered(AliMUONVTrackerDataMaker* data)
108 /// A data reader was unregistered
109 Long_t param[] = { (Long_t)data };
111 Emit("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",param);
115 //_____________________________________________________________________________
117 AliMUONPainterRegistry::DataSourceWasRegistered(AliMUONVTrackerData* data)
119 /// A new data source was registered
120 Long_t param[] = { (Long_t)data };
122 Emit("DataSourceWasRegistered(AliMUONVTrackerData*)",param);
125 //_____________________________________________________________________________
127 AliMUONPainterRegistry::DataSourceWasUnregistered(AliMUONVTrackerData* data)
129 /// A data source was unregistered
130 Long_t param[] = { (Long_t)data };
132 Emit("DataSourceWasUnregistered(AliMUONVTrackerData*)",param);
136 //_____________________________________________________________________________
138 AliMUONPainterRegistry::DataSource(const char* name) const
140 /// Find a data source by name
141 for ( Int_t i = 0; i < NumberOfDataMakers(); ++i )
143 AliMUONVTrackerData* data = DataMaker(i)->Data();
146 TString dname(data->GetName());
147 if ( dname == name ) return data;
153 //_____________________________________________________________________________
155 AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
157 /// Get the index of a given painterMatrix
158 return fPainterMatrices->IndexOf(group);
161 //_____________________________________________________________________________
162 AliMUONPainterMatrix*
163 AliMUONPainterRegistry::PainterMatrix(const char* name) const
165 /// Get a painterMatrix by name
166 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
169 //_____________________________________________________________________________
171 AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
173 /// A painterMatrix was chosen from the history menu
175 AliDebug(1,Form("i=%d",i));
177 TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
179 AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
181 PainterMatrixWantToShow(group);
184 //_____________________________________________________________________________
185 AliMUONPainterRegistry*
186 AliMUONPainterRegistry::Instance()
188 /// Get unique instance of this class
189 if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
193 //_____________________________________________________________________________
194 AliMUONPainterMatrix*
195 AliMUONPainterRegistry::PainterMatrix(Int_t i) const
197 /// Get one painter matrix
198 if ( i >= 0 && i <= fPainterMatrices->GetLast() )
200 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
204 AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
209 //_____________________________________________________________________________
211 AliMUONPainterRegistry::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
213 /// A given paintermatrix want to appear on screen
214 Long_t param[] = { (Long_t)group };
216 Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);
219 //_____________________________________________________________________________
221 AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
223 /// Add a matrix to the history
225 if ( !fHistoryMenu && fMenuBar )
227 fHistoryMenu = new TGPopupMenu(gClient->GetRoot());
228 TGPopupMenu* before = 0x0; //FIXME: could try to find a place where to put it (e.g. before Help ?)
230 fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
232 fHistoryMenu->Connect("Activated(Int_t)",
233 "AliMUONPainterRegistry",this,
234 "HistoryMenuActivated(Int_t)");
236 AliDebug(1,Form("HistoryMenu create at %x",fHistoryMenu));
241 TIter next(fHistoryMenu->GetListOfEntries());
244 while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
246 if ( e->GetUserData() == group )
248 fHistoryMenu->DeleteEntry(e);
253 e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
255 fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
259 AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
263 //_____________________________________________________________________________
265 AliMUONPainterRegistry::PainterMatrixWasRegistered(AliMUONPainterMatrix* group)
267 /// A new painter matrix was registered
268 Long_t param[] = { (Long_t)group };
270 Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
273 //_____________________________________________________________________________
275 AliMUONPainterRegistry::PainterMatrixWasUnregistered(AliMUONPainterMatrix* group)
277 /// A painter matrix was unregistered
278 Long_t param[] = { (Long_t)group };
280 Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
283 //_____________________________________________________________________________
285 AliMUONPainterRegistry::Print(Option_t* opt) const
291 cout << "Number of data readers = " << NumberOfDataMakers() << endl;
292 cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
294 if ( sopt.Contains("FULL") || sopt.Contains("READER") )
296 TIter next(fDataMakers);
297 AliMUONVTrackerDataMaker* reader;
299 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
305 if ( sopt.Contains("FULL") || sopt.Contains("DATA") )
307 TIter next(fDataMakers);
308 AliMUONVTrackerDataMaker* reader;
310 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
312 AliMUONVTrackerData* data = reader->Data();
313 if ( data ) data->Print();
317 if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
319 TIter next(fPainterMatrices);
320 AliMUONPainterMatrix* matrix;
322 while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
330 //_____________________________________________________________________________
332 AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
334 /// group is adopted, i.e. the registry becomes the owner of it.
335 fPainterMatrices->AddLast(group);
337 PainterMatrixWasRegistered(group);
339 return fPainterMatrices->IndexOf(group);
342 //_____________________________________________________________________________
344 AliMUONPainterRegistry::Register(AliMUONVTrackerDataMaker* reader)
346 /// reader is adopted, i.e. the registry becomes the owner of it.
347 fDataMakers->AddLast(reader);
348 DataMakerWasRegistered(reader);
349 if ( reader->Data() ) DataSourceWasRegistered(reader->Data());
352 //_____________________________________________________________________________
354 AliMUONPainterRegistry::NumberOfDataMakers() const
356 /// The number of data readers we handle
357 return fDataMakers->GetLast()+1;
360 //_____________________________________________________________________________
362 AliMUONPainterRegistry::NumberOfPainterMatrices() const
364 /// The number of painter matrices we handle
365 return fPainterMatrices->GetLast()+1;
368 //_____________________________________________________________________________
370 AliMUONPainterRegistry::DeleteZombies()
376 //_____________________________________________________________________________
378 AliMUONPainterRegistry::Unregister(AliMUONVTrackerDataMaker* reader)
380 /// Unregister some reader
382 if (!reader) return kFALSE;
384 if ( reader->Data() )
386 DataSourceWasUnregistered(reader->Data());
387 reader->Data()->Destroyed(); // we pretend it's deleted now, even
388 // if it will be only later on when zombie are killed, so that
389 // for instance painters depending on it will no longer try to access it
392 DataMakerWasUnregistered(reader);
394 TObject* o = fDataMakers->Remove(reader);
396 fZombies->Add(o); // for later deletion
404 // AliError(Form("Could not unregister data named %s title %s",reader->GetName(),
405 // reader->GetTitle()));
410 //_____________________________________________________________________________
412 AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
414 /// Unregister some matrix
416 if (!group) return kFALSE;
418 PainterMatrixWasUnregistered(group);
420 TObject* o = fPainterMatrices->Remove(group);
427 AliError(Form("Could not unregister group named %s",group->GetName()));