CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
edm::RunningAverage Class Reference

#include <RunningAverage.h>

Public Member Functions

int mean () const
 
 RunningAverage (unsigned int k=4)
 
void update (unsigned int q)
 
int upper () const
 

Static Public Attributes

static constexpr int N = 16
 

Private Member Functions

friend int::test::running_average::test ()
 

Private Attributes

std::array< std::atomic< int >, Nm_buffer
 
std::atomic< int > m_curr
 
std::atomic< int > m_mean
 

Detailed Description

Definition at line 17 of file RunningAverage.h.

Constructor & Destructor Documentation

edm::RunningAverage::RunningAverage ( unsigned int  k = 4)
inlineexplicit

Definition at line 23 of file RunningAverage.h.

References i, relval_2017::k, and m_buffer.

23  : m_mean(N*k), m_curr(0) {
24  for (auto & i : m_buffer) i=k;
25  }
int i
Definition: DBlmapReader.cc:9
std::array< std::atomic< int >, N > m_buffer
static constexpr int N
std::atomic< int > m_mean
std::atomic< int > m_curr

Member Function Documentation

edm::RunningAverage::int::test::running_average::test ( )
private
int edm::RunningAverage::mean ( ) const
inline

Definition at line 27 of file RunningAverage.h.

References m_mean, and N.

Referenced by upper().

27 { return m_mean/N;}
static constexpr int N
std::atomic< int > m_mean
void edm::RunningAverage::update ( unsigned int  q)
inline

Definition at line 31 of file RunningAverage.h.

References alignCSCRings::e, relval_2017::k, m_buffer, m_curr, m_mean, and N.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), HitPairGenerator::clear(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), HitTripletGenerator::run(), MultiHitGenerator::run(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

31  {
32  int e=m_curr;
33  while(!m_curr.compare_exchange_weak(e,e+1));
34  int k = (N-1)&e;
35  int old = m_buffer[k];
36  if (!m_buffer[k].compare_exchange_strong(old,q)) return;
37  m_mean+= (q-old);
38  }
std::array< std::atomic< int >, N > m_buffer
static constexpr int N
std::atomic< int > m_mean
std::atomic< int > m_curr
int edm::RunningAverage::upper ( ) const
inline

Definition at line 29 of file RunningAverage.h.

References funct::abs(), m_buffer, mean(), and N.

Referenced by HitTripletGenerator::run(), HitPairGenerator::run(), and MultiHitGenerator::run().

29 { auto lm = mean(); return lm+=(std::abs(m_buffer[0]-lm)+std::abs(m_buffer[N/2]-lm)); } // about 2 sigma
std::array< std::atomic< int >, N > m_buffer
static constexpr int N
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

Member Data Documentation

std::array<std::atomic<int>,N> edm::RunningAverage::m_buffer
private

Definition at line 42 of file RunningAverage.h.

Referenced by RunningAverage(), update(), and upper().

std::atomic<int> edm::RunningAverage::m_curr
private

Definition at line 44 of file RunningAverage.h.

Referenced by update().

std::atomic<int> edm::RunningAverage::m_mean
private

Definition at line 43 of file RunningAverage.h.

Referenced by mean(), and update().

constexpr int edm::RunningAverage::N = 16
static

Definition at line 22 of file RunningAverage.h.

Referenced by mean(), update(), and upper().