]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliSignal.cxx
New functions (Marian)
[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  fSigflags=0;
127  fWaveforms=0;
128  fLinks=0;
129  fDevice=0;
130  fTracks=0;
131 }
132 ///////////////////////////////////////////////////////////////////////////
133 AliSignal::~AliSignal()
134 {
135 // Destructor to delete dynamically allocated memory
136  if (fSignals)
137  {
138   delete fSignals;
139   fSignals=0;
140  }
141  if (fDsignals)
142  {
143   delete fDsignals;
144   fDsignals=0;
145  }
146  if (fSigflags)
147  {
148   delete fSigflags;
149   fSigflags=0;
150  }
151  if (fWaveforms)
152  {
153   delete fWaveforms;
154   fWaveforms=0;
155  }
156  if (fLinks)
157  {
158   delete fLinks;
159   fLinks=0;
160  }
161  if (fTracks)
162  {
163   // Remove this signal from all related tracks
164   for (Int_t i=1; i<=GetNtracks(); i++)
165   {
166    AliTrack* tx=GetTrack(i);
167    if (tx) tx->RemoveSignal(*this,0);
168   }
169   delete fTracks;
170   fTracks=0;
171  }
172 }
173 ///////////////////////////////////////////////////////////////////////////
174 AliSignal::AliSignal(const AliSignal& s) : TNamed(s),AliPosition(s),AliAttrib(s)
175 {
176 // Copy constructor
177  fSignals=0;
178  fDsignals=0;
179  fSigflags=0;
180  fWaveforms=0;
181  fLinks=0;
182  fTracks=0;
183
184  // Don't copy the owning device pointer for the copy
185  fDevice=0;
186
187  Int_t n=s.GetNvalues();
188  Double_t val;
189  for (Int_t i=1; i<=n; i++)
190  {
191   if (s.GetSignalFlag(i))
192   {
193    val=s.GetSignal(i);
194    SetSignal(val,i);
195   }
196  } 
197
198  n=s.GetNerrors();
199  for (Int_t j=1; j<=n; j++)
200  {
201   if (s.GetErrorFlag(j))
202   {
203    val=s.GetSignalError(j);
204    SetSignalError(val,j);
205   }
206  }
207
208  n=s.GetNwaveforms();
209  for (Int_t k=1; k<=n; k++)
210  {
211   TH1F* hist=s.GetWaveform(k);
212   if (hist) SetWaveform(hist,k); 
213  }
214
215  TArrayI slotarr;
216  TArrayI posarr;
217  TObject* dum=0;
218  n=s.GetIndices(dum,slotarr,posarr);
219  Int_t slot,pos;
220  for (Int_t idx=0; idx<n; idx++)
221  {
222   slot=slotarr.At(idx);
223   pos=posarr.At(idx);
224   TObject* obj=s.GetLink(slot,pos);
225   if (obj) SetLink(obj,slot,pos); 
226  }
227
228  Int_t ntk=s.GetNtracks();
229  if (ntk)
230  {
231   fTracks=new TObjArray(ntk);
232   for (Int_t it=1; it<=ntk; it++)
233   {
234    AliTrack* tx=s.GetTrack(it);
235    fTracks->Add(tx);
236   }
237  }
238 }
239 ///////////////////////////////////////////////////////////////////////////
240 void AliSignal::Reset(Int_t mode)
241 {
242 // Reset all signal and position values and errors to 0.
243 //
244 // mode = 0 Reset position and all signal values and their errors to 0.
245 //          The waveform histograms are reset, but the calibration
246 //          constants (i.e. gains and offsets) are kept.
247 //        1 Reset position and delete the signal and error storage arrays.
248 //          Also the waveform histograms, gains and offset arrays are deleted.
249 //
250 // The default when invoking Reset() corresponds to mode=0.
251 //
252 // Note : In all cases the storage of the various links will be reset.
253 //        The UniqueID, name and title will NOT be reset.
254 //        In case the user wants to reset these attributes, this has to
255 //        be done explicitly via the SET facilities. 
256 //
257 // The usage of mode=0 allows to re-use the allocated memory for new
258 // signal (and error) values. This behaviour is preferable (i.e. faster)
259 // in case the various signals always contain the same number of values
260 // and have the same calibration constants.
261 // The usage of mode=1 is slower, but allows a more efficient memory
262 // occupation (and smaller output file size) in case the different
263 // signals have a variable number of values.
264 //
265 // For more specific actions see ResetPosition(), ResetSignals(),
266 // DeleteSignals(), ResetGain(), ResetOffset(), ResetLink(), ResetWaveform(),
267 // DeleteWaveform() and DeleteCalibrations().
268 //
269
270  if (mode<0 || mode>1)
271  {
272   cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
273   cout << " Default mode=0 will be used." << endl;
274   mode=0;
275  }
276
277  ResetPosition();
278  if (!mode)
279  {
280   ResetSignals();
281  }
282  else
283  {
284   DeleteSignals();
285   DeleteCalibrations();
286  }
287
288  if (fLinks) fLinks->Reset();
289  fDevice=0;
290
291  if (fTracks)
292  {
293   delete fTracks;
294   fTracks=0;
295  }
296 }
297 ///////////////////////////////////////////////////////////////////////////
298 void AliSignal::ResetSignals(Int_t mode)
299 {
300 // Reset various signal data according to user selection.
301 //
302 // mode = 0 Reset all signal values and their errors to 0.
303 //        1 Reset only signal values
304 //        2 Reset only signal errors
305 //
306 // The default when invoking ResetSignals() corresponds to mode=0.
307 //
308 // Irrespective of the mode, the waveform histograms are reset.
309
310  if (mode<0 || mode>2)
311  {
312   cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
313   cout << " Default mode=0 will be used." << endl;
314   mode=0;
315  }
316
317  Int_t sflag=0;
318  Int_t eflag=0;
319
320  if (fSignals && (mode==0 || mode==1))
321  {
322   for (Int_t i=1; i<=fSignals->GetSize(); i++)
323   {
324    fSignals->AddAt(0,i-1);
325    eflag=GetErrorFlag(i);
326    SetSigFlags(0,eflag,i);
327   }
328  }
329
330  if (fDsignals && (mode==0 || mode==2))
331  {
332   for (Int_t j=1; j<=fDsignals->GetSize(); j++)
333   {
334    fDsignals->AddAt(0,j-1);
335    sflag=GetSignalFlag(j);
336    SetSigFlags(sflag,0,j);
337   }
338  }
339
340  ResetWaveform(0);
341 }
342 ///////////////////////////////////////////////////////////////////////////
343 void AliSignal::DeleteSignals(Int_t mode)
344 {
345 // Delete storage arrays of various signal data according to user selection.
346 //
347 // mode = 0 Delete arrays of both signal values and their errors.
348 //        1 Delete only signal values array
349 //        2 Delete only signal errors array
350 //
351 // The default when invoking DeleteSignals() corresponds to mode=0.
352 //
353 // Irrespective of the mode, the waveform histograms are deleted.
354
355  if (mode<0 || mode>2)
356  {
357   cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
358   cout << " Default mode=0 will be used." << endl;
359   mode=0;
360  }
361
362  if (fSignals && (mode==0 || mode==1))
363  {
364   delete fSignals;
365   fSignals=0;
366  }
367
368  if (fDsignals && (mode==0 || mode==2))
369  {
370   delete fDsignals;
371   fDsignals=0;
372  }
373
374  Int_t sflag=0;
375  Int_t eflag=0;
376
377  if (mode==0)
378  {
379   delete fSigflags;
380   fSigflags=0;
381  }
382  else if (mode==1)
383  {
384   for (Int_t i=1; i<=fSigflags->GetSize(); i++)
385   {
386    eflag=GetErrorFlag(i);
387    SetSigFlags(0,eflag,i);
388   }
389  }
390  else if (mode==2)
391  {
392   for (Int_t j=1; j<=fSigflags->GetSize(); j++)
393   {
394    sflag=GetSignalFlag(j);
395    SetSigFlags(sflag,0,j);
396   }
397  }
398
399  DeleteWaveform(0);
400 }
401 ///////////////////////////////////////////////////////////////////////////
402 void AliSignal::SetSignal(Double_t sig,Int_t j)
403 {
404 // Store signal value for the j-th (default j=1) slot.
405 // Note : The first signal slot is at j=1.
406 // In case the value of the index j exceeds the maximum number of reserved
407 // slots for signal values, the number of reserved slots for the
408 // signal values is increased automatically.
409
410  if (!fSignals)
411  {
412   fSignals=new TArrayF(j);
413   ResetSignals(1);
414  }
415
416  Int_t size=fSignals->GetSize();
417
418  if (j>size)
419  {
420   fSignals->Set(j);
421  }
422
423  fSignals->AddAt(float(sig),j-1);
424
425  Int_t eflag=GetErrorFlag(j);
426  SetSigFlags(1,eflag,j);
427 }
428 ///////////////////////////////////////////////////////////////////////////
429 void AliSignal::SetSignal(Double_t sig,TString name)
430 {
431 // Store signal value for the name-specified slot.
432 //
433 // This procedure involves a slot-index search based on the specified name
434 // at each invokation. This may become slow in case many slots have been
435 // defined and/or when this procedure is invoked many times.
436 // In such cases it is preferable to use indexed addressing in the user code
437 // either directly or via a few invokations of GetSlotIndex().
438
439  Int_t j=GetSlotIndex(name);
440  if (j>0) SetSignal(sig,j);
441 }
442 ///////////////////////////////////////////////////////////////////////////
443 void AliSignal::AddSignal(Double_t sig,Int_t j)
444 {
445 // Add value to the signal of the j-th (default j=1) slot.
446 // Note : The first signal slot is at j=1.
447 // In case the value of the index j exceeds the maximum number of reserved
448 // slots for signal values, the number of reserved slots for the
449 // signal values is increased automatically.
450
451  if (!fSignals)
452  {
453   fSignals=new TArrayF(j);
454   ResetSignals(1);
455  }
456
457  Int_t size=fSignals->GetSize();
458
459  if (j>size)
460  {
461   fSignals->Set(j);
462  }
463
464  Float_t sum=(fSignals->At(j-1))+sig;
465  fSignals->AddAt(sum,j-1);
466
467  Int_t eflag=GetErrorFlag(j);
468  SetSigFlags(1,eflag,j);
469 }
470 ///////////////////////////////////////////////////////////////////////////
471 void AliSignal::AddSignal(Double_t sig,TString name)
472 {
473 // Add value to the signal of the name-specified slot.
474 //
475 // This procedure involves a slot-index search based on the specified name
476 // at each invokation. This may become slow in case many slots have been
477 // defined and/or when this procedure is invoked many times.
478 // In such cases it is preferable to use indexed addressing in the user code
479 // either directly or via a few invokations of GetSlotIndex().
480
481  Int_t j=GetSlotIndex(name);
482  if (j>0) AddSignal(sig,j);
483 }
484 ///////////////////////////////////////////////////////////////////////////
485 Float_t AliSignal::GetSignal(Int_t j,Int_t mode) const
486 {
487 // Provide signal value of the j-th (default j=1) slot.
488 // Note : The first signal slot is at j=1.
489 // In case no signal is present or the input argument "j" or "mode" is invalid,
490 // the value 0 is returned.
491 // The parameter "mode" allows for automatic (de)calibration of the signal
492 // (e.g. gain etc... correction or via explicit (de)calibration functions).
493 //
494 // mode = 0 : Just the j-th signal is returned.
495 //        1 : The j-th signal is corrected for the gain, offset, dead flag etc...
496 //            In case the j-th slot was marked dead, 0 is returned.
497 //            In case the gain value was not set, gain=1 will be assumed.
498 //            In case the gain value was 0, a signal value of 0 is returned.
499 //            In case the offset value was not set, offset=0 will be assumed.
500 //        2 : Same as mode=1 but gain, offset dead flag etc... are taken from
501 //            the AliDevice which owns this AliSignal object.
502 //            The corresponding AliDevice slot is obtained via matching of
503 //            the slotnames. In case this fails, the slotindex "j" of the
504 //            input argument will be used. 
505 //            In case this AliSignal object has no parent AliDevice, just
506 //            the j-th signal is returned (like with mode=0).
507 //        3 : The j-th signal is corrected using the corresponding calibration
508 //            function.
509 //            In case the j-th slot was marked dead, 0 is returned.
510 //            In case no calibration function is present, just the j-th signal
511 //            is returned (like with mode=0).
512 //        4 : Same as mode=3 but the calibration function and dead flag are
513 //            taken from the AliDevice which owns this AliSignal object.
514 //            The corresponding AliDevice slot is obtained via matching of
515 //            the slotnames. In case this fails, the slotindex "j" of the
516 //            input argument will be used. 
517 //        5 : Same as mode=2 but in case no parent AliDevice is present
518 //            an automatic switch to mode=1 will be made.
519 //        6 : Same as mode=4 but in case no parent AliDevice is present
520 //            an automatic switch to mode=3 will be made.
521 //        7 : Same as mode=3 but in case no calibration function is present
522 //            an automatic switch to mode=4 will be made.
523 //        8 : Same as mode=7 but also the corresponding dead flag of the
524 //            parent device (if any) will be checked.
525 //            If either the dead flag of the requested signal slot of this
526 //            AliSignal object or the corresponding parent device slot is
527 //            set, 0 is returned.
528 //
529 //       <0 : The corresponding de-correction or de-calibration is performed
530 //
531 // The corrected signal (sigc) is determined as follows :
532 //
533 //              sigc=(signal/gain)-offset 
534 //
535 // The de-corrected signal is determined as follows :
536 //
537 //              signal=(sigc+offset)*gain 
538 //
539 // The default is mode=0.
540
541  if (abs(mode)>8) return 0;
542
543  Int_t jcal=j;
544  Float_t sig=0;
545  Float_t gain=1;
546  Float_t offset=0;
547
548  // Get the corresponding slot index (and dead flag) of the parent device
549  Int_t pj=0;
550  Int_t pdead=0;
551  AliSignal* parent=(AliSignal*)GetDevice();
552  if ((abs(mode)==2 || abs(mode)>=4) && parent)
553  {
554    TString name=GetSlotName(j);
555    if (strlen(name.Data())) pj=parent->GetSlotIndex(name);
556    if (abs(mode)==8 && pj) pdead=parent->GetDeadValue(pj);
557  }
558  if (mode==8) mode=7;
559  if (mode==-8) mode=-7;
560
561  AliSignal* sx=(AliSignal*)this;
562
563  TF1* f=0;
564  if (mode==7)
565  {
566   f=sx->GetCalFunction(jcal);
567   if (f)
568   {
569    mode=3;
570   }
571   else
572   {
573    mode=4;
574   } 
575  }
576  if (mode==-7)
577  {
578   f=sx->GetDecalFunction(jcal);
579   if (f)
580   {
581    mode=-3;
582   }
583   else
584   {
585    mode=-4;
586   } 
587  }
588
589  if (abs(mode)==2 || abs(mode)>=4)
590  {
591   sx=(AliSignal*)GetDevice();
592   if (pj) jcal=pj;
593  }
594  if (!sx && abs(mode)>=5) sx=(AliSignal*)this;
595  if (mode==5) mode=2;
596  if (mode==-5) mode=-2;
597  if (mode==6) mode=3;
598  if (mode==-6) mode=-3;
599
600  if (fSignals)
601  {
602   if (j>0 && j<=(fSignals->GetSize()))
603   {
604    sig=fSignals->At(j-1);
605
606    if (mode==0 || !sx) return sig;
607
608    // Check for the dead flag setting
609    if (sx->GetDeadValue(jcal) || pdead) return 0;
610
611    // (De)correct the signal for the gain and offset
612    if (abs(mode)==1 || abs(mode)==2)
613    {
614     if (sx->GetGainFlag(jcal)) gain=sx->GetGain(jcal);
615     if (sx->GetOffsetFlag(jcal)) offset=sx->GetOffset(jcal);
616
617     if (fabs(gain)>0.)
618     {
619      if (mode>0) sig=(sig/gain)-offset; // Gain and offset correction
620      if (mode<0) sig=(sig+offset)*gain; // Gain and offset de-correction
621     }
622     else
623     {
624      sig=0;
625     }
626     return sig;
627    }
628
629    // (De)calibrate the signal with the corresponding (de)calibration function
630    if (abs(mode)==3 || abs(mode)==4)
631    {
632     f=sx->GetCalFunction(jcal);
633     if (mode<0) f=sx->GetDecalFunction(jcal);
634     if (f) sig=f->Eval(sig);
635     return sig;
636    }
637   }
638   else
639   {
640    cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
641   } 
642  }
643  return sig;
644 }
645 ///////////////////////////////////////////////////////////////////////////
646 Float_t AliSignal::GetSignal(TString name,Int_t mode) const
647 {
648 // Provide signal value of the name-specified slot.
649 // In case no signal is present, 0 is returned.
650 // The parameter "mode" allows for automatic (de)calibration of the signal
651 // (e.g. gain etc... correction or via explicit (de)calibration functions).
652 // For further details about the (de)calibration modes, please refer to the
653 // corresponding slot-index based memberfunction. 
654 //
655 // The default is mode=0.
656 //
657 // This procedure involves a slot-index search based on the specified name
658 // at each invokation. This may become slow in case many slots have been
659 // defined and/or when this procedure is invoked many times.
660 // In such cases it is preferable to use indexed addressing in the user code
661 // either directly or via a few invokations of GetSlotIndex().
662
663  Int_t j=GetSlotIndex(name);
664  Float_t val=0;
665  if (j>0) val=GetSignal(j,mode);
666  return val;
667 }
668 ///////////////////////////////////////////////////////////////////////////
669 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
670 {
671 // Store error on the signal for the j-th (default j=1) slot.
672 // Note : The first signal slot is at j=1.
673 // In case the value of the index j exceeds the maximum number of reserved
674 // slots for signal error values, the number of reserved slots for the
675 // signal errors is increased automatically.
676
677  if (!fDsignals)
678  {
679   fDsignals=new TArrayF(j);
680   ResetSignals(2);
681  }
682
683  Int_t size=fDsignals->GetSize();
684
685  if (j>size)
686  {
687   fDsignals->Set(j);
688  }
689
690  fDsignals->AddAt(float(dsig),j-1);
691
692  Int_t sflag=GetSignalFlag(j);
693  SetSigFlags(sflag,1,j);
694 }
695 ///////////////////////////////////////////////////////////////////////////
696 void AliSignal::SetSignalError(Double_t dsig,TString name)
697 {
698 // Store error on the signal for the name-specified slot.
699 //
700 // This procedure involves a slot-index search based on the specified name
701 // at each invokation. This may become slow in case many slots have been
702 // defined and/or when this procedure is invoked many times.
703 // In such cases it is preferable to use indexed addressing in the user code
704 // either directly or via a few invokations of GetSlotIndex().
705
706  Int_t j=GetSlotIndex(name);
707  if (j>0) SetSignalError(dsig,j);
708 }
709 ///////////////////////////////////////////////////////////////////////////
710 Float_t AliSignal::GetSignalError(Int_t j) const
711 {
712 // Provide error on the signal of the j-th (default j=1) slot.
713 // Note : The first signal slot is at j=1.
714 // In case no signal is present or the argument j is invalid, 0 is returned.
715  Float_t err=0;
716  if (fDsignals)
717  {
718   if (j>0 && j<=(fDsignals->GetSize()))
719   {
720    err=fDsignals->At(j-1);
721   }
722   else
723   {
724    cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
725   } 
726  }
727  return err;
728 }
729 ///////////////////////////////////////////////////////////////////////////
730 Float_t AliSignal::GetSignalError(TString name) const
731 {
732 // Provide error on the signal of the name-specified slot.
733 //
734 // This procedure involves a slot-index search based on the specified name
735 // at each invokation. This may become slow in case many slots have been
736 // defined and/or when this procedure is invoked many times.
737 // In such cases it is preferable to use indexed addressing in the user code
738 // either directly or via a few invokations of GetSlotIndex().
739
740  Int_t j=GetSlotIndex(name);
741  Float_t val=0;
742  if (j>0) val=GetSignalError(j);
743  return val;
744 }
745 ///////////////////////////////////////////////////////////////////////////
746 void AliSignal::Data(TString f,TString u) const
747 {
748 // Provide all signal information within the coordinate frame f.
749 //
750 // The string argument "u" allows to choose between different angular units
751 // in case e.g. a spherical frame is selected.
752 // u = "rad" : angles provided in radians
753 //     "deg" : angles provided in degrees
754 //
755 // The defaults are f="car" and u="rad".
756
757  const char* name=GetName();
758  const char* title=GetTitle();
759
760  cout << " *" << ClassName() << "::Data* Id : " << GetUniqueID();
761  if (strlen(name))  cout << " Name : " << name;
762  if (strlen(title)) cout << " Title : " << title;
763  cout << endl;
764  cout << "   Position";
765  AliPosition::Data(f,u);
766  if (fDevice)
767  {
768   const char* devname=fDevice->GetName();
769   const char* devtitle=fDevice->GetTitle();
770   cout << "   Owned by device : " << fDevice->ClassName()
771        << " Id : " << fDevice->GetUniqueID();
772   if (strlen(devname))  cout << " Name : " << devname;
773   if (strlen(devtitle)) cout << " Title : " << devtitle;
774   cout << endl;
775  }
776
777  // Provide an overview of the stored waveforms
778  ListWaveform(-1);
779
780  // Provide an overview of the associated tracks
781  ListTrack(-1);
782
783  // Provide an overview of all the data and attribute slots
784  List(-1);
785
786 ///////////////////////////////////////////////////////////////////////////
787 void AliSignal::List(Int_t j) const
788 {
789 // Provide signal information for the j-th slot.
790 // The first slot is at j=1.
791 // In case j=0 (default) the data of all slots will be listed.
792 // In case j=-1 the data of all slots will be listed, but the header
793 // information will be suppressed.
794
795  if (j<-1) 
796  {
797   cout << " *AliSignal::List* Invalid argument j = " << j << endl;
798   return;
799  }
800
801  if (j != -1)
802  {
803   const char* name=GetName();
804   const char* title=GetTitle();
805
806   cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
807   if (strlen(name))  cout << " Name : " << name;
808   if (strlen(title)) cout << " Title : " << title;
809   cout << endl;
810   if (fDevice)
811   {
812    const char* devname=fDevice->GetName();
813    const char* devtitle=fDevice->GetTitle();
814    cout << "   Owned by device : " << fDevice->ClassName();
815    if (strlen(devname))  cout << " Name : " << devname;
816    if (strlen(devtitle)) cout << " Title : " << devtitle;
817    cout << endl;
818   }
819  }
820
821  Int_t n=GetNslots();
822  Int_t nlinkslots=0;
823  if (GetNlinks()) nlinkslots=fLinks->GetMaxColumn();
824  if (nlinkslots>n) n=nlinkslots;
825  
826  TObject* obj=0;
827  Int_t nrefs=0;
828  TArrayI posarr;
829  Int_t pos;
830
831  if (j<=0)
832  {
833   for (Int_t i=1; i<=n; i++)
834   {
835    obj=0;
836    nrefs=GetIndices(obj,i,posarr);
837
838    if (GetSignalFlag(i) || GetErrorFlag(i) || GetCalFunction(i) || GetDecalFunction(i) || GetCalWord(i) || nrefs)
839    {
840     cout << "   Slot : " << i;
841     if (GetSignalFlag(i)) cout << " Signal value : " << GetSignal(i);
842     if (GetErrorFlag(i))  cout << " error : " << GetSignalError(i);
843     AliAttrib::List(i);
844     cout << endl;
845
846     for (Int_t k=0; k<nrefs; k++)
847     {
848      pos=posarr.At(k);
849      obj=GetLink(i,pos);
850      if (obj)
851      {
852       cout << "    Link at position " << pos << " to : " << obj->ClassName();
853       if (obj->InheritsFrom("TNamed"))
854       {
855        const char* lname=obj->GetName();
856        const char* ltitle=obj->GetTitle();
857        if (strlen(lname))  cout << " Name : " << lname;
858        if (strlen(ltitle)) cout << " Title : " << ltitle;
859       }
860       cout << endl;
861      }
862     }
863    }
864   }
865  }
866  else
867  {
868   if (j<=n)
869   {
870    obj=0;
871    nrefs=GetIndices(obj,j,posarr);
872
873    if (GetSignalFlag(j) || GetErrorFlag(j) || GetCalFunction(j) || GetDecalFunction(j) || GetCalWord(j) || nrefs)
874    {
875     cout << "   Slot : " << j;
876     if (GetSignalFlag(j)) cout << " Signal value : " << GetSignal(j);
877     if (GetErrorFlag(j))  cout << " error : " << GetSignalError(j);
878     AliAttrib::List(j);
879     cout << endl;
880
881     for (Int_t kj=0; kj<nrefs; kj++)
882     {
883      pos=posarr.At(kj);
884      obj=GetLink(j,pos);
885      if (obj)
886      {
887       cout << "    Link at position " << pos << " to : " << obj->ClassName();
888       if (obj->InheritsFrom("TNamed"))
889       {
890        const char* lnamej=obj->GetName();
891        const char* ltitlej=obj->GetTitle();
892        if (strlen(lnamej))  cout << " Name : " << lnamej;
893        if (strlen(ltitlej)) cout << " Title : " << ltitlej;
894       }
895       cout << endl;
896      }
897     }
898    }
899   }
900  }
901
902 ///////////////////////////////////////////////////////////////////////////
903 void AliSignal::List(TString name) const
904 {
905 // Provide signal information for the name-specified slot.
906 //
907 // This procedure involves a slot-index search based on the specified name
908 // at each invokation. This may become slow in case many slots have been
909 // defined and/or when this procedure is invoked many times.
910 // In such cases it is preferable to use indexed addressing in the user code
911 // either directly or via a few invokations of GetSlotIndex().
912
913  Int_t j=GetSlotIndex(name);
914  if (j>0) List(j);
915 }
916 ///////////////////////////////////////////////////////////////////////////
917 void AliSignal::ListWaveform(Int_t j) const
918 {
919 // Provide information for the j-th waveform.
920 // The first waveform is at j=1.
921 // In case j=0 (default) the info of all waveforms will be listed.
922 // In case j=-1 the info of all waveforms will be listed, but the header
923 // information will be suppressed.
924
925  if (j<-1) 
926  {
927   cout << " *AliSignal::ListWaveform* Invalid argument j = " << j << endl;
928   return;
929  }
930
931  if (j != -1)
932  {
933   const char* name=GetName();
934   const char* title=GetTitle();
935
936   cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
937   if (strlen(name))  cout << " Name : " << name;
938   if (strlen(title)) cout << " Title : " << title;
939   cout << endl;
940   if (fDevice)
941   {
942    const char* devname=fDevice->GetName();
943    const char* devtitle=fDevice->GetTitle();
944    cout << "   Owned by device : " << fDevice->ClassName();
945    if (strlen(devname))  cout << " Name : " << devname;
946    if (strlen(devtitle)) cout << " Title : " << devtitle;
947    cout << endl;
948   }
949  }
950
951  Int_t n=GetNwaveforms();
952  TObject* obj=0;
953
954  if (j<=0)
955  {
956   for (Int_t i=1; i<=n; i++)
957   {
958    obj=GetWaveform(i);
959    if (obj)
960    {
961     const char* wfname=obj->GetName();
962     const char* wftitle=obj->GetTitle();
963     cout << "    Waveform " << i << " : " << obj->ClassName();
964     if (strlen(wfname))  cout << " Name : " << wfname;
965     if (strlen(wftitle)) cout << " Title : " << wftitle;
966     cout << endl;
967    }
968   }
969  }
970  else
971  {
972   if (j<=n)
973   {
974    obj=GetWaveform(j);
975    if (obj)
976    {
977     const char* wfnamej=obj->GetName();
978     const char* wftitlej=obj->GetTitle();
979     cout << "    Waveform " << j << " : " << obj->ClassName();
980     if (strlen(wfnamej))  cout << " Name : " << wfnamej;
981     if (strlen(wftitlej)) cout << " Title : " << wftitlej;
982     cout << endl;
983    }
984   }
985  }
986 }
987 ///////////////////////////////////////////////////////////////////////////
988 void AliSignal::ListTrack(Int_t j) const
989 {
990 // Provide information for the j-th associated track.
991 // The first associated track is at j=1.
992 // In case j=0 (default) the info of all associated tracks will be listed.
993 // In case j=-1 the info of all tracks will be listed, but the header
994 // information will be suppressed.
995
996  if (j<-1) 
997  {
998   cout << " *AliSignal::ListTrack* Invalid argument j = " << j << endl;
999   return;
1000  }
1001
1002  if (j != -1)
1003  {
1004   const char* name=GetName();
1005   const char* title=GetTitle();
1006
1007   cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
1008   if (strlen(name))  cout << " Name : " << name;
1009   if (strlen(title)) cout << " Title : " << title;
1010   cout << endl;
1011   if (fDevice)
1012   {
1013    const char* devname=fDevice->GetName();
1014    const char* devtitle=fDevice->GetTitle();
1015    cout << "   Owned by device : " << fDevice->ClassName();
1016    if (strlen(devname))  cout << " Name : " << devname;
1017    if (strlen(devtitle)) cout << " Title : " << devtitle;
1018    cout << endl;
1019   }
1020  }
1021
1022  Int_t n=GetNtracks();
1023  AliTrack* tx=0;
1024
1025  if (j<=0)
1026  {
1027   for (Int_t i=1; i<=n; i++)
1028   {
1029    tx=GetTrack(i);
1030    if (tx)
1031    {
1032     const char* txname=tx->GetName();
1033     const char* txtitle=tx->GetTitle();
1034     cout << "    Track " << i << " : " << tx->ClassName() << " Id : " << tx->GetId();
1035     if (strlen(txname))  cout << " Name : " << txname;
1036     if (strlen(txtitle)) cout << " Title : " << txtitle;
1037     cout << endl;
1038    }
1039   }
1040  }
1041  else
1042  {
1043   if (j<=n)
1044   {
1045    tx=GetTrack(j);
1046    if (tx)
1047    {
1048     const char* txnamej=tx->GetName();
1049     const char* txtitlej=tx->GetTitle();
1050     cout << "    Track " << j << " : " << tx->ClassName() << " Id : " << tx->GetId();
1051     if (strlen(txnamej))  cout << " Name : " << txnamej;
1052     if (strlen(txtitlej)) cout << " Title : " << txtitlej;
1053     cout << endl;
1054    }
1055   }
1056  }
1057 }
1058 ///////////////////////////////////////////////////////////////////////////
1059 Int_t AliSignal::GetNvalues() const
1060 {
1061 // Provide the number of values for this signal.
1062  
1063  if (!fSignals) return 0;
1064
1065  Int_t n=0;
1066  for (Int_t i=1; i<=fSigflags->GetSize(); i++)
1067  {
1068   if (GetSignalFlag(i)) n=i;
1069  }
1070
1071  return n;
1072 }
1073 ///////////////////////////////////////////////////////////////////////////
1074 Int_t AliSignal::GetNerrors() const
1075 {
1076 // Provide the number specified errors on the values for this signal.
1077  
1078  if (!fDsignals) return 0;
1079
1080  Int_t n=0;
1081  for (Int_t i=1; i<=fSigflags->GetSize(); i++)
1082  {
1083   if (GetErrorFlag(i)) n=i;
1084  }
1085
1086  return n;
1087 }
1088 ///////////////////////////////////////////////////////////////////////////
1089 void AliSignal::SetSigFlags(Int_t is,Int_t ie,Int_t j)
1090 {
1091 // Store signal and/or error value flags of the j-th (default j=1) slot.
1092 // Note : The first slot is at j=1.
1093 // In case the value of the index j exceeds the maximum number of reserved
1094 // slots for the flags, the number of reserved slots for the flags is
1095 // increased automatically.
1096 // The value stored is : 10*signalflag + errorflag.
1097
1098  if (j<1) 
1099  {
1100   cout << " *AliSignal::SetSigFlags* Invalid argument j = " << j << endl;
1101   return;
1102  }
1103
1104  if (!fSigflags)
1105  {
1106   fSigflags=new TArrayI(j);
1107  }
1108
1109  Int_t size=fSigflags->GetSize();
1110
1111  if (j>size)
1112  {
1113   fSigflags->Set(j);
1114  }
1115
1116  Int_t word=10*is+ie;
1117  
1118  fSigflags->AddAt(word,j-1);
1119 }
1120 ///////////////////////////////////////////////////////////////////////////
1121 Int_t AliSignal::GetSignalFlag(Int_t j) const
1122 {
1123 // Provide signal value flag of the j-th (default j=1) slot.
1124 //
1125 // flag = 1 : Signal value was set
1126 //        0 : Signal value was not set
1127 //
1128 // Note : The first attribute slot is at j=1.
1129 // In case j is invalid, 0 is returned.
1130
1131  if (j<1) 
1132  {
1133   cout << " *AliSignal::GetSignalFlag* Invalid argument j = " << j << endl;
1134   return 0;
1135  }
1136  Int_t flag=0;
1137  if (fSigflags)
1138  {
1139   if (j>0 && j<=(fSigflags->GetSize()))
1140   {
1141    Int_t word=fSigflags->At(j-1);
1142    flag=word/10;
1143   }
1144  }
1145  return flag;
1146 }
1147 ///////////////////////////////////////////////////////////////////////////
1148 Int_t AliSignal::GetSignalFlag(TString name) const
1149 {
1150 // Provide signal value flag of the name-specified slot.
1151 //
1152 // flag = 1 : Signal value was set
1153 //        0 : Signal value was not set
1154 //
1155 //
1156 // This procedure involves a slot-index search based on the specified name
1157 // at each invokation. This may become slow in case many slots have been
1158 // defined and/or when this procedure is invoked many times.
1159 // In such cases it is preferable to use indexed addressing in the user code
1160 // either directly or via a few invokations of GetSlotIndex().
1161
1162  Int_t j=GetSlotIndex(name);
1163  Int_t flag=0;
1164  if (j>0) flag=GetSignalFlag(j);
1165  return flag;
1166 }
1167 ///////////////////////////////////////////////////////////////////////////
1168 Int_t AliSignal::GetErrorFlag(Int_t j) const
1169 {
1170 // Provide error value flag of the j-th (default j=1) slot.
1171 //
1172 // flag = 1 : Error value was set
1173 //        0 : Error value was not set
1174 //
1175 // Note : The first attribute slot is at j=1.
1176 // In case j is invalid, 0 is returned.
1177
1178  if (j<1) 
1179  {
1180   cout << " *AliSignal::GetErrorFlag* Invalid argument j = " << j << endl;
1181   return 0;
1182  }
1183  Int_t flag=0;
1184  if (fSigflags)
1185  {
1186   if (j>0 && j<=(fSigflags->GetSize()))
1187   {
1188    Int_t word=fSigflags->At(j-1);
1189    flag=word%10;
1190   }
1191  }
1192  return flag;
1193 }
1194 ///////////////////////////////////////////////////////////////////////////
1195 Int_t AliSignal::GetErrorFlag(TString name) const
1196 {
1197 // Provide error value flag of the name-specified slot.
1198 //
1199 // flag = 1 : Error value was set
1200 //        0 : Error value was not set
1201 //
1202 //
1203 // This procedure involves a slot-index search based on the specified name
1204 // at each invokation. This may become slow in case many slots have been
1205 // defined and/or when this procedure is invoked many times.
1206 // In such cases it is preferable to use indexed addressing in the user code
1207 // either directly or via a few invokations of GetSlotIndex().
1208
1209  Int_t j=GetSlotIndex(name);
1210  Int_t flag=0;
1211  if (j>0) flag=GetErrorFlag(j);
1212  return flag;
1213 }
1214 ///////////////////////////////////////////////////////////////////////////
1215 Int_t AliSignal::GetNslots() const
1216 {
1217 // Provide the number of existing slots.
1218
1219  Int_t n=AliAttrib::GetNslots();
1220
1221  if (!fSigflags) return n;
1222
1223  Int_t nflags=0;
1224  for (Int_t i=0; i<fSigflags->GetSize(); i++)
1225  {
1226   if (fSigflags->At(i)) nflags=i+1;
1227  }
1228
1229  if (n<nflags) n=nflags;
1230
1231  return n;
1232 }
1233 ///////////////////////////////////////////////////////////////////////////
1234 Int_t AliSignal::GetNwaveforms() const
1235 {
1236 // Provide the number of specified waveforms for this signal.
1237 // Actually the return value is the highest index of the stored waveforms.
1238 // This allows an index dependent meaning of waveform info (e.g. waveforms
1239 // with various gain values).
1240 // So, when all waveforms are stored in consequetive positions (e.g. 1,2,3),
1241 // this memberfunction returns 3, being both the highest filled position
1242 // and the actual number of waveforms.
1243 // In case only waveforms are stored at positions 1,2,5,7 this memberfunction
1244 // returns a value 7 whereas only 4 actual waveforms are present.
1245 // This implies that when looping over the various waveform slots, one
1246 // always has to check whether the returned pointer value is non-zero
1247 // (which is a good practice anyhow).
1248  Int_t n=-1;
1249  if (fWaveforms) n=fWaveforms->GetLast();
1250  return (n+1);
1251 }
1252 ///////////////////////////////////////////////////////////////////////////
1253 TH1F* AliSignal::GetWaveform(Int_t j) const
1254 {
1255 // Provide pointer to the j-th waveform histogram.
1256  TH1F* waveform=0;
1257  if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
1258  return waveform;
1259 }
1260 ///////////////////////////////////////////////////////////////////////////
1261 TH1F* AliSignal::GetWaveform(TString name) const
1262 {
1263 // Provide pointer to the waveform histogram with the specified name.
1264 // In case no match is found, zero is returned.
1265  Int_t n=GetNwaveforms();
1266  TString str;
1267  for (Int_t i=1; i<=n; i++)
1268  {
1269   TH1F* waveform=GetWaveform(i);
1270   if (waveform)
1271   {
1272    str=waveform->GetName();
1273    if (str == name) return waveform;
1274   }
1275  }
1276  return 0; // No match found
1277 }
1278 ///////////////////////////////////////////////////////////////////////////
1279 Int_t AliSignal::GetWaveformIndex(TString name) const
1280 {
1281 // Provide index to the waveform histogram with the specified name.
1282 // In case no match is found, zero is returned.
1283  Int_t n=GetNwaveforms();
1284  TString str;
1285  for (Int_t i=1; i<=n; i++)
1286  {
1287   TH1F* waveform=GetWaveform(i);
1288   if (waveform)
1289   {
1290    str=waveform->GetName();
1291    if (str == name) return i;
1292   }
1293  }
1294  return 0; // No match found
1295 }
1296 ///////////////////////////////////////////////////////////////////////////
1297 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
1298 {
1299 // Set the 1D waveform histogram for the j-th waveform.
1300 //
1301 // Notes :
1302 //  The first waveform position at j=1.
1303 //  j=1 is the default value.
1304 //
1305 // In case the value of the index j exceeds the maximum number of reserved
1306 // positions for the waveforms, the number of reserved positions for the waveforms
1307 // is increased automatically.
1308 //
1309 // In case the histo pointer argument has the same value as the current waveform
1310 // histogram pointer value, no action is taken since the user has already
1311 // modified the actual histogram.
1312 //
1313 // In case the histo pointer argument is zero, the current waveform histogram
1314 // is deleted and the pointer set to zero.
1315 //
1316 // In all other cases the current waveform histogram is deleted and a new
1317 // copy of the input histogram is created which becomes the current waveform
1318 // histogram.
1319
1320  if (j<1) return;
1321
1322  if (!fWaveforms)
1323  {
1324   fWaveforms=new TObjArray(j);
1325   fWaveforms->SetOwner();
1326  }
1327
1328  if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
1329
1330  TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
1331  if (waveform != hcur)
1332  {
1333   if (hcur)
1334   {
1335    fWaveforms->Remove(hcur);
1336    delete hcur;
1337    hcur=0;
1338   }
1339   if (waveform)
1340   {
1341    hcur=new TH1F(*waveform);
1342    fWaveforms->AddAt(hcur,j-1);
1343   }
1344  } 
1345 }
1346 ///////////////////////////////////////////////////////////////////////////
1347 void AliSignal::ResetWaveform(Int_t j)
1348 {
1349 // Reset the histogram of the j-th (default j=1) waveform.
1350 // This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
1351 // To actually delete the histograms from memory, use DeleteWaveform().
1352 // Notes : The first position is at j=1.
1353 //         j=0 ==> All waveforms will be reset.
1354  
1355  if (!fWaveforms) return;
1356
1357  Int_t size=fWaveforms->GetSize();
1358
1359  if ((j>=0) && (j<=size))
1360  {
1361   if (j)
1362   {
1363    TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
1364    if (hwave) hwave->Reset();
1365   }
1366   else
1367   {
1368    for (Int_t i=0; i<size; i++)
1369    {
1370     TH1F* hwave=(TH1F*)fWaveforms->At(i);
1371     if (hwave) hwave->Reset();
1372    }
1373   }
1374  }
1375  else
1376  {
1377   cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
1378   return;
1379  }
1380 }
1381 ///////////////////////////////////////////////////////////////////////////
1382 void AliSignal::ResetWaveform(TString name)
1383 {
1384 // Reset the waveform with the specified name.
1385  Int_t j=GetWaveformIndex(name);
1386  if (j>0) ResetWaveform(j);
1387 }
1388 ///////////////////////////////////////////////////////////////////////////
1389 void AliSignal::DeleteWaveform(Int_t j)
1390 {
1391 // Delete the histogram of the j-th (default j=1) waveform.
1392 // Notes : The first position is at j=1.
1393 //         j=0 ==> All waveforms will be deleted.
1394  
1395  if (!fWaveforms) return;
1396
1397  Int_t size=fWaveforms->GetSize();
1398
1399  if ((j>=0) && (j<=size))
1400  {
1401   if (j)
1402   {
1403    TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
1404    if (hwave)
1405    {
1406     fWaveforms->Remove(hwave);
1407     delete hwave;
1408    }
1409   }
1410   else
1411   {
1412    delete fWaveforms;
1413    fWaveforms=0;
1414   }
1415  }
1416  else
1417  {
1418   cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
1419   return;
1420  }
1421 }
1422 ///////////////////////////////////////////////////////////////////////////
1423 void AliSignal::DeleteWaveform(TString name)
1424 {
1425 // Delete the waveform with the specified name.
1426  Int_t j=GetWaveformIndex(name);
1427  if (j>0) DeleteWaveform(j);
1428 }
1429 ///////////////////////////////////////////////////////////////////////////
1430 Int_t AliSignal::GetNlinks(TObject* obj,Int_t j) const
1431 {
1432 // Provide the number of links to the specified object for the j-th slot.
1433 // If j=0 (default) all slots will be scanned for the specified object.
1434 // If obj=0 (default) all encountered objects for the specified slot will be counted.
1435 // So, invokation of the default GetNlinks() will return the total number of
1436 // all references to all sorts of stored objects.
1437  if (j<0)
1438  {
1439   cout << " *AliSignal::GetNlinks* Index j = " << j << " invalid." << endl;
1440   return 0;
1441  }
1442
1443  if (!fLinks) return 0;
1444
1445  Int_t n=0;
1446  if (!j)
1447  {
1448   n=fLinks->GetNrefs(obj);
1449  }
1450  else
1451  {
1452   TArrayI posarr;
1453   n=GetIndices(obj,j,posarr);
1454  }
1455  return n;
1456 }
1457 ///////////////////////////////////////////////////////////////////////////
1458 Int_t AliSignal::GetNlinks(TObject* obj,TString name) const
1459 {
1460 // Provide the number of links to the specified object for the name-spec. slot.
1461 // If obj=0 all encountered objects for the specified slot will be counted.
1462 //
1463 // This procedure involves a slot-index search based on the specified name
1464 // at each invokation. This may become slow in case many slots have been
1465 // defined and/or when this procedure is invoked many times.
1466 // In such cases it is preferable to use indexed addressing in the user code
1467 // either directly or via a few invokations of GetSlotIndex().
1468
1469  Int_t j=GetSlotIndex(name);
1470  Int_t n=0;
1471  if (j>0) n=GetNlinks(obj,j);
1472  return n;
1473 }
1474 ///////////////////////////////////////////////////////////////////////////
1475 TObject* AliSignal::GetLink(Int_t j,Int_t k) const
1476 {
1477 // Provide pointer of the object linked to the j-th slot at position k.
1478
1479  TObject* obj=0;
1480  // Note : In the internal storage matrix slots=columns positions=rows 
1481  if (fLinks) obj=fLinks->GetObject(k,j);
1482  return obj;
1483 }
1484 ///////////////////////////////////////////////////////////////////////////
1485 TObject* AliSignal::GetLink(TString name,Int_t k) const
1486 {
1487 // Provide pointer of the object linked to the name-spec. slot at position k.
1488 //
1489 // This procedure involves a slot-index search based on the specified name
1490 // at each invokation. This may become slow in case many slots have been
1491 // defined and/or when this procedure is invoked many times.
1492 // In such cases it is preferable to use indexed addressing in the user code
1493 // either directly or via a few invokations of GetSlotIndex().
1494
1495  Int_t j=GetSlotIndex(name);
1496  TObject* obj=0;
1497  if (j>0) obj=GetLink(j,k);
1498  return obj;
1499 }
1500 ///////////////////////////////////////////////////////////////////////////
1501 void AliSignal::SetLink(TObject* obj,Int_t j,Int_t k)
1502 {
1503 // Introduce a link (=pointer) to an object for the j-th slot at position k.
1504 // Only the pointer values are stored for (backward) reference, meaning
1505 // that the objects of which the pointers are stored are NOT owned
1506 // by the AliSignal object.
1507 //
1508 // Notes :
1509 //  The first slot is at j=1 and the first position is at k=1.
1510 //  j=1 and k=1 are the default values.
1511 //
1512 // If needed, the storage area for the links is increased automatically.
1513 //
1514 // In case the pointer argument is zero, indeed a value of zero will be
1515 // stored at the specified position (k) for the specified slot (j).
1516 //
1517 // In principle any object derived from TObject can be referred to by this
1518 // mechanism.
1519 // However, this "linking back" facility was introduced to enable AliSignal slots
1520 // to refer directly to the various AliTracks to which the AliSignal object itself
1521 // is related (see AliTrack::AddSignal).
1522 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1523 // object, the current signal is automatically related to this AliTrack
1524 // (or derived) object.
1525 // Also a global link to this AliTrack (or derived) object will be stored
1526 // via the AddTrack() facility.
1527 //
1528 // IMPORTANT NOTE :
1529 // ----------------
1530 // In case one just wants to relate the current AliSignal to a certain AliTrack
1531 // without a specific signal slot association, it is much more efficient
1532 // (both memory and CPU wise) to use the memberfunction AddTrack() instead.
1533 // 
1534 // Please also have a look at the docs of the memberfunction ResetLink()
1535 // to prevent the situation of stored pointers to non-existent object. 
1536
1537  if (!fLinks && obj) fLinks=new AliObjMatrix();
1538
1539  if (!fLinks) return;
1540
1541  // Note : In the internal storage matrix slots=columns positions=rows 
1542  fLinks->EnterObject(k,j,obj);
1543  if (obj) 
1544  {
1545   if (obj->InheritsFrom("AliTrack"))
1546   {
1547    AliTrack* t=(AliTrack*)obj;
1548    AddTrack(*t,1);
1549   }
1550  }
1551 }
1552 ///////////////////////////////////////////////////////////////////////////
1553 void AliSignal::SetLink(TObject* obj,TString name,Int_t k)
1554 {
1555 // Introduce a link (=pointer) to an object for the name-spec. slot at position k.
1556 // Only the pointer values are stored for (backward) reference, meaning
1557 // that the objects of which the pointers are stored are NOT owned
1558 // by the AliSignal object.
1559 //
1560 // This procedure involves a slot-index search based on the specified name
1561 // at each invokation. This may become slow in case many slots have been
1562 // defined and/or when this procedure is invoked many times.
1563 // In such cases it is preferable to use indexed addressing in the user code
1564 // either directly or via a few invokations of GetSlotIndex().
1565 //
1566 // In case the pointer argument is zero, indeed a value of zero will be
1567 // stored at the specified position (k) for the specified slotname.
1568 //
1569 // In principle any object derived from TObject can be referred to by this
1570 // mechanism.
1571 // However, this "linking back" facility was introduced to enable AliSignal slots
1572 // to refer directly to the various AliTracks to which the AliSignal object itself
1573 // is related (see AliTrack::AddSignal).
1574 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1575 // object, the current signal is automatically related to this AliTrack
1576 // (or derived) object.
1577 // Also a global link to this AliTrack (or derived) object will be stored
1578 // via the AddTrack() facility.
1579 //
1580 // IMPORTANT NOTE :
1581 // ----------------
1582 // In case one just wants to relate the current AliSignal to a certain AliTrack
1583 // without a specific signal slot association, it is much more efficient
1584 // (both memory and CPU wise) to use the memberfunction AddTrack() instead.
1585 // 
1586 // Please also have a look at the docs of the memberfunction ResetLink()
1587 // to prevent the situation of stored pointers to non-existent object. 
1588
1589  Int_t j=GetSlotIndex(name);
1590  if (j>0) SetLink(obj,j,k);
1591 }
1592 ///////////////////////////////////////////////////////////////////////////
1593 void AliSignal::AddLink(TObject* obj,Int_t j)
1594 {
1595 // Introduce a link (=pointer) to an object for the j-th slot at the first
1596 // free position.
1597 // Only the pointer values are stored for (backward) reference, meaning
1598 // that the objects of which the pointers are stored are NOT owned
1599 // by the AliSignal object.
1600 //
1601 // Notes :
1602 //  The first slot is at j=1 and the first position is at k=1.
1603 //  j=1 is the default value.
1604 //
1605 // If needed, the storage area for the links is increased automatically.
1606 //
1607 // In case the pointer argument is zero, no link will be added.
1608 //
1609 // In principle any object derived from TObject can be referred to by this
1610 // mechanism.
1611 // However, this "linking back" facility was introduced to enable AliSignal slots
1612 // to refer directly to the various AliTracks to which the AliSignal object itself
1613 // is related (see AliTrack::AddSignal).
1614 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1615 // object, the current signal is automatically related to this AliTrack
1616 // (or derived) object.
1617 // Also a global link to this AliTrack (or derived) object will be stored
1618 // via the AddTrack() facility.
1619 //
1620 // IMPORTANT NOTE :
1621 // ----------------
1622 // In case one just wants to relate the current AliSignal to a certain AliTrack
1623 // without a specific signal slot association, it is much more efficient
1624 // (both memory and CPU wise) to use the memberfunction AddTrack() instead.
1625 // 
1626 // Please also have a look at the docs of the memberfunction ResetLink()
1627 // to prevent the situation of stored pointers to non-existent object. 
1628
1629  if (!obj || j<=0) return;
1630
1631  if (!fLinks) fLinks=new AliObjMatrix();
1632
1633  TObject* dum=0;
1634  Int_t n=GetNlinks(dum,j);
1635  Int_t pos=1;
1636  for (Int_t k=1; k<=n; k++)
1637  {
1638   dum=GetLink(j,k);
1639   if (!dum) break;
1640   pos++;
1641  }
1642
1643  SetLink(obj,j,pos);
1644 }
1645 ///////////////////////////////////////////////////////////////////////////
1646 void AliSignal::AddLink(TObject* obj,TString name)
1647 {
1648 // Introduce a link (=pointer) to an object for the name-spec slot at the first
1649 // free position.
1650 // Only the pointer values are stored for (backward) reference, meaning
1651 // that the objects of which the pointers are stored are NOT owned
1652 // by the AliSignal object.
1653 //
1654 // This procedure involves a slot-index search based on the specified name
1655 // at each invokation. This may become slow in case many slots have been
1656 // defined and/or when this procedure is invoked many times.
1657 // In such cases it is preferable to use indexed addressing in the user code
1658 // either directly or via a few invokations of GetSlotIndex().
1659 //
1660 // In case the pointer argument is zero, indeed a value of zero will be
1661 // stored at the first free position of the specified slotname.
1662 //
1663 // In principle any object derived from TObject can be referred to by this
1664 // mechanism.
1665 // However, this "linking back" facility was introduced to enable AliSignal slots
1666 // to refer directly to the various AliTracks to which the AliSignal object itself
1667 // is related (see AliTrack::AddSignal).
1668 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1669 // object, the current signal is automatically related to this AliTrack
1670 // (or derived) object.
1671 // Also a global link to this AliTrack (or derived) object will be stored
1672 // via the AddTrack() facility.
1673 //
1674 // IMPORTANT NOTE :
1675 // ----------------
1676 // In case one just wants to relate the current AliSignal to a certain AliTrack
1677 // without a specific signal slot association, it is much more efficient
1678 // (both memory and CPU wise) to use the memberfunction AddTrack() instead.
1679 // 
1680 // Please also have a look at the docs of the memberfunction ResetLink()
1681 // to prevent the situation of stored pointers to non-existent object. 
1682
1683  Int_t j=GetSlotIndex(name);
1684  if (j>0) AddLink(obj,j);
1685 }
1686 ///////////////////////////////////////////////////////////////////////////
1687 void AliSignal::ResetLink(Int_t j,Int_t k)
1688 {
1689 // Reset the link of the j-th slot at position k.
1690 //
1691 // Notes :
1692 //  The first slot is at j=1 and the first position is at k=1.
1693 //  j=1 and k=1 are the default values.
1694 //
1695 //  This memberfunction is intended to reset only 1 specified link location.
1696 //  For extended functionality, please refer to the memberfuction ResetLinks().
1697 //
1698 // In general the user should take care of properly clearing the corresponding
1699 // pointer here when the referred object is deleted.
1700 // However, this "linking back" facility was introduced to enable AliSignal slots
1701 // to refer directly to the various AliTracks to which the AliSignal object itself
1702 // is related (see AliTrack::AddSignal).
1703 // As such, the AliTrack destructor already takes care of clearing the corresponding
1704 // links from the various AliSignal slots for all the AliSignal objects that were
1705 // related to that AliTrack. 
1706 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1707 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1708 // the AliSignal object when the corresponding AliTrack object is deleted.
1709  
1710  // Note : In the internal storage matrix slots=columns positions=rows 
1711  if (fLinks) fLinks->RemoveObject(k,j);
1712 }
1713 ///////////////////////////////////////////////////////////////////////////
1714 void AliSignal::ResetLink(TString name,Int_t k)
1715 {
1716 // Reset the link of the name-specified slot at position k.
1717 //
1718 // This memberfunction is intended to reset only 1 specified link location.
1719 // For extended functionality, please refer to the memberfuction ResetLinks().
1720 //
1721 // This procedure involves a slot-index search based on the specified name
1722 // at each invokation. This may become slow in case many slots have been
1723 // defined and/or when this procedure is invoked many times.
1724 // In such cases it is preferable to use indexed addressing in the user code
1725 // either directly or via a few invokations of GetSlotIndex().
1726
1727  Int_t j=GetSlotIndex(name);
1728  if (j>0) ResetLink(j,k);
1729 }
1730 ///////////////////////////////////////////////////////////////////////////
1731 void AliSignal::ResetLinks(TObject* obj,Int_t j,Int_t k)
1732 {
1733 // Reset single or multiple slot link(s) according to user specified selections.
1734 //
1735 // IMPORTANT NOTE :
1736 // ----------------
1737 // This facility only acts on the slot related links.
1738 // The global track reference list will not be affected.
1739 // To remove all references to AliTrack (or derived) objects, please
1740 // use the RemoveTrack() of RemoveTracks() memberfunctions.
1741 //
1742 // A link is only reset if the stored reference matches the argument "obj".
1743 // In case obj=0 no check on the matching of the stored reference is performed
1744 // and the stored link is always reset in accordance with the other
1745 // selection criteria.
1746 //
1747 // In case the slot argument "j" is specified, only the links from that
1748 // specified slot will be deleted.
1749 // In case j=0 (default) no checking on the slot index is performed.
1750 //
1751 // In case the position argument "k" is specified, only the links from that
1752 // specified position will be deleted.
1753 // In case k=0 (default) no checking on the position index is performed.
1754 //
1755 // So, invokation of ResetLinks(obj) will remove all references to the
1756 // object "obj" from the total AliSignal, whereas ResetLinks(obj,j)
1757 // will remove all references to the object "obj" only from slot "j".
1758 //
1759 // Notes :
1760 // -------
1761 // The first slot is indicated as j=1, whereas the first position is at k=1.
1762 //
1763 // Invokation of ResetLinks(0,row,col) is equivalent to invoking the
1764 // memberfunction ResetLink(row,col).
1765 // Invoking the latter directly is slightly faster.
1766 //
1767 // Invokation of ResetLinks(0) will reset all stored references in this AliSignal.
1768 //
1769 // In general the user should take care of properly clearing the corresponding
1770 // pointer here when the referred object is deleted.
1771 // However, this "linking back" facility was introduced to enable AliSignal slots
1772 // to refer directly to the various AliTracks to which the AliSignal object itself
1773 // is related (see AliTrack::AddSignal).
1774 // As such, the AliTrack destructor already takes care of clearing the corresponding
1775 // links from the various AliSignal slots for all the AliSignal objects that were
1776 // related to that AliTrack. 
1777 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1778 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1779 // the AliSignal object when the corresponding AliTrack object is deleted.
1780  
1781  if (!fLinks) return;
1782
1783  if (!obj && !j && !k)
1784  {
1785   fLinks->Reset();
1786  }
1787  else
1788  {
1789   // Note : In the internal storage matrix slots=columns positions=rows 
1790   fLinks->RemoveObjects(obj,k,j);
1791  }
1792 }
1793 ///////////////////////////////////////////////////////////////////////////
1794 void AliSignal::ResetLinks(TObject* obj,TString name,Int_t k)
1795 {
1796 // Reset single or multiple slot link(s) according to user specified selections.
1797 //
1798 // IMPORTANT NOTE :
1799 // ----------------
1800 // This facility only acts on the slot related links.
1801 // The global track reference list will not be affected.
1802 // To remove all references to AliTrack (or derived) objects, please
1803 // use the RemoveTrack() of RemoveTracks() memberfunctions.
1804 //
1805 // A link is only reset if the stored reference matches the argument "obj".
1806 // In case obj=0 no check on the matching of the stored reference is performed
1807 // and the stored link is always reset in accordance with the other
1808 // selection criteria.
1809 //
1810 // In case the position argument "k" is specified, only the links from that
1811 // specified position will be deleted.
1812 // In case k=0 (default) no checking on the position index is performed.
1813 //
1814 // This procedure involves a slot-index search based on the specified name
1815 // at each invokation. This may become slow in case many slots have been
1816 // defined and/or when this procedure is invoked many times.
1817 // In such cases it is preferable to use indexed addressing in the user code
1818 // either directly or via a few invokations of GetSlotIndex().
1819 //
1820 // In general the user should take care of properly clearing the corresponding
1821 // pointer here when the referred object is deleted.
1822 // However, this "linking back" facility was introduced to enable AliSignal slots
1823 // to refer directly to the various AliTracks to which the AliSignal object itself
1824 // is related (see AliTrack::AddSignal).
1825 // As such, the AliTrack destructor already takes care of clearing the corresponding
1826 // links from the various AliSignal slots for all the AliSignal objects that were
1827 // related to that AliTrack. 
1828 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1829 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1830 // the AliSignal object when the corresponding AliTrack object is deleted.
1831
1832  Int_t j=GetSlotIndex(name);
1833  if (j>0) ResetLinks(obj,j,k);
1834 }
1835 ///////////////////////////////////////////////////////////////////////////
1836 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,TArrayI& ks) const
1837 {
1838 // Provide the slot and position indices of all the storage locations
1839 // of the specified object.
1840 // The slot (j) and pos. (k) indices are returned in the two separate TArrayI arrays
1841 // from which the (j,k) pairs can be obtained from the corresponding
1842 // array indices like (j,k)=(js.At(i),ks.At(i)).
1843 // The integer return argument represents the number of (j,k) pairs which
1844 // were encountered for the specified object.
1845 //
1846 // If obj=0 no object selection is performed and all (j,k) indices
1847 // of the stored references for all objects are returned.
1848 //
1849 // Notes :
1850 // -------
1851 // As usual the convention is that slot and position numbering starts at 1.
1852 // 
1853 // This memberfunction always resets the two TArrayI arrays at the start.
1854 //
1855 // This memberfunction can only be used to obtain the (j,k) indices
1856 // of the object as stored via the SetLink() or AddLink() memberfunction.
1857 // This means that in case the user has entered a TObjArray as object
1858 // (to increase the dimension of the resulting structure), the (j,k)
1859 // indices of that TObjArray are obtained and NOT the indices of the
1860 // actual objects contained in that TObjArray structure.
1861 //
1862  Int_t nrefs=0;
1863  js.Reset();
1864  ks.Reset();
1865  // Note : In the internal storage matrix slots=columns positions=rows 
1866  if (fLinks) nrefs=fLinks->GetIndices(obj,ks,js);
1867  return nrefs;
1868 }
1869 ///////////////////////////////////////////////////////////////////////////
1870 Int_t AliSignal::GetIndices(TObject* obj,Int_t j,TArrayI& ks) const
1871 {
1872 // Provide the position indices of all the storage locations of the
1873 // specified object in the j-th slot of this AliSignal.
1874 // The position indices are returned in the TArrayI array.
1875 // The integer return argument represents the number of storage locations which
1876 // were encountered for the specified object in the j-th slot.
1877 //
1878 // If obj=0 no object selection is performed and all position indices
1879 // of the stored references for all objects of the j-th slot are returned.
1880 //
1881 // If j=0 all slots will be scanned and all position indices matching the
1882 // object selection are returned.
1883 // Note that in this case multiple appearances of the same position index
1884 // will only be recorded once in the returned TArrayI array.
1885 //
1886 // Notes :
1887 // -------
1888 // As usual the convention is that slot and position numbering starts at 1.
1889 // 
1890 // This memberfunction always resets the TArrayI array at the start.
1891 //
1892 // This memberfunction can only be used to obtain the position indices
1893 // of the object as stored via the SetLink() or AddLink() memberfunction.
1894 // This means that in case the user has entered a TObjArray as object
1895 // (to increase the dimension of the resulting structure), the position
1896 // indices of that TObjArray are obtained and NOT the indices of the
1897 // actual objects contained in that TObjArray structure.
1898 //
1899  Int_t nrefs=0;
1900  ks.Reset();
1901  // Note : In the internal storage matrix slots=columns positions=rows 
1902  if (fLinks) nrefs=fLinks->GetIndices(obj,ks,j);
1903  return nrefs;
1904 }
1905 ///////////////////////////////////////////////////////////////////////////
1906 Int_t AliSignal::GetIndices(TObject* obj,TString name,TArrayI& ks) const
1907 {
1908 // Provide the position indices of all the storage locations of the
1909 // specified object in the name-specified slot of this AliSignal.
1910 // The position indices are returned in the TArrayI array.
1911 // The integer return argument represents the number of storage locations which
1912 // were encountered for the specified object in the j-th slot.
1913 //
1914 // If obj=0 no object selection is performed and all position indices
1915 // of the stored references for all objects of the j-th slot are returned.
1916 //
1917 // This procedure involves a slot-index search based on the specified name
1918 // at each invokation. This may become slow in case many slots have been
1919 // defined and/or when this procedure is invoked many times.
1920 // In such cases it is preferable to use indexed addressing in the user code
1921 // either directly or via a few invokations of GetSlotIndex().
1922
1923  Int_t j=GetSlotIndex(name);
1924  Int_t n=0;
1925  if (j>0) n=GetIndices(obj,j,ks);
1926  return n;
1927 }
1928 ///////////////////////////////////////////////////////////////////////////
1929 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,Int_t k) const
1930 {
1931 // Provide the slot indices of all the storage locations of the
1932 // specified object for the k-th position in this AliSignal.
1933 // The slot indices are returned in the TArrayI array.
1934 // The integer return argument represents the number of storage locations which
1935 // were encountered for the specified object in the k-th position.
1936 //
1937 // If obj=0 no object selection is performed and all slot indices
1938 // of the stored references for all objects in the k-th position are returned.
1939 //
1940 // If k=0 all positions will be scanned and all slot indices matching the
1941 // object selection are returned.
1942 // Note that in this case multiple appearances of the same slot index
1943 // will only be recorded once in the returned TArrayI array.
1944 //
1945 // Notes :
1946 // -------
1947 // As usual the convention is that slot and position numbering starts at 1.
1948 // 
1949 // This memberfunction always resets the TArrayI array at the start.
1950 //
1951 // This memberfunction can only be used to obtain the slot indices
1952 // of the object as stored via the SetLink() or AddLink() memberfunction.
1953 // This means that in case the user has entered a TObjArray as object
1954 // (to increase the dimension of the resulting structure), the slot
1955 // indices of that TObjArray are obtained and NOT the indices of the
1956 // actual objects contained in that TObjArray structure.
1957 //
1958  Int_t nrefs=0;
1959  js.Reset();
1960  // Note : In the internal storage matrix slots=columns positions=rows 
1961  if (fLinks) nrefs=fLinks->GetIndices(obj,k,js);
1962  return nrefs;
1963 }
1964 ///////////////////////////////////////////////////////////////////////////
1965 void AliSignal::SetSwapMode(Int_t swap)
1966 {
1967 // Set swapmode flag for the internal link storage.
1968 // In case for the stored links the maximum slot number differs considerably
1969 // from the maximum position number, it might be more efficient
1970 // (w.r.t. memory usage and/or output file size) to internally store the
1971 // link reference matrix with the rows and colums swapped.
1972 // This swapping is only related with the internal storage and as such
1973 // is completely hidden for the user.
1974 // At invokation of this memberfunction the default argument is swap=1.
1975 //
1976 // Note : The swap mode can only be set as long as no links are
1977 //        stored in the AliSignal (i.e. a new instance of AliSignal
1978 //        or after invokation of the Reset() or ResetLinks() function).
1979  
1980  if (!fLinks) fLinks=new AliObjMatrix();
1981  fLinks->SetSwapMode(swap);
1982 }
1983 ///////////////////////////////////////////////////////////////////////////
1984 Int_t AliSignal::GetSwapMode() const
1985 {
1986 // Provide swapmode flag of the link storage.
1987  Int_t swap=0; 
1988  if (fLinks) swap=fLinks->GetSwapMode();
1989  return swap;
1990 }
1991 ///////////////////////////////////////////////////////////////////////////
1992 void AliSignal::SetDevice(TObject* dev)
1993 {
1994 // Store the pointer to the device which owns this AliSignal object.
1995 // This memberfunction is meant for internal use in AliDevice.
1996  fDevice=dev;
1997 }
1998 ///////////////////////////////////////////////////////////////////////////
1999 AliDevice* AliSignal::GetDevice() const
2000 {
2001 // Provide the pointer to the device which owns this AliSignal object.
2002  return (AliDevice*)fDevice;
2003 }
2004 ///////////////////////////////////////////////////////////////////////////
2005 void AliSignal::AddTrack(AliTrack& t,Int_t mode)
2006 {
2007 // Relate an AliTrack object to this signal.
2008 // Only the pointer values are stored for (backward) reference, meaning
2009 // that the tracks of which the pointers are stored are NOT owned
2010 // by the AliSignal object.
2011 //
2012 // mode = 0 : Only the reference to the specified track is stored in
2013 //            the current signal, without storing the (backward) reference
2014 //            to this signal into the AliTrack structure. 
2015 //        1 : The (backward) reference to the current signal is also automatically
2016 //            stored into the AliTrack (or derived) object specified in the
2017 //            input argument.
2018 //
2019 // The default is mode=1.
2020
2021  if (!fTracks) fTracks=new TObjArray(1);
2022
2023  // Check if this track is already stored for this signal
2024  Int_t ntk=GetNtracks();
2025  for (Int_t i=0; i<ntk; i++)
2026  {
2027   if (&t==fTracks->At(i)) return; 
2028  }
2029
2030  fTracks->Add(&t);
2031  if (mode==1) t.AddSignal(*this,0);
2032 }
2033 ///////////////////////////////////////////////////////////////////////////
2034 void AliSignal::RemoveTrack(AliTrack& t,Int_t mode)
2035 {
2036 // Remove related AliTrack object from this signal.
2037 // Also all references (if any) to this track in the slot links area
2038 // are removed.
2039 //
2040 // mode = 0 : All references to the specified track are removed from
2041 //            the current signal, without removing the (backward) reference
2042 //            to this signal from the AliTrack structure. 
2043 //        1 : The (backward) reference to the current signal is also automatically
2044 //            removed from the AliTrack (or derived) object specified in the
2045 //            input argument.
2046 //
2047 // The default is mode=1.
2048
2049  if (fTracks)
2050  {
2051   AliTrack* test=(AliTrack*)fTracks->Remove(&t);
2052   if (test) fTracks->Compress();
2053  }
2054
2055  ResetLinks(&t);
2056
2057  if (mode==1) t.RemoveSignal(*this,0);
2058 }
2059 ///////////////////////////////////////////////////////////////////////////
2060 void AliSignal::RemoveTracks(Int_t mode)
2061 {
2062 // Remove all related AliTrack objects from this signal.
2063 // Also all references (if any) to the related tracks in the slot links area
2064 // are removed.
2065 //
2066 // mode = 0 : All track references are removed from the current signal,
2067 //            without removing the (backward) references to this signal from
2068 //            the corresponding AliTrack objects. 
2069 //        1 : The (backward) references to the current signal are also automatically
2070 //            removed from the corresponding AliTrack (or derived) objects.
2071 //
2072 // The default is mode=1.
2073  
2074  if (!fTracks) return;
2075
2076  Int_t ntk=GetNtracks();
2077  for (Int_t i=0; i<ntk; i++)
2078  {
2079   AliTrack* tx=(AliTrack*)fTracks->At(i);
2080   if (tx)
2081   {
2082    ResetLinks(tx);
2083    if (mode==1) tx->RemoveSignal(*this,0);
2084   }
2085  }
2086
2087  delete fTracks;
2088  fTracks=0;
2089 }
2090 ///////////////////////////////////////////////////////////////////////////
2091 Int_t AliSignal::GetNtracks(AliTrack* t) const
2092 {
2093 // Provide the number of related AliTracks.
2094 // In case an AliTrack pointer is specified as input argument,
2095 // the number returned will be the number of occurrences (i.e. 0 or 1)
2096 // for that specified track.
2097 // By default t=0, which implies that just the number of all associated
2098 // tracks will be returned.
2099
2100  if (!fTracks) return 0;
2101
2102  Int_t ntk=fTracks->GetEntries();
2103
2104  if (!t) return ntk;
2105
2106  for (Int_t i=0; i<ntk; i++)
2107  {
2108   AliTrack* tx=(AliTrack*)fTracks->At(i);
2109   if (tx==t) return 1;
2110  }
2111
2112  return 0;
2113 }
2114 ///////////////////////////////////////////////////////////////////////////
2115 AliTrack* AliSignal::GetTrack(Int_t j) const
2116 {
2117 // Provide the related AliTrack number j.
2118 // Note : j=1 denotes the first track.
2119
2120  if (!fTracks) return 0;
2121
2122  if ((j >= 1) && (j <= GetNtracks()))
2123  {
2124   return (AliTrack*)fTracks->At(j-1);
2125  }
2126  else
2127  {
2128   cout << " *AliSignal* track number : " << j << " out of range."
2129        << " Ntk = " << GetNtracks() << endl;
2130   return 0;
2131  }
2132 }
2133 ///////////////////////////////////////////////////////////////////////////
2134 AliTrack* AliSignal::GetIdTrack(Int_t id) const
2135 {
2136 // Return the track with user identifier "id" of this signal
2137  if (!fTracks) return 0;
2138
2139  AliTrack* tx=0;
2140  for (Int_t i=0; i<GetNtracks(); i++)
2141  {
2142   tx=(AliTrack*)fTracks->At(i);
2143   if (id == tx->GetId()) return tx;
2144  }
2145  return 0; // No matching id found
2146 }
2147 ///////////////////////////////////////////////////////////////////////////
2148 TObject* AliSignal::Clone(const char* name) const
2149 {
2150 // Make a deep copy of the current object and provide the pointer to the copy.
2151 // This memberfunction enables automatic creation of new objects of the
2152 // correct type depending on the object type, a feature which may be very useful
2153 // for containers when adding objects in case the container owns the objects.
2154 // This feature allows e.g. AliTrack to store either AliSignal objects or
2155 // objects derived from AliSignal via the AddSignal memberfunction, provided
2156 // these derived classes also have a proper Clone memberfunction. 
2157
2158  AliSignal* sig=new AliSignal(*this);
2159  if (name)
2160  {
2161   if (strlen(name)) sig->SetName(name);
2162  }
2163  return sig;
2164 }
2165 ///////////////////////////////////////////////////////////////////////////