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 ///////////////////////////////////////////////////////////////////////////
20 // Signal (Hit) handling of a generic device.
21 // Basically this class provides a user interface to group and handle
22 // various instances of AliSignal objects, called generically "hits".
23 // An AliDevice object itself has (in addition to hit storage) also the
24 // complete functionality of the class AliSignal.
31 // m.SetName("OM123");
33 // Float_t pos[3]={1,2,3};
34 // m.SetPosition(pos,"car");
39 // s.SetName("OM123 Hit 1");
40 // s.SetSlotName("ADC");
42 // s.SetSlotName("LE",2);
43 // s.SetSignal(-100,2);
44 // s.SetSlotName("TOT",3);
45 // s.SetSignal(-1000,3);
49 // s.SetName("OM123 Hit 2");
50 // s.SetSlotName("ADC");
52 // s.SetSlotName("LE",2);
53 // s.SetSignal(-101,2);
54 // s.SetSlotName("TOT",3);
55 // s.SetSignal(1001,3);
59 // s.SetName("OM123 Hit 3");
60 // s.SetSlotName("ADC");
62 // s.SetSlotName("LE",2);
63 // s.SetSignal(-102,2);
64 // s.SetSlotName("TOT",3);
65 // s.SetSignal(-1002,3);
68 // TObjArray ordered=m.SortHits("TOT");
69 // nhits=ordered.GetEntries();
70 // for (Int_t i=0; i<nhits; i++)
72 // AliSignal* sx=(AliSignal*)ordered.At(i);
73 // if (sx) sx->Data();
76 //--- Author: Nick van Eijndhoven 23-jun-2004 Utrecht University
77 //- Modified: NvE $Date$ Utrecht University
78 ///////////////////////////////////////////////////////////////////////////
80 #include "AliDevice.h"
81 #include "Riostream.h"
83 ClassImp(AliDevice) // Class implementation to enable ROOT I/O
85 AliDevice::AliDevice() : AliSignal()
87 // Default constructor.
91 ///////////////////////////////////////////////////////////////////////////
92 AliDevice::~AliDevice()
94 // Default destructor.
101 ///////////////////////////////////////////////////////////////////////////
102 AliDevice::AliDevice(const AliDevice& dev) : AliSignal(dev)
105 fHitCopy=dev.GetHitCopy();
106 Int_t nhits=dev.GetNhits();
109 fHits=new TObjArray(nhits);
110 if (fHitCopy) fHits->SetOwner();
111 for (Int_t ih=1; ih<=nhits; ih++)
113 AliSignal* sx=dev.GetHit(ih);
116 fHits->Add(sx->Clone());
117 Int_t nhits=GetNhits();
118 AliSignal* s=GetHit(nhits);
119 s->ResetLinks((AliDevice*)&dev);
130 ///////////////////////////////////////////////////////////////////////////
131 void AliDevice::Reset(Int_t mode)
133 // Reset registered hits and AliSignal attributes.
134 // See AliSignal::Reset() for further details.
136 AliSignal::Reset(mode);
138 ///////////////////////////////////////////////////////////////////////////
139 void AliDevice::SetHitCopy(Int_t j)
141 // (De)activate the creation of private copies of the AliSignals added as hits.
142 // j=0 ==> No private copies are made; pointers of original hits are stored.
143 // j=1 ==> Private copies of the hits are made and these pointers are stored.
145 // Note : Once the storage contains pointer(s) to hit(s) one cannot
146 // change the HitCopy mode anymore.
147 // To change the HitCopy mode for an existing AliDevice containing
148 // hits one first has to invoke either RemoveHits() or Reset().
157 cout << "*AliDevice::SetHitCopy* Invalid argument : " << j << endl;
162 cout << "*AliDevice::SetHitCopy* Storage already contained hits."
163 << " ==> HitCopy mode not changed." << endl;
166 ///////////////////////////////////////////////////////////////////////////
167 Int_t AliDevice::GetHitCopy() const
169 // Provide value of the HitCopy mode.
170 // 0 ==> No private copies are made; pointers of original hits are stored.
171 // 1 ==> Private copies of the hits are made and these pointers are stored.
174 ///////////////////////////////////////////////////////////////////////////
175 void AliDevice::AddHit(AliSignal& s)
177 // Register an AliSignal object as a hit to this device.
178 // Note : A (backward) link to this device is added to the first slot of
179 // the AliSignal if there was no link to this device already present.
182 fHits=new TObjArray(1);
183 if (fHitCopy) fHits->SetOwner();
186 // Check if this signal is already stored for this device.
187 Int_t nhits=GetNhits();
188 for (Int_t i=0; i<nhits; i++)
190 if (&s==fHits->At(i)) return;
193 // Set the (backward) link to this device.
194 Int_t nlinks=GetNlinks(this);
195 if (!nlinks) s.AddLink(this);
199 fHits->Add(s.Clone());
206 ///////////////////////////////////////////////////////////////////////////
207 void AliDevice::RemoveHit(AliSignal& s)
209 // Remove AliSignal object registered as a hit from this device.
212 AliSignal* test=(AliSignal*)fHits->Remove(&s);
216 if (fHitCopy) delete test;
220 ///////////////////////////////////////////////////////////////////////////
221 void AliDevice::RemoveHits()
223 // Remove all AliSignal objects registered as hits from this device.
230 ///////////////////////////////////////////////////////////////////////////
231 Int_t AliDevice::GetNhits() const
233 // Provide the number of registered hits for this device.
235 if (fHits) nhits=fHits->GetEntries();
238 ///////////////////////////////////////////////////////////////////////////
239 AliSignal* AliDevice::GetHit(Int_t j) const
241 // Provide the AliSignal object registered as hit number j.
242 // Note : j=1 denotes the first hit.
243 if (!fHits) return 0;
245 if ((j >= 1) && (j <= GetNhits()))
247 return (AliSignal*)fHits->At(j-1);
254 ///////////////////////////////////////////////////////////////////////////
255 TObjArray* AliDevice::GetHits()
257 // Provide the references to all the registered hits.
260 ///////////////////////////////////////////////////////////////////////////
261 void AliDevice::ShowHit(Int_t j) const
263 // Show data of the registered j-th hit.
264 // If j=0 all associated hits will be shown.
265 // The default is j=0.
268 Int_t nhits=GetNhits();
269 for (Int_t ih=1; ih<=nhits; ih++)
271 AliSignal* sx=GetHit(ih);
277 AliSignal* s=GetHit(j);
281 ///////////////////////////////////////////////////////////////////////////
282 void AliDevice::Data(TString f) const
284 // Print the device and all registered hit info according to the specified
287 Int_t nhits=GetNhits();
290 cout << " The following " << nhits << " hits are registered : " << endl;
295 cout << " No hits have been registered for this device." << endl;
298 ///////////////////////////////////////////////////////////////////////////
299 TObjArray AliDevice::SortHits(Int_t idx,Int_t mode,TObjArray* hits) const
301 // Order the references to an array of hits by looping over the input array "hits"
302 // and checking the signal value. The ordered array is returned as a TObjArray.
303 // In case hits=0 (default), the registered hits of the current device are used.
304 // Note that the original hit array in not modified.
305 // A "hit" represents an abstract object which is derived from AliSignal.
306 // The user can specify the index of the signal slot to perform the sorting on.
307 // By default the slotindex will be 1.
308 // Via the "mode" argument the user can specify ordering in decreasing
309 // order (mode=-1) or ordering in increasing order (mode=1).
310 // The default is mode=-1.
311 // Signals which were declared as "Dead" will be rejected.
312 // The gain etc... corrected signals will be used in the ordering process.
316 if (!hits) hits=fHits;
318 if (idx<=0 || abs(mode)!=1 || !hits) return ordered;
320 Int_t nhits=hits->GetEntries();
327 ordered.Expand(nhits);
331 for (Int_t i=0; i<nhits; i++) // Loop over all hits of the array
333 AliSignal* s=(AliSignal*)hits->At(i);
337 if (idx > s->GetNvalues()) continue; // User specified slotindex out of range for this signal
338 if (s->GetDeadValue(idx)) continue; // Only take alive signals
340 if (nord == 0) // store the first hit with a signal at the first ordered position
343 ordered.AddAt(s,nord-1);
347 for (Int_t j=0; j<=nord; j++) // put hit in the right ordered position
349 if (j == nord) // module has smallest (mode=-1) or largest (mode=1) signal seen so far
352 ordered.AddAt(s,j); // add hit at the end
353 break; // go for next hit
356 if (mode==-1 && s->GetSignal(idx,1) < ((AliSignal*)ordered.At(j))->GetSignal(idx,1)) continue;
357 if (mode==1 && s->GetSignal(idx,1) > ((AliSignal*)ordered.At(j))->GetSignal(idx,1)) continue;
360 for (Int_t k=nord-1; k>j; k--) // create empty position
362 ordered.AddAt(ordered.At(k-1),k);
364 ordered.AddAt(s,j); // put hit at empty position
365 break; // go for next matrix module
370 ///////////////////////////////////////////////////////////////////////////
371 TObjArray AliDevice::SortHits(TString name,Int_t mode,TObjArray* hits) const
373 // Order the references to an array of hits by looping over the input array "hits"
374 // and checking the signal value. The ordered array is returned as a TObjArray.
375 // In case hits=0 (default), the registered hits of the current device are used.
376 // Note that the input array in not modified.
377 // A "hit" represents an abstract object which is derived from AliSignal.
378 // The user can specify the name of the signal slot to perform the sorting on.
379 // In case no matching slotname is found, the signal will be skipped.
380 // Via the "mode" argument the user can specify ordering in decreasing
381 // order (mode=-1) or ordering in increasing order (mode=1).
382 // The default is mode=-1.
383 // Signals which were declared as "Dead" will be rejected.
384 // The gain etc... corrected signals will be used in the ordering process.
388 if (!hits) hits=fHits;
390 if (abs(mode)!=1 || !hits) return ordered;
392 Int_t nhits=hits->GetEntries();
399 ordered.Expand(nhits);
402 Int_t idx=0; // The signal slotindex to perform the sorting on
405 for (Int_t i=0; i<nhits; i++) // loop over all hits of the array
407 AliSignal* s=(AliSignal*)hits->At(i);
411 // Obtain the slotindex corresponding to the user selection
412 idx=s->GetSlotIndex(name);
415 if (s->GetDeadValue(idx)) continue; // only take alive signals
417 if (nord == 0) // store the first hit with a signal at the first ordered position
420 ordered.AddAt(s,nord-1);
424 for (Int_t j=0; j<=nord; j++) // put hit in the right ordered position
426 if (j == nord) // module has smallest (mode=-1) or largest (mode=1) signal seen so far
429 ordered.AddAt(s,j); // add hit at the end
430 break; // go for next hit
433 if (mode==-1 && s->GetSignal(idx,1) < ((AliSignal*)ordered.At(j))->GetSignal(idx,1)) continue;
434 if (mode==1 && s->GetSignal(idx,1) > ((AliSignal*)ordered.At(j))->GetSignal(idx,1)) continue;
437 for (Int_t k=nord-1; k>j; k--) // create empty position
439 ordered.AddAt(ordered.At(k-1),k);
441 ordered.AddAt(s,j); // put hit at empty position
442 break; // go for next matrix module
447 ///////////////////////////////////////////////////////////////////////////
448 TObject* AliDevice::Clone(const char* name) const
450 // Make a deep copy of the current object and provide the pointer to the copy.
451 // This memberfunction enables automatic creation of new objects of the
452 // correct type depending on the object type, a feature which may be very useful
453 // for containers like AliEvent when adding objects in case the
454 // container owns the objects. This feature allows e.g. AliEvent
455 // to store either AliDevice objects or objects derived from AliDevice
456 // via tha AddDevice memberfunction, provided these derived classes also have
457 // a proper Clone memberfunction.
459 AliDevice* dev=new AliDevice(*this);
462 if (strlen(name)) dev->SetName(name);
466 ///////////////////////////////////////////////////////////////////////////