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