]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliSignal.cxx
Possibility to switch off heavy flavor production added.
[u/mrichter/AliRoot.git] / RALICE / AliSignal.cxx
CommitLineData
4c039060 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
f531a546 16// $Id$
4c039060 17
959fbac5 18///////////////////////////////////////////////////////////////////////////
19// Class AliSignal
dafe31a2 20// Generic handling of (extrapolated) detector signals.
959fbac5 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;
7a5c405b 39// s.SetName("Start counter");
959fbac5 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;
1fbffa23 44// Float_t offset=-12.78;
45// Float_t gain=250;
959fbac5 46// s.SetPosition(pos,"car");
47// s.SetPositionErrors(err,"car");
48// s.SetSignal(signal);
49// s.SetSignalError(error);
1fbffa23 50// s.SetOffset(offset);
51// s.SetGain(gain);
959fbac5 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//
c72198f1 58// AliSignal q; // In the example below a signal contains the
959fbac5 59// // following data : timing, ADC and dE/dx
965bd237 60// q.SetNameTitle("Hybrid","Test for multiple signal data");
959fbac5 61// q.SetPosition(pos,"car");
62// q.SetPositionErrors(err,"car");
7a5c405b 63// signal=82.5; // e.g. signal time in ns
959fbac5 64// error=2.01;
1fbffa23 65// offset=0.003;
965bd237 66// q.SetSlotName("TOF");
959fbac5 67// q.SetSignal(signal,1);
68// q.SetSignalError(error,1);
1fbffa23 69// q.SetOffset(offset,1);
959fbac5 70// signal=268.1; // e.g. ADC value of signal
71// error=3.75;
1fbffa23 72// gain=120.78;
965bd237 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");
959fbac5 78// signal=23.7; // e.g. corresponding dE/dx value
79// error=0.48;
1fbffa23 80// offset=0.2;
81// gain=150;
965bd237 82// q.SetSlotName("dE/dx");
959fbac5 83// q.SetSignal(signal,3);
84// q.SetSignalError(error,3);
1fbffa23 85// q.SetOffset(offset,3);
86// q.SetGain(gain,3);
959fbac5 87//
965bd237 88// Float_t dedx=q.GetSignal("dE/dx");
89//
959fbac5 90//--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
f531a546 91//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 92///////////////////////////////////////////////////////////////////////////
93
d88f97cc 94#include "AliSignal.h"
5f25234b 95#include "AliTrack.h"
c72198f1 96#include "Riostream.h"
d88f97cc 97
98ClassImp(AliSignal) // Class implementation to enable ROOT I/O
99
1c01b4f8 100AliSignal::AliSignal() : TNamed(),AliPosition(),AliAttrib()
d88f97cc 101{
959fbac5 102// Creation of an AliSignal object and initialisation of parameters.
1fbffa23 103// Several signal values (with errors) can be stored in different slots.
fdadc78a 104// If needed, the storage for values (and errors) will be expanded automatically
105// when entering values and/or errors.
1fbffa23 106 fSignals=0;
107 fDsignals=0;
108 fWaveforms=0;
5f25234b 109 fLinks=0;
965bd237 110 fDevice=0;
d88f97cc 111}
112///////////////////////////////////////////////////////////////////////////
113AliSignal::~AliSignal()
114{
115// Destructor to delete dynamically allocated memory
1fbffa23 116 if (fSignals)
959fbac5 117 {
1fbffa23 118 delete fSignals;
119 fSignals=0;
959fbac5 120 }
1fbffa23 121 if (fDsignals)
959fbac5 122 {
1fbffa23 123 delete fDsignals;
124 fDsignals=0;
959fbac5 125 }
1fbffa23 126 if (fWaveforms)
c72198f1 127 {
1fbffa23 128 delete fWaveforms;
129 fWaveforms=0;
c72198f1 130 }
5f25234b 131 if (fLinks)
132 {
ea0b5b7f 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 }
5f25234b 144 delete fLinks;
145 fLinks=0;
146 }
d88f97cc 147}
148///////////////////////////////////////////////////////////////////////////
261c0caf 149AliSignal::AliSignal(const AliSignal& s) : TNamed(s),AliPosition(s),AliAttrib(s)
8e8e6c7f 150{
151// Copy constructor
1fbffa23 152 fSignals=0;
153 fDsignals=0;
1fbffa23 154 fWaveforms=0;
5f25234b 155 fLinks=0;
8e8e6c7f 156
965bd237 157 // Don't copy the owning device pointer for the copy
158 fDevice=0;
159
1fbffa23 160 Int_t n=s.GetNvalues();
161 Double_t val;
162 for (Int_t i=1; i<=n; i++)
8e8e6c7f 163 {
1fbffa23 164 val=s.GetSignal(i);
165 SetSignal(val,i);
fdadc78a 166 }
167
1fbffa23 168 n=s.GetNerrors();
169 for (Int_t j=1; j<=n; j++)
fdadc78a 170 {
1fbffa23 171 val=s.GetSignalError(j);
172 SetSignalError(val,j);
c72198f1 173 }
174
1fbffa23 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 }
5f25234b 181
d0a8ef71 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++)
5f25234b 188 {
d0a8ef71 189 slot=slotarr.At(idx);
190 pos=posarr.At(idx);
191 TObject* obj=s.GetLink(slot,pos);
192 if (obj) SetLink(obj,slot,pos);
5f25234b 193 }
8e8e6c7f 194}
195///////////////////////////////////////////////////////////////////////////
fdadc78a 196void AliSignal::Reset(Int_t mode)
d88f97cc 197{
959fbac5 198// Reset all signal and position values and errors to 0.
fdadc78a 199//
200// mode = 0 Reset position and all signal values and their errors to 0.
1fbffa23 201// The waveform histograms are reset, but the calibration
202// constants (i.e. gains and offsets) are kept.
fdadc78a 203// 1 Reset position and delete the signal and error storage arrays.
1fbffa23 204// Also the waveform histograms, gains and offset arrays are deleted.
fdadc78a 205//
206// The default when invoking Reset() corresponds to mode=0.
207//
d0a8ef71 208// Note : In all cases the storage of the various links will be reset.
4f368c8c 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.
5f25234b 212//
fdadc78a 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)
1fbffa23 215// in case the various signals always contain the same number of values
216// and have the same calibration constants.
fdadc78a 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//
1fbffa23 221// For more specific actions see ResetPosition(), ResetSignals(),
d0a8ef71 222// DeleteSignals(), ResetGain(), ResetOffset(), ResetLink(), ResetWaveform(),
223// DeleteWaveform() and DeleteCalibrations().
c72198f1 224//
959fbac5 225
fdadc78a 226 if (mode<0 || mode>1)
959fbac5 227 {
fdadc78a 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();
1fbffa23 241 DeleteCalibrations();
959fbac5 242 }
5f25234b 243
d0a8ef71 244 if (fLinks) fLinks->Reset();
965bd237 245 fDevice=0;
959fbac5 246}
247///////////////////////////////////////////////////////////////////////////
fdadc78a 248void AliSignal::ResetSignals(Int_t mode)
959fbac5 249{
fdadc78a 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.
c72198f1 257//
1fbffa23 258// Irrespective of the mode, the waveform histograms are reset.
959fbac5 259
fdadc78a 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
1fbffa23 267 if (fSignals && (mode==0 || mode==1))
959fbac5 268 {
1fbffa23 269 for (Int_t i=0; i<fSignals->GetSize(); i++)
dafe31a2 270 {
1fbffa23 271 fSignals->AddAt(0,i);
fdadc78a 272 }
273 }
274
1fbffa23 275 if (fDsignals && (mode==0 || mode==2))
fdadc78a 276 {
1fbffa23 277 for (Int_t j=0; j<fDsignals->GetSize(); j++)
fdadc78a 278 {
1fbffa23 279 fDsignals->AddAt(0,j);
dafe31a2 280 }
959fbac5 281 }
c72198f1 282
1fbffa23 283 ResetWaveform(0);
d88f97cc 284}
285///////////////////////////////////////////////////////////////////////////
fdadc78a 286void 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.
c72198f1 295//
1fbffa23 296// Irrespective of the mode, the waveform histograms are deleted.
fdadc78a 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
1fbffa23 305 if (fSignals && (mode==0 || mode==1))
fdadc78a 306 {
1fbffa23 307 delete fSignals;
308 fSignals=0;
fdadc78a 309 }
310
1fbffa23 311 if (fDsignals && (mode==0 || mode==2))
fdadc78a 312 {
1fbffa23 313 delete fDsignals;
314 fDsignals=0;
fdadc78a 315 }
c72198f1 316
1fbffa23 317 DeleteWaveform(0);
fdadc78a 318}
319///////////////////////////////////////////////////////////////////////////
959fbac5 320void AliSignal::SetSignal(Double_t sig,Int_t j)
d88f97cc 321{
2cb7369d 322// Store signal value for the j-th (default j=1) slot.
1fbffa23 323// Note : The first signal slot is at j=1.
dafe31a2 324// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 325// slots for signal values, the number of reserved slots for the
326// signal values is increased automatically.
959fbac5 327
1fbffa23 328 if (!fSignals)
959fbac5 329 {
1fbffa23 330 fSignals=new TArrayF(j);
fdadc78a 331 ResetSignals(1);
959fbac5 332 }
dafe31a2 333
1fbffa23 334 Int_t size=fSignals->GetSize();
dafe31a2 335
336 if (j>size)
959fbac5 337 {
1fbffa23 338 fSignals->Set(j);
959fbac5 339 }
dafe31a2 340
1fbffa23 341 fSignals->AddAt(float(sig),j-1);
d88f97cc 342}
343///////////////////////////////////////////////////////////////////////////
2cb7369d 344void 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///////////////////////////////////////////////////////////////////////////
959fbac5 358void AliSignal::AddSignal(Double_t sig,Int_t j)
359{
2cb7369d 360// Add value to the signal of the j-th (default j=1) slot.
1fbffa23 361// Note : The first signal slot is at j=1.
dafe31a2 362// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 363// slots for signal values, the number of reserved slots for the
364// signal values is increased automatically.
959fbac5 365
1fbffa23 366 if (!fSignals)
959fbac5 367 {
1fbffa23 368 fSignals=new TArrayF(j);
fdadc78a 369 ResetSignals(1);
959fbac5 370 }
dafe31a2 371
1fbffa23 372 Int_t size=fSignals->GetSize();
dafe31a2 373
374 if (j>size)
959fbac5 375 {
1fbffa23 376 fSignals->Set(j);
959fbac5 377 }
dafe31a2 378
1fbffa23 379 Float_t sum=(fSignals->At(j-1))+sig;
380 fSignals->AddAt(sum,j-1);
959fbac5 381}
382///////////////////////////////////////////////////////////////////////////
2cb7369d 383void 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///////////////////////////////////////////////////////////////////////////
261c0caf 397Float_t AliSignal::GetSignal(Int_t j,Int_t mode) const
959fbac5 398{
2cb7369d 399// Provide signal value of the j-th (default j=1) slot.
1fbffa23 400// Note : The first signal slot is at j=1.
fdadc78a 401// In case no signal is present or the argument j is invalid, 0 is returned.
1fbffa23 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
fdadc78a 417 Float_t sig=0;
1fbffa23 418 Float_t gain=1;
419 Float_t offset=0;
420 if (fSignals)
959fbac5 421 {
1fbffa23 422 if (j>0 && j<=(fSignals->GetSize()))
fdadc78a 423 {
1fbffa23 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 }
fdadc78a 442 }
443 else
444 {
445 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
446 }
959fbac5 447 }
fdadc78a 448 return sig;
959fbac5 449}
450///////////////////////////////////////////////////////////////////////////
2cb7369d 451Float_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///////////////////////////////////////////////////////////////////////////
959fbac5 482void AliSignal::SetSignalError(Double_t dsig,Int_t j)
483{
2cb7369d 484// Store error on the signal for the j-th (default j=1) slot.
1fbffa23 485// Note : The first signal slot is at j=1.
dafe31a2 486// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 487// slots for signal error values, the number of reserved slots for the
488// signal errors is increased automatically.
959fbac5 489
1fbffa23 490 if (!fDsignals)
959fbac5 491 {
1fbffa23 492 fDsignals=new TArrayF(j);
fdadc78a 493 ResetSignals(2);
959fbac5 494 }
dafe31a2 495
1fbffa23 496 Int_t size=fDsignals->GetSize();
dafe31a2 497
498 if (j>size)
959fbac5 499 {
1fbffa23 500 fDsignals->Set(j);
959fbac5 501 }
dafe31a2 502
1fbffa23 503 fDsignals->AddAt(float(dsig),j-1);
959fbac5 504}
505///////////////////////////////////////////////////////////////////////////
2cb7369d 506void 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///////////////////////////////////////////////////////////////////////////
261c0caf 520Float_t AliSignal::GetSignalError(Int_t j) const
959fbac5 521{
2cb7369d 522// Provide error on the signal of the j-th (default j=1) slot.
1fbffa23 523// Note : The first signal slot is at j=1.
fdadc78a 524// In case no signal is present or the argument j is invalid, 0 is returned.
525 Float_t err=0;
1fbffa23 526 if (fDsignals)
959fbac5 527 {
1fbffa23 528 if (j>0 && j<=(fDsignals->GetSize()))
fdadc78a 529 {
1fbffa23 530 err=fDsignals->At(j-1);
fdadc78a 531 }
532 else
533 {
534 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
535 }
959fbac5 536 }
fdadc78a 537 return err;
959fbac5 538}
539///////////////////////////////////////////////////////////////////////////
2cb7369d 540Float_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///////////////////////////////////////////////////////////////////////////
261c0caf 556void AliSignal::Data(TString f) const
1c01b4f8 557{
558// Provide all signal information within the coordinate frame f.
559
5f25234b 560 const char* name=GetName();
561 const char* title=GetTitle();
562
f67e2651 563 cout << " *" << ClassName() << "::Data* Id : " << GetUniqueID();
5f25234b 564 if (strlen(name)) cout << " Name : " << name;
565 if (strlen(title)) cout << " Title : " << title;
566 cout << endl;
d0a8ef71 567 cout << " Position";
1c01b4f8 568 Ali3Vector::Data(f);
965bd237 569 if (fDevice)
570 {
571 const char* devname=fDevice->GetName();
572 const char* devtitle=fDevice->GetTitle();
f67e2651 573 cout << " Owned by device : " << fDevice->ClassName()
574 << " Id : " << fDevice->GetUniqueID();
965bd237 575 if (strlen(devname)) cout << " Name : " << devname;
576 if (strlen(devtitle)) cout << " Title : " << devtitle;
577 cout << endl;
578 }
1c01b4f8 579
6a8254a0 580 // Provide an overview of the stored waveforms
581 ListWaveform(-1);
582
583 // Provide an overview of all the data and attribute slots
1c01b4f8 584 List(-1);
585}
586///////////////////////////////////////////////////////////////////////////
261c0caf 587void AliSignal::List(Int_t j) const
959fbac5 588{
1c01b4f8 589// Provide signal information for the j-th slot.
1fbffa23 590// The first slot is at j=1.
591// In case j=0 (default) the data of all slots will be listed.
1c01b4f8 592// In case j=-1 the data of all slots will be listed, but the header
593// information will be suppressed.
1fbffa23 594
1c01b4f8 595 if (j<-1)
1fbffa23 596 {
1c01b4f8 597 cout << " *AliSignal::List* Invalid argument j = " << j << endl;
1fbffa23 598 return;
599 }
600
5f25234b 601 if (j != -1)
602 {
603 const char* name=GetName();
604 const char* title=GetTitle();
605
6a8254a0 606 cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
5f25234b 607 if (strlen(name)) cout << " Name : " << name;
608 if (strlen(title)) cout << " Title : " << title;
609 cout << endl;
6a8254a0 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 }
5f25234b 619 }
fdadc78a 620
621 Int_t nvalues=GetNvalues();
622 Int_t nerrors=GetNerrors();
d0a8ef71 623 Int_t nlinkslots=0;
624 if (fLinks) nlinkslots=fLinks->GetMaxColumn();
1fbffa23 625 Int_t n=nvalues;
626 if (nerrors>n) n=nerrors;
d0a8ef71 627 if (nlinkslots>n) n=nlinkslots;
5f25234b 628
629 TObject* obj=0;
d0a8ef71 630 Int_t nrefs=0;
631 TArrayI posarr;
632 Int_t pos;
fdadc78a 633
1c01b4f8 634 if (j<=0)
959fbac5 635 {
1fbffa23 636 for (Int_t i=1; i<=n; i++)
959fbac5 637 {
d0a8ef71 638 cout << " Slot : " << i;
639 if (i<=nvalues) cout << " Signal value : " << GetSignal(i);
1fbffa23 640 if (i<=nerrors) cout << " error : " << GetSignalError(i);
1c01b4f8 641 AliAttrib::List(i);
1fbffa23 642 cout << endl;
d0a8ef71 643 obj=0;
644 nrefs=GetIndices(obj,i,posarr);
645 for (Int_t k=0; k<nrefs; k++)
5f25234b 646 {
d0a8ef71 647 pos=posarr.At(k);
648 obj=GetLink(i,pos);
649 if (obj)
03b59bc9 650 {
d0a8ef71 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;
03b59bc9 660 }
5f25234b 661 }
1fbffa23 662 }
663 }
664 else
665 {
666 if (j<=n)
667 {
d0a8ef71 668 cout << " Slot : " << j;
669 if (j<=nvalues) cout << " Signal value : " << GetSignal(j);
1fbffa23 670 if (j<=nerrors) cout << " error : " << GetSignalError(j);
1c01b4f8 671 AliAttrib::List(j);
fdadc78a 672 cout << endl;
d0a8ef71 673 obj=0;
674 nrefs=GetIndices(obj,j,posarr);
675 for (Int_t kj=0; kj<nrefs; kj++)
5f25234b 676 {
d0a8ef71 677 pos=posarr.At(kj);
678 obj=GetLink(j,pos);
679 if (obj)
03b59bc9 680 {
d0a8ef71 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;
03b59bc9 690 }
5f25234b 691 }
959fbac5 692 }
693 }
694}
695///////////////////////////////////////////////////////////////////////////
2cb7369d 696void 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///////////////////////////////////////////////////////////////////////////
6a8254a0 710void 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///////////////////////////////////////////////////////////////////////////
261c0caf 781Int_t AliSignal::GetNvalues() const
8e8e6c7f 782{
783// Provide the number of values for this signal.
dafe31a2 784 Int_t n=0;
1fbffa23 785 if (fSignals) n=fSignals->GetSize();
fdadc78a 786 return n;
787}
788///////////////////////////////////////////////////////////////////////////
261c0caf 789Int_t AliSignal::GetNerrors() const
fdadc78a 790{
791// Provide the number specified errors on the values for this signal.
792 Int_t n=0;
1fbffa23 793 if (fDsignals) n=fDsignals->GetSize();
dafe31a2 794 return n;
8e8e6c7f 795}
796///////////////////////////////////////////////////////////////////////////
261c0caf 797Int_t AliSignal::GetNwaveforms() const
c72198f1 798{
a80c27d9 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);
c72198f1 814}
815///////////////////////////////////////////////////////////////////////////
261c0caf 816TH1F* AliSignal::GetWaveform(Int_t j) const
c72198f1 817{
6a8254a0 818// Provide pointer to the j-th waveform histogram.
1fbffa23 819 TH1F* waveform=0;
820 if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
821 return waveform;
822}
823///////////////////////////////////////////////////////////////////////////
2cb7369d 824TH1F* AliSignal::GetWaveform(TString name) const
825{
6a8254a0 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///////////////////////////////////////////////////////////////////////////
842Int_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
2cb7369d 858}
859///////////////////////////////////////////////////////////////////////////
1fbffa23 860void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
861{
6a8254a0 862// Set the 1D waveform histogram for the j-th waveform.
1fbffa23 863//
864// Notes :
6a8254a0 865// The first waveform position at j=1.
1fbffa23 866// j=1 is the default value.
867//
868// In case the value of the index j exceeds the maximum number of reserved
6a8254a0 869// positions for the waveforms, the number of reserved positions for the waveforms
1fbffa23 870// is increased automatically.
c72198f1 871//
1fbffa23 872// In case the histo pointer argument has the same value as the current waveform
c72198f1 873// histogram pointer value, no action is taken since the user has already
874// modified the actual histogram.
875//
1fbffa23 876// In case the histo pointer argument is zero, the current waveform histogram
c72198f1 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
6a8254a0 883 if (j<1) return;
884
1fbffa23 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)
c72198f1 895 {
1fbffa23 896 if (hcur)
c72198f1 897 {
1fbffa23 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);
c72198f1 906 }
c72198f1 907 }
908}
909///////////////////////////////////////////////////////////////////////////
1fbffa23 910void AliSignal::ResetWaveform(Int_t j)
911{
6a8254a0 912// Reset the histogram of the j-th (default j=1) waveform.
1fbffa23 913// This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
914// To actually delete the histograms from memory, use DeleteWaveform().
6a8254a0 915// Notes : The first position is at j=1.
1fbffa23 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///////////////////////////////////////////////////////////////////////////
2cb7369d 945void AliSignal::ResetWaveform(TString name)
946{
6a8254a0 947// Reset the waveform with the specified name.
948 Int_t j=GetWaveformIndex(name);
2cb7369d 949 if (j>0) ResetWaveform(j);
950}
951///////////////////////////////////////////////////////////////////////////
1fbffa23 952void AliSignal::DeleteWaveform(Int_t j)
953{
6a8254a0 954// Delete the histogram of the j-th (default j=1) waveform.
955// Notes : The first position is at j=1.
1fbffa23 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///////////////////////////////////////////////////////////////////////////
2cb7369d 986void AliSignal::DeleteWaveform(TString name)
987{
6a8254a0 988// Delete the waveform with the specified name.
989 Int_t j=GetWaveformIndex(name);
2cb7369d 990 if (j>0) DeleteWaveform(j);
991}
992///////////////////////////////////////////////////////////////////////////
261c0caf 993Int_t AliSignal::GetNlinks(TObject* obj,Int_t j) const
5f25234b 994{
d0a8ef71 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
5f25234b 1006 Int_t n=0;
d0a8ef71 1007 if (!j)
1008 {
7a086578 1009 if (fLinks) n=fLinks->GetNrefs(obj);
d0a8ef71 1010 }
1011 else
1012 {
1013 TArrayI posarr;
1014 n=GetIndices(obj,j,posarr);
1015 }
5f25234b 1016 return n;
1017}
1018///////////////////////////////////////////////////////////////////////////
2cb7369d 1019Int_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///////////////////////////////////////////////////////////////////////////
261c0caf 1036TObject* AliSignal::GetLink(Int_t j,Int_t k) const
5f25234b 1037{
d0a8ef71 1038// Provide pointer of the object linked to the j-th slot at position k.
1039
5f25234b 1040 TObject* obj=0;
d0a8ef71 1041 // Note : In the internal storage matrix slots=columns positions=rows
1042 if (fLinks) obj=fLinks->GetObject(k,j);
5f25234b 1043 return obj;
1044}
1045///////////////////////////////////////////////////////////////////////////
2cb7369d 1046TObject* 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///////////////////////////////////////////////////////////////////////////
d0a8ef71 1062void AliSignal::SetLink(TObject* obj,Int_t j,Int_t k)
5f25234b 1063{
d0a8ef71 1064// Introduce a link (=pointer) to an object for the j-th slot at position k.
5f25234b 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 :
d0a8ef71 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.
5f25234b 1072//
d0a8ef71 1073// If needed, the storage area for the links is increased automatically.
5f25234b 1074//
1075// In case the pointer argument is zero, indeed a value of zero will be
d0a8ef71 1076// stored at the specified position (k) for the specified slot (j).
5f25234b 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
d0a8ef71 1090 if (!fLinks && obj) fLinks=new AliObjMatrix();
5f25234b 1091
d0a8ef71 1092 if (!fLinks) return;
5f25234b 1093
d0a8ef71 1094 // Note : In the internal storage matrix slots=columns positions=rows
1095 fLinks->EnterObject(k,j,obj);
1096 if (obj)
5f25234b 1097 {
d0a8ef71 1098 if (obj->InheritsFrom("AliTrack"))
5f25234b 1099 {
d0a8ef71 1100 AliTrack* t=(AliTrack*)obj;
1101 t->AddSignal(*this);
5f25234b 1102 }
1103 }
1104}
1105///////////////////////////////////////////////////////////////////////////
2cb7369d 1106void 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///////////////////////////////////////////////////////////////////////////
d0a8ef71 1123void 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///////////////////////////////////////////////////////////////////////////
2cb7369d 1168void 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///////////////////////////////////////////////////////////////////////////
d0a8ef71 1186void AliSignal::ResetLink(Int_t j,Int_t k)
5f25234b 1187{
d0a8ef71 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().
5f25234b 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
d0a8ef71 1209 // Note : In the internal storage matrix slots=columns positions=rows
1210 if (fLinks) fLinks->RemoveObject(k,j);
5f25234b 1211}
1212///////////////////////////////////////////////////////////////////////////
2cb7369d 1213void 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///////////////////////////////////////////////////////////////////////////
d0a8ef71 1230void AliSignal::ResetLinks(TObject* obj,Int_t j,Int_t k)
5f25234b 1231{
d0a8ef71 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.
5f25234b 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
d0a8ef71 1273 if (!fLinks) return;
5f25234b 1274
d0a8ef71 1275 if (!obj && !j && !k)
5f25234b 1276 {
d0a8ef71 1277 fLinks->Reset();
5f25234b 1278 }
d0a8ef71 1279 else
1280 {
1281 // Note : In the internal storage matrix slots=columns positions=rows
1282 fLinks->RemoveObjects(obj,k,j);
1283 }
1284}
1285///////////////////////////////////////////////////////////////////////////
2cb7369d 1286void 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///////////////////////////////////////////////////////////////////////////
261c0caf 1309Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,TArrayI& ks) const
d0a8ef71 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///////////////////////////////////////////////////////////////////////////
261c0caf 1343Int_t AliSignal::GetIndices(TObject* obj,Int_t j,TArrayI& ks) const
d0a8ef71 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///////////////////////////////////////////////////////////////////////////
2cb7369d 1379Int_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///////////////////////////////////////////////////////////////////////////
261c0caf 1402Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,Int_t k) const
d0a8ef71 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///////////////////////////////////////////////////////////////////////////
1438void 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///////////////////////////////////////////////////////////////////////////
261c0caf 1457Int_t AliSignal::GetSwapMode() const
d0a8ef71 1458{
1459// Provide swapmode flag of the link storage.
1460 Int_t swap=0;
1461 if (fLinks) swap=fLinks->GetSwapMode();
1462 return swap;
5f25234b 1463}
1464///////////////////////////////////////////////////////////////////////////
965bd237 1465void 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///////////////////////////////////////////////////////////////////////////
1472AliDevice* AliSignal::GetDevice() const
1473{
1474// Provide the pointer to the device which owns this AliSignal object.
1475 return (AliDevice*)fDevice;
1476}
1477///////////////////////////////////////////////////////////////////////////
261c0caf 1478TObject* AliSignal::Clone(const char* name) const
c72198f1 1479{
1c01b4f8 1480// Make a deep copy of the current object and provide the pointer to the copy.
c72198f1 1481// This memberfunction enables automatic creation of new objects of the
1c01b4f8 1482// correct type depending on the object type, a feature which may be very useful
c72198f1 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
1c01b4f8 1486// these derived classes also have a proper Clone memberfunction.
c72198f1 1487
1c01b4f8 1488 AliSignal* sig=new AliSignal(*this);
1489 if (name)
1490 {
1491 if (strlen(name)) sig->SetName(name);
1492 }
c72198f1 1493 return sig;
1494}
1495///////////////////////////////////////////////////////////////////////////