#ifndef ROOT_THnSparse
#define ROOT_THnSparse
#ifndef ROOT_THnBase
#include "THnBase.h"
#endif
#ifndef ROOT_TExMap
#include "TExMap.h"
#endif
#ifndef ROOT_THnSparse_Internal
#include "THnSparse_Internal.h"
#endif
#ifndef ROOT_TArrayF
#include "TArrayF.h"
#endif
#ifndef ROOT_TArrayL
#include "TArrayL.h"
#endif
#ifndef ROOT_TArrayI
#include "TArrayI.h"
#endif
#ifndef ROOT_TArrayS
#include "TArrayS.h"
#endif
#ifndef ROOT_TArrayC
#include "TArrayC.h"
#endif
class THnSparseCompactBinCoord;
class THnSparse: public THnBase {
private:
Int_t fChunkSize;
Long64_t fFilledBins;
TObjArray fBinContent;
TExMap fBins;
TExMap fBinsContinued;
THnSparseCompactBinCoord *fCompactCoord;
THnSparse(const THnSparse&);
THnSparse& operator=(const THnSparse&);
protected:
THnSparse();
THnSparse(const char* name, const char* title, Int_t dim,
const Int_t* nbins, const Double_t* xmin, const Double_t* xmax,
Int_t chunksize);
THnSparseCompactBinCoord* GetCompactCoord() const;
THnSparseArrayChunk* GetChunk(Int_t idx) const {
return (THnSparseArrayChunk*) fBinContent[idx]; }
THnSparseArrayChunk* AddChunk();
void Reserve(Long64_t nbins);
void FillExMap();
virtual TArray* GenerateArray() const = 0;
Long64_t GetBinIndexForCurrentBin(Bool_t allocate);
void FillBin(Long64_t bin, Double_t w) {
THnSparseArrayChunk* chunk = GetChunk(bin / fChunkSize);
chunk->AddBinContent(bin % fChunkSize, w);
FillBinBase(w);
}
void InitStorage(Int_t* nbins, Int_t chunkSize);
public:
virtual ~THnSparse();
static THnSparse* CreateSparse(const char* name, const char* title,
const TH1* h1, Int_t chunkSize = 1024 * 16) {
return (THnSparse*) CreateHnAny(name, title, h1, kTRUE ,
chunkSize);
}
static THnSparse* CreateSparse(const char* name, const char* title,
const THnBase* hn, Int_t chunkSize = 1024 * 16) {
return (THnSparse*) CreateHnAny(name, title, hn, kTRUE ,
chunkSize);
}
Int_t GetChunkSize() const { return fChunkSize; }
Int_t GetNChunks() const { return fBinContent.GetEntriesFast(); }
ROOT::THnBaseBinIter* CreateIter(Bool_t respectAxisRange) const;
Long64_t GetNbins() const { return fFilledBins; }
void SetFilledBins(Long64_t nbins) { fFilledBins = nbins; }
Long64_t GetBin(const Int_t* idx) const { return const_cast<THnSparse*>(this)->GetBin(idx, kFALSE); }
Long64_t GetBin(const Double_t* x) const { return const_cast<THnSparse*>(this)->GetBin(x, kFALSE); }
Long64_t GetBin(const char* name[]) const { return const_cast<THnSparse*>(this)->GetBin(name, kFALSE); }
Long64_t GetBin(const Int_t* idx, Bool_t allocate = kTRUE);
Long64_t GetBin(const Double_t* x, Bool_t allocate = kTRUE);
Long64_t GetBin(const char* name[], Bool_t allocate = kTRUE);
void SetBinContent(const Int_t* idx, Double_t v) {
THnBase::SetBinContent(idx, v);
}
void SetBinContent(Long64_t bin, Double_t v);
void SetBinError2(Long64_t bin, Double_t e2);
void AddBinContent(const Int_t* idx, Double_t v = 1.) {
THnBase::AddBinContent(idx, v);
}
void AddBinContent(Long64_t bin, Double_t v = 1.);
void AddBinError2(Long64_t bin, Double_t e2);
Double_t GetBinContent(const Int_t *idx) const {
return THnBase::GetBinContent(idx);
}
Double_t GetBinContent(Long64_t bin, Int_t* idx = 0) const;
Double_t GetBinError2(Long64_t linidx) const;
Double_t GetSparseFractionBins() const;
Double_t GetSparseFractionMem() const;
TH1D* Projection(Int_t xDim, Option_t* option = "") const{
return THnBase::Projection(xDim, option);
}
TH2D* Projection(Int_t yDim, Int_t xDim,
Option_t* option = "") const {
return THnBase::Projection(yDim, xDim, option);
}
TH3D* Projection(Int_t xDim, Int_t yDim, Int_t zDim,
Option_t* option = "") const {
return THnBase::Projection(xDim, yDim, zDim, option);
}
THnSparse* Projection(Int_t ndim, const Int_t* dim,
Option_t* option = "") const {
return (THnSparse*) ProjectionND(ndim, dim, option);
}
THnSparse* Rebin(Int_t group) const {
return (THnSparse*) RebinBase(group);
}
THnSparse* Rebin(const Int_t* group) const {
return (THnSparse*) RebinBase(group);
}
void Reset(Option_t* option = "");
void Sumw2();
ClassDef(THnSparse, 3);
};
template <class CONT>
class THnSparseT: public THnSparse {
public:
THnSparseT() {}
THnSparseT(const char* name, const char* title, Int_t dim,
const Int_t* nbins, const Double_t* xmin = 0,
const Double_t* xmax = 0, Int_t chunksize = 1024 * 16):
THnSparse(name, title, dim, nbins, xmin, xmax, chunksize) {}
TArray* GenerateArray() const { return new CONT(GetChunkSize()); }
private:
ClassDef(THnSparseT, 1);
};
typedef THnSparseT<TArrayD> THnSparseD;
typedef THnSparseT<TArrayF> THnSparseF;
typedef THnSparseT<TArrayL> THnSparseL;
typedef THnSparseT<TArrayI> THnSparseI;
typedef THnSparseT<TArrayS> THnSparseS;
typedef THnSparseT<TArrayC> THnSparseC;
#endif // ROOT_THnSparse