-
Notifications
You must be signed in to change notification settings - Fork 3
/
detqmcptparams.cpp
68 lines (62 loc) · 2.36 KB
/
detqmcptparams.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. See the enclosed file LICENSE for a copy or if
* that was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright 2017 Max H. Gerlach
*
* */
#include <functional> // std::function
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wshadow"
#include "boost/assign/std/vector.hpp"
#include "boost/algorithm/string/join.hpp"
#include "boost/range/adaptor/transformed.hpp"
#pragma GCC diagnostic pop
#include "tools.h"
#include "detqmcptparams.h"
#include "exceptions.h"
void DetQMCPTParams::check() {
//check parameters
using namespace boost::assign;
std::vector<std::string> neededPars;
neededPars += "exchangeInterval", "controlParameterValues", "controlParameterName";
for (auto p = neededPars.cbegin(); p != neededPars.cend(); ++p) {
if (specified.count(*p) == 0) {
throw_ParameterMissing(*p);
}
}
if (controlParameterValues.size() == 0) {
throw_ParameterWrong_message("No PT control parameters specified");
}
}
MetadataMap DetQMCPTParams::prepareMetadataMap() const {
MetadataMap meta;
#define META_INSERT(VAR) meta[#VAR] = numToString(VAR)
META_INSERT(exchangeInterval);
META_INSERT(controlParameterName);
#undef META_INSERT
using boost::algorithm::join;
using boost::adaptors::transformed;
// std::string valuesString = join(
// controlParameterValues | transformed(numToString<num>),
// " ");
/// The argument to transformed needs to fulfill some qualities,
/// e.g. it must be copy-constructible, the simple statement above
/// does not compile on the Intel Compiler, C++11 lambdas do not
/// work either (!
/// http://stackoverflow.com/questions/11872558/using-boost-adaptors-with-c11-lambdas),
/// apparently they need to be a functor with member result_type.
/// Work around: std::function
/// -- This may or may not be better in a more recent version of
/// Boost than 1.51 --
std::function<std::string(num)> func = [](num v) {
return numToString<num>(v);
};
std::string valuesString = join(
controlParameterValues | transformed(func),
" ");
meta["controlParameterValues"] = valuesString;
return meta;
}