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 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 Attributes

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

Detailed Description

Definition at line 10 of file RunningAverage.h.

Constructor & Destructor Documentation

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

Definition at line 13 of file RunningAverage.h.

References i, roll_playback::k, and m_buffer.

13  : m_mean(N*k), m_curr(0) {
14  for (auto & i : m_buffer) i=k;
15  }
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

int edm::RunningAverage::mean ( ) const
inline

Definition at line 17 of file RunningAverage.h.

References m_mean, and N.

Referenced by upper().

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

Definition at line 21 of file RunningAverage.h.

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

Referenced by progressbar.ProgressBar::__next__(), relval_steps.Matrix::__setitem__(), relval_steps.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(), relval_steps.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().

21  {
22  int e=m_curr;
23  while(!m_curr.compare_exchange_weak(e,e+1));
24  int k = (N-1)&e;
25  int old = m_buffer[k];
26  if (!m_buffer[k].compare_exchange_strong(old,q)) return;
27  m_mean+= (q-old);
28  }
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 19 of file RunningAverage.h.

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

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

19 { 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 32 of file RunningAverage.h.

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

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

Definition at line 34 of file RunningAverage.h.

Referenced by update().

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

Definition at line 33 of file RunningAverage.h.

Referenced by mean(), and update().

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

Definition at line 12 of file RunningAverage.h.

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