]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterRegistry.cxx
Separating run-dependent mapping data from data, which are not
[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   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);
91 }
92
93 //_____________________________________________________________________________
94 AliMUONVTrackerDataMaker* 
95 AliMUONPainterRegistry::DataMaker(Int_t i) const
96 {
97   /// Get one data source
98   if ( i >= 0 && i <= fDataMakers->GetLast() )
99   {
100     return static_cast<AliMUONVTrackerDataMaker*>(fDataMakers->At(i));
101   }
102   else
103   {
104     AliError(Form("Index out of bounds : %d / %d",i,fDataMakers->GetLast()+1));
105     return 0x0;
106   }
107 }
108
109 //_____________________________________________________________________________
110 AliMUONVTrackerData* 
111 AliMUONPainterRegistry::DataSource(Int_t i) const
112 {
113   /// Get one data source
114   
115   AliMUONVTrackerDataMaker* maker = DataMaker(i);
116   if ( maker ) return maker->Data();
117   return 0x0;
118 }
119
120 //_____________________________________________________________________________
121 void 
122 AliMUONPainterRegistry::DataMakerWasRegistered(AliMUONVTrackerDataMaker* data)
123 {
124   /// A new reader source was registered
125   Long_t param[] = { (Long_t)data };
126   
127   Emit("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",param);
128 }
129
130 //_____________________________________________________________________________
131 void
132 AliMUONPainterRegistry::DataMakerWasUnregistered(AliMUONVTrackerDataMaker* data)
133 {
134   /// A data reader was unregistered
135   Long_t param[] = { (Long_t)data };
136   
137   Emit("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",param);
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*
164 AliMUONPainterRegistry::DataSource(const char* name) const
165 {
166   /// Find a data source by name
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;
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
187 //_____________________________________________________________________________
188 AliMUONPainterMatrix*
189 AliMUONPainterRegistry::PainterMatrix(const char* name) const
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
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
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   
328   cout << "Number of data readers = " << NumberOfDataMakers() << endl;
329   cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
330   
331   if ( sopt.Contains("FULL") || sopt.Contains("READER") )
332   {
333     TIter next(fDataMakers);
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   {
344     TIter next(fDataMakers);
345     AliMUONVTrackerDataMaker* reader;
346     
347     while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
348     {
349       AliMUONVTrackerData* data = reader->Data();
350       if ( data ) data->Print();
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
379 //_____________________________________________________________________________
380 void
381 AliMUONPainterRegistry::Register(AliMUONVTrackerDataMaker* reader)
382 {
383   /// reader is adopted, i.e. the registry becomes the owner of it.
384   fDataMakers->AddLast(reader);
385   DataMakerWasRegistered(reader);
386   if ( reader->Data() ) DataSourceWasRegistered(reader->Data());
387 }
388
389 //_____________________________________________________________________________
390 Int_t 
391 AliMUONPainterRegistry::NumberOfDataMakers() const
392 {
393   /// The number of data readers we handle
394   return fDataMakers->GetLast()+1;
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 //_____________________________________________________________________________
406 void 
407 AliMUONPainterRegistry::DeleteZombies()
408 {
409   /// Delete zombies
410   fZombies->Delete();
411 }
412
413 //_____________________________________________________________________________
414 Bool_t 
415 AliMUONPainterRegistry::Unregister(AliMUONVTrackerDataMaker* reader)
416 {
417   /// Unregister some reader
418   
419   if (!reader) return kFALSE;
420   
421   if ( reader->Data() ) 
422   {
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
427   }
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 //  }
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 }