CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
RandBit.h
Go to the documentation of this file.
1// $Id: RandBit.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- RandBit ---
7// class header file
8// -----------------------------------------------------------------------
9//
10
11// Class defining methods for shooting Flat or Bit random numbers, double or
12// integers.
13// It provides methods to fill with double flat values arrays of
14// specified size, as well as methods for shooting sequences of 0,1 (bits).
15// Default boundaries ]0.1[ for operator()().
16
17// This is derived from RandFlat and is a drop-in replacement. However
18// the shootBit() and fireBit() methods are stateless (which makes them
19// an order of magnitude slower, but allows save/restore engine status
20// to work correctly).
21
22// =======================================================================
23// M. Fischler - Created: 15th Feb 2000
24// M Fischler - put and get to/from streams 12/10/04
25// M Fischler - static save/restore to streams streams 12/20/04
26// =======================================================================
27
28#ifndef RandBit_h
29#define RandBit_h 1
30
31#include "CLHEP/Random/defs.h"
32#include "CLHEP/Random/RandFlat.h"
33
34namespace CLHEP {
35
36/**
37 * @author
38 * @ingroup random
39 */
40class RandBit : public RandFlat {
41
42public:
43
44 inline RandBit ( HepRandomEngine& anEngine );
45 inline RandBit ( HepRandomEngine& anEngine, double width );
46 inline RandBit ( HepRandomEngine& anEngine, double a, double b );
47 inline RandBit ( HepRandomEngine* anEngine );
48 inline RandBit ( HepRandomEngine* anEngine, double width );
49 inline RandBit ( HepRandomEngine* anEngine, double a, double b );
50 // These constructors should be used to instantiate a RandBit
51 // distribution object defining a local engine for it.
52 // The static generator will be skipped using the non-static methods
53 // defined below.
54 // If the engine is passed by pointer the corresponding engine object
55 // will be deleted by the RandBit destructor.
56 // If the engine is passed by reference the corresponding engine object
57 // will not be deleted by the RandBit destructor.
58
59 virtual ~RandBit();
60 // Destructor
61
62 // Other than the Bit routines, constructors, and destructor, everything is
63 // simply inherited from RandFlat.
64
65 static inline int shootBit();
66
67 static inline int shootBit( HepRandomEngine* );
68
69 // Methods using the localEngine to shoot random values, by-passing
70 // the static generator.
71
72 inline int fireBit();
73
74 // Save and restore to/from streams
75
76 std::ostream & put ( std::ostream & os ) const;
77 std::istream & get ( std::istream & is );
78
79 std::string name() const;
80
81 static std::string distributionName() {return "RandBit";}
82 // Provides the name of this distribution class
83
84 static std::ostream& saveFullState ( std::ostream & os )
85 // Saves to stream the state of the engine and cached data.
86 {return RandFlat::saveFullState(os);}
87
88 static std::istream& restoreFullState ( std::istream & is )
89 // Restores from stream the state of the engine and cached data.
90 {return RandFlat::restoreFullState(is);}
91
92 static std::ostream& saveDistState ( std::ostream & os )
93 // Saves to stream the state of the cached data.
94 {return RandFlat::saveDistState(os);}
95
96 static std::istream& restoreDistState ( std::istream & is )
97 // Restores from stream the state of the cached data.
98 {return RandFlat::restoreDistState(is);}
99
100
101private:
102
103 // All the engine info, and the default A and B, are in the RandFlat
104 // base class.
105
106};
107
108} // namespace CLHEP
109
110#ifdef ENABLE_BACKWARDS_COMPATIBILITY
111// backwards compatibility will be enabled ONLY in CLHEP 1.9
112using namespace CLHEP;
113#endif
114
115#include "CLHEP/Random/RandBit.icc"
116
117#endif
RandBit(HepRandomEngine &anEngine, double width)
RandBit(HepRandomEngine &anEngine, double a, double b)
RandBit(HepRandomEngine *anEngine)
static std::ostream & saveFullState(std::ostream &os)
Definition: RandBit.h:84
std::string name() const
Definition: RandBit.cc:24
std::istream & get(std::istream &is)
Definition: RandBit.cc:35
static int shootBit(HepRandomEngine *)
std::ostream & put(std::ostream &os) const
Definition: RandBit.cc:29
static std::istream & restoreDistState(std::istream &is)
Definition: RandBit.h:96
RandBit(HepRandomEngine &anEngine)
static std::ostream & saveDistState(std::ostream &os)
Definition: RandBit.h:92
static std::string distributionName()
Definition: RandBit.h:81
RandBit(HepRandomEngine *anEngine, double width)
static int shootBit()
RandBit(HepRandomEngine *anEngine, double a, double b)
static std::istream & restoreFullState(std::istream &is)
Definition: RandBit.h:88
virtual ~RandBit()
Definition: RandBit.cc:26
static std::ostream & saveFullState(std::ostream &os)
Definition: RandFlat.cc:262
static std::ostream & saveDistState(std::ostream &os)
Definition: RandFlat.cc:228
static std::istream & restoreDistState(std::istream &is)
Definition: RandFlat.cc:237
static std::istream & restoreFullState(std::istream &is)
Definition: RandFlat.cc:268