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
40 ClassImp(AliMUONPainterRegistry)
43 AliMUONPainterRegistry* AliMUONPainterRegistry::fgInstance(0x0);
45 //_____________________________________________________________________________
46 AliMUONPainterRegistry::AliMUONPainterRegistry() : TObject(), TQObject(),
47 fPainterMatrices(new TObjArray),
53 fPainterMatrices->SetOwner(kTRUE);
56 //_____________________________________________________________________________
57 AliMUONPainterRegistry::~AliMUONPainterRegistry()
60 delete fPainterMatrices;
63 //_____________________________________________________________________________
65 AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
67 /// Get the index of a given painterMatrix
68 return fPainterMatrices->IndexOf(group);
71 //_____________________________________________________________________________
73 AliMUONPainterRegistry::PainterMatrix(const char* name) const
75 /// Get a painterMatrix by name
76 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
79 //_____________________________________________________________________________
81 AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
83 /// A painterMatrix was chosen from the history menu
85 AliDebug(1,Form("i=%d",i));
87 TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
89 AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
91 PainterMatrixWantToShow(group);
94 //_____________________________________________________________________________
95 AliMUONPainterRegistry*
96 AliMUONPainterRegistry::Instance()
98 /// Get unique instance of this class
99 if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
103 //_____________________________________________________________________________
104 AliMUONPainterMatrix*
105 AliMUONPainterRegistry::PainterMatrix(Int_t i) const
107 /// Get one painter matrix
108 if ( i >= 0 && i <= fPainterMatrices->GetLast() )
110 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
114 AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
119 //_____________________________________________________________________________
121 AliMUONPainterRegistry::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
123 /// A given paintermatrix want to appear on screen
124 Long_t param[] = { (Long_t)group };
126 Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);
129 //_____________________________________________________________________________
131 AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
133 /// Add a matrix to the history
135 if ( !fHistoryMenu && fMenuBar )
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 ?)
140 fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
142 fHistoryMenu->Connect("Activated(Int_t)",
143 "AliMUONPainterRegistry",this,
144 "HistoryMenuActivated(Int_t)");
146 AliDebug(1,Form("HistoryMenu create at %x",fHistoryMenu));
151 TIter next(fHistoryMenu->GetListOfEntries());
154 while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
156 if ( e->GetUserData() == group )
158 fHistoryMenu->DeleteEntry(e);
163 e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
165 fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
169 AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
173 //_____________________________________________________________________________
175 AliMUONPainterRegistry::PainterMatrixWasRegistered(AliMUONPainterMatrix* group)
177 /// A new painter matrix was registered
178 Long_t param[] = { (Long_t)group };
180 Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
183 //_____________________________________________________________________________
185 AliMUONPainterRegistry::PainterMatrixWasUnregistered(AliMUONPainterMatrix* group)
187 /// A painter matrix was unregistered
188 Long_t param[] = { (Long_t)group };
190 Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
193 //_____________________________________________________________________________
195 AliMUONPainterRegistry::Print(Option_t* opt) const
201 cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
203 if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
205 TIter next(fPainterMatrices);
206 AliMUONPainterMatrix* matrix;
208 while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
216 //_____________________________________________________________________________
218 AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
220 /// group is adopted, i.e. the registry becomes the owner of it.
221 fPainterMatrices->AddLast(group);
223 PainterMatrixWasRegistered(group);
225 return fPainterMatrices->IndexOf(group);
228 //_____________________________________________________________________________
230 AliMUONPainterRegistry::NumberOfPainterMatrices() const
232 /// The number of painter matrices we handle
233 return fPainterMatrices->GetLast()+1;
236 //_____________________________________________________________________________
238 AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
240 /// Unregister some matrix
242 if (!group) return kFALSE;
244 PainterMatrixWasUnregistered(group);
246 TObject* o = fPainterMatrices->Remove(group);
253 AliError(Form("Could not unregister group named %s",group->GetName()));