1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONSparseHisto.h"
20 #include <Riostream.h>
23 /// \class AliMUONSparseHisto
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 ;-)
30 /// \author Laurent Aphecetche, Subatech
33 ClassImp(AliMUONSparseHisto)
36 //______________________________________________________________________________
37 AliMUONSparseHisto::AliMUONSparseHisto()
45 //______________________________________________________________________________
46 AliMUONSparseHisto::AliMUONSparseHisto(const AliMUONSparseHisto& rhs)
55 //______________________________________________________________________________
57 AliMUONSparseHisto::operator=(const AliMUONSparseHisto& rhs)
59 /// assignment operator
67 //______________________________________________________________________________
68 AliMUONSparseHisto::~AliMUONSparseHisto()
74 //______________________________________________________________________________
76 AliMUONSparseHisto::Clear(Option_t*)
84 //______________________________________________________________________________
86 AliMUONSparseHisto::Copy(TObject& object) const
88 /// Copy this to *object
89 TObject::Copy(object);
90 AliMUONSparseHisto& h = static_cast<AliMUONSparseHisto&>(object);
93 h.fNbins = GetNbins();
96 h.fArray = new Int_t[GetNbins()];
97 for ( Int_t i = 0; i < GetNbins(); ++i )
99 h.fArray[i] = GetBinContent(i);
104 //______________________________________________________________________________
106 AliMUONSparseHisto::Decode(Int_t value, Int_t& adc, Int_t& count) const
108 /// Convert value into (adc,count) pair
110 adc = ( value & 0xFFF00000 ) >> 20;
111 count = ( value & 0x000FFFFF );
114 //______________________________________________________________________________
116 AliMUONSparseHisto::Encode(Int_t adc, Int_t count) const
118 /// Convert (adc,count) into a single value
119 return ( ( adc & 0xFFF ) ) << 20 | ( count & 0xFFFFF );
122 //______________________________________________________________________________
124 AliMUONSparseHisto::Expand()
126 /// Make fArray of size n
127 if (!fArray || !fNbins)
130 fArray = new Int_t[1];
135 Int_t* tmp = new Int_t[fNbins+1];
136 for ( Int_t i = 0; i < fNbins; ++i )
146 //______________________________________________________________________________
148 AliMUONSparseHisto::Fill(Int_t adc)
152 if ( adc < 0 || adc > 4095 ) return -1;
160 fArray[n] = Encode(adc,1);
166 Decode(fArray[i],iadc,icontent);
167 fArray[i] = Encode(adc,icontent+1);
173 //______________________________________________________________________________
175 AliMUONSparseHisto::Find(Int_t adc) const
177 /// Return the index in fArray of adc, or -1 if not found
178 for ( Int_t i = 0; i < GetNbins(); ++i )
180 Int_t content = GetBinContent(i);
182 Decode(content,iadc,value);
183 if ( iadc == adc ) return i;
188 //______________________________________________________________________________
190 AliMUONSparseHisto::GetBinContent(Int_t bin) const
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];
198 //______________________________________________________________________________
200 AliMUONSparseHisto::Print(Option_t* opt) const
203 Int_t id1 = ( GetUniqueID() & 0xFFFF0000 ) >> 16;
204 Int_t id2 = GetUniqueID() & 0xFFFF;
206 cout << "(" << id1 << "," << id2 << ") n bins = " << GetNbins() << endl;
211 if ( sopt.Contains("FULL") )
213 for ( Int_t i = 0; i < GetNbins(); ++i )
215 Int_t content = GetBinContent(i);
217 Decode(content,adc,value);
218 cout << Form("i %4d content %10x adc %4d value %6d",i,content,adc,value)