]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibParam1I.cxx
Possibility to use loadlibs.C on Solaris x86
[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 {
57 /// Normal constructor, where theSize specifies the number of channels handled
58 /// by this object, and fillWithValue the default value assigned to each
59 /// channel.
60
61   if ( fSize > 0 )
62   {
63     fValues = new Int_t[fSize];
64     memset(fValues,fillWithValue,fSize*sizeof(Int_t));
65   }
66 }
67
68 //_____________________________________________________________________________
69 AliMUONCalibParam1I::AliMUONCalibParam1I(const AliMUONCalibParam1I& other) 
70 : AliMUONVCalibParam(other),
71 fSize(0),
72 fValues(0x0)
73 {
74 /// Copy constructor
75
76   other.CopyTo(*this);
77 }
78
79 //_____________________________________________________________________________
80 AliMUONCalibParam1I&
81 AliMUONCalibParam1I::operator=(const AliMUONCalibParam1I& other) 
82 {
83 /// Assignment operator
84
85   AliMUONVCalibParam::operator=(other);
86   other.CopyTo(*this);
87   return *this;
88 }
89
90 //_____________________________________________________________________________
91 AliMUONCalibParam1I::~AliMUONCalibParam1I()
92 {
93 /// Destructor.
94
95   delete[] fValues;
96 }
97
98 //_____________________________________________________________________________
99 void
100 AliMUONCalibParam1I::CopyTo(AliMUONCalibParam1I& destination) const
101 {
102 /// Copy this into destination.
103
104   delete[] destination.fValues;
105   destination.fSize = fSize;
106   if ( fSize > 0 )
107   {
108     destination.fValues = new Int_t[fSize];
109     for ( Int_t i = 0; i < fSize; ++i )
110     {
111       destination.fValues[i] = fValues[i];
112     }
113   }
114 }
115
116 //_____________________________________________________________________________
117 void
118 AliMUONCalibParam1I::Print(Option_t* opt) const
119 {
120 /// Output this object to stdout.
121 /// If opt=="full", then all channels are printed, otherwise
122 /// only the general characteristics are printed.
123
124   TString sopt(opt);
125   sopt.ToUpper();
126   cout << "AliMUONCalibParam1I - Size=" << Size()
127     << " Dimension=" << Dimension()
128     << endl;
129   if ( sopt.Contains("FULL") )
130   {
131     for ( Int_t i = 0; i < Size(); ++i )
132     {
133       cout << setw(6) << ValueAsInt(i) << " , " << endl;
134     }
135   }
136 }
137
138 //_____________________________________________________________________________
139 void
140 AliMUONCalibParam1I::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
141 {
142 /// Set the value as a float, which is casted to an int prior to storage.
143
144   SetValueAsInt(i,j,TMath::Nint(value));
145 }
146
147 //_____________________________________________________________________________
148 void
149 AliMUONCalibParam1I::SetValueAsInt(Int_t i, Int_t j, Int_t value)
150 {
151 /// Set the value for a given channel.
152 /// (i,j) are checked for correctness before use.
153
154   if ( j != 0 || i >= fSize || i < 0 )
155   {
156     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
157                   i,j,Size()-1,Dimension()-1));
158   }
159   else
160   {
161     fValues[i]=value;
162   }
163 }
164
165 //_____________________________________________________________________________
166 Float_t
167 AliMUONCalibParam1I::ValueAsFloat(Int_t i, Int_t j) const
168 {
169 /// Return one value as a float.
170
171   return 1.0*ValueAsInt(i,j);
172 }
173
174 //_____________________________________________________________________________
175 Int_t
176 AliMUONCalibParam1I::ValueAsInt(Int_t i, Int_t j) const
177 {
178 /// Return one value as an integer, after checking that (i,j)
179 /// are valid indices.
180
181   if ( j != 0 || i >= fSize || i < 0 )
182   {
183     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
184                   i,j,Size()-1,Dimension()-1));
185     return 0;
186   }
187   else
188   {
189     return fValues[i];
190   }
191 }