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