Fixes for #86059: Install data when ALICE_ROOT does not point to source (Christian)
[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 "AliLog.h"
25 #include <TGMenu.h>
26 #include <TGWindow.h>
27 #include <THashList.h>
28 #include <TObjArray.h>
29 #include <TString.h>
30 #include <Riostream.h>
31
32 ///\class AliMUONPainterRegistry
33 ///
34 /// Registry for AliMUONVPainter related stuff : painter data sources
35 /// and painter matrices
36 ///
37 ///\author Laurent Aphecetche, Subatech
38
39 ///\cond CLASSIMP
40 ClassImp(AliMUONPainterRegistry)
41 ///\endcond
42
43 AliMUONPainterRegistry* AliMUONPainterRegistry::fgInstance(0x0);
44
45 //_____________________________________________________________________________
46 AliMUONPainterRegistry::AliMUONPainterRegistry() : TObject(), TQObject(),
47 fPainterMatrices(new TObjArray),
48 fHistoryMenu(0x0),
49 fMenuBar(0x0),
50 fHistoryCounter(0)
51 {
52   /// ctor
53   fPainterMatrices->SetOwner(kTRUE);
54 }
55
56 //_____________________________________________________________________________
57 AliMUONPainterRegistry::~AliMUONPainterRegistry()
58 {
59   /// dtor
60   delete fPainterMatrices;
61 }
62
63 //_____________________________________________________________________________
64 Int_t 
65 AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
66 {
67   /// Get the index of a given painterMatrix
68   return fPainterMatrices->IndexOf(group);
69 }
70
71 //_____________________________________________________________________________
72 AliMUONPainterMatrix*
73 AliMUONPainterRegistry::PainterMatrix(const char* name) const
74 {
75   /// Get a painterMatrix by name
76   return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
77 }
78
79 //_____________________________________________________________________________
80 void
81 AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
82 {
83   /// A painterMatrix was chosen from the history menu
84   
85   AliDebug(1,Form("i=%d",i));
86   
87   TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
88   
89   AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
90   
91   PainterMatrixWantToShow(group);
92 }
93
94 //_____________________________________________________________________________
95 AliMUONPainterRegistry*
96 AliMUONPainterRegistry::Instance()
97 {
98   /// Get unique instance of this class
99   if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
100   return fgInstance;
101 }
102
103 //_____________________________________________________________________________
104 AliMUONPainterMatrix* 
105 AliMUONPainterRegistry::PainterMatrix(Int_t i) const
106 {
107   /// Get one painter matrix
108   if ( i >= 0 && i <= fPainterMatrices->GetLast() )
109   {
110     return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
111   }
112   else
113   {
114     AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
115     return 0x0;
116   }
117 }
118
119 //_____________________________________________________________________________
120 void 
121 AliMUONPainterRegistry::PainterMatrixWantToShow(const AliMUONPainterMatrix* group)
122 {
123   /// A given paintermatrix want to appear on screen
124   Long_t param[] = { (Long_t)group };
125   
126   Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);  
127 }
128
129 //_____________________________________________________________________________
130 void
131 AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
132 {
133   /// Add a matrix to the history
134   
135   if ( !fHistoryMenu && fMenuBar ) 
136   {
137     fHistoryMenu =  new TGPopupMenu(gClient->GetRoot());
138     TGPopupMenu* before = 0x0; //FIXME: could try to find a place where to put it (e.g. before Help ?)
139     
140     fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
141     
142     fHistoryMenu->Connect("Activated(Int_t)",
143                           "AliMUONPainterRegistry",this,
144                           "HistoryMenuActivated(Int_t)");
145     
146     AliDebug(1,Form("HistoryMenu create at %p",fHistoryMenu));
147   }
148   
149   if ( fHistoryMenu ) 
150   {
151     TIter next(fHistoryMenu->GetListOfEntries());
152     TGMenuEntry* e(0x0);
153     
154     while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
155     {
156       if ( e->GetUserData() == group ) 
157       {
158         fHistoryMenu->DeleteEntry(e);
159         break;
160       }
161     }
162     
163     e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
164     
165     fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
166   }
167   else
168   {
169     AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
170   }
171 }
172
173 //_____________________________________________________________________________
174 void 
175 AliMUONPainterRegistry::PainterMatrixWasRegistered(const AliMUONPainterMatrix* group)
176 {
177   /// A new painter matrix was registered
178   Long_t param[] = { (Long_t)group };
179   
180   Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
181 }
182
183 //_____________________________________________________________________________
184 void 
185 AliMUONPainterRegistry::PainterMatrixWasUnregistered(const AliMUONPainterMatrix* group)
186 {
187   /// A painter matrix was unregistered
188   Long_t param[] = { (Long_t)group };
189   
190   Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
191 }
192
193 //_____________________________________________________________________________
194 void 
195 AliMUONPainterRegistry::Print(Option_t* opt) const
196 {
197   /// Printout
198   TString sopt(opt);
199   sopt.ToUpper();
200   
201   cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
202   
203   if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
204   {
205     TIter next(fPainterMatrices);
206     AliMUONPainterMatrix* matrix;
207     
208     while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
209     {
210       matrix->Print();
211     }
212   }
213   
214 }
215
216 //_____________________________________________________________________________
217 Int_t
218 AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
219 {
220   /// group is adopted, i.e. the registry becomes the owner of it.
221   fPainterMatrices->AddLast(group);
222   
223   PainterMatrixWasRegistered(group);
224   
225   return fPainterMatrices->IndexOf(group);
226 }
227
228 //_____________________________________________________________________________
229 Int_t 
230 AliMUONPainterRegistry::NumberOfPainterMatrices() const
231 {
232   /// The number of painter matrices we handle
233   return fPainterMatrices->GetLast()+1;
234 }
235
236 //_____________________________________________________________________________
237 Bool_t 
238 AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
239 {
240   /// Unregister some matrix
241   
242   if (!group) return kFALSE;
243   
244   PainterMatrixWasUnregistered(group);
245   
246   TObject* o = fPainterMatrices->Remove(group);
247   if ( o ) 
248   {
249     delete o;
250   }
251   else
252   {
253     AliError(Form("Could not unregister group named %s",group->GetName()));
254   }
255   return ( o != 0x0 );
256 }