Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JSUPPORT::JRandomSampler< T > Struct Template Reference

Template class for randomly sampling from a JLANG::JRewindableObjectIterator using a JLANG::JObjectSampler. More...

#include <JRandomSampler.hh>

Public Member Functions

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

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.
 
std::ostream & operator<< (std::ostream &out, const JRandomSampler &sampler)
 Write random sampler to output.
 

Detailed Description

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

Template class for randomly sampling from a JLANG::JRewindableObjectIterator using a JLANG::JObjectSampler.

The JRandomSampler class provides for an implementation of randomly sampling objects.
The sampling is controlled via two parameters, namely:

Definition at line 33 of file JRandomSampler.hh.

Constructor & Destructor Documentation

◆ JRandomSampler() [1/2]

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

Default constructor.

This constructor will sample all objects.

Definition at line 39 of file JRandomSampler.hh.

39 :
40 averageOn (1),
41 averageOff(0),
42 count (0)
43 {}

◆ JRandomSampler() [2/2]

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 52 of file JRandomSampler.hh.

53 :
54 averageOn (on),
55 averageOff(off),
56 count (0)
57 {}

Member Function Documentation

◆ getRandomSampler() [1/2]

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

Get random sampler.

Returns
random sampler

Definition at line 65 of file JRandomSampler.hh.

66 {
67 return static_cast<const JRandomSampler&>(*this);
68 }
JRandomSampler()
Default constructor.

◆ getRandomSampler() [2/2]

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

Get random sampler.

Returns
random sampler

Definition at line 76 of file JRandomSampler.hh.

77 {
78 return static_cast<JRandomSampler&>(*this);
79 }

◆ operator()()

template<class T >
skip_type JSUPPORT::JRandomSampler< T >::operator() ( const T & object) const
inline

Acceptance test operator.

Return value 0 means accept and >0 number of objects to skip.

Parameters
objectobject
Returns
number of objects to skip

Definition at line 89 of file JRandomSampler.hh.

90 {
91 if (count == 0) {
92
93 count = gRandom->Integer(2 * averageOn);
94
95 return (skip_type) gRandom->Integer(2 * averageOff);
96
97 } else {
98
99 count -= 1;
100
101 return 0;
102 }
103 }
unsigned int skip_type
Type definition for number of objects to skip.

Friends And Related Symbol Documentation

◆ operator>>

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 113 of file JRandomSampler.hh.

114 {
115 in >> sampler.averageOn;
116 in >> sampler.averageOff;
117
118 sampler.count = 0;
119
120 return in;
121 }

◆ operator<<

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 131 of file JRandomSampler.hh.

132 {
133 out << sampler.averageOn;
134 out << ' ';
135 out << sampler.averageOff;
136
137 return out;
138 }

Member Data Documentation

◆ averageOn

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

Definition at line 141 of file JRandomSampler.hh.

◆ averageOff

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

Definition at line 142 of file JRandomSampler.hh.

◆ count

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

Definition at line 143 of file JRandomSampler.hh.


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