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 **************************************************************************/
16 // $Id: AliMUONPainterDataRegistry.cxx 26812 2008-06-20 15:22:59Z laphecet $
18 #include "AliMUONPainterDataRegistry.h"
20 #include "AliMpManuIterator.h"
21 #include "AliMUON2DMap.h"
22 #include "AliMUONCalibParamND.h"
23 #include "AliMUONTrackerData.h"
24 #include "AliMUONVTrackerDataMaker.h"
26 #include <THashList.h>
27 #include <TObjArray.h>
29 #include <Riostream.h>
31 ///\class AliMUONPainterDataRegistry
33 /// Registry for AliMUONVPainter related stuff : painter data sources
34 /// and painter matrices
36 ///\author Laurent Aphecetche, Subatech
41 ClassImp(AliMUONPainterDataRegistry)
44 AliMUONPainterDataRegistry* AliMUONPainterDataRegistry::fgInstance(0x0);
46 //_____________________________________________________________________________
47 AliMUONPainterDataRegistry::AliMUONPainterDataRegistry() : TObject(), TQObject(),
48 fDataMakers(new TObjArray),
49 fZombies(new TObjArray),
50 fInteractiveReadOutConfig(0x0)
53 fDataMakers->SetOwner(kTRUE);
54 fZombies->SetOwner(kTRUE);
57 //_____________________________________________________________________________
58 AliMUONPainterDataRegistry::~AliMUONPainterDataRegistry()
62 delete fInteractiveReadOutConfig;
65 //_____________________________________________________________________________
67 AliMUONPainterDataRegistry::CreateInteractiveReadOutConfig() const
69 /// Create a base config
71 fInteractiveReadOutConfig = new AliMUONTrackerData("IROC","IROC",1);
72 fInteractiveReadOutConfig->SetDimensionName(0,"Switch");
73 fInteractiveReadOutConfig->DisableChannelLevel();
77 AliMUON2DMap store(true);
79 while ( it.Next(detElemId,manuId) )
81 AliMUONVCalibParam* param = new AliMUONCalibParamND(1,64,detElemId,manuId,1);
84 fInteractiveReadOutConfig->Add(store);
87 //_____________________________________________________________________________
88 AliMUONVTrackerDataMaker*
89 AliMUONPainterDataRegistry::DataMaker(Int_t i) const
91 /// Get one data source
92 if ( i >= 0 && i <= fDataMakers->GetLast() )
94 return static_cast<AliMUONVTrackerDataMaker*>(fDataMakers->At(i));
98 AliError(Form("Index out of bounds : %d / %d",i,fDataMakers->GetLast()+1));
103 //_____________________________________________________________________________
105 AliMUONPainterDataRegistry::DataSource(Int_t i) const
107 /// Get one data source
109 AliMUONVTrackerDataMaker* maker = DataMaker(i);
110 if ( maker ) return maker->Data();
114 //_____________________________________________________________________________
116 AliMUONPainterDataRegistry::DataMakerWasRegistered(const AliMUONVTrackerDataMaker* data)
118 /// A new reader source was registered
119 Long_t param[] = { (Long_t)data };
121 Emit("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",param);
124 //_____________________________________________________________________________
126 AliMUONPainterDataRegistry::DataMakerWasUnregistered(const AliMUONVTrackerDataMaker* data)
128 /// A data reader was unregistered
129 Long_t param[] = { (Long_t)data };
131 Emit("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",param);
135 //_____________________________________________________________________________
137 AliMUONPainterDataRegistry::DataSourceWasRegistered(const AliMUONVTrackerData* data)
139 /// A new data source was registered
140 Long_t param[] = { (Long_t)data };
142 Emit("DataSourceWasRegistered(AliMUONVTrackerData*)",param);
145 //_____________________________________________________________________________
147 AliMUONPainterDataRegistry::DataSourceWasUnregistered(const AliMUONVTrackerData* data)
149 /// A data source was unregistered
150 Long_t param[] = { (Long_t)data };
152 Emit("DataSourceWasUnregistered(AliMUONVTrackerData*)",param);
156 //_____________________________________________________________________________
158 AliMUONPainterDataRegistry::DataSource(const char* name) const
160 /// Find a data source by name
161 for ( Int_t i = 0; i < NumberOfDataMakers(); ++i )
163 AliMUONVTrackerData* data = DataMaker(i)->Data();
166 TString dname(data->GetName());
167 if ( dname == name ) return data;
173 //_____________________________________________________________________________
174 AliMUONPainterDataRegistry*
175 AliMUONPainterDataRegistry::Instance()
177 /// Get unique instance of this class
178 if ( !fgInstance ) fgInstance = new AliMUONPainterDataRegistry;
182 //_____________________________________________________________________________
184 AliMUONPainterDataRegistry::InteractiveReadOutConfig() const
186 /// Return an object that contains the parts of the detector selected
187 /// (using the mouse) to be part of the readout.
189 if (!fInteractiveReadOutConfig) CreateInteractiveReadOutConfig();
190 return fInteractiveReadOutConfig;
193 //_____________________________________________________________________________
195 AliMUONPainterDataRegistry::Print(Option_t* opt) const
201 cout << "Number of data readers = " << NumberOfDataMakers() << endl;
203 if ( sopt.Contains("FULL") || sopt.Contains("READER") || sopt.Contains("DATA") )
205 TIter next(fDataMakers);
206 AliMUONVTrackerDataMaker* reader;
208 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
210 if ( sopt.Contains("DATA") )
212 AliMUONVTrackerData* data = reader->Data();
213 if ( data ) data->Print();
223 //_____________________________________________________________________________
225 AliMUONPainterDataRegistry::Register(AliMUONVTrackerDataMaker* reader)
227 /// reader is adopted, i.e. the registry becomes the owner of it.
228 fDataMakers->AddLast(reader);
229 DataMakerWasRegistered(reader);
230 if ( reader->Data() ) DataSourceWasRegistered(reader->Data());
233 //_____________________________________________________________________________
235 AliMUONPainterDataRegistry::NumberOfDataMakers() const
237 /// The number of data readers we handle
238 return fDataMakers->GetLast()+1;
241 //_____________________________________________________________________________
243 AliMUONPainterDataRegistry::DeleteZombies()
249 //_____________________________________________________________________________
251 AliMUONPainterDataRegistry::Unregister(AliMUONVTrackerDataMaker* reader)
253 /// Unregister some reader
255 if (!reader) return kFALSE;
257 if ( reader->Data() )
259 DataSourceWasUnregistered(reader->Data());
260 reader->Data()->Destroyed(); // we pretend it's deleted now, even
261 // if it will be only later on when zombie are killed, so that
262 // for instance painters depending on it will no longer try to access it
265 DataMakerWasUnregistered(reader);
267 TObject* o = fDataMakers->Remove(reader);
269 fZombies->Add(o); // for later deletion
277 // AliError(Form("Could not unregister data named %s title %s",reader->GetName(),
278 // reader->GetTitle()));