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