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