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