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