Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | Friends | List of all members
JSUPPORT::JRandomSampler< T > Struct Template Reference

Template class for randomly sampling from a JRewindableObjectIterator. More...

#include <JRandomSampler.hh>

Public Member Functions

 JRandomSampler ()
 Default constructor. More...
 
 JRandomSampler (const unsigned int on, const unsigned int off)
 Constructor. More...
 
const JRandomSampler & getRandomSampler () const
 Get random sampler. More...
 
JRandomSampler & getRandomSampler ()
 Get random sampler. More...
 
skip_type operator() (const T &object) const
 Acceptance test operator. More...
 

Protected Attributes

skip_type averageOn
 
skip_type averageOff
 
skip_type count
 

Friends

std::istream & operator>> (std::istream &in, JRandomSampler &sampler)
 Read random sampler from input. More...
 
std::ostream & operator<< (std::ostream &out, const JRandomSampler &sampler)
 Write random sampler to output. More...
 

Detailed Description

template<class T>
struct JSUPPORT::JRandomSampler< T >

Template class for randomly sampling from a JRewindableObjectIterator.

Definition at line 28 of file JRandomSampler.hh.

Constructor & Destructor Documentation

template<class T>
JSUPPORT::JRandomSampler< T >::JRandomSampler ( )
inline

Default constructor.

This constructor will sample all objects.

Definition at line 34 of file JRandomSampler.hh.

34  :
35  averageOn (1),
36  averageOff(0),
37  count (0)
38  {}
template<class T>
JSUPPORT::JRandomSampler< T >::JRandomSampler ( const unsigned int  on,
const unsigned int  off 
)
inline

Constructor.

Parameters
onaverage number of consecutively accepted events
offaverage number of consecutively rejected events

Definition at line 47 of file JRandomSampler.hh.

48  :
49  averageOn (on),
50  averageOff(off),
51  count (0)
52  {}

Member Function Documentation

template<class T>
const JRandomSampler& JSUPPORT::JRandomSampler< T >::getRandomSampler ( ) const
inline

Get random sampler.

Returns
random sampler

Definition at line 60 of file JRandomSampler.hh.

61  {
62  return static_cast<const JRandomSampler&>(*this);
63  }
Template class for randomly sampling from a JRewindableObjectIterator.
template<class T>
JRandomSampler& JSUPPORT::JRandomSampler< T >::getRandomSampler ( )
inline

Get random sampler.

Returns
random sampler

Definition at line 71 of file JRandomSampler.hh.

72  {
73  return static_cast<JRandomSampler&>(*this);
74  }
Template class for randomly sampling from a JRewindableObjectIterator.
template<class T>
skip_type JSUPPORT::JRandomSampler< T >::operator() ( const T &  object) const
inline

Acceptance test operator.

Parameters
objectobject
Returns
number of object to skip

Definition at line 83 of file JRandomSampler.hh.

84  {
85  if (count == 0) {
86 
87  count = gRandom->Integer(2 * averageOn);
88 
89  return (unsigned int) gRandom->Integer(2 * averageOff);
90 
91  } else {
92 
93  count -= 1;
94 
95  return 0;
96  }
97  }

Friends And Related Function Documentation

template<class T>
std::istream& operator>> ( std::istream &  in,
JRandomSampler< T > &  sampler 
)
friend

Read random sampler from input.

Parameters
ininput stream
samplerrandom sampler
Returns
input stream

Definition at line 107 of file JRandomSampler.hh.

108  {
109  in >> sampler.averageOn;
110  in >> sampler.averageOff;
111 
112  sampler.count = 0;
113 
114  return in;
115  }
template<class T>
std::ostream& operator<< ( std::ostream &  out,
const JRandomSampler< T > &  sampler 
)
friend

Write random sampler to output.

Parameters
outoutput stream
samplerrandom sampler
Returns
output stream

Definition at line 125 of file JRandomSampler.hh.

126  {
127  out << sampler.averageOn;
128  out << ' ';
129  out << sampler.averageOff;
130 
131  return out;
132  }

Member Data Documentation

template<class T>
skip_type JSUPPORT::JRandomSampler< T >::averageOn
protected

Definition at line 135 of file JRandomSampler.hh.

template<class T>
skip_type JSUPPORT::JRandomSampler< T >::averageOff
protected

Definition at line 136 of file JRandomSampler.hh.

template<class T>
skip_type JSUPPORT::JRandomSampler< T >::count
mutableprotected

Definition at line 137 of file JRandomSampler.hh.


The documentation for this struct was generated from the following file: