source: src/RandomNumbers/RandomNumberEngine_Parameters.cpp@ ac9dc8

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes
Last change on this file since ac9dc8 was 9eb71b3, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Commented out MemDebug include and Memory::ignore.

  • MemDebug clashes with various allocation operators that use a specific placement in memory. It is so far not possible to wrap new/delete fully. Hence, we stop this effort which so far has forced us to put ever more includes (with clashes) into MemDebug and thereby bloat compilation time.
  • MemDebug does not add that much usefulness which is not also provided by valgrind.
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * RandomNumberEngine_Parameters.cpp
25 *
26 * Created on: Jan 6, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35//#include "CodePatterns/MemDebug.hpp"
36
37#include <iostream>
38#include <boost/tokenizer.hpp>
39#include <string>
40#include <map>
41
42#include "CodePatterns/Assert.hpp"
43#include "CodePatterns/Log.hpp"
44#include "CodePatterns/Verbose.hpp"
45
46#include "RandomNumberEngine_Parameters.hpp"
47
48#include "RandomNumberEngine.hpp"
49
50RandomNumberEngine_Parameters::ParamNames RandomNumberEngine_Parameters::params;
51const double RandomNumberEngine_Parameters::noset_value = -1.;
52
53RandomNumberEngine_Parameters::RandomNumberEngine_Parameters() :
54 seed(noset_value)
55{
56 // if param names map not yet filled, do so
57 if (params.begin() == params.end()) {
58 params["seed"] = param_seed;
59 }
60}
61
62RandomNumberEngine_Parameters::RandomNumberEngine_Parameters(
63 const RandomNumberEngine_Parameters &_ref)
64{
65 // check self assignment
66 if (&_ref != this) {
67 seed = _ref.seed;
68 }
69}
70
71RandomNumberEngine_Parameters::~RandomNumberEngine_Parameters()
72{}
73
74void RandomNumberEngine_Parameters::getParameters(const RandomNumberEngine* const _engine)
75{
76 seed = _engine->getseed();
77}
78
79void RandomNumberEngine_Parameters::update(const RandomNumberEngine_Parameters &_params)
80{
81 seed = _params.seed != noset_value ? _params.seed : seed;
82}
83
84bool RandomNumberEngine_Parameters::isDefault() const
85{
86 bool status = true;
87 status = status && (seed == noset_value);
88 return status;
89}
90
91std::ostream & operator << (std::ostream& ost, const RandomNumberEngine_Parameters &params)
92{
93 std::ostringstream output;
94 output << "seed=" << params.seed << ";";
95 ost << output.str();
96 return ost;
97}
98
99// TODO: These should throw exceptions such that invalid user entry can be detected.
100std::istream & operator >> (std::istream& ist, RandomNumberEngine_Parameters &params)
101{
102 typedef boost::tokenizer<boost::char_separator<char> >
103 tokenizer;
104 boost::char_separator<char> semicolonsep(";");
105 boost::char_separator<char> equalitysep("=");
106 std::string line;
107 double tmp;
108 std::getline( ist, line );
109 //LOG(0, "INFO: full line of parameters is '" << line << "'");
110 tokenizer tokens(line, semicolonsep);
111 ASSERT(tokens.begin() != tokens.end(),
112 "operator<< on RandomNumberEngine_Parameters - empty string, need at least ';'!");
113 for (tokenizer::iterator tok_iter = tokens.begin();
114 tok_iter != tokens.end(); ++tok_iter) {
115 tokenizer paramtokens(*tok_iter, equalitysep);
116 if (paramtokens.begin() != paramtokens.end()) {
117 tokenizer::iterator tok_paramiter = paramtokens.begin();
118 tokenizer::iterator tok_valueiter = tok_paramiter;
119 tokenizer::iterator tok_checkiter = ++tok_valueiter;
120 ASSERT(tok_paramiter != paramtokens.end(),
121 "operator<< on RandomNumberEngine_Parameters - missing value before '=' in token"
122 +*tok_iter+"!");
123 ASSERT(tok_valueiter != paramtokens.end(),
124 "operator<< on RandomNumberEngine_Parameters - missing value after '=' in token"
125 +*tok_iter+"!");
126 ++tok_checkiter;
127 ASSERT(tok_checkiter == paramtokens.end(),
128 "operator<< on RandomNumberEngine_Parameters - still tokens before ';' in token"
129 +*tok_iter+": "+*tok_checkiter+"!");
130 LOG(0, "INFO: Token pair is " << *tok_paramiter << "," << *tok_valueiter);
131 std::stringstream value(*tok_valueiter);
132 value >> tmp;
133 if ((RandomNumberEngine_Parameters::params.count(*tok_paramiter) != 0)
134 && (tmp != RandomNumberEngine_Parameters::noset_value)) {
135 switch (RandomNumberEngine_Parameters::params[*tok_paramiter]) {
136 case (RandomNumberEngine_Parameters::param_seed):
137 params.seed = tmp;
138 break;
139 default:
140 std::cerr << "This is weird, we cannot get here!" << std::endl;
141 }
142 LOG(1, "ACCEPT: Value for token " << *tok_paramiter << " set.");
143 } else {
144 LOG(1, "REJECT: Value for token " << *tok_paramiter << " not specified.");
145 }
146 } else {
147 ist.setstate(std::ios::eofbit);
148 }
149 }
150 return ist;
151}
Note: See TracBrowser for help on using the repository browser.