LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
rndm::details::RangeCheckHelper< SEED > Class Template Reference

Helper class to support range checking. More...

#include "BasePolicies.h"

Public Types

using seed_t = SEED
 
using seed_t = SEED
 

Public Member Functions

 RangeCheckHelper (std::string maxSeedsLabel="maxUniqueEngines", std::string baseSeedLabel="baseSeed", std::string checkRangeLabel="checkRange")
 Constructor; specify configuration labels. More...
 
void SetConfigLabels (std::string maxSeedsLabel="maxUniqueEngines", std::string baseSeedLabel="baseSeed", std::string checkRangeLabel="checkRange")
 
bool configure (fhicl::ParameterSet const &pset)
 
void SetCheck (bool doCheck=true)
 Sets whether to perform the check or not. More...
 
void SetBaseSeed (seed_t base_seed)
 Sets the base seed directly. More...
 
void SetNSeeds (seed_t nSeeds)
 Sets the number of seeds directly. More...
 
bool operator() (seed_t seed) const
 Performs the check on the specified seed. More...
 
void EnsureRange (std::string policy, SeedMasterHelper::EngineId const &id, seed_t seed) const
 Throws an exception if the range check on seed fails. More...
 
bool isConfigured () const
 Returns whether all the parameters are configured. More...
 
std::vector< std::string > missingConfig () const
 Returns the items currently not configured. More...
 
template<typename STREAM >
void print (STREAM &out, std::string indent=std::string()) const
 Prints the configuration int the specified stream. More...
 
 RangeCheckHelper (std::string maxSeedsLabel="maxUniqueEngines", std::string baseSeedLabel="baseSeed", std::string checkRangeLabel="checkRange")
 Constructor; specify configuration labels. More...
 
void SetConfigLabels (std::string maxSeedsLabel="maxUniqueEngines", std::string baseSeedLabel="baseSeed", std::string checkRangeLabel="checkRange")
 
bool configure (fhicl::ParameterSet const &pset)
 
void SetCheck (bool doCheck=true)
 Sets whether to perform the check or not. More...
 
void SetBaseSeed (seed_t base_seed)
 Sets the base seed directly. More...
 
void SetNSeeds (seed_t nSeeds)
 Sets the number of seeds directly. More...
 
bool operator() (seed_t seed) const
 Performs the check on the specified seed. More...
 
void EnsureRange (std::string policy, SeedMasterHelper::EngineId const &id, seed_t seed) const
 Throws an exception if the range check on seed fails. More...
 
bool isConfigured () const
 Returns whether all the parameters are configured. More...
 
std::vector< std::string > missingConfig () const
 Returns the items currently not configured. More...
 
template<typename STREAM >
void print (STREAM &out, std::string indent=std::string()) const
 Prints the configuration int the specified stream. More...
 

Protected Types

enum  Params_t {
  pmMaxSeeds, pmBaseSeed, pmDoCheck, pmNParams,
  pmMaxSeeds, pmBaseSeed, pmDoCheck, pmNParams
}
 
enum  Params_t {
  pmMaxSeeds, pmBaseSeed, pmDoCheck, pmNParams,
  pmMaxSeeds, pmBaseSeed, pmDoCheck, pmNParams
}
 

Protected Attributes

std::array< std::string, NParamsparamLabels
 
std::bitset< NParamshasParameters
 
bool bCheck = true
 should we perform the check? More...
 
seed_t BaseSeed
 minimum valid seed More...
 
seed_t MaxSeeds
 number of valid seeds More...
 

Static Protected Attributes

static constexpr unsigned int NParams = (unsigned int) pmNParams
 

Detailed Description

template<typename SEED>
class rndm::details::RangeCheckHelper< SEED >

Helper class to support range checking.

Definition at line 99 of file BasePolicies.h.

Member Typedef Documentation

template<typename SEED>
using rndm::details::RangeCheckHelper< SEED >::seed_t = SEED

Definition at line 101 of file BasePolicies.h.

template<typename SEED>
using rndm::details::RangeCheckHelper< SEED >::seed_t = SEED

Definition at line 146 of file RandomSeedPolicyBase.h.

Member Enumeration Documentation

template<typename SEED>
enum rndm::details::RangeCheckHelper::Params_t
protected
Enumerator
pmMaxSeeds 
pmBaseSeed 
pmDoCheck 
pmNParams 
pmMaxSeeds 
pmBaseSeed 
pmDoCheck 
pmNParams 

