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