ATLAS Offline Software
FlexErrArrayGroup.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Header file for class FlexErrArrayGroup //
9 // //
10 // Description: Covering up to 128 bins, the class uses up //
11 // to 8 FlexBinChunk's and up to 8 double[16] //
12 // internally for bin contents and sumw. //
13 // Alternatively it uses just one long array //
14 // if the overhead from the subgroups becomes //
15 // too high (when almost all bins are fully //
16 // used). //
17 // //
18 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
19 // Initial version: March 2009 //
20 // //
22 
23 #ifndef FLEXERRARRAYGROUP_H
24 #define FLEXERRARRAYGROUP_H
25 
26 #define FLEXERRARRAYGROUP_NCHUNKS 8
27 #define FLEXERRARRAYGROUP_MAXBINS (FLEXBINCHUNK_NBINS*FLEXERRARRAYGROUP_NCHUNKS)
28 
29 #ifdef LW_STRICT_ROOT_BEHAVIOUR
30 #define STRICT_ROOT_PAR(x) , x
31 #else
32 #define STRICT_ROOT_PAR(x)
33 #endif
34 
35 #ifndef NDEBUG
36 template <class T> inline bool isNaN(const T&t) { return t!=t; }
37 template <class T> inline bool bothNaN(const T&t1, const T&t2) { return isNaN(t1)&&isNaN(t2); }
38 
39 #endif
40 
41 #include "FlexBinChunk.h"
42 #include "LWHistBitUtils.h"
43 #include <cmath>
44 #include <cstdlib>
45 #include <cassert>
46 
47 template <class T>
49 public:
50 
53 
54  void fill(unsigned bin STRICT_ROOT_PAR(bool pretendSumWMode));
55  void fill(unsigned bin, const double& weight STRICT_ROOT_PAR(bool pretendSumWMode));
56 
57  T getBinContent(unsigned bin) const;
58  double getBinError(unsigned bin) const;
59  void getBinContentAndError(unsigned bin, T& content, double& error ) const;
60 
61  // void setBinContent(unsigned bin, const T& val);
62  void setBinContent(unsigned bin, const T& val STRICT_ROOT_PAR(bool pretendSumWMode));
63  void setBinError(unsigned bin, const double& error);
64  void setBinContentAndError(unsigned bin, const T& content, const double& error);
65 
66  bool holdsSeparateSumW2Info() const { return m_sumw2allocated; }
67  void copyContents(T*cont, double*err=0) const;//Won't copy errors if err==0.
68 
69  unsigned getNBins() const { return m_nbins; }
70 
71  double Integral() const;
73  bool getNextActiveBin(unsigned& bin, T& content, double& error);
74 
75 private:
76 
79 
80  void** m_indices;//Pointer(s) to data. First pointer(s) to bin
81  //content (chunks or one T array), then follows
82  //pointer(s) to sumw2.
83  uint8_t m_nbins;//since we might have less than the full 8*16 bins... Actually only needed in copycontents (could be passed as arg)
84  uint8_t m_chunksallocated;//8 bits telling which chunks are allocated
85  uint8_t m_sumw2allocated;//8 bits telling which sumw2 are allocated
86  uint8_t m_fastloop_nextbin2check;//fixme: do it by chunk instead!
87 
88  //Fixme: We have 1 byte (2 if we get rid of m_nbins) available here due to alignment... use it for something? cache nindicesusedbychunks?
89  void addIndexPointer(unsigned position, void* newval);
90 
91  unsigned nIndicesUsedByChunks() const { return m_chunksallocated ? LWHistBitUtils::countSetBits<uint8_t>(m_chunksallocated) : 0; }//FIXME: CACHE
92  unsigned nIndicesUsedByErrors() const { return m_sumw2allocated ? LWHistBitUtils::countSetBits<uint8_t>(m_sumw2allocated) : 0; }
93 
94 
95  //The following bit-handling help could be outside the class to avoid template duplication:
97  return bin/FLEXBINCHUNK_NBINS; }
98  unsigned getChunkBin(unsigned bin) const { return bin%FLEXBINCHUNK_NBINS; }
99 
100  FlexBinChunk<T>* getChunk(unsigned igroup);
101  const FlexBinChunk<T>* getChunkNoAlloc(unsigned igroup) const;//returns 0 if no allocated
102  FlexBinChunk<T>* getChunkNoAlloc(unsigned igroup);//returns 0 if no allocated
103  double* getErrChunk(unsigned igroup);
104  const double* getErrChunkNoAlloc(unsigned igroup) const;//returns 0 if no allocated
105 };
106 
107 #include "FlexErrArrayGroup.icc"
108 
109 #endif
FlexErrArrayGroup
Definition: FlexErrArrayGroup.h:48
FlexErrArrayGroup::FlexErrArrayGroup
FlexErrArrayGroup(unsigned nbins=FLEXERRARRAYGROUP_MAXBINS)
FlexErrArrayGroup::holdsSeparateSumW2Info
bool holdsSeparateSumW2Info() const
Definition: FlexErrArrayGroup.h:66
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
FlexErrArrayGroup::nIndicesUsedByErrors
unsigned nIndicesUsedByErrors() const
Definition: FlexErrArrayGroup.h:92
FlexErrArrayGroup::getChunk
FlexBinChunk< T > * getChunk(unsigned igroup)
FlexErrArrayGroup::getChunkBin
unsigned getChunkBin(unsigned bin) const
Definition: FlexErrArrayGroup.h:98
FlexErrArrayGroup::getGroupIndex
unsigned getGroupIndex(unsigned bin) const
Definition: FlexErrArrayGroup.h:96
FlexErrArrayGroup::~FlexErrArrayGroup
~FlexErrArrayGroup()
FlexErrArrayGroup::getNextActiveBin
bool getNextActiveBin(unsigned &bin, T &content, double &error)
FlexErrArrayGroup::setBinContent
void setBinContent(unsigned bin, const T &val STRICT_ROOT_PAR(bool pretendSumWMode))
FlexErrArrayGroup::getErrChunkNoAlloc
const double * getErrChunkNoAlloc(unsigned igroup) const
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
LWHistBitUtils.h
FlexErrArrayGroup::getBinContentAndError
void getBinContentAndError(unsigned bin, T &content, double &error) const
bothNaN
bool bothNaN(const T &t1, const T &t2)
Definition: FlexErrArrayGroup.h:37
bin
Definition: BinsDiffFromStripMedian.h:43
STRICT_ROOT_PAR
#define STRICT_ROOT_PAR(x)
Definition: FlexErrArrayGroup.h:32
FlexErrArrayGroup::copyContents
void copyContents(T *cont, double *err=0) const
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
FLEXERRARRAYGROUP_NCHUNKS
#define FLEXERRARRAYGROUP_NCHUNKS
Definition: FlexErrArrayGroup.h:26
FlexErrArrayGroup::operator=
FlexErrArrayGroup & operator=(const FlexErrArrayGroup &)
FlexErrArrayGroup::getChunkNoAlloc
FlexBinChunk< T > * getChunkNoAlloc(unsigned igroup)
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
FlexErrArrayGroup::getChunkNoAlloc
const FlexBinChunk< T > * getChunkNoAlloc(unsigned igroup) const
grepfile.content
string content
Definition: grepfile.py:56
FlexErrArrayGroup.icc
FlexBinChunk
Definition: FlexBinChunk.h:30
FlexErrArrayGroup::nIndicesUsedByChunks
unsigned nIndicesUsedByChunks() const
Definition: FlexErrArrayGroup.h:91
FlexErrArrayGroup::setBinContentAndError
void setBinContentAndError(unsigned bin, const T &content, const double &error)
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
FlexErrArrayGroup::m_indices
void ** m_indices
Definition: FlexErrArrayGroup.h:80
FlexBinChunk.h
FlexErrArrayGroup::fill
void fill(unsigned bin STRICT_ROOT_PAR(bool pretendSumWMode))
FlexErrArrayGroup::getErrChunk
double * getErrChunk(unsigned igroup)
FlexErrArrayGroup::setBinError
void setBinError(unsigned bin, const double &error)
FlexErrArrayGroup::resetActiveBinLoop
void resetActiveBinLoop()
FlexErrArrayGroup::m_chunksallocated
uint8_t m_chunksallocated
Definition: FlexErrArrayGroup.h:84
FlexErrArrayGroup::fill
void fill(unsigned bin, const double &weight STRICT_ROOT_PAR(bool pretendSumWMode))
FlexErrArrayGroup::m_nbins
uint8_t m_nbins
Definition: FlexErrArrayGroup.h:83
FlexErrArrayGroup::addIndexPointer
void addIndexPointer(unsigned position, void *newval)
FlexErrArrayGroup::getNBins
unsigned getNBins() const
Definition: FlexErrArrayGroup.h:69
FlexErrArrayGroup::Integral
double Integral() const
isNaN
bool isNaN(const T &t)
Definition: FlexErrArrayGroup.h:36
FLEXERRARRAYGROUP_MAXBINS
#define FLEXERRARRAYGROUP_MAXBINS
Definition: FlexErrArrayGroup.h:27
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
FlexErrArrayGroup::m_sumw2allocated
uint8_t m_sumw2allocated
Definition: FlexErrArrayGroup.h:85
FlexErrArrayGroup::getBinError
double getBinError(unsigned bin) const
FlexErrArrayGroup::m_fastloop_nextbin2check
uint8_t m_fastloop_nextbin2check
Definition: FlexErrArrayGroup.h:86
FlexErrArrayGroup::getBinContent
T getBinContent(unsigned bin) const
error
Definition: IImpactPoint3dEstimator.h:70
FLEXBINCHUNK_NBINS
#define FLEXBINCHUNK_NBINS
Definition: FlexBinChunk.h:21
FlexErrArrayGroup::FlexErrArrayGroup
FlexErrArrayGroup(const FlexErrArrayGroup &)
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35