1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
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.
30 // a.SetSlotName("PMT amplitude in Volt");
32 // a.SetSlotName("PMT amplitude in ADC",3);
34 // a.SetOffset(-22.5,2);
35 // a.SetSlotName("Time of flight in ns",2);
39 //--- Author: Nick van Eijndhoven 18-sep-2003 Utrecht University
40 //- Modified: NvE $Date$ Utrecht University
41 ///////////////////////////////////////////////////////////////////////////
43 #include "AliAttrib.h"
44 #include "Riostream.h"
46 ClassImp(AliAttrib) // Class implementation to enable ROOT I/O
48 AliAttrib::AliAttrib()
50 // Creation of an AliAttrib object and initialisation of parameters.
51 // Several values of the same type (e.g. gain) can be stored in different slots.
52 // If needed, the storage for values will be expanded automatically
53 // when entering values.
59 ///////////////////////////////////////////////////////////////////////////
60 AliAttrib::~AliAttrib()
62 // Destructor to delete dynamically allocated memory
84 ///////////////////////////////////////////////////////////////////////////
85 AliAttrib::AliAttrib(AliAttrib& a)
97 for (Int_t ig=1; ig<=n; ig++)
100 if (a.GetGainFlag(ig)) SetGain(val,ig);
104 for (Int_t io=1; io<=n; io++)
107 if (a.GetOffsetFlag(io)) SetOffset(val,io);
111 for (Int_t ic=1; ic<=n; ic++)
113 SetEdgeValue(a.GetEdgeValue(ic),ic);
114 if (a.GetDeadValue(ic)) SetDead(ic);
119 for (Int_t in=1; in<=n; in++)
122 if (s!="") SetSlotName(s,in);
125 ///////////////////////////////////////////////////////////////////////////
126 Int_t AliAttrib::GetNgains()
128 // Provide the number of specified gains for this attribute.
130 if (fGains) n=fGains->GetSize();
133 ///////////////////////////////////////////////////////////////////////////
134 Int_t AliAttrib::GetNoffsets()
136 // Provide the number of specified offsets for this attribute.
138 if (fOffsets) n=fOffsets->GetSize();
141 ///////////////////////////////////////////////////////////////////////////
142 Int_t AliAttrib::GetNcalflags()
144 // Provide the number of specified calib. flags for this attribute.
146 if (fCalflags) n=fCalflags->GetSize();
149 ///////////////////////////////////////////////////////////////////////////
150 Int_t AliAttrib::GetNnames()
152 // Provide the maximum number of specified names for this attribute.
154 if (fNames) n=fNames->GetSize();
157 ///////////////////////////////////////////////////////////////////////////
158 void AliAttrib::SetGain(Double_t gain,Int_t j)
160 // Store gain value of the j-th (default j=1) attribute slot.
161 // Note : The first attribute slot is at j=1.
162 // In case the value of the index j exceeds the maximum number of reserved
163 // slots for gain values, the number of reserved slots for the gain
164 // values is increased automatically.
168 cout << " *AliAttrib::SetGain* Invalid argument j = " << j << endl;
174 fGains=new TArrayF(j);
177 Int_t size=fGains->GetSize();
184 fGains->AddAt(float(gain),j-1);
186 Int_t oflag=GetOffsetFlag(j);
188 SetCalFlags(1,oflag,j);
190 ///////////////////////////////////////////////////////////////////////////
191 void AliAttrib::SetOffset(Double_t off,Int_t j)
193 // Store offset value of the j-th (default j=1) attribute slot.
194 // Note : The first attribute slot is at j=1.
195 // In case the value of the index j exceeds the maximum number of reserved
196 // slots for offset values, the number of reserved slots for the offset
197 // values is increased automatically.
201 cout << " *AliAttrib::GetOffset* Invalid argument j = " << j << endl;
207 fOffsets=new TArrayF(j);
210 Int_t size=fOffsets->GetSize();
217 fOffsets->AddAt(float(off),j-1);
219 Int_t gflag=GetGainFlag(j);
221 SetCalFlags(gflag,1,j);
223 ///////////////////////////////////////////////////////////////////////////
224 void AliAttrib::SetCalFlags(Int_t gainflag,Int_t offsetflag,Int_t j)
226 // Store calibration flags of the j-th (default j=1) attribute slot.
227 // Note : The first attribute slot is at j=1.
228 // In case the value of the index j exceeds the maximum number of reserved
229 // slots for the calib. flags, the number of reserved slots for the calib.
230 // flags is increased automatically.
231 // The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
235 cout << " *AliAttrib::GetCalFlags* Invalid argument j = " << j << endl;
241 fCalflags=new TArrayI(j);
244 Int_t size=fCalflags->GetSize();
251 Int_t edge=GetEdgeValue(j);
252 Int_t dead=GetDeadValue(j);
254 Int_t word=1000*edge+100*dead+10*gainflag+offsetflag;
256 fCalflags->AddAt(word,j-1);
258 ///////////////////////////////////////////////////////////////////////////
259 Int_t AliAttrib::GetGainFlag(Int_t j)
261 // Provide gain flag of the j-th (default j=1) attribute slot.
263 // flag = 1 : Gain was set
264 // 0 : Gain was not set
266 // Note : The first attribute slot is at j=1.
267 // In case j is invalid, 0 is returned.
271 cout << " *AliAttrib::GetGainFlag* Invalid argument j = " << j << endl;
277 if (j>0 && j<=(fCalflags->GetSize()))
279 Int_t word=fCalflags->At(j-1);
286 ///////////////////////////////////////////////////////////////////////////
287 Int_t AliAttrib::GetOffsetFlag(Int_t j)
289 // Provide offset flag of the j-th (default j=1) attribute slot.
291 // flag = 1 : Offset was set
292 // 0 : Offset was not set
294 // Note : The first attribute slot is at j=1.
295 // In case j is invalid, 0 is returned.
299 cout << " *AliAttrib::GetOffsetFlag* Invalid argument j = " << j << endl;
306 if (j>0 && j<=(fCalflags->GetSize()))
308 Int_t word=fCalflags->At(j-1);
314 ///////////////////////////////////////////////////////////////////////////
315 Float_t AliAttrib::GetGain(Int_t j)
317 // Provide gain value of the j-th (default j=1) attribute slot.
318 // The first attribute slot is at j=1.
319 // In case no gain value was set or the argument j is invalid, 0 is returned.
320 // Note : Use GetGainFlag(j) to check whether this gain was set or not.
324 cout << " *AliAttrib::GetGain* Invalid argument j = " << j << endl;
331 if (j>0 && j<=(fGains->GetSize()))
333 if (GetGainFlag(j)) gain=fGains->At(j-1);
338 ///////////////////////////////////////////////////////////////////////////
339 Float_t AliAttrib::GetOffset(Int_t j)
341 // Provide offset value of the j-th (default j=1) attribute slot.
342 // The first attribute slot at j=1.
343 // In case no offset value was set or the argument j is invalid, 0 is returned.
344 // Note : Use GetOffsetFlag(j) to check whether this offset was set or not.
348 cout << " *AliAttrib::GetOffset* Invalid argument j = " << j << endl;
355 if (j>0 && j<=(fOffsets->GetSize()))
357 if (GetOffsetFlag(j)) offset=fOffsets->At(j-1);
362 ///////////////////////////////////////////////////////////////////////////
363 void AliAttrib::ResetGain(Int_t j)
365 // Reset the gain value of the j-th (default j=1) attribute slot.
366 // Notes : The first attribute slot is at j=1.
367 // j=0 ==> All gain values will be reset.
371 Int_t size=fGains->GetSize();
373 if ((j>=0) && (j<=size))
377 fGains->AddAt(0,j-1);
378 Int_t oflag=GetOffsetFlag(j);
379 SetCalFlags(0,oflag,j);
383 for (Int_t i=0; i<size; i++)
386 Int_t oflag=GetOffsetFlag(i);
387 SetCalFlags(0,oflag,i);
393 cout << " *AliAttrib::ResetGain* Index j = " << j << " invalid." << endl;
397 ///////////////////////////////////////////////////////////////////////////
398 void AliAttrib::ResetOffset(Int_t j)
400 // Reset the offset value of the j-th (default j=1) attribute slot.
401 // Notes : The first attribute slot is at j=1.
402 // j=0 ==> All offset values will be reset.
404 if (!fOffsets) return;
406 Int_t size=fOffsets->GetSize();
408 if ((j>=0) && (j<=size))
412 fOffsets->AddAt(0,j-1);
413 Int_t gflag=GetGainFlag(j);
414 SetCalFlags(gflag,0,j);
418 for (Int_t i=0; i<size; i++)
420 fOffsets->AddAt(0,i);
421 Int_t gflag=GetGainFlag(i);
422 SetCalFlags(gflag,0,i);
428 cout << " *AliAttrib::ResetOffset* Index j = " << j << " invalid." << endl;
432 ///////////////////////////////////////////////////////////////////////////
433 void AliAttrib::DeleteCalibrations(Int_t mode)
435 // User selected delete of all gains and/or offsets.
436 // mode = 0 : All attributes (names, gains, offsets, edge and dead values) are deleted.
437 // 1 : Only the gains are deleted.
438 // 2 : Only the offsets are deleted.
439 // 3 : Both gains and offsets are deleted, but names, edge and dead values are kept.
441 // The default when invoking DeleteCalibrations() corresponds to mode=0.
443 if (mode<0 || mode>3)
445 cout << " *AliAttrib::DeleteCalibrations* Unknown mode : " << mode << endl;
446 cout << " Default mode=0 will be used." << endl;
450 if (mode==0 || mode==3)
464 if (fCalflags && mode==0)
469 if (fNames && mode==0)
496 ///////////////////////////////////////////////////////////////////////////
497 void AliAttrib::SetDead(Int_t j)
499 // Set the dead flag to 1 for the j-th (default j=1) attribute slot.
500 // Note : The first attribute slot is at j=1.
501 // In case the value of the index j exceeds the maximum number of reserved
502 // slots for the flags, the number of reserved slots for the flags
503 // is increased automatically.
504 // The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
508 cout << " *AliAttrib::SetDead* Invalid argument j = " << j << endl;
514 fCalflags=new TArrayI(j);
517 Int_t size=fCalflags->GetSize();
525 Int_t oflag=GetOffsetFlag(j);
526 Int_t gflag=GetGainFlag(j);
527 Int_t edge=GetEdgeValue(j);
529 Int_t word=1000*edge+100*dead+10*gflag+oflag;
531 fCalflags->AddAt(word,j-1);
533 ///////////////////////////////////////////////////////////////////////////
534 void AliAttrib::SetAlive(Int_t j)
536 // Set the dead flag to 0 for the j-th (default j=1) attribute slot.
537 // Note : The first attribute slot is at j=1.
538 // In case the value of the index j exceeds the maximum number of reserved
539 // slots for the flags, no action is taken since by default the dead flag is 0.
540 // The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
544 cout << " *AliAttrib::SetAlive* Invalid argument j = " << j << endl;
548 if (!fCalflags || j>fCalflags->GetSize()) return;
551 Int_t oflag=GetOffsetFlag(j);
552 Int_t gflag=GetGainFlag(j);
553 Int_t edge=GetEdgeValue(j);
555 Int_t word=1000*edge+100*dead+10*gflag+oflag;
557 fCalflags->AddAt(word,j-1);
559 ///////////////////////////////////////////////////////////////////////////
560 void AliAttrib::SetEdgeOn(Int_t j)
562 // Set the edge value to 1 for the j-th (default j=1) attribute slot.
563 // Note : The first attribute slot is at j=1.
564 // In case the value of the index j exceeds the maximum number of reserved
565 // slots for the flags, the number of reserved slots for the flags
566 // is increased automatically.
567 // The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
571 cout << " *AliAttrib::SetEdgeOn* Invalid argument j = " << j << endl;
577 ///////////////////////////////////////////////////////////////////////////
578 void AliAttrib::SetEdgeOff(Int_t j)
580 // Set the edge value to 0 for the j-th (default j=1) attribute slot.
581 // Note : The first attribute slot is at j=1.
582 // In case the value of the index j exceeds the maximum number of reserved
583 // slots for the flags, no action is taken since by default the edge flag is 0.
584 // The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
588 cout << " *AliAttrib::SetEdgeOff* Invalid argument j = " << j << endl;
592 if (!fCalflags || j>fCalflags->GetSize()) return;
596 ///////////////////////////////////////////////////////////////////////////
597 void AliAttrib::SetEdgeValue(Int_t val,Int_t j)
599 // Set the edge value to "val" for the j-th (default j=1) attribute slot.
600 // Note : The first attribute slot is at j=1.
601 // In case the value of the index j exceeds the maximum number of reserved
602 // slots for the flags, the number of reserved slots for the flags
603 // is increased automatically.
604 // The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
608 cout << " *AliAttrib::SetEdgeValue* Invalid argument j = " << j << endl;
614 fCalflags=new TArrayI(j);
617 Int_t size=fCalflags->GetSize();
625 Int_t dead=GetDeadValue(j);
626 Int_t gflag=GetGainFlag(j);
627 Int_t oflag=GetOffsetFlag(j);
629 Int_t word=1000*edge+100*dead+10*gflag+oflag;
631 fCalflags->AddAt(word,j-1);
633 ///////////////////////////////////////////////////////////////////////////
634 void AliAttrib::IncreaseEdgeValue(Int_t j)
636 // Increase the edge value by 1 for the j-th (default j=1) attribute slot.
637 // Note : The first attribute slot is at j=1.
638 // In case the value of the index j exceeds the maximum number of reserved
639 // slots for the flags, the number of reserved slots for the flags
640 // is increased automatically.
641 // The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
645 cout << " *AliAttrib::IncreaseEdgeValue* Invalid argument j = " << j << endl;
649 Int_t edge=GetEdgeValue();
650 SetEdgeValue(edge+1,j);
652 ///////////////////////////////////////////////////////////////////////////
653 void AliAttrib::DecreaseEdgeValue(Int_t j)
655 // Decrease the edge value by 1 for the j-th (default j=1) attribute slot.
656 // Note : The first attribute slot is at j=1.
657 // In case the value of the index j exceeds the maximum number of reserved
658 // slots for the flags, the number of reserved slots for the flags
659 // is increased automatically.
660 // The value stored is : 1000*edge + 100*dead + 10*gainflag + offsetflag.
664 cout << " *AliAttrib::DecreaseEdgeValue* Invalid argument j = " << j << endl;
668 Int_t edge=GetEdgeValue();
669 SetEdgeValue(edge-1,j);
671 ///////////////////////////////////////////////////////////////////////////
672 Int_t AliAttrib::GetEdgeValue(Int_t j)
674 // Provide edge value of the j-th (default j=1) attribute slot.
675 // Note : The first attribute slot is at j=1.
676 // In case j is invalid, 0 is returned.
680 cout << " *AliAttrib::GetEdgeValue* Invalid argument j = " << j << endl;
687 if (j>0 && j<=(fCalflags->GetSize()))
689 Int_t word=fCalflags->At(j-1);
695 ///////////////////////////////////////////////////////////////////////////
696 Int_t AliAttrib::GetDeadValue(Int_t j)
698 // Provide dead value of the j-th (default j=1) attribute slot.
699 // Note : The first attribute slot is at j=1.
700 // In case j is invalid, 0 is returned.
704 cout << " *AliAttrib::GetDeadValue* Invalid argument j = " << j << endl;
711 if (j>0 && j<=(fCalflags->GetSize()))
713 Int_t word=fCalflags->At(j-1);
720 ///////////////////////////////////////////////////////////////////////////
721 AliAttrib* AliAttrib::MakeCopy(AliAttrib& a)
723 // Make a deep copy of the input object and provide the pointer to the copy.
724 // This memberfunction enables automatic creation of new objects of the
725 // correct type depending on the argument type, a feature which may be very useful
726 // for containers when adding objects in case the container owns the objects.
728 AliAttrib* att=new AliAttrib(a);
731 ///////////////////////////////////////////////////////////////////////////
732 void AliAttrib::SetSlotName(TString s,Int_t j)
734 // Set a user defined name for the j-th (default j=1) slot.
735 // Note : The first attribute slot is at j=1.
739 cout << " *AliAttrib::SetSlotName* Invalid argument j = " << j << endl;
745 fNames=new TObjArray(j);
749 if (j>fNames->GetSize()) fNames->Expand(j);
751 TObjString* so=(TObjString*)fNames->At(j-1);
754 so=new TObjString(s.Data());
755 fNames->AddAt(so,j-1);
762 ///////////////////////////////////////////////////////////////////////////
763 TString AliAttrib::GetSlotName(Int_t j)
765 // Provide the user defined name for the j-th (default j=1) slot.
766 // Note : The first attribute slot is at j=1.
771 cout << " *AliAttrib::GetSlotName* Invalid argument j = " << j << endl;
777 if (j<=fNames->GetSize())
779 TObjString* so=(TObjString*)fNames->At(j-1);
780 if (so) s=so->GetString();
785 ///////////////////////////////////////////////////////////////////////////
786 Int_t AliAttrib::GetSlotIndex(TString name)
788 // Provide the slot index for the matching name.
789 // If no matching name is found, 0 is returned.
790 // Note : The first attribute slot is at j=1.
797 Int_t size=fNames->GetSize();
798 for (Int_t i=0; i<size; i++)
800 TObjString* so=(TObjString*)fNames->At(i);
802 if (s==name) index=i+1;
807 ///////////////////////////////////////////////////////////////////////////
808 void AliAttrib::Data(Int_t j)
810 // Provide attribute information for the j-th slot.
811 // The first slot is at j=1.
812 // In case j=0 (default) the data of all slots will be listed.
816 cout << " *AliAttrib::Data* Invalid argument j = " << j << endl;
822 if (GetGainFlag(j)) cout << " gain : " << GetGain(j);
823 if (GetOffsetFlag(j)) cout << " offset : " << GetOffset(j);
824 if (GetEdgeValue(j)) cout << " edge : " << GetEdgeValue(j);
825 if (GetDeadValue(j)) cout << " dead : " << GetDeadValue(j);
826 TString s=GetSlotName(j);
827 if (s!="") cout << " name : " << s.Data();
831 Int_t ng=GetNgains();
832 Int_t no=GetNoffsets();
834 if (fCalflags) nf=fCalflags->GetSize();
835 Int_t nn=GetNnames();
842 for (Int_t i=1; i<=n; i++)
845 if (GetGainFlag(i)) {cout << " gain : " << GetGain(i); printf=1;}
846 if (GetOffsetFlag(i)) {cout << " offset : " << GetOffset(i); printf=1;}
847 if (GetEdgeValue(i)) {cout << " edge : " << GetEdgeValue(i); printf=1;}
848 if (GetDeadValue(i)) {cout << " dead : " << GetDeadValue(i); printf=1;}
850 if (s!="") {cout << " name : " << s.Data(); printf=1;}
851 if (printf) cout << endl;
855 ///////////////////////////////////////////////////////////////////////////
856 void AliAttrib::Load(AliAttrib& a,Int_t j)
858 // Load attributes of the j-th slot of the input AliAttrib into this AliAttrib object.
860 // Note : if j=0, then all attributes of all slots are loaded
862 // The default is j=0.
866 cout << " *AliAttrib::Load* Invalid argument j = " << j << endl;
872 if (j==0) // load attributes for all slots
875 for (Int_t ig=1; ig<=n; ig++)
877 if (a.GetGainFlag(ig))
879 SetGain(a.GetGain(ig),ig);
887 for (Int_t io=1; io<=n; io++)
889 if (a.GetOffsetFlag(io))
891 SetOffset(a.GetOffset(io),io);
899 for (Int_t ic=1; ic<=n; ic++)
901 SetEdgeValue(a.GetEdgeValue(ic),ic);
902 if (a.GetDeadValue(ic))
914 for (Int_t in=1; in<=n; in++)
917 if (s!="") SetSlotName(s,in);
921 else // load attributes for specified j-th slot only
926 if (a.GetGainFlag(j))
928 SetGain(a.GetGain(j),j);
938 if (a.GetOffsetFlag(j))
940 SetOffset(a.GetOffset(j),j);
950 SetEdgeValue(a.GetEdgeValue(j),j);
951 if (a.GetDeadValue(j))
966 if (s!="") SetSlotName(s,j);
971 ///////////////////////////////////////////////////////////////////////////