source: src/RandomNumbers/RandomNumberEngine_Parameters.cpp@ abae35

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since abae35 was 47d041, checked in by Frederik Heber <heber@…>, 13 years ago

HUGE: Removed all calls to Log(), eLog(), replaced by LOG() and ELOG().

  • Replaced DoLog(.) && (Log() << Verbose(.) << ... << std::endl) by Log(., ...).
  • Replaced Log() << Verbose(.) << .. << by Log(., ...)
  • on multiline used stringstream to generate and message which was finally used in LOG(., output.str())
  • there should be no more occurence of Log(). LOG() and ELOG() must be used instead.
  • Eventually, this will allow for storing all errors and re-printing them on program exit which would be very helpful to ascertain error-free runs for the user.
  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * RandomNumberEngine_Parameters.cpp
10 *
11 * Created on: Jan 6, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <iostream>
23#include <boost/tokenizer.hpp>
24#include <string>
25#include <map>
26
27#include "CodePatterns/Assert.hpp"
28#include "CodePatterns/Log.hpp"
29#include "CodePatterns/Verbose.hpp"
30
31#include "RandomNumberEngine_Parameters.hpp"
32
33#include "RandomNumberEngine.hpp"
34
35RandomNumberEngine_Parameters::ParamNames RandomNumberEngine_Parameters::params;
36const double RandomNumberEngine_Parameters::noset_value = -1.;
37
38RandomNumberEngine_Parameters::RandomNumberEngine_Parameters() :
39 seed(noset_value)
40{
41 // if param names map not yet filled, do so
42 if (params.begin() == params.end()) {
43 params["seed"] = param_seed;
44 }
45}
46
47RandomNumberEngine_Parameters::RandomNumberEngine_Parameters(
48 const RandomNumberEngine_Parameters &_ref)
49{
50 // check self assignment
51 if (&_ref != this) {
52 seed = _ref.seed;
53 }
54}
55
56RandomNumberEngine_Parameters::~RandomNumberEngine_Parameters()
57{}
58
59void RandomNumberEngine_Parameters::getParameters(const RandomNumberEngine* const _engine)
60{
61 seed = _engine->getseed();
62}
63
64void RandomNumberEngine_Parameters::update(const RandomNumberEngine_Parameters &_params)
65{
66 seed = _params.seed != noset_value ? _params.seed : seed;
67}
68
69bool RandomNumberEngine_Parameters::isDefault() const
70{
71 bool status = true;
72 status = status && (seed == noset_value);
73 return status;
74}
75
76std::ostream & operator << (std::ostream& ost, const RandomNumberEngine_Parameters &params)
77{
78 std::ostringstream output;
79 output << "seed=" << params.seed << ";";
80 ost << output.str();
81 return ost;
82}
83
84// TODO: These should throw exceptions such that invalid user entry can be detected.
85std::istream & operator >> (std::istream& ist, RandomNumberEngine_Parameters &params)
86{
87 typedef boost::tokenizer<boost::char_separator<char> >
88 tokenizer;
89 boost::char_separator<char> semicolonsep(";");
90 boost::char_separator<char> equalitysep("=");
91 std::string line;
92 double tmp;
93 std::getline( ist, line );
94 //LOG(0, "INFO: full line of parameters is '" << line << "'");
95 tokenizer tokens(line, semicolonsep);
96 ASSERT(tokens.begin() != tokens.end(),
97 "operator<< on RandomNumberEngine_Parameters - empty string, need at least ';'!");
98 for (tokenizer::iterator tok_iter = tokens.begin();
99 tok_iter != tokens.end(); ++tok_iter) {
100 tokenizer paramtokens(*tok_iter, equalitysep);
101 if (paramtokens.begin() != paramtokens.end()) {
102 tokenizer::iterator tok_paramiter = paramtokens.begin();
103 tokenizer::iterator tok_valueiter = tok_paramiter;
104 tokenizer::iterator tok_checkiter = ++tok_valueiter;
105 ASSERT(tok_paramiter != paramtokens.end(),
106 "operator<< on RandomNumberEngine_Parameters - missing value before '=' in token"
107 +*tok_iter+"!");
108 ASSERT(tok_valueiter != paramtokens.end(),
109 "operator<< on RandomNumberEngine_Parameters - missing value after '=' in token"
110 +*tok_iter+"!");
111 ++tok_checkiter;
112 ASSERT(tok_checkiter == paramtokens.end(),
113 "operator<< on RandomNumberEngine_Parameters - still tokens before ';' in token"
114 +*tok_iter+": "+*tok_checkiter+"!");
115 LOG(0, "INFO: Token pair is " << *tok_paramiter << "," << *tok_valueiter);
116 std::stringstream value(*tok_valueiter);
117 value >> tmp;
118 if ((RandomNumberEngine_Parameters::params.count(*tok_paramiter) != 0)
119 && (tmp != RandomNumberEngine_Parameters::noset_value)) {
120 switch (RandomNumberEngine_Parameters::params[*tok_paramiter]) {
121 case (RandomNumberEngine_Parameters::param_seed):
122 params.seed = tmp;
123 break;
124 default:
125 std::cerr << "This is weird, we cannot get here!" << std::endl;
126 }
127 LOG(1, "ACCEPT: Value for token " << *tok_paramiter << " set.");
128 } else {
129 LOG(1, "REJECT: Value for token " << *tok_paramiter << " not specified.");
130 }
131 } else {
132 ist.setstate(std::ios::eofbit);
133 }
134 }
135 return ist;
136}
Note: See TracBrowser for help on using the repository browser.