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