]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPainterRegistry.cxx
adding script to retrieve all datapoints for testing purposes
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterRegistry.cxx
CommitLineData
0145e89a 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 "AliMUONPainterMatrix.h"
21#include "AliMUONVTrackerData.h"
22#include "AliMUONVTrackerDataMaker.h"
23#include "AliLog.h"
24#include <TGMenu.h>
25#include <TGWindow.h>
26#include <THashList.h>
27#include <TObjArray.h>
28#include <TString.h>
29#include <Riostream.h>
30
31///\class AliMUONPainterRegistry
32///
33/// Registry for AliMUONVPainter related stuff : painter data sources
34/// and painter matrices
35///
36///\author Laurent Aphecetche, Subatech
37
38///\cond CLASSIMP
39ClassImp(AliMUONPainterRegistry)
40///\endcond
41
42AliMUONPainterRegistry* AliMUONPainterRegistry::fgInstance(0x0);
43
44//_____________________________________________________________________________
4a3224ff 45AliMUONPainterRegistry::AliMUONPainterRegistry() : TObject(), TQObject(),
0145e89a 46fPainterMatrices(new TObjArray),
49419555 47fDataMakers(new TObjArray),
0145e89a 48fHistoryMenu(0x0),
49fMenuBar(0x0),
49419555 50fHistoryCounter(0),
51fZombies(new TObjArray)
0145e89a 52{
53 /// ctor
0145e89a 54 fPainterMatrices->SetOwner(kTRUE);
49419555 55 fDataMakers->SetOwner(kTRUE);
56 fZombies->SetOwner(kTRUE);
0145e89a 57}
58
59//_____________________________________________________________________________
60AliMUONPainterRegistry::~AliMUONPainterRegistry()
61{
62 /// dtor
0145e89a 63 delete fPainterMatrices;
49419555 64 delete fDataMakers;
0145e89a 65}
66
67//_____________________________________________________________________________
68AliMUONVTrackerDataMaker*
49419555 69AliMUONPainterRegistry::DataMaker(Int_t i) const
0145e89a 70{
71 /// Get one data source
49419555 72 if ( i >= 0 && i <= fDataMakers->GetLast() )
0145e89a 73 {
49419555 74 return static_cast<AliMUONVTrackerDataMaker*>(fDataMakers->At(i));
0145e89a 75 }
76 else
77 {
49419555 78 AliError(Form("Index out of bounds : %d / %d",i,fDataMakers->GetLast()+1));
0145e89a 79 return 0x0;
80 }
81}
82
83//_____________________________________________________________________________
84AliMUONVTrackerData*
85AliMUONPainterRegistry::DataSource(Int_t i) const
86{
87 /// Get one data source
49419555 88
89 AliMUONVTrackerDataMaker* maker = DataMaker(i);
90 if ( maker ) return maker->Data();
91 return 0x0;
0145e89a 92}
93
94//_____________________________________________________________________________
95void
49419555 96AliMUONPainterRegistry::DataMakerWasRegistered(AliMUONVTrackerDataMaker* data)
0145e89a 97{
98 /// A new reader source was registered
99 Long_t param[] = { (Long_t)data };
100
49419555 101 Emit("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",param);
0145e89a 102}
103
104//_____________________________________________________________________________
105void
49419555 106AliMUONPainterRegistry::DataMakerWasUnregistered(AliMUONVTrackerDataMaker* data)
0145e89a 107{
108 /// A data reader was unregistered
109 Long_t param[] = { (Long_t)data };
110
49419555 111 Emit("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",param);
0145e89a 112
113}
114
115//_____________________________________________________________________________
116void
117AliMUONPainterRegistry::DataSourceWasRegistered(AliMUONVTrackerData* data)
118{
119 /// A new data source was registered
120 Long_t param[] = { (Long_t)data };
121
122 Emit("DataSourceWasRegistered(AliMUONVTrackerData*)",param);
123}
124
125//_____________________________________________________________________________
126void
127AliMUONPainterRegistry::DataSourceWasUnregistered(AliMUONVTrackerData* data)
128{
129 /// A data source was unregistered
130 Long_t param[] = { (Long_t)data };
131
132 Emit("DataSourceWasUnregistered(AliMUONVTrackerData*)",param);
133
134}
135
136//_____________________________________________________________________________
137AliMUONVTrackerData*
49419555 138AliMUONPainterRegistry::DataSource(const char* name) const
0145e89a 139{
140 /// Find a data source by name
49419555 141 for ( Int_t i = 0; i < NumberOfDataMakers(); ++i )
142 {
143 AliMUONVTrackerData* data = DataMaker(i)->Data();
144 if ( data )
145 {
146 TString dname(data->GetName());
147 if ( dname == name ) return data;
148 }
149 }
150 return 0x0;
0145e89a 151}
152
153//_____________________________________________________________________________
154Int_t
155AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
156{
157 /// Get the index of a given painterMatrix
158 return fPainterMatrices->IndexOf(group);
159}
160
0145e89a 161//_____________________________________________________________________________
162AliMUONPainterMatrix*
49419555 163AliMUONPainterRegistry::PainterMatrix(const char* name) const
0145e89a 164{
165 /// Get a painterMatrix by name
166 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
167}
168
169//_____________________________________________________________________________
170void
171AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
172{
173 /// A painterMatrix was chosen from the history menu
174
175 AliDebug(1,Form("i=%d",i));
176
177 TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
178
179 AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
180
181 PainterMatrixWantToShow(group);
182}
183
184//_____________________________________________________________________________
185AliMUONPainterRegistry*
186AliMUONPainterRegistry::Instance()
187{
188 /// Get unique instance of this class
189 if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
190 return fgInstance;
191}
192
193//_____________________________________________________________________________
194AliMUONPainterMatrix*
195AliMUONPainterRegistry::PainterMatrix(Int_t i) const
196{
197 /// Get one painter matrix
198 if ( i >= 0 && i <= fPainterMatrices->GetLast() )
199 {
200 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
201 }
202 else
203 {
204 AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
205 return 0x0;
206 }
207}
208
209//_____________________________________________________________________________
210void
211AliMUONPainterRegistry::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
212{
213 /// A given paintermatrix want to appear on screen
214 Long_t param[] = { (Long_t)group };
215
216 Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);
217}
218
219//_____________________________________________________________________________
220void
221AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
222{
223 /// Add a matrix to the history
224
225 if ( !fHistoryMenu && fMenuBar )
226 {
227 fHistoryMenu = new TGPopupMenu(gClient->GetRoot());
228 TGPopupMenu* before = 0x0; //FIXME: could try to find a place where to put it (e.g. before Help ?)
229
230 fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
231
232 fHistoryMenu->Connect("Activated(Int_t)",
233 "AliMUONPainterRegistry",this,
234 "HistoryMenuActivated(Int_t)");
235
236 AliDebug(1,Form("HistoryMenu create at %x",fHistoryMenu));
237 }
238
239 if ( fHistoryMenu )
240 {
241 TIter next(fHistoryMenu->GetListOfEntries());
242 TGMenuEntry* e(0x0);
243
244 while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
245 {
246 if ( e->GetUserData() == group )
247 {
248 fHistoryMenu->DeleteEntry(e);
249 break;
250 }
251 }
252
253 e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
254
255 fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
256 }
257 else
258 {
259 AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
260 }
261}
262
263//_____________________________________________________________________________
264void
265AliMUONPainterRegistry::PainterMatrixWasRegistered(AliMUONPainterMatrix* group)
266{
267 /// A new painter matrix was registered
268 Long_t param[] = { (Long_t)group };
269
270 Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
271}
272
273//_____________________________________________________________________________
274void
275AliMUONPainterRegistry::PainterMatrixWasUnregistered(AliMUONPainterMatrix* group)
276{
277 /// A painter matrix was unregistered
278 Long_t param[] = { (Long_t)group };
279
280 Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
281}
282
283//_____________________________________________________________________________
284void
285AliMUONPainterRegistry::Print(Option_t* opt) const
286{
287 /// Printout
288 TString sopt(opt);
289 sopt.ToUpper();
290
49419555 291 cout << "Number of data readers = " << NumberOfDataMakers() << endl;
0145e89a 292 cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
293
294 if ( sopt.Contains("FULL") || sopt.Contains("READER") )
295 {
49419555 296 TIter next(fDataMakers);
0145e89a 297 AliMUONVTrackerDataMaker* reader;
298
299 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
300 {
301 reader->Print();
302 }
303 }
304
305 if ( sopt.Contains("FULL") || sopt.Contains("DATA") )
306 {
49419555 307 TIter next(fDataMakers);
308 AliMUONVTrackerDataMaker* reader;
309
310 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
0145e89a 311 {
49419555 312 AliMUONVTrackerData* data = reader->Data();
313 if ( data ) data->Print();
0145e89a 314 }
315 }
316
317 if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
318 {
319 TIter next(fPainterMatrices);
320 AliMUONPainterMatrix* matrix;
321
322 while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
323 {
324 matrix->Print();
325 }
326 }
327
328}
329
330//_____________________________________________________________________________
331Int_t
332AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
333{
334 /// group is adopted, i.e. the registry becomes the owner of it.
335 fPainterMatrices->AddLast(group);
336
337 PainterMatrixWasRegistered(group);
338
339 return fPainterMatrices->IndexOf(group);
340}
341
0145e89a 342//_____________________________________________________________________________
343void
344AliMUONPainterRegistry::Register(AliMUONVTrackerDataMaker* reader)
345{
346 /// reader is adopted, i.e. the registry becomes the owner of it.
49419555 347 fDataMakers->AddLast(reader);
348 DataMakerWasRegistered(reader);
349 if ( reader->Data() ) DataSourceWasRegistered(reader->Data());
0145e89a 350}
351
352//_____________________________________________________________________________
353Int_t
49419555 354AliMUONPainterRegistry::NumberOfDataMakers() const
0145e89a 355{
356 /// The number of data readers we handle
49419555 357 return fDataMakers->GetLast()+1;
0145e89a 358}
359
360//_____________________________________________________________________________
361Int_t
362AliMUONPainterRegistry::NumberOfPainterMatrices() const
363{
364 /// The number of painter matrices we handle
365 return fPainterMatrices->GetLast()+1;
366}
367
368//_____________________________________________________________________________
49419555 369void
370AliMUONPainterRegistry::DeleteZombies()
0145e89a 371{
49419555 372 /// Delete zombies
373 fZombies->Delete();
0145e89a 374}
375
376//_____________________________________________________________________________
377Bool_t
378AliMUONPainterRegistry::Unregister(AliMUONVTrackerDataMaker* reader)
379{
380 /// Unregister some reader
381
382 if (!reader) return kFALSE;
383
49419555 384 if ( reader->Data() )
0145e89a 385 {
49419555 386 DataSourceWasUnregistered(reader->Data());
387 reader->Data()->Destroyed(); // we pretend it's deleted now, even
388 // if it will be only later on when zombie are killed, so that
389 // for instance painters depending on it will no longer try to access it
0145e89a 390 }
49419555 391
392 DataMakerWasUnregistered(reader);
393
394 TObject* o = fDataMakers->Remove(reader);
395
396 fZombies->Add(o); // for later deletion
397
398// if ( o )
399// {
400// delete o;
401// }
402// else
403// {
404// AliError(Form("Could not unregister data named %s title %s",reader->GetName(),
405// reader->GetTitle()));
406// }
0145e89a 407 return ( o != 0x0 );
408}
409
410//_____________________________________________________________________________
411Bool_t
412AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
413{
414 /// Unregister some matrix
415
416 if (!group) return kFALSE;
417
418 PainterMatrixWasUnregistered(group);
419
420 TObject* o = fPainterMatrices->Remove(group);
421 if ( o )
422 {
423 delete o;
424 }
425 else
426 {
427 AliError(Form("Could not unregister group named %s",group->GetName()));
428 }
429 return ( o != 0x0 );
430}