]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliSignal.cxx
20-apr-2005 NvE Id of owning device added to the output of AliSignal::Data().
[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        << " Id : " << fDevice->GetUniqueID();
575   if (strlen(devname))  cout << " Name : " << devname;
576   if (strlen(devtitle)) cout << " Title : " << devtitle;
577   cout << endl;
578  }
579
580  // Provide an overview of the stored waveforms
581  ListWaveform(-1);
582
583  // Provide an overview of all the data and attribute slots
584  List(-1);
585
586 ///////////////////////////////////////////////////////////////////////////
587 void AliSignal::List(Int_t j) const
588 {
589 // Provide signal information for the j-th slot.
590 // The first slot is at j=1.
591 // In case j=0 (default) the data of all slots will be listed.
592 // In case j=-1 the data of all slots will be listed, but the header
593 // information will be suppressed.
594
595  if (j<-1) 
596  {
597   cout << " *AliSignal::List* Invalid argument j = " << j << endl;
598   return;
599  }
600
601  if (j != -1)
602  {
603   const char* name=GetName();
604   const char* title=GetTitle();
605
606   cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
607   if (strlen(name))  cout << " Name : " << name;
608   if (strlen(title)) cout << " Title : " << title;
609   cout << endl;
610   if (fDevice)
611   {
612    const char* devname=fDevice->GetName();
613    const char* devtitle=fDevice->GetTitle();
614    cout << "   Owned by device : " << fDevice->ClassName();
615    if (strlen(devname))  cout << " Name : " << devname;
616    if (strlen(devtitle)) cout << " Title : " << devtitle;
617    cout << endl;
618   }
619  }
620
621  Int_t nvalues=GetNvalues();
622  Int_t nerrors=GetNerrors();
623  Int_t nlinkslots=0;
624  if (fLinks) nlinkslots=fLinks->GetMaxColumn();
625  Int_t n=nvalues;
626  if (nerrors>n) n=nerrors;
627  if (nlinkslots>n) n=nlinkslots;
628
629  TObject* obj=0;
630  Int_t nrefs=0;
631  TArrayI posarr;
632  Int_t pos;
633
634  if (j<=0)
635  {
636   for (Int_t i=1; i<=n; i++)
637   {
638    cout << "   Slot : " << i;
639    if (i<=nvalues) cout << " Signal value : " << GetSignal(i);
640    if (i<=nerrors) cout << " error : " << GetSignalError(i);
641    AliAttrib::List(i);
642    cout << endl;
643    obj=0;
644    nrefs=GetIndices(obj,i,posarr);
645    for (Int_t k=0; k<nrefs; k++)
646    {
647     pos=posarr.At(k);
648     obj=GetLink(i,pos);
649     if (obj)
650     {
651      cout << "    Link at position " << pos << " to : " << obj->ClassName();
652      if (obj->InheritsFrom("TNamed"))
653      {
654       const char* lname=obj->GetName();
655       const char* ltitle=obj->GetTitle();
656       if (strlen(lname))  cout << " Name : " << lname;
657       if (strlen(ltitle)) cout << " Title : " << ltitle;
658      }
659      cout << endl;
660     }
661    }
662   }
663  }
664  else
665  {
666   if (j<=n)
667   {
668    cout << "   Slot : " << j;
669    if (j<=nvalues) cout << " Signal value : " << GetSignal(j);
670    if (j<=nerrors) cout << " error : " << GetSignalError(j);
671    AliAttrib::List(j);
672    cout << endl;
673    obj=0;
674    nrefs=GetIndices(obj,j,posarr);
675    for (Int_t kj=0; kj<nrefs; kj++)
676    {
677     pos=posarr.At(kj);
678     obj=GetLink(j,pos);
679     if (obj)
680     {
681      cout << "    Link at position " << pos << " to : " << obj->ClassName();
682      if (obj->InheritsFrom("TNamed"))
683      {
684       const char* lnamej=obj->GetName();
685       const char* ltitlej=obj->GetTitle();
686       if (strlen(lnamej))  cout << " Name : " << lnamej;
687       if (strlen(ltitlej)) cout << " Title : " << ltitlej;
688      }
689      cout << endl;
690     }
691    }
692   }
693  }
694
695 ///////////////////////////////////////////////////////////////////////////
696 void AliSignal::List(TString name) const
697 {
698 // Provide signal information for the name-specified slot.
699 //
700 // This procedure involves a slot-index search based on the specified name
701 // at each invokation. This may become slow in case many slots have been
702 // defined and/or when this procedure is invoked many times.
703 // In such cases it is preferable to use indexed addressing in the user code
704 // either directly or via a few invokations of GetSlotIndex().
705
706  Int_t j=GetSlotIndex(name);
707  if (j>0) List(j);
708 }
709 ///////////////////////////////////////////////////////////////////////////
710 void AliSignal::ListWaveform(Int_t j) const
711 {
712 // Provide information for the j-th waveform.
713 // The first waveform is at j=1.
714 // In case j=0 (default) the info of all waveforms will be listed.
715 // In case j=-1 the info of all waveforms will be listed, but the header
716 // information will be suppressed.
717
718  if (j<-1) 
719  {
720   cout << " *AliSignal::ListWaveform* Invalid argument j = " << j << endl;
721   return;
722  }
723
724  if (j != -1)
725  {
726   const char* name=GetName();
727   const char* title=GetTitle();
728
729   cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
730   if (strlen(name))  cout << " Name : " << name;
731   if (strlen(title)) cout << " Title : " << title;
732   cout << endl;
733   if (fDevice)
734   {
735    const char* devname=fDevice->GetName();
736    const char* devtitle=fDevice->GetTitle();
737    cout << "   Owned by device : " << fDevice->ClassName();
738    if (strlen(devname))  cout << " Name : " << devname;
739    if (strlen(devtitle)) cout << " Title : " << devtitle;
740    cout << endl;
741   }
742  }
743
744  Int_t n=GetNwaveforms();
745  TObject* obj=0;
746
747  if (j<=0)
748  {
749   for (Int_t i=1; i<=n; i++)
750   {
751    obj=GetWaveform(i);
752    if (obj)
753    {
754     const char* wfname=obj->GetName();
755     const char* wftitle=obj->GetTitle();
756     cout << "    Waveform " << i << " : " << obj->ClassName();
757     if (strlen(wfname))  cout << " Name : " << wfname;
758     if (strlen(wftitle)) cout << " Title : " << wftitle;
759     cout << endl;
760    }
761   }
762  }
763  else
764  {
765   if (j<=n)
766   {
767    obj=GetWaveform(j);
768    if (obj)
769    {
770     const char* wfnamej=obj->GetName();
771     const char* wftitlej=obj->GetTitle();
772     cout << "    Waveform " << j << " : " << obj->ClassName();
773     if (strlen(wfnamej))  cout << " Name : " << wfnamej;
774     if (strlen(wftitlej)) cout << " Title : " << wftitlej;
775     cout << endl;
776    }
777   }
778  }
779 }
780 ///////////////////////////////////////////////////////////////////////////
781 Int_t AliSignal::GetNvalues() const
782 {
783 // Provide the number of values for this signal.
784  Int_t n=0;
785  if (fSignals) n=fSignals->GetSize();
786  return n;
787 }
788 ///////////////////////////////////////////////////////////////////////////
789 Int_t AliSignal::GetNerrors() const
790 {
791 // Provide the number specified errors on the values for this signal.
792  Int_t n=0;
793  if (fDsignals) n=fDsignals->GetSize();
794  return n;
795 }
796 ///////////////////////////////////////////////////////////////////////////
797 Int_t AliSignal::GetNwaveforms() const
798 {
799 // Provide the number of specified waveforms for this signal.
800 // Actually the return value is the highest index of the stored waveforms.
801 // This allows an index dependent meaning of waveform info (e.g. waveforms
802 // with various gain values).
803 // So, when all waveforms are stored in consequetive positions (e.g. 1,2,3),
804 // this memberfunction returns 3, being both the highest filled position
805 // and the actual number of waveforms.
806 // In case only waveforms are stored at positions 1,2,5,7 this memberfunction
807 // returns a value 7 whereas only 4 actual waveforms are present.
808 // This implies that when looping over the various waveform slots, one
809 // always has to check whether the returned pointer value is non-zero
810 // (which is a good practice anyhow).
811  Int_t n=-1;
812  if (fWaveforms) n=fWaveforms->GetLast();
813  return (n+1);
814 }
815 ///////////////////////////////////////////////////////////////////////////
816 TH1F* AliSignal::GetWaveform(Int_t j) const
817 {
818 // Provide pointer to the j-th waveform histogram.
819  TH1F* waveform=0;
820  if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
821  return waveform;
822 }
823 ///////////////////////////////////////////////////////////////////////////
824 TH1F* AliSignal::GetWaveform(TString name) const
825 {
826 // Provide pointer to the waveform histogram with the specified name.
827 // In case no match is found, zero is returned.
828  Int_t n=GetNwaveforms();
829  TString str;
830  for (Int_t i=1; i<=n; i++)
831  {
832   TH1F* waveform=GetWaveform(i);
833   if (waveform)
834   {
835    str=waveform->GetName();
836    if (str == name) return waveform;
837   }
838  }
839  return 0; // No match found
840 }
841 ///////////////////////////////////////////////////////////////////////////
842 Int_t AliSignal::GetWaveformIndex(TString name) const
843 {
844 // Provide index to the waveform histogram with the specified name.
845 // In case no match is found, zero is returned.
846  Int_t n=GetNwaveforms();
847  TString str;
848  for (Int_t i=1; i<=n; i++)
849  {
850   TH1F* waveform=GetWaveform(i);
851   if (waveform)
852   {
853    str=waveform->GetName();
854    if (str == name) return i;
855   }
856  }
857  return 0; // No match found
858 }
859 ///////////////////////////////////////////////////////////////////////////
860 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
861 {
862 // Set the 1D waveform histogram for the j-th waveform.
863 //
864 // Notes :
865 //  The first waveform position at j=1.
866 //  j=1 is the default value.
867 //
868 // In case the value of the index j exceeds the maximum number of reserved
869 // positions for the waveforms, the number of reserved positions for the waveforms
870 // is increased automatically.
871 //
872 // In case the histo pointer argument has the same value as the current waveform
873 // histogram pointer value, no action is taken since the user has already
874 // modified the actual histogram.
875 //
876 // In case the histo pointer argument is zero, the current waveform histogram
877 // is deleted and the pointer set to zero.
878 //
879 // In all other cases the current waveform histogram is deleted and a new
880 // copy of the input histogram is created which becomes the current waveform
881 // histogram.
882
883  if (j<1) return;
884
885  if (!fWaveforms)
886  {
887   fWaveforms=new TObjArray(j);
888   fWaveforms->SetOwner();
889  }
890
891  if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
892
893  TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
894  if (waveform != hcur)
895  {
896   if (hcur)
897   {
898    fWaveforms->Remove(hcur);
899    delete hcur;
900    hcur=0;
901   }
902   if (waveform)
903   {
904    hcur=new TH1F(*waveform);
905    fWaveforms->AddAt(hcur,j-1);
906   }
907  } 
908 }
909 ///////////////////////////////////////////////////////////////////////////
910 void AliSignal::ResetWaveform(Int_t j)
911 {
912 // Reset the histogram of the j-th (default j=1) waveform.
913 // This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
914 // To actually delete the histograms from memory, use DeleteWaveform().
915 // Notes : The first position is at j=1.
916 //         j=0 ==> All waveforms will be reset.
917  
918  if (!fWaveforms) return;
919
920  Int_t size=fWaveforms->GetSize();
921
922  if ((j>=0) && (j<=size))
923  {
924   if (j)
925   {
926    TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
927    if (hwave) hwave->Reset();
928   }
929   else
930   {
931    for (Int_t i=0; i<size; i++)
932    {
933     TH1F* hwave=(TH1F*)fWaveforms->At(i);
934     if (hwave) hwave->Reset();
935    }
936   }
937  }
938  else
939  {
940   cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
941   return;
942  }
943 }
944 ///////////////////////////////////////////////////////////////////////////
945 void AliSignal::ResetWaveform(TString name)
946 {
947 // Reset the waveform with the specified name.
948  Int_t j=GetWaveformIndex(name);
949  if (j>0) ResetWaveform(j);
950 }
951 ///////////////////////////////////////////////////////////////////////////
952 void AliSignal::DeleteWaveform(Int_t j)
953 {
954 // Delete the histogram of the j-th (default j=1) waveform.
955 // Notes : The first position is at j=1.
956 //         j=0 ==> All waveforms will be deleted.
957  
958  if (!fWaveforms) return;
959
960  Int_t size=fWaveforms->GetSize();
961
962  if ((j>=0) && (j<=size))
963  {
964   if (j)
965   {
966    TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
967    if (hwave)
968    {
969     fWaveforms->Remove(hwave);
970     delete hwave;
971    }
972   }
973   else
974   {
975    delete fWaveforms;
976    fWaveforms=0;
977   }
978  }
979  else
980  {
981   cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
982   return;
983  }
984 }
985 ///////////////////////////////////////////////////////////////////////////
986 void AliSignal::DeleteWaveform(TString name)
987 {
988 // Delete the waveform with the specified name.
989  Int_t j=GetWaveformIndex(name);
990  if (j>0) DeleteWaveform(j);
991 }
992 ///////////////////////////////////////////////////////////////////////////
993 Int_t AliSignal::GetNlinks(TObject* obj,Int_t j) const
994 {
995 // Provide the number of links to the specified object for the j-th slot.
996 // If j=0 (default) all slots will be scanned for the specified object.
997 // If obj=0 (default) all encountered objects for the specified slot will be counted.
998 // So, invokation of the default GetNlinks() will return the total number of
999 // all references to all sorts of stored objects.
1000  if (j<0)
1001  {
1002   cout << " *AliSignal::GetNlinks* Index j = " << j << " invalid." << endl;
1003   return 0;
1004  }
1005
1006  Int_t n=0;
1007  if (!j)
1008  {
1009   if (fLinks) n=fLinks->GetNrefs(obj);
1010  }
1011  else
1012  {
1013   TArrayI posarr;
1014   n=GetIndices(obj,j,posarr);
1015  }
1016  return n;
1017 }
1018 ///////////////////////////////////////////////////////////////////////////
1019 Int_t AliSignal::GetNlinks(TObject* obj,TString name) const
1020 {
1021 // Provide the number of links to the specified object for the name-spec. slot.
1022 // If obj=0 all encountered objects for the specified slot will be counted.
1023 //
1024 // This procedure involves a slot-index search based on the specified name
1025 // at each invokation. This may become slow in case many slots have been
1026 // defined and/or when this procedure is invoked many times.
1027 // In such cases it is preferable to use indexed addressing in the user code
1028 // either directly or via a few invokations of GetSlotIndex().
1029
1030  Int_t j=GetSlotIndex(name);
1031  Int_t n=0;
1032  if (j>0) n=GetNlinks(obj,j);
1033  return n;
1034 }
1035 ///////////////////////////////////////////////////////////////////////////
1036 TObject* AliSignal::GetLink(Int_t j,Int_t k) const
1037 {
1038 // Provide pointer of the object linked to the j-th slot at position k.
1039
1040  TObject* obj=0;
1041  // Note : In the internal storage matrix slots=columns positions=rows 
1042  if (fLinks) obj=fLinks->GetObject(k,j);
1043  return obj;
1044 }
1045 ///////////////////////////////////////////////////////////////////////////
1046 TObject* AliSignal::GetLink(TString name,Int_t k) const
1047 {
1048 // Provide pointer of the object linked to the name-spec. slot at position k.
1049 //
1050 // This procedure involves a slot-index search based on the specified name
1051 // at each invokation. This may become slow in case many slots have been
1052 // defined and/or when this procedure is invoked many times.
1053 // In such cases it is preferable to use indexed addressing in the user code
1054 // either directly or via a few invokations of GetSlotIndex().
1055
1056  Int_t j=GetSlotIndex(name);
1057  TObject* obj=0;
1058  if (j>0) obj=GetLink(j,k);
1059  return obj;
1060 }
1061 ///////////////////////////////////////////////////////////////////////////
1062 void AliSignal::SetLink(TObject* obj,Int_t j,Int_t k)
1063 {
1064 // Introduce a link (=pointer) to an object for the j-th slot at position k.
1065 // Only the pointer values are stored for (backward) reference, meaning
1066 // that the objects of which the pointers are stored are NOT owned
1067 // by the AliSignal object.
1068 //
1069 // Notes :
1070 //  The first slot is at j=1 and the first position is at k=1.
1071 //  j=1 and k=1 are the default values.
1072 //
1073 // If needed, the storage area for the links is increased automatically.
1074 //
1075 // In case the pointer argument is zero, indeed a value of zero will be
1076 // stored at the specified position (k) for the specified slot (j).
1077 //
1078 // In principle any object derived from TObject can be referred to by this
1079 // mechanism.
1080 // However, this "linking back" facility was introduced to enable AliSignal slots
1081 // to refer directly to the various AliTracks to which the AliSignal object itself
1082 // is related (see AliTrack::AddSignal).
1083 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1084 // object, the current signal is automatically related to this AliTrack
1085 // (or derived) object.
1086 // 
1087 // Please also have a look at the docs of the memberfunction ResetLink()
1088 // to prevent the situation of stored pointers to non-existent object. 
1089
1090  if (!fLinks && obj) fLinks=new AliObjMatrix();
1091
1092  if (!fLinks) return;
1093
1094  // Note : In the internal storage matrix slots=columns positions=rows 
1095  fLinks->EnterObject(k,j,obj);
1096  if (obj) 
1097  {
1098   if (obj->InheritsFrom("AliTrack"))
1099   {
1100    AliTrack* t=(AliTrack*)obj;
1101    t->AddSignal(*this);
1102   }
1103  }
1104 }
1105 ///////////////////////////////////////////////////////////////////////////
1106 void AliSignal::SetLink(TObject* obj,TString name,Int_t k)
1107 {
1108 // Introduce a link (=pointer) to an object for the name-spec. slot at position k.
1109 // Only the pointer values are stored for (backward) reference, meaning
1110 // that the objects of which the pointers are stored are NOT owned
1111 // by the AliSignal object.
1112 //
1113 // This procedure involves a slot-index search based on the specified name
1114 // at each invokation. This may become slow in case many slots have been
1115 // defined and/or when this procedure is invoked many times.
1116 // In such cases it is preferable to use indexed addressing in the user code
1117 // either directly or via a few invokations of GetSlotIndex().
1118
1119  Int_t j=GetSlotIndex(name);
1120  if (j>0) SetLink(obj,j,k);
1121 }
1122 ///////////////////////////////////////////////////////////////////////////
1123 void AliSignal::AddLink(TObject* obj,Int_t j)
1124 {
1125 // Introduce a link (=pointer) to an object for the j-th slot at the first
1126 // free position.
1127 // Only the pointer values are stored for (backward) reference, meaning
1128 // that the objects of which the pointers are stored are NOT owned
1129 // by the AliSignal object.
1130 //
1131 // Notes :
1132 //  The first slot is at j=1 and the first position is at k=1.
1133 //  j=1 is the default value.
1134 //
1135 // If needed, the storage area for the links is increased automatically.
1136 //
1137 // In case the pointer argument is zero, no link will be added.
1138 //
1139 // In principle any object derived from TObject can be referred to by this
1140 // mechanism.
1141 // However, this "linking back" facility was introduced to enable AliSignal slots
1142 // to refer directly to the various AliTracks to which the AliSignal object itself
1143 // is related (see AliTrack::AddSignal).
1144 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1145 // object, the current signal is automatically related to this AliTrack
1146 // (or derived) object.
1147 // 
1148 // Please also have a look at the docs of the memberfunction ResetLink()
1149 // to prevent the situation of stored pointers to non-existent object. 
1150
1151  if (!obj || j<=0) return;
1152
1153  if (!fLinks) fLinks=new AliObjMatrix();
1154
1155  TObject* dum=0;
1156  Int_t n=GetNlinks(dum,j);
1157  Int_t pos=1;
1158  for (Int_t k=1; k<=n; k++)
1159  {
1160   dum=GetLink(j,k);
1161   if (!dum) break;
1162   pos++;
1163  }
1164
1165  SetLink(obj,j,pos);
1166 }
1167 ///////////////////////////////////////////////////////////////////////////
1168 void AliSignal::AddLink(TObject* obj,TString name)
1169 {
1170 // Introduce a link (=pointer) to an object for the name-spec slot at the first
1171 // free position.
1172 // Only the pointer values are stored for (backward) reference, meaning
1173 // that the objects of which the pointers are stored are NOT owned
1174 // by the AliSignal object.
1175 //
1176 // This procedure involves a slot-index search based on the specified name
1177 // at each invokation. This may become slow in case many slots have been
1178 // defined and/or when this procedure is invoked many times.
1179 // In such cases it is preferable to use indexed addressing in the user code
1180 // either directly or via a few invokations of GetSlotIndex().
1181
1182  Int_t j=GetSlotIndex(name);
1183  if (j>0) AddLink(obj,j);
1184 }
1185 ///////////////////////////////////////////////////////////////////////////
1186 void AliSignal::ResetLink(Int_t j,Int_t k)
1187 {
1188 // Reset the link of the j-th slot at position k.
1189 //
1190 // Notes :
1191 //  The first slot is at j=1 and the first position is at k=1.
1192 //  j=1 and k=1 are the default values.
1193 //
1194 //  This memberfunction is intended to reset only 1 specified link location.
1195 //  For extended functionality, please refer to the memberfuction ResetLinks().
1196 //
1197 // In general the user should take care of properly clearing the corresponding
1198 // pointer here when the referred object is deleted.
1199 // However, this "linking back" facility was introduced to enable AliSignal slots
1200 // to refer directly to the various AliTracks to which the AliSignal object itself
1201 // is related (see AliTrack::AddSignal).
1202 // As such, the AliTrack destructor already takes care of clearing the corresponding
1203 // links from the various AliSignal slots for all the AliSignal objects that were
1204 // related to that AliTrack. 
1205 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1206 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1207 // the AliSignal object when the corresponding AliTrack object is deleted.
1208  
1209  // Note : In the internal storage matrix slots=columns positions=rows 
1210  if (fLinks) fLinks->RemoveObject(k,j);
1211 }
1212 ///////////////////////////////////////////////////////////////////////////
1213 void AliSignal::ResetLink(TString name,Int_t k)
1214 {
1215 // Reset the link of the name-specified slot at position k.
1216 //
1217 // This memberfunction is intended to reset only 1 specified link location.
1218 // For extended functionality, please refer to the memberfuction ResetLinks().
1219 //
1220 // This procedure involves a slot-index search based on the specified name
1221 // at each invokation. This may become slow in case many slots have been
1222 // defined and/or when this procedure is invoked many times.
1223 // In such cases it is preferable to use indexed addressing in the user code
1224 // either directly or via a few invokations of GetSlotIndex().
1225
1226  Int_t j=GetSlotIndex(name);
1227  if (j>0) ResetLink(j,k);
1228 }
1229 ///////////////////////////////////////////////////////////////////////////
1230 void AliSignal::ResetLinks(TObject* obj,Int_t j,Int_t k)
1231 {
1232 // Reset single or multiple link(s) according to user specified selections.
1233 //
1234 // A link is only reset if the stored reference matches the argument "obj".
1235 // In case obj=0 no check on the matching of the stored reference is performed
1236 // and the stored link is always reset in accordance with the other
1237 // selection criteria.
1238 //
1239 // In case the slot argument "j" is specified, only the links from that
1240 // specified slot will be deleted.
1241 // In case j=0 (default) no checking on the slot index is performed.
1242 //
1243 // In case the position argument "k" is specified, only the links from that
1244 // specified position will be deleted.
1245 // In case k=0 (default) no checking on the position index is performed.
1246 //
1247 // So, invokation of ResetLinks(obj) will remove all references to the
1248 // object "obj" from the total AliSignal, whereas ResetLinks(obj,j)
1249 // will remove all references to the object "obj" only from slot "j".
1250 //
1251 // Notes :
1252 // -------
1253 // The first slot is indicated as j=1, whereas the first position is at k=1.
1254 //
1255 // Invokation of ResetLinks(0,row,col) is equivalent to invoking the
1256 // memberfunction ResetLink(row,col).
1257 // Invoking the latter directly is slightly faster.
1258 //
1259 // Invokation of ResetLinks(0) will reset all stored references in this AliSignal.
1260 //
1261 // In general the user should take care of properly clearing the corresponding
1262 // pointer here when the referred object is deleted.
1263 // However, this "linking back" facility was introduced to enable AliSignal slots
1264 // to refer directly to the various AliTracks to which the AliSignal object itself
1265 // is related (see AliTrack::AddSignal).
1266 // As such, the AliTrack destructor already takes care of clearing the corresponding
1267 // links from the various AliSignal slots for all the AliSignal objects that were
1268 // related to that AliTrack. 
1269 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1270 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1271 // the AliSignal object when the corresponding AliTrack object is deleted.
1272  
1273  if (!fLinks) return;
1274
1275  if (!obj && !j && !k)
1276  {
1277   fLinks->Reset();
1278  }
1279  else
1280  {
1281   // Note : In the internal storage matrix slots=columns positions=rows 
1282   fLinks->RemoveObjects(obj,k,j);
1283  }
1284 }
1285 ///////////////////////////////////////////////////////////////////////////
1286 void AliSignal::ResetLinks(TObject* obj,TString name,Int_t k)
1287 {
1288 // Reset single or multiple link(s) according to user specified selections.
1289 //
1290 // A link is only reset if the stored reference matches the argument "obj".
1291 // In case obj=0 no check on the matching of the stored reference is performed
1292 // and the stored link is always reset in accordance with the other
1293 // selection criteria.
1294 //
1295 // In case the position argument "k" is specified, only the links from that
1296 // specified position will be deleted.
1297 // In case k=0 (default) no checking on the position index is performed.
1298 //
1299 // This procedure involves a slot-index search based on the specified name
1300 // at each invokation. This may become slow in case many slots have been
1301 // defined and/or when this procedure is invoked many times.
1302 // In such cases it is preferable to use indexed addressing in the user code
1303 // either directly or via a few invokations of GetSlotIndex().
1304
1305  Int_t j=GetSlotIndex(name);
1306  if (j>0) ResetLinks(obj,j,k);
1307 }
1308 ///////////////////////////////////////////////////////////////////////////
1309 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,TArrayI& ks) const
1310 {
1311 // Provide the slot and position indices of all the storage locations
1312 // of the specified object.
1313 // The slot (j) and pos. (k) indices are returned in the two separate TArrayI arrays
1314 // from which the (j,k) pairs can be obtained from the corresponding
1315 // array indices like (j,k)=(js.At(i),ks.At(i)).
1316 // The integer return argument represents the number of (j,k) pairs which
1317 // were encountered for the specified object.
1318 //
1319 // If obj=0 no object selection is performed and all (j,k) indices
1320 // of the stored references for all objects are returned.
1321 //
1322 // Notes :
1323 // -------
1324 // As usual the convention is that slot and position numbering starts at 1.
1325 // 
1326 // This memberfunction always resets the two TArrayI arrays at the start.
1327 //
1328 // This memberfunction can only be used to obtain the (j,k) indices
1329 // of the object as stored via the SetLink() or AddLink() memberfunction.
1330 // This means that in case the user has entered a TObjArray as object
1331 // (to increase the dimension of the resulting structure), the (j,k)
1332 // indices of that TObjArray are obtained and NOT the indices of the
1333 // actual objects contained in that TObjArray structure.
1334 //
1335  Int_t nrefs=0;
1336  js.Reset();
1337  ks.Reset();
1338  // Note : In the internal storage matrix slots=columns positions=rows 
1339  if (fLinks) nrefs=fLinks->GetIndices(obj,ks,js);
1340  return nrefs;
1341 }
1342 ///////////////////////////////////////////////////////////////////////////
1343 Int_t AliSignal::GetIndices(TObject* obj,Int_t j,TArrayI& ks) const
1344 {
1345 // Provide the position indices of all the storage locations of the
1346 // specified object in the j-th slot of this AliSignal.
1347 // The position indices are returned in the TArrayI array.
1348 // The integer return argument represents the number of storage locations which
1349 // were encountered for the specified object in the j-th slot.
1350 //
1351 // If obj=0 no object selection is performed and all position indices
1352 // of the stored references for all objects of the j-th slot are returned.
1353 //
1354 // If j=0 all slots will be scanned and all position indices matching the
1355 // object selection are returned.
1356 // Note that in this case multiple appearances of the same position index
1357 // will only be recorded once in the returned TArrayI array.
1358 //
1359 // Notes :
1360 // -------
1361 // As usual the convention is that slot and position numbering starts at 1.
1362 // 
1363 // This memberfunction always resets the TArrayI array at the start.
1364 //
1365 // This memberfunction can only be used to obtain the position indices
1366 // of the object as stored via the SetLink() or AddLink() memberfunction.
1367 // This means that in case the user has entered a TObjArray as object
1368 // (to increase the dimension of the resulting structure), the position
1369 // indices of that TObjArray are obtained and NOT the indices of the
1370 // actual objects contained in that TObjArray structure.
1371 //
1372  Int_t nrefs=0;
1373  ks.Reset();
1374  // Note : In the internal storage matrix slots=columns positions=rows 
1375  if (fLinks) nrefs=fLinks->GetIndices(obj,ks,j);
1376  return nrefs;
1377 }
1378 ///////////////////////////////////////////////////////////////////////////
1379 Int_t AliSignal::GetIndices(TObject* obj,TString name,TArrayI& ks) const
1380 {
1381 // Provide the position indices of all the storage locations of the
1382 // specified object in the name-specified slot of this AliSignal.
1383 // The position indices are returned in the TArrayI array.
1384 // The integer return argument represents the number of storage locations which
1385 // were encountered for the specified object in the j-th slot.
1386 //
1387 // If obj=0 no object selection is performed and all position indices
1388 // of the stored references for all objects of the j-th slot are returned.
1389 //
1390 // This procedure involves a slot-index search based on the specified name
1391 // at each invokation. This may become slow in case many slots have been
1392 // defined and/or when this procedure is invoked many times.
1393 // In such cases it is preferable to use indexed addressing in the user code
1394 // either directly or via a few invokations of GetSlotIndex().
1395
1396  Int_t j=GetSlotIndex(name);
1397  Int_t n=0;
1398  if (j>0) n=GetIndices(obj,j,ks);
1399  return n;
1400 }
1401 ///////////////////////////////////////////////////////////////////////////
1402 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,Int_t k) const
1403 {
1404 // Provide the slot indices of all the storage locations of the
1405 // specified object for the k-th position in this AliSignal.
1406 // The slot indices are returned in the TArrayI array.
1407 // The integer return argument represents the number of storage locations which
1408 // were encountered for the specified object in the k-th position.
1409 //
1410 // If obj=0 no object selection is performed and all slot indices
1411 // of the stored references for all objects in the k-th position are returned.
1412 //
1413 // If k=0 all positions will be scanned and all slot indices matching the
1414 // object selection are returned.
1415 // Note that in this case multiple appearances of the same slot index
1416 // will only be recorded once in the returned TArrayI array.
1417 //
1418 // Notes :
1419 // -------
1420 // As usual the convention is that slot and position numbering starts at 1.
1421 // 
1422 // This memberfunction always resets the TArrayI array at the start.
1423 //
1424 // This memberfunction can only be used to obtain the slot indices
1425 // of the object as stored via the SetLink() or AddLink() memberfunction.
1426 // This means that in case the user has entered a TObjArray as object
1427 // (to increase the dimension of the resulting structure), the slot
1428 // indices of that TObjArray are obtained and NOT the indices of the
1429 // actual objects contained in that TObjArray structure.
1430 //
1431  Int_t nrefs=0;
1432  js.Reset();
1433  // Note : In the internal storage matrix slots=columns positions=rows 
1434  if (fLinks) nrefs=fLinks->GetIndices(obj,k,js);
1435  return nrefs;
1436 }
1437 ///////////////////////////////////////////////////////////////////////////
1438 void AliSignal::SetSwapMode(Int_t swap)
1439 {
1440 // Set swapmode flag for the internal link storage.
1441 // In case for the stored links the maximum slot number differs considerably
1442 // from the maximum position number, it might be more efficient
1443 // (w.r.t. memory usage and/or output file size) to internally store the
1444 // link reference matrix with the rows and colums swapped.
1445 // This swapping is only related with the internal storage and as such
1446 // is completely hidden for the user.
1447 // At invokation of this memberfunction the default argument is swap=1.
1448 //
1449 // Note : The swap mode can only be set as long as no links are
1450 //        stored in the AliSignal (i.e. a new instance of AliSignal
1451 //        or after invokation of the Reset() or ResetLinks() function).
1452  
1453  if (!fLinks) fLinks=new AliObjMatrix();
1454  fLinks->SetSwapMode(swap);
1455 }
1456 ///////////////////////////////////////////////////////////////////////////
1457 Int_t AliSignal::GetSwapMode() const
1458 {
1459 // Provide swapmode flag of the link storage.
1460  Int_t swap=0; 
1461  if (fLinks) swap=fLinks->GetSwapMode();
1462  return swap;
1463 }
1464 ///////////////////////////////////////////////////////////////////////////
1465 void AliSignal::SetDevice(TObject* dev)
1466 {
1467 // Store the pointer to the device which owns this AliSignal object.
1468 // This memberfunction is meant for internal use in AliDevice.
1469  fDevice=dev;
1470 }
1471 ///////////////////////////////////////////////////////////////////////////
1472 AliDevice* AliSignal::GetDevice() const
1473 {
1474 // Provide the pointer to the device which owns this AliSignal object.
1475  return (AliDevice*)fDevice;
1476 }
1477 ///////////////////////////////////////////////////////////////////////////
1478 TObject* AliSignal::Clone(const char* name) const
1479 {
1480 // Make a deep copy of the current object and provide the pointer to the copy.
1481 // This memberfunction enables automatic creation of new objects of the
1482 // correct type depending on the object type, a feature which may be very useful
1483 // for containers when adding objects in case the container owns the objects.
1484 // This feature allows e.g. AliTrack to store either AliSignal objects or
1485 // objects derived from AliSignal via the AddSignal memberfunction, provided
1486 // these derived classes also have a proper Clone memberfunction. 
1487
1488  AliSignal* sig=new AliSignal(*this);
1489  if (name)
1490  {
1491   if (strlen(name)) sig->SetName(name);
1492  }
1493  return sig;
1494 }
1495 ///////////////////////////////////////////////////////////////////////////