]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliAttrib.cxx
12-jan-2005 NvE Bug fix in AliAttrib::GetSlotIndex() by exiting as soon as matching...
[u/mrichter/AliRoot.git] / RALICE / AliAttrib.cxx
CommitLineData
1fbffa23 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
16// $Id$
17
18///////////////////////////////////////////////////////////////////////////
19// Class AliAttrib
20// Generic handling of detector signal (calibration) attributes.
21// Normally this class is only used as a base class to provide the various
22// attributes to the derived class. An example of this is AliSignal.
23// However, one can of course also use this class on its own as shown
24// in the simple example hereafter.
25//
26// Example :
27// ---------
28// AliAttrib a;
1fbffa23 29// a.SetSlotName("PMT amplitude in Volt");
965bd237 30// a.SetGain(250.7);
31// a.SetSlotName("Time of flight in ns",2);
32// a.SetOffset(-22.5,2);
1fbffa23 33// a.SetSlotName("PMT amplitude in ADC",3);
965bd237 34// a.SetGain(1340,3);
35// a.SetSlotName("TDC",4);
36// a.SetOffset(10.75,"TDC");
1fbffa23 37// a.SetEdgeOn(3);
1fbffa23 38// a.SetDead(1);
387a745b 39// a.List();
1fbffa23 40//
41//--- Author: Nick van Eijndhoven 18-sep-2003 Utrecht University
42//- Modified: NvE $Date$ Utrecht University
43///////////////////////////////////////////////////////////////////////////
44
45#include "AliAttrib.h"
46#include "Riostream.h"
47
48ClassImp(AliAttrib) // Class implementation to enable ROOT I/O
49
50AliAttrib::AliAttrib()
51{
52// Creation of an AliAttrib object and initialisation of parameters.
53// Several values of the same type (e.g. gain) can be stored in different slots.
54// If needed, the storage for values will be expanded automatically
55// when entering values.
56 fGains=0;
57 fOffsets=0;
58 fCalflags=0;
59 fNames=0;
60}
61///////////////////////////////////////////////////////////////////////////
62AliAttrib::~AliAttrib()
63{
64// Destructor to delete dynamically allocated memory
65 if (fGains)
66 {
67 delete fGains;
68 fGains=0;
69 }
70 if (fOffsets)
71 {
72 delete fOffsets;
73 fOffsets=0;
74 }
75 if (fCalflags)
76 {
77 delete fCalflags;
78 fCalflags=0;
79 }
80 if (fNames)
81 {
82 delete fNames;
83 fNames=0;
84 }
85}
86///////////////////////////////////////////////////////////////////////////
261c0caf 87AliAttrib::AliAttrib(const AliAttrib& a)
1fbffa23 88{
89// Copy constructor
90 fGains=0;
91 fOffsets=0;
92 fCalflags=0;
93 fNames=0;
94
95 Int_t n=0;
96 Double_t val=0;
97
98 n=a.GetNgains();
99 for (Int_t ig=1; ig<=n; ig++)
100 {
101 val=a.GetGain(ig);
102 if (a.GetGainFlag(ig)) SetGain(val,ig);
103 }
104
105 n=a.GetNoffsets();
106 for (Int_t io=1; io<=n; io++)
107 {
108 val=a.GetOffset(io);
109 if (a.GetOffsetFlag(io)) SetOffset(val,io);
110 }
111
112 n=a.GetNcalflags();
113 for (Int_t ic=1; ic<=n; ic++)
114 {
115 SetEdgeValue(a.GetEdgeValue(ic),ic);
116 if (a.GetDeadValue(ic)) SetDead(ic);
117 }
118
119 n=a.GetNnames();
120 TString s;
121 for (Int_t in=1; in<=n; in++)
122 {
123 s=a.GetSlotName(in);
124 if (s!="") SetSlotName(s,in);
125 }
126}
127///////////////////////////////////////////////////////////////////////////
261c0caf 128Int_t AliAttrib::GetNgains() const
1fbffa23 129{
130// Provide the number of specified gains for this attribute.
131 Int_t n=0;
132 if (fGains) n=fGains->GetSize();
133 return n;
134}
135///////////////////////////////////////////////////////////////////////////
261c0caf 136Int_t AliAttrib::GetNoffsets() const
1fbffa23 137{
138// Provide the number of specified offsets for this attribute.
139 Int_t n=0;
140 if (fOffsets) n=fOffsets->GetSize();
141 return n;
142}
143///////////////////////////////////////////////////////////////////////////
261c0caf 144Int_t AliAttrib::GetNcalflags() const
1fbffa23 145{
146// Provide the number of specified calib. flags for this attribute.
147 Int_t n=0;
148 if (fCalflags) n=fCalflags->GetSize();
149 return n;
150}
151///////////////////////////////////////////////////////////////////////////
261c0caf 152Int_t AliAttrib::GetNnames() const
1fbffa23 153{
154// Provide the maximum number of specified names for this attribute.
155 Int_t n=0;
156 if (fNames) n=fNames->GetSize();
157 return n;
158}
159///////////////////////////////////////////////////////////////////////////
160void AliAttrib::SetGain(Double_t gain,Int_t j)
161{
162// Store gain value of the j-th (default j=1) attribute slot.
163// Note : The first attribute slot is at j=1.
164// In case the value of the index j exceeds the maximum number of reserved
165// slots for gain values, the number of reserved slots for the gain
166// values is increased automatically.
167
168 if (j<1)
169 {
170 cout << " *AliAttrib::SetGain* Invalid argument j = " << j << endl;
171 return;
172 }
173
174 if (!fGains)
175 {
176 fGains=new TArrayF(j);
177 }
178
179 Int_t size=fGains->GetSize();
180
181 if (j>size)
182 {
183 fGains->Set(j);
184 }
185
186 fGains->AddAt(float(gain),j-1);
187
188 Int_t oflag=GetOffsetFlag(j);
189
190 SetCalFlags(1,oflag,j);
191}
192///////////////////////////////////////////////////////////////////////////
2cb7369d 193void AliAttrib::SetGain(Double_t gain,TString name)
194{
195// Store gain value of the name-specified attribute slot.
196//
197// This procedure involves a slot-index search based on the specified name
198// at each invokation. This may become slow in case many slots have been
199// defined and/or when this procedure is invoked many times.
200// In such cases it is preferable to use indexed addressing in the user code
201// either directly or via a few invokations of GetSlotIndex().
202
203 Int_t j=GetSlotIndex(name);
204 if (j>0) SetGain(gain,j);
205}
206///////////////////////////////////////////////////////////////////////////
1fbffa23 207void AliAttrib::SetOffset(Double_t off,Int_t j)
208{
209// Store offset value of the j-th (default j=1) attribute slot.
210// Note : The first attribute slot is at j=1.
211// In case the value of the index j exceeds the maximum number of reserved
212// slots for offset values, the number of reserved slots for the offset
213// values is increased automatically.
214
215 if (j<1)
216 {
217 cout << " *AliAttrib::GetOffset* Invalid argument j = " << j << endl;
218 return;
219 }
220
221 if (!fOffsets)
222 {
223 fOffsets=new TArrayF(j);
224 }
225
226 Int_t size=fOffsets->GetSize();
227
228 if (j>size)
229 {
230 fOffsets->Set(j);
231 }
232
233 fOffsets->AddAt(float(off),j-1);
234
235 Int_t gflag=GetGainFlag(j);
236
237 SetCalFlags(gflag,1,j);
238}
239///////////////////////////////////////////////////////////////////////////
2cb7369d 240void AliAttrib::SetOffset(Double_t off,TString name)
241{
242// Store offset value of the name-specified attribute slot.
243//
244// This procedure involves a slot-index search based on the specified name
245// at each invokation. This may become slow in case many slots have been
246// defined and/or when this procedure is invoked many times.
247// In such cases it is preferable to use indexed addressing in the user code
248// either directly or via a few invokations of GetSlotIndex().
249
250 Int_t j=GetSlotIndex(name);
251 if (j>0) SetOffset(off,j);
252}
253///////////////////////////////////////////////////////////////////////////
1fbffa23 254void AliAttrib::SetCalFlags(Int_t gainflag,Int_t offsetflag,Int_t j)
255{
256// Store calibration flags of the j-th (default j=1) attribute slot.
257// Note : The first attribute slot is at j=1.
258// In case the value of the index j exceeds the maximum number of reserved
259// slots for the calib. flags, the number of reserved slots for the calib.
260// flags is increased automatically.
261// The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
262
263 if (j<1)
264 {
265 cout << " *AliAttrib::GetCalFlags* Invalid argument j = " << j << endl;
266 return;
267 }
268
269 if (!fCalflags)
270 {
271 fCalflags=new TArrayI(j);
272 }
273
274 Int_t size=fCalflags->GetSize();
275
276 if (j>size)
277 {
278 fCalflags->Set(j);
279 }
280
281 Int_t edge=GetEdgeValue(j);
282 Int_t dead=GetDeadValue(j);
283
284 Int_t word=1000*edge+100*dead+10*gainflag+offsetflag;
285
286 fCalflags->AddAt(word,j-1);
287}
288///////////////////////////////////////////////////////////////////////////
261c0caf 289Int_t AliAttrib::GetGainFlag(Int_t j) const
1fbffa23 290{
291// Provide gain flag of the j-th (default j=1) attribute slot.
292//
293// flag = 1 : Gain was set
294// 0 : Gain was not set
295//
296// Note : The first attribute slot is at j=1.
297// In case j is invalid, 0 is returned.
298
299 if (j<1)
300 {
301 cout << " *AliAttrib::GetGainFlag* Invalid argument j = " << j << endl;
302 return 0;
303 }
304 Int_t gflag=0;
305 if (fCalflags)
306 {
307 if (j>0 && j<=(fCalflags->GetSize()))
308 {
309 Int_t word=fCalflags->At(j-1);
310 word=word%100;
311 gflag=word/10;
312 }
313 }
314 return gflag;
315}
316///////////////////////////////////////////////////////////////////////////
2cb7369d 317Int_t AliAttrib::GetGainFlag(TString name) const
318{
319// Provide gain flag of the name-specified attribute slot.
320//
321// flag = 1 : Gain was set
322// 0 : Gain was not set
323//
324//
325// This procedure involves a slot-index search based on the specified name
326// at each invokation. This may become slow in case many slots have been
327// defined and/or when this procedure is invoked many times.
328// In such cases it is preferable to use indexed addressing in the user code
329// either directly or via a few invokations of GetSlotIndex().
330
331 Int_t j=GetSlotIndex(name);
332 Int_t flag=0;
333 if (j>0) flag=GetGainFlag(j);
334 return flag;
335}
336///////////////////////////////////////////////////////////////////////////
261c0caf 337Int_t AliAttrib::GetOffsetFlag(Int_t j) const
1fbffa23 338{
339// Provide offset flag of the j-th (default j=1) attribute slot.
340//
341// flag = 1 : Offset was set
342// 0 : Offset was not set
343//
344// Note : The first attribute slot is at j=1.
345// In case j is invalid, 0 is returned.
346
347 if (j<1)
348 {
349 cout << " *AliAttrib::GetOffsetFlag* Invalid argument j = " << j << endl;
350 return 0;
351 }
352
353 Int_t oflag=0;
354 if (fCalflags)
355 {
356 if (j>0 && j<=(fCalflags->GetSize()))
357 {
358 Int_t word=fCalflags->At(j-1);
359 oflag=word%10;
360 }
361 }
362 return oflag;
363}
364///////////////////////////////////////////////////////////////////////////
2cb7369d 365Int_t AliAttrib::GetOffsetFlag(TString name) const
366{
367// Provide ofset flag of the name-specified attribute slot.
368//
369// flag = 1 : Offset was set
370// 0 : Offset was not set
371//
372//
373// This procedure involves a slot-index search based on the specified name
374// at each invokation. This may become slow in case many slots have been
375// defined and/or when this procedure is invoked many times.
376// In such cases it is preferable to use indexed addressing in the user code
377// either directly or via a few invokations of GetSlotIndex().
378
379 Int_t j=GetSlotIndex(name);
380 Int_t flag=0;
381 if (j>0) flag=GetOffsetFlag(j);
382 return flag;
383}
384///////////////////////////////////////////////////////////////////////////
261c0caf 385Float_t AliAttrib::GetGain(Int_t j) const
1fbffa23 386{
387// Provide gain value of the j-th (default j=1) attribute slot.
388// The first attribute slot is at j=1.
389// In case no gain value was set or the argument j is invalid, 0 is returned.
390// Note : Use GetGainFlag(j) to check whether this gain was set or not.
391
392 if (j<1)
393 {
394 cout << " *AliAttrib::GetGain* Invalid argument j = " << j << endl;
395 return 0;
396 }
397
398 Float_t gain=0;
399 if (fGains)
400 {
401 if (j>0 && j<=(fGains->GetSize()))
402 {
403 if (GetGainFlag(j)) gain=fGains->At(j-1);
404 }
405 }
406 return gain;
407}
408///////////////////////////////////////////////////////////////////////////
2cb7369d 409Float_t AliAttrib::GetGain(TString name) const
410{
411// Provide gain value of the name-specified attribute slot.
412//
413// This procedure involves a slot-index search based on the specified name
414// at each invokation. This may become slow in case many slots have been
415// defined and/or when this procedure is invoked many times.
416// In such cases it is preferable to use indexed addressing in the user code
417// either directly or via a few invokations of GetSlotIndex().
418
419 Int_t j=GetSlotIndex(name);
420 Float_t gain=0;
421 if (j>0) gain=GetGain(j);
422 return gain;
423}
424///////////////////////////////////////////////////////////////////////////
261c0caf 425Float_t AliAttrib::GetOffset(Int_t j) const
1fbffa23 426{
427// Provide offset value of the j-th (default j=1) attribute slot.
428// The first attribute slot at j=1.
429// In case no offset value was set or the argument j is invalid, 0 is returned.
430// Note : Use GetOffsetFlag(j) to check whether this offset was set or not.
431
432 if (j<1)
433 {
434 cout << " *AliAttrib::GetOffset* Invalid argument j = " << j << endl;
435 return 0;
436 }
437
438 Float_t offset=0;
439 if (fOffsets)
440 {
441 if (j>0 && j<=(fOffsets->GetSize()))
442 {
443 if (GetOffsetFlag(j)) offset=fOffsets->At(j-1);
444 }
445 }
446 return offset;
447}
448///////////////////////////////////////////////////////////////////////////
2cb7369d 449Float_t AliAttrib::GetOffset(TString name) const
450{
451// Provide offset value of the name-specified attribute slot.
452//
453// This procedure involves a slot-index search based on the specified name
454// at each invokation. This may become slow in case many slots have been
455// defined and/or when this procedure is invoked many times.
456// In such cases it is preferable to use indexed addressing in the user code
457// either directly or via a few invokations of GetSlotIndex().
458
459 Int_t j=GetSlotIndex(name);
460 Float_t offset=0;
461 if (j>0) offset=GetOffset(j);
462 return offset;
463}
464///////////////////////////////////////////////////////////////////////////
1fbffa23 465void AliAttrib::ResetGain(Int_t j)
466{
467// Reset the gain value of the j-th (default j=1) attribute slot.
468// Notes : The first attribute slot is at j=1.
469// j=0 ==> All gain values will be reset.
470
471 if (!fGains) return;
472
473 Int_t size=fGains->GetSize();
474
475 if ((j>=0) && (j<=size))
476 {
477 if (j)
478 {
479 fGains->AddAt(0,j-1);
480 Int_t oflag=GetOffsetFlag(j);
481 SetCalFlags(0,oflag,j);
482 }
483 else
484 {
485 for (Int_t i=0; i<size; i++)
486 {
487 fGains->AddAt(0,i);
488 Int_t oflag=GetOffsetFlag(i);
489 SetCalFlags(0,oflag,i);
490 }
491 }
492 }
493 else
494 {
495 cout << " *AliAttrib::ResetGain* Index j = " << j << " invalid." << endl;
496 return;
497 }
498}
499///////////////////////////////////////////////////////////////////////////
2cb7369d 500void AliAttrib::ResetGain(TString name)
501{
502// Reset the gain value of the name-specified attribute slot.
503//
504// This procedure involves a slot-index search based on the specified name
505// at each invokation. This may become slow in case many slots have been
506// defined and/or when this procedure is invoked many times.
507// In such cases it is preferable to use indexed addressing in the user code
508// either directly or via a few invokations of GetSlotIndex().
509
510 Int_t j=GetSlotIndex(name);
511 if (j>0) ResetGain(j);
512}
513///////////////////////////////////////////////////////////////////////////
1fbffa23 514void AliAttrib::ResetOffset(Int_t j)
515{
516// Reset the offset value of the j-th (default j=1) attribute slot.
517// Notes : The first attribute slot is at j=1.
518// j=0 ==> All offset values will be reset.
519
520 if (!fOffsets) return;
521
522 Int_t size=fOffsets->GetSize();
523
524 if ((j>=0) && (j<=size))
525 {
526 if (j)
527 {
528 fOffsets->AddAt(0,j-1);
529 Int_t gflag=GetGainFlag(j);
530 SetCalFlags(gflag,0,j);
531 }
532 else
533 {
534 for (Int_t i=0; i<size; i++)
535 {
536 fOffsets->AddAt(0,i);
537 Int_t gflag=GetGainFlag(i);
538 SetCalFlags(gflag,0,i);
539 }
540 }
541 }
542 else
543 {
544 cout << " *AliAttrib::ResetOffset* Index j = " << j << " invalid." << endl;
545 return;
546 }
547}
548///////////////////////////////////////////////////////////////////////////
2cb7369d 549void AliAttrib::ResetOffset(TString name)
550{
551// Reset the offset value of the name-specified attribute slot.
552//
553// This procedure involves a slot-index search based on the specified name
554// at each invokation. This may become slow in case many slots have been
555// defined and/or when this procedure is invoked many times.
556// In such cases it is preferable to use indexed addressing in the user code
557// either directly or via a few invokations of GetSlotIndex().
558
559 Int_t j=GetSlotIndex(name);
560 if (j>0) ResetOffset(j);
561}
562///////////////////////////////////////////////////////////////////////////
1fbffa23 563void AliAttrib::DeleteCalibrations(Int_t mode)
564{
565// User selected delete of all gains and/or offsets.
566// mode = 0 : All attributes (names, gains, offsets, edge and dead values) are deleted.
567// 1 : Only the gains are deleted.
568// 2 : Only the offsets are deleted.
569// 3 : Both gains and offsets are deleted, but names, edge and dead values are kept.
570//
571// The default when invoking DeleteCalibrations() corresponds to mode=0.
572
573 if (mode<0 || mode>3)
574 {
575 cout << " *AliAttrib::DeleteCalibrations* Unknown mode : " << mode << endl;
576 cout << " Default mode=0 will be used." << endl;
577 mode=0;
578 }
579
580 if (mode==0 || mode==3)
581 {
582 ResetGain(0);
583 if (fGains)
584 {
585 delete fGains;
586 fGains=0;
587 }
588 ResetOffset(0);
589 if (fOffsets)
590 {
591 delete fOffsets;
592 fOffsets=0;
593 }
594 if (fCalflags && mode==0)
595 {
596 delete fCalflags;
597 fCalflags=0;
598 }
599 if (fNames && mode==0)
600 {
601 delete fNames;
602 fNames=0;
603 }
604 return;
605 }
606
607 if (mode==1)
608 {
609 ResetGain(0);
610 if (fGains)
611 {
612 delete fGains;
613 fGains=0;
614 }
615 }
616 else
617 {
618 ResetOffset(0);
619 if (fOffsets)
620 {
621 delete fOffsets;
622 fOffsets=0;
623 }
624 }
625}
626///////////////////////////////////////////////////////////////////////////
627void AliAttrib::SetDead(Int_t j)
628{
629// Set the dead flag to 1 for the j-th (default j=1) attribute slot.
630// Note : The first attribute slot is at j=1.
631// In case the value of the index j exceeds the maximum number of reserved
632// slots for the flags, the number of reserved slots for the flags
633// is increased automatically.
634// The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
635
636 if (j<1)
637 {
638 cout << " *AliAttrib::SetDead* Invalid argument j = " << j << endl;
639 return;
640 }
641
642 if (!fCalflags)
643 {
644 fCalflags=new TArrayI(j);
645 }
646
647 Int_t size=fCalflags->GetSize();
648
649 if (j>size)
650 {
651 fCalflags->Set(j);
652 }
653
654 Int_t dead=1;
655 Int_t oflag=GetOffsetFlag(j);
656 Int_t gflag=GetGainFlag(j);
657 Int_t edge=GetEdgeValue(j);
658
659 Int_t word=1000*edge+100*dead+10*gflag+oflag;
660
661 fCalflags->AddAt(word,j-1);
662}
663///////////////////////////////////////////////////////////////////////////
2cb7369d 664void AliAttrib::SetDead(TString name)
665{
666// Set the dead flag to 1 for the name-specified attribute slot.
667//
668// This procedure involves a slot-index search based on the specified name
669// at each invokation. This may become slow in case many slots have been
670// defined and/or when this procedure is invoked many times.
671// In such cases it is preferable to use indexed addressing in the user code
672// either directly or via a few invokations of GetSlotIndex().
673
674 Int_t j=GetSlotIndex(name);
675 if (j>0) SetDead(j);
676}
677///////////////////////////////////////////////////////////////////////////
1fbffa23 678void AliAttrib::SetAlive(Int_t j)
679{
680// Set the dead flag to 0 for the j-th (default j=1) attribute slot.
681// Note : The first attribute slot is at j=1.
682// In case the value of the index j exceeds the maximum number of reserved
683// slots for the flags, no action is taken since by default the dead flag is 0.
684// The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
685
686 if (j<1)
687 {
688 cout << " *AliAttrib::SetAlive* Invalid argument j = " << j << endl;
689 return;
690 }
691
692 if (!fCalflags || j>fCalflags->GetSize()) return;
693
694 Int_t dead=0;
695 Int_t oflag=GetOffsetFlag(j);
696 Int_t gflag=GetGainFlag(j);
697 Int_t edge=GetEdgeValue(j);
698
699 Int_t word=1000*edge+100*dead+10*gflag+oflag;
700
701 fCalflags->AddAt(word,j-1);
702}
703///////////////////////////////////////////////////////////////////////////
2cb7369d 704void AliAttrib::SetAlive(TString name)
705{
706// Set the dead flag to 0 for the name-specified attribute slot.
707//
708// This procedure involves a slot-index search based on the specified name
709// at each invokation. This may become slow in case many slots have been
710// defined and/or when this procedure is invoked many times.
711// In such cases it is preferable to use indexed addressing in the user code
712// either directly or via a few invokations of GetSlotIndex().
713
714 Int_t j=GetSlotIndex(name);
715 if (j>0) SetAlive(j);
716}
717///////////////////////////////////////////////////////////////////////////
1fbffa23 718void AliAttrib::SetEdgeOn(Int_t j)
719{
720// Set the edge value to 1 for the j-th (default j=1) attribute slot.
721// Note : The first attribute slot is at j=1.
722// In case the value of the index j exceeds the maximum number of reserved
723// slots for the flags, the number of reserved slots for the flags
724// is increased automatically.
725// The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
726
727 if (j<1)
728 {
729 cout << " *AliAttrib::SetEdgeOn* Invalid argument j = " << j << endl;
730 return;
731 }
732
733 SetEdgeValue(1,j);
734}
735///////////////////////////////////////////////////////////////////////////
2cb7369d 736void AliAttrib::SetEdgeOn(TString name)
737{
738// Set the edge value to 1 for the name-specified attribute slot.
739//
740// This procedure involves a slot-index search based on the specified name
741// at each invokation. This may become slow in case many slots have been
742// defined and/or when this procedure is invoked many times.
743// In such cases it is preferable to use indexed addressing in the user code
744// either directly or via a few invokations of GetSlotIndex().
745
746 Int_t j=GetSlotIndex(name);
747 if (j>0) SetEdgeOn(j);
748}
749///////////////////////////////////////////////////////////////////////////
1fbffa23 750void AliAttrib::SetEdgeOff(Int_t j)
751{
752// Set the edge value to 0 for the j-th (default j=1) attribute slot.
753// Note : The first attribute slot is at j=1.
754// In case the value of the index j exceeds the maximum number of reserved
755// slots for the flags, no action is taken since by default the edge flag is 0.
756// The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
757
758 if (j<1)
759 {
760 cout << " *AliAttrib::SetEdgeOff* Invalid argument j = " << j << endl;
761 return;
762 }
763
764 if (!fCalflags || j>fCalflags->GetSize()) return;
765
766 SetEdgeValue(0,j);
767}
768///////////////////////////////////////////////////////////////////////////
2cb7369d 769void AliAttrib::SetEdgeOff(TString name)
770{
771// Set the edge value to 0 for the name-specified attribute slot.
772//
773// This procedure involves a slot-index search based on the specified name
774// at each invokation. This may become slow in case many slots have been
775// defined and/or when this procedure is invoked many times.
776// In such cases it is preferable to use indexed addressing in the user code
777// either directly or via a few invokations of GetSlotIndex().
778
779 Int_t j=GetSlotIndex(name);
780 if (j>0) SetEdgeOff(j);
781}
782///////////////////////////////////////////////////////////////////////////
1fbffa23 783void AliAttrib::SetEdgeValue(Int_t val,Int_t j)
784{
785// Set the edge value to "val" for the j-th (default j=1) attribute slot.
786// Note : The first attribute slot is at j=1.
787// In case the value of the index j exceeds the maximum number of reserved
788// slots for the flags, the number of reserved slots for the flags
789// is increased automatically.
790// The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
791
792 if (j<1)
793 {
794 cout << " *AliAttrib::SetEdgeValue* Invalid argument j = " << j << endl;
795 return;
796 }
797
798 if (!fCalflags)
799 {
800 fCalflags=new TArrayI(j);
801 }
802
803 Int_t size=fCalflags->GetSize();
804
805 if (j>size)
806 {
807 fCalflags->Set(j);
808 }
809
810 Int_t edge=val;
811 Int_t dead=GetDeadValue(j);
812 Int_t gflag=GetGainFlag(j);
813 Int_t oflag=GetOffsetFlag(j);
814
815 Int_t word=1000*edge+100*dead+10*gflag+oflag;
816
817 fCalflags->AddAt(word,j-1);
818}
819///////////////////////////////////////////////////////////////////////////
2cb7369d 820void AliAttrib::SetEdgeValue(Int_t val,TString name)
821{
822// Set the edge value to "val" for the name-specified attribute slot.
823//
824// This procedure involves a slot-index search based on the specified name
825// at each invokation. This may become slow in case many slots have been
826// defined and/or when this procedure is invoked many times.
827// In such cases it is preferable to use indexed addressing in the user code
828// either directly or via a few invokations of GetSlotIndex().
829
830 Int_t j=GetSlotIndex(name);
831 if (j>0) SetEdgeValue(val,j);
832}
833///////////////////////////////////////////////////////////////////////////
1fbffa23 834void AliAttrib::IncreaseEdgeValue(Int_t j)
835{
836// Increase the edge value by 1 for the j-th (default j=1) attribute slot.
837// Note : The first attribute slot is at j=1.
838// In case the value of the index j exceeds the maximum number of reserved
839// slots for the flags, the number of reserved slots for the flags
840// is increased automatically.
841// The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
842
843 if (j<1)
844 {
845 cout << " *AliAttrib::IncreaseEdgeValue* Invalid argument j = " << j << endl;
846 return;
847 }
848
849 Int_t edge=GetEdgeValue();
850 SetEdgeValue(edge+1,j);
851}
852///////////////////////////////////////////////////////////////////////////
2cb7369d 853void AliAttrib::IncreaseEdgeValue(TString name)
854{
855// Increase the edge value by 1 for the name-specified attribute slot.
856//
857// This procedure involves a slot-index search based on the specified name
858// at each invokation. This may become slow in case many slots have been
859// defined and/or when this procedure is invoked many times.
860// In such cases it is preferable to use indexed addressing in the user code
861// either directly or via a few invokations of GetSlotIndex().
862
863 Int_t j=GetSlotIndex(name);
864 if (j>0) IncreaseEdgeValue(j);
865}
866///////////////////////////////////////////////////////////////////////////
1fbffa23 867void AliAttrib::DecreaseEdgeValue(Int_t j)
868{
869// Decrease the edge value by 1 for the j-th (default j=1) attribute slot.
870// Note : The first attribute slot is at j=1.
871// In case the value of the index j exceeds the maximum number of reserved
872// slots for the flags, the number of reserved slots for the flags
873// is increased automatically.
874// The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
875
876 if (j<1)
877 {
878 cout << " *AliAttrib::DecreaseEdgeValue* Invalid argument j = " << j << endl;
879 return;
880 }
881
882 Int_t edge=GetEdgeValue();
883 SetEdgeValue(edge-1,j);
884}
885///////////////////////////////////////////////////////////////////////////
2cb7369d 886void AliAttrib::DecreaseEdgeValue(TString name)
887{
888// Decrease the edge value by 1 for the name-specified attribute slot.
889//
890// This procedure involves a slot-index search based on the specified name
891// at each invokation. This may become slow in case many slots have been
892// defined and/or when this procedure is invoked many times.
893// In such cases it is preferable to use indexed addressing in the user code
894// either directly or via a few invokations of GetSlotIndex().
895
896 Int_t j=GetSlotIndex(name);
897 if (j>0) DecreaseEdgeValue(j);
898}
899///////////////////////////////////////////////////////////////////////////
261c0caf 900Int_t AliAttrib::GetEdgeValue(Int_t j) const
1fbffa23 901{
902// Provide edge value of the j-th (default j=1) attribute slot.
903// Note : The first attribute slot is at j=1.
904// In case j is invalid, 0 is returned.
905
906 if (j<1)
907 {
908 cout << " *AliAttrib::GetEdgeValue* Invalid argument j = " << j << endl;
909 return 0;
910 }
911
912 Int_t edge=0;
913 if (fCalflags)
914 {
915 if (j>0 && j<=(fCalflags->GetSize()))
916 {
917 Int_t word=fCalflags->At(j-1);
918 edge=word/1000;
919 }
920 }
921 return edge;
922}
923///////////////////////////////////////////////////////////////////////////
2cb7369d 924Int_t AliAttrib::GetEdgeValue(TString name) const
925{
926// Provide edge value of the name-specified attribute slot.
927//
928// This procedure involves a slot-index search based on the specified name
929// at each invokation. This may become slow in case many slots have been
930// defined and/or when this procedure is invoked many times.
931// In such cases it is preferable to use indexed addressing in the user code
932// either directly or via a few invokations of GetSlotIndex().
933
934 Int_t j=GetSlotIndex(name);
935 Int_t val=0;
936 if (j>0) val=GetEdgeValue(j);
937 return val;
938}
939///////////////////////////////////////////////////////////////////////////
261c0caf 940Int_t AliAttrib::GetDeadValue(Int_t j) const
1fbffa23 941{
942// Provide dead value of the j-th (default j=1) attribute slot.
943// Note : The first attribute slot is at j=1.
944// In case j is invalid, 0 is returned.
945
946 if (j<1)
947 {
948 cout << " *AliAttrib::GetDeadValue* Invalid argument j = " << j << endl;
949 return 0;
950 }
951
952 Int_t dead=0;
953 if (fCalflags)
954 {
955 if (j>0 && j<=(fCalflags->GetSize()))
956 {
957 Int_t word=fCalflags->At(j-1);
958 word=word%1000;
959 dead=word/100;
960 }
961 }
962 return dead;
963}
964///////////////////////////////////////////////////////////////////////////
2cb7369d 965Int_t AliAttrib::GetDeadValue(TString name) const
966{
967// Provide dead value of the name-specified attribute slot.
968//
969// This procedure involves a slot-index search based on the specified name
970// at each invokation. This may become slow in case many slots have been
971// defined and/or when this procedure is invoked many times.
972// In such cases it is preferable to use indexed addressing in the user code
973// either directly or via a few invokations of GetSlotIndex().
974
975 Int_t j=GetSlotIndex(name);
976 Int_t val=0;
977 if (j>0) val=GetDeadValue(j);
978 return val;
979}
980///////////////////////////////////////////////////////////////////////////
1fbffa23 981void AliAttrib::SetSlotName(TString s,Int_t j)
982{
983// Set a user defined name for the j-th (default j=1) slot.
984// Note : The first attribute slot is at j=1.
985
986 if (j<1)
987 {
988 cout << " *AliAttrib::SetSlotName* Invalid argument j = " << j << endl;
989 return;
990 }
991
992 if (!fNames)
993 {
994 fNames=new TObjArray(j);
995 fNames->SetOwner();
996 }
997
998 if (j>fNames->GetSize()) fNames->Expand(j);
999
1000 TObjString* so=(TObjString*)fNames->At(j-1);
1001 if (!so)
1002 {
1003 so=new TObjString(s.Data());
1004 fNames->AddAt(so,j-1);
1005 }
1006 else
1007 {
1008 so->SetString(s);
1009 }
1010}
1011///////////////////////////////////////////////////////////////////////////
261c0caf 1012TString AliAttrib::GetSlotName(Int_t j) const
1fbffa23 1013{
1014// Provide the user defined name for the j-th (default j=1) slot.
1015// Note : The first attribute slot is at j=1.
1016
1017 TString s="";
1018 if (j<1)
1019 {
1020 cout << " *AliAttrib::GetSlotName* Invalid argument j = " << j << endl;
1021 return s;
1022 }
1023
1024 if (fNames)
1025 {
1026 if (j<=fNames->GetSize())
1027 {
1028 TObjString* so=(TObjString*)fNames->At(j-1);
1029 if (so) s=so->GetString();
1030 }
1031 }
1032 return s;
1033}
1034///////////////////////////////////////////////////////////////////////////
261c0caf 1035Int_t AliAttrib::GetSlotIndex(TString name) const
1fbffa23 1036{
1037// Provide the slot index for the matching name.
1038// If no matching name is found, 0 is returned.
1039// Note : The first attribute slot is at j=1.
1040
1041 Int_t index=0;
1042
1043 if (fNames)
1044 {
1045 TString s;
1046 Int_t size=fNames->GetSize();
1047 for (Int_t i=0; i<size; i++)
1048 {
1049 TObjString* so=(TObjString*)fNames->At(i);
387a745b 1050 if (so) s=so->GetString();
74c40ae5 1051 if (s==name)
1052 {
1053 index=i+1;
1054 break;
1055 }
1fbffa23 1056 }
1057 }
1058 return index;
1059}
1060///////////////////////////////////////////////////////////////////////////
261c0caf 1061void AliAttrib::List(Int_t j) const
1fbffa23 1062{
1063// Provide attribute information for the j-th slot.
1064// The first slot is at j=1.
1065// In case j=0 (default) the data of all slots will be listed.
1066
1067 if (j<0)
1068 {
1069 cout << " *AliAttrib::Data* Invalid argument j = " << j << endl;
1070 return;
1071 }
1072
1073 if (j>0)
1074 {
1075 if (GetGainFlag(j)) cout << " gain : " << GetGain(j);
1076 if (GetOffsetFlag(j)) cout << " offset : " << GetOffset(j);
1077 if (GetEdgeValue(j)) cout << " edge : " << GetEdgeValue(j);
1078 if (GetDeadValue(j)) cout << " dead : " << GetDeadValue(j);
1079 TString s=GetSlotName(j);
1080 if (s!="") cout << " name : " << s.Data();
1081 }
1082 else
1083 {
1084 Int_t ng=GetNgains();
1085 Int_t no=GetNoffsets();
1086 Int_t nf=0;
1087 if (fCalflags) nf=fCalflags->GetSize();
1088 Int_t nn=GetNnames();
1089 Int_t n=ng;
1090 if (n<no) n=no;
1091 if (n<nn) n=nn;
1092 if (n<nf) n=nf;
1093 Int_t printf=0;
1094 TString s;
1095 for (Int_t i=1; i<=n; i++)
1096 {
1097 printf=0;
1098 if (GetGainFlag(i)) {cout << " gain : " << GetGain(i); printf=1;}
1099 if (GetOffsetFlag(i)) {cout << " offset : " << GetOffset(i); printf=1;}
1100 if (GetEdgeValue(i)) {cout << " edge : " << GetEdgeValue(i); printf=1;}
1101 if (GetDeadValue(i)) {cout << " dead : " << GetDeadValue(i); printf=1;}
1102 s=GetSlotName(i);
1103 if (s!="") {cout << " name : " << s.Data(); printf=1;}
1104 if (printf) cout << endl;
1105 }
1106 }
1107}
1108///////////////////////////////////////////////////////////////////////////
2cb7369d 1109void AliAttrib::List(TString name) const
1110{
1111// Provide attribute information for the name-specified slot.
1112//
1113// This procedure involves a slot-index search based on the specified name
1114// at each invokation. This may become slow in case many slots have been
1115// defined and/or when this procedure is invoked many times.
1116// In such cases it is preferable to use indexed addressing in the user code
1117// either directly or via a few invokations of GetSlotIndex().
1118
1119 Int_t j=GetSlotIndex(name);
1120 if (j>0) List(j);
1121}
1122///////////////////////////////////////////////////////////////////////////
1fbffa23 1123void AliAttrib::Load(AliAttrib& a,Int_t j)
1124{
1125// Load attributes of the j-th slot of the input AliAttrib into this AliAttrib object.
1126//
1127// Note : if j=0, then all attributes of all slots are loaded
1128//
1129// The default is j=0.
1130
1131 if (j<0)
1132 {
1133 cout << " *AliAttrib::Load* Invalid argument j = " << j << endl;
1134 return;
1135 }
1136
1137 Int_t n=0;
1138
1139 if (j==0) // load attributes for all slots
1140 {
1141 n=a.GetNgains();
1142 for (Int_t ig=1; ig<=n; ig++)
1143 {
1144 if (a.GetGainFlag(ig))
1145 {
1146 SetGain(a.GetGain(ig),ig);
1147 }
1148 else
1149 {
1150 ResetGain(ig);
1151 }
1152 }
1153 n=a.GetNoffsets();
1154 for (Int_t io=1; io<=n; io++)
1155 {
1156 if (a.GetOffsetFlag(io))
1157 {
1158 SetOffset(a.GetOffset(io),io);
1159 }
1160 else
1161 {
1162 ResetOffset(io);
1163 }
1164 }
1165 n=a.GetNcalflags();
1166 for (Int_t ic=1; ic<=n; ic++)
1167 {
1168 SetEdgeValue(a.GetEdgeValue(ic),ic);
1169 if (a.GetDeadValue(ic))
1170 {
1171 SetDead(ic);
1172 }
1173 else
1174 {
1175 SetAlive(ic);
1176 }
1177 }
1178 n=a.GetNnames();
1179 {
1180 TString s;
1181 for (Int_t in=1; in<=n; in++)
1182 {
1183 s=a.GetSlotName(in);
1184 if (s!="") SetSlotName(s,in);
1185 }
1186 }
1187 }
1188 else // load attributes for specified j-th slot only
1189 {
1190 n=a.GetNgains();
1191 if (j<=n)
1192 {
1193 if (a.GetGainFlag(j))
1194 {
1195 SetGain(a.GetGain(j),j);
1196 }
1197 else
1198 {
1199 ResetGain(j);
1200 }
1201 }
1202 n=a.GetNoffsets();
1203 if (j<=n)
1204 {
1205 if (a.GetOffsetFlag(j))
1206 {
1207 SetOffset(a.GetOffset(j),j);
1208 }
1209 else
1210 {
1211 ResetOffset(j);
1212 }
1213 }
1214 n=a.GetNcalflags();
1215 if (j<=n)
1216 {
1217 SetEdgeValue(a.GetEdgeValue(j),j);
1218 if (a.GetDeadValue(j))
1219 {
1220 SetDead(j);
1221 }
1222 else
1223 {
1224 SetAlive(j);
1225 }
1226 }
1227 n=a.GetNnames();
1228 {
1229 TString s;
1230 if (j<=n)
1231 {
1232 s=a.GetSlotName(j);
1233 if (s!="") SetSlotName(s,j);
1234 }
1235 }
1236 }
1237}
1238///////////////////////////////////////////////////////////////////////////
2cb7369d 1239void AliAttrib::Load(AliAttrib& a,TString name)
1240{
1241// Load attributes of the name-specified slot of the input AliAttrib into
1242// this AliAttrib object.
1243//
1244// This procedure involves a slot-index search based on the specified name
1245// at each invokation. This may become slow in case many slots have been
1246// defined and/or when this procedure is invoked many times.
1247// In such cases it is preferable to use indexed addressing in the user code
1248// either directly or via a few invokations of GetSlotIndex().
1249
1250 Int_t j=GetSlotIndex(name);
1251 if (j>0) Load(a,j);
1252}
1253///////////////////////////////////////////////////////////////////////////