]>
Commit | Line | Data |
---|---|---|
8741815f | 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 "AliMUONSparseHisto.h" | |
19 | #include <TString.h> | |
20 | #include <Riostream.h> | |
21 | #include <TH1.h> | |
22 | ||
23 | /// \class AliMUONSparseHisto | |
24 | /// | |
25 | /// Tiny histogram-like class to hold adc distributions of tracker data. | |
26 | /// Only intent of this class is to minimize memory consumption, in | |
27 | /// order to fit a maximum number of channel histograms into memory. | |
28 | /// The rest is not supported ;-) | |
29 | /// | |
30 | /// \author Laurent Aphecetche, Subatech | |
31 | ||
32 | /// \cond CLASSIMP | |
33 | ClassImp(AliMUONSparseHisto) | |
34 | /// \endcond | |
35 | ||
36 | //______________________________________________________________________________ | |
37 | AliMUONSparseHisto::AliMUONSparseHisto() | |
38 | : TObject(), | |
39 | fNbins(0), | |
40 | fArray(0x0) | |
41 | { | |
42 | /// ctor | |
43 | } | |
44 | ||
45 | //______________________________________________________________________________ | |
46 | AliMUONSparseHisto::AliMUONSparseHisto(const AliMUONSparseHisto& rhs) | |
47 | : TObject(rhs), | |
48 | fNbins(0), | |
49 | fArray(0x0) | |
50 | { | |
51 | /// copy ctor | |
52 | rhs.Copy(*this); | |
53 | } | |
54 | ||
55 | //______________________________________________________________________________ | |
56 | AliMUONSparseHisto& | |
57 | AliMUONSparseHisto::operator=(const AliMUONSparseHisto& rhs) | |
58 | { | |
59 | /// assignment operator | |
60 | if ( this != &rhs ) | |
61 | { | |
62 | rhs.Copy(*this); | |
63 | } | |
64 | return *this; | |
65 | } | |
66 | ||
67 | //______________________________________________________________________________ | |
68 | AliMUONSparseHisto::~AliMUONSparseHisto() | |
69 | { | |
70 | /// dtor | |
71 | delete[] fArray; | |
72 | } | |
73 | ||
74 | //______________________________________________________________________________ | |
75 | void | |
76 | AliMUONSparseHisto::Clear(Option_t*) | |
77 | { | |
78 | /// Reset the content | |
79 | delete[] fArray; | |
80 | fArray = 0x0; | |
81 | fNbins = 0; | |
82 | } | |
83 | ||
84 | //______________________________________________________________________________ | |
85 | void | |
86 | AliMUONSparseHisto::Copy(TObject& object) const | |
87 | { | |
88 | /// Copy this to *object | |
89 | TObject::Copy(object); | |
90 | AliMUONSparseHisto& h = static_cast<AliMUONSparseHisto&>(object); | |
91 | delete[] h.fArray; | |
92 | h.fArray = 0x0; | |
93 | h.fNbins = GetNbins(); | |
94 | if ( GetNbins() > 0 ) | |
95 | { | |
96 | h.fArray = new Int_t[GetNbins()]; | |
97 | for ( Int_t i = 0; i < GetNbins(); ++i ) | |
98 | { | |
99 | h.fArray[i] = GetBinContent(i); | |
100 | } | |
101 | } | |
102 | } | |
103 | ||
104 | //______________________________________________________________________________ | |
105 | void | |
106 | AliMUONSparseHisto::Decode(Int_t value, Int_t& adc, Int_t& count) const | |
107 | { | |
108 | /// Convert value into (adc,count) pair | |
109 | ||
110 | adc = ( value & 0xFFF00000 ) >> 20; | |
111 | count = ( value & 0x000FFFFF ); | |
112 | } | |
113 | ||
114 | //______________________________________________________________________________ | |
115 | Int_t | |
116 | AliMUONSparseHisto::Encode(Int_t adc, Int_t count) const | |
117 | { | |
118 | /// Convert (adc,count) into a single value | |
119 | return ( ( adc & 0xFFF ) ) << 20 | ( count & 0xFFFFF ); | |
120 | } | |
121 | ||
122 | //______________________________________________________________________________ | |
123 | void | |
124 | AliMUONSparseHisto::Expand() | |
125 | { | |
126 | /// Make fArray of size n | |
127 | if (!fArray || !fNbins) | |
128 | { | |
129 | delete[] fArray; | |
130 | fArray = new Int_t[1]; | |
131 | fNbins = 1; | |
132 | } | |
133 | else | |
134 | { | |
135 | Int_t* tmp = new Int_t[fNbins+1]; | |
136 | for ( Int_t i = 0; i < fNbins; ++i ) | |
137 | { | |
138 | tmp[i] = fArray[i]; | |
139 | } | |
140 | delete[] fArray; | |
141 | fArray = tmp; | |
142 | ++fNbins; | |
143 | } | |
144 | } | |
145 | ||
146 | //______________________________________________________________________________ | |
147 | Int_t | |
148 | AliMUONSparseHisto::Fill(Int_t adc) | |
149 | { | |
150 | /// Fill | |
151 | ||
152 | if ( adc < 0 || adc > 4095 ) return -1; | |
153 | ||
154 | Int_t i = Find(adc); | |
155 | ||
156 | if ( i < 0 ) | |
157 | { | |
158 | Int_t n = fNbins; | |
159 | Expand(); | |
160 | fArray[n] = Encode(adc,1); | |
161 | i = n; | |
162 | } | |
163 | else | |
164 | { | |
165 | Int_t iadc,icontent; | |
166 | Decode(fArray[i],iadc,icontent); | |
167 | fArray[i] = Encode(adc,icontent+1); | |
168 | } | |
169 | ||
170 | return i; | |
171 | } | |
172 | ||
173 | //______________________________________________________________________________ | |
174 | Int_t | |
175 | AliMUONSparseHisto::Find(Int_t adc) const | |
176 | { | |
177 | /// Return the index in fArray of adc, or -1 if not found | |
178 | for ( Int_t i = 0; i < GetNbins(); ++i ) | |
179 | { | |
180 | Int_t content = GetBinContent(i); | |
181 | Int_t iadc,value; | |
182 | Decode(content,iadc,value); | |
183 | if ( iadc == adc ) return i; | |
184 | } | |
185 | return -1; | |
186 | } | |
187 | ||
188 | //______________________________________________________________________________ | |
189 | Int_t | |
190 | AliMUONSparseHisto::GetBinContent(Int_t bin) const | |
191 | { | |
192 | /// Get bin content. Note that the content is compacted, so you must | |
193 | /// use Decode() method to get (adc,count) values. | |
194 | if ( bin >= 0 && bin < GetNbins() ) return fArray[bin]; | |
195 | return 0; | |
196 | } | |
197 | ||
198 | //______________________________________________________________________________ | |
199 | void | |
200 | AliMUONSparseHisto::Print(Option_t* opt) const | |
201 | { | |
202 | /// Printout | |
203 | Int_t id1 = ( GetUniqueID() & 0xFFFF0000 ) >> 16; | |
204 | Int_t id2 = GetUniqueID() & 0xFFFF; | |
205 | ||
206 | cout << "(" << id1 << "," << id2 << ") n bins = " << GetNbins() << endl; | |
207 | ||
208 | TString sopt(opt); | |
209 | sopt.ToUpper(); | |
210 | ||
211 | if ( sopt.Contains("FULL") ) | |
212 | { | |
213 | for ( Int_t i = 0; i < GetNbins(); ++i ) | |
214 | { | |
215 | Int_t content = GetBinContent(i); | |
216 | Int_t adc,value; | |
217 | Decode(content,adc,value); | |
218 | cout << Form("i %4d content %10x adc %4d value %6d",i,content,adc,value) | |
219 | << endl; | |
220 | } | |
221 | } | |
222 | } |