]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibParam2F.cxx
Minor fixes in the event tag to take into account the new way of storing the trigger...
[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 /// 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
32 ClassImp(AliMUONCalibParam2F)
33
34 //_____________________________________________________________________________
35 AliMUONCalibParam2F::AliMUONCalibParam2F() 
36 : AliMUONVCalibParam(),
37   fSize(0),
38   fN(0),
39   fValues(0x0)
40 {
41   //
42   // Default ctor.
43   // 
44 }
45
46 //_____________________________________________________________________________
47 AliMUONCalibParam2F::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
64
65 //_____________________________________________________________________________
66 AliMUONCalibParam2F::AliMUONCalibParam2F(const AliMUONCalibParam2F& other) 
67 : AliMUONVCalibParam(),
68 fSize(0),
69 fN(0),
70 fValues(0x0)
71 {
72   other.CopyTo(*this);
73 }
74
75 //_____________________________________________________________________________
76 AliMUONCalibParam2F&
77 AliMUONCalibParam2F::operator=(const AliMUONCalibParam2F& other) 
78 {
79   other.CopyTo(*this);
80   return *this;
81 }
82
83 //_____________________________________________________________________________
84 AliMUONCalibParam2F::~AliMUONCalibParam2F()
85 {
86   //
87   // dtor
88   //
89   delete[] fValues;
90 }
91
92 //_____________________________________________________________________________
93 void
94 AliMUONCalibParam2F::CopyTo(AliMUONCalibParam2F& destination) const
95 {
96   //
97   // Copy *this to destination
98   //
99   delete[] destination.fValues;
100   destination.fN = fN;
101   destination.fSize = fSize;
102
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 }
112
113 //_____________________________________________________________________________
114 Int_t
115 AliMUONCalibParam2F::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 //_____________________________________________________________________________
129 void
130 AliMUONCalibParam2F::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 //_____________________________________________________________________________
152 void
153 AliMUONCalibParam2F::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 //_____________________________________________________________________________
172 void
173 AliMUONCalibParam2F::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 //_____________________________________________________________________________
182 Float_t
183 AliMUONCalibParam2F::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 //_____________________________________________________________________________
203 Int_t
204 AliMUONCalibParam2F::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 }