]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliSignal.cxx
20-oct-2005 NvE Trigger time window selection introduced in IceCleanHits based
[u/mrichter/AliRoot.git] / RALICE / AliSignal.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // $Id$
17
18 ///////////////////////////////////////////////////////////////////////////
19 // Class AliSignal
20 // Generic handling of (extrapolated) detector signals.
21 //
22 // The user can decide to store either calibrated or uncalibrated signals.
23 // Via the specification of a gain and offset or/and an explicit
24 // (de)calibration function both calibrated and uncalibrated signals
25 // can always be obtained. For details see the documentation of the
26 // memberfunction GetSignal() and the class AliAttrib.
27 // The explicit specification of a (de)calibration function offers the
28 // maximum flexibility and also allows automatic indication whether
29 // calibrated or uncalibrated data has been stored.
30 // The latter can be achieved by only specifying a calibration function
31 // (and no de-calibration function) in case uncalibrated data is stored,
32 // whereas in case of stored calibrated data the user should only
33 // provide a de-calibration function (and no calibration function).
34 //
35 // Note :
36 // ------
37 // Signal positions (r) and reference frames (f) are specified via
38 // SetPosition(r,f) under the following conventions :
39 //
40 // f="car" ==> r is Cartesian   (x,y,z)
41 // f="sph" ==> r is Spherical   (r,theta,phi)
42 // f="cyl" ==> r is Cylindrical (rho,phi,z)
43 //
44 // The same holds for SetPositionErrors().
45 //
46 // All angles are in radians.
47 //
48 // Example :
49 // ---------
50 //
51 // AliSignal s;
52 // s.SetName("Start counter");
53 // Float_t pos[3]={-1,25,7};
54 // Float_t err[3]={0.03,0.7,0.18};
55 // Float_t signal=120.8;
56 // Float_t error=1.73;
57 // Float_t offset=-12.78;
58 // Float_t gain=250;
59 // s.SetPosition(pos,"car");
60 // s.SetPositionErrors(err,"car");
61 // s.SetSignal(signal);
62 // s.SetSignalError(error);
63 // s.SetOffset(offset);
64 // s.SetGain(gain);
65 // Float_t loc[3],dr[3],sigma;
66 // s.GetPosition(loc,"sph");
67 // s.GetPositionErrors(dr,"sph");
68 // Float_t adc=s.GetSignal();
69 // Float_t sigma=s.GetSignalError();
70 //
71 // AliSignal q;    // In the example below a signal contains the
72 //                 // following data : timing, ADC and dE/dx
73 // q.SetNameTitle("Hybrid","Test for multiple signal data");
74 // q.SetPosition(pos,"car");
75 // q.SetPositionErrors(err,"car");
76 // signal=82.5; // e.g. signal time in ns
77 // error=2.01;
78 // offset=0.003;
79 // q.SetSlotName("TOF",1);
80 // q.SetSignal(signal,1);
81 // q.SetSignalError(error,1);
82 // q.SetOffset(offset,1);
83 // signal=268.1; // e.g. ADC value of signal
84 // error=3.75;
85 // gain=120.78;
86 // offset=1.5732;
87 // // Addressing via name specification instead of index 
88 // q.SetSlotName("ADC",2);
89 // q.SetSignal(signal,"ADC");
90 // q.SetSignalError(error,"ADC");
91 // q.SetGain(gain,"ADC");
92 // q.SetOffset(offset,"ADC");
93 // signal=23.7; // e.g. corresponding dE/dx value
94 // error=0.48;
95 // TF1 f=("calib","[0]*pow(x,2)+[1]"); // dE/dx calib. function
96 // f.SetParameter(0,3.285);
97 // f.SetParameter(1,-18.67);
98 // q.SetSlotName("dE/dx",3);
99 // q.SetCalFunction(&f,"dE/dx");
100 // q.SetSignal(signal,"dE/dx");
101 // q.SetSignalError(error,"dE/dx");
102 //
103 // // Signal retrieval with various (de)calibration modes
104 // Float_t tof=q.GetSignal("TOF");
105 // Float_t adc=q.GetSignal("ADC",1);
106 // Float_t dedx=q.GetSignal("dE/dx",3);
107 //
108 //--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
109 //- Modified: NvE $Date$ UU-SAP Utrecht
110 ///////////////////////////////////////////////////////////////////////////
111
112 #include "AliSignal.h"
113 #include "AliTrack.h"
114 #include "Riostream.h"
115  
116 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
117  
118 AliSignal::AliSignal() : TNamed(),AliPosition(),AliAttrib()
119 {
120 // Creation of an AliSignal object and initialisation of parameters.
121 // Several signal values (with errors) can be stored in different slots.
122 // If needed, the storage for values (and errors) will be expanded automatically
123 // when entering values and/or errors.
124  fSignals=0;
125  fDsignals=0;
126  fWaveforms=0;
127  fLinks=0;
128  fDevice=0;
129 }
130 ///////////////////////////////////////////////////////////////////////////
131 AliSignal::~AliSignal()
132 {
133 // Destructor to delete dynamically allocated memory
134  if (fSignals)
135  {
136   delete fSignals;
137   fSignals=0;
138  }
139  if (fDsignals)
140  {
141   delete fDsignals;
142   fDsignals=0;
143  }
144  if (fWaveforms)
145  {
146   delete fWaveforms;
147   fWaveforms=0;
148  }
149  if (fLinks)
150  {
151   // Remove this signal from all related tracks
152   for (Int_t i=1; i<=fLinks->GetNobjects(); i++)
153   {
154    TObject* obj=fLinks->GetObject(i);
155    if (!obj) continue;
156    if (obj->InheritsFrom("AliTrack"))
157    {
158     AliTrack* tx=(AliTrack*)obj;
159     tx->RemoveSignal(*this);
160    }
161   }
162   delete fLinks;
163   fLinks=0;
164  }
165 }
166 ///////////////////////////////////////////////////////////////////////////
167 AliSignal::AliSignal(const AliSignal& s) : TNamed(s),AliPosition(s),AliAttrib(s)
168 {
169 // Copy constructor
170  fSignals=0;
171  fDsignals=0;
172  fWaveforms=0;
173  fLinks=0;
174
175  // Don't copy the owning device pointer for the copy
176  fDevice=0;
177
178  Int_t n=s.GetNvalues();
179  Double_t val;
180  for (Int_t i=1; i<=n; i++)
181  {
182   val=s.GetSignal(i);
183   SetSignal(val,i);
184  } 
185
186  n=s.GetNerrors();
187  for (Int_t j=1; j<=n; j++)
188  {
189   val=s.GetSignalError(j);
190   SetSignalError(val,j);
191  }
192
193  n=s.GetNwaveforms();
194  for (Int_t k=1; k<=n; k++)
195  {
196   TH1F* hist=s.GetWaveform(k);
197   if (hist) SetWaveform(hist,k); 
198  }
199
200  TArrayI slotarr;
201  TArrayI posarr;
202  TObject* dum=0;
203  n=s.GetIndices(dum,slotarr,posarr);
204  Int_t slot,pos;
205  for (Int_t idx=0; idx<n; idx++)
206  {
207   slot=slotarr.At(idx);
208   pos=posarr.At(idx);
209   TObject* obj=s.GetLink(slot,pos);
210   if (obj) SetLink(obj,slot,pos); 
211  }
212 }
213 ///////////////////////////////////////////////////////////////////////////
214 void AliSignal::Reset(Int_t mode)
215 {
216 // Reset all signal and position values and errors to 0.
217 //
218 // mode = 0 Reset position and all signal values and their errors to 0.
219 //          The waveform histograms are reset, but the calibration
220 //          constants (i.e. gains and offsets) are kept.
221 //        1 Reset position and delete the signal and error storage arrays.
222 //          Also the waveform histograms, gains and offset arrays are deleted.
223 //
224 // The default when invoking Reset() corresponds to mode=0.
225 //
226 // Note : In all cases the storage of the various links will be reset.
227 //        The UniqueID, name and title will NOT be reset.
228 //        In case the user wants to reset these attributes, this has to
229 //        be done explicitly via the SET facilities. 
230 //
231 // The usage of mode=0 allows to re-use the allocated memory for new
232 // signal (and error) values. This behaviour is preferable (i.e. faster)
233 // in case the various signals always contain the same number of values
234 // and have the same calibration constants.
235 // The usage of mode=1 is slower, but allows a more efficient memory
236 // occupation (and smaller output file size) in case the different
237 // signals have a variable number of values.
238 //
239 // For more specific actions see ResetPosition(), ResetSignals(),
240 // DeleteSignals(), ResetGain(), ResetOffset(), ResetLink(), ResetWaveform(),
241 // DeleteWaveform() and DeleteCalibrations().
242 //
243
244  if (mode<0 || mode>1)
245  {
246   cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
247   cout << " Default mode=0 will be used." << endl;
248   mode=0;
249  }
250
251  ResetPosition();
252  if (!mode)
253  {
254   ResetSignals();
255  }
256  else
257  {
258   DeleteSignals();
259   DeleteCalibrations();
260  }
261
262  if (fLinks) fLinks->Reset();
263  fDevice=0;
264 }
265 ///////////////////////////////////////////////////////////////////////////
266 void AliSignal::ResetSignals(Int_t mode)
267 {
268 // Reset various signal data according to user selection.
269 //
270 // mode = 0 Reset all signal values and their errors to 0.
271 //        1 Reset only signal values
272 //        2 Reset only signal errors
273 //
274 // The default when invoking ResetSignals() corresponds to mode=0.
275 //
276 // Irrespective of the mode, the waveform histograms are reset.
277
278  if (mode<0 || mode>2)
279  {
280   cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
281   cout << " Default mode=0 will be used." << endl;
282   mode=0;
283  }
284
285  if (fSignals && (mode==0 || mode==1))
286  {
287   for (Int_t i=0; i<fSignals->GetSize(); i++)
288   {
289    fSignals->AddAt(0,i);
290   }
291  }
292
293  if (fDsignals && (mode==0 || mode==2))
294  {
295   for (Int_t j=0; j<fDsignals->GetSize(); j++)
296   {
297    fDsignals->AddAt(0,j);
298   }
299  }
300
301  ResetWaveform(0);
302 }
303 ///////////////////////////////////////////////////////////////////////////
304 void AliSignal::DeleteSignals(Int_t mode)
305 {
306 // Delete storage arrays of various signal data according to user selection.
307 //
308 // mode = 0 Delete arrays of both signal values and their errors.
309 //        1 Delete only signal values array
310 //        2 Delete only signal errors array
311 //
312 // The default when invoking DeleteSignals() corresponds to mode=0.
313 //
314 // Irrespective of the mode, the waveform histograms are deleted.
315
316  if (mode<0 || mode>2)
317  {
318   cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
319   cout << " Default mode=0 will be used." << endl;
320   mode=0;
321  }
322
323  if (fSignals && (mode==0 || mode==1))
324  {
325   delete fSignals;
326   fSignals=0;
327  }
328
329  if (fDsignals && (mode==0 || mode==2))
330  {
331   delete fDsignals;
332   fDsignals=0;
333  }
334
335  DeleteWaveform(0);
336 }
337 ///////////////////////////////////////////////////////////////////////////
338 void AliSignal::SetSignal(Double_t sig,Int_t j)
339 {
340 // Store signal value for the j-th (default j=1) slot.
341 // Note : The first signal slot is at j=1.
342 // In case the value of the index j exceeds the maximum number of reserved
343 // slots for signal values, the number of reserved slots for the
344 // signal values is increased automatically.
345
346  if (!fSignals)
347  {
348   fSignals=new TArrayF(j);
349   ResetSignals(1);
350  }
351
352  Int_t size=fSignals->GetSize();
353
354  if (j>size)
355  {
356   fSignals->Set(j);
357  }
358
359  fSignals->AddAt(float(sig),j-1);
360 }
361 ///////////////////////////////////////////////////////////////////////////
362 void AliSignal::SetSignal(Double_t sig,TString name)
363 {
364 // Store signal value for the name-specified slot.
365 //
366 // This procedure involves a slot-index search based on the specified name
367 // at each invokation. This may become slow in case many slots have been
368 // defined and/or when this procedure is invoked many times.
369 // In such cases it is preferable to use indexed addressing in the user code
370 // either directly or via a few invokations of GetSlotIndex().
371
372  Int_t j=GetSlotIndex(name);
373  if (j>0) SetSignal(sig,j);
374 }
375 ///////////////////////////////////////////////////////////////////////////
376 void AliSignal::AddSignal(Double_t sig,Int_t j)
377 {
378 // Add value to the signal of the j-th (default j=1) slot.
379 // Note : The first signal slot is at j=1.
380 // In case the value of the index j exceeds the maximum number of reserved
381 // slots for signal values, the number of reserved slots for the
382 // signal values is increased automatically.
383
384  if (!fSignals)
385  {
386   fSignals=new TArrayF(j);
387   ResetSignals(1);
388  }
389
390  Int_t size=fSignals->GetSize();
391
392  if (j>size)
393  {
394   fSignals->Set(j);
395  }
396
397  Float_t sum=(fSignals->At(j-1))+sig;
398  fSignals->AddAt(sum,j-1);
399 }
400 ///////////////////////////////////////////////////////////////////////////
401 void AliSignal::AddSignal(Double_t sig,TString name)
402 {
403 // Add value to the signal of the name-specified slot.
404 //
405 // This procedure involves a slot-index search based on the specified name
406 // at each invokation. This may become slow in case many slots have been
407 // defined and/or when this procedure is invoked many times.
408 // In such cases it is preferable to use indexed addressing in the user code
409 // either directly or via a few invokations of GetSlotIndex().
410
411  Int_t j=GetSlotIndex(name);
412  if (j>0) AddSignal(sig,j);
413 }
414 ///////////////////////////////////////////////////////////////////////////
415 Float_t AliSignal::GetSignal(Int_t j,Int_t mode) const
416 {
417 // Provide signal value of the j-th (default j=1) slot.
418 // Note : The first signal slot is at j=1.
419 // In case no signal is present or the input argument "j" or "mode" is invalid,
420 // the value 0 is returned.
421 // The parameter "mode" allows for automatic (de)calibration of the signal
422 // (e.g. gain etc... correction or via explicit (de)calibration functions).
423 //
424 // mode = 0 : Just the j-th signal is returned.
425 //        1 : The j-th signal is corrected for the gain, offset, dead flag etc...
426 //            In case the j-th slot was marked dead, 0 is returned.
427 //            In case the gain value was not set, gain=1 will be assumed.
428 //            In case the gain value was 0, a signal value of 0 is returned.
429 //            In case the offset value was not set, offset=0 will be assumed.
430 //        2 : Same as mode=1 but gain, offset dead flag etc... are taken from
431 //            the AliDevice which owns this AliSignal object.
432 //            The corresponding AliDevice slot is obtained via matching of
433 //            the slotnames. In case this fails, the slotindex "j" of the
434 //            input argument will be used. 
435 //            In case this AliSignal object has no parent AliDevice, just
436 //            the j-th signal is returned (like with mode=0).
437 //        3 : The j-th signal is corrected using the corresponding calibration
438 //            function.
439 //            In case the j-th slot was marked dead, 0 is returned.
440 //            In case no calibration function is present, just the j-th signal
441 //            is returned (like with mode=0).
442 //        4 : Same as mode=3 but the calibration function and dead flag are
443 //            taken from the AliDevice which owns this AliSignal object.
444 //            The corresponding AliDevice slot is obtained via matching of
445 //            the slotnames. In case this fails, the slotindex "j" of the
446 //            input argument will be used. 
447 //        5 : Same as mode=2 but in case no parent AliDevice is present
448 //            an automatic switch to mode=1 will be made.
449 //        6 : Same as mode=4 but in case no parent AliDevice is present
450 //            an automatic switch to mode=3 will be made.
451 //        7 : Same as mode=3 but in case no calibration function is present
452 //            an automatic switch to mode=4 will be made.
453 //        8 : Same as mode=7 but also the corresponding dead flag of the
454 //            parent device (if any) will be checked.
455 //            If either the dead flag of the requested signal slot of this
456 //            AliSignal object or the corresponding parent device slot is
457 //            set, 0 is returned.
458 //
459 //       <0 : The corresponding de-correction or de-calibration is performed
460 //
461 // The corrected signal (sigc) is determined as follows :
462 //
463 //              sigc=(signal/gain)-offset 
464 //
465 // The de-corrected signal is determined as follows :
466 //
467 //              signal=(sigc+offset)*gain 
468 //
469 // The default is mode=0.
470
471  if (abs(mode)>8) return 0;
472
473  Int_t jcal=j;
474  Float_t sig=0;
475  Float_t gain=1;
476  Float_t offset=0;
477
478  // Get the corresponding slot index (and dead flag) of the parent device
479  Int_t pj=0;
480  Int_t pdead=0;
481  AliSignal* parent=(AliSignal*)GetDevice();
482  if ((abs(mode)==2 || abs(mode)>=4) && parent)
483  {
484    TString name=GetSlotName(j);
485    if (strlen(name.Data())) pj=parent->GetSlotIndex(name);
486    if (abs(mode)==8 && pj) pdead=parent->GetDeadValue(pj);
487  }
488  if (mode==8) mode=7;
489  if (mode==-8) mode=-7;
490
491  AliSignal* sx=(AliSignal*)this;
492
493  TF1* f=0;
494  if (mode==7)
495  {
496   f=sx->GetCalFunction(jcal);
497   if (f)
498   {
499    mode=3;
500   }
501   else
502   {
503    mode=4;
504   } 
505  }
506  if (mode==-7)
507  {
508   f=sx->GetDecalFunction(jcal);
509   if (f)
510   {
511    mode=-3;
512   }
513   else
514   {
515    mode=-4;
516   } 
517  }
518
519  if (abs(mode)==2 || abs(mode)>=4)
520  {
521   sx=(AliSignal*)GetDevice();
522   if (pj) jcal=pj;
523  }
524  if (!sx && abs(mode)>=5) sx=(AliSignal*)this;
525  if (mode==5) mode=2;
526  if (mode==-5) mode=-2;
527  if (mode==6) mode=3;
528  if (mode==-6) mode=-3;
529
530  if (fSignals)
531  {
532   if (j>0 && j<=(fSignals->GetSize()))
533   {
534    sig=fSignals->At(j-1);
535
536    if (mode==0 || !sx) return sig;
537
538    // Check for the dead flag setting
539    if (sx->GetDeadValue(jcal) || pdead) return 0;
540
541    // (De)correct the signal for the gain and offset
542    if (abs(mode)==1 || abs(mode)==2)
543    {
544     if (sx->GetGainFlag(jcal)) gain=sx->GetGain(jcal);
545     if (sx->GetOffsetFlag(jcal)) offset=sx->GetOffset(jcal);
546
547     if (fabs(gain)>0.)
548     {
549      if (mode>0) sig=(sig/gain)-offset; // Gain and offset correction
550      if (mode<0) sig=(sig+offset)*gain; // Gain and offset de-correction
551     }
552     else
553     {
554      sig=0;
555     }
556     return sig;
557    }
558
559    // (De)calibrate the signal with the corresponding (de)calibration function
560    if (abs(mode)==3 || abs(mode)==4)
561    {
562     f=sx->GetCalFunction(jcal);
563     if (mode<0) f=sx->GetDecalFunction(jcal);
564     if (f) sig=f->Eval(sig);
565     return sig;
566    }
567   }
568   else
569   {
570    cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
571   } 
572  }
573  return sig;
574 }
575 ///////////////////////////////////////////////////////////////////////////
576 Float_t AliSignal::GetSignal(TString name,Int_t mode) const
577 {
578 // Provide signal value of the name-specified slot.
579 // In case no signal is present, 0 is returned.
580 // The parameter "mode" allows for automatic (de)calibration of the signal
581 // (e.g. gain etc... correction or via explicit (de)calibration functions).
582 // For further details about the (de)calibration modes, please refer to the
583 // corresponding slot-index based memberfunction. 
584 //
585 // The default is mode=0.
586 //
587 // This procedure involves a slot-index search based on the specified name
588 // at each invokation. This may become slow in case many slots have been
589 // defined and/or when this procedure is invoked many times.
590 // In such cases it is preferable to use indexed addressing in the user code
591 // either directly or via a few invokations of GetSlotIndex().
592
593  Int_t j=GetSlotIndex(name);
594  Float_t val=0;
595  if (j>0) val=GetSignal(j,mode);
596  return val;
597 }
598 ///////////////////////////////////////////////////////////////////////////
599 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
600 {
601 // Store error on the signal for the j-th (default j=1) slot.
602 // Note : The first signal slot is at j=1.
603 // In case the value of the index j exceeds the maximum number of reserved
604 // slots for signal error values, the number of reserved slots for the
605 // signal errors is increased automatically.
606
607  if (!fDsignals)
608  {
609   fDsignals=new TArrayF(j);
610   ResetSignals(2);
611  }
612
613  Int_t size=fDsignals->GetSize();
614
615  if (j>size)
616  {
617   fDsignals->Set(j);
618  }
619
620  fDsignals->AddAt(float(dsig),j-1);
621 }
622 ///////////////////////////////////////////////////////////////////////////
623 void AliSignal::SetSignalError(Double_t dsig,TString name)
624 {
625 // Store error on the signal for the name-specified slot.
626 //
627 // This procedure involves a slot-index search based on the specified name
628 // at each invokation. This may become slow in case many slots have been
629 // defined and/or when this procedure is invoked many times.
630 // In such cases it is preferable to use indexed addressing in the user code
631 // either directly or via a few invokations of GetSlotIndex().
632
633  Int_t j=GetSlotIndex(name);
634  if (j>0) SetSignalError(dsig,j);
635 }
636 ///////////////////////////////////////////////////////////////////////////
637 Float_t AliSignal::GetSignalError(Int_t j) const
638 {
639 // Provide error on the signal of the j-th (default j=1) slot.
640 // Note : The first signal slot is at j=1.
641 // In case no signal is present or the argument j is invalid, 0 is returned.
642  Float_t err=0;
643  if (fDsignals)
644  {
645   if (j>0 && j<=(fDsignals->GetSize()))
646   {
647    err=fDsignals->At(j-1);
648   }
649   else
650   {
651    cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
652   } 
653  }
654  return err;
655 }
656 ///////////////////////////////////////////////////////////////////////////
657 Float_t AliSignal::GetSignalError(TString name) const
658 {
659 // Provide error on the signal of the name-specified slot.
660 //
661 // This procedure involves a slot-index search based on the specified name
662 // at each invokation. This may become slow in case many slots have been
663 // defined and/or when this procedure is invoked many times.
664 // In such cases it is preferable to use indexed addressing in the user code
665 // either directly or via a few invokations of GetSlotIndex().
666
667  Int_t j=GetSlotIndex(name);
668  Float_t val=0;
669  if (j>0) val=GetSignalError(j);
670  return val;
671 }
672 ///////////////////////////////////////////////////////////////////////////
673 void AliSignal::Data(TString f) const
674 {
675 // Provide all signal information within the coordinate frame f.
676
677  const char* name=GetName();
678  const char* title=GetTitle();
679
680  cout << " *" << ClassName() << "::Data* Id : " << GetUniqueID();
681  if (strlen(name))  cout << " Name : " << name;
682  if (strlen(title)) cout << " Title : " << title;
683  cout << endl;
684  cout << "   Position";
685  AliPosition::Data(f);
686  if (fDevice)
687  {
688   const char* devname=fDevice->GetName();
689   const char* devtitle=fDevice->GetTitle();
690   cout << "   Owned by device : " << fDevice->ClassName()
691        << " Id : " << fDevice->GetUniqueID();
692   if (strlen(devname))  cout << " Name : " << devname;
693   if (strlen(devtitle)) cout << " Title : " << devtitle;
694   cout << endl;
695  }
696
697  // Provide an overview of the stored waveforms
698  ListWaveform(-1);
699
700  // Provide an overview of all the data and attribute slots
701  List(-1);
702
703 ///////////////////////////////////////////////////////////////////////////
704 void AliSignal::List(Int_t j) const
705 {
706 // Provide signal information for the j-th slot.
707 // The first slot is at j=1.
708 // In case j=0 (default) the data of all slots will be listed.
709 // In case j=-1 the data of all slots will be listed, but the header
710 // information will be suppressed.
711
712  if (j<-1) 
713  {
714   cout << " *AliSignal::List* Invalid argument j = " << j << endl;
715   return;
716  }
717
718  if (j != -1)
719  {
720   const char* name=GetName();
721   const char* title=GetTitle();
722
723   cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
724   if (strlen(name))  cout << " Name : " << name;
725   if (strlen(title)) cout << " Title : " << title;
726   cout << endl;
727   if (fDevice)
728   {
729    const char* devname=fDevice->GetName();
730    const char* devtitle=fDevice->GetTitle();
731    cout << "   Owned by device : " << fDevice->ClassName();
732    if (strlen(devname))  cout << " Name : " << devname;
733    if (strlen(devtitle)) cout << " Title : " << devtitle;
734    cout << endl;
735   }
736  }
737
738  Int_t nvalues=GetNvalues();
739  Int_t nerrors=GetNerrors();
740  Int_t nlinkslots=0;
741  if (fLinks) nlinkslots=fLinks->GetMaxColumn();
742  Int_t ncalibs=GetNcalflags();
743  Int_t ncalfuncs=GetNcalfuncs();
744  Int_t ndecalfuncs=GetNdecalfuncs();
745
746  Int_t n=nvalues;
747  if (nerrors>n) n=nerrors;
748  if (nlinkslots>n) n=nlinkslots;
749  if (InheritsFrom("AliDevice"))
750  {
751   if (ncalibs>n) n=ncalibs;
752   if (ncalfuncs>n) n=ncalfuncs;
753   if (ndecalfuncs>n) n=ndecalfuncs;
754  }
755  
756  TObject* obj=0;
757  Int_t nrefs=0;
758  TArrayI posarr;
759  Int_t pos;
760
761  if (j<=0)
762  {
763   for (Int_t i=1; i<=n; i++)
764   {
765    cout << "   Slot : " << i;
766    if (i<=nvalues) cout << " Signal value : " << GetSignal(i);
767    if (i<=nerrors) cout << " error : " << GetSignalError(i);
768    AliAttrib::List(i);
769    cout << endl;
770    obj=0;
771    nrefs=GetIndices(obj,i,posarr);
772    for (Int_t k=0; k<nrefs; k++)
773    {
774     pos=posarr.At(k);
775     obj=GetLink(i,pos);
776     if (obj)
777     {
778      cout << "    Link at position " << pos << " to : " << obj->ClassName();
779      if (obj->InheritsFrom("TNamed"))
780      {
781       const char* lname=obj->GetName();
782       const char* ltitle=obj->GetTitle();
783       if (strlen(lname))  cout << " Name : " << lname;
784       if (strlen(ltitle)) cout << " Title : " << ltitle;
785      }
786      cout << endl;
787     }
788    }
789   }
790  }
791  else
792  {
793   if (j<=n)
794   {
795    cout << "   Slot : " << j;
796    if (j<=nvalues) cout << " Signal value : " << GetSignal(j);
797    if (j<=nerrors) cout << " error : " << GetSignalError(j);
798    AliAttrib::List(j);
799    cout << endl;
800    obj=0;
801    nrefs=GetIndices(obj,j,posarr);
802    for (Int_t kj=0; kj<nrefs; kj++)
803    {
804     pos=posarr.At(kj);
805     obj=GetLink(j,pos);
806     if (obj)
807     {
808      cout << "    Link at position " << pos << " to : " << obj->ClassName();
809      if (obj->InheritsFrom("TNamed"))
810      {
811       const char* lnamej=obj->GetName();
812       const char* ltitlej=obj->GetTitle();
813       if (strlen(lnamej))  cout << " Name : " << lnamej;
814       if (strlen(ltitlej)) cout << " Title : " << ltitlej;
815      }
816      cout << endl;
817     }
818    }
819   }
820  }
821
822 ///////////////////////////////////////////////////////////////////////////
823 void AliSignal::List(TString name) const
824 {
825 // Provide signal information for the name-specified slot.
826 //
827 // This procedure involves a slot-index search based on the specified name
828 // at each invokation. This may become slow in case many slots have been
829 // defined and/or when this procedure is invoked many times.
830 // In such cases it is preferable to use indexed addressing in the user code
831 // either directly or via a few invokations of GetSlotIndex().
832
833  Int_t j=GetSlotIndex(name);
834  if (j>0) List(j);
835 }
836 ///////////////////////////////////////////////////////////////////////////
837 void AliSignal::ListWaveform(Int_t j) const
838 {
839 // Provide information for the j-th waveform.
840 // The first waveform is at j=1.
841 // In case j=0 (default) the info of all waveforms will be listed.
842 // In case j=-1 the info of all waveforms will be listed, but the header
843 // information will be suppressed.
844
845  if (j<-1) 
846  {
847   cout << " *AliSignal::ListWaveform* Invalid argument j = " << j << endl;
848   return;
849  }
850
851  if (j != -1)
852  {
853   const char* name=GetName();
854   const char* title=GetTitle();
855
856   cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
857   if (strlen(name))  cout << " Name : " << name;
858   if (strlen(title)) cout << " Title : " << title;
859   cout << endl;
860   if (fDevice)
861   {
862    const char* devname=fDevice->GetName();
863    const char* devtitle=fDevice->GetTitle();
864    cout << "   Owned by device : " << fDevice->ClassName();
865    if (strlen(devname))  cout << " Name : " << devname;
866    if (strlen(devtitle)) cout << " Title : " << devtitle;
867    cout << endl;
868   }
869  }
870
871  Int_t n=GetNwaveforms();
872  TObject* obj=0;
873
874  if (j<=0)
875  {
876   for (Int_t i=1; i<=n; i++)
877   {
878    obj=GetWaveform(i);
879    if (obj)
880    {
881     const char* wfname=obj->GetName();
882     const char* wftitle=obj->GetTitle();
883     cout << "    Waveform " << i << " : " << obj->ClassName();
884     if (strlen(wfname))  cout << " Name : " << wfname;
885     if (strlen(wftitle)) cout << " Title : " << wftitle;
886     cout << endl;
887    }
888   }
889  }
890  else
891  {
892   if (j<=n)
893   {
894    obj=GetWaveform(j);
895    if (obj)
896    {
897     const char* wfnamej=obj->GetName();
898     const char* wftitlej=obj->GetTitle();
899     cout << "    Waveform " << j << " : " << obj->ClassName();
900     if (strlen(wfnamej))  cout << " Name : " << wfnamej;
901     if (strlen(wftitlej)) cout << " Title : " << wftitlej;
902     cout << endl;
903    }
904   }
905  }
906 }
907 ///////////////////////////////////////////////////////////////////////////
908 Int_t AliSignal::GetNvalues() const
909 {
910 // Provide the number of values for this signal.
911  Int_t n=0;
912  if (fSignals) n=fSignals->GetSize();
913  return n;
914 }
915 ///////////////////////////////////////////////////////////////////////////
916 Int_t AliSignal::GetNerrors() const
917 {
918 // Provide the number specified errors on the values for this signal.
919  Int_t n=0;
920  if (fDsignals) n=fDsignals->GetSize();
921  return n;
922 }
923 ///////////////////////////////////////////////////////////////////////////
924 Int_t AliSignal::GetNwaveforms() const
925 {
926 // Provide the number of specified waveforms for this signal.
927 // Actually the return value is the highest index of the stored waveforms.
928 // This allows an index dependent meaning of waveform info (e.g. waveforms
929 // with various gain values).
930 // So, when all waveforms are stored in consequetive positions (e.g. 1,2,3),
931 // this memberfunction returns 3, being both the highest filled position
932 // and the actual number of waveforms.
933 // In case only waveforms are stored at positions 1,2,5,7 this memberfunction
934 // returns a value 7 whereas only 4 actual waveforms are present.
935 // This implies that when looping over the various waveform slots, one
936 // always has to check whether the returned pointer value is non-zero
937 // (which is a good practice anyhow).
938  Int_t n=-1;
939  if (fWaveforms) n=fWaveforms->GetLast();
940  return (n+1);
941 }
942 ///////////////////////////////////////////////////////////////////////////
943 TH1F* AliSignal::GetWaveform(Int_t j) const
944 {
945 // Provide pointer to the j-th waveform histogram.
946  TH1F* waveform=0;
947  if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
948  return waveform;
949 }
950 ///////////////////////////////////////////////////////////////////////////
951 TH1F* AliSignal::GetWaveform(TString name) const
952 {
953 // Provide pointer to the waveform histogram with the specified name.
954 // In case no match is found, zero is returned.
955  Int_t n=GetNwaveforms();
956  TString str;
957  for (Int_t i=1; i<=n; i++)
958  {
959   TH1F* waveform=GetWaveform(i);
960   if (waveform)
961   {
962    str=waveform->GetName();
963    if (str == name) return waveform;
964   }
965  }
966  return 0; // No match found
967 }
968 ///////////////////////////////////////////////////////////////////////////
969 Int_t AliSignal::GetWaveformIndex(TString name) const
970 {
971 // Provide index to the waveform histogram with the specified name.
972 // In case no match is found, zero is returned.
973  Int_t n=GetNwaveforms();
974  TString str;
975  for (Int_t i=1; i<=n; i++)
976  {
977   TH1F* waveform=GetWaveform(i);
978   if (waveform)
979   {
980    str=waveform->GetName();
981    if (str == name) return i;
982   }
983  }
984  return 0; // No match found
985 }
986 ///////////////////////////////////////////////////////////////////////////
987 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
988 {
989 // Set the 1D waveform histogram for the j-th waveform.
990 //
991 // Notes :
992 //  The first waveform position at j=1.
993 //  j=1 is the default value.
994 //
995 // In case the value of the index j exceeds the maximum number of reserved
996 // positions for the waveforms, the number of reserved positions for the waveforms
997 // is increased automatically.
998 //
999 // In case the histo pointer argument has the same value as the current waveform
1000 // histogram pointer value, no action is taken since the user has already
1001 // modified the actual histogram.
1002 //
1003 // In case the histo pointer argument is zero, the current waveform histogram
1004 // is deleted and the pointer set to zero.
1005 //
1006 // In all other cases the current waveform histogram is deleted and a new
1007 // copy of the input histogram is created which becomes the current waveform
1008 // histogram.
1009
1010  if (j<1) return;
1011
1012  if (!fWaveforms)
1013  {
1014   fWaveforms=new TObjArray(j);
1015   fWaveforms->SetOwner();
1016  }
1017
1018  if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
1019
1020  TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
1021  if (waveform != hcur)
1022  {
1023   if (hcur)
1024   {
1025    fWaveforms->Remove(hcur);
1026    delete hcur;
1027    hcur=0;
1028   }
1029   if (waveform)
1030   {
1031    hcur=new TH1F(*waveform);
1032    fWaveforms->AddAt(hcur,j-1);
1033   }
1034  } 
1035 }
1036 ///////////////////////////////////////////////////////////////////////////
1037 void AliSignal::ResetWaveform(Int_t j)
1038 {
1039 // Reset the histogram of the j-th (default j=1) waveform.
1040 // This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
1041 // To actually delete the histograms from memory, use DeleteWaveform().
1042 // Notes : The first position is at j=1.
1043 //         j=0 ==> All waveforms will be reset.
1044  
1045  if (!fWaveforms) return;
1046
1047  Int_t size=fWaveforms->GetSize();
1048
1049  if ((j>=0) && (j<=size))
1050  {
1051   if (j)
1052   {
1053    TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
1054    if (hwave) hwave->Reset();
1055   }
1056   else
1057   {
1058    for (Int_t i=0; i<size; i++)
1059    {
1060     TH1F* hwave=(TH1F*)fWaveforms->At(i);
1061     if (hwave) hwave->Reset();
1062    }
1063   }
1064  }
1065  else
1066  {
1067   cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
1068   return;
1069  }
1070 }
1071 ///////////////////////////////////////////////////////////////////////////
1072 void AliSignal::ResetWaveform(TString name)
1073 {
1074 // Reset the waveform with the specified name.
1075  Int_t j=GetWaveformIndex(name);
1076  if (j>0) ResetWaveform(j);
1077 }
1078 ///////////////////////////////////////////////////////////////////////////
1079 void AliSignal::DeleteWaveform(Int_t j)
1080 {
1081 // Delete the histogram of the j-th (default j=1) waveform.
1082 // Notes : The first position is at j=1.
1083 //         j=0 ==> All waveforms will be deleted.
1084  
1085  if (!fWaveforms) return;
1086
1087  Int_t size=fWaveforms->GetSize();
1088
1089  if ((j>=0) && (j<=size))
1090  {
1091   if (j)
1092   {
1093    TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
1094    if (hwave)
1095    {
1096     fWaveforms->Remove(hwave);
1097     delete hwave;
1098    }
1099   }
1100   else
1101   {
1102    delete fWaveforms;
1103    fWaveforms=0;
1104   }
1105  }
1106  else
1107  {
1108   cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
1109   return;
1110  }
1111 }
1112 ///////////////////////////////////////////////////////////////////////////
1113 void AliSignal::DeleteWaveform(TString name)
1114 {
1115 // Delete the waveform with the specified name.
1116  Int_t j=GetWaveformIndex(name);
1117  if (j>0) DeleteWaveform(j);
1118 }
1119 ///////////////////////////////////////////////////////////////////////////
1120 Int_t AliSignal::GetNlinks(TObject* obj,Int_t j) const
1121 {
1122 // Provide the number of links to the specified object for the j-th slot.
1123 // If j=0 (default) all slots will be scanned for the specified object.
1124 // If obj=0 (default) all encountered objects for the specified slot will be counted.
1125 // So, invokation of the default GetNlinks() will return the total number of
1126 // all references to all sorts of stored objects.
1127  if (j<0)
1128  {
1129   cout << " *AliSignal::GetNlinks* Index j = " << j << " invalid." << endl;
1130   return 0;
1131  }
1132
1133  Int_t n=0;
1134  if (!j)
1135  {
1136   if (fLinks) n=fLinks->GetNrefs(obj);
1137  }
1138  else
1139  {
1140   TArrayI posarr;
1141   n=GetIndices(obj,j,posarr);
1142  }
1143  return n;
1144 }
1145 ///////////////////////////////////////////////////////////////////////////
1146 Int_t AliSignal::GetNlinks(TObject* obj,TString name) const
1147 {
1148 // Provide the number of links to the specified object for the name-spec. slot.
1149 // If obj=0 all encountered objects for the specified slot will be counted.
1150 //
1151 // This procedure involves a slot-index search based on the specified name
1152 // at each invokation. This may become slow in case many slots have been
1153 // defined and/or when this procedure is invoked many times.
1154 // In such cases it is preferable to use indexed addressing in the user code
1155 // either directly or via a few invokations of GetSlotIndex().
1156
1157  Int_t j=GetSlotIndex(name);
1158  Int_t n=0;
1159  if (j>0) n=GetNlinks(obj,j);
1160  return n;
1161 }
1162 ///////////////////////////////////////////////////////////////////////////
1163 TObject* AliSignal::GetLink(Int_t j,Int_t k) const
1164 {
1165 // Provide pointer of the object linked to the j-th slot at position k.
1166
1167  TObject* obj=0;
1168  // Note : In the internal storage matrix slots=columns positions=rows 
1169  if (fLinks) obj=fLinks->GetObject(k,j);
1170  return obj;
1171 }
1172 ///////////////////////////////////////////////////////////////////////////
1173 TObject* AliSignal::GetLink(TString name,Int_t k) const
1174 {
1175 // Provide pointer of the object linked to the name-spec. slot at position k.
1176 //
1177 // This procedure involves a slot-index search based on the specified name
1178 // at each invokation. This may become slow in case many slots have been
1179 // defined and/or when this procedure is invoked many times.
1180 // In such cases it is preferable to use indexed addressing in the user code
1181 // either directly or via a few invokations of GetSlotIndex().
1182
1183  Int_t j=GetSlotIndex(name);
1184  TObject* obj=0;
1185  if (j>0) obj=GetLink(j,k);
1186  return obj;
1187 }
1188 ///////////////////////////////////////////////////////////////////////////
1189 void AliSignal::SetLink(TObject* obj,Int_t j,Int_t k)
1190 {
1191 // Introduce a link (=pointer) to an object for the j-th slot at position k.
1192 // Only the pointer values are stored for (backward) reference, meaning
1193 // that the objects of which the pointers are stored are NOT owned
1194 // by the AliSignal object.
1195 //
1196 // Notes :
1197 //  The first slot is at j=1 and the first position is at k=1.
1198 //  j=1 and k=1 are the default values.
1199 //
1200 // If needed, the storage area for the links is increased automatically.
1201 //
1202 // In case the pointer argument is zero, indeed a value of zero will be
1203 // stored at the specified position (k) for the specified slot (j).
1204 //
1205 // In principle any object derived from TObject can be referred to by this
1206 // mechanism.
1207 // However, this "linking back" facility was introduced to enable AliSignal slots
1208 // to refer directly to the various AliTracks to which the AliSignal object itself
1209 // is related (see AliTrack::AddSignal).
1210 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1211 // object, the current signal is automatically related to this AliTrack
1212 // (or derived) object.
1213 // 
1214 // Please also have a look at the docs of the memberfunction ResetLink()
1215 // to prevent the situation of stored pointers to non-existent object. 
1216
1217  if (!fLinks && obj) fLinks=new AliObjMatrix();
1218
1219  if (!fLinks) return;
1220
1221  // Note : In the internal storage matrix slots=columns positions=rows 
1222  fLinks->EnterObject(k,j,obj);
1223  if (obj) 
1224  {
1225   if (obj->InheritsFrom("AliTrack"))
1226   {
1227    AliTrack* t=(AliTrack*)obj;
1228    t->AddSignal(*this);
1229   }
1230  }
1231 }
1232 ///////////////////////////////////////////////////////////////////////////
1233 void AliSignal::SetLink(TObject* obj,TString name,Int_t k)
1234 {
1235 // Introduce a link (=pointer) to an object for the name-spec. slot at position k.
1236 // Only the pointer values are stored for (backward) reference, meaning
1237 // that the objects of which the pointers are stored are NOT owned
1238 // by the AliSignal object.
1239 //
1240 // This procedure involves a slot-index search based on the specified name
1241 // at each invokation. This may become slow in case many slots have been
1242 // defined and/or when this procedure is invoked many times.
1243 // In such cases it is preferable to use indexed addressing in the user code
1244 // either directly or via a few invokations of GetSlotIndex().
1245
1246  Int_t j=GetSlotIndex(name);
1247  if (j>0) SetLink(obj,j,k);
1248 }
1249 ///////////////////////////////////////////////////////////////////////////
1250 void AliSignal::AddLink(TObject* obj,Int_t j)
1251 {
1252 // Introduce a link (=pointer) to an object for the j-th slot at the first
1253 // free position.
1254 // Only the pointer values are stored for (backward) reference, meaning
1255 // that the objects of which the pointers are stored are NOT owned
1256 // by the AliSignal object.
1257 //
1258 // Notes :
1259 //  The first slot is at j=1 and the first position is at k=1.
1260 //  j=1 is the default value.
1261 //
1262 // If needed, the storage area for the links is increased automatically.
1263 //
1264 // In case the pointer argument is zero, no link will be added.
1265 //
1266 // In principle any object derived from TObject can be referred to by this
1267 // mechanism.
1268 // However, this "linking back" facility was introduced to enable AliSignal slots
1269 // to refer directly to the various AliTracks to which the AliSignal object itself
1270 // is related (see AliTrack::AddSignal).
1271 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1272 // object, the current signal is automatically related to this AliTrack
1273 // (or derived) object.
1274 // 
1275 // Please also have a look at the docs of the memberfunction ResetLink()
1276 // to prevent the situation of stored pointers to non-existent object. 
1277
1278  if (!obj || j<=0) return;
1279
1280  if (!fLinks) fLinks=new AliObjMatrix();
1281
1282  TObject* dum=0;
1283  Int_t n=GetNlinks(dum,j);
1284  Int_t pos=1;
1285  for (Int_t k=1; k<=n; k++)
1286  {
1287   dum=GetLink(j,k);
1288   if (!dum) break;
1289   pos++;
1290  }
1291
1292  SetLink(obj,j,pos);
1293 }
1294 ///////////////////////////////////////////////////////////////////////////
1295 void AliSignal::AddLink(TObject* obj,TString name)
1296 {
1297 // Introduce a link (=pointer) to an object for the name-spec slot at the first
1298 // free position.
1299 // Only the pointer values are stored for (backward) reference, meaning
1300 // that the objects of which the pointers are stored are NOT owned
1301 // by the AliSignal object.
1302 //
1303 // This procedure involves a slot-index search based on the specified name
1304 // at each invokation. This may become slow in case many slots have been
1305 // defined and/or when this procedure is invoked many times.
1306 // In such cases it is preferable to use indexed addressing in the user code
1307 // either directly or via a few invokations of GetSlotIndex().
1308
1309  Int_t j=GetSlotIndex(name);
1310  if (j>0) AddLink(obj,j);
1311 }
1312 ///////////////////////////////////////////////////////////////////////////
1313 void AliSignal::ResetLink(Int_t j,Int_t k)
1314 {
1315 // Reset the link of the j-th slot at position k.
1316 //
1317 // Notes :
1318 //  The first slot is at j=1 and the first position is at k=1.
1319 //  j=1 and k=1 are the default values.
1320 //
1321 //  This memberfunction is intended to reset only 1 specified link location.
1322 //  For extended functionality, please refer to the memberfuction ResetLinks().
1323 //
1324 // In general the user should take care of properly clearing the corresponding
1325 // pointer here when the referred object is deleted.
1326 // However, this "linking back" facility was introduced to enable AliSignal slots
1327 // to refer directly to the various AliTracks to which the AliSignal object itself
1328 // is related (see AliTrack::AddSignal).
1329 // As such, the AliTrack destructor already takes care of clearing the corresponding
1330 // links from the various AliSignal slots for all the AliSignal objects that were
1331 // related to that AliTrack. 
1332 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1333 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1334 // the AliSignal object when the corresponding AliTrack object is deleted.
1335  
1336  // Note : In the internal storage matrix slots=columns positions=rows 
1337  if (fLinks) fLinks->RemoveObject(k,j);
1338 }
1339 ///////////////////////////////////////////////////////////////////////////
1340 void AliSignal::ResetLink(TString name,Int_t k)
1341 {
1342 // Reset the link of the name-specified slot at position k.
1343 //
1344 // This memberfunction is intended to reset only 1 specified link location.
1345 // For extended functionality, please refer to the memberfuction ResetLinks().
1346 //
1347 // This procedure involves a slot-index search based on the specified name
1348 // at each invokation. This may become slow in case many slots have been
1349 // defined and/or when this procedure is invoked many times.
1350 // In such cases it is preferable to use indexed addressing in the user code
1351 // either directly or via a few invokations of GetSlotIndex().
1352
1353  Int_t j=GetSlotIndex(name);
1354  if (j>0) ResetLink(j,k);
1355 }
1356 ///////////////////////////////////////////////////////////////////////////
1357 void AliSignal::ResetLinks(TObject* obj,Int_t j,Int_t k)
1358 {
1359 // Reset single or multiple link(s) according to user specified selections.
1360 //
1361 // A link is only reset if the stored reference matches the argument "obj".
1362 // In case obj=0 no check on the matching of the stored reference is performed
1363 // and the stored link is always reset in accordance with the other
1364 // selection criteria.
1365 //
1366 // In case the slot argument "j" is specified, only the links from that
1367 // specified slot will be deleted.
1368 // In case j=0 (default) no checking on the slot index is performed.
1369 //
1370 // In case the position argument "k" is specified, only the links from that
1371 // specified position will be deleted.
1372 // In case k=0 (default) no checking on the position index is performed.
1373 //
1374 // So, invokation of ResetLinks(obj) will remove all references to the
1375 // object "obj" from the total AliSignal, whereas ResetLinks(obj,j)
1376 // will remove all references to the object "obj" only from slot "j".
1377 //
1378 // Notes :
1379 // -------
1380 // The first slot is indicated as j=1, whereas the first position is at k=1.
1381 //
1382 // Invokation of ResetLinks(0,row,col) is equivalent to invoking the
1383 // memberfunction ResetLink(row,col).
1384 // Invoking the latter directly is slightly faster.
1385 //
1386 // Invokation of ResetLinks(0) will reset all stored references in this AliSignal.
1387 //
1388 // In general the user should take care of properly clearing the corresponding
1389 // pointer here when the referred object is deleted.
1390 // However, this "linking back" facility was introduced to enable AliSignal slots
1391 // to refer directly to the various AliTracks to which the AliSignal object itself
1392 // is related (see AliTrack::AddSignal).
1393 // As such, the AliTrack destructor already takes care of clearing the corresponding
1394 // links from the various AliSignal slots for all the AliSignal objects that were
1395 // related to that AliTrack. 
1396 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1397 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1398 // the AliSignal object when the corresponding AliTrack object is deleted.
1399  
1400  if (!fLinks) return;
1401
1402  if (!obj && !j && !k)
1403  {
1404   fLinks->Reset();
1405  }
1406  else
1407  {
1408   // Note : In the internal storage matrix slots=columns positions=rows 
1409   fLinks->RemoveObjects(obj,k,j);
1410  }
1411 }
1412 ///////////////////////////////////////////////////////////////////////////
1413 void AliSignal::ResetLinks(TObject* obj,TString name,Int_t k)
1414 {
1415 // Reset single or multiple link(s) according to user specified selections.
1416 //
1417 // A link is only reset if the stored reference matches the argument "obj".
1418 // In case obj=0 no check on the matching of the stored reference is performed
1419 // and the stored link is always reset in accordance with the other
1420 // selection criteria.
1421 //
1422 // In case the position argument "k" is specified, only the links from that
1423 // specified position will be deleted.
1424 // In case k=0 (default) no checking on the position index is performed.
1425 //
1426 // This procedure involves a slot-index search based on the specified name
1427 // at each invokation. This may become slow in case many slots have been
1428 // defined and/or when this procedure is invoked many times.
1429 // In such cases it is preferable to use indexed addressing in the user code
1430 // either directly or via a few invokations of GetSlotIndex().
1431
1432  Int_t j=GetSlotIndex(name);
1433  if (j>0) ResetLinks(obj,j,k);
1434 }
1435 ///////////////////////////////////////////////////////////////////////////
1436 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,TArrayI& ks) const
1437 {
1438 // Provide the slot and position indices of all the storage locations
1439 // of the specified object.
1440 // The slot (j) and pos. (k) indices are returned in the two separate TArrayI arrays
1441 // from which the (j,k) pairs can be obtained from the corresponding
1442 // array indices like (j,k)=(js.At(i),ks.At(i)).
1443 // The integer return argument represents the number of (j,k) pairs which
1444 // were encountered for the specified object.
1445 //
1446 // If obj=0 no object selection is performed and all (j,k) indices
1447 // of the stored references for all objects are returned.
1448 //
1449 // Notes :
1450 // -------
1451 // As usual the convention is that slot and position numbering starts at 1.
1452 // 
1453 // This memberfunction always resets the two TArrayI arrays at the start.
1454 //
1455 // This memberfunction can only be used to obtain the (j,k) indices
1456 // of the object as stored via the SetLink() or AddLink() memberfunction.
1457 // This means that in case the user has entered a TObjArray as object
1458 // (to increase the dimension of the resulting structure), the (j,k)
1459 // indices of that TObjArray are obtained and NOT the indices of the
1460 // actual objects contained in that TObjArray structure.
1461 //
1462  Int_t nrefs=0;
1463  js.Reset();
1464  ks.Reset();
1465  // Note : In the internal storage matrix slots=columns positions=rows 
1466  if (fLinks) nrefs=fLinks->GetIndices(obj,ks,js);
1467  return nrefs;
1468 }
1469 ///////////////////////////////////////////////////////////////////////////
1470 Int_t AliSignal::GetIndices(TObject* obj,Int_t j,TArrayI& ks) const
1471 {
1472 // Provide the position indices of all the storage locations of the
1473 // specified object in the j-th slot of this AliSignal.
1474 // The position indices are returned in the TArrayI array.
1475 // The integer return argument represents the number of storage locations which
1476 // were encountered for the specified object in the j-th slot.
1477 //
1478 // If obj=0 no object selection is performed and all position indices
1479 // of the stored references for all objects of the j-th slot are returned.
1480 //
1481 // If j=0 all slots will be scanned and all position indices matching the
1482 // object selection are returned.
1483 // Note that in this case multiple appearances of the same position index
1484 // will only be recorded once in the returned TArrayI array.
1485 //
1486 // Notes :
1487 // -------
1488 // As usual the convention is that slot and position numbering starts at 1.
1489 // 
1490 // This memberfunction always resets the TArrayI array at the start.
1491 //
1492 // This memberfunction can only be used to obtain the position indices
1493 // of the object as stored via the SetLink() or AddLink() memberfunction.
1494 // This means that in case the user has entered a TObjArray as object
1495 // (to increase the dimension of the resulting structure), the position
1496 // indices of that TObjArray are obtained and NOT the indices of the
1497 // actual objects contained in that TObjArray structure.
1498 //
1499  Int_t nrefs=0;
1500  ks.Reset();
1501  // Note : In the internal storage matrix slots=columns positions=rows 
1502  if (fLinks) nrefs=fLinks->GetIndices(obj,ks,j);
1503  return nrefs;
1504 }
1505 ///////////////////////////////////////////////////////////////////////////
1506 Int_t AliSignal::GetIndices(TObject* obj,TString name,TArrayI& ks) const
1507 {
1508 // Provide the position indices of all the storage locations of the
1509 // specified object in the name-specified slot of this AliSignal.
1510 // The position indices are returned in the TArrayI array.
1511 // The integer return argument represents the number of storage locations which
1512 // were encountered for the specified object in the j-th slot.
1513 //
1514 // If obj=0 no object selection is performed and all position indices
1515 // of the stored references for all objects of the j-th slot are returned.
1516 //
1517 // This procedure involves a slot-index search based on the specified name
1518 // at each invokation. This may become slow in case many slots have been
1519 // defined and/or when this procedure is invoked many times.
1520 // In such cases it is preferable to use indexed addressing in the user code
1521 // either directly or via a few invokations of GetSlotIndex().
1522
1523  Int_t j=GetSlotIndex(name);
1524  Int_t n=0;
1525  if (j>0) n=GetIndices(obj,j,ks);
1526  return n;
1527 }
1528 ///////////////////////////////////////////////////////////////////////////
1529 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,Int_t k) const
1530 {
1531 // Provide the slot indices of all the storage locations of the
1532 // specified object for the k-th position in this AliSignal.
1533 // The slot indices are returned in the TArrayI array.
1534 // The integer return argument represents the number of storage locations which
1535 // were encountered for the specified object in the k-th position.
1536 //
1537 // If obj=0 no object selection is performed and all slot indices
1538 // of the stored references for all objects in the k-th position are returned.
1539 //
1540 // If k=0 all positions will be scanned and all slot indices matching the
1541 // object selection are returned.
1542 // Note that in this case multiple appearances of the same slot index
1543 // will only be recorded once in the returned TArrayI array.
1544 //
1545 // Notes :
1546 // -------
1547 // As usual the convention is that slot and position numbering starts at 1.
1548 // 
1549 // This memberfunction always resets the TArrayI array at the start.
1550 //
1551 // This memberfunction can only be used to obtain the slot indices
1552 // of the object as stored via the SetLink() or AddLink() memberfunction.
1553 // This means that in case the user has entered a TObjArray as object
1554 // (to increase the dimension of the resulting structure), the slot
1555 // indices of that TObjArray are obtained and NOT the indices of the
1556 // actual objects contained in that TObjArray structure.
1557 //
1558  Int_t nrefs=0;
1559  js.Reset();
1560  // Note : In the internal storage matrix slots=columns positions=rows 
1561  if (fLinks) nrefs=fLinks->GetIndices(obj,k,js);
1562  return nrefs;
1563 }
1564 ///////////////////////////////////////////////////////////////////////////
1565 void AliSignal::SetSwapMode(Int_t swap)
1566 {
1567 // Set swapmode flag for the internal link storage.
1568 // In case for the stored links the maximum slot number differs considerably
1569 // from the maximum position number, it might be more efficient
1570 // (w.r.t. memory usage and/or output file size) to internally store the
1571 // link reference matrix with the rows and colums swapped.
1572 // This swapping is only related with the internal storage and as such
1573 // is completely hidden for the user.
1574 // At invokation of this memberfunction the default argument is swap=1.
1575 //
1576 // Note : The swap mode can only be set as long as no links are
1577 //        stored in the AliSignal (i.e. a new instance of AliSignal
1578 //        or after invokation of the Reset() or ResetLinks() function).
1579  
1580  if (!fLinks) fLinks=new AliObjMatrix();
1581  fLinks->SetSwapMode(swap);
1582 }
1583 ///////////////////////////////////////////////////////////////////////////
1584 Int_t AliSignal::GetSwapMode() const
1585 {
1586 // Provide swapmode flag of the link storage.
1587  Int_t swap=0; 
1588  if (fLinks) swap=fLinks->GetSwapMode();
1589  return swap;
1590 }
1591 ///////////////////////////////////////////////////////////////////////////
1592 void AliSignal::SetDevice(TObject* dev)
1593 {
1594 // Store the pointer to the device which owns this AliSignal object.
1595 // This memberfunction is meant for internal use in AliDevice.
1596  fDevice=dev;
1597 }
1598 ///////////////////////////////////////////////////////////////////////////
1599 AliDevice* AliSignal::GetDevice() const
1600 {
1601 // Provide the pointer to the device which owns this AliSignal object.
1602  return (AliDevice*)fDevice;
1603 }
1604 ///////////////////////////////////////////////////////////////////////////
1605 TObject* AliSignal::Clone(const char* name) const
1606 {
1607 // Make a deep copy of the current object and provide the pointer to the copy.
1608 // This memberfunction enables automatic creation of new objects of the
1609 // correct type depending on the object type, a feature which may be very useful
1610 // for containers when adding objects in case the container owns the objects.
1611 // This feature allows e.g. AliTrack to store either AliSignal objects or
1612 // objects derived from AliSignal via the AddSignal memberfunction, provided
1613 // these derived classes also have a proper Clone memberfunction. 
1614
1615  AliSignal* sig=new AliSignal(*this);
1616  if (name)
1617  {
1618   if (strlen(name)) sig->SetName(name);
1619  }
1620  return sig;
1621 }
1622 ///////////////////////////////////////////////////////////////////////////