Definition at line 158 of file BasePolicies.h.

template<typename SEED>
enum rndm::details::RangeCheckHelper::Params_t
protected
Enumerator
pmMaxSeeds 
pmBaseSeed 
pmDoCheck 
pmNParams 
pmMaxSeeds 
pmBaseSeed 
pmDoCheck 
pmNParams 

Definition at line 203 of file RandomSeedPolicyBase.h.

Constructor & Destructor Documentation

template<typename SEED>
rndm::details::RangeCheckHelper< SEED >::RangeCheckHelper ( std::string  maxSeedsLabel = "maxUniqueEngines",
std::string  baseSeedLabel = "baseSeed",
std::string  checkRangeLabel = "checkRange" 
)
inline

Constructor; specify configuration labels.

Definition at line 104 of file BasePolicies.h.

109  { SetConfigLabels(maxSeedsLabel, baseSeedLabel, checkRangeLabel); }
void SetConfigLabels(std::string maxSeedsLabel="maxUniqueEngines", std::string baseSeedLabel="baseSeed", std::string checkRangeLabel="checkRange")
Definition: BasePolicies.h:177
template<typename SEED>
rndm::details::RangeCheckHelper< SEED >::RangeCheckHelper ( std::string  maxSeedsLabel = "maxUniqueEngines",
std::string  baseSeedLabel = "baseSeed",
std::string  checkRangeLabel = "checkRange" 
)
inline

Constructor; specify configuration labels.

Definition at line 149 of file RandomSeedPolicyBase.h.

154  { SetConfigLabels(maxSeedsLabel, baseSeedLabel, checkRangeLabel); }
void SetConfigLabels(std::string maxSeedsLabel="maxUniqueEngines", std::string baseSeedLabel="baseSeed", std::string checkRangeLabel="checkRange")
Definition: BasePolicies.h:177

Member Function Documentation

template<typename SEED >
bool rndm::details::RangeCheckHelper< SEED >::configure ( fhicl::ParameterSet const &  pset)

Configures from a parameter set

Returns
if the configuration after the call is complete

Definition at line 189 of file BasePolicies.h.

References util::empty(), fhicl::ParameterSet::get_if_present(), and seed.

Referenced by rndm::details::CheckedRangePolicy< SEED >::ensureRange(), and rndm::details::CheckedRangePolicy< SEED >::static_configure().

189  {
190  if (!paramLabels[pmMaxSeeds].empty()) {
191  seed_t seed;
192  if (pset.get_if_present(paramLabels[pmMaxSeeds], seed)) SetNSeeds(seed);
193  }
194  if (!paramLabels[pmBaseSeed].empty()) {
195  seed_t seed;
196  if (pset.get_if_present(paramLabels[pmBaseSeed], seed))
197  SetBaseSeed(seed);
198  }
199  if (!paramLabels[pmDoCheck].empty()) {
200  bool flag;
201  if (pset.get_if_present(paramLabels[pmDoCheck], flag)) SetCheck(flag);
202  }
203  return isConfigured();
204  } // RangeCheckHelper<SEED>::configure()
bool isConfigured() const
Returns whether all the parameters are configured.
Definition: BasePolicies.h:208
void SetCheck(bool doCheck=true)
Sets whether to perform the check or not.
Definition: BasePolicies.h:124
void SetNSeeds(seed_t nSeeds)
Sets the number of seeds directly.
Definition: BasePolicies.h:132
long seed
Definition: chem4.cc:67
std::array< std::string, NParams > paramLabels
Definition: BasePolicies.h:166
void SetBaseSeed(seed_t base_seed)
Sets the base seed directly.
Definition: BasePolicies.h:128
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
template<typename SEED>
bool rndm::details::RangeCheckHelper< SEED >::configure ( fhicl::ParameterSet const &  pset)

Configures from a parameter set

Returns
if the configuration after the call is complete
template<typename SEED >
void rndm::details::RangeCheckHelper< SEED >::EnsureRange ( std::string  policy,
SeedMasterHelper::EngineId const &  id,
seed_t  seed 
) const

Throws an exception if the range check on seed fails.

Definition at line 214 of file BasePolicies.h.

References art::errors::LogicError, and rndm::details::RangeCheckHelper< SEED >::print().

Referenced by rndm::details::CheckedRangePolicy< SEED >::ensureRange().

