slic/src
diff -N EventDebugger.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ EventDebugger.cc 22 Sep 2005 01:09:48 -0000 1.1
@@ -0,0 +1,141 @@
+// $Header: /cvs/lcd/slic/src/EventDebugger.cc,v 1.1 2005/09/22 01:09:48 jeremy Exp $
+#include "EventDebugger.hh"
+
+// slic
+#include "EventDebuggerMessenger.hh"
+
+// geant4
+#include "G4Run.hh"
+#include "G4Event.hh"
+#include "G4UImanager.hh"
+
+// std
+#include <iostream>
+
+using std::cerr;
+using std::endl;
+
+namespace slic
+{
+ EventDebugger* EventDebugger::m_instance = 0;
+
+
+ EventDebugger::EventDebugger()
+ : Module("EventDebugger"),
+ m_debugging(false),
+ m_haveDebugMacro(false),
+ m_haveCleanupMacro(false)
+ {
+ m_messenger = new EventDebuggerMessenger();
+ }
+
+ EventDebugger::~EventDebugger()
+ {
+ delete m_messenger;
+ }
+
+ EventDebugger* EventDebugger::instance()
+ {
+ if ( 0 == m_instance ) {
+ m_instance = new EventDebugger();
+ }
+ return m_instance;
+ }
+
+ void EventDebugger::enableDebug(bool e)
+ {
+ m_forceDebugMode = e;
+ }
+
+ void EventDebugger::addDebugEvent(G4int eventNum)
+ {
+ if ( !haveDebugEvent(eventNum) ) {
+ m_events.push_back(eventNum);
+ std::cout << "Added debug event <" << eventNum << ">" << std::endl;
+ }
+ else {
+ cerr << "EventDebugger::addDebugEvent - Ignoring dup event #" << eventNum << endl;
+ }
+ }
+
+ void EventDebugger::setDebugMacro(std::string mac)
+ {
+ m_haveDebugMacro = true;
+ m_debugMacro = mac;
+ }
+
+ void EventDebugger::setCleanupMacro(std::string mac)
+ {
+ m_haveCleanupMacro = true;
+ m_cleanupMacro = mac;
+ }
+
+ void EventDebugger::clearDebugEvents()
+ {
+ m_events.clear();
+ }
+
+ void EventDebugger::sortDebugEvents()
+ {
+ std::sort(m_events.begin(), m_events.end() );
+ }
+
+ bool EventDebugger::haveDebugEvent(G4int evtNum) const
+ {
+ for ( DebugEventList::const_iterator it = m_events.begin();
+ it != m_events.end();
+ it++ ) {
+ if ( (*it) == evtNum ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void EventDebugger::beginRun(const G4Run*)
+ {
+ sortDebugEvents();
+ }
+
+ void EventDebugger::beginEvent(const G4Event* evt)
+ {
+ // if ( m_events.size() > 0 ) {
+ if ( m_forceDebugMode ||
+ haveDebugEvent( evt->GetEventID() ) ) {
+ m_debugging = true;
+ execDebugMacro();
+ }
+ }
+
+ void EventDebugger::endEvent(const G4Event*)
+ {
+ if ( m_debugging ) {
+ execCleanupMacro();
+ m_debugging = false;
+ }
+ }
+
+ void EventDebugger::execDebugMacro()
+ {
+ if ( m_haveDebugMacro ) {
+ G4UImanager::GetUIpointer()->ApplyCommand( "/control/execute " + m_debugMacro );
+
+ if ( !m_haveCleanupMacro ) {
+ cerr << "WARNING: Executed debugging macro, but cleanup macro was not set." << endl;
+ }
+ }
+ else {
+ cerr << "ERROR: debug macro not set" << endl;
+ }
+ }
+
+ void EventDebugger::execCleanupMacro()
+ {
+ if ( m_haveCleanupMacro ) {
+ G4UImanager::GetUIpointer()->ApplyCommand( "/control/execute " + m_cleanupMacro );
+ }
+ else {
+ cerr << "ERROR: cleanup macro not set" << endl;
+ }
+ }
+}
slic/include
diff -N EventDebugger.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ EventDebugger.hh 22 Sep 2005 01:09:49 -0000 1.1
@@ -0,0 +1,78 @@
+// $Header: /cvs/lcd/slic/include/EventDebugger.hh,v 1.1 2005/09/22 01:09:49 jeremy Exp $
+#ifndef slic_EventDebugger_hh
+#define slic_EventDebugger_hh 11
+
+// slic
+#include "Module.hh"
+
+// geant4
+#include "globals.hh"
+
+// std
+#include <string>
+#include <vector>
+
+class G4Run;
+class G4Event;
+
+namespace slic
+{
+ class EventDebuggerMessenger;
+
+ /**
+ * @class EventDebugger
+ * @brief Manages debugging of individual G4Events.
+ */
+ class EventDebugger : public Module
+ {
+ public:
+
+ typedef std::vector<G4int> DebugEventList;
+
+ public:
+ virtual ~EventDebugger();
+ static EventDebugger* instance();
+
+ protected:
+ EventDebugger();
+
+ public:
+
+ void enableDebug(bool e = true);
+
+ void addDebugEvent(G4int eventNum);
+ void clearDebugEvents();
+ bool haveDebugEvent(G4int) const;
+
+ void setDebugMacro(std::string);
+ void setCleanupMacro(std::string);
+
+ void beginRun(const G4Run*);
+ void beginEvent(const G4Event*);
+ void endEvent(const G4Event*);
+
+ private:
+
+ void sortDebugEvents();
+
+ void execDebugMacro();
+ void execCleanupMacro();
+
+ private:
+
+ static EventDebugger* m_instance;
+
+ EventDebuggerMessenger* m_messenger;
+
+ std::string m_debugMacro;
+ std::string m_cleanupMacro;
+
+ DebugEventList m_events;
+ bool m_forceDebugMode;
+ bool m_debugging;
+ bool m_haveDebugMacro;
+ bool m_haveCleanupMacro;
+ };
+};
+
+#endif