]>
Commit | Line | Data |
---|---|---|
0145e89a | 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 | #include "AliMUONPainterRegistry.h" | |
19 | ||
20 | #include "AliMUONPainterMatrix.h" | |
21 | #include "AliMUONVTrackerData.h" | |
22 | #include "AliMUONVTrackerDataMaker.h" | |
23 | #include "AliLog.h" | |
24 | #include <TGMenu.h> | |
25 | #include <TGWindow.h> | |
26 | #include <THashList.h> | |
27 | #include <TObjArray.h> | |
28 | #include <TString.h> | |
29 | #include <Riostream.h> | |
30 | ||
31 | ///\class AliMUONPainterRegistry | |
32 | /// | |
33 | /// Registry for AliMUONVPainter related stuff : painter data sources | |
34 | /// and painter matrices | |
35 | /// | |
36 | ///\author Laurent Aphecetche, Subatech | |
37 | ||
38 | ///\cond CLASSIMP | |
39 | ClassImp(AliMUONPainterRegistry) | |
40 | ///\endcond | |
41 | ||
42 | AliMUONPainterRegistry* AliMUONPainterRegistry::fgInstance(0x0); | |
43 | ||
44 | //_____________________________________________________________________________ | |
45 | AliMUONPainterRegistry::AliMUONPainterRegistry() : TObject(), | |
46 | fDataSources(new TObjArray), | |
47 | fPainterMatrices(new TObjArray), | |
48 | fDataReaders(new TObjArray), | |
49 | fHistoryMenu(0x0), | |
50 | fMenuBar(0x0), | |
51 | fHistoryCounter(0) | |
52 | { | |
53 | /// ctor | |
54 | fDataSources->SetOwner(kTRUE); | |
55 | fPainterMatrices->SetOwner(kTRUE); | |
56 | fDataReaders->SetOwner(kTRUE); | |
57 | } | |
58 | ||
59 | //_____________________________________________________________________________ | |
60 | AliMUONPainterRegistry::~AliMUONPainterRegistry() | |
61 | { | |
62 | /// dtor | |
63 | delete fDataSources; | |
64 | delete fPainterMatrices; | |
65 | delete fDataReaders; | |
66 | } | |
67 | ||
68 | //_____________________________________________________________________________ | |
69 | AliMUONVTrackerDataMaker* | |
70 | AliMUONPainterRegistry::DataReader(Int_t i) const | |
71 | { | |
72 | /// Get one data source | |
73 | if ( i >= 0 && i <= fDataReaders->GetLast() ) | |
74 | { | |
75 | return static_cast<AliMUONVTrackerDataMaker*>(fDataReaders->At(i)); | |
76 | } | |
77 | else | |
78 | { | |
79 | AliError(Form("Index out of bounds : %d / %d",i,fDataReaders->GetLast()+1)); | |
80 | return 0x0; | |
81 | } | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliMUONVTrackerData* | |
86 | AliMUONPainterRegistry::DataSource(Int_t i) const | |
87 | { | |
88 | /// Get one data source | |
89 | if ( i >= 0 && i <= fDataSources->GetLast() ) | |
90 | { | |
91 | return static_cast<AliMUONVTrackerData*>(fDataSources->At(i)); | |
92 | } | |
93 | else | |
94 | { | |
95 | AliError(Form("Index out of bounds : %d / %d",i,fDataSources->GetLast()+1)); | |
96 | return 0x0; | |
97 | } | |
98 | } | |
99 | ||
100 | //_____________________________________________________________________________ | |
101 | void | |
102 | AliMUONPainterRegistry::DataReaderWasRegistered(AliMUONVTrackerDataMaker* data) | |
103 | { | |
104 | /// A new reader source was registered | |
105 | Long_t param[] = { (Long_t)data }; | |
106 | ||
107 | Emit("DataReaderWasRegistered(AliMUONVTrackerDataMaker*)",param); | |
108 | } | |
109 | ||
110 | //_____________________________________________________________________________ | |
111 | void | |
112 | AliMUONPainterRegistry::DataReaderWasUnregistered(AliMUONVTrackerDataMaker* data) | |
113 | { | |
114 | /// A data reader was unregistered | |
115 | Long_t param[] = { (Long_t)data }; | |
116 | ||
117 | Emit("DataReaderWasUnregistered(AliMUONVTrackerDataMaker*)",param); | |
118 | ||
119 | } | |
120 | ||
121 | //_____________________________________________________________________________ | |
122 | void | |
123 | AliMUONPainterRegistry::DataSourceWasRegistered(AliMUONVTrackerData* data) | |
124 | { | |
125 | /// A new data source was registered | |
126 | Long_t param[] = { (Long_t)data }; | |
127 | ||
128 | Emit("DataSourceWasRegistered(AliMUONVTrackerData*)",param); | |
129 | } | |
130 | ||
131 | //_____________________________________________________________________________ | |
132 | void | |
133 | AliMUONPainterRegistry::DataSourceWasUnregistered(AliMUONVTrackerData* data) | |
134 | { | |
135 | /// A data source was unregistered | |
136 | Long_t param[] = { (Long_t)data }; | |
137 | ||
138 | Emit("DataSourceWasUnregistered(AliMUONVTrackerData*)",param); | |
139 | ||
140 | } | |
141 | ||
142 | //_____________________________________________________________________________ | |
143 | AliMUONVTrackerData* | |
144 | AliMUONPainterRegistry::FindDataSource(const char* name) const | |
145 | { | |
146 | /// Find a data source by name | |
147 | return static_cast<AliMUONVTrackerData*>(fDataSources->FindObject(name)); | |
148 | } | |
149 | ||
150 | //_____________________________________________________________________________ | |
151 | Int_t | |
152 | AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const | |
153 | { | |
154 | /// Get the index of a given painterMatrix | |
155 | return fPainterMatrices->IndexOf(group); | |
156 | } | |
157 | ||
158 | //_____________________________________________________________________________ | |
159 | Int_t | |
160 | AliMUONPainterRegistry::FindIndexOf(AliMUONVTrackerData* data) const | |
161 | { | |
162 | /// Get the index of a given data | |
163 | return fDataSources->IndexOf(data); | |
164 | } | |
165 | ||
166 | //_____________________________________________________________________________ | |
167 | AliMUONPainterMatrix* | |
168 | AliMUONPainterRegistry::FindPainterMatrix(const char* name) const | |
169 | { | |
170 | /// Get a painterMatrix by name | |
171 | return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name)); | |
172 | } | |
173 | ||
174 | //_____________________________________________________________________________ | |
175 | void | |
176 | AliMUONPainterRegistry::HistoryMenuActivated(Int_t i) | |
177 | { | |
178 | /// A painterMatrix was chosen from the history menu | |
179 | ||
180 | AliDebug(1,Form("i=%d",i)); | |
181 | ||
182 | TGMenuEntry* entry = fHistoryMenu->GetEntry(i); | |
183 | ||
184 | AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData()); | |
185 | ||
186 | PainterMatrixWantToShow(group); | |
187 | } | |
188 | ||
189 | //_____________________________________________________________________________ | |
190 | AliMUONPainterRegistry* | |
191 | AliMUONPainterRegistry::Instance() | |
192 | { | |
193 | /// Get unique instance of this class | |
194 | if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry; | |
195 | return fgInstance; | |
196 | } | |
197 | ||
198 | //_____________________________________________________________________________ | |
199 | AliMUONPainterMatrix* | |
200 | AliMUONPainterRegistry::PainterMatrix(Int_t i) const | |
201 | { | |
202 | /// Get one painter matrix | |
203 | if ( i >= 0 && i <= fPainterMatrices->GetLast() ) | |
204 | { | |
205 | return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i)); | |
206 | } | |
207 | else | |
208 | { | |
209 | AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1)); | |
210 | return 0x0; | |
211 | } | |
212 | } | |
213 | ||
214 | //_____________________________________________________________________________ | |
215 | void | |
216 | AliMUONPainterRegistry::PainterMatrixWantToShow(AliMUONPainterMatrix* group) | |
217 | { | |
218 | /// A given paintermatrix want to appear on screen | |
219 | Long_t param[] = { (Long_t)group }; | |
220 | ||
221 | Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param); | |
222 | } | |
223 | ||
224 | //_____________________________________________________________________________ | |
225 | void | |
226 | AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group) | |
227 | { | |
228 | /// Add a matrix to the history | |
229 | ||
230 | if ( !fHistoryMenu && fMenuBar ) | |
231 | { | |
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 ?) | |
234 | ||
235 | fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before); | |
236 | ||
237 | fHistoryMenu->Connect("Activated(Int_t)", | |
238 | "AliMUONPainterRegistry",this, | |
239 | "HistoryMenuActivated(Int_t)"); | |
240 | ||
241 | AliDebug(1,Form("HistoryMenu create at %x",fHistoryMenu)); | |
242 | } | |
243 | ||
244 | if ( fHistoryMenu ) | |
245 | { | |
246 | TIter next(fHistoryMenu->GetListOfEntries()); | |
247 | TGMenuEntry* e(0x0); | |
248 | ||
249 | while ( ( e = static_cast<TGMenuEntry*>(next()) ) ) | |
250 | { | |
251 | if ( e->GetUserData() == group ) | |
252 | { | |
253 | fHistoryMenu->DeleteEntry(e); | |
254 | break; | |
255 | } | |
256 | } | |
257 | ||
258 | e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First()); | |
259 | ||
260 | fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e); | |
261 | } | |
262 | else | |
263 | { | |
264 | AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?"); | |
265 | } | |
266 | } | |
267 | ||
268 | //_____________________________________________________________________________ | |
269 | void | |
270 | AliMUONPainterRegistry::PainterMatrixWasRegistered(AliMUONPainterMatrix* group) | |
271 | { | |
272 | /// A new painter matrix was registered | |
273 | Long_t param[] = { (Long_t)group }; | |
274 | ||
275 | Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param); | |
276 | } | |
277 | ||
278 | //_____________________________________________________________________________ | |
279 | void | |
280 | AliMUONPainterRegistry::PainterMatrixWasUnregistered(AliMUONPainterMatrix* group) | |
281 | { | |
282 | /// A painter matrix was unregistered | |
283 | Long_t param[] = { (Long_t)group }; | |
284 | ||
285 | Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param); | |
286 | } | |
287 | ||
288 | //_____________________________________________________________________________ | |
289 | void | |
290 | AliMUONPainterRegistry::Print(Option_t* opt) const | |
291 | { | |
292 | /// Printout | |
293 | TString sopt(opt); | |
294 | sopt.ToUpper(); | |
295 | ||
296 | cout << "Number of data sources = " << NumberOfDataSources() << endl; | |
297 | cout << "Number of data readers = " << NumberOfDataReaders() << endl; | |
298 | cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl; | |
299 | ||
300 | if ( sopt.Contains("FULL") || sopt.Contains("READER") ) | |
301 | { | |
302 | TIter next(fDataReaders); | |
303 | AliMUONVTrackerDataMaker* reader; | |
304 | ||
305 | while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) ) | |
306 | { | |
307 | reader->Print(); | |
308 | } | |
309 | } | |
310 | ||
311 | if ( sopt.Contains("FULL") || sopt.Contains("DATA") ) | |
312 | { | |
313 | TIter next(fDataSources); | |
314 | AliMUONVTrackerData* data; | |
315 | ||
316 | while ( ( data = static_cast<AliMUONVTrackerData*>(next()) ) ) | |
317 | { | |
318 | data->Print(); | |
319 | } | |
320 | } | |
321 | ||
322 | if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") ) | |
323 | { | |
324 | TIter next(fPainterMatrices); | |
325 | AliMUONPainterMatrix* matrix; | |
326 | ||
327 | while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) ) | |
328 | { | |
329 | matrix->Print(); | |
330 | } | |
331 | } | |
332 | ||
333 | } | |
334 | ||
335 | //_____________________________________________________________________________ | |
336 | Int_t | |
337 | AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group) | |
338 | { | |
339 | /// group is adopted, i.e. the registry becomes the owner of it. | |
340 | fPainterMatrices->AddLast(group); | |
341 | ||
342 | PainterMatrixWasRegistered(group); | |
343 | ||
344 | return fPainterMatrices->IndexOf(group); | |
345 | } | |
346 | ||
347 | //_____________________________________________________________________________ | |
348 | void | |
349 | AliMUONPainterRegistry::Register(AliMUONVTrackerData* data) | |
350 | { | |
351 | /// data is adopted, i.e. the registry becomes the owner of it. | |
352 | fDataSources->AddLast(data); | |
353 | DataSourceWasRegistered(data); | |
354 | } | |
355 | ||
356 | //_____________________________________________________________________________ | |
357 | void | |
358 | AliMUONPainterRegistry::Register(AliMUONVTrackerDataMaker* reader) | |
359 | { | |
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 | |
365 | } | |
366 | ||
367 | //_____________________________________________________________________________ | |
368 | Int_t | |
369 | AliMUONPainterRegistry::NumberOfDataReaders() const | |
370 | { | |
371 | /// The number of data readers we handle | |
372 | return fDataReaders->GetLast()+1; | |
373 | } | |
374 | ||
375 | //_____________________________________________________________________________ | |
376 | Int_t | |
377 | AliMUONPainterRegistry::NumberOfDataSources() const | |
378 | { | |
379 | /// The number of data soures we handle | |
380 | return fDataSources->GetLast()+1; | |
381 | } | |
382 | ||
383 | //_____________________________________________________________________________ | |
384 | Int_t | |
385 | AliMUONPainterRegistry::NumberOfPainterMatrices() const | |
386 | { | |
387 | /// The number of painter matrices we handle | |
388 | return fPainterMatrices->GetLast()+1; | |
389 | } | |
390 | ||
391 | //_____________________________________________________________________________ | |
392 | Bool_t | |
393 | AliMUONPainterRegistry::Unregister(AliMUONVTrackerData* data) | |
394 | { | |
395 | /// Unregister some data | |
396 | ||
397 | if (!data) return kFALSE; | |
398 | ||
399 | DataSourceWasUnregistered(data); | |
400 | ||
401 | TObject* o = fDataSources->Remove(data); | |
402 | if ( o ) | |
403 | { | |
404 | delete o; | |
405 | } | |
406 | else | |
407 | { | |
408 | AliError(Form("Could not unregister data named %s title %s",data->GetName(), | |
409 | data->GetTitle())); | |
410 | } | |
411 | return ( o != 0x0 ); | |
412 | } | |
413 | ||
414 | //_____________________________________________________________________________ | |
415 | Bool_t | |
416 | AliMUONPainterRegistry::Unregister(AliMUONVTrackerDataMaker* reader) | |
417 | { | |
418 | /// Unregister some reader | |
419 | ||
420 | if (!reader) return kFALSE; | |
421 | ||
422 | DataReaderWasUnregistered(reader); | |
423 | ||
424 | TObject* o = fDataReaders->Remove(reader); | |
425 | if ( o ) | |
426 | { | |
427 | delete o; | |
428 | } | |
429 | else | |
430 | { | |
431 | AliError(Form("Could not unregister data named %s title %s",reader->GetName(), | |
432 | reader->GetTitle())); | |
433 | } | |
434 | return ( o != 0x0 ); | |
435 | } | |
436 | ||
437 | //_____________________________________________________________________________ | |
438 | Bool_t | |
439 | AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group) | |
440 | { | |
441 | /// Unregister some matrix | |
442 | ||
443 | if (!group) return kFALSE; | |
444 | ||
445 | PainterMatrixWasUnregistered(group); | |
446 | ||
447 | TObject* o = fPainterMatrices->Remove(group); | |
448 | if ( o ) | |
449 | { | |
450 | delete o; | |
451 | } | |
452 | else | |
453 | { | |
454 | AliError(Form("Could not unregister group named %s",group->GetName())); | |
455 | } | |
456 | return ( o != 0x0 ); | |
457 | } |