+ Int_t j=GetSlotIndex(name);
+ Int_t flag=0;
+ if (j>0) flag=GetSignalFlag(j);
+ return flag;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetErrorFlag(Int_t j) const
+{
+// Provide error value flag of the j-th (default j=1) slot.
+//
+// flag = 1 : Error value was set
+// 0 : Error value was not set
+//
+// Note : The first attribute slot is at j=1.
+// In case j is invalid, 0 is returned.
+
+ if (j<1)
+ {
+ cout << " *AliSignal::GetErrorFlag* Invalid argument j = " << j << endl;
+ return 0;
+ }
+ Int_t flag=0;
+ if (fSigflags)
+ {
+ if (j>0 && j<=(fSigflags->GetSize()))
+ {
+ Int_t word=fSigflags->At(j-1);
+ flag=word%10;
+ }
+ }
+ return flag;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetErrorFlag(TString name) const
+{
+// Provide error value flag of the name-specified slot.
+//
+// flag = 1 : Error value was set
+// 0 : Error value was not set
+//
+//
+// This procedure involves a slot-index search based on the specified name
+// at each invokation. This may become slow in case many slots have been
+// defined and/or when this procedure is invoked many times.
+// In such cases it is preferable to use indexed addressing in the user code
+// either directly or via a few invokations of GetSlotIndex().
+
+ Int_t j=GetSlotIndex(name);
+ Int_t flag=0;
+ if (j>0) flag=GetErrorFlag(j);
+ return flag;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetNslots() const
+{
+// Provide the number of existing slots.
+
+ Int_t n=AliAttrib::GetNslots();
+
+ if (!fSigflags) return n;
+
+ Int_t nflags=0;
+ for (Int_t i=0; i<fSigflags->GetSize(); i++)
+ {
+ if (fSigflags->At(i)) nflags=i+1;
+ }
+
+ if (n<nflags) n=nflags;
+
+ return n;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetNwaveforms() const
+{
+// Provide the number of specified waveforms for this signal.
+// Actually the return value is the highest index of the stored waveforms.
+// This allows an index dependent meaning of waveform info (e.g. waveforms
+// with various gain values).
+// So, when all waveforms are stored in consequetive positions (e.g. 1,2,3),
+// this memberfunction returns 3, being both the highest filled position
+// and the actual number of waveforms.
+// In case only waveforms are stored at positions 1,2,5,7 this memberfunction
+// returns a value 7 whereas only 4 actual waveforms are present.
+// This implies that when looping over the various waveform slots, one
+// always has to check whether the returned pointer value is non-zero
+// (which is a good practice anyhow).
+ Int_t n=-1;
+ if (fWaveforms) n=fWaveforms->GetLast();
+ return (n+1);
+}
+///////////////////////////////////////////////////////////////////////////
+TH1F* AliSignal::GetWaveform(Int_t j) const
+{
+// Provide pointer to the j-th waveform histogram.
+ TH1F* waveform=0;
+ if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
+ return waveform;
+}
+///////////////////////////////////////////////////////////////////////////
+TH1F* AliSignal::GetWaveform(TString name) const
+{
+// Provide pointer to the waveform histogram with the specified name.
+// In case no match is found, zero is returned.
+ Int_t n=GetNwaveforms();
+ TString str;
+ for (Int_t i=1; i<=n; i++)
+ {
+ TH1F* waveform=GetWaveform(i);
+ if (waveform)
+ {
+ str=waveform->GetName();
+ if (str == name) return waveform;
+ }
+ }
+ return 0; // No match found
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetWaveformIndex(TString name) const
+{
+// Provide index to the waveform histogram with the specified name.
+// In case no match is found, zero is returned.
+ Int_t n=GetNwaveforms();
+ TString str;
+ for (Int_t i=1; i<=n; i++)
+ {
+ TH1F* waveform=GetWaveform(i);
+ if (waveform)
+ {
+ str=waveform->GetName();
+ if (str == name) return i;
+ }
+ }
+ return 0; // No match found
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
+{
+// Set the 1D waveform histogram for the j-th waveform.
+//
+// Notes :
+// The first waveform position at j=1.
+// j=1 is the default value.
+//
+// In case the value of the index j exceeds the maximum number of reserved
+// positions for the waveforms, the number of reserved positions for the waveforms
+// is increased automatically.
+//
+// In case the histo pointer argument has the same value as the current waveform
+// histogram pointer value, no action is taken since the user has already
+// modified the actual histogram.
+//
+// In case the histo pointer argument is zero, the current waveform histogram
+// is deleted and the pointer set to zero.
+//
+// In all other cases the current waveform histogram is deleted and a new
+// copy of the input histogram is created which becomes the current waveform
+// histogram.
+
+ if (j<1) return;
+
+ if (!fWaveforms)
+ {
+ fWaveforms=new TObjArray(j);
+ fWaveforms->SetOwner();
+ }
+
+ if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
+
+ TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
+ if (waveform != hcur)
+ {
+ if (hcur)
+ {
+ fWaveforms->Remove(hcur);
+ delete hcur;
+ hcur=0;
+ }
+ if (waveform)
+ {
+ hcur=new TH1F(*waveform);
+ fWaveforms->AddAt(hcur,j-1);
+ }
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::ResetWaveform(Int_t j)
+{
+// Reset the histogram of the j-th (default j=1) waveform.
+// This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
+// To actually delete the histograms from memory, use DeleteWaveform().
+// Notes : The first position is at j=1.
+// j=0 ==> All waveforms will be reset.
+
+ if (!fWaveforms) return;
+
+ Int_t size=fWaveforms->GetSize();
+
+ if ((j>=0) && (j<=size))
+ {
+ if (j)
+ {
+ TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
+ if (hwave) hwave->Reset();
+ }
+ else
+ {
+ for (Int_t i=0; i<size; i++)
+ {
+ TH1F* hwave=(TH1F*)fWaveforms->At(i);
+ if (hwave) hwave->Reset();
+ }
+ }
+ }
+ else
+ {
+ cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
+ return;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::ResetWaveform(TString name)
+{
+// Reset the waveform with the specified name.
+ Int_t j=GetWaveformIndex(name);
+ if (j>0) ResetWaveform(j);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::DeleteWaveform(Int_t j)
+{
+// Delete the histogram of the j-th (default j=1) waveform.
+// Notes : The first position is at j=1.
+// j=0 ==> All waveforms will be deleted.
+
+ if (!fWaveforms) return;
+
+ Int_t size=fWaveforms->GetSize();
+
+ if ((j>=0) && (j<=size))
+ {
+ if (j)
+ {
+ TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
+ if (hwave)
+ {
+ fWaveforms->Remove(hwave);
+ delete hwave;
+ }
+ }
+ else
+ {
+ delete fWaveforms;
+ fWaveforms=0;
+ }
+ }
+ else
+ {
+ cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
+ return;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::DeleteWaveform(TString name)
+{
+// Delete the waveform with the specified name.
+ Int_t j=GetWaveformIndex(name);
+ if (j>0) DeleteWaveform(j);
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetNlinks(TObject* obj,Int_t j) const
+{
+// Provide the number of links to the specified object for the j-th slot.
+// If j=0 (default) all slots will be scanned for the specified object.
+// If obj=0 (default) all encountered objects for the specified slot will be counted.
+// So, invokation of the default GetNlinks() will return the total number of
+// all references to all sorts of stored objects.
+ if (j<0)
+ {
+ cout << " *AliSignal::GetNlinks* Index j = " << j << " invalid." << endl;
+ return 0;
+ }
+
+ if (!fLinks) return 0;
+
+ Int_t n=0;
+ if (!j)
+ {
+ n=fLinks->GetNrefs(obj);
+ }
+ else
+ {
+ TArrayI posarr;
+ n=GetIndices(obj,j,posarr);
+ }
+ return n;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetNlinks(TObject* obj,TString name) const
+{
+// Provide the number of links to the specified object for the name-spec. slot.
+// If obj=0 all encountered objects for the specified slot will be counted.
+//
+// This procedure involves a slot-index search based on the specified name
+// at each invokation. This may become slow in case many slots have been
+// defined and/or when this procedure is invoked many times.
+// In such cases it is preferable to use indexed addressing in the user code
+// either directly or via a few invokations of GetSlotIndex().
+
+ Int_t j=GetSlotIndex(name);
+ Int_t n=0;
+ if (j>0) n=GetNlinks(obj,j);
+ return n;
+}
+///////////////////////////////////////////////////////////////////////////
+TObject* AliSignal::GetLink(Int_t j,Int_t k) const
+{
+// Provide pointer of the object linked to the j-th slot at position k.
+
+ TObject* obj=0;
+ // Note : In the internal storage matrix slots=columns positions=rows
+ if (fLinks) obj=fLinks->GetObject(k,j);
+ return obj;
+}
+///////////////////////////////////////////////////////////////////////////
+TObject* AliSignal::GetLink(TString name,Int_t k) const
+{
+// Provide pointer of the object linked to the name-spec. slot at position k.
+//
+// This procedure involves a slot-index search based on the specified name
+// at each invokation. This may become slow in case many slots have been
+// defined and/or when this procedure is invoked many times.
+// In such cases it is preferable to use indexed addressing in the user code
+// either directly or via a few invokations of GetSlotIndex().
+
+ Int_t j=GetSlotIndex(name);
+ TObject* obj=0;
+ if (j>0) obj=GetLink(j,k);
+ return obj;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::SetLink(TObject* obj,Int_t j,Int_t k)
+{
+// Introduce a link (=pointer) to an object for the j-th slot at position k.
+// Only the pointer values are stored for (backward) reference, meaning
+// that the objects of which the pointers are stored are NOT owned
+// by the AliSignal object.
+//
+// Notes :
+// The first slot is at j=1 and the first position is at k=1.
+// j=1 and k=1 are the default values.
+//
+// If needed, the storage area for the links is increased automatically.
+//
+// In case the pointer argument is zero, indeed a value of zero will be
+// stored at the specified position (k) for the specified slot (j).
+//
+// In principle any object derived from TObject can be referred to by this
+// mechanism.
+// However, this "linking back" facility was introduced to enable AliSignal slots
+// to refer directly to the various AliTracks to which the AliSignal object itself
+// is related (see AliTrack::AddSignal).
+// Therefore, in case the input argument "obj" points to an AliTrack (or derived)
+// object, the current signal is automatically related to this AliTrack
+// (or derived) object.
+// Also a global link to this AliTrack (or derived) object will be stored
+// via the AddTrack() facility.
+//
+// IMPORTANT NOTE :
+// ----------------
+// In case one just wants to relate the current AliSignal to a certain AliTrack
+// without a specific signal slot association, it is much more efficient
+// (both memory and CPU wise) to use the memberfunction AddTrack() instead.
+//
+// Please also have a look at the docs of the memberfunction ResetLink()
+// to prevent the situation of stored pointers to non-existent object.
+
+ if (!fLinks && obj) fLinks=new AliObjMatrix();
+
+ if (!fLinks) return;
+
+ // Note : In the internal storage matrix slots=columns positions=rows
+ fLinks->EnterObject(k,j,obj);
+ if (obj)
+ {
+ if (obj->InheritsFrom("AliTrack"))
+ {
+ AliTrack* t=(AliTrack*)obj;
+ AddTrack(*t,1);
+ }
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::SetLink(TObject* obj,TString name,Int_t k)
+{
+// Introduce a link (=pointer) to an object for the name-spec. slot at position k.
+// Only the pointer values are stored for (backward) reference, meaning
+// that the objects of which the pointers are stored are NOT owned
+// by the AliSignal object.
+//
+// This procedure involves a slot-index search based on the specified name
+// at each invokation. This may become slow in case many slots have been
+// defined and/or when this procedure is invoked many times.
+// In such cases it is preferable to use indexed addressing in the user code
+// either directly or via a few invokations of GetSlotIndex().
+//
+// In case the pointer argument is zero, indeed a value of zero will be
+// stored at the specified position (k) for the specified slotname.
+//
+// In principle any object derived from TObject can be referred to by this
+// mechanism.
+// However, this "linking back" facility was introduced to enable AliSignal slots
+// to refer directly to the various AliTracks to which the AliSignal object itself
+// is related (see AliTrack::AddSignal).
+// Therefore, in case the input argument "obj" points to an AliTrack (or derived)
+// object, the current signal is automatically related to this AliTrack
+// (or derived) object.
+// Also a global link to this AliTrack (or derived) object will be stored
+// via the AddTrack() facility.
+//
+// IMPORTANT NOTE :
+// ----------------
+// In case one just wants to relate the current AliSignal to a certain AliTrack
+// without a specific signal slot association, it is much more efficient
+// (both memory and CPU wise) to use the memberfunction AddTrack() instead.
+//
+// Please also have a look at the docs of the memberfunction ResetLink()
+// to prevent the situation of stored pointers to non-existent object.
+
+ Int_t j=GetSlotIndex(name);
+ if (j>0) SetLink(obj,j,k);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::AddLink(TObject* obj,Int_t j)
+{
+// Introduce a link (=pointer) to an object for the j-th slot at the first
+// free position.
+// Only the pointer values are stored for (backward) reference, meaning
+// that the objects of which the pointers are stored are NOT owned
+// by the AliSignal object.
+//
+// Notes :
+// The first slot is at j=1 and the first position is at k=1.
+// j=1 is the default value.
+//
+// If needed, the storage area for the links is increased automatically.
+//
+// In case the pointer argument is zero, no link will be added.
+//
+// In principle any object derived from TObject can be referred to by this
+// mechanism.
+// However, this "linking back" facility was introduced to enable AliSignal slots
+// to refer directly to the various AliTracks to which the AliSignal object itself
+// is related (see AliTrack::AddSignal).
+// Therefore, in case the input argument "obj" points to an AliTrack (or derived)
+// object, the current signal is automatically related to this AliTrack
+// (or derived) object.
+// Also a global link to this AliTrack (or derived) object will be stored
+// via the AddTrack() facility.
+//
+// IMPORTANT NOTE :
+// ----------------
+// In case one just wants to relate the current AliSignal to a certain AliTrack
+// without a specific signal slot association, it is much more efficient
+// (both memory and CPU wise) to use the memberfunction AddTrack() instead.
+//
+// Please also have a look at the docs of the memberfunction ResetLink()
+// to prevent the situation of stored pointers to non-existent object.
+
+ if (!obj || j<=0) return;
+
+ if (!fLinks) fLinks=new AliObjMatrix();
+
+ TObject* dum=0;
+ Int_t n=GetNlinks(dum,j);
+ Int_t pos=1;
+ for (Int_t k=1; k<=n; k++)
+ {
+ dum=GetLink(j,k);
+ if (!dum) break;
+ pos++;
+ }
+
+ SetLink(obj,j,pos);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::AddLink(TObject* obj,TString name)
+{
+// Introduce a link (=pointer) to an object for the name-spec slot at the first
+// free position.
+// Only the pointer values are stored for (backward) reference, meaning
+// that the objects of which the pointers are stored are NOT owned
+// by the AliSignal object.
+//
+// This procedure involves a slot-index search based on the specified name
+// at each invokation. This may become slow in case many slots have been
+// defined and/or when this procedure is invoked many times.
+// In such cases it is preferable to use indexed addressing in the user code
+// either directly or via a few invokations of GetSlotIndex().
+//
+// In case the pointer argument is zero, indeed a value of zero will be
+// stored at the first free position of the specified slotname.
+//
+// In principle any object derived from TObject can be referred to by this
+// mechanism.
+// However, this "linking back" facility was introduced to enable AliSignal slots
+// to refer directly to the various AliTracks to which the AliSignal object itself
+// is related (see AliTrack::AddSignal).
+// Therefore, in case the input argument "obj" points to an AliTrack (or derived)
+// object, the current signal is automatically related to this AliTrack
+// (or derived) object.
+// Also a global link to this AliTrack (or derived) object will be stored
+// via the AddTrack() facility.
+//
+// IMPORTANT NOTE :
+// ----------------
+// In case one just wants to relate the current AliSignal to a certain AliTrack
+// without a specific signal slot association, it is much more efficient
+// (both memory and CPU wise) to use the memberfunction AddTrack() instead.
+//
+// Please also have a look at the docs of the memberfunction ResetLink()
+// to prevent the situation of stored pointers to non-existent object.
+
+ Int_t j=GetSlotIndex(name);
+ if (j>0) AddLink(obj,j);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::ResetLink(Int_t j,Int_t k)
+{
+// Reset the link of the j-th slot at position k.
+//
+// Notes :
+// The first slot is at j=1 and the first position is at k=1.
+// j=1 and k=1 are the default values.
+//
+// This memberfunction is intended to reset only 1 specified link location.
+// For extended functionality, please refer to the memberfuction ResetLinks().
+//
+// In general the user should take care of properly clearing the corresponding
+// pointer here when the referred object is deleted.
+// However, this "linking back" facility was introduced to enable AliSignal slots
+// to refer directly to the various AliTracks to which the AliSignal object itself
+// is related (see AliTrack::AddSignal).
+// As such, the AliTrack destructor already takes care of clearing the corresponding
+// links from the various AliSignal slots for all the AliSignal objects that were
+// related to that AliTrack.
+// So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
+// the user doesn't have to worry about clearing the corresponding AliTrack link from
+// the AliSignal object when the corresponding AliTrack object is deleted.
+
+ // Note : In the internal storage matrix slots=columns positions=rows
+ if (fLinks) fLinks->RemoveObject(k,j);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::ResetLink(TString name,Int_t k)
+{
+// Reset the link of the name-specified slot at position k.
+//
+// This memberfunction is intended to reset only 1 specified link location.
+// For extended functionality, please refer to the memberfuction ResetLinks().
+//
+// This procedure involves a slot-index search based on the specified name
+// at each invokation. This may become slow in case many slots have been
+// defined and/or when this procedure is invoked many times.
+// In such cases it is preferable to use indexed addressing in the user code
+// either directly or via a few invokations of GetSlotIndex().
+
+ Int_t j=GetSlotIndex(name);
+ if (j>0) ResetLink(j,k);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::ResetLinks(TObject* obj,Int_t j,Int_t k)
+{
+// Reset single or multiple slot link(s) according to user specified selections.
+//
+// IMPORTANT NOTE :
+// ----------------
+// This facility only acts on the slot related links.
+// The global track reference list will not be affected.
+// To remove all references to AliTrack (or derived) objects, please
+// use the RemoveTrack() of RemoveTracks() memberfunctions.
+//
+// A link is only reset if the stored reference matches the argument "obj".
+// In case obj=0 no check on the matching of the stored reference is performed
+// and the stored link is always reset in accordance with the other
+// selection criteria.
+//
+// In case the slot argument "j" is specified, only the links from that
+// specified slot will be deleted.
+// In case j=0 (default) no checking on the slot index is performed.
+//
+// In case the position argument "k" is specified, only the links from that
+// specified position will be deleted.
+// In case k=0 (default) no checking on the position index is performed.
+//
+// So, invokation of ResetLinks(obj) will remove all references to the
+// object "obj" from the total AliSignal, whereas ResetLinks(obj,j)
+// will remove all references to the object "obj" only from slot "j".
+//
+// Notes :
+// -------
+// The first slot is indicated as j=1, whereas the first position is at k=1.
+//
+// Invokation of ResetLinks(0,row,col) is equivalent to invoking the
+// memberfunction ResetLink(row,col).
+// Invoking the latter directly is slightly faster.
+//
+// Invokation of ResetLinks(0) will reset all stored references in this AliSignal.
+//
+// In general the user should take care of properly clearing the corresponding
+// pointer here when the referred object is deleted.
+// However, this "linking back" facility was introduced to enable AliSignal slots
+// to refer directly to the various AliTracks to which the AliSignal object itself
+// is related (see AliTrack::AddSignal).
+// As such, the AliTrack destructor already takes care of clearing the corresponding
+// links from the various AliSignal slots for all the AliSignal objects that were
+// related to that AliTrack.
+// So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
+// the user doesn't have to worry about clearing the corresponding AliTrack link from
+// the AliSignal object when the corresponding AliTrack object is deleted.
+
+ if (!fLinks) return;
+
+ if (!obj && !j && !k)
+ {
+ fLinks->Reset();
+ }
+ else
+ {
+ // Note : In the internal storage matrix slots=columns positions=rows
+ fLinks->RemoveObjects(obj,k,j);
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::ResetLinks(TObject* obj,TString name,Int_t k)
+{
+// Reset single or multiple slot link(s) according to user specified selections.
+//
+// IMPORTANT NOTE :
+// ----------------
+// This facility only acts on the slot related links.
+// The global track reference list will not be affected.
+// To remove all references to AliTrack (or derived) objects, please
+// use the RemoveTrack() of RemoveTracks() memberfunctions.
+//
+// A link is only reset if the stored reference matches the argument "obj".
+// In case obj=0 no check on the matching of the stored reference is performed
+// and the stored link is always reset in accordance with the other
+// selection criteria.
+//
+// In case the position argument "k" is specified, only the links from that
+// specified position will be deleted.
+// In case k=0 (default) no checking on the position index is performed.
+//
+// This procedure involves a slot-index search based on the specified name
+// at each invokation. This may become slow in case many slots have been
+// defined and/or when this procedure is invoked many times.
+// In such cases it is preferable to use indexed addressing in the user code
+// either directly or via a few invokations of GetSlotIndex().
+//
+// In general the user should take care of properly clearing the corresponding
+// pointer here when the referred object is deleted.
+// However, this "linking back" facility was introduced to enable AliSignal slots
+// to refer directly to the various AliTracks to which the AliSignal object itself
+// is related (see AliTrack::AddSignal).
+// As such, the AliTrack destructor already takes care of clearing the corresponding
+// links from the various AliSignal slots for all the AliSignal objects that were
+// related to that AliTrack.
+// So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
+// the user doesn't have to worry about clearing the corresponding AliTrack link from
+// the AliSignal object when the corresponding AliTrack object is deleted.
+
+ Int_t j=GetSlotIndex(name);
+ if (j>0) ResetLinks(obj,j,k);
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,TArrayI& ks) const
+{
+// Provide the slot and position indices of all the storage locations
+// of the specified object.
+// The slot (j) and pos. (k) indices are returned in the two separate TArrayI arrays
+// from which the (j,k) pairs can be obtained from the corresponding
+// array indices like (j,k)=(js.At(i),ks.At(i)).
+// The integer return argument represents the number of (j,k) pairs which
+// were encountered for the specified object.
+//
+// If obj=0 no object selection is performed and all (j,k) indices
+// of the stored references for all objects are returned.
+//
+// Notes :
+// -------
+// As usual the convention is that slot and position numbering starts at 1.
+//
+// This memberfunction always resets the two TArrayI arrays at the start.
+//
+// This memberfunction can only be used to obtain the (j,k) indices
+// of the object as stored via the SetLink() or AddLink() memberfunction.
+// This means that in case the user has entered a TObjArray as object
+// (to increase the dimension of the resulting structure), the (j,k)
+// indices of that TObjArray are obtained and NOT the indices of the
+// actual objects contained in that TObjArray structure.
+//
+ Int_t nrefs=0;
+ js.Reset();
+ ks.Reset();
+ // Note : In the internal storage matrix slots=columns positions=rows
+ if (fLinks) nrefs=fLinks->GetIndices(obj,ks,js);
+ return nrefs;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetIndices(TObject* obj,Int_t j,TArrayI& ks) const
+{
+// Provide the position indices of all the storage locations of the
+// specified object in the j-th slot of this AliSignal.
+// The position indices are returned in the TArrayI array.
+// The integer return argument represents the number of storage locations which
+// were encountered for the specified object in the j-th slot.
+//
+// If obj=0 no object selection is performed and all position indices
+// of the stored references for all objects of the j-th slot are returned.
+//
+// If j=0 all slots will be scanned and all position indices matching the
+// object selection are returned.
+// Note that in this case multiple appearances of the same position index
+// will only be recorded once in the returned TArrayI array.
+//
+// Notes :
+// -------
+// As usual the convention is that slot and position numbering starts at 1.
+//
+// This memberfunction always resets the TArrayI array at the start.
+//
+// This memberfunction can only be used to obtain the position indices
+// of the object as stored via the SetLink() or AddLink() memberfunction.
+// This means that in case the user has entered a TObjArray as object
+// (to increase the dimension of the resulting structure), the position
+// indices of that TObjArray are obtained and NOT the indices of the
+// actual objects contained in that TObjArray structure.
+//
+ Int_t nrefs=0;
+ ks.Reset();
+ // Note : In the internal storage matrix slots=columns positions=rows
+ if (fLinks) nrefs=fLinks->GetIndices(obj,ks,j);
+ return nrefs;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetIndices(TObject* obj,TString name,TArrayI& ks) const
+{
+// Provide the position indices of all the storage locations of the
+// specified object in the name-specified slot of this AliSignal.
+// The position indices are returned in the TArrayI array.
+// The integer return argument represents the number of storage locations which
+// were encountered for the specified object in the j-th slot.
+//
+// If obj=0 no object selection is performed and all position indices
+// of the stored references for all objects of the j-th slot are returned.
+//
+// This procedure involves a slot-index search based on the specified name
+// at each invokation. This may become slow in case many slots have been
+// defined and/or when this procedure is invoked many times.
+// In such cases it is preferable to use indexed addressing in the user code
+// either directly or via a few invokations of GetSlotIndex().
+
+ Int_t j=GetSlotIndex(name);
+ Int_t n=0;
+ if (j>0) n=GetIndices(obj,j,ks);
+ return n;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,Int_t k) const
+{
+// Provide the slot indices of all the storage locations of the
+// specified object for the k-th position in this AliSignal.
+// The slot indices are returned in the TArrayI array.
+// The integer return argument represents the number of storage locations which
+// were encountered for the specified object in the k-th position.
+//
+// If obj=0 no object selection is performed and all slot indices
+// of the stored references for all objects in the k-th position are returned.
+//
+// If k=0 all positions will be scanned and all slot indices matching the
+// object selection are returned.
+// Note that in this case multiple appearances of the same slot index
+// will only be recorded once in the returned TArrayI array.
+//
+// Notes :
+// -------
+// As usual the convention is that slot and position numbering starts at 1.
+//
+// This memberfunction always resets the TArrayI array at the start.
+//
+// This memberfunction can only be used to obtain the slot indices
+// of the object as stored via the SetLink() or AddLink() memberfunction.
+// This means that in case the user has entered a TObjArray as object
+// (to increase the dimension of the resulting structure), the slot
+// indices of that TObjArray are obtained and NOT the indices of the
+// actual objects contained in that TObjArray structure.
+//
+ Int_t nrefs=0;
+ js.Reset();
+ // Note : In the internal storage matrix slots=columns positions=rows
+ if (fLinks) nrefs=fLinks->GetIndices(obj,k,js);
+ return nrefs;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::SetSwapMode(Int_t swap)
+{
+// Set swapmode flag for the internal link storage.
+// In case for the stored links the maximum slot number differs considerably
+// from the maximum position number, it might be more efficient
+// (w.r.t. memory usage and/or output file size) to internally store the
+// link reference matrix with the rows and colums swapped.
+// This swapping is only related with the internal storage and as such
+// is completely hidden for the user.
+// At invokation of this memberfunction the default argument is swap=1.
+//
+// Note : The swap mode can only be set as long as no links are
+// stored in the AliSignal (i.e. a new instance of AliSignal
+// or after invokation of the Reset() or ResetLinks() function).
+
+ if (!fLinks) fLinks=new AliObjMatrix();
+ fLinks->SetSwapMode(swap);
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetSwapMode() const
+{
+// Provide swapmode flag of the link storage.
+ Int_t swap=0;
+ if (fLinks) swap=fLinks->GetSwapMode();
+ return swap;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::SetDevice(TObject* dev)
+{
+// Store the pointer to the device which owns this AliSignal object.
+// This memberfunction is meant for internal use in AliDevice.
+ fDevice=dev;
+}
+///////////////////////////////////////////////////////////////////////////
+AliDevice* AliSignal::GetDevice() const
+{
+// Provide the pointer to the device which owns this AliSignal object.
+ return (AliDevice*)fDevice;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::AddTrack(AliTrack& t,Int_t mode)
+{
+// Relate an AliTrack object to this signal.
+// Only the pointer values are stored for (backward) reference, meaning
+// that the tracks of which the pointers are stored are NOT owned
+// by the AliSignal object.
+//
+// mode = 0 : Only the reference to the specified track is stored in
+// the current signal, without storing the (backward) reference
+// to this signal into the AliTrack structure.
+// 1 : The (backward) reference to the current signal is also automatically
+// stored into the AliTrack (or derived) object specified in the
+// input argument.
+//
+// The default is mode=1.
+
+ if (!fTracks) fTracks=new TObjArray(1);
+
+ // Check if this track is already stored for this signal
+ Int_t ntk=GetNtracks();
+ for (Int_t i=0; i<ntk; i++)
+ {
+ if (&t==fTracks->At(i)) return;
+ }
+
+ fTracks->Add(&t);
+ if (mode==1) t.AddSignal(*this,0);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::RemoveTrack(AliTrack& t,Int_t mode)
+{
+// Remove related AliTrack object from this signal.
+// Also all references (if any) to this track in the slot links area
+// are removed.
+//
+// mode = 0 : All references to the specified track are removed from
+// the current signal, without removing the (backward) reference
+// to this signal from the AliTrack structure.
+// 1 : The (backward) reference to the current signal is also automatically
+// removed from the AliTrack (or derived) object specified in the
+// input argument.
+//
+// The default is mode=1.
+
+ if (fTracks)
+ {
+ AliTrack* test=(AliTrack*)fTracks->Remove(&t);
+ if (test) fTracks->Compress();
+ }
+
+ ResetLinks(&t);
+
+ if (mode==1) t.RemoveSignal(*this,0);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliSignal::RemoveTracks(Int_t mode)
+{
+// Remove all related AliTrack objects from this signal.
+// Also all references (if any) to the related tracks in the slot links area
+// are removed.
+//
+// mode = 0 : All track references are removed from the current signal,
+// without removing the (backward) references to this signal from
+// the corresponding AliTrack objects.
+// 1 : The (backward) references to the current signal are also automatically
+// removed from the corresponding AliTrack (or derived) objects.
+//
+// The default is mode=1.
+
+ if (!fTracks) return;
+
+ Int_t ntk=GetNtracks();
+ for (Int_t i=0; i<ntk; i++)
+ {
+ AliTrack* tx=(AliTrack*)fTracks->At(i);
+ if (tx)
+ {
+ ResetLinks(tx);
+ if (mode==1) tx->RemoveSignal(*this,0);
+ }
+ }
+
+ delete fTracks;
+ fTracks=0;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetNtracks(AliTrack* t) const
+{
+// Provide the number of related AliTracks.
+// In case an AliTrack pointer is specified as input argument,
+// the number returned will be the number of occurrences (i.e. 0 or 1)
+// for that specified track.
+// By default t=0, which implies that just the number of all associated
+// tracks will be returned.
+
+ if (!fTracks) return 0;
+
+ Int_t ntk=fTracks->GetEntries();
+
+ if (!t) return ntk;
+
+ for (Int_t i=0; i<ntk; i++)
+ {
+ AliTrack* tx=(AliTrack*)fTracks->At(i);
+ if (tx==t) return 1;
+ }
+
+ return 0;
+}
+///////////////////////////////////////////////////////////////////////////
+AliTrack* AliSignal::GetTrack(Int_t j) const
+{
+// Provide the related AliTrack number j.
+// Note : j=1 denotes the first track.
+
+ if (!fTracks) return 0;
+
+ if ((j >= 1) && (j <= GetNtracks()))
+ {
+ return (AliTrack*)fTracks->At(j-1);
+ }
+ else
+ {
+ cout << " *AliSignal* track number : " << j << " out of range."
+ << " Ntk = " << GetNtracks() << endl;
+ return 0;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+AliTrack* AliSignal::GetIdTrack(Int_t id) const
+{
+// Return the track with user identifier "id" of this signal
+ if (!fTracks) return 0;
+
+ AliTrack* tx=0;
+ for (Int_t i=0; i<GetNtracks(); i++)
+ {
+ tx=(AliTrack*)fTracks->At(i);
+ if (id == tx->GetId()) return tx;
+ }
+ return 0; // No matching id found
+}
+///////////////////////////////////////////////////////////////////////////
+TObject* AliSignal::Clone(const char* name) const
+{
+// Make a deep copy of the current object and provide the pointer to the copy.
+// This memberfunction enables automatic creation of new objects of the
+// correct type depending on the object type, a feature which may be very useful
+// for containers when adding objects in case the container owns the objects.
+// This feature allows e.g. AliTrack to store either AliSignal objects or
+// objects derived from AliSignal via the AddSignal memberfunction, provided
+// these derived classes also have a proper Clone memberfunction.
+
+ AliSignal* sig=new AliSignal(*this);
+ if (name)
+ {
+ if (strlen(name)) sig->SetName(name);
+ }