1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Generic handling of (extrapolated) detector signals.
24 // Signal positions (r) and reference frames (f) are specified via
25 // SetPosition(r,f) under the following conventions :
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)
31 // The same holds for SetPositionErrors().
33 // All angles are in radians.
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;
46 // s.SetPosition(pos,"car");
47 // s.SetPositionErrors(err,"car");
48 // s.SetSignal(signal);
49 // s.SetSignalError(error);
50 // s.SetOffset(offset);
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();
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
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
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
82 // q.SetSlotName("dE/dx");
83 // q.SetSignal(signal,3);
84 // q.SetSignalError(error,3);
85 // q.SetOffset(offset,3);
88 // Float_t dedx=q.GetSignal("dE/dx");
90 //--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
91 //- Modified: NvE $Date$ UU-SAP Utrecht
92 ///////////////////////////////////////////////////////////////////////////
94 #include "AliSignal.h"
96 #include "Riostream.h"
98 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
100 AliSignal::AliSignal() : TNamed(),AliPosition(),AliAttrib()
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.
112 ///////////////////////////////////////////////////////////////////////////
113 AliSignal::~AliSignal()
115 // Destructor to delete dynamically allocated memory
137 ///////////////////////////////////////////////////////////////////////////
138 AliSignal::AliSignal(const AliSignal& s) : TNamed(s),AliPosition(s),AliAttrib(s)
146 // Don't copy the owning device pointer for the copy
149 Int_t n=s.GetNvalues();
151 for (Int_t i=1; i<=n; i++)
158 for (Int_t j=1; j<=n; j++)
160 val=s.GetSignalError(j);
161 SetSignalError(val,j);
165 for (Int_t k=1; k<=n; k++)
167 TH1F* hist=s.GetWaveform(k);
168 if (hist) SetWaveform(hist,k);
174 n=s.GetIndices(dum,slotarr,posarr);
176 for (Int_t idx=0; idx<n; idx++)
178 slot=slotarr.At(idx);
180 TObject* obj=s.GetLink(slot,pos);
181 if (obj) SetLink(obj,slot,pos);
184 ///////////////////////////////////////////////////////////////////////////
185 void AliSignal::Reset(Int_t mode)
187 // Reset all signal and position values and errors to 0.
189 // mode = 0 Reset position and all signal values and their errors to 0.
190 // The waveform histograms are reset, but the calibration
191 // constants (i.e. gains and offsets) are kept.
192 // 1 Reset position and delete the signal and error storage arrays.
193 // Also the waveform histograms, gains and offset arrays are deleted.
195 // The default when invoking Reset() corresponds to mode=0.
197 // Note : In all cases the storage of the various links will be reset.
198 // The UniqueID, name and title will NOT be reset.
199 // In case the user wants to reset these attributes, this has to
200 // be done explicitly via the SET facilities.
202 // The usage of mode=0 allows to re-use the allocated memory for new
203 // signal (and error) values. This behaviour is preferable (i.e. faster)
204 // in case the various signals always contain the same number of values
205 // and have the same calibration constants.
206 // The usage of mode=1 is slower, but allows a more efficient memory
207 // occupation (and smaller output file size) in case the different
208 // signals have a variable number of values.
210 // For more specific actions see ResetPosition(), ResetSignals(),
211 // DeleteSignals(), ResetGain(), ResetOffset(), ResetLink(), ResetWaveform(),
212 // DeleteWaveform() and DeleteCalibrations().
215 if (mode<0 || mode>1)
217 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
218 cout << " Default mode=0 will be used." << endl;
230 DeleteCalibrations();
233 if (fLinks) fLinks->Reset();
236 ///////////////////////////////////////////////////////////////////////////
237 void AliSignal::ResetSignals(Int_t mode)
239 // Reset various signal data according to user selection.
241 // mode = 0 Reset all signal values and their errors to 0.
242 // 1 Reset only signal values
243 // 2 Reset only signal errors
245 // The default when invoking ResetSignals() corresponds to mode=0.
247 // Irrespective of the mode, the waveform histograms are reset.
249 if (mode<0 || mode>2)
251 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
252 cout << " Default mode=0 will be used." << endl;
256 if (fSignals && (mode==0 || mode==1))
258 for (Int_t i=0; i<fSignals->GetSize(); i++)
260 fSignals->AddAt(0,i);
264 if (fDsignals && (mode==0 || mode==2))
266 for (Int_t j=0; j<fDsignals->GetSize(); j++)
268 fDsignals->AddAt(0,j);
274 ///////////////////////////////////////////////////////////////////////////
275 void AliSignal::DeleteSignals(Int_t mode)
277 // Delete storage arrays of various signal data according to user selection.
279 // mode = 0 Delete arrays of both signal values and their errors.
280 // 1 Delete only signal values array
281 // 2 Delete only signal errors array
283 // The default when invoking DeleteSignals() corresponds to mode=0.
285 // Irrespective of the mode, the waveform histograms are deleted.
287 if (mode<0 || mode>2)
289 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
290 cout << " Default mode=0 will be used." << endl;
294 if (fSignals && (mode==0 || mode==1))
300 if (fDsignals && (mode==0 || mode==2))
308 ///////////////////////////////////////////////////////////////////////////
309 void AliSignal::SetSignal(Double_t sig,Int_t j)
311 // Store signal value for the j-th (default j=1) slot.
312 // Note : The first signal slot is at j=1.
313 // In case the value of the index j exceeds the maximum number of reserved
314 // slots for signal values, the number of reserved slots for the
315 // signal values is increased automatically.
319 fSignals=new TArrayF(j);
323 Int_t size=fSignals->GetSize();
330 fSignals->AddAt(float(sig),j-1);
332 ///////////////////////////////////////////////////////////////////////////
333 void AliSignal::SetSignal(Double_t sig,TString name)
335 // Store signal value for the name-specified slot.
337 // This procedure involves a slot-index search based on the specified name
338 // at each invokation. This may become slow in case many slots have been
339 // defined and/or when this procedure is invoked many times.
340 // In such cases it is preferable to use indexed addressing in the user code
341 // either directly or via a few invokations of GetSlotIndex().
343 Int_t j=GetSlotIndex(name);
344 if (j>0) SetSignal(sig,j);
346 ///////////////////////////////////////////////////////////////////////////
347 void AliSignal::AddSignal(Double_t sig,Int_t j)
349 // Add value to the signal of the j-th (default j=1) slot.
350 // Note : The first signal slot is at j=1.
351 // In case the value of the index j exceeds the maximum number of reserved
352 // slots for signal values, the number of reserved slots for the
353 // signal values is increased automatically.
357 fSignals=new TArrayF(j);
361 Int_t size=fSignals->GetSize();
368 Float_t sum=(fSignals->At(j-1))+sig;
369 fSignals->AddAt(sum,j-1);
371 ///////////////////////////////////////////////////////////////////////////
372 void AliSignal::AddSignal(Double_t sig,TString name)
374 // Add value to the signal of the name-specified slot.
376 // This procedure involves a slot-index search based on the specified name
377 // at each invokation. This may become slow in case many slots have been
378 // defined and/or when this procedure is invoked many times.
379 // In such cases it is preferable to use indexed addressing in the user code
380 // either directly or via a few invokations of GetSlotIndex().
382 Int_t j=GetSlotIndex(name);
383 if (j>0) AddSignal(sig,j);
385 ///////////////////////////////////////////////////////////////////////////
386 Float_t AliSignal::GetSignal(Int_t j,Int_t mode) const
388 // Provide signal value of the j-th (default j=1) slot.
389 // Note : The first signal slot is at j=1.
390 // In case no signal is present or the argument j is invalid, 0 is returned.
391 // The parameter "mode" allows for automatic gain etc... correction of the signal.
393 // mode = 0 : Just the j-th signal is returned.
394 // 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
395 // In case the gain value was not set, gain=1 will be assumed.
396 // In case the gain value was 0, a signal value of 0 is returned.
397 // In case the offset value was not set, offset=0 will be assumed.
398 // In case the j-th slot was marked dead, 0 is returned.
400 // The corrected signal (sigc) is determined as follows :
402 // sigc=(signal/gain)-offset
404 // The default is mode=0.
411 if (j>0 && j<=(fSignals->GetSize()))
413 sig=fSignals->At(j-1);
415 if (mode==0) return sig;
417 // Correct the signal for the gain, offset, dead flag etc...
418 if (GetDeadValue(j)) return 0;
420 if (GetGainFlag(j)) gain=GetGain(j);
421 if (GetOffsetFlag(j)) offset=GetOffset(j);
425 sig=(sig/gain)-offset;
434 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
439 ///////////////////////////////////////////////////////////////////////////
440 Float_t AliSignal::GetSignal(TString name,Int_t mode) const
442 // Provide signal value of the name-specified slot.
443 // In case no signal is present, 0 is returned.
444 // The parameter "mode" allows for automatic gain etc... correction of the signal.
446 // mode = 0 : Just the j-th signal is returned.
447 // 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
448 // In case the gain value was not set, gain=1 will be assumed.
449 // In case the gain value was 0, a signal value of 0 is returned.
450 // In case the offset value was not set, offset=0 will be assumed.
451 // In case the j-th slot was marked dead, 0 is returned.
453 // The corrected signal (sigc) is determined as follows :
455 // sigc=(signal/gain)-offset
457 // The default is mode=0.
459 // This procedure involves a slot-index search based on the specified name
460 // at each invokation. This may become slow in case many slots have been
461 // defined and/or when this procedure is invoked many times.
462 // In such cases it is preferable to use indexed addressing in the user code
463 // either directly or via a few invokations of GetSlotIndex().
465 Int_t j=GetSlotIndex(name);
467 if (j>0) val=GetSignal(j,mode);
470 ///////////////////////////////////////////////////////////////////////////
471 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
473 // Store error on the signal for the j-th (default j=1) slot.
474 // Note : The first signal slot is at j=1.
475 // In case the value of the index j exceeds the maximum number of reserved
476 // slots for signal error values, the number of reserved slots for the
477 // signal errors is increased automatically.
481 fDsignals=new TArrayF(j);
485 Int_t size=fDsignals->GetSize();
492 fDsignals->AddAt(float(dsig),j-1);
494 ///////////////////////////////////////////////////////////////////////////
495 void AliSignal::SetSignalError(Double_t dsig,TString name)
497 // Store error on the signal for the name-specified slot.
499 // This procedure involves a slot-index search based on the specified name
500 // at each invokation. This may become slow in case many slots have been
501 // defined and/or when this procedure is invoked many times.
502 // In such cases it is preferable to use indexed addressing in the user code
503 // either directly or via a few invokations of GetSlotIndex().
505 Int_t j=GetSlotIndex(name);
506 if (j>0) SetSignalError(dsig,j);
508 ///////////////////////////////////////////////////////////////////////////
509 Float_t AliSignal::GetSignalError(Int_t j) const
511 // Provide error on the signal of the j-th (default j=1) slot.
512 // Note : The first signal slot is at j=1.
513 // In case no signal is present or the argument j is invalid, 0 is returned.
517 if (j>0 && j<=(fDsignals->GetSize()))
519 err=fDsignals->At(j-1);
523 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
528 ///////////////////////////////////////////////////////////////////////////
529 Float_t AliSignal::GetSignalError(TString name) const
531 // Provide error on the signal of the name-specified slot.
533 // This procedure involves a slot-index search based on the specified name
534 // at each invokation. This may become slow in case many slots have been
535 // defined and/or when this procedure is invoked many times.
536 // In such cases it is preferable to use indexed addressing in the user code
537 // either directly or via a few invokations of GetSlotIndex().
539 Int_t j=GetSlotIndex(name);
541 if (j>0) val=GetSignalError(j);
544 ///////////////////////////////////////////////////////////////////////////
545 void AliSignal::Data(TString f) const
547 // Provide all signal information within the coordinate frame f.
549 const char* name=GetName();
550 const char* title=GetTitle();
552 cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
553 if (strlen(name)) cout << " Name : " << name;
554 if (strlen(title)) cout << " Title : " << title;
560 const char* devname=fDevice->GetName();
561 const char* devtitle=fDevice->GetTitle();
562 cout << " Owned by device : " << fDevice->ClassName();
563 if (strlen(devname)) cout << " Name : " << devname;
564 if (strlen(devtitle)) cout << " Title : " << devtitle;
568 // Provide an overview of the stored waveforms
571 // Provide an overview of all the data and attribute slots
574 ///////////////////////////////////////////////////////////////////////////
575 void AliSignal::List(Int_t j) const
577 // Provide signal information for the j-th slot.
578 // The first slot is at j=1.
579 // In case j=0 (default) the data of all slots will be listed.
580 // In case j=-1 the data of all slots will be listed, but the header
581 // information will be suppressed.
585 cout << " *AliSignal::List* Invalid argument j = " << j << endl;
591 const char* name=GetName();
592 const char* title=GetTitle();
594 cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
595 if (strlen(name)) cout << " Name : " << name;
596 if (strlen(title)) cout << " Title : " << title;
600 const char* devname=fDevice->GetName();
601 const char* devtitle=fDevice->GetTitle();
602 cout << " Owned by device : " << fDevice->ClassName();
603 if (strlen(devname)) cout << " Name : " << devname;
604 if (strlen(devtitle)) cout << " Title : " << devtitle;
609 Int_t nvalues=GetNvalues();
610 Int_t nerrors=GetNerrors();
612 if (fLinks) nlinkslots=fLinks->GetMaxColumn();
614 if (nerrors>n) n=nerrors;
615 if (nlinkslots>n) n=nlinkslots;
624 for (Int_t i=1; i<=n; i++)
626 cout << " Slot : " << i;
627 if (i<=nvalues) cout << " Signal value : " << GetSignal(i);
628 if (i<=nerrors) cout << " error : " << GetSignalError(i);
632 nrefs=GetIndices(obj,i,posarr);
633 for (Int_t k=0; k<nrefs; k++)
639 cout << " Link at position " << pos << " to : " << obj->ClassName();
640 if (obj->InheritsFrom("TNamed"))
642 const char* lname=obj->GetName();
643 const char* ltitle=obj->GetTitle();
644 if (strlen(lname)) cout << " Name : " << lname;
645 if (strlen(ltitle)) cout << " Title : " << ltitle;
656 cout << " Slot : " << j;
657 if (j<=nvalues) cout << " Signal value : " << GetSignal(j);
658 if (j<=nerrors) cout << " error : " << GetSignalError(j);
662 nrefs=GetIndices(obj,j,posarr);
663 for (Int_t kj=0; kj<nrefs; kj++)
669 cout << " Link at position " << pos << " to : " << obj->ClassName();
670 if (obj->InheritsFrom("TNamed"))
672 const char* lnamej=obj->GetName();
673 const char* ltitlej=obj->GetTitle();
674 if (strlen(lnamej)) cout << " Name : " << lnamej;
675 if (strlen(ltitlej)) cout << " Title : " << ltitlej;
683 ///////////////////////////////////////////////////////////////////////////
684 void AliSignal::List(TString name) const
686 // Provide signal information for the name-specified slot.
688 // This procedure involves a slot-index search based on the specified name
689 // at each invokation. This may become slow in case many slots have been
690 // defined and/or when this procedure is invoked many times.
691 // In such cases it is preferable to use indexed addressing in the user code
692 // either directly or via a few invokations of GetSlotIndex().
694 Int_t j=GetSlotIndex(name);
697 ///////////////////////////////////////////////////////////////////////////
698 void AliSignal::ListWaveform(Int_t j) const
700 // Provide information for the j-th waveform.
701 // The first waveform is at j=1.
702 // In case j=0 (default) the info of all waveforms will be listed.
703 // In case j=-1 the info of all waveforms will be listed, but the header
704 // information will be suppressed.
708 cout << " *AliSignal::ListWaveform* Invalid argument j = " << j << endl;
714 const char* name=GetName();
715 const char* title=GetTitle();
717 cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
718 if (strlen(name)) cout << " Name : " << name;
719 if (strlen(title)) cout << " Title : " << title;
723 const char* devname=fDevice->GetName();
724 const char* devtitle=fDevice->GetTitle();
725 cout << " Owned by device : " << fDevice->ClassName();
726 if (strlen(devname)) cout << " Name : " << devname;
727 if (strlen(devtitle)) cout << " Title : " << devtitle;
732 Int_t n=GetNwaveforms();
737 for (Int_t i=1; i<=n; i++)
742 const char* wfname=obj->GetName();
743 const char* wftitle=obj->GetTitle();
744 cout << " Waveform " << i << " : " << obj->ClassName();
745 if (strlen(wfname)) cout << " Name : " << wfname;
746 if (strlen(wftitle)) cout << " Title : " << wftitle;
758 const char* wfnamej=obj->GetName();
759 const char* wftitlej=obj->GetTitle();
760 cout << " Waveform " << j << " : " << obj->ClassName();
761 if (strlen(wfnamej)) cout << " Name : " << wfnamej;
762 if (strlen(wftitlej)) cout << " Title : " << wftitlej;
768 ///////////////////////////////////////////////////////////////////////////
769 Int_t AliSignal::GetNvalues() const
771 // Provide the number of values for this signal.
773 if (fSignals) n=fSignals->GetSize();
776 ///////////////////////////////////////////////////////////////////////////
777 Int_t AliSignal::GetNerrors() const
779 // Provide the number specified errors on the values for this signal.
781 if (fDsignals) n=fDsignals->GetSize();
784 ///////////////////////////////////////////////////////////////////////////
785 Int_t AliSignal::GetNwaveforms() const
787 // Provide the number specified waveforms for this signal.
789 if (fWaveforms) n=fWaveforms->GetSize();
792 ///////////////////////////////////////////////////////////////////////////
793 TH1F* AliSignal::GetWaveform(Int_t j) const
795 // Provide pointer to the j-th waveform histogram.
797 if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
800 ///////////////////////////////////////////////////////////////////////////
801 TH1F* AliSignal::GetWaveform(TString name) const
803 // Provide pointer to the waveform histogram with the specified name.
804 // In case no match is found, zero is returned.
805 Int_t n=GetNwaveforms();
807 for (Int_t i=1; i<=n; i++)
809 TH1F* waveform=GetWaveform(i);
812 str=waveform->GetName();
813 if (str == name) return waveform;
816 return 0; // No match found
818 ///////////////////////////////////////////////////////////////////////////
819 Int_t AliSignal::GetWaveformIndex(TString name) const
821 // Provide index to the waveform histogram with the specified name.
822 // In case no match is found, zero is returned.
823 Int_t n=GetNwaveforms();
825 for (Int_t i=1; i<=n; i++)
827 TH1F* waveform=GetWaveform(i);
830 str=waveform->GetName();
831 if (str == name) return i;
834 return 0; // No match found
836 ///////////////////////////////////////////////////////////////////////////
837 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
839 // Set the 1D waveform histogram for the j-th waveform.
842 // The first waveform position at j=1.
843 // j=1 is the default value.
845 // In case the value of the index j exceeds the maximum number of reserved
846 // positions for the waveforms, the number of reserved positions for the waveforms
847 // is increased automatically.
849 // In case the histo pointer argument has the same value as the current waveform
850 // histogram pointer value, no action is taken since the user has already
851 // modified the actual histogram.
853 // In case the histo pointer argument is zero, the current waveform histogram
854 // is deleted and the pointer set to zero.
856 // In all other cases the current waveform histogram is deleted and a new
857 // copy of the input histogram is created which becomes the current waveform
864 fWaveforms=new TObjArray(j);
865 fWaveforms->SetOwner();
868 if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
870 TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
871 if (waveform != hcur)
875 fWaveforms->Remove(hcur);
881 hcur=new TH1F(*waveform);
882 fWaveforms->AddAt(hcur,j-1);
886 ///////////////////////////////////////////////////////////////////////////
887 void AliSignal::ResetWaveform(Int_t j)
889 // Reset the histogram of the j-th (default j=1) waveform.
890 // This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
891 // To actually delete the histograms from memory, use DeleteWaveform().
892 // Notes : The first position is at j=1.
893 // j=0 ==> All waveforms will be reset.
895 if (!fWaveforms) return;
897 Int_t size=fWaveforms->GetSize();
899 if ((j>=0) && (j<=size))
903 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
904 if (hwave) hwave->Reset();
908 for (Int_t i=0; i<size; i++)
910 TH1F* hwave=(TH1F*)fWaveforms->At(i);
911 if (hwave) hwave->Reset();
917 cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
921 ///////////////////////////////////////////////////////////////////////////
922 void AliSignal::ResetWaveform(TString name)
924 // Reset the waveform with the specified name.
925 Int_t j=GetWaveformIndex(name);
926 if (j>0) ResetWaveform(j);
928 ///////////////////////////////////////////////////////////////////////////
929 void AliSignal::DeleteWaveform(Int_t j)
931 // Delete the histogram of the j-th (default j=1) waveform.
932 // Notes : The first position is at j=1.
933 // j=0 ==> All waveforms will be deleted.
935 if (!fWaveforms) return;
937 Int_t size=fWaveforms->GetSize();
939 if ((j>=0) && (j<=size))
943 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
946 fWaveforms->Remove(hwave);
958 cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
962 ///////////////////////////////////////////////////////////////////////////
963 void AliSignal::DeleteWaveform(TString name)
965 // Delete the waveform with the specified name.
966 Int_t j=GetWaveformIndex(name);
967 if (j>0) DeleteWaveform(j);
969 ///////////////////////////////////////////////////////////////////////////
970 Int_t AliSignal::GetNlinks(TObject* obj,Int_t j) const
972 // Provide the number of links to the specified object for the j-th slot.
973 // If j=0 (default) all slots will be scanned for the specified object.
974 // If obj=0 (default) all encountered objects for the specified slot will be counted.
975 // So, invokation of the default GetNlinks() will return the total number of
976 // all references to all sorts of stored objects.
979 cout << " *AliSignal::GetNlinks* Index j = " << j << " invalid." << endl;
986 if (fLinks) n=fLinks->GetNrefs(obj);
991 n=GetIndices(obj,j,posarr);
995 ///////////////////////////////////////////////////////////////////////////
996 Int_t AliSignal::GetNlinks(TObject* obj,TString name) const
998 // Provide the number of links to the specified object for the name-spec. slot.
999 // If obj=0 all encountered objects for the specified slot will be counted.
1001 // This procedure involves a slot-index search based on the specified name
1002 // at each invokation. This may become slow in case many slots have been
1003 // defined and/or when this procedure is invoked many times.
1004 // In such cases it is preferable to use indexed addressing in the user code
1005 // either directly or via a few invokations of GetSlotIndex().
1007 Int_t j=GetSlotIndex(name);
1009 if (j>0) n=GetNlinks(obj,j);
1012 ///////////////////////////////////////////////////////////////////////////
1013 TObject* AliSignal::GetLink(Int_t j,Int_t k) const
1015 // Provide pointer of the object linked to the j-th slot at position k.
1018 // Note : In the internal storage matrix slots=columns positions=rows
1019 if (fLinks) obj=fLinks->GetObject(k,j);
1022 ///////////////////////////////////////////////////////////////////////////
1023 TObject* AliSignal::GetLink(TString name,Int_t k) const
1025 // Provide pointer of the object linked to the name-spec. slot at position k.
1027 // This procedure involves a slot-index search based on the specified name
1028 // at each invokation. This may become slow in case many slots have been
1029 // defined and/or when this procedure is invoked many times.
1030 // In such cases it is preferable to use indexed addressing in the user code
1031 // either directly or via a few invokations of GetSlotIndex().
1033 Int_t j=GetSlotIndex(name);
1035 if (j>0) obj=GetLink(j,k);
1038 ///////////////////////////////////////////////////////////////////////////
1039 void AliSignal::SetLink(TObject* obj,Int_t j,Int_t k)
1041 // Introduce a link (=pointer) to an object for the j-th slot at position k.
1042 // Only the pointer values are stored for (backward) reference, meaning
1043 // that the objects of which the pointers are stored are NOT owned
1044 // by the AliSignal object.
1047 // The first slot is at j=1 and the first position is at k=1.
1048 // j=1 and k=1 are the default values.
1050 // If needed, the storage area for the links is increased automatically.
1052 // In case the pointer argument is zero, indeed a value of zero will be
1053 // stored at the specified position (k) for the specified slot (j).
1055 // In principle any object derived from TObject can be referred to by this
1057 // However, this "linking back" facility was introduced to enable AliSignal slots
1058 // to refer directly to the various AliTracks to which the AliSignal object itself
1059 // is related (see AliTrack::AddSignal).
1060 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1061 // object, the current signal is automatically related to this AliTrack
1062 // (or derived) object.
1064 // Please also have a look at the docs of the memberfunction ResetLink()
1065 // to prevent the situation of stored pointers to non-existent object.
1067 if (!fLinks && obj) fLinks=new AliObjMatrix();
1069 if (!fLinks) return;
1071 // Note : In the internal storage matrix slots=columns positions=rows
1072 fLinks->EnterObject(k,j,obj);
1075 if (obj->InheritsFrom("AliTrack"))
1077 AliTrack* t=(AliTrack*)obj;
1078 t->AddSignal(*this);
1082 ///////////////////////////////////////////////////////////////////////////
1083 void AliSignal::SetLink(TObject* obj,TString name,Int_t k)
1085 // Introduce a link (=pointer) to an object for the name-spec. slot at position k.
1086 // Only the pointer values are stored for (backward) reference, meaning
1087 // that the objects of which the pointers are stored are NOT owned
1088 // by the AliSignal object.
1090 // This procedure involves a slot-index search based on the specified name
1091 // at each invokation. This may become slow in case many slots have been
1092 // defined and/or when this procedure is invoked many times.
1093 // In such cases it is preferable to use indexed addressing in the user code
1094 // either directly or via a few invokations of GetSlotIndex().
1096 Int_t j=GetSlotIndex(name);
1097 if (j>0) SetLink(obj,j,k);
1099 ///////////////////////////////////////////////////////////////////////////
1100 void AliSignal::AddLink(TObject* obj,Int_t j)
1102 // Introduce a link (=pointer) to an object for the j-th slot at the first
1104 // Only the pointer values are stored for (backward) reference, meaning
1105 // that the objects of which the pointers are stored are NOT owned
1106 // by the AliSignal object.
1109 // The first slot is at j=1 and the first position is at k=1.
1110 // j=1 is the default value.
1112 // If needed, the storage area for the links is increased automatically.
1114 // In case the pointer argument is zero, no link will be added.
1116 // In principle any object derived from TObject can be referred to by this
1118 // However, this "linking back" facility was introduced to enable AliSignal slots
1119 // to refer directly to the various AliTracks to which the AliSignal object itself
1120 // is related (see AliTrack::AddSignal).
1121 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1122 // object, the current signal is automatically related to this AliTrack
1123 // (or derived) object.
1125 // Please also have a look at the docs of the memberfunction ResetLink()
1126 // to prevent the situation of stored pointers to non-existent object.
1128 if (!obj || j<=0) return;
1130 if (!fLinks) fLinks=new AliObjMatrix();
1133 Int_t n=GetNlinks(dum,j);
1135 for (Int_t k=1; k<=n; k++)
1144 ///////////////////////////////////////////////////////////////////////////
1145 void AliSignal::AddLink(TObject* obj,TString name)
1147 // Introduce a link (=pointer) to an object for the name-spec slot at the first
1149 // Only the pointer values are stored for (backward) reference, meaning
1150 // that the objects of which the pointers are stored are NOT owned
1151 // by the AliSignal object.
1153 // This procedure involves a slot-index search based on the specified name
1154 // at each invokation. This may become slow in case many slots have been
1155 // defined and/or when this procedure is invoked many times.
1156 // In such cases it is preferable to use indexed addressing in the user code
1157 // either directly or via a few invokations of GetSlotIndex().
1159 Int_t j=GetSlotIndex(name);
1160 if (j>0) AddLink(obj,j);
1162 ///////////////////////////////////////////////////////////////////////////
1163 void AliSignal::ResetLink(Int_t j,Int_t k)
1165 // Reset the link of the j-th slot at position k.
1168 // The first slot is at j=1 and the first position is at k=1.
1169 // j=1 and k=1 are the default values.
1171 // This memberfunction is intended to reset only 1 specified link location.
1172 // For extended functionality, please refer to the memberfuction ResetLinks().
1174 // In general the user should take care of properly clearing the corresponding
1175 // pointer here when the referred object is deleted.
1176 // However, this "linking back" facility was introduced to enable AliSignal slots
1177 // to refer directly to the various AliTracks to which the AliSignal object itself
1178 // is related (see AliTrack::AddSignal).
1179 // As such, the AliTrack destructor already takes care of clearing the corresponding
1180 // links from the various AliSignal slots for all the AliSignal objects that were
1181 // related to that AliTrack.
1182 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1183 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1184 // the AliSignal object when the corresponding AliTrack object is deleted.
1186 // Note : In the internal storage matrix slots=columns positions=rows
1187 if (fLinks) fLinks->RemoveObject(k,j);
1189 ///////////////////////////////////////////////////////////////////////////
1190 void AliSignal::ResetLink(TString name,Int_t k)
1192 // Reset the link of the name-specified slot at position k.
1194 // This memberfunction is intended to reset only 1 specified link location.
1195 // For extended functionality, please refer to the memberfuction ResetLinks().
1197 // This procedure involves a slot-index search based on the specified name
1198 // at each invokation. This may become slow in case many slots have been
1199 // defined and/or when this procedure is invoked many times.
1200 // In such cases it is preferable to use indexed addressing in the user code
1201 // either directly or via a few invokations of GetSlotIndex().
1203 Int_t j=GetSlotIndex(name);
1204 if (j>0) ResetLink(j,k);
1206 ///////////////////////////////////////////////////////////////////////////
1207 void AliSignal::ResetLinks(TObject* obj,Int_t j,Int_t k)
1209 // Reset single or multiple link(s) according to user specified selections.
1211 // A link is only reset if the stored reference matches the argument "obj".
1212 // In case obj=0 no check on the matching of the stored reference is performed
1213 // and the stored link is always reset in accordance with the other
1214 // selection criteria.
1216 // In case the slot argument "j" is specified, only the links from that
1217 // specified slot will be deleted.
1218 // In case j=0 (default) no checking on the slot index is performed.
1220 // In case the position argument "k" is specified, only the links from that
1221 // specified position will be deleted.
1222 // In case k=0 (default) no checking on the position index is performed.
1224 // So, invokation of ResetLinks(obj) will remove all references to the
1225 // object "obj" from the total AliSignal, whereas ResetLinks(obj,j)
1226 // will remove all references to the object "obj" only from slot "j".
1230 // The first slot is indicated as j=1, whereas the first position is at k=1.
1232 // Invokation of ResetLinks(0,row,col) is equivalent to invoking the
1233 // memberfunction ResetLink(row,col).
1234 // Invoking the latter directly is slightly faster.
1236 // Invokation of ResetLinks(0) will reset all stored references in this AliSignal.
1238 // In general the user should take care of properly clearing the corresponding
1239 // pointer here when the referred object is deleted.
1240 // However, this "linking back" facility was introduced to enable AliSignal slots
1241 // to refer directly to the various AliTracks to which the AliSignal object itself
1242 // is related (see AliTrack::AddSignal).
1243 // As such, the AliTrack destructor already takes care of clearing the corresponding
1244 // links from the various AliSignal slots for all the AliSignal objects that were
1245 // related to that AliTrack.
1246 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1247 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1248 // the AliSignal object when the corresponding AliTrack object is deleted.
1250 if (!fLinks) return;
1252 if (!obj && !j && !k)
1258 // Note : In the internal storage matrix slots=columns positions=rows
1259 fLinks->RemoveObjects(obj,k,j);
1262 ///////////////////////////////////////////////////////////////////////////
1263 void AliSignal::ResetLinks(TObject* obj,TString name,Int_t k)
1265 // Reset single or multiple link(s) according to user specified selections.
1267 // A link is only reset if the stored reference matches the argument "obj".
1268 // In case obj=0 no check on the matching of the stored reference is performed
1269 // and the stored link is always reset in accordance with the other
1270 // selection criteria.
1272 // In case the position argument "k" is specified, only the links from that
1273 // specified position will be deleted.
1274 // In case k=0 (default) no checking on the position index is performed.
1276 // This procedure involves a slot-index search based on the specified name
1277 // at each invokation. This may become slow in case many slots have been
1278 // defined and/or when this procedure is invoked many times.
1279 // In such cases it is preferable to use indexed addressing in the user code
1280 // either directly or via a few invokations of GetSlotIndex().
1282 Int_t j=GetSlotIndex(name);
1283 if (j>0) ResetLinks(obj,j,k);
1285 ///////////////////////////////////////////////////////////////////////////
1286 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,TArrayI& ks) const
1288 // Provide the slot and position indices of all the storage locations
1289 // of the specified object.
1290 // The slot (j) and pos. (k) indices are returned in the two separate TArrayI arrays
1291 // from which the (j,k) pairs can be obtained from the corresponding
1292 // array indices like (j,k)=(js.At(i),ks.At(i)).
1293 // The integer return argument represents the number of (j,k) pairs which
1294 // were encountered for the specified object.
1296 // If obj=0 no object selection is performed and all (j,k) indices
1297 // of the stored references for all objects are returned.
1301 // As usual the convention is that slot and position numbering starts at 1.
1303 // This memberfunction always resets the two TArrayI arrays at the start.
1305 // This memberfunction can only be used to obtain the (j,k) indices
1306 // of the object as stored via the SetLink() or AddLink() memberfunction.
1307 // This means that in case the user has entered a TObjArray as object
1308 // (to increase the dimension of the resulting structure), the (j,k)
1309 // indices of that TObjArray are obtained and NOT the indices of the
1310 // actual objects contained in that TObjArray structure.
1315 // Note : In the internal storage matrix slots=columns positions=rows
1316 if (fLinks) nrefs=fLinks->GetIndices(obj,ks,js);
1319 ///////////////////////////////////////////////////////////////////////////
1320 Int_t AliSignal::GetIndices(TObject* obj,Int_t j,TArrayI& ks) const
1322 // Provide the position indices of all the storage locations of the
1323 // specified object in the j-th slot of this AliSignal.
1324 // The position indices are returned in the TArrayI array.
1325 // The integer return argument represents the number of storage locations which
1326 // were encountered for the specified object in the j-th slot.
1328 // If obj=0 no object selection is performed and all position indices
1329 // of the stored references for all objects of the j-th slot are returned.
1331 // If j=0 all slots will be scanned and all position indices matching the
1332 // object selection are returned.
1333 // Note that in this case multiple appearances of the same position index
1334 // will only be recorded once in the returned TArrayI array.
1338 // As usual the convention is that slot and position numbering starts at 1.
1340 // This memberfunction always resets the TArrayI array at the start.
1342 // This memberfunction can only be used to obtain the position indices
1343 // of the object as stored via the SetLink() or AddLink() memberfunction.
1344 // This means that in case the user has entered a TObjArray as object
1345 // (to increase the dimension of the resulting structure), the position
1346 // indices of that TObjArray are obtained and NOT the indices of the
1347 // actual objects contained in that TObjArray structure.
1351 // Note : In the internal storage matrix slots=columns positions=rows
1352 if (fLinks) nrefs=fLinks->GetIndices(obj,ks,j);
1355 ///////////////////////////////////////////////////////////////////////////
1356 Int_t AliSignal::GetIndices(TObject* obj,TString name,TArrayI& ks) const
1358 // Provide the position indices of all the storage locations of the
1359 // specified object in the name-specified slot of this AliSignal.
1360 // The position indices are returned in the TArrayI array.
1361 // The integer return argument represents the number of storage locations which
1362 // were encountered for the specified object in the j-th slot.
1364 // If obj=0 no object selection is performed and all position indices
1365 // of the stored references for all objects of the j-th slot are returned.
1367 // This procedure involves a slot-index search based on the specified name
1368 // at each invokation. This may become slow in case many slots have been
1369 // defined and/or when this procedure is invoked many times.
1370 // In such cases it is preferable to use indexed addressing in the user code
1371 // either directly or via a few invokations of GetSlotIndex().
1373 Int_t j=GetSlotIndex(name);
1375 if (j>0) n=GetIndices(obj,j,ks);
1378 ///////////////////////////////////////////////////////////////////////////
1379 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,Int_t k) const
1381 // Provide the slot indices of all the storage locations of the
1382 // specified object for the k-th position in this AliSignal.
1383 // The slot 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 k-th position.
1387 // If obj=0 no object selection is performed and all slot indices
1388 // of the stored references for all objects in the k-th position are returned.
1390 // If k=0 all positions will be scanned and all slot indices matching the
1391 // object selection are returned.
1392 // Note that in this case multiple appearances of the same slot index
1393 // will only be recorded once in the returned TArrayI array.
1397 // As usual the convention is that slot and position numbering starts at 1.
1399 // This memberfunction always resets the TArrayI array at the start.
1401 // This memberfunction can only be used to obtain the slot indices
1402 // of the object as stored via the SetLink() or AddLink() memberfunction.
1403 // This means that in case the user has entered a TObjArray as object
1404 // (to increase the dimension of the resulting structure), the slot
1405 // indices of that TObjArray are obtained and NOT the indices of the
1406 // actual objects contained in that TObjArray structure.
1410 // Note : In the internal storage matrix slots=columns positions=rows
1411 if (fLinks) nrefs=fLinks->GetIndices(obj,k,js);
1414 ///////////////////////////////////////////////////////////////////////////
1415 void AliSignal::SetSwapMode(Int_t swap)
1417 // Set swapmode flag for the internal link storage.
1418 // In case for the stored links the maximum slot number differs considerably
1419 // from the maximum position number, it might be more efficient
1420 // (w.r.t. memory usage and/or output file size) to internally store the
1421 // link reference matrix with the rows and colums swapped.
1422 // This swapping is only related with the internal storage and as such
1423 // is completely hidden for the user.
1424 // At invokation of this memberfunction the default argument is swap=1.
1426 // Note : The swap mode can only be set as long as no links are
1427 // stored in the AliSignal (i.e. a new instance of AliSignal
1428 // or after invokation of the Reset() or ResetLinks() function).
1430 if (!fLinks) fLinks=new AliObjMatrix();
1431 fLinks->SetSwapMode(swap);
1433 ///////////////////////////////////////////////////////////////////////////
1434 Int_t AliSignal::GetSwapMode() const
1436 // Provide swapmode flag of the link storage.
1438 if (fLinks) swap=fLinks->GetSwapMode();
1441 ///////////////////////////////////////////////////////////////////////////
1442 void AliSignal::SetDevice(TObject* dev)
1444 // Store the pointer to the device which owns this AliSignal object.
1445 // This memberfunction is meant for internal use in AliDevice.
1448 ///////////////////////////////////////////////////////////////////////////
1449 AliDevice* AliSignal::GetDevice() const
1451 // Provide the pointer to the device which owns this AliSignal object.
1452 return (AliDevice*)fDevice;
1454 ///////////////////////////////////////////////////////////////////////////
1455 TObject* AliSignal::Clone(const char* name) const
1457 // Make a deep copy of the current object and provide the pointer to the copy.
1458 // This memberfunction enables automatic creation of new objects of the
1459 // correct type depending on the object type, a feature which may be very useful
1460 // for containers when adding objects in case the container owns the objects.
1461 // This feature allows e.g. AliTrack to store either AliSignal objects or
1462 // objects derived from AliSignal via the AddSignal memberfunction, provided
1463 // these derived classes also have a proper Clone memberfunction.
1465 AliSignal* sig=new AliSignal(*this);
1468 if (strlen(name)) sig->SetName(name);
1472 ///////////////////////////////////////////////////////////////////////////