ATLAS Offline Software
FlexErrArray.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Header file for class FlexErrArray //
9 // //
10 // Description: Array of bins and possible associated errors //
11 // used internally in THXY_LW classes. //
12 // //
13 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
14 // Initial version: March 2009 //
15 // //
17 
18 #ifndef FLEXERRARRAY_H
19 #define FLEXERRARRAY_H
20 
21 //A few global typedefs:
22 
23 #include "LWHistGlobalSettings.h"
24 #include "FlexErrArrayGroup.h"
25 
26 #include <cmath>
27 #include <cassert>
28 
29 #define FLEX1DERRARRAY_NGROUPSPERINDEX 8
30 
31 //T should be a builtin numeric type with sizeof(T) > sizeof(short)
32 
33 template <class T>
34 class FlexErrArray {
35 public:
36 
37  //extraAllocSize indicates the size of the memory immediately following the object which will be used for supergroups indices.
38  static unsigned extraAllocSize(unsigned nbins) { return (small(nbins) ? nGroupsNeeded(nbins) : nSuperGroups(nbins))*sizeof(void*); }
40  bool small() const { return small(m_nbins); }
41 
42  FlexErrArray( unsigned nbins );
44 
45  unsigned getNBins() const;
46 
47  void fill(unsigned bin);
48  void fill(unsigned bin, const double& weight);
49  T getBinContent(unsigned bin) const;
50  double getBinError(unsigned bin) const;
51  void getBinContentAndError(unsigned bin, T& content, double& error ) const;
52 
53  void setBinContent(unsigned bin, const T& content);
54  void setBinError(unsigned bin, const double& error );
55  void setBinContentAndError(unsigned bin, const T& content, const double& error );
56 
57  bool holdsSeparateSumW2Info() const;
58  void copyContents(T*cont, double*err=0) const;//Won't copy errors if err==0.
59 
60  double Integral() const;
61 
62  //For fast looping through bins, automatically skipping bins where
63  //both content and error are 0:
65  bool getNextActiveBin(unsigned& bin, T& content, double& error);
66 
67  void scaleContentsAndErrors( const double& fact );
68 
69 #ifdef LW_STRICT_ROOT_BEHAVIOUR
70  void forcePretendSumWMode() { m_pretendSumWMode = true; }
71  bool pretendSumWMode() const { return m_pretendSumWMode; }
72 #endif
73 
74 private:
75 
78 
79  //If we are "small()" (i.e. <=1024 bins), we just keep an array of
80  //the group pointers. If larger than that, we keep arrays of arrays
81  //of groups (super-groups).
82 
83  //Data members:
84  const FlexErrArrayGroup<T> * const* const* superGroups() const
85  {
86  assert(!small());
87  return reinterpret_cast<const FlexErrArrayGroup<T> * const* const*>(m_indices);
88  }
90  {
91  assert(!small());
92  return reinterpret_cast<FlexErrArrayGroup<T> ***>(m_indices);
93  }
94  const FlexErrArrayGroup<T> *const* groups() const
95  {
96  assert(small());
97  return reinterpret_cast<const FlexErrArrayGroup<T> * const*>(m_indices);
98  }
100  {
101  assert(small());
102  return reinterpret_cast<FlexErrArrayGroup<T> **>(m_indices);
103  }
104 
105  void* m_indices;
107  const unsigned m_nbins;
110 #ifdef LW_STRICT_ROOT_BEHAVIOUR
111  bool m_pretendSumWMode;
112 #endif
113 
115 
118  // unsigned superGroupBin(unsigned bin) const { assert(bin<m_nbins); return bin%(FLEXERRARRAYGROUP_MAXBINS*FLEX1DERRARRAY_NGROUPSPERINDEX); }
119  unsigned groupBin(unsigned bin) const { assert(bin<m_nbins); return bin%FLEXERRARRAYGROUP_MAXBINS; }
120  unsigned iGroup(unsigned bin) const { assert(bin<m_nbins); return bin/FLEXERRARRAYGROUP_MAXBINS; }
121  //This example should show how to use m_supergroups to use the individual groups:
122  // m_supergroups[iSuperGroup(bin)][superGroupBin(bin)]->fill(groupBin(bin))
123 
124  const FlexErrArrayGroup<T> * getGroupNoAlloc(unsigned bin) const
125  {
126  assert(bin<m_nbins);
127  if (small()) {
128  assert(iGroup(bin)<nGroupsNeeded(m_nbins));
129  return groups()[iGroup(bin)];
130  } else {
132  const FlexErrArrayGroup<T> * const* supergroup = superGroups()[iSuperGroup(bin)];
133  return supergroup ? supergroup[superGroupBin(bin)] : 0;
134  }
135  }
137  {
138  assert(bin<m_nbins);
139  if (small()) {
140  assert(iGroup(bin)<nGroupsNeeded(m_nbins));
141  return groups()[iGroup(bin)];
142  } else {
144  FlexErrArrayGroup<T> ** supergroup = superGroups()[iSuperGroup(bin)];
145  return supergroup ? supergroup[superGroupBin(bin)] : 0;
146  }
147  }
149 
152  //NB: The last index array is allocated/released shorter than FLEX1DERRARRAY_NGROUPSPERINDEX
153 
154  unsigned entriesInSuperGroup(unsigned iSuperGroup) const {
155  unsigned l(nSuperGroups(m_nbins));
156  if (iSuperGroup+1<l) {
158  } else {
159  //Fixme: nGroupsNeeded calculated twice!
162  }
163  }
164 };
165 
166 #include "FlexErrArray.icc"
167 
168 #endif
FlexErrArray::groups
const FlexErrArrayGroup< T > *const * groups() const
Definition: FlexErrArray.h:94
FlexErrArray::iGroup
unsigned iGroup(unsigned bin) const
Definition: FlexErrArray.h:120
FlexErrArrayGroup
Definition: FlexErrArrayGroup.h:48
FlexErrArrayGroup.h
FlexErrArray::entriesInSuperGroup
unsigned entriesInSuperGroup(unsigned iSuperGroup) const
Definition: FlexErrArray.h:154
FlexErrArray::m_fastloop_igr2check
unsigned m_fastloop_igr2check
Definition: FlexErrArray.h:109
FlexErrArray::m_fastloop_isuper2check
unsigned m_fastloop_isuper2check
Definition: FlexErrArray.h:108
FlexErrArray::getGroupNoAlloc
FlexErrArrayGroup< T > * getGroupNoAlloc(unsigned bin)
Definition: FlexErrArray.h:136
FlexErrArray::getNextActiveBin
bool getNextActiveBin(unsigned &bin, T &content, double &error)
FlexErrArray::scaleContentsAndErrors
void scaleContentsAndErrors(const double &fact)
FlexErrArray::nGroupsNeeded
static unsigned nGroupsNeeded(unsigned nbins)
Definition: FlexErrArray.h:150
FlexErrArray::iSuperGroup
unsigned iSuperGroup(unsigned bin) const
Definition: FlexErrArray.h:116
bin
Definition: BinsDiffFromStripMedian.h:43
FlexErrArray::FlexErrArray
FlexErrArray(unsigned nbins)
FLEX1DERRARRAY_NGROUPSPERINDEX
#define FLEX1DERRARRAY_NGROUPSPERINDEX
Definition: FlexErrArray.h:29
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
FlexErrArray::~FlexErrArray
~FlexErrArray()
FlexErrArray::operator=
FlexErrArray & operator=(const FlexErrArray &)
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
LWHistGlobalSettings.h
FlexErrArray::Integral
double Integral() const
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
FlexErrArray::copyContents
void copyContents(T *cont, double *err=0) const
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
grepfile.content
string content
Definition: grepfile.py:56
FlexErrArray::groups
FlexErrArrayGroup< T > ** groups()
Definition: FlexErrArray.h:99
FlexErrArray::fill
void fill(unsigned bin, const double &weight)
FlexErrArray::extraAllocSize
static unsigned extraAllocSize(unsigned nbins)
Definition: FlexErrArray.h:38
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
beamspotman.n
n
Definition: beamspotman.py:731
FlexErrArray::superGroups
FlexErrArrayGroup< T > *** superGroups()
Definition: FlexErrArray.h:89
FlexErrArray::nSuperGroups
static unsigned nSuperGroups(unsigned nbins)
Definition: FlexErrArray.h:151
FlexErrArray::fastLoop_findAndResetNextGroup
void fastLoop_findAndResetNextGroup()
FlexErrArray::getGroupNoAlloc
const FlexErrArrayGroup< T > * getGroupNoAlloc(unsigned bin) const
Definition: FlexErrArray.h:124
FlexErrArray::superGroups
const FlexErrArrayGroup< T > *const *const * superGroups() const
Definition: FlexErrArray.h:84
FLEXERRARRAYGROUP_MAXBINS
#define FLEXERRARRAYGROUP_MAXBINS
Definition: FlexErrArrayGroup.h:27
FlexErrArray::small
bool small() const
Definition: FlexErrArray.h:40
FlexErrArray::m_fastloop_group2check
FlexErrArrayGroup< T > * m_fastloop_group2check
Definition: FlexErrArray.h:106
FlexErrArray::m_nbins
const unsigned m_nbins
Definition: FlexErrArray.h:107
FlexErrArray::fill
void fill(unsigned bin)
FlexErrArray::getNBins
unsigned getNBins() const
FlexErrArray::resetActiveBinLoop
void resetActiveBinLoop()
FlexErrArray::setBinContentAndError
void setBinContentAndError(unsigned bin, const T &content, const double &error)
FlexErrArray::superGroupBin
unsigned superGroupBin(unsigned bin) const
Definition: FlexErrArray.h:117
FlexErrArray::holdsSeparateSumW2Info
bool holdsSeparateSumW2Info() const
FlexErrArray::groupBin
unsigned groupBin(unsigned bin) const
Definition: FlexErrArray.h:119
FlexErrArray::getBinContent
T getBinContent(unsigned bin) const
FlexErrArray::setBinError
void setBinError(unsigned bin, const double &error)
FlexErrArray::getBinError
double getBinError(unsigned bin) const
FlexErrArray.icc
FlexErrArray::m_indices
void * m_indices
Definition: FlexErrArray.h:105
FlexErrArray
Definition: FlexErrArray.h:34
FlexErrArray::getBinContentAndError
void getBinContentAndError(unsigned bin, T &content, double &error) const
error
Definition: IImpactPoint3dEstimator.h:70
FlexErrArray::setBinContent
void setBinContent(unsigned bin, const T &content)
FlexErrArray::FlexErrArray
FlexErrArray(const FlexErrArray &)
FlexErrArray::small
static bool small(unsigned nbins)
Definition: FlexErrArray.h:39
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
FlexErrArray::getGroup
FlexErrArrayGroup< T > * getGroup(unsigned bin)