05-aug-2005 NvE Typos fixed in AliAttrib::GetCalFunction and AliAttrib::GetDecalFunct...
[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//
b721efb7 22// The user can decide to store either calibrated or uncalibrated signals.
23// Via the specification of a gain and offset or/and an explicit
24// (de)calibration function both calibrated and uncalibrated signals
25// can always be obtained. For details see the documentation of the
26// memberfunction GetSignal() and the class AliAttrib.
27// The explicit specification of a (de)calibration function offers the
28// maximum flexibility and also allows automatic indication whether
29// calibrated or uncalibrated data has been stored.
30// The latter can be achieved by only specifying a calibration function
31// (and no de-calibration function) in case uncalibrated data is stored,
32// whereas in case of stored calibrated data the user should only
33// provide a de-calibration function (and no calibration function).
34//
959fbac5 35// Note :
36// ------
37// Signal positions (r) and reference frames (f) are specified via
38// SetPosition(r,f) under the following conventions :
39//
40// f="car" ==> r is Cartesian (x,y,z)
41// f="sph" ==> r is Spherical (r,theta,phi)
42// f="cyl" ==> r is Cylindrical (rho,phi,z)
43//
44// The same holds for SetPositionErrors().
45//
46// All angles are in radians.
47//
48// Example :
49// ---------
50//
51// AliSignal s;
7a5c405b 52// s.SetName("Start counter");
959fbac5 53// Float_t pos[3]={-1,25,7};
54// Float_t err[3]={0.03,0.7,0.18};
55// Float_t signal=120.8;
56// Float_t error=1.73;
1fbffa23 57// Float_t offset=-12.78;
58// Float_t gain=250;
959fbac5 59// s.SetPosition(pos,"car");
60// s.SetPositionErrors(err,"car");
61// s.SetSignal(signal);
62// s.SetSignalError(error);
1fbffa23 63// s.SetOffset(offset);
64// s.SetGain(gain);
959fbac5 65// Float_t loc[3],dr[3],sigma;
66// s.GetPosition(loc,"sph");
67// s.GetPositionErrors(dr,"sph");
68// Float_t adc=s.GetSignal();
69// Float_t sigma=s.GetSignalError();
70//
c72198f1 71// AliSignal q; // In the example below a signal contains the
959fbac5 72// // following data : timing, ADC and dE/dx
965bd237 73// q.SetNameTitle("Hybrid","Test for multiple signal data");
959fbac5 74// q.SetPosition(pos,"car");
75// q.SetPositionErrors(err,"car");
7a5c405b 76// signal=82.5; // e.g. signal time in ns
959fbac5 77// error=2.01;
1fbffa23 78// offset=0.003;
b721efb7 79// q.SetSlotName("TOF",1);
959fbac5 80// q.SetSignal(signal,1);
81// q.SetSignalError(error,1);
1fbffa23 82// q.SetOffset(offset,1);
959fbac5 83// signal=268.1; // e.g. ADC value of signal
84// error=3.75;
1fbffa23 85// gain=120.78;
b721efb7 86// offset=1.5732;
965bd237 87// // Addressing via name specification instead of index
b721efb7 88// q.SetSlotName("ADC",2);
965bd237 89// q.SetSignal(signal,"ADC");
90// q.SetSignalError(error,"ADC");
91// q.SetGain(gain,"ADC");
b721efb7 92// q.SetOffset(offset,"ADC");
959fbac5 93// signal=23.7; // e.g. corresponding dE/dx value
94// error=0.48;
b721efb7 95// TF1 f=("calib","[0]*pow(x,2)+[1]"); // dE/dx calib. function
96// f.SetParameter(0,3.285);
97// f.SetParameter(1,-18.67);
98// q.SetSlotName("dE/dx",3);
99// q.SetCalFunction(&f,"dE/dx");
100// q.SetSignal(signal,"dE/dx");
101// q.SetSignalError(error,"dE/dx");
102//
103// // Signal retrieval with various (de)calibration modes
104// Float_t tof=q.GetSignal("TOF");
105// Float_t adc=q.GetSignal("ADC",1);
106// Float_t dedx=q.GetSignal("dE/dx",3);
965bd237 107//
959fbac5 108//--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
f531a546 109//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 110///////////////////////////////////////////////////////////////////////////
111
d88f97cc 112#include "AliSignal.h"
5f25234b 113#include "AliTrack.h"
c72198f1 114#include "Riostream.h"
d88f97cc 115
116ClassImp(AliSignal) // Class implementation to enable ROOT I/O
117
1c01b4f8 118AliSignal::AliSignal() : TNamed(),AliPosition(),AliAttrib()
d88f97cc 119{
959fbac5 120// Creation of an AliSignal object and initialisation of parameters.
1fbffa23 121// Several signal values (with errors) can be stored in different slots.
fdadc78a 122// If needed, the storage for values (and errors) will be expanded automatically
123// when entering values and/or errors.
1fbffa23 124 fSignals=0;
125 fDsignals=0;
126 fWaveforms=0;
5f25234b 127 fLinks=0;
965bd237 128 fDevice=0;
d88f97cc 129}
130///////////////////////////////////////////////////////////////////////////
131AliSignal::~AliSignal()
132{
133// Destructor to delete dynamically allocated memory
1fbffa23 134 if (fSignals)
959fbac5 135 {
1fbffa23 136 delete fSignals;
137 fSignals=0;
959fbac5 138 }
1fbffa23 139 if (fDsignals)
959fbac5 140 {
1fbffa23 141 delete fDsignals;
142 fDsignals=0;
959fbac5 143 }
1fbffa23 144 if (fWaveforms)
c72198f1 145 {
1fbffa23 146 delete fWaveforms;
147 fWaveforms=0;
c72198f1 148 }
5f25234b 149 if (fLinks)
150 {
ea0b5b7f 151 // Remove this signal from all related tracks
152 for (Int_t i=1; i<=fLinks->GetNobjects(); i++)
153 {
154 TObject* obj=fLinks->GetObject(i);
155 if (!obj) continue;
156 if (obj->InheritsFrom("AliTrack"))
157 {
158 AliTrack* tx=(AliTrack*)obj;
159 tx->RemoveSignal(*this);
160 }
161 }
5f25234b 162 delete fLinks;
163 fLinks=0;
164 }
d88f97cc 165}
166///////////////////////////////////////////////////////////////////////////
261c0caf 167AliSignal::AliSignal(const AliSignal& s) : TNamed(s),AliPosition(s),AliAttrib(s)
8e8e6c7f 168{
169// Copy constructor
1fbffa23 170 fSignals=0;
171 fDsignals=0;
1fbffa23 172 fWaveforms=0;
5f25234b 173 fLinks=0;
8e8e6c7f 174
965bd237 175 // Don't copy the owning device pointer for the copy
176 fDevice=0;
177
1fbffa23 178 Int_t n=s.GetNvalues();
179 Double_t val;
180 for (Int_t i=1; i<=n; i++)
8e8e6c7f 181 {
1fbffa23 182 val=s.GetSignal(i);
183 SetSignal(val,i);
fdadc78a 184 }
185
1fbffa23 186 n=s.GetNerrors();
187 for (Int_t j=1; j<=n; j++)
fdadc78a 188 {
1fbffa23 189 val=s.GetSignalError(j);
190 SetSignalError(val,j);
c72198f1 191 }
192
1fbffa23 193 n=s.GetNwaveforms();
194 for (Int_t k=1; k<=n; k++)
195 {
196 TH1F* hist=s.GetWaveform(k);
197 if (hist) SetWaveform(hist,k);
198 }
5f25234b 199
d0a8ef71 200 TArrayI slotarr;
201 TArrayI posarr;
202 TObject* dum=0;
203 n=s.GetIndices(dum,slotarr,posarr);
204 Int_t slot,pos;
205 for (Int_t idx=0; idx<n; idx++)
5f25234b 206 {
d0a8ef71 207 slot=slotarr.At(idx);
208 pos=posarr.At(idx);
209 TObject* obj=s.GetLink(slot,pos);
210 if (obj) SetLink(obj,slot,pos);
5f25234b 211 }
8e8e6c7f 212}
213///////////////////////////////////////////////////////////////////////////
fdadc78a 214void AliSignal::Reset(Int_t mode)
d88f97cc 215{
959fbac5 216// Reset all signal and position values and errors to 0.
fdadc78a 217//
218// mode = 0 Reset position and all signal values and their errors to 0.
1fbffa23 219// The waveform histograms are reset, but the calibration
220// constants (i.e. gains and offsets) are kept.
fdadc78a 221// 1 Reset position and delete the signal and error storage arrays.
1fbffa23 222// Also the waveform histograms, gains and offset arrays are deleted.
fdadc78a 223//
224// The default when invoking Reset() corresponds to mode=0.
225//
d0a8ef71 226// Note : In all cases the storage of the various links will be reset.
4f368c8c 227// The UniqueID, name and title will NOT be reset.
228// In case the user wants to reset these attributes, this has to
229// be done explicitly via the SET facilities.
5f25234b 230//
fdadc78a 231// The usage of mode=0 allows to re-use the allocated memory for new
232// signal (and error) values. This behaviour is preferable (i.e. faster)
1fbffa23 233// in case the various signals always contain the same number of values
234// and have the same calibration constants.
fdadc78a 235// The usage of mode=1 is slower, but allows a more efficient memory
236// occupation (and smaller output file size) in case the different
237// signals have a variable number of values.
238//
1fbffa23 239// For more specific actions see ResetPosition(), ResetSignals(),
d0a8ef71 240// DeleteSignals(), ResetGain(), ResetOffset(), ResetLink(), ResetWaveform(),
241// DeleteWaveform() and DeleteCalibrations().
c72198f1 242//
959fbac5 243
fdadc78a 244 if (mode<0 || mode>1)
959fbac5 245 {
fdadc78a 246 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
247 cout << " Default mode=0 will be used." << endl;
248 mode=0;
249 }
250
251 ResetPosition();
252 if (!mode)
253 {
254 ResetSignals();
255 }
256 else
257 {
258 DeleteSignals();
1fbffa23 259 DeleteCalibrations();
959fbac5 260 }
5f25234b 261
d0a8ef71 262 if (fLinks) fLinks->Reset();
965bd237 263 fDevice=0;
959fbac5 264}
265///////////////////////////////////////////////////////////////////////////
fdadc78a 266void AliSignal::ResetSignals(Int_t mode)
959fbac5 267{
fdadc78a 268// Reset various signal data according to user selection.
269//
270// mode = 0 Reset all signal values and their errors to 0.
271// 1 Reset only signal values
272// 2 Reset only signal errors
273//
274// The default when invoking ResetSignals() corresponds to mode=0.
c72198f1 275//
1fbffa23 276// Irrespective of the mode, the waveform histograms are reset.
959fbac5 277
fdadc78a 278 if (mode<0 || mode>2)
279 {
280 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
281 cout << " Default mode=0 will be used." << endl;
282 mode=0;
283 }
284
1fbffa23 285 if (fSignals && (mode==0 || mode==1))
959fbac5 286 {
1fbffa23 287 for (Int_t i=0; i<fSignals->GetSize(); i++)
dafe31a2 288 {
1fbffa23 289 fSignals->AddAt(0,i);
fdadc78a 290 }
291 }
292
1fbffa23 293 if (fDsignals && (mode==0 || mode==2))
fdadc78a 294 {
1fbffa23 295 for (Int_t j=0; j<fDsignals->GetSize(); j++)
fdadc78a 296 {
1fbffa23 297 fDsignals->AddAt(0,j);
dafe31a2 298 }
959fbac5 299 }
c72198f1 300
1fbffa23 301 ResetWaveform(0);
d88f97cc 302}
303///////////////////////////////////////////////////////////////////////////
fdadc78a 304void AliSignal::DeleteSignals(Int_t mode)
305{
306// Delete storage arrays of various signal data according to user selection.
307//
308// mode = 0 Delete arrays of both signal values and their errors.
309// 1 Delete only signal values array
310// 2 Delete only signal errors array
311//
312// The default when invoking DeleteSignals() corresponds to mode=0.
c72198f1 313//
1fbffa23 314// Irrespective of the mode, the waveform histograms are deleted.
fdadc78a 315
316 if (mode<0 || mode>2)
317 {
318 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
319 cout << " Default mode=0 will be used." << endl;
320 mode=0;
321 }
322
1fbffa23 323 if (fSignals && (mode==0 || mode==1))
fdadc78a 324 {
1fbffa23 325 delete fSignals;
326 fSignals=0;
fdadc78a 327 }
328
1fbffa23 329 if (fDsignals && (mode==0 || mode==2))
fdadc78a 330 {
1fbffa23 331 delete fDsignals;
332 fDsignals=0;
fdadc78a 333 }
c72198f1 334
1fbffa23 335 DeleteWaveform(0);
fdadc78a 336}
337///////////////////////////////////////////////////////////////////////////
959fbac5 338void AliSignal::SetSignal(Double_t sig,Int_t j)
d88f97cc 339{
2cb7369d 340// Store signal value for the j-th (default j=1) slot.
1fbffa23 341// Note : The first signal slot is at j=1.
dafe31a2 342// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 343// slots for signal values, the number of reserved slots for the
344// signal values is increased automatically.
959fbac5 345
1fbffa23 346 if (!fSignals)
959fbac5 347 {
1fbffa23 348 fSignals=new TArrayF(j);
fdadc78a 349 ResetSignals(1);
959fbac5 350 }
dafe31a2 351
1fbffa23 352 Int_t size=fSignals->GetSize();
dafe31a2 353
354 if (j>size)
959fbac5 355 {
1fbffa23 356 fSignals->Set(j);
959fbac5 357 }
dafe31a2 358
1fbffa23 359 fSignals->AddAt(float(sig),j-1);
d88f97cc 360}
361///////////////////////////////////////////////////////////////////////////
2cb7369d 362void AliSignal::SetSignal(Double_t sig,TString name)
363{
364// Store signal value for the name-specified slot.
365//
366// This procedure involves a slot-index search based on the specified name
367// at each invokation. This may become slow in case many slots have been
368// defined and/or when this procedure is invoked many times.
369// In such cases it is preferable to use indexed addressing in the user code
370// either directly or via a few invokations of GetSlotIndex().
371
372 Int_t j=GetSlotIndex(name);
373 if (j>0) SetSignal(sig,j);
374}
375///////////////////////////////////////////////////////////////////////////
959fbac5 376void AliSignal::AddSignal(Double_t sig,Int_t j)
377{
2cb7369d 378// Add value to the signal of the j-th (default j=1) slot.
1fbffa23 379// Note : The first signal slot is at j=1.
dafe31a2 380// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 381// slots for signal values, the number of reserved slots for the
382// signal values is increased automatically.
959fbac5 383
1fbffa23 384 if (!fSignals)
959fbac5 385 {
1fbffa23 386 fSignals=new TArrayF(j);
fdadc78a 387 ResetSignals(1);
959fbac5 388 }
dafe31a2 389
1fbffa23 390 Int_t size=fSignals->GetSize();
dafe31a2 391
392 if (j>size)
959fbac5 393 {
1fbffa23 394 fSignals->Set(j);
959fbac5 395 }
dafe31a2 396
1fbffa23 397 Float_t sum=(fSignals->At(j-1))+sig;
398 fSignals->AddAt(sum,j-1);
959fbac5 399}
400///////////////////////////////////////////////////////////////////////////
2cb7369d 401void AliSignal::AddSignal(Double_t sig,TString name)
402{
403// Add value to the signal of the name-specified slot.
404//
405// This procedure involves a slot-index search based on the specified name
406// at each invokation. This may become slow in case many slots have been
407// defined and/or when this procedure is invoked many times.
408// In such cases it is preferable to use indexed addressing in the user code
409// either directly or via a few invokations of GetSlotIndex().
410
411 Int_t j=GetSlotIndex(name);
412 if (j>0) AddSignal(sig,j);
413}
414///////////////////////////////////////////////////////////////////////////
261c0caf 415Float_t AliSignal::GetSignal(Int_t j,Int_t mode) const
959fbac5 416{
2cb7369d 417// Provide signal value of the j-th (default j=1) slot.
1fbffa23 418// Note : The first signal slot is at j=1.
b721efb7 419// In case no signal is present or the input argument "j" or "mode" is invalid,
420// the value 0 is returned.
421// The parameter "mode" allows for automatic (de)calibration of the signal
422// (e.g. gain etc... correction or via explicit (de)calibration functions).
1fbffa23 423//
424// mode = 0 : Just the j-th signal is returned.
425// 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
b721efb7 426// In case the j-th slot was marked dead, 0 is returned.
1fbffa23 427// In case the gain value was not set, gain=1 will be assumed.
428// In case the gain value was 0, a signal value of 0 is returned.
429// In case the offset value was not set, offset=0 will be assumed.
b721efb7 430// 2 : Same as mode=1 but gain, offset dead flag etc... are taken from
431// the AliDevice which owns this AliSignal object.
64c21700 432// The corresponding AliDevice slot is obtained via matching of
433// the slotnames. In case this fails, the slotindex "j" of the
434// input argument will be used.
b721efb7 435// In case this AliSignal object has no parent AliDevice, just
436// the j-th signal is returned (like with mode=0).
437// 3 : The j-th signal is corrected using the corresponding calibration
438// function.
1fbffa23 439// In case the j-th slot was marked dead, 0 is returned.
b721efb7 440// In case no calibration function is present, just the j-th signal
441// is returned (like with mode=0).
442// 4 : Same as mode=3 but the calibration function is taken from
443// the AliDevice which owns this AliSignal object.
64c21700 444// The corresponding AliDevice slot is obtained via matching of
445// the slotnames. In case this fails, the slotindex "j" of the
446// input argument will be used.
b721efb7 447// 5 : Same as mode=2 but in case no parent AliDevice is present
448// an automatic switch to mode=1 will be made.
449// 6 : Same as mode=4 but in case no parent AliDevice is present
450// an automatic switch to mode=3 will be made.
64c21700 451// 7 : Same as mode=3 but in case no calibration function is present
452// an automatic switch to mode=4 will be made.
b721efb7 453//
454// <0 : The corresponding de-correction or de-calibration is performed
1fbffa23 455//
456// The corrected signal (sigc) is determined as follows :
457//
458// sigc=(signal/gain)-offset
459//
b721efb7 460// The de-corrected signal is determined as follows :
461//
462// signal=(sigc+offset)*gain
463//
1fbffa23 464// The default is mode=0.
465
64c21700 466 if (abs(mode)>7) return 0;
b721efb7 467
64c21700 468 Int_t jcal=j;
fdadc78a 469 Float_t sig=0;
1fbffa23 470 Float_t gain=1;
471 Float_t offset=0;
b721efb7 472
473 AliSignal* sx=(AliSignal*)this;
64c21700 474
475 TF1* f=0;
476 if (mode==7)
477 {
478 f=sx->GetCalFunction(jcal);
479 if (f)
480 {
481 mode=3;
482 }
483 else
484 {
485 mode=4;
486 }
487 }
488 if (mode==-7)
489 {
490 f=sx->GetDecalFunction(jcal);
491 if (f)
492 {
493 mode=-3;
494 }
495 else
496 {
497 mode=-4;
498 }
499 }
500
501 if (abs(mode)==2 || abs(mode)>=4)
502 {
503 sx=(AliSignal*)GetDevice();
504 if (sx)
505 {
506 TString name=GetSlotName(j);
507 if (strlen(name.Data())) jcal=sx->GetSlotIndex(name);
508 if (!jcal) jcal=j;
509 }
510 }
b721efb7 511 if (!sx && abs(mode)>=5) sx=(AliSignal*)this;
512 if (mode==5) mode=2;
513 if (mode==-5) mode=-2;
514 if (mode==6) mode=3;
515 if (mode==-6) mode=-3;
516
1fbffa23 517 if (fSignals)
959fbac5 518 {
1fbffa23 519 if (j>0 && j<=(fSignals->GetSize()))
fdadc78a 520 {
1fbffa23 521 sig=fSignals->At(j-1);
522
b721efb7 523 if (mode==0 || !sx) return sig;
1fbffa23 524
b721efb7 525 // Check for the dead flag setting
64c21700 526 if (sx->GetDeadValue(jcal)) return 0;
1fbffa23 527
b721efb7 528 // (De)correct the signal for the gain and offset
529 if (abs(mode)==1 || abs(mode)==2)
1fbffa23 530 {
64c21700 531 if (sx->GetGainFlag(jcal)) gain=sx->GetGain(jcal);
532 if (sx->GetOffsetFlag(jcal)) offset=sx->GetOffset(jcal);
b721efb7 533
534 if (fabs(gain)>0.)
535 {
536 if (mode>0) sig=(sig/gain)-offset; // Gain and offset correction
537 if (mode<0) sig=(sig+offset)*gain; // Gain and offset de-correction
538 }
539 else
540 {
541 sig=0;
542 }
543 return sig;
1fbffa23 544 }
b721efb7 545
546 // (De)calibrate the signal with the corresponding (de)calibration function
547 if (abs(mode)==3 || abs(mode)==4)
1fbffa23 548 {
64c21700 549 f=sx->GetCalFunction(jcal);
550 if (mode<0) f=sx->GetDecalFunction(jcal);
b721efb7 551 if (f) sig=f->Eval(sig);
552 return sig;
1fbffa23 553 }
fdadc78a 554 }
555 else
556 {
557 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
558 }
959fbac5 559 }
fdadc78a 560 return sig;
959fbac5 561}
562///////////////////////////////////////////////////////////////////////////
2cb7369d 563Float_t AliSignal::GetSignal(TString name,Int_t mode) const
564{
565// Provide signal value of the name-specified slot.
566// In case no signal is present, 0 is returned.
64c21700 567// The parameter "mode" allows for automatic (de)calibration of the signal
568// (e.g. gain etc... correction or via explicit (de)calibration functions).
569// For further details about the (de)calibration modes, please refer to the
570// corresponding slot-index based memberfunction.
2cb7369d 571//
572// The default is mode=0.
573//
574// This procedure involves a slot-index search based on the specified name
575// at each invokation. This may become slow in case many slots have been
576// defined and/or when this procedure is invoked many times.
577// In such cases it is preferable to use indexed addressing in the user code
578// either directly or via a few invokations of GetSlotIndex().
579
580 Int_t j=GetSlotIndex(name);
581 Float_t val=0;
582 if (j>0) val=GetSignal(j,mode);
583 return val;
584}
585///////////////////////////////////////////////////////////////////////////
959fbac5 586void AliSignal::SetSignalError(Double_t dsig,Int_t j)
587{
2cb7369d 588// Store error on the signal for the j-th (default j=1) slot.
1fbffa23 589// Note : The first signal slot is at j=1.
dafe31a2 590// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 591// slots for signal error values, the number of reserved slots for the
592// signal errors is increased automatically.
959fbac5 593
1fbffa23 594 if (!fDsignals)
959fbac5 595 {
1fbffa23 596 fDsignals=new TArrayF(j);
fdadc78a 597 ResetSignals(2);
959fbac5 598 }
dafe31a2 599
1fbffa23 600 Int_t size=fDsignals->GetSize();
dafe31a2 601
602 if (j>size)
959fbac5 603 {
1fbffa23 604 fDsignals->Set(j);
959fbac5 605 }
dafe31a2 606
1fbffa23 607 fDsignals->AddAt(float(dsig),j-1);
959fbac5 608}
609///////////////////////////////////////////////////////////////////////////
2cb7369d 610void AliSignal::SetSignalError(Double_t dsig,TString name)
611{
612// Store error on the signal for the name-specified slot.
613//
614// This procedure involves a slot-index search based on the specified name
615// at each invokation. This may become slow in case many slots have been
616// defined and/or when this procedure is invoked many times.
617// In such cases it is preferable to use indexed addressing in the user code
618// either directly or via a few invokations of GetSlotIndex().
619
620 Int_t j=GetSlotIndex(name);
621 if (j>0) SetSignalError(dsig,j);
622}
623///////////////////////////////////////////////////////////////////////////
261c0caf 624Float_t AliSignal::GetSignalError(Int_t j) const
959fbac5 625{
2cb7369d 626// Provide error on the signal of the j-th (default j=1) slot.
1fbffa23 627// Note : The first signal slot is at j=1.
fdadc78a 628// In case no signal is present or the argument j is invalid, 0 is returned.
629 Float_t err=0;
1fbffa23 630 if (fDsignals)
959fbac5 631 {
1fbffa23 632 if (j>0 && j<=(fDsignals->GetSize()))
fdadc78a 633 {
1fbffa23 634 err=fDsignals->At(j-1);
fdadc78a 635 }
636 else
637 {
638 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
639 }
959fbac5 640 }
fdadc78a 641 return err;
959fbac5 642}
643///////////////////////////////////////////////////////////////////////////
2cb7369d 644Float_t AliSignal::GetSignalError(TString name) const
645{
646// Provide error on the signal of the name-specified slot.
647//
648// This procedure involves a slot-index search based on the specified name
649// at each invokation. This may become slow in case many slots have been
650// defined and/or when this procedure is invoked many times.
651// In such cases it is preferable to use indexed addressing in the user code
652// either directly or via a few invokations of GetSlotIndex().
653
654 Int_t j=GetSlotIndex(name);
655 Float_t val=0;
656 if (j>0) val=GetSignalError(j);
657 return val;
658}
659///////////////////////////////////////////////////////////////////////////
261c0caf 660void AliSignal::Data(TString f) const
1c01b4f8 661{
662// Provide all signal information within the coordinate frame f.
663
5f25234b 664 const char* name=GetName();
665 const char* title=GetTitle();
666
f67e2651 667 cout << " *" << ClassName() << "::Data* Id : " << GetUniqueID();
5f25234b 668 if (strlen(name)) cout << " Name : " << name;
669 if (strlen(title)) cout << " Title : " << title;
670 cout << endl;
d0a8ef71 671 cout << " Position";
a7dc0627 672 AliPosition::Data(f);
965bd237 673 if (fDevice)
674 {
675 const char* devname=fDevice->GetName();
676 const char* devtitle=fDevice->GetTitle();
f67e2651 677 cout << " Owned by device : " << fDevice->ClassName()
678 << " Id : " << fDevice->GetUniqueID();
965bd237 679 if (strlen(devname)) cout << " Name : " << devname;
680 if (strlen(devtitle)) cout << " Title : " << devtitle;
681 cout << endl;
682 }
1c01b4f8 683
6a8254a0 684 // Provide an overview of the stored waveforms
685 ListWaveform(-1);
686
687 // Provide an overview of all the data and attribute slots
1c01b4f8 688 List(-1);
689}
690///////////////////////////////////////////////////////////////////////////
261c0caf 691void AliSignal::List(Int_t j) const
959fbac5 692{
1c01b4f8 693// Provide signal information for the j-th slot.
1fbffa23 694// The first slot is at j=1.
695// In case j=0 (default) the data of all slots will be listed.
1c01b4f8 696// In case j=-1 the data of all slots will be listed, but the header
697// information will be suppressed.
1fbffa23 698
1c01b4f8 699 if (j<-1)
1fbffa23 700 {
1c01b4f8 701 cout << " *AliSignal::List* Invalid argument j = " << j << endl;
1fbffa23 702 return;
703 }
704
5f25234b 705 if (j != -1)
706 {
707 const char* name=GetName();
708 const char* title=GetTitle();
709
6a8254a0 710 cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
5f25234b 711 if (strlen(name)) cout << " Name : " << name;
712 if (strlen(title)) cout << " Title : " << title;
713 cout << endl;
6a8254a0 714 if (fDevice)
715 {
716 const char* devname=fDevice->GetName();
717 const char* devtitle=fDevice->GetTitle();
718 cout << " Owned by device : " << fDevice->ClassName();
719 if (strlen(devname)) cout << " Name : " << devname;
720 if (strlen(devtitle)) cout << " Title : " << devtitle;
721 cout << endl;
722 }
5f25234b 723 }
fdadc78a 724
725 Int_t nvalues=GetNvalues();
726 Int_t nerrors=GetNerrors();
d0a8ef71 727 Int_t nlinkslots=0;
728 if (fLinks) nlinkslots=fLinks->GetMaxColumn();
b721efb7 729 Int_t ncalibs=GetNcalflags();
730 Int_t ncalfuncs=GetNcalfuncs();
731 Int_t ndecalfuncs=GetNdecalfuncs();
732
1fbffa23 733 Int_t n=nvalues;
734 if (nerrors>n) n=nerrors;
d0a8ef71 735 if (nlinkslots>n) n=nlinkslots;
b721efb7 736 if (InheritsFrom("AliDevice"))
737 {
738 if (ncalibs>n) n=ncalibs;
739 if (ncalfuncs>n) n=ncalfuncs;
740 if (ndecalfuncs>n) n=ndecalfuncs;
741 }
742
5f25234b 743 TObject* obj=0;
d0a8ef71 744 Int_t nrefs=0;
745 TArrayI posarr;
746 Int_t pos;
fdadc78a 747
1c01b4f8 748 if (j<=0)
959fbac5 749 {
1fbffa23 750 for (Int_t i=1; i<=n; i++)
959fbac5 751 {
d0a8ef71 752 cout << " Slot : " << i;
753 if (i<=nvalues) cout << " Signal value : " << GetSignal(i);
1fbffa23 754 if (i<=nerrors) cout << " error : " << GetSignalError(i);
1c01b4f8 755 AliAttrib::List(i);
1fbffa23 756 cout << endl;
d0a8ef71 757 obj=0;
758 nrefs=GetIndices(obj,i,posarr);
759 for (Int_t k=0; k<nrefs; k++)
5f25234b 760 {
d0a8ef71 761 pos=posarr.At(k);
762 obj=GetLink(i,pos);
763 if (obj)
03b59bc9 764 {
d0a8ef71 765 cout << " Link at position " << pos << " to : " << obj->ClassName();
766 if (obj->InheritsFrom("TNamed"))
767 {
768 const char* lname=obj->GetName();
769 const char* ltitle=obj->GetTitle();
770 if (strlen(lname)) cout << " Name : " << lname;
771 if (strlen(ltitle)) cout << " Title : " << ltitle;
772 }
773 cout << endl;
03b59bc9 774 }
5f25234b 775 }
1fbffa23 776 }
777 }
778 else
779 {
780 if (j<=n)
781 {
d0a8ef71 782 cout << " Slot : " << j;
783 if (j<=nvalues) cout << " Signal value : " << GetSignal(j);
1fbffa23 784 if (j<=nerrors) cout << " error : " << GetSignalError(j);
1c01b4f8 785 AliAttrib::List(j);
fdadc78a 786 cout << endl;
d0a8ef71 787 obj=0;
788 nrefs=GetIndices(obj,j,posarr);
789 for (Int_t kj=0; kj<nrefs; kj++)
5f25234b 790 {
d0a8ef71 791 pos=posarr.At(kj);
792 obj=GetLink(j,pos);
793 if (obj)
03b59bc9 794 {
d0a8ef71 795 cout << " Link at position " << pos << " to : " << obj->ClassName();
796 if (obj->InheritsFrom("TNamed"))
797 {
798 const char* lnamej=obj->GetName();
799 const char* ltitlej=obj->GetTitle();
800 if (strlen(lnamej)) cout << " Name : " << lnamej;
801 if (strlen(ltitlej)) cout << " Title : " << ltitlej;
802 }
803 cout << endl;
03b59bc9 804 }
5f25234b 805 }
959fbac5 806 }
807 }
808}
809///////////////////////////////////////////////////////////////////////////
2cb7369d 810void AliSignal::List(TString name) const
811{
812// Provide signal information for the name-specified slot.
813//
814// This procedure involves a slot-index search based on the specified name
815// at each invokation. This may become slow in case many slots have been
816// defined and/or when this procedure is invoked many times.
817// In such cases it is preferable to use indexed addressing in the user code
818// either directly or via a few invokations of GetSlotIndex().
819
820 Int_t j=GetSlotIndex(name);
821 if (j>0) List(j);
822}
823///////////////////////////////////////////////////////////////////////////
6a8254a0 824void AliSignal::ListWaveform(Int_t j) const
825{
826// Provide information for the j-th waveform.
827// The first waveform is at j=1.
828// In case j=0 (default) the info of all waveforms will be listed.
829// In case j=-1 the info of all waveforms will be listed, but the header
830// information will be suppressed.
831
832 if (j<-1)
833 {
834 cout << " *AliSignal::ListWaveform* Invalid argument j = " << j << endl;
835 return;
836 }
837
838 if (j != -1)
839 {
840 const char* name=GetName();
841 const char* title=GetTitle();
842
843 cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
844 if (strlen(name)) cout << " Name : " << name;
845 if (strlen(title)) cout << " Title : " << title;
846 cout << endl;
847 if (fDevice)
848 {
849 const char* devname=fDevice->GetName();
850 const char* devtitle=fDevice->GetTitle();
851 cout << " Owned by device : " << fDevice->ClassName();
852 if (strlen(devname)) cout << " Name : " << devname;
853 if (strlen(devtitle)) cout << " Title : " << devtitle;
854 cout << endl;
855 }
856 }
857
858 Int_t n=GetNwaveforms();
859 TObject* obj=0;
860
861 if (j<=0)
862 {
863 for (Int_t i=1; i<=n; i++)
864 {
865 obj=GetWaveform(i);
866 if (obj)
867 {
868 const char* wfname=obj->GetName();
869 const char* wftitle=obj->GetTitle();
870 cout << " Waveform " << i << " : " << obj->ClassName();
871 if (strlen(wfname)) cout << " Name : " << wfname;
872 if (strlen(wftitle)) cout << " Title : " << wftitle;
873 cout << endl;
874 }
875 }
876 }
877 else
878 {
879 if (j<=n)
880 {
881 obj=GetWaveform(j);
882 if (obj)
883 {
884 const char* wfnamej=obj->GetName();
885 const char* wftitlej=obj->GetTitle();
886 cout << " Waveform " << j << " : " << obj->ClassName();
887 if (strlen(wfnamej)) cout << " Name : " << wfnamej;
888 if (strlen(wftitlej)) cout << " Title : " << wftitlej;
889 cout << endl;
890 }
891 }
892 }
893}
894///////////////////////////////////////////////////////////////////////////
261c0caf 895Int_t AliSignal::GetNvalues() const
8e8e6c7f 896{
897// Provide the number of values for this signal.
dafe31a2 898 Int_t n=0;
1fbffa23 899 if (fSignals) n=fSignals->GetSize();
fdadc78a 900 return n;
901}
902///////////////////////////////////////////////////////////////////////////
261c0caf 903Int_t AliSignal::GetNerrors() const
fdadc78a 904{
905// Provide the number specified errors on the values for this signal.
906 Int_t n=0;
1fbffa23 907 if (fDsignals) n=fDsignals->GetSize();
dafe31a2 908 return n;
8e8e6c7f 909}
910///////////////////////////////////////////////////////////////////////////
261c0caf 911Int_t AliSignal::GetNwaveforms() const
c72198f1 912{
a80c27d9 913// Provide the number of specified waveforms for this signal.
914// Actually the return value is the highest index of the stored waveforms.
915// This allows an index dependent meaning of waveform info (e.g. waveforms
916// with various gain values).
917// So, when all waveforms are stored in consequetive positions (e.g. 1,2,3),
918// this memberfunction returns 3, being both the highest filled position
919// and the actual number of waveforms.
920// In case only waveforms are stored at positions 1,2,5,7 this memberfunction
921// returns a value 7 whereas only 4 actual waveforms are present.
922// This implies that when looping over the various waveform slots, one
923// always has to check whether the returned pointer value is non-zero
924// (which is a good practice anyhow).
925 Int_t n=-1;
926 if (fWaveforms) n=fWaveforms->GetLast();
927 return (n+1);
c72198f1 928}
929///////////////////////////////////////////////////////////////////////////
261c0caf 930TH1F* AliSignal::GetWaveform(Int_t j) const
c72198f1 931{
6a8254a0 932// Provide pointer to the j-th waveform histogram.
1fbffa23 933 TH1F* waveform=0;
934 if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
935 return waveform;
936}
937///////////////////////////////////////////////////////////////////////////
2cb7369d 938TH1F* AliSignal::GetWaveform(TString name) const
939{
6a8254a0 940// Provide pointer to the waveform histogram with the specified name.
941// In case no match is found, zero is returned.
942 Int_t n=GetNwaveforms();
943 TString str;
944 for (Int_t i=1; i<=n; i++)
945 {
946 TH1F* waveform=GetWaveform(i);
947 if (waveform)
948 {
949 str=waveform->GetName();
950 if (str == name) return waveform;
951 }
952 }
953 return 0; // No match found
954}
955///////////////////////////////////////////////////////////////////////////
956Int_t AliSignal::GetWaveformIndex(TString name) const
957{
958// Provide index to the waveform histogram with the specified name.
959// In case no match is found, zero is returned.
960 Int_t n=GetNwaveforms();
961 TString str;
962 for (Int_t i=1; i<=n; i++)
963 {
964 TH1F* waveform=GetWaveform(i);
965 if (waveform)
966 {
967 str=waveform->GetName();
968 if (str == name) return i;
969 }
970 }
971 return 0; // No match found
2cb7369d 972}
973///////////////////////////////////////////////////////////////////////////
1fbffa23 974void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
975{
6a8254a0 976// Set the 1D waveform histogram for the j-th waveform.
1fbffa23 977//
978// Notes :
6a8254a0 979// The first waveform position at j=1.
1fbffa23 980// j=1 is the default value.
981//
982// In case the value of the index j exceeds the maximum number of reserved
6a8254a0 983// positions for the waveforms, the number of reserved positions for the waveforms
1fbffa23 984// is increased automatically.
c72198f1 985//
1fbffa23 986// In case the histo pointer argument has the same value as the current waveform
c72198f1 987// histogram pointer value, no action is taken since the user has already
988// modified the actual histogram.
989//
1fbffa23 990// In case the histo pointer argument is zero, the current waveform histogram
c72198f1 991// is deleted and the pointer set to zero.
992//
993// In all other cases the current waveform histogram is deleted and a new
994// copy of the input histogram is created which becomes the current waveform
995// histogram.
996
6a8254a0 997 if (j<1) return;
998
1fbffa23 999 if (!fWaveforms)
1000 {
1001 fWaveforms=new TObjArray(j);
1002 fWaveforms->SetOwner();
1003 }
1004
1005 if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
1006
1007 TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
1008 if (waveform != hcur)
c72198f1 1009 {
1fbffa23 1010 if (hcur)
c72198f1 1011 {
1fbffa23 1012 fWaveforms->Remove(hcur);
1013 delete hcur;
1014 hcur=0;
1015 }
1016 if (waveform)
1017 {
1018 hcur=new TH1F(*waveform);
1019 fWaveforms->AddAt(hcur,j-1);
c72198f1 1020 }
c72198f1 1021 }
1022}
1023///////////////////////////////////////////////////////////////////////////
1fbffa23 1024void AliSignal::ResetWaveform(Int_t j)
1025{
6a8254a0 1026// Reset the histogram of the j-th (default j=1) waveform.
1fbffa23 1027// This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
1028// To actually delete the histograms from memory, use DeleteWaveform().
6a8254a0 1029// Notes : The first position is at j=1.
1fbffa23 1030// j=0 ==> All waveforms will be reset.
1031
1032 if (!fWaveforms) return;
1033
1034 Int_t size=fWaveforms->GetSize();
1035
1036 if ((j>=0) && (j<=size))
1037 {
1038 if (j)
1039 {
1040 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
1041 if (hwave) hwave->Reset();
1042 }
1043 else
1044 {
1045 for (Int_t i=0; i<size; i++)
1046 {
1047 TH1F* hwave=(TH1F*)fWaveforms->At(i);
1048 if (hwave) hwave->Reset();
1049 }
1050 }
1051 }
1052 else
1053 {
1054 cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
1055 return;
1056 }
1057}
1058///////////////////////////////////////////////////////////////////////////
2cb7369d 1059void AliSignal::ResetWaveform(TString name)
1060{
6a8254a0 1061// Reset the waveform with the specified name.
1062 Int_t j=GetWaveformIndex(name);
2cb7369d 1063 if (j>0) ResetWaveform(j);
1064}
1065///////////////////////////////////////////////////////////////////////////
1fbffa23 1066void AliSignal::DeleteWaveform(Int_t j)
1067{
6a8254a0 1068// Delete the histogram of the j-th (default j=1) waveform.
1069// Notes : The first position is at j=1.
1fbffa23 1070// j=0 ==> All waveforms will be deleted.
1071
1072 if (!fWaveforms) return;
1073
1074 Int_t size=fWaveforms->GetSize();
1075
1076 if ((j>=0) && (j<=size))
1077 {
1078 if (j)
1079 {
1080 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
1081 if (hwave)
1082 {
1083 fWaveforms->Remove(hwave);
1084 delete hwave;
1085 }
1086 }
1087 else
1088 {
1089 delete fWaveforms;
1090 fWaveforms=0;
1091 }
1092 }
1093 else
1094 {
1095 cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
1096 return;
1097 }
1098}
1099///////////////////////////////////////////////////////////////////////////
2cb7369d 1100void AliSignal::DeleteWaveform(TString name)
1101{
6a8254a0 1102// Delete the waveform with the specified name.
1103 Int_t j=GetWaveformIndex(name);
2cb7369d 1104 if (j>0) DeleteWaveform(j);
1105}
1106///////////////////////////////////////////////////////////////////////////
261c0caf 1107Int_t AliSignal::GetNlinks(TObject* obj,Int_t j) const
5f25234b 1108{
d0a8ef71 1109// Provide the number of links to the specified object for the j-th slot.
1110// If j=0 (default) all slots will be scanned for the specified object.
1111// If obj=0 (default) all encountered objects for the specified slot will be counted.
1112// So, invokation of the default GetNlinks() will return the total number of
1113// all references to all sorts of stored objects.
1114 if (j<0)
1115 {
1116 cout << " *AliSignal::GetNlinks* Index j = " << j << " invalid." << endl;
1117 return 0;
1118 }
1119
5f25234b 1120 Int_t n=0;
d0a8ef71 1121 if (!j)
1122 {
7a086578 1123 if (fLinks) n=fLinks->GetNrefs(obj);
d0a8ef71 1124 }
1125 else
1126 {
1127 TArrayI posarr;
1128 n=GetIndices(obj,j,posarr);
1129 }
5f25234b 1130 return n;
1131}
1132///////////////////////////////////////////////////////////////////////////
2cb7369d 1133Int_t AliSignal::GetNlinks(TObject* obj,TString name) const
1134{
1135// Provide the number of links to the specified object for the name-spec. slot.
1136// If obj=0 all encountered objects for the specified slot will be counted.
1137//
1138// This procedure involves a slot-index search based on the specified name
1139// at each invokation. This may become slow in case many slots have been
1140// defined and/or when this procedure is invoked many times.
1141// In such cases it is preferable to use indexed addressing in the user code
1142// either directly or via a few invokations of GetSlotIndex().
1143
1144 Int_t j=GetSlotIndex(name);
1145 Int_t n=0;
1146 if (j>0) n=GetNlinks(obj,j);
1147 return n;
1148}
1149///////////////////////////////////////////////////////////////////////////
261c0caf 1150TObject* AliSignal::GetLink(Int_t j,Int_t k) const
5f25234b 1151{
d0a8ef71 1152// Provide pointer of the object linked to the j-th slot at position k.
1153
5f25234b 1154 TObject* obj=0;
d0a8ef71 1155 // Note : In the internal storage matrix slots=columns positions=rows
1156 if (fLinks) obj=fLinks->GetObject(k,j);
5f25234b 1157 return obj;
1158}
1159///////////////////////////////////////////////////////////////////////////
2cb7369d 1160TObject* AliSignal::GetLink(TString name,Int_t k) const
1161{
1162// Provide pointer of the object linked to the name-spec. slot at position k.
1163//
1164// This procedure involves a slot-index search based on the specified name
1165// at each invokation. This may become slow in case many slots have been
1166// defined and/or when this procedure is invoked many times.
1167// In such cases it is preferable to use indexed addressing in the user code
1168// either directly or via a few invokations of GetSlotIndex().
1169
1170 Int_t j=GetSlotIndex(name);
1171 TObject* obj=0;
1172 if (j>0) obj=GetLink(j,k);
1173 return obj;
1174}
1175///////////////////////////////////////////////////////////////////////////
d0a8ef71 1176void AliSignal::SetLink(TObject* obj,Int_t j,Int_t k)
5f25234b 1177{
d0a8ef71 1178// Introduce a link (=pointer) to an object for the j-th slot at position k.
5f25234b 1179// Only the pointer values are stored for (backward) reference, meaning
1180// that the objects of which the pointers are stored are NOT owned
1181// by the AliSignal object.
1182//
1183// Notes :
d0a8ef71 1184// The first slot is at j=1 and the first position is at k=1.
1185// j=1 and k=1 are the default values.
5f25234b 1186//
d0a8ef71 1187// If needed, the storage area for the links is increased automatically.
5f25234b 1188//
1189// In case the pointer argument is zero, indeed a value of zero will be
d0a8ef71 1190// stored at the specified position (k) for the specified slot (j).
5f25234b 1191//
1192// In principle any object derived from TObject can be referred to by this
1193// mechanism.
1194// However, this "linking back" facility was introduced to enable AliSignal slots
1195// to refer directly to the various AliTracks to which the AliSignal object itself
1196// is related (see AliTrack::AddSignal).
1197// Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1198// object, the current signal is automatically related to this AliTrack
1199// (or derived) object.
1200//
1201// Please also have a look at the docs of the memberfunction ResetLink()
1202// to prevent the situation of stored pointers to non-existent object.
1203
d0a8ef71 1204 if (!fLinks && obj) fLinks=new AliObjMatrix();
5f25234b 1205
d0a8ef71 1206 if (!fLinks) return;
5f25234b 1207
d0a8ef71 1208 // Note : In the internal storage matrix slots=columns positions=rows
1209 fLinks->EnterObject(k,j,obj);
1210 if (obj)
5f25234b 1211 {
d0a8ef71 1212 if (obj->InheritsFrom("AliTrack"))
5f25234b 1213 {
d0a8ef71 1214 AliTrack* t=(AliTrack*)obj;
1215 t->AddSignal(*this);
5f25234b 1216 }
1217 }
1218}
1219///////////////////////////////////////////////////////////////////////////
2cb7369d 1220void AliSignal::SetLink(TObject* obj,TString name,Int_t k)
1221{
1222// Introduce a link (=pointer) to an object for the name-spec. slot at position k.
1223// Only the pointer values are stored for (backward) reference, meaning
1224// that the objects of which the pointers are stored are NOT owned
1225// by the AliSignal object.
1226//
1227// This procedure involves a slot-index search based on the specified name
1228// at each invokation. This may become slow in case many slots have been
1229// defined and/or when this procedure is invoked many times.
1230// In such cases it is preferable to use indexed addressing in the user code
1231// either directly or via a few invokations of GetSlotIndex().
1232
1233 Int_t j=GetSlotIndex(name);
1234 if (j>0) SetLink(obj,j,k);
1235}
1236///////////////////////////////////////////////////////////////////////////
d0a8ef71 1237void AliSignal::AddLink(TObject* obj,Int_t j)
1238{
1239// Introduce a link (=pointer) to an object for the j-th slot at the first
1240// free position.
1241// Only the pointer values are stored for (backward) reference, meaning
1242// that the objects of which the pointers are stored are NOT owned
1243// by the AliSignal object.
1244//
1245// Notes :
1246// The first slot is at j=1 and the first position is at k=1.
1247// j=1 is the default value.
1248//
1249// If needed, the storage area for the links is increased automatically.
1250//
1251// In case the pointer argument is zero, no link will be added.
1252//
1253// In principle any object derived from TObject can be referred to by this
1254// mechanism.
1255// However, this "linking back" facility was introduced to enable AliSignal slots
1256// to refer directly to the various AliTracks to which the AliSignal object itself
1257// is related (see AliTrack::AddSignal).
1258// Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1259// object, the current signal is automatically related to this AliTrack
1260// (or derived) object.
1261//
1262// Please also have a look at the docs of the memberfunction ResetLink()
1263// to prevent the situation of stored pointers to non-existent object.
1264
1265 if (!obj || j<=0) return;
1266
1267 if (!fLinks) fLinks=new AliObjMatrix();
1268
1269 TObject* dum=0;
1270 Int_t n=GetNlinks(dum,j);
1271 Int_t pos=1;
1272 for (Int_t k=1; k<=n; k++)
1273 {
1274 dum=GetLink(j,k);
1275 if (!dum) break;
1276 pos++;
1277 }
1278
1279 SetLink(obj,j,pos);
1280}
1281///////////////////////////////////////////////////////////////////////////
2cb7369d 1282void AliSignal::AddLink(TObject* obj,TString name)
1283{
1284// Introduce a link (=pointer) to an object for the name-spec slot at the first
1285// free position.
1286// Only the pointer values are stored for (backward) reference, meaning
1287// that the objects of which the pointers are stored are NOT owned
1288// by the AliSignal object.
1289//
1290// This procedure involves a slot-index search based on the specified name
1291// at each invokation. This may become slow in case many slots have been
1292// defined and/or when this procedure is invoked many times.
1293// In such cases it is preferable to use indexed addressing in the user code
1294// either directly or via a few invokations of GetSlotIndex().
1295
1296 Int_t j=GetSlotIndex(name);
1297 if (j>0) AddLink(obj,j);
1298}
1299///////////////////////////////////////////////////////////////////////////
d0a8ef71 1300void AliSignal::ResetLink(Int_t j,Int_t k)
5f25234b 1301{
d0a8ef71 1302// Reset the link of the j-th slot at position k.
1303//
1304// Notes :
1305// The first slot is at j=1 and the first position is at k=1.
1306// j=1 and k=1 are the default values.
1307//
1308// This memberfunction is intended to reset only 1 specified link location.
1309// For extended functionality, please refer to the memberfuction ResetLinks().
5f25234b 1310//
1311// In general the user should take care of properly clearing the corresponding
1312// pointer here when the referred object is deleted.
1313// However, this "linking back" facility was introduced to enable AliSignal slots
1314// to refer directly to the various AliTracks to which the AliSignal object itself
1315// is related (see AliTrack::AddSignal).
1316// As such, the AliTrack destructor already takes care of clearing the corresponding
1317// links from the various AliSignal slots for all the AliSignal objects that were
1318// related to that AliTrack.
1319// So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1320// the user doesn't have to worry about clearing the corresponding AliTrack link from
1321// the AliSignal object when the corresponding AliTrack object is deleted.
1322
d0a8ef71 1323 // Note : In the internal storage matrix slots=columns positions=rows
1324 if (fLinks) fLinks->RemoveObject(k,j);
5f25234b 1325}
1326///////////////////////////////////////////////////////////////////////////
2cb7369d 1327void AliSignal::ResetLink(TString name,Int_t k)
1328{
1329// Reset the link of the name-specified slot at position k.
1330//
1331// This memberfunction is intended to reset only 1 specified link location.
1332// For extended functionality, please refer to the memberfuction ResetLinks().
1333//
1334// This procedure involves a slot-index search based on the specified name
1335// at each invokation. This may become slow in case many slots have been
1336// defined and/or when this procedure is invoked many times.
1337// In such cases it is preferable to use indexed addressing in the user code
1338// either directly or via a few invokations of GetSlotIndex().
1339
1340 Int_t j=GetSlotIndex(name);
1341 if (j>0) ResetLink(j,k);
1342}
1343///////////////////////////////////////////////////////////////////////////
d0a8ef71 1344void AliSignal::ResetLinks(TObject* obj,Int_t j,Int_t k)
5f25234b 1345{
d0a8ef71 1346// Reset single or multiple link(s) according to user specified selections.
1347//
1348// A link is only reset if the stored reference matches the argument "obj".
1349// In case obj=0 no check on the matching of the stored reference is performed
1350// and the stored link is always reset in accordance with the other
1351// selection criteria.
1352//
1353// In case the slot argument "j" is specified, only the links from that
1354// specified slot will be deleted.
1355// In case j=0 (default) no checking on the slot index is performed.
1356//
1357// In case the position argument "k" is specified, only the links from that
1358// specified position will be deleted.
1359// In case k=0 (default) no checking on the position index is performed.
1360//
1361// So, invokation of ResetLinks(obj) will remove all references to the
1362// object "obj" from the total AliSignal, whereas ResetLinks(obj,j)
1363// will remove all references to the object "obj" only from slot "j".
1364//
1365// Notes :
1366// -------
1367// The first slot is indicated as j=1, whereas the first position is at k=1.
1368//
1369// Invokation of ResetLinks(0,row,col) is equivalent to invoking the
1370// memberfunction ResetLink(row,col).
1371// Invoking the latter directly is slightly faster.
1372//
1373// Invokation of ResetLinks(0) will reset all stored references in this AliSignal.
5f25234b 1374//
1375// In general the user should take care of properly clearing the corresponding
1376// pointer here when the referred object is deleted.
1377// However, this "linking back" facility was introduced to enable AliSignal slots
1378// to refer directly to the various AliTracks to which the AliSignal object itself
1379// is related (see AliTrack::AddSignal).
1380// As such, the AliTrack destructor already takes care of clearing the corresponding
1381// links from the various AliSignal slots for all the AliSignal objects that were
1382// related to that AliTrack.
1383// So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1384// the user doesn't have to worry about clearing the corresponding AliTrack link from
1385// the AliSignal object when the corresponding AliTrack object is deleted.
1386
d0a8ef71 1387 if (!fLinks) return;
5f25234b 1388
d0a8ef71 1389 if (!obj && !j && !k)
5f25234b 1390 {
d0a8ef71 1391 fLinks->Reset();
5f25234b 1392 }
d0a8ef71 1393 else
1394 {
1395 // Note : In the internal storage matrix slots=columns positions=rows
1396 fLinks->RemoveObjects(obj,k,j);
1397 }
1398}
1399///////////////////////////////////////////////////////////////////////////
2cb7369d 1400void AliSignal::ResetLinks(TObject* obj,TString name,Int_t k)
1401{
1402// Reset single or multiple link(s) according to user specified selections.
1403//
1404// A link is only reset if the stored reference matches the argument "obj".
1405// In case obj=0 no check on the matching of the stored reference is performed
1406// and the stored link is always reset in accordance with the other
1407// selection criteria.
1408//
1409// In case the position argument "k" is specified, only the links from that
1410// specified position will be deleted.
1411// In case k=0 (default) no checking on the position index is performed.
1412//
1413// This procedure involves a slot-index search based on the specified name
1414// at each invokation. This may become slow in case many slots have been
1415// defined and/or when this procedure is invoked many times.
1416// In such cases it is preferable to use indexed addressing in the user code
1417// either directly or via a few invokations of GetSlotIndex().
1418
1419 Int_t j=GetSlotIndex(name);
1420 if (j>0) ResetLinks(obj,j,k);
1421}
1422///////////////////////////////////////////////////////////////////////////
261c0caf 1423Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,TArrayI& ks) const
d0a8ef71 1424{
1425// Provide the slot and position indices of all the storage locations
1426// of the specified object.
1427// The slot (j) and pos. (k) indices are returned in the two separate TArrayI arrays
1428// from which the (j,k) pairs can be obtained from the corresponding
1429// array indices like (j,k)=(js.At(i),ks.At(i)).
1430// The integer return argument represents the number of (j,k) pairs which
1431// were encountered for the specified object.
1432//
1433// If obj=0 no object selection is performed and all (j,k) indices
1434// of the stored references for all objects are returned.
1435//
1436// Notes :
1437// -------
1438// As usual the convention is that slot and position numbering starts at 1.
1439//
1440// This memberfunction always resets the two TArrayI arrays at the start.
1441//
1442// This memberfunction can only be used to obtain the (j,k) indices
1443// of the object as stored via the SetLink() or AddLink() memberfunction.
1444// This means that in case the user has entered a TObjArray as object
1445// (to increase the dimension of the resulting structure), the (j,k)
1446// indices of that TObjArray are obtained and NOT the indices of the
1447// actual objects contained in that TObjArray structure.
1448//
1449 Int_t nrefs=0;
1450 js.Reset();
1451 ks.Reset();
1452 // Note : In the internal storage matrix slots=columns positions=rows
1453 if (fLinks) nrefs=fLinks->GetIndices(obj,ks,js);
1454 return nrefs;
1455}
1456///////////////////////////////////////////////////////////////////////////
261c0caf 1457Int_t AliSignal::GetIndices(TObject* obj,Int_t j,TArrayI& ks) const
d0a8ef71 1458{
1459// Provide the position indices of all the storage locations of the
1460// specified object in the j-th slot of this AliSignal.
1461// The position indices are returned in the TArrayI array.
1462// The integer return argument represents the number of storage locations which
1463// were encountered for the specified object in the j-th slot.
1464//
1465// If obj=0 no object selection is performed and all position indices
1466// of the stored references for all objects of the j-th slot are returned.
1467//
1468// If j=0 all slots will be scanned and all position indices matching the
1469// object selection are returned.
1470// Note that in this case multiple appearances of the same position index
1471// will only be recorded once in the returned TArrayI array.
1472//
1473// Notes :
1474// -------
1475// As usual the convention is that slot and position numbering starts at 1.
1476//
1477// This memberfunction always resets the TArrayI array at the start.
1478//
1479// This memberfunction can only be used to obtain the position indices
1480// of the object as stored via the SetLink() or AddLink() memberfunction.
1481// This means that in case the user has entered a TObjArray as object
1482// (to increase the dimension of the resulting structure), the position
1483// indices of that TObjArray are obtained and NOT the indices of the
1484// actual objects contained in that TObjArray structure.
1485//
1486 Int_t nrefs=0;
1487 ks.Reset();
1488 // Note : In the internal storage matrix slots=columns positions=rows
1489 if (fLinks) nrefs=fLinks->GetIndices(obj,ks,j);
1490 return nrefs;
1491}
1492///////////////////////////////////////////////////////////////////////////
2cb7369d 1493Int_t AliSignal::GetIndices(TObject* obj,TString name,TArrayI& ks) const
1494{
1495// Provide the position indices of all the storage locations of the
1496// specified object in the name-specified slot of this AliSignal.
1497// The position indices are returned in the TArrayI array.
1498// The integer return argument represents the number of storage locations which
1499// were encountered for the specified object in the j-th slot.
1500//
1501// If obj=0 no object selection is performed and all position indices
1502// of the stored references for all objects of the j-th slot are returned.
1503//
1504// This procedure involves a slot-index search based on the specified name
1505// at each invokation. This may become slow in case many slots have been
1506// defined and/or when this procedure is invoked many times.
1507// In such cases it is preferable to use indexed addressing in the user code
1508// either directly or via a few invokations of GetSlotIndex().
1509
1510 Int_t j=GetSlotIndex(name);
1511 Int_t n=0;
1512 if (j>0) n=GetIndices(obj,j,ks);
1513 return n;
1514}
1515///////////////////////////////////////////////////////////////////////////
261c0caf 1516Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,Int_t k) const
d0a8ef71 1517{
1518// Provide the slot indices of all the storage locations of the
1519// specified object for the k-th position in this AliSignal.
1520// The slot indices are returned in the TArrayI array.
1521// The integer return argument represents the number of storage locations which
1522// were encountered for the specified object in the k-th position.
1523//
1524// If obj=0 no object selection is performed and all slot indices
1525// of the stored references for all objects in the k-th position are returned.
1526//
1527// If k=0 all positions will be scanned and all slot indices matching the
1528// object selection are returned.
1529// Note that in this case multiple appearances of the same slot index
1530// will only be recorded once in the returned TArrayI array.
1531//
1532// Notes :
1533// -------
1534// As usual the convention is that slot and position numbering starts at 1.
1535//
1536// This memberfunction always resets the TArrayI array at the start.
1537//
1538// This memberfunction can only be used to obtain the slot indices
1539// of the object as stored via the SetLink() or AddLink() memberfunction.
1540// This means that in case the user has entered a TObjArray as object
1541// (to increase the dimension of the resulting structure), the slot
1542// indices of that TObjArray are obtained and NOT the indices of the
1543// actual objects contained in that TObjArray structure.
1544//
1545 Int_t nrefs=0;
1546 js.Reset();
1547 // Note : In the internal storage matrix slots=columns positions=rows
1548 if (fLinks) nrefs=fLinks->GetIndices(obj,k,js);
1549 return nrefs;
1550}
1551///////////////////////////////////////////////////////////////////////////
1552void AliSignal::SetSwapMode(Int_t swap)
1553{
1554// Set swapmode flag for the internal link storage.
1555// In case for the stored links the maximum slot number differs considerably
1556// from the maximum position number, it might be more efficient
1557// (w.r.t. memory usage and/or output file size) to internally store the
1558// link reference matrix with the rows and colums swapped.
1559// This swapping is only related with the internal storage and as such
1560// is completely hidden for the user.
1561// At invokation of this memberfunction the default argument is swap=1.
1562//
1563// Note : The swap mode can only be set as long as no links are
1564// stored in the AliSignal (i.e. a new instance of AliSignal
1565// or after invokation of the Reset() or ResetLinks() function).
1566
1567 if (!fLinks) fLinks=new AliObjMatrix();
1568 fLinks->SetSwapMode(swap);
1569}
1570///////////////////////////////////////////////////////////////////////////
261c0caf 1571Int_t AliSignal::GetSwapMode() const
d0a8ef71 1572{
1573// Provide swapmode flag of the link storage.
1574 Int_t swap=0;
1575 if (fLinks) swap=fLinks->GetSwapMode();
1576 return swap;
5f25234b 1577}
1578///////////////////////////////////////////////////////////////////////////
965bd237 1579void AliSignal::SetDevice(TObject* dev)
1580{
1581// Store the pointer to the device which owns this AliSignal object.
1582// This memberfunction is meant for internal use in AliDevice.
1583 fDevice=dev;
1584}
1585///////////////////////////////////////////////////////////////////////////
1586AliDevice* AliSignal::GetDevice() const
1587{
1588// Provide the pointer to the device which owns this AliSignal object.
1589 return (AliDevice*)fDevice;
1590}
1591///////////////////////////////////////////////////////////////////////////
261c0caf 1592TObject* AliSignal::Clone(const char* name) const
c72198f1 1593{
1c01b4f8 1594// Make a deep copy of the current object and provide the pointer to the copy.
c72198f1 1595// This memberfunction enables automatic creation of new objects of the
1c01b4f8 1596// correct type depending on the object type, a feature which may be very useful
c72198f1 1597// for containers when adding objects in case the container owns the objects.
1598// This feature allows e.g. AliTrack to store either AliSignal objects or
1599// objects derived from AliSignal via the AddSignal memberfunction, provided
1c01b4f8 1600// these derived classes also have a proper Clone memberfunction.
c72198f1 1601
1c01b4f8 1602 AliSignal* sig=new AliSignal(*this);
1603 if (name)
1604 {
1605 if (strlen(name)) sig->SetName(name);
1606 }
c72198f1 1607 return sig;
1608}
1609///////////////////////////////////////////////////////////////////////////