Jpp  17.1.1
the software that should make you happy
 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 JLANG::JRewindableObjectIterator using a JLANG::JObjectSampler. More...

#include <JRandomSampler.hh>

Public Member Functions

 JRandomSampler ()
 Default constructor. More...
 
 JRandomSampler (const unsigned int on, const unsigned int off)
 Constructor. More...
 
const JRandomSamplergetRandomSampler () const
 Get random sampler. More...
 
JRandomSamplergetRandomSampler ()
 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 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 31 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 37 of file JRandomSampler.hh.

37  :
38  averageOn (1),
39  averageOff(0),
40  count (0)
41  {}
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 50 of file JRandomSampler.hh.

51  :
52  averageOn (on),
53  averageOff(off),
54  count (0)
55  {}

Member Function Documentation

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

Get random sampler.

Returns
random sampler

Definition at line 63 of file JRandomSampler.hh.

64  {
65  return static_cast<const JRandomSampler&>(*this);
66  }
Template class for randomly sampling from a JLANG::JRewindableObjectIterator using a JLANG::JObjectSa...
template<class T>
JRandomSampler& JSUPPORT::JRandomSampler< T >::getRandomSampler ( )
inline

Get random sampler.

Returns
random sampler

Definition at line 74 of file JRandomSampler.hh.

75  {
76  return static_cast<JRandomSampler&>(*this);
77  }
Template class for randomly sampling from a JLANG::JRewindableObjectIterator using a JLANG::JObjectSa...
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 87 of file JRandomSampler.hh.

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

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

112  {
113  in >> sampler.averageOn;
114  in >> sampler.averageOff;
115 
116  sampler.count = 0;
117 
118  return in;
119  }
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
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 129 of file JRandomSampler.hh.

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

Member Data Documentation

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

Definition at line 139 of file JRandomSampler.hh.

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

Definition at line 140 of file JRandomSampler.hh.

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

Definition at line 141 of file JRandomSampler.hh.


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