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