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