Typedefs | Functions
testing::NuRandomService Namespace Reference

Typedefs

using seed_t = art::detail::EngineCreator::seed_t
 Type of seed. More...
 

Functions

bool isSeedServiceException (std::exception const &e)
 Returns whether the exception looks to be from NuRandomService. More...
 
bool isSeedServiceException (std::exception const &e, art::errors::ErrorCodes code)
 Returns whether the exception looks to be from NuRandomService and has specified code. More...
 
unsigned short RollStat (CLHEP::RandFlat &rand)
 Extracts "statistics" from a flat random number distribution. More...
 
std::string CreateCharacter (CLHEP::HepRandomEngine &engine)
 Creates a "character statistics" using the specified random engine. More...
 
seed_t readSeed (CLHEP::HepRandomEngine const &engine)
 Returns the seed of the specified engine (CLHEP overload) More...
 

Typedef Documentation

Type of seed.

Definition at line 32 of file SeedTestUtils.h.

Function Documentation

std::string testing::NuRandomService::CreateCharacter ( CLHEP::HepRandomEngine &  engine)

Creates a "character statistics" using the specified random engine.

Definition at line 79 of file SeedTestUtils.cxx.

79  {
80  CLHEP::RandFlat flat(engine);
81  constexpr size_t NStats = 6;
82  static const std::array<std::string, NStats> statNames
83  = {{ "STR", "DEX", "CON", "INT", "WIS", "CHA" }};
84  std::array<unsigned short int, NStats> stats;
85  std::generate(stats.begin(), stats.end(), [&flat]{ return RollStat(flat); });
86 
87  short int bonus = 0;
88  std::ostringstream sstr;
89  for (size_t iStat = 0; iStat < NStats; ++iStat) {
90  sstr << " " << statNames[iStat] << "=" << std::setw(2) << stats[iStat];
91  bonus += stats[iStat] / 2 - 5;
92  } // for
93  sstr << " [bonus: " << std::setw(3) << std::showpos << bonus << "]";
94  return sstr.str();
95  } // CreateCharacter()
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
unsigned short RollStat(CLHEP::RandFlat &rand)
Extracts "statistics" from a flat random number distribution.
bool testing::NuRandomService::isSeedServiceException ( std::exception const &  e)

Returns whether the exception looks to be from NuRandomService.

Definition at line 32 of file SeedTestUtils.cxx.

32  {
33 
34  // is it an art::Exception? (NuRandomService exceptions are)
35  art::Exception const* art_exc = dynamic_cast<art::Exception const*>(&e);
36  if (!art_exc) return false;
37 
38  // All configuration exceptions are from NuRandomService.
39  // Why? just because.
40  if (art_exc->categoryCode() == art::errors::Configuration)
41  return true;
42 
43  // does it have "NuRandomService" in the message? (NuRandomService exceptions should)
44  if ( (art_exc->explain_self().find("NuRandomService") == std::string::npos)
45  && (art_exc->explain_self().find("SeedMaster") == std::string::npos)
46  )
47  return false;
48 
49  // we can't do better than this
50  return true;
51  } // isSeedServiceException(exception)
const double e
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool testing::NuRandomService::isSeedServiceException ( std::exception const &  e,
art::errors::ErrorCodes  code 
)

Returns whether the exception looks to be from NuRandomService and has specified code.

Returns whether the exception looks to be from NuRandomService and has specified code

Definition at line 56 of file SeedTestUtils.cxx.

57  {
58  if (!isSeedServiceException(e)) return false;
59  // by now we know "e" is a art::Exception
60  return static_cast<art::Exception const&>(e).categoryCode() == code;
61  } // isSeedServiceException(exception, ErrorCodes)
const double e
CodeOutputInterface * code
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool isSeedServiceException(std::exception const &e, art::errors::ErrorCodes code)
Returns whether the exception looks to be from NuRandomService and has specified code.
seed_t testing::NuRandomService::readSeed ( CLHEP::HepRandomEngine const &  engine)

Returns the seed of the specified engine (CLHEP overload)

Returns the seed of the specified engine

Definition at line 99 of file SeedTestUtils.cxx.

100  { return engine.getSeed(); }
unsigned short testing::NuRandomService::RollStat ( CLHEP::RandFlat &  rand)

Extracts "statistics" from a flat random number distribution.

Definition at line 65 of file SeedTestUtils.cxx.

65  {
66  // std::array<unsigned short, 4> rolls;
67  unsigned int min = 6, total = 0;
68  for (int i = 0; i < 4; ++i) {
69  unsigned int roll = 1 + rand.fireInt(0, 6);
70  // rolls[i] = roll;
71  if (min > roll) min = roll;
72  total += roll;
73  }
74  total -= min;
75  return total;
76  } // RollStat()
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55