27 THnSparseBinIter(
Bool_t respectAxisRange,
const THnSparse* hist):
28 ROOT::
Internal::THnBaseBinIter(respectAxisRange), fHist(hist),
29 fNbins(hist->GetNbins()), fIndex(-1) {
34 ~THnSparseBinIter()
override {
delete [] fCoord; }
40 THnSparseBinIter(
const THnSparseBinIter&) =
delete;
41 THnSparseBinIter&
operator=(
const THnSparseBinIter&) =
delete;
43 const THnSparse* fHist;
52 if (fCoord[0] == -1) {
63 if (!fHist)
return -1;
66 Int_t* useCoordBuf = fCoord;
78 if (RespectsAxisRange()) {
81 }
while (RespectsAxisRange()
83 && (fHaveSkippedBin =
kTRUE ));
85 if (coord && coord[0] == -1) {
86 if (fCoord[0] == -1) {
121 Int_t GetBufferSize()
const {
return fCoordBufferSize; }
123 void SetCoordFromBuffer(
const Char_t* buf_in,
Int_t* coord_out)
const;
155 for (
Int_t i = 0; i < dim; ++i) {
181 if (&other ==
this)
return *
this;
206 Int_t* coord_out)
const
213 coord_out[i] = *pbuf >> shift;
215 subst = subst << nbits;
216 nbits -= (8 - shift);
218 for (
Int_t n = 0;
n * 8 < nbits; ++
n) {
220 coord_out[i] += *pbuf << shift;
223 coord_out[i] &= ~subst;
241 memcpy(buf_out, &l64buf,
sizeof(
Long64_t));
252 Char_t* pbuf = buf_out + offset;
253 *pbuf += 0xff & (val << shift);
254 val = val >> (8 - shift);
269ULong64_t THnSparseCoordCompression::GetHashFromCoords(const Int_t* coord) const
271 // Bins are addressed in two different modes, depending
272 // on whether the compact bin index fits into a Long64_t or not.
273 // If it does, we can use it as a "perfect hash" for the TExMap.
274 // If not we build a hash from the compact bin index, and use that
275 // as the TExMap's hash.
277 if (fCoordBufferSize <= 8) {
278 // fits into a Long64_t
280 for (Int_t i = 0; i < fNdimensions; ++i) {
281 hash1 += coord[i] << fBitOffsets[i];
286 // else: doesn't fit into a Long64_t:
287 memset(coord, 0, fCoordBufferSize);
288 for (Int_t i = 0; i < fNdimensions; ++i) {
289 const Int_t offset = fBitOffsets[i] / 8;
290 const Int_t shift = fBitOffsets[i] % 8;
291 ULong64_t val = coord[i];
293 Char_t* pbuf = fCoordBuffer + offset;
294 *pbuf += 0xff & (val << shift);
295 val = val >> (8 - shift);
303 ULong64_t hash = 5381;
304 Char_t* str = fCoordBuffer;
305 while (str - fCoordBuffer < fCoordBufferSize) {
397 if (bufAllocSize <
sizeof(
Long64_t))
618 const std::vector<TAxis>& axes,
623 const size_t dim=axes.size();
624 auto nbins=
new Int_t[dim];
625 for (
size_t i=0; i<dim; i++)
638 const std::vector<std::vector<double>> &xbins,
Int_t chunksize)
660 delete copiedContent;
664 std::vector<Int_t> nbins(dim);
665 for (
Int_t i = 0; i < dim; i++)
724 const Char_t* endbuf = buf + singleCoordSize * chunkSize;
725 for (; buf < endbuf; buf += singleCoordSize, ++idx) {
737 fBins.Add(hash, idx + 1);
750 if (2 * nbins >
fBins.Capacity()) {
751 fBins.Expand(3 * nbins);
832 if (linidx < 0)
return 0.;
860 if (!nextlinidx)
break;
864 if (!allocate)
return -1;
883 fBins.Add(hash, newidx + 1);
923 Int_t arrayElementSize = 0;
929 if (!arrayElementSize) {
930 Warning(
"GetSparseFractionMem",
"Cannot determine type of elements!");
936 sizePerChunkElement +=
sizeof(
Double_t);
946 return size / nbinsTotal / arrayElementSize;
955 return new THnSparseBinIter(respectAxisRange,
this);
977 Error(
"SetBinError",
"GetCalculateErrors() logic error!");
994 Error(
"SetBinError",
"GetCalculateErrors() logic error!");
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
char Char_t
Character 1 byte (char).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
long long Long64_t
Portable signed long integer 8 bytes.
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
const char Option_t
Option string (const char).
Binding & operator=(OUT(*fun)(void))
Iterator over THnBase bins (internal implementation).
Array of doubles (64 bits per element).
Double_t GetAt(Int_t i) const override
void SetAt(Double_t v, Int_t i) override
Abstract array base class.
virtual void SetAt(Double_t v, Int_t i)=0
virtual TClass * IsA() const
virtual Double_t GetAt(Int_t i) const =0
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
TClass instances represent classes, structs and namespaces in the ROOT type system.
TDataMember * GetDataMember(const char *datamember) const
Return pointer to datamember object with name "datamember".
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TObject * Clone(const char *newname="") const override
Make a clone of an collection using the Streamer facility.
All ROOT classes may have RTTI (run time type identification) support added.
TDataType * GetDataType() const
Int_t Size() const
Get size of basic typedef'ed type.
Double_t fEntries
Number of entries, spread over chunks.
Bool_t IsInRange(Int_t *coord) const
Check whether bin coord is in range, as defined by TAxis::SetRange().
Int_t GetNdimensions() const
void ResetBase(Option_t *option="")
Clear the histogram.
Bool_t GetCalculateErrors() const
Double_t fTsumw2
Total sum of weights squared; -1 if no errors are calculated.
TAxis * GetAxis(Int_t dim) const
THnSparseArrayChunk is used internally by THnSparse.
Bool_t Matches(Int_t idx, const Char_t *idxbuf) const
Check whether bin at idx batches idxbuf.
~THnSparseArrayChunk() override
Destructor.
TArrayD * fSumw2
Bin errors.
Int_t fCoordinatesSize
Size of the bin coordinate buffer.
Int_t fSingleCoordinateSize
Size of a single bin coordinate.
void Sumw2()
Turn on support of errors.
Char_t * fCoordinates
[fCoordinatesSize] compact bin coordinate buffer
TArray * fContent
Bin content.
void AddBin(Int_t idx, const Char_t *idxbuf)
Create a new bin in this chunk.
Int_t fCoordinateAllocationSize
! Size of the allocated coordinate buffer; -1 means none or fCoordinatesSize
THnSparseCompactBinCoord is a class used by THnSparse internally.
THnSparseCompactBinCoord(Int_t dim, const Int_t *nbins)
Initialize a THnSparseCompactBinCoord object with "dim" dimensions and "bins" holding the number of b...
ULong64_t GetHash() const
const Char_t * GetBuffer() const
~THnSparseCompactBinCoord()
destruct a THnSparseCompactBinCoord
THnSparseCompactBinCoord(const THnSparseCompactBinCoord &)=delete
void SetBuffer(const Char_t *buf)
void SetCoord(const Int_t *coord)
THnSparseCompactBinCoord & operator=(const THnSparseCompactBinCoord &)=delete
THnSparseCoordCompression is a class used by THnSparse internally.
Int_t GetNdimensions() const
Int_t GetNumBits(Int_t n) const
void SetCoordFromBuffer(const Char_t *buf_in, Int_t *coord_out) const
Given the compressed coordinate buffer buf_in, calculate ("decompact") the bin coordinates and return...
ULong64_t SetBufferFromCoord(const Int_t *coord_in, Char_t *buf_out) const
Given the cbin coordinates coord_in, calculate ("compact") the bin coordinates and return them in buf...
Int_t GetBufferSize() const
THnSparseCoordCompression & operator=(const THnSparseCoordCompression &other)
Set this to other if different.
ULong64_t GetHashFromBuffer(const Char_t *buf) const
Calculate hash from compact bin index.
THnSparseCoordCompression(Int_t dim, const Int_t *nbins)
Initialize a THnSparseCoordCompression object with "dim" dimensions and "bins" holding the number of ...
~THnSparseCoordCompression()
destruct a THnSparseCoordCompression
Double_t GetSparseFractionBins() const
Return the amount of filled bins over all bins.
Double_t GetSparseFractionMem() const
Return the amount of used memory over memory that would be used by a non-sparse n-dimensional histogr...
Double_t GetBinContent(Long64_t bin, Int_t *idx=nullptr) const override
Return the content of the filled bin number "idx".
void Reset(Option_t *option="") override
Clear the histogram.
void AddBinError2(Long64_t bin, Double_t e2) override
Add "e" to error of bin with index "bin", enable errors if needed.
THnSparseArrayChunk * GetChunk(Int_t idx) const
THnSparseCompactBinCoord * fCompactCoord
! Compact coordinate
Int_t GetChunkSize() const
void SetBinContent(Long64_t bin, Double_t v) override
Set content of bin with index "bin" to "v".
Long64_t fFilledBins
Number of filled bins.
Long64_t GetBin(const Int_t *idx) const override
void AddBinContent(Long64_t bin, Double_t v=1.) override
Add "v" to the content of bin with index "bin".
TObjArray fBinContent
Array of THnSparseArrayChunk.
THnSparseCompactBinCoord * GetCompactCoord() const
Return THnSparseCompactBinCoord object.
void InitStorage(Int_t *nbins, Int_t chunkSize) override
Initialize the storage of a histogram created via Init().
Double_t GetBinError2(Long64_t linidx) const override
Get square of the error of bin addressed by linidx as If errors are not enabled (via Sumw2() or Calc...
THnSparse()
Construct an empty THnSparse.
THnSparseArrayChunk * AddChunk()
Create a new chunk of bin content.
virtual TArray * GenerateArray() const =0
void SetBinError2(Long64_t bin, Double_t e2) override
Set error of bin with index "bin" to "e", enable errors if needed.
void FillExMap()
We have been streamed; set up fBins.
~THnSparse() override
Destruct a THnSparse.
TExMap fBins
! Filled bins
TExMap fBinsContinued
! Filled bins for non-unique hashes, containing pairs of (bin index 0, bin index 1)
void Reserve(Long64_t nbins) override
Initialize storage for nbins.
Int_t fChunkSize
Number of entries for each chunk.
void Sumw2() override
Enable calculation of errors.
Long64_t GetNbins() const override
ROOT::Internal::THnBaseBinIter * CreateIter(Bool_t respectAxisRange) const override
Create an iterator over all filled bins of a THnSparse.
Long64_t GetBinIndexForCurrentBin(Bool_t allocate)
Return the index for fCurrentBinIndex.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.