217  {
218  if (operator()(seed)) return;
219  seed_t offset = seed - BaseSeed;
221  << "NuRandomService (policy: " << policy << ") for engine: "
222  << id << " the offset of seed " << seed << " is: " << offset << "."
223  "\nAllowed seed offsets are in the range 0....(N-1) where N is: "
224  << MaxSeeds << " (as configured in maxUniqueEngines)";
225  } // RangeCheckHelper<SEED>::EnsureRange()
seed_t MaxSeeds
number of valid seeds
Definition: BasePolicies.h:171
long seed
Definition: chem4.cc:67
seed_t BaseSeed
minimum valid seed
Definition: BasePolicies.h:170
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
template<typename SEED>
void rndm::details::RangeCheckHelper< SEED >::EnsureRange ( std::string  policy,
SeedMasterHelper::EngineId const &  id,
seed_t  seed 
) const

Throws an exception if the range check on seed fails.

template<typename SEED >
bool rndm::details::RangeCheckHelper< SEED >::isConfigured ( ) const

Returns whether all the parameters are configured.

Definition at line 208 of file BasePolicies.h.

Referenced by rndm::details::CheckedRangePolicy< SEED >::CheckRangeConfiguration(), and rndm::details::CheckedRangePolicy< SEED >::ensureRange().

208  {
209  return (hasParameters.test(pmDoCheck) && !bCheck) || hasParameters.all();
210  } // RangeCheckHelper<SEED>::isConfigured()
std::bitset< NParams > hasParameters
Definition: BasePolicies.h:167
bool bCheck
should we perform the check?
Definition: BasePolicies.h:169
template<typename SEED>
bool rndm::details::RangeCheckHelper< SEED >::isConfigured ( ) const

Returns whether all the parameters are configured.

template<typename SEED >
std::vector< std::string > rndm::details::RangeCheckHelper< SEED >::missingConfig ( ) const

Returns the items currently not configured.

Definition at line 242 of file BasePolicies.h.

Referenced by rndm::details::CheckedRangePolicy< SEED >::CheckRangeConfiguration(), and rndm::details::CheckedRangePolicy< SEED >::ensureRange().

242  {
243  if (hasParameters.test(pmDoCheck) && !bCheck) return {};
244  std::vector<std::string> missing;
245  for (unsigned int i = 0; i < NParams; ++i)
246  if (!hasParameters.test(i)) missing.push_back(paramLabels[i]);
247  return missing;
248  } // RangeCheckHelper<SEED>::missingConfig()
std::bitset< NParams > hasParameters
Definition: BasePolicies.h:167
bool bCheck
should we perform the check?
Definition: BasePolicies.h:169
std::array< std::string, NParams > paramLabels
Definition: BasePolicies.h:166
static constexpr unsigned int NParams
Definition: BasePolicies.h:164
template<typename SEED>
std::vector<std::string> rndm::details::RangeCheckHelper< SEED >::missingConfig ( ) const

Returns the items currently not configured.

template<typename SEED>
bool rndm::details::RangeCheckHelper< SEED >::operator() ( seed_t  seed) const
inline

Performs the check on the specified seed.

Definition at line 136 of file BasePolicies.h.

137  {
138  return
139  !bCheck || ((seed >= BaseSeed) && (seed < BaseSeed + MaxSeeds));
140  } // operator()
seed_t MaxSeeds
number of valid seeds
Definition: BasePolicies.h:171
bool bCheck
should we perform the check?
Definition: BasePolicies.h:169
long seed
Definition: chem4.cc:67
seed_t BaseSeed
minimum valid seed
Definition: BasePolicies.h:170
template<typename SEED>
bool rndm::details::RangeCheckHelper< SEED >::operator() ( seed_t  seed) const
inline

Performs the check on the specified seed.

Definition at line 181 of file RandomSeedPolicyBase.h.

182  {
183  return
184  !bCheck || ((seed >= BaseSeed) && (seed < BaseSeed + MaxSeeds));
185  } // operator()
seed_t MaxSeeds
number of valid seeds
Definition: BasePolicies.h:171
bool bCheck
should we perform the check?
Definition: BasePolicies.h:169
long seed
Definition: chem4.cc:67
seed_t BaseSeed
minimum valid seed
Definition: BasePolicies.h:170
template<typename SEED >
template<typename STREAM >
void rndm::details::RangeCheckHelper< SEED >::print ( STREAM &  out,
std::string  indent = std::string() 
) const

Prints the configuration int the specified stream.

Definition at line 230 of file BasePolicies.h.

Referenced by rndm::details::RangeCheckHelper< SEED >::EnsureRange().

