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