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
39 ClassImp(AliMUONPainterDataRegistry)
42 AliMUONPainterDataRegistry* AliMUONPainterDataRegistry::fgInstance(0x0);
44 //_____________________________________________________________________________
45 AliMUONPainterDataRegistry::AliMUONPainterDataRegistry() : TObject(), TQObject(),
46 fDataMakers(new TObjArray),
47 fZombies(new TObjArray),
48 fInteractiveReadOutConfig(0x0)
51 fDataMakers->SetOwner(kTRUE);
52 fZombies->SetOwner(kTRUE);
55 //_____________________________________________________________________________
56 AliMUONPainterDataRegistry::~AliMUONPainterDataRegistry()
60 delete fInteractiveReadOutConfig;
63 //_____________________________________________________________________________
65 AliMUONPainterDataRegistry::CreateInteractiveReadOutConfig() const
67 /// Create a base config
69 fInteractiveReadOutConfig = new AliMUONTrackerData("IROC","IROC",1);
70 fInteractiveReadOutConfig->SetDimensionName(0,"Switch");
71 fInteractiveReadOutConfig->DisableChannelLevel();
75 AliMUON2DMap store(true);
77 while ( it.Next(detElemId,manuId) )
79 AliMUONVCalibParam* param = new AliMUONCalibParamND(1,64,detElemId,manuId,1);
82 fInteractiveReadOutConfig->Add(store);
85 //_____________________________________________________________________________
86 AliMUONVTrackerDataMaker*
87 AliMUONPainterDataRegistry::DataMaker(Int_t i) const
89 /// Get one data source
90 if ( i >= 0 && i <= fDataMakers->GetLast() )
92 return static_cast<AliMUONVTrackerDataMaker*>(fDataMakers->At(i));
96 AliError(Form("Index out of bounds : %d / %d",i,fDataMakers->GetLast()+1));
101 //_____________________________________________________________________________
103 AliMUONPainterDataRegistry::DataSource(Int_t i) const
105 /// Get one data source
107 AliMUONVTrackerDataMaker* maker = DataMaker(i);
108 if ( maker ) return maker->Data();
112 //_____________________________________________________________________________
114 AliMUONPainterDataRegistry::DataMakerWasRegistered(AliMUONVTrackerDataMaker* data)
116 /// A new reader source was registered
117 Long_t param[] = { (Long_t)data };
119 Emit("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",param);
122 //_____________________________________________________________________________
124 AliMUONPainterDataRegistry::DataMakerWasUnregistered(AliMUONVTrackerDataMaker* data)
126 /// A data reader was unregistered
127 Long_t param[] = { (Long_t)data };
129 Emit("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",param);
133 //_____________________________________________________________________________
135 AliMUONPainterDataRegistry::DataSourceWasRegistered(AliMUONVTrackerData* data)
137 /// A new data source was registered
138 Long_t param[] = { (Long_t)data };
140 Emit("DataSourceWasRegistered(AliMUONVTrackerData*)",param);
143 //_____________________________________________________________________________
145 AliMUONPainterDataRegistry::DataSourceWasUnregistered(AliMUONVTrackerData* data)
147 /// A data source was unregistered
148 Long_t param[] = { (Long_t)data };
150 Emit("DataSourceWasUnregistered(AliMUONVTrackerData*)",param);
154 //_____________________________________________________________________________
156 AliMUONPainterDataRegistry::DataSource(const char* name) const
158 /// Find a data source by name
159 for ( Int_t i = 0; i < NumberOfDataMakers(); ++i )
161 AliMUONVTrackerData* data = DataMaker(i)->Data();
164 TString dname(data->GetName());
165 if ( dname == name ) return data;
171 //_____________________________________________________________________________
172 AliMUONPainterDataRegistry*
173 AliMUONPainterDataRegistry::Instance()
175 /// Get unique instance of this class
176 if ( !fgInstance ) fgInstance = new AliMUONPainterDataRegistry;
180 //_____________________________________________________________________________
182 AliMUONPainterDataRegistry::InteractiveReadOutConfig() const
184 /// Return an object that contains the parts of the detector selected
185 /// (using the mouse) to be part of the readout.
187 if (!fInteractiveReadOutConfig) CreateInteractiveReadOutConfig();
188 return fInteractiveReadOutConfig;
191 //_____________________________________________________________________________
193 AliMUONPainterDataRegistry::Print(Option_t* opt) const
199 cout << "Number of data readers = " << NumberOfDataMakers() << endl;
201 if ( sopt.Contains("FULL") || sopt.Contains("READER") || sopt.Contains("DATA") )
203 TIter next(fDataMakers);
204 AliMUONVTrackerDataMaker* reader;
206 while ( ( reader = static_cast<AliMUONVTrackerDataMaker*>(next()) ) )
208 if ( sopt.Contains("DATA") )
210 AliMUONVTrackerData* data = reader->Data();
211 if ( data ) data->Print();
221 //_____________________________________________________________________________
223 AliMUONPainterDataRegistry::Register(AliMUONVTrackerDataMaker* reader)
225 /// reader is adopted, i.e. the registry becomes the owner of it.
226 fDataMakers->AddLast(reader);
227 DataMakerWasRegistered(reader);
228 if ( reader->Data() ) DataSourceWasRegistered(reader->Data());
231 //_____________________________________________________________________________
233 AliMUONPainterDataRegistry::NumberOfDataMakers() const
235 /// The number of data readers we handle
236 return fDataMakers->GetLast()+1;
239 //_____________________________________________________________________________
241 AliMUONPainterDataRegistry::DeleteZombies()
247 //_____________________________________________________________________________
249 AliMUONPainterDataRegistry::Unregister(AliMUONVTrackerDataMaker* reader)
251 /// Unregister some reader
253 if (!reader) return kFALSE;
255 if ( reader->Data() )
257 DataSourceWasUnregistered(reader->Data());
258 reader->Data()->Destroyed(); // we pretend it's deleted now, even
259 // if it will be only later on when zombie are killed, so that
260 // for instance painters depending on it will no longer try to access it
263 DataMakerWasUnregistered(reader);
265 TObject* o = fDataMakers->Remove(reader);
267 fZombies->Add(o); // for later deletion
275 // AliError(Form("Could not unregister data named %s title %s",reader->GetName(),
276 // reader->GetTitle()));