231  {
232  if (!isConfigured())
233  out << indent << "seed range checker not configured!";
234  else if (bCheck)
235  out << indent << "maximum number of seeds: " << MaxSeeds;
236  else
237  out << indent << "no limit on number of seeds.";
238  } // RangeCheckHelper<SEED>::print()
bool isConfigured() const
Returns whether all the parameters are configured.
Definition: BasePolicies.h:208
seed_t MaxSeeds
number of valid seeds
Definition: BasePolicies.h:171
bool bCheck
should we perform the check?
Definition: BasePolicies.h:169
std::string indent(std::size_t const i)
template<typename SEED>
template<typename STREAM >
void rndm::details::RangeCheckHelper< SEED >::print ( STREAM &  out,
std::string  indent = std::string() 
) const

Prints the configuration int the specified stream.

template<typename SEED>
void rndm::details::RangeCheckHelper< SEED >::SetBaseSeed ( seed_t  base_seed)
inline
template<typename SEED>
void rndm::details::RangeCheckHelper< SEED >::SetBaseSeed ( seed_t  base_seed)
inline

Sets the base seed directly.

Definition at line 173 of file RandomSeedPolicyBase.h.

template<typename SEED>
void rndm::details::RangeCheckHelper< SEED >::SetCheck ( bool  doCheck = true)
inline

Sets whether to perform the check or not.

Definition at line 124 of file BasePolicies.h.

Referenced by rndm::details::PredefinedSeedPolicy< SEED >::static_configure().

125  { bCheck = doCheck; hasParameters.set(pmDoCheck); }
std::bitset< NParams > hasParameters
Definition: BasePolicies.h:167
bool bCheck
should we perform the check?
Definition: BasePolicies.h:169
template<typename SEED>
void rndm::details::RangeCheckHelper< SEED >::SetCheck ( bool  doCheck = true)
inline

Sets whether to perform the check or not.

Definition at line 169 of file RandomSeedPolicyBase.h.

170  { bCheck = doCheck; hasParameters.set(pmDoCheck); }
std::bitset< NParams > hasParameters
Definition: BasePolicies.h:167
bool bCheck
should we perform the check?
Definition: BasePolicies.h:169
template<typename SEED >
void rndm::details::RangeCheckHelper< SEED >::SetConfigLabels ( std::string  maxSeedsLabel = "maxUniqueEngines",
std::string  baseSeedLabel = "baseSeed",
std::string  checkRangeLabel = "checkRange" 
)
template<typename SEED>
void rndm::details::RangeCheckHelper< SEED >::SetConfigLabels ( std::string  maxSeedsLabel = "maxUniqueEngines",
std::string  baseSeedLabel = "baseSeed",
std::string  checkRangeLabel = "checkRange" 
)
template<typename SEED>
void rndm::details::RangeCheckHelper< SEED >::SetNSeeds ( seed_t  nSeeds)
inline

Sets the number of seeds directly.

Definition at line 132 of file BasePolicies.h.

Referenced by rndm::details::LinearMappingPolicy< SEED >::createSeed().

template<typename SEED>
void rndm::details::RangeCheckHelper< SEED >::SetNSeeds ( seed_t  nSeeds)
inline

Sets the number of seeds directly.

Definition at line 177 of file RandomSeedPolicyBase.h.

Member Data Documentation

template<typename SEED>
seed_t rndm::details::RangeCheckHelper< SEED >::BaseSeed
protected

minimum valid seed

Definition at line 170 of file BasePolicies.h.

template<typename SEED>
bool rndm::details::RangeCheckHelper< SEED >::bCheck = true
protected

should we perform the check?

Definition at line 169 of file BasePolicies.h.

template<typename SEED>
std::bitset< NParams > rndm::details::RangeCheckHelper< SEED >::hasParameters
protected

Definition at line 167 of file BasePolicies.h.

template<typename SEED>
seed_t rndm::details::RangeCheckHelper< SEED >::MaxSeeds
protected

number of valid seeds

Definition at line 171 of file BasePolicies.h.

template<typename SEED>
static constexpr unsigned int rndm::details::RangeCheckHelper< SEED >::NParams = (unsigned int) pmNParams
staticprotected

Definition at line 164 of file BasePolicies.h.

template<typename SEED>
std::array< std::string, NParams > rndm::details::RangeCheckHelper< SEED >::paramLabels
protected

Definition at line 166 of file BasePolicies.h.


The documentation for this class was generated from the following files: