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