]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCalibParam2F.cxx
Implementations of VCalibParam for 2 floats (used by pedestals and gains)
[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
25ClassImp(AliMUONCalibParam2F)
26
27//_____________________________________________________________________________
28AliMUONCalibParam2F::AliMUONCalibParam2F()
29: AliMUONVCalibParam(),
30 fSize(0),
31 fN(0),
32 fValues(0x0)
33{
34 //
35 // Default ctor.
36 //
37}
38
39//_____________________________________________________________________________
40AliMUONCalibParam2F::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//_____________________________________________________________________________
58AliMUONCalibParam2F::~AliMUONCalibParam2F()
59{
60 //
61 // dtor
62 //
63 delete[] fValues;
64}
65
66//_____________________________________________________________________________
67Int_t
68AliMUONCalibParam2F::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//_____________________________________________________________________________
82void
83AliMUONCalibParam2F::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//_____________________________________________________________________________
105void
106AliMUONCalibParam2F::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//_____________________________________________________________________________
125void
126AliMUONCalibParam2F::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//_____________________________________________________________________________
135Float_t
136AliMUONCalibParam2F::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//_____________________________________________________________________________
156Int_t
157AliMUONCalibParam2F::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}