flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
slha_format.hpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#ifndef SLHA_FORMAT_H
20#define SLHA_FORMAT_H
21
22#include <string>
23
24namespace flexiblesusy {
25
27extern const char * const mass_formatter;
29extern const char * const mixing_matrix_formatter;
31extern const char * const vector_formatter;
33extern const char * const number_formatter;
35extern const char * const tensor_formatter;
37extern const char * const scale_formatter;
39extern const char * const single_element_formatter;
41extern const char * const spinfo_formatter;
43extern const char * const obsinfo_formatter;
45extern const char * const wilson_formatter;
47extern const char * const format_total_width;
49extern const char * const format_effectivecouplings;
50
51namespace {
53 constexpr unsigned SLHA_MAX_LINE_LENGTH = 200;
54} // namespace
55
56template <typename Container>
57std::string format_decay(double br, const Container& pids, const std::string& name)
58{
59 const int nda = pids.size();
60 char buf[SLHA_MAX_LINE_LENGTH] = { 0 };
61 int written = 0;
62 written += std::snprintf(buf + written, SLHA_MAX_LINE_LENGTH - written,
63 " %16.8E %2d ", br, nda);
64 for (int i = 0; i < nda; i++) {
65 written += std::snprintf(buf + written, SLHA_MAX_LINE_LENGTH - written,
66 " %9d", pids[i]);
67 }
68 written += std::snprintf(buf + written, SLHA_MAX_LINE_LENGTH - written,
69 " # %s\n", name.c_str());
70 return std::string(buf);
71}
72
73#define FORMAT_MASS(pdg, mass, name) \
74 [&] { \
75 char buf[SLHA_MAX_LINE_LENGTH]; \
76 const int pdg_ = (pdg); \
77 const double mass_ = (mass); \
78 const std::string name_ = (name); \
79 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, mass_formatter, pdg_, mass_, \
80 name_.c_str()); \
81 return std::string(buf); \
82 }()
83
84#define FORMAT_MIXING_MATRIX(i, k, entry, name) \
85 [&] { \
86 char buf[SLHA_MAX_LINE_LENGTH]; \
87 const int i_ = (i); \
88 const int k_ = (k); \
89 const double entry_ = (entry); \
90 const std::string name_ = (name); \
91 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, mixing_matrix_formatter, i_, \
92 k_, entry_, name_.c_str()); \
93 return std::string(buf); \
94 }()
95
96#define FORMAT_VECTOR(i, entry, name) \
97 [&] { \
98 char buf[SLHA_MAX_LINE_LENGTH]; \
99 const int i_ = (i); \
100 const double entry_ = (entry); \
101 const std::string name_ = (name); \
102 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, vector_formatter, i_, entry_, \
103 name_.c_str()); \
104 return std::string(buf); \
105 }()
106
107#define FORMAT_ELEMENT(pdg, value, name) \
108 [&] { \
109 char buf[SLHA_MAX_LINE_LENGTH]; \
110 const int pdg_ = (pdg); \
111 const double value_ = (value); \
112 const std::string name_ = (name); \
113 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, single_element_formatter, pdg_, \
114 value_, name_.c_str()); \
115 return std::string(buf); \
116 }()
117
118#define FORMAT_SCALE(n) \
119 [&] { \
120 char buf[SLHA_MAX_LINE_LENGTH]; \
121 const double n_ = (n); \
122 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, scale_formatter, n_); \
123 return std::string(buf); \
124 }()
125
126#define FORMAT_NUMBER(n, str) \
127 [&] { \
128 char buf[SLHA_MAX_LINE_LENGTH]; \
129 const double n_ = (n); \
130 const std::string str_ = (str); \
131 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, number_formatter, n_, \
132 str_.c_str()); \
133 return std::string(buf); \
134 }()
135
136#define FORMAT_SPINFO(n, str) \
137 [&] { \
138 char buf[SLHA_MAX_LINE_LENGTH]; \
139 const int n_ = (n); \
140 const std::string str_ = (str); \
141 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, spinfo_formatter, n_, \
142 str_.c_str()); \
143 return std::string(buf); \
144 }()
145
146#define FORMAT_OBSINFO(i, j, str) \
147 [&] { \
148 char buf[SLHA_MAX_LINE_LENGTH]; \
149 const int i_ = (i); \
150 const int j_ = (j); \
151 const std::string str_ = (str); \
152 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, obsinfo_formatter, i_, j_, \
153 str_.c_str()); \
154 return std::string(buf); \
155 }()
156
157#define FORMAT_RANK_THREE_TENSOR(i, j, k, entry, name) \
158 [&] { \
159 char buf[SLHA_MAX_LINE_LENGTH]; \
160 const int i_ = (i); \
161 const int j_ = (j); \
162 const int k_ = (k); \
163 const double entry_ = (entry); \
164 const std::string name_ = (name); \
165 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, tensor_formatter, i_, j_, k_, \
166 entry_, name_.c_str()); \
167 return std::string(buf); \
168 }()
169
170#define FORMAT_WILSON_COEFFICIENTS(f, m, x, y, ph, entry, name) \
171 [&] { \
172 char buf[SLHA_MAX_LINE_LENGTH]; \
173 const std::string f_ = (f); \
174 const std::string m_ = (m); \
175 const int x_ = (x); \
176 const int y_ = (y); \
177 const int ph_ = (ph); \
178 const double entry_ = (entry); \
179 const std::string name_ = (name); \
180 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, wilson_formatter, f_.c_str(), \
181 m_.c_str(), x_, y_, ph_, entry_, name_.c_str()); \
182 return std::string(buf); \
183 }()
184
185#define FORMAT_TOTAL_WIDTH(pdg, width, name) \
186 [&] { \
187 char buf[SLHA_MAX_LINE_LENGTH]; \
188 const int pdg_ = (pdg); \
189 const double width_ = (width); \
190 const std::string name_ = (name); \
191 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, format_total_width, \
192 pdg_, width_, name_.c_str()); \
193 return std::string(buf); \
194 }()
195
196#define FORMAT_EFFECTIVECOUPLINGS(pdg1, pdg2, pdg3, width, comment) \
197 [&] { \
198 char buf[SLHA_MAX_LINE_LENGTH]; \
199 const int pdg1_ = (pdg1); \
200 const int pdg2_ = (pdg2); \
201 const int pdg3_ = (pdg3); \
202 const double width_ = (width); \
203 const std::string comment_ = (comment); \
204 std::snprintf(buf, SLHA_MAX_LINE_LENGTH, format_effectivecouplings, \
205 pdg1_, pdg2_, pdg3_, width_, comment_.c_str()); \
206 return std::string(buf); \
207 }()
208
209} // namespace flexiblesusy
210
211#endif
212
constexpr unsigned SLHA_MAX_LINE_LENGTH
maximum line length in SLHA output
Definition: slha_format.hpp:53
const char *const mixing_matrix_formatter
SLHA line formatter for the mixing matrix entries = NMIX, UMIX, VMIX, ...
Definition: slha_format.cpp:26
const char *const format_total_width
SLHA line formatter for the DECAY block.
Definition: slha_format.cpp:44
const char *const number_formatter
SLHA number formatter.
Definition: slha_format.cpp:30
const char *const wilson_formatter
FLHA line formatter for FWCOEF, IMFCOEF block entries.
Definition: slha_format.cpp:42
const char *const tensor_formatter
SLHA line formatter for entries with three indices.
Definition: slha_format.cpp:32
const char *const format_effectivecouplings
SLHA line formatter for the EFFECTIVECOUPLINGS block.
Definition: slha_format.cpp:46
const char *const vector_formatter
SLHA line formatter for vector entries.
Definition: slha_format.cpp:28
const char *const mass_formatter
SLHA line formatter for the MASS block entries.
Definition: slha_format.cpp:24
const char *const spinfo_formatter
SLHA line formatter for the SPINFO block entries.
Definition: slha_format.cpp:38
const char *const single_element_formatter
SLHA line formatter for the one-element entries = HMIX, GAUGE, MSOFT, ...
Definition: slha_format.cpp:36
const char *const scale_formatter
SLHA scale formatter.
Definition: slha_format.cpp:34
const char *const obsinfo_formatter
SLHA line formatter for the OBSINFO block entries.
Definition: slha_format.cpp:40
std::string format_decay(double br, const Container &pids, const std::string &name)
Definition: slha_format.hpp:57