1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONPainterRegistry.h"
20 #include "AliMpManuIterator.h"
21 #include "AliMUON2DMap.h"
22 #include "AliMUONCalibParamND.h"
23 #include "AliMUONPainterMatrix.h"
27 #include <THashList.h>
28 #include <TObjArray.h>
30 #include <Riostream.h>
32 ///\class AliMUONPainterRegistry
34 /// Registry for AliMUONVPainter related stuff : painter data sources
35 /// and painter matrices
37 ///\author Laurent Aphecetche, Subatech
42 ClassImp(AliMUONPainterRegistry)
45 AliMUONPainterRegistry* AliMUONPainterRegistry::fgInstance(0x0);
47 //_____________________________________________________________________________
48 AliMUONPainterRegistry::AliMUONPainterRegistry() : TObject(), TQObject(),
49 fPainterMatrices(new TObjArray),
55 fPainterMatrices->SetOwner(kTRUE);
58 //_____________________________________________________________________________
59 AliMUONPainterRegistry::~AliMUONPainterRegistry()
62 delete fPainterMatrices;
65 //_____________________________________________________________________________
67 AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
69 /// Get the index of a given painterMatrix
70 return fPainterMatrices->IndexOf(group);
73 //_____________________________________________________________________________
75 AliMUONPainterRegistry::PainterMatrix(const char* name) const
77 /// Get a painterMatrix by name
78 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
81 //_____________________________________________________________________________
83 AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
85 /// A painterMatrix was chosen from the history menu
87 AliDebug(1,Form("i=%d",i));
89 TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
91 AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
93 PainterMatrixWantToShow(group);
96 //_____________________________________________________________________________
97 AliMUONPainterRegistry*
98 AliMUONPainterRegistry::Instance()
100 /// Get unique instance of this class
101 if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
105 //_____________________________________________________________________________
106 AliMUONPainterMatrix*
107 AliMUONPainterRegistry::PainterMatrix(Int_t i) const
109 /// Get one painter matrix
110 if ( i >= 0 && i <= fPainterMatrices->GetLast() )
112 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
116 AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
121 //_____________________________________________________________________________
123 AliMUONPainterRegistry::PainterMatrixWantToShow(const AliMUONPainterMatrix* group)
125 /// A given paintermatrix want to appear on screen
126 Long_t param[] = { (Long_t)group };
128 Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);
131 //_____________________________________________________________________________
133 AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
135 /// Add a matrix to the history
137 if ( !fHistoryMenu && fMenuBar )
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 ?)
142 fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
144 fHistoryMenu->Connect("Activated(Int_t)",
145 "AliMUONPainterRegistry",this,
146 "HistoryMenuActivated(Int_t)");
148 AliDebug(1,Form("HistoryMenu create at %p",fHistoryMenu));
153 TIter next(fHistoryMenu->GetListOfEntries());
156 while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
158 if ( e->GetUserData() == group )
160 fHistoryMenu->DeleteEntry(e);
165 e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
167 fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
171 AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
175 //_____________________________________________________________________________
177 AliMUONPainterRegistry::PainterMatrixWasRegistered(const AliMUONPainterMatrix* group)
179 /// A new painter matrix was registered
180 Long_t param[] = { (Long_t)group };
182 Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
185 //_____________________________________________________________________________
187 AliMUONPainterRegistry::PainterMatrixWasUnregistered(const AliMUONPainterMatrix* group)
189 /// A painter matrix was unregistered
190 Long_t param[] = { (Long_t)group };
192 Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
195 //_____________________________________________________________________________
197 AliMUONPainterRegistry::Print(Option_t* opt) const
203 cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
205 if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
207 TIter next(fPainterMatrices);
208 AliMUONPainterMatrix* matrix;
210 while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
218 //_____________________________________________________________________________
220 AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
222 /// group is adopted, i.e. the registry becomes the owner of it.
223 fPainterMatrices->AddLast(group);
225 PainterMatrixWasRegistered(group);
227 return fPainterMatrices->IndexOf(group);
230 //_____________________________________________________________________________
232 AliMUONPainterRegistry::NumberOfPainterMatrices() const
234 /// The number of painter matrices we handle
235 return fPainterMatrices->GetLast()+1;
238 //_____________________________________________________________________________
240 AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
242 /// Unregister some matrix
244 if (!group) return kFALSE;
246 PainterMatrixWasUnregistered(group);
248 TObject* o = fPainterMatrices->Remove(group);
255 AliError(Form("Could not unregister group named %s",group->GetName()));