]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibParam1I.cxx
Coding conventions (Annalisa)
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibParam1I.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 "AliMUONCalibParam1I.h"
19
20 #include "AliLog.h"
21 #include "Riostream.h"
22 #include "TMath.h"
23 #include "TString.h"
24
25 /// This class is implementing the AliMUONVCalibParam interface.
26 /// 
27 /// It stores a given number of integers.
28 /// 
29 /// Those integers can also be retrieved as floats if really needed 
30 /// (this is to comply with the base class).
31 /// 
32 /// You might consider just as it is, namely a C++ wrapper to 
33 /// a plain int[] array.
34
35 ClassImp(AliMUONCalibParam1I)
36
37 //_____________________________________________________________________________
38 AliMUONCalibParam1I::AliMUONCalibParam1I() 
39 : AliMUONVCalibParam(),
40   fSize(0),
41   fValues(0x0)
42 {
43     //
44     // Default ctor.
45     // 
46 }
47
48 //_____________________________________________________________________________
49 AliMUONCalibParam1I::AliMUONCalibParam1I(Int_t theSize, Int_t fillWithValue) 
50 : AliMUONVCalibParam(),
51   fSize(theSize)
52 {
53   //
54   // Normal ctor, where theSize specifies the number of channels handled
55   // by this object, and fillWithValue the default value assigned to each
56   // channel.
57   //
58   if ( fSize > 0 )
59   {
60     fValues = new Int_t[fSize];
61     memset(fValues,fillWithValue,fSize*sizeof(Int_t));
62   }
63 }
64
65 //_____________________________________________________________________________
66 AliMUONCalibParam1I::AliMUONCalibParam1I(const AliMUONCalibParam1I& other) 
67 : AliMUONVCalibParam(other),
68 fSize(0),
69 fValues(0x0)
70 {
71   //
72   // Copy ctor
73   //
74   other.CopyTo(*this);
75 }
76
77 //_____________________________________________________________________________
78 AliMUONCalibParam1I&
79 AliMUONCalibParam1I::operator=(const AliMUONCalibParam1I& other) 
80 {
81   //
82   // Assignment operator
83   //
84   AliMUONVCalibParam::operator=(other);
85   other.CopyTo(*this);
86   return *this;
87 }
88
89 //_____________________________________________________________________________
90 AliMUONCalibParam1I::~AliMUONCalibParam1I()
91 {
92   //
93   // dtor.
94   //
95   delete[] fValues;
96 }
97
98 //_____________________________________________________________________________
99 void
100 AliMUONCalibParam1I::CopyTo(AliMUONCalibParam1I& destination) const
101 {
102   //
103   // Copy this into destination.
104   //
105   delete[] destination.fValues;
106   destination.fSize = fSize;
107   if ( fSize > 0 )
108   {
109     destination.fValues = new Int_t[fSize];
110     for ( Int_t i = 0; i < fSize; ++i )
111     {
112       destination.fValues[i] = fValues[i];
113     }
114   }
115 }
116
117 //_____________________________________________________________________________
118 void
119 AliMUONCalibParam1I::Print(Option_t* opt) const
120 {
121   //
122   // Output this object to stdout.
123   // If opt=="full", then all channels are printed, otherwise
124   // only the general characteristics are printed.
125   //
126   TString sopt(opt);
127   sopt.ToUpper();
128   cout << "AliMUONCalibParam1I - Size=" << Size()
129     << " Dimension=" << Dimension()
130     << endl;
131   if ( sopt.Contains("FULL") )
132   {
133     for ( Int_t i = 0; i < Size(); ++i )
134     {
135       cout << setw(6) << ValueAsInt(i) << " , " << endl;
136     }
137   }
138 }
139
140 //_____________________________________________________________________________
141 void
142 AliMUONCalibParam1I::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
143 {
144   //
145   // Set the value as a float, which is casted to an int prior to storage.
146   //
147   SetValueAsInt(i,j,TMath::Nint(value));
148 }
149
150 //_____________________________________________________________________________
151 void
152 AliMUONCalibParam1I::SetValueAsInt(Int_t i, Int_t j, Int_t value)
153 {
154   //
155   // Set the value for a given channel.
156   // (i,j) are checked for correctness before use.
157   //
158   if ( j != 0 || i >= fSize || i < 0 )
159   {
160     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
161                   i,j,Size()-1,Dimension()-1));
162   }
163   else
164   {
165     fValues[i]=value;
166   }
167 }
168
169 //_____________________________________________________________________________
170 Float_t
171 AliMUONCalibParam1I::ValueAsFloat(Int_t i, Int_t j) const
172 {
173   //
174   // Return one value as a float.
175   //
176   return 1.0*ValueAsInt(i,j);
177 }
178
179 //_____________________________________________________________________________
180 Int_t
181 AliMUONCalibParam1I::ValueAsInt(Int_t i, Int_t j) const
182 {
183   //
184   // Return one value as an integer, after checking that (i,j)
185   // are valid indices.
186   //
187   if ( j != 0 || i >= fSize || i < 0 )
188   {
189     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
190                   i,j,Size()-1,Dimension()-1));
191     return 0;
192   }
193   else
194   {
195     return fValues[i];
196   }
197 }