]>
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 | ||
9d5f6a64 | 25 | /// |
5398f946 | 26 | /// \class AliMUONCalibParam2F |
27 | /// \brief Implementation of AliMUONVCalibParam for pair of floats. | |
9d5f6a64 | 28 | /// |
5398f946 | 29 | /// Handle the case of 2 floating point parameters per channel. |
9d5f6a64 | 30 | /// Conceptually, this class is the equivalent of a vector or float pairs, |
31 | /// but it is implemented using bare Float_t[] array. | |
32 | /// | |
5398f946 | 33 | /// \author Laurent Aphecetche |
9d5f6a64 | 34 | |
5398f946 | 35 | /// \cond CLASSIMP |
9369bbee | 36 | ClassImp(AliMUONCalibParam2F) |
5398f946 | 37 | /// \endcond |
9369bbee | 38 | |
39 | //_____________________________________________________________________________ | |
40 | AliMUONCalibParam2F::AliMUONCalibParam2F() | |
41 | : AliMUONVCalibParam(), | |
42 | fSize(0), | |
43 | fN(0), | |
44 | fValues(0x0) | |
45 | { | |
5398f946 | 46 | /// Default constructor. |
9369bbee | 47 | } |
48 | ||
49 | //_____________________________________________________________________________ | |
50 | AliMUONCalibParam2F::AliMUONCalibParam2F(Int_t theSize, Int_t fillWithValue) | |
51 | : AliMUONVCalibParam(), | |
52 | fSize(theSize), | |
53 | fN(fSize*Dimension()) | |
54 | { | |
5398f946 | 55 | /// Normal constructor, where theSize specifies the number of channels handled |
56 | /// by this object, and fillWithValue the default value assigned to each | |
57 | /// channel. | |
58 | ||
9369bbee | 59 | if ( fN > 0 ) |
60 | { | |
61 | fValues = new Float_t[fN]; | |
62 | memset(fValues,fillWithValue,fN*sizeof(Float_t)); | |
63 | } | |
64 | } | |
65 | ||
884a73f1 | 66 | |
9d5f6a64 | 67 | //_____________________________________________________________________________ |
68 | AliMUONCalibParam2F::AliMUONCalibParam2F(const AliMUONCalibParam2F& other) | |
69 | : AliMUONVCalibParam(), | |
70 | fSize(0), | |
71 | fN(0), | |
72 | fValues(0x0) | |
73 | { | |
5398f946 | 74 | /// Copy constructor. |
75 | ||
9d5f6a64 | 76 | other.CopyTo(*this); |
77 | } | |
78 | ||
79 | //_____________________________________________________________________________ | |
80 | AliMUONCalibParam2F& | |
81 | AliMUONCalibParam2F::operator=(const AliMUONCalibParam2F& other) | |
82 | { | |
5398f946 | 83 | /// Assignment operator |
84 | ||
9d5f6a64 | 85 | other.CopyTo(*this); |
86 | return *this; | |
884a73f1 | 87 | } |
88 | ||
9369bbee | 89 | //_____________________________________________________________________________ |
90 | AliMUONCalibParam2F::~AliMUONCalibParam2F() | |
91 | { | |
5398f946 | 92 | /// Destructor |
93 | ||
9369bbee | 94 | delete[] fValues; |
95 | } | |
96 | ||
9d5f6a64 | 97 | //_____________________________________________________________________________ |
98 | void | |
99 | AliMUONCalibParam2F::CopyTo(AliMUONCalibParam2F& destination) const | |
884a73f1 | 100 | { |
5398f946 | 101 | /// Copy *this to destination |
102 | ||
9d5f6a64 | 103 | delete[] destination.fValues; |
104 | destination.fN = fN; | |
105 | destination.fSize = fSize; | |
884a73f1 | 106 | |
9d5f6a64 | 107 | if ( fN > 0 ) |
108 | { | |
109 | destination.fValues = new Float_t[fN]; | |
110 | for ( Int_t i = 0; i < fN; ++i ) | |
111 | { | |
112 | destination.fValues[i] = fValues[i]; | |
113 | } | |
114 | } | |
115 | } | |
884a73f1 | 116 | |
9369bbee | 117 | //_____________________________________________________________________________ |
118 | Int_t | |
119 | AliMUONCalibParam2F::Index(Int_t i, Int_t j) const | |
120 | { | |
5398f946 | 121 | /// Compute the 1D index of the internal storage from the pair (i,j) |
122 | /// Returns -1 if the (i,j) pair is invalid | |
123 | ||
9369bbee | 124 | if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() ) |
125 | { | |
126 | return i + Size()*j; | |
127 | } | |
128 | return -1; | |
129 | } | |
130 | ||
131 | //_____________________________________________________________________________ | |
132 | void | |
133 | AliMUONCalibParam2F::Print(Option_t* opt) const | |
134 | { | |
5398f946 | 135 | /// Output this object to stdout. |
136 | /// If opt=="full", then all channels are printed, otherwise | |
137 | /// only the general characteristics are printed. | |
138 | ||
9369bbee | 139 | TString sopt(opt); |
140 | sopt.ToUpper(); | |
141 | cout << "AliMUONCalibParam2F - Size=" << Size() | |
142 | << " Dimension=" << Dimension() | |
143 | << endl; | |
144 | if ( sopt.Contains("FULL") ) | |
145 | { | |
146 | for ( Int_t i = 0; i < Size(); ++i ) | |
147 | { | |
148 | cout << setw(6) << ValueAsFloat(i,0) << "," << ValueAsFloat(i,1) << endl; | |
149 | } | |
150 | } | |
151 | } | |
152 | ||
153 | //_____________________________________________________________________________ | |
154 | void | |
155 | AliMUONCalibParam2F::SetValueAsFloat(Int_t i, Int_t j, Float_t value) | |
156 | { | |
5398f946 | 157 | /// Set one value as a float, after checking that the indices are correct. |
158 | ||
9369bbee | 159 | Int_t ix = Index(i,j); |
160 | ||
161 | if ( ix < 0 ) | |
162 | { | |
163 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
164 | i,j,Size()-1,Dimension()-1)); | |
165 | } | |
166 | else | |
167 | { | |
168 | fValues[ix]=value; | |
169 | } | |
170 | } | |
171 | ||
172 | //_____________________________________________________________________________ | |
173 | void | |
174 | AliMUONCalibParam2F::SetValueAsInt(Int_t i, Int_t j, Int_t value) | |
175 | { | |
5398f946 | 176 | /// Set one value as an int. |
177 | ||
9369bbee | 178 | SetValueAsFloat(i,j,static_cast<Float_t>(value)); |
179 | } | |
180 | ||
181 | //_____________________________________________________________________________ | |
182 | Float_t | |
183 | AliMUONCalibParam2F::ValueAsFloat(Int_t i, Int_t j) const | |
184 | { | |
5398f946 | 185 | /// Return the value as a float (which it is), after checking indices. |
186 | ||
9369bbee | 187 | Int_t ix = Index(i,j); |
188 | ||
189 | if ( ix < 0 ) | |
190 | { | |
191 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
192 | i,j,Size()-1,Dimension()-1)); | |
193 | return 0.0; | |
194 | } | |
195 | else | |
196 | { | |
197 | return fValues[ix]; | |
198 | } | |
199 | } | |
200 | ||
201 | //_____________________________________________________________________________ | |
202 | Int_t | |
203 | AliMUONCalibParam2F::ValueAsInt(Int_t i, Int_t j) const | |
204 | { | |
5398f946 | 205 | /// Return the value as an int, by rounding the internal float value. |
206 | ||
9369bbee | 207 | Float_t v = ValueAsFloat(i,j); |
208 | return TMath::Nint(v); | |
209 | } |