]>
Commit | Line | Data |
---|---|---|
9369bbee | 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 | #include "AliMUONCalibParam2F.h" | |
19 | ||
20 | #include "AliLog.h" | |
21 | #include "Riostream.h" | |
22 | #include "TMath.h" | |
23 | #include "TString.h" | |
24 | ||
25 | ClassImp(AliMUONCalibParam2F) | |
26 | ||
27 | //_____________________________________________________________________________ | |
28 | AliMUONCalibParam2F::AliMUONCalibParam2F() | |
29 | : AliMUONVCalibParam(), | |
30 | fSize(0), | |
31 | fN(0), | |
32 | fValues(0x0) | |
33 | { | |
34 | // | |
35 | // Default ctor. | |
36 | // | |
37 | } | |
38 | ||
39 | //_____________________________________________________________________________ | |
40 | AliMUONCalibParam2F::AliMUONCalibParam2F(Int_t theSize, Int_t fillWithValue) | |
41 | : AliMUONVCalibParam(), | |
42 | fSize(theSize), | |
43 | fN(fSize*Dimension()) | |
44 | { | |
45 | // | |
46 | // Normal ctor, where theSize specifies the number of channels handled | |
47 | // by this object, and fillWithValue the default value assigned to each | |
48 | // channel. | |
49 | // | |
50 | if ( fN > 0 ) | |
51 | { | |
52 | fValues = new Float_t[fN]; | |
53 | memset(fValues,fillWithValue,fN*sizeof(Float_t)); | |
54 | } | |
55 | } | |
56 | ||
57 | //_____________________________________________________________________________ | |
58 | AliMUONCalibParam2F::~AliMUONCalibParam2F() | |
59 | { | |
60 | // | |
61 | // dtor | |
62 | // | |
63 | delete[] fValues; | |
64 | } | |
65 | ||
66 | //_____________________________________________________________________________ | |
67 | Int_t | |
68 | AliMUONCalibParam2F::Index(Int_t i, Int_t j) const | |
69 | { | |
70 | // | |
71 | // Compute the 1D index of the internal storage from the pair (i,j) | |
72 | // Returns -1 if the (i,j) pair is invalid | |
73 | // | |
74 | if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() ) | |
75 | { | |
76 | return i + Size()*j; | |
77 | } | |
78 | return -1; | |
79 | } | |
80 | ||
81 | //_____________________________________________________________________________ | |
82 | void | |
83 | AliMUONCalibParam2F::Print(Option_t* opt) const | |
84 | { | |
85 | // | |
86 | // Output this object to stdout. | |
87 | // If opt=="full", then all channels are printed, otherwise | |
88 | // only the general characteristics are printed. | |
89 | // | |
90 | TString sopt(opt); | |
91 | sopt.ToUpper(); | |
92 | cout << "AliMUONCalibParam2F - Size=" << Size() | |
93 | << " Dimension=" << Dimension() | |
94 | << endl; | |
95 | if ( sopt.Contains("FULL") ) | |
96 | { | |
97 | for ( Int_t i = 0; i < Size(); ++i ) | |
98 | { | |
99 | cout << setw(6) << ValueAsFloat(i,0) << "," << ValueAsFloat(i,1) << endl; | |
100 | } | |
101 | } | |
102 | } | |
103 | ||
104 | //_____________________________________________________________________________ | |
105 | void | |
106 | AliMUONCalibParam2F::SetValueAsFloat(Int_t i, Int_t j, Float_t value) | |
107 | { | |
108 | // | |
109 | // Set one value as a float, after checking that the indices are correct. | |
110 | // | |
111 | Int_t ix = Index(i,j); | |
112 | ||
113 | if ( ix < 0 ) | |
114 | { | |
115 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
116 | i,j,Size()-1,Dimension()-1)); | |
117 | } | |
118 | else | |
119 | { | |
120 | fValues[ix]=value; | |
121 | } | |
122 | } | |
123 | ||
124 | //_____________________________________________________________________________ | |
125 | void | |
126 | AliMUONCalibParam2F::SetValueAsInt(Int_t i, Int_t j, Int_t value) | |
127 | { | |
128 | // | |
129 | // Set one value as an int. | |
130 | // | |
131 | SetValueAsFloat(i,j,static_cast<Float_t>(value)); | |
132 | } | |
133 | ||
134 | //_____________________________________________________________________________ | |
135 | Float_t | |
136 | AliMUONCalibParam2F::ValueAsFloat(Int_t i, Int_t j) const | |
137 | { | |
138 | // | |
139 | // Return the value as a float (which it is), after checking indices. | |
140 | // | |
141 | Int_t ix = Index(i,j); | |
142 | ||
143 | if ( ix < 0 ) | |
144 | { | |
145 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
146 | i,j,Size()-1,Dimension()-1)); | |
147 | return 0.0; | |
148 | } | |
149 | else | |
150 | { | |
151 | return fValues[ix]; | |
152 | } | |
153 | } | |
154 | ||
155 | //_____________________________________________________________________________ | |
156 | Int_t | |
157 | AliMUONCalibParam2F::ValueAsInt(Int_t i, Int_t j) const | |
158 | { | |
159 | // | |
160 | // Return the value as an int, by rounding the internal float value. | |
161 | // | |
162 | Float_t v = ValueAsFloat(i,j); | |
163 | return TMath::Nint(v); | |
164 | } |