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 /// Create configuration of readout
77 fInteractiveReadOutConfig = new AliMUONTrackerData("IROC","IROC",1);
78 fInteractiveReadOutConfig->SetDimensionName(0,"Switch");
79 /// FIXME: should use a version of TrackerData w/ no storage for channels
80 /// (i.e. starting at the manu level, or even bus patch level ?)
84 AliMUON2DMap store(true);
86 while ( it.Next(detElemId,manuId) )
88 AliMUONVCalibParam* param = new AliMUONCalibParamND(1,64,detElemId,manuId,1);
91 fInteractiveReadOutConfig->Add(store);
94 //_____________________________________________________________________________
95 AliMUONVTrackerDataMaker*
96 AliMUONPainterRegistry::DataMaker(Int_t i) const
98 /// Get one data source
99 if ( i >= 0 && i <= fDataMakers->GetLast() )
101 return static_cast<AliMUONVTrackerDataMaker*>(fDataMakers->At(i));
105 AliError(Form("Index out of bounds : %d / %d",i,fDataMakers->GetLast()+1));
110 //_____________________________________________________________________________
112 AliMUONPainterRegistry::DataSource(Int_t i) const
114 /// Get one data source
116 AliMUONVTrackerDataMaker* maker = DataMaker(i);
117 if ( maker ) return maker->Data();
121 //_____________________________________________________________________________
123 AliMUONPainterRegistry::DataMakerWasRegistered(const AliMUONVTrackerDataMaker* data)
125 /// A new reader source was registered
126 Long_t param[] = { (Long_t)data };
128 Emit("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",param);
131 //_____________________________________________________________________________
133 AliMUONPainterRegistry::DataMakerWasUnregistered(const AliMUONVTrackerDataMaker* data)
135 /// A data reader was unregistered
136 Long_t param[] = { (Long_t)data };
138 Emit("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",param);
142 //_____________________________________________________________________________
144 AliMUONPainterRegistry::DataSourceWasRegistered(const AliMUONVTrackerData* data)
146 /// A new data source was registered
147 Long_t param[] = { (Long_t)data };
149 Emit("DataSourceWasRegistered(AliMUONVTrackerData*)",param);
152 //_____________________________________________________________________________
154 AliMUONPainterRegistry::DataSourceWasUnregistered(const AliMUONVTrackerData* data)
156 /// A data source was unregistered
157 Long_t param[] = { (Long_t)data };
159 Emit("DataSourceWasUnregistered(AliMUONVTrackerData*)",param);
163 //_____________________________________________________________________________
165 AliMUONPainterRegistry::DataSource(const char* name) const
167 /// Find a data source by name
168 for ( Int_t i = 0; i < NumberOfDataMakers(); ++i )
170 AliMUONVTrackerData* data = DataMaker(i)->Data();
173 TString dname(data->GetName());
174 if ( dname == name ) return data;
180 //_____________________________________________________________________________
182 AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
184 /// Get the index of a given painterMatrix
185 return fPainterMatrices->IndexOf(group);
188 //_____________________________________________________________________________
189 AliMUONPainterMatrix*
190 AliMUONPainterRegistry::PainterMatrix(const char* name) const
192 /// Get a painterMatrix by name
193 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
196 //_____________________________________________________________________________
198 AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
200 /// A painterMatrix was chosen from the history menu
202 AliDebug(1,Form("i=%d",i));
204 TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
206 AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
208 PainterMatrixWantToShow(group);
211 //_____________________________________________________________________________
212 AliMUONPainterRegistry*
213 AliMUONPainterRegistry::Instance()
215 /// Get unique instance of this class
216 if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
220 //_____________________________________________________________________________
222 AliMUONPainterRegistry::InteractiveReadOutConfig() const
224 /// Return an object that contains the parts of the detector selected
225 /// (using the mouse) to be part of the readout.
227 if (!fInteractiveReadOutConfig) CreateInteractiveReadOutConfig();
228 return fInteractiveReadOutConfig;
231 //_____________________________________________________________________________
232 AliMUONPainterMatrix*
233 AliMUONPainterRegistry::PainterMatrix(Int_t i) const
235 /// Get one painter matrix
236 if ( i >= 0 && i <= fPainterMatrices->GetLast() )
238 return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
242 AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
247 //_____________________________________________________________________________
249 AliMUONPainterRegistry::PainterMatrixWantToShow(const AliMUONPainterMatrix* group)
251 /// A given paintermatrix want to appear on screen
252 Long_t param[] = { (Long_t)group };
254 Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);
257 //_____________________________________________________________________________
259 AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
261 /// Add a matrix to the history
263 if ( !fHistoryMenu && fMenuBar )
265 fHistoryMenu = new TGPopupMenu(gClient->GetRoot());
266 TGPopupMenu* before = 0x0; //FIXME: could try to find a place where to put it (e.g. before Help ?)
268 fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
270 fHistoryMenu->Connect("Activated(Int_t)",
271 "AliMUONPainterRegistry",this,
272 "HistoryMenuActivated(Int_t)");
274 AliDebug(1,Form("HistoryMenu create at %x",fHistoryMenu));
279 TIter next(fHistoryMenu->GetListOfEntries());
282 while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
284 if ( e->GetUserData() == group )
286 fHistoryMenu->DeleteEntry(e);
291 e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
293 fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
297 AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
301 //_____________________________________________________________________________
303 AliMUONPainterRegistry::PainterMatrixWasRegistered(const AliMUONPainterMatrix* group)
305 /// A new painter matrix was registered
306 Long_t param[] = { (Long_t)group };
308 Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
311 //_____________________________________________________________________________
313 AliMUONPainterRegistry::PainterMatrixWasUnregistered(const AliMUONPainterMatrix* group)
315 /// A painter matrix was unregistered
316 Long_t param[] = { (Long_t)group };
318 Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
321 //_____________________________________________________________________________
323 AliMUONPainterRegistry::Print(Option_t* opt) const
329 cout << "Number of data readers = " << NumberOfDataMakers() << endl;
330 cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
332 if ( sopt.Contains("FULL") || sopt.Contains("READER") )
334 TIter next(fDataMakers);
335 AliMUONVTrackerDataMaker* reader;
337 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
343 if ( sopt.Contains("FULL") || sopt.Contains("DATA") )
345 TIter next(fDataMakers);
346 AliMUONVTrackerDataMaker* reader;
348 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
350 AliMUONVTrackerData* data = reader->Data();
351 if ( data ) data->Print();
355 if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
357 TIter next(fPainterMatrices);
358 AliMUONPainterMatrix* matrix;
360 while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
368 //_____________________________________________________________________________
370 AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
372 /// group is adopted, i.e. the registry becomes the owner of it.
373 fPainterMatrices->AddLast(group);
375 PainterMatrixWasRegistered(group);
377 return fPainterMatrices->IndexOf(group);
380 //_____________________________________________________________________________
382 AliMUONPainterRegistry::Register(AliMUONVTrackerDataMaker* reader)
384 /// reader is adopted, i.e. the registry becomes the owner of it.
385 fDataMakers->AddLast(reader);
386 DataMakerWasRegistered(reader);
387 if ( reader->Data() ) DataSourceWasRegistered(reader->Data());
390 //_____________________________________________________________________________
392 AliMUONPainterRegistry::NumberOfDataMakers() const
394 /// The number of data readers we handle
395 return fDataMakers->GetLast()+1;
398 //_____________________________________________________________________________
400 AliMUONPainterRegistry::NumberOfPainterMatrices() const
402 /// The number of painter matrices we handle
403 return fPainterMatrices->GetLast()+1;
406 //_____________________________________________________________________________
408 AliMUONPainterRegistry::DeleteZombies()
414 //_____________________________________________________________________________
416 AliMUONPainterRegistry::Unregister(AliMUONVTrackerDataMaker* reader)
418 /// Unregister some reader
420 if (!reader) return kFALSE;
422 if ( reader->Data() )
424 DataSourceWasUnregistered(reader->Data());
425 reader->Data()->Destroyed(); // we pretend it's deleted now, even
426 // if it will be only later on when zombie are killed, so that
427 // for instance painters depending on it will no longer try to access it
430 DataMakerWasUnregistered(reader);
432 TObject* o = fDataMakers->Remove(reader);
434 fZombies->Add(o); // for later deletion
442 // AliError(Form("Could not unregister data named %s title %s",reader->GetName(),
443 // reader->GetTitle()));
448 //_____________________________________________________________________________
450 AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
452 /// Unregister some matrix
454 if (!group) return kFALSE;
456 PainterMatrixWasUnregistered(group);
458 TObject* o = fPainterMatrices->Remove(group);
465 AliError(Form("Could not unregister group named %s",group->GetName()));