10 # include <sys/time.h> 15 #include <CLHEP/Random/RandomEngine.h> 17 #include <HepMC/HerwigWrapper.h> 55 assert(instance !=
nullptr);
63 *exit = FortranInstance::getInstance<Herwig6Instance>()->hwwarn(
function, *code);
73 <<
"Herwig6 stopped run with error code " << *ecode
92 #ifdef _POSIX_C_SOURCE 99 assert(instance !=
nullptr);
108 <<
"Herwig6Instance::timeout() called recursively." 110 struct sigaction saOld;
111 std::memset(&saOld, 0,
sizeof saOld);
113 struct itimerval itv;
114 timerclear(&itv.it_value);
115 timerclear(&itv.it_interval);
116 itv.it_value.tv_sec = 0;
117 itv.it_interval.tv_sec = 0;
118 setitimer(ITIMER_VIRTUAL, &itv,
nullptr);
122 sigaddset(&ss, SIGVTALRM);
124 sigprocmask(SIG_UNBLOCK, &ss,
nullptr);
125 sigprocmask(SIG_BLOCK, &ss,
nullptr);
132 itv.it_value.tv_sec = 0;
133 itv.it_interval.tv_sec = 0;
134 setitimer(ITIMER_VIRTUAL, &itv,
nullptr);
135 sigprocmask(SIG_UNBLOCK, &ss,
nullptr);
139 itv.it_value.tv_sec = secs;
140 itv.it_interval.tv_sec = secs;
141 setitimer(ITIMER_VIRTUAL, &itv,
nullptr);
144 std::memset(&sa, 0,
sizeof sa);
146 sa.sa_flags = SA_ONESHOT;
147 sigemptyset(&sa.sa_mask);
149 sigaction(SIGVTALRM, &sa, &saOld);
150 sigprocmask(SIG_UNBLOCK, &ss,
nullptr);
158 itv.it_value.tv_sec = 0;
159 itv.it_interval.tv_sec = 0;
160 setitimer(ITIMER_VIRTUAL, &itv,
nullptr);
162 sigaction(SIGVTALRM, &saOld,
nullptr);
170 itv.it_value.tv_sec = 0;
171 itv.it_interval.tv_sec = 0;
172 setitimer(ITIMER_VIRTUAL, &itv,
nullptr);
174 sigaction(SIGVTALRM, &saOld,
nullptr);
195 typedef std::istringstream::traits_type traits;
197 const char *
p = line.c_str(), *
q;
198 p += std::strspn(p,
" \t\r\n");
200 for(
q = p; std::isalnum(*
q);
q++);
203 const ConfigParam *param;
204 for(param = configParams; param->name; param++)
205 if (name == param->name)
210 p =
q + std::strspn(
q,
" \t\r\n");
213 std::size_t mult = 1;
214 for(
unsigned int i = 0;
i < 3;
i++) {
215 if (!param->dim[
i].size)
218 if (*p++ != (
i ?
',' :
'('))
221 p += std::strspn(p,
" \t\r\n");
223 for(
q = p; std::isdigit(*
q);
q++);
227 if (ss.bad() || ss.peek() != traits::eof())
230 if (index < param->dim[
i].
offset)
232 index -= param->dim[
i].offset;
233 if (index >= param->dim[
i].size)
236 p =
q + std::strspn(
q,
" \t\r\n");
239 mult *= param->dim[
i].size;
242 if (param->dim[0].size) {
245 p += std::strspn(p,
" \t\r\n");
250 p += std::strspn(p,
" \t\r\n");
252 for(
q = p; *
q && (std::isalnum(*
q) || std::strchr(
".-+", *
q));
q++);
255 p =
q + std::strspn(
q,
" \t\r\n");
259 switch(param->type) {
263 if (ss.bad() || ss.peek() != traits::eof())
266 ((
int*)param->ptr)[pos] =
value;
272 if (ss.bad() || ss.peek() != traits::eof())
275 ((
double*)param->ptr)[pos] =
value;
281 if (ss.bad() || ss.peek() != traits::eof())
284 for(std::string::iterator iter = value_.begin();
285 iter != value_.end(); ++iter)
286 *iter = std::tolower(*iter);
288 if (value_ ==
"yes" || value_ ==
"true" || value_ ==
"1")
290 else if (value_ ==
"no" || value_ ==
"false" || value_ ==
"0")
295 ((
int*)param->ptr)[pos] =
value;
CLHEP::HepRandomEngine * randomEngine
static PFTauRenderPlugin instance
bool timeout(unsigned int secs, void(*fn)())
static void _timeout_sighandler(int signr)
void openParticleSpecFile(const std::string fileName)
__attribute__((visibility("hidden"))) void dummy()
~Herwig6Instance() override
bool give(const std::string &line)
void cms_hwwarn_(char fn[6], int *, int *)
virtual bool hwwarn(const std::string &fn, int code)
CLHEP::HepRandomEngine * randomEngine
void lunread_(const char filename[], const int length)
std::string fullPath() const
void cmsending_(int *ecode)