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"
24 #include "AliMUONTrackerData.h"
25 #include "AliMUONVTrackerDataMaker.h"
29 #include <THashList.h>
30 #include <TObjArray.h>
32 #include <Riostream.h>
34 ///\class AliMUONPainterRegistry
36 /// Registry for AliMUONVPainter related stuff : painter data sources
37 /// and painter matrices
39 ///\author Laurent Aphecetche, Subatech
42 ClassImp(AliMUONPainterRegistry)
45 AliMUONPainterRegistry* AliMUONPainterRegistry::fgInstance(0x0);
47 //_____________________________________________________________________________
48 AliMUONPainterRegistry::AliMUONPainterRegistry() : TObject(), TQObject(),
49 fPainterMatrices(new TObjArray),
50 fDataMakers(new TObjArray),
54 fZombies(new TObjArray),
55 fInteractiveReadOutConfig(0x0)
58 fPainterMatrices->SetOwner(kTRUE);
59 fDataMakers->SetOwner(kTRUE);
60 fZombies->SetOwner(kTRUE);
63 //_____________________________________________________________________________
64 AliMUONPainterRegistry::~AliMUONPainterRegistry()
67 delete fPainterMatrices;
69 delete fInteractiveReadOutConfig;
72 //_____________________________________________________________________________
74 AliMUONPainterRegistry::CreateInteractiveReadOutConfig() const
76 fInteractiveReadOutConfig = new AliMUONTrackerData("IROC","IROC",1);
77 fInteractiveReadOutConfig->SetDimensionName(0,"Switch");
78 /// FIXME: should use a version of TrackerData w/ no storage for channels
79 /// (i.e. starting at the manu level, or even bus patch level ?)
83 AliMUON2DMap store(true);
85 while ( it.Next(detElemId,manuId) )
87 AliMUONVCalibParam* param = new AliMUONCalibParamND(1,64,detElemId,manuId,1);
90 fInteractiveReadOutConfig->Add(store);
93 //_____________________________________________________________________________
94 AliMUONVTrackerDataMaker*
95 AliMUONPainterRegistry::DataMaker(Int_t i) const
97 /// Get one data source
98 if ( i >= 0 && i <= fDataMakers->GetLast() )
100 return static_cast<AliMUONVTrackerDataMaker*>(fDataMakers->At(i));
104 AliError(Form("Index out of bounds : %d / %d",i,fDataMakers->GetLast()+1));
109 //_____________________________________________________________________________
111 AliMUONPainterRegistry::DataSource(Int_t i) const
113 /// Get one data source
115 AliMUONVTrackerDataMaker* maker = DataMaker(i);
116 if ( maker ) return maker->Data();
120 //_____________________________________________________________________________
122 AliMUONPainterRegistry::DataMakerWasRegistered(AliMUONVTrackerDataMaker* data)
124 /// A new reader source was registered
125 Long_t param[] = { (Long_t)data };
127 Emit("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",param);
130 //_____________________________________________________________________________
132 AliMUONPainterRegistry::DataMakerWasUnregistered(AliMUONVTrackerDataMaker* data)
134 /// A data reader was unregistered
135 Long_t param[] = { (Long_t)data };
137 Emit("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",param);
141 //_____________________________________________________________________________
143 AliMUONPainterRegistry::DataSourceWasRegistered(AliMUONVTrackerData* data)
145 /// A new data source was registered
146 Long_t param[] = { (Long_t)data };
148 Emit("DataSourceWasRegistered(AliMUONVTrackerData*)",param);
151 //_____________________________________________________________________________
153 AliMUONPainterRegistry::DataSourceWasUnregistered(AliMUONVTrackerData* data)
155 /// A data source was unregistered
156 Long_t param[] = { (Long_t)data };
158 Emit("DataSourceWasUnregistered(AliMUONVTrackerData*)",param);
162 //_____________________________________________________________________________
164 AliMUONPainterRegistry::DataSource(const char* name) const
166 /// Find a data source by name
167 for ( Int_t i = 0; i < NumberOfDataMakers(); ++i )
169 AliMUONVTrackerData* data = DataMaker(i)->Data();
172 TString dname(data->GetName());
173 if ( dname == name ) return data;
179 //_____________________________________________________________________________
181 AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
183 /// Get the index of a given painterMatrix
184 return fPainterMatrices->IndexOf(group);
187 //_____________________________________________________________________________
188 AliMUONPainterMatrix*
189 AliMUONPainterRegistry::PainterMatrix(const char* name) const
191 /// Get a painterMatrix by name
192 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
195 //_____________________________________________________________________________
197 AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
199 /// A painterMatrix was chosen from the history menu
201 AliDebug(1,Form("i=%d",i));
203 TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
205 AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
207 PainterMatrixWantToShow(group);
210 //_____________________________________________________________________________
211 AliMUONPainterRegistry*
212 AliMUONPainterRegistry::Instance()
214 /// Get unique instance of this class
215 if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
219 //_____________________________________________________________________________
221 AliMUONPainterRegistry::InteractiveReadOutConfig() const
223 /// Return an object that contains the parts of the detector selected
224 /// (using the mouse) to be part of the readout.
226 if (!fInteractiveReadOutConfig) CreateInteractiveReadOutConfig();
227 return fInteractiveReadOutConfig;
230 //_____________________________________________________________________________
231 AliMUONPainterMatrix*
232 AliMUONPainterRegistry::PainterMatrix(Int_t i) const
234 /// Get one painter matrix
235 if ( i >= 0 && i <= fPainterMatrices->GetLast() )
237 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
241 AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
246 //_____________________________________________________________________________
248 AliMUONPainterRegistry::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
250 /// A given paintermatrix want to appear on screen
251 Long_t param[] = { (Long_t)group };
253 Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);
256 //_____________________________________________________________________________
258 AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
260 /// Add a matrix to the history
262 if ( !fHistoryMenu && fMenuBar )
264 fHistoryMenu = new TGPopupMenu(gClient->GetRoot());
265 TGPopupMenu* before = 0x0; //FIXME: could try to find a place where to put it (e.g. before Help ?)
267 fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
269 fHistoryMenu->Connect("Activated(Int_t)",
270 "AliMUONPainterRegistry",this,
271 "HistoryMenuActivated(Int_t)");
273 AliDebug(1,Form("HistoryMenu create at %x",fHistoryMenu));
278 TIter next(fHistoryMenu->GetListOfEntries());
281 while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
283 if ( e->GetUserData() == group )
285 fHistoryMenu->DeleteEntry(e);
290 e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
292 fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
296 AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
300 //_____________________________________________________________________________
302 AliMUONPainterRegistry::PainterMatrixWasRegistered(AliMUONPainterMatrix* group)
304 /// A new painter matrix was registered
305 Long_t param[] = { (Long_t)group };
307 Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
310 //_____________________________________________________________________________
312 AliMUONPainterRegistry::PainterMatrixWasUnregistered(AliMUONPainterMatrix* group)
314 /// A painter matrix was unregistered
315 Long_t param[] = { (Long_t)group };
317 Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
320 //_____________________________________________________________________________
322 AliMUONPainterRegistry::Print(Option_t* opt) const
328 cout << "Number of data readers = " << NumberOfDataMakers() << endl;
329 cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
331 if ( sopt.Contains("FULL") || sopt.Contains("READER") )
333 TIter next(fDataMakers);
334 AliMUONVTrackerDataMaker* reader;
336 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
342 if ( sopt.Contains("FULL") || sopt.Contains("DATA") )
344 TIter next(fDataMakers);
345 AliMUONVTrackerDataMaker* reader;
347 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
349 AliMUONVTrackerData* data = reader->Data();
350 if ( data ) data->Print();
354 if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
356 TIter next(fPainterMatrices);
357 AliMUONPainterMatrix* matrix;
359 while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
367 //_____________________________________________________________________________
369 AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
371 /// group is adopted, i.e. the registry becomes the owner of it.
372 fPainterMatrices->AddLast(group);
374 PainterMatrixWasRegistered(group);
376 return fPainterMatrices->IndexOf(group);
379 //_____________________________________________________________________________
381 AliMUONPainterRegistry::Register(AliMUONVTrackerDataMaker* reader)
383 /// reader is adopted, i.e. the registry becomes the owner of it.
384 fDataMakers->AddLast(reader);
385 DataMakerWasRegistered(reader);
386 if ( reader->Data() ) DataSourceWasRegistered(reader->Data());
389 //_____________________________________________________________________________
391 AliMUONPainterRegistry::NumberOfDataMakers() const
393 /// The number of data readers we handle
394 return fDataMakers->GetLast()+1;
397 //_____________________________________________________________________________
399 AliMUONPainterRegistry::NumberOfPainterMatrices() const
401 /// The number of painter matrices we handle
402 return fPainterMatrices->GetLast()+1;
405 //_____________________________________________________________________________
407 AliMUONPainterRegistry::DeleteZombies()
413 //_____________________________________________________________________________
415 AliMUONPainterRegistry::Unregister(AliMUONVTrackerDataMaker* reader)
417 /// Unregister some reader
419 if (!reader) return kFALSE;
421 if ( reader->Data() )
423 DataSourceWasUnregistered(reader->Data());
424 reader->Data()->Destroyed(); // we pretend it's deleted now, even
425 // if it will be only later on when zombie are killed, so that
426 // for instance painters depending on it will no longer try to access it
429 DataMakerWasUnregistered(reader);
431 TObject* o = fDataMakers->Remove(reader);
433 fZombies->Add(o); // for later deletion
441 // AliError(Form("Could not unregister data named %s title %s",reader->GetName(),
442 // reader->GetTitle()));
447 //_____________________________________________________________________________
449 AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
451 /// Unregister some matrix
453 if (!group) return kFALSE;
455 PainterMatrixWasUnregistered(group);
457 TObject* o = fPainterMatrices->Remove(group);
464 AliError(Form("Could not unregister group named %s",group->GetName()));