summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2011-09-16 20:09:49 -0400
committerStan Seibert <stan@mtrr.org>2011-09-16 20:09:49 -0400
commit26e5398807b6edd6dd71046ef745f5c6acfab1ed (patch)
tree82de046a7289576278f5d58f5c15f9563166280a /src
parent5fa54a5e6f2d76a52ec0d25b663d1051136de395 (diff)
downloadchroma-26e5398807b6edd6dd71046ef745f5c6acfab1ed.tar.gz
chroma-26e5398807b6edd6dd71046ef745f5c6acfab1ed.tar.bz2
chroma-26e5398807b6edd6dd71046ef745f5c6acfab1ed.zip
Silence annoying GEANT4 warnings and banners during operation.
Diffstat (limited to 'src')
-rw-r--r--src/mute.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/mute.cc b/src/mute.cc
new file mode 100644
index 0000000..e13814f
--- /dev/null
+++ b/src/mute.cc
@@ -0,0 +1,41 @@
+#include <geant4/G4ios.hh>
+
+class discard_streambuf : public std::streambuf {
+public:
+ discard_streambuf() { };
+
+ virtual int_type overflow(int_type c) {
+ // Do nothing with this character
+ return c;
+ };
+};
+
+discard_streambuf discard;
+std::streambuf *g4cout_orig = G4cout.rdbuf();
+std::streambuf *g4cerr_orig = G4cerr.rdbuf();
+
+void mute_g4mute() {
+ G4cout.rdbuf(&discard);
+ G4cerr.rdbuf(&discard);
+}
+
+void mute_g4unmute() {
+ G4cout.rdbuf(g4cout_orig);
+ G4cerr.rdbuf(g4cerr_orig);
+}
+
+
+#include <boost/python.hpp>
+
+using namespace boost::python;
+
+void export_mute()
+{
+ def("g4mute", mute_g4mute, default_call_policies(), "Silence all GEANT4 output");
+ def("g4unmute", mute_g4unmute, default_call_policies(), "Re-enable GEANT4 output after calling ``g4mute()``.");
+}
+
+BOOST_PYTHON_MODULE(mute)
+{
+ export_mute();
+}