FloatingPointException.cc
Go to the documentation of this file.
1 #ifdef _GNU_SOURCE
2 # include <fenv.h>
3 #endif
4 
6 #include <utl/Reader.h>
7 #include <fwk/CentralConfig.h>
8 #include <utl/ErrorLogger.h>
9 #include <utl/String.h>
10 
11 #include <evt/Event.h>
12 
13 using namespace std;
14 using namespace utl;
15 using namespace fwk;
16 
17 
19 
22  {
23 #ifndef _GNU_SOURCE
24  WARNING("floating-point exceptions will not be enabled on this architecture.");
25 #else
26  Branch topB =
27  CentralConfig::GetInstance()->GetTopBranch("FloatingPointException");
28  const vector<unsigned int> bits = topB.GetChild("ExceptionBits").Get<vector<unsigned int>>();
29  ostringstream info;
30  info << "enabling floating point exception bits:";
31  fExceptions = 0;
32  for (const auto bit : bits) {
33  fExceptions |= (1 << bit);
34  info << ' ' << bit;
35  }
36  info << " (" << AsBinary(fExceptions, 8) << " = " << fExceptions << ')';
37  INFO(info);
38 #endif
39  fCounter = 0;
40 
41  return eSuccess;
42  }
43 
44 
46  FloatingPointException::Run(evt::Event& /*event*/)
47  {
48  ++fCounter;
49 #ifdef _GNU_SOURCE
50  if (fCounter & 1) {
51  feenableexcept(fExceptions);
52  INFO("Enabling.");
53  } else {
54  fedisableexcept(fExceptions);
55  INFO("Disabling.");
56  }
57 #endif
58  return eSuccess;
59  }
60 
61 }
Branch GetTopBranch() const
Definition: Branch.cc:63
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
T Get() const
Definition: Branch.h:271
Class representing a document branch.
Definition: Branch.h:107
std::string AsBinary(const T &number, const int maxBits=8 *sizeof(T), const char separator= ' ', const int stride=4)
converts integer-type numbers into a string of binary representation
Definition: String.h:135
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60

, generated on Tue Sep 26 2023.