EventDebugger.cc

Go to the documentation of this file.
00001 // $Header: /cvs/lcd/slic/src/EventDebugger.cc,v 1.6 2007/04/27 01:54:34 jeremy Exp $
00002 #include "EventDebugger.hh"
00003 
00004 // slic
00005 #include "EventDebuggerMessenger.hh"
00006 
00007 // geant4
00008 #include "G4Run.hh"
00009 #include "G4Event.hh"
00010 #include "G4UImanager.hh"
00011 
00012 namespace slic
00013 {
00014   EventDebugger::EventDebugger()
00015     : Module("EventDebugger"),
00016       m_debugging(false),
00017       m_haveDebugMacro(false),
00018       m_haveCleanupMacro(false),
00019       m_forceDebugMode(false)
00020   {
00021     m_messenger = new EventDebuggerMessenger();
00022   }
00023 
00024   EventDebugger::~EventDebugger()
00025   {
00026     delete m_messenger;
00027   }
00028 
00029   void EventDebugger::enableDebug(bool e)
00030   {
00031     m_forceDebugMode = e;
00032   }
00033 
00034   void EventDebugger::addDebugEvent(G4int eventNum)
00035   {
00036     if ( !haveDebugEvent(eventNum) ) {
00037       m_events.push_back(eventNum);
00038 #ifdef SLIC_LOG      
00039       log() << LOG::okay << "EventDebugger - Added debug event <" << eventNum << ">" << LOG::done;
00040 #endif
00041     }
00042 #ifdef SLIC_LOG
00043     else {
00044       log() << LOG::warning << "EventDebugger - Ignoring dup event #" << eventNum << LOG::done;
00045     }
00046 #endif
00047   }
00048 
00049   void EventDebugger::setDebugMacro(std::string mac)
00050   {
00051     m_haveDebugMacro = true;
00052     m_debugMacro = mac;
00053   }
00054 
00055   void EventDebugger::setCleanupMacro(std::string mac)
00056   {
00057     m_haveCleanupMacro = true;
00058     m_cleanupMacro = mac;
00059   }
00060 
00061   void EventDebugger::clearDebugEvents()
00062   {
00063     m_events.clear();
00064   }
00065 
00066   void EventDebugger::sortDebugEvents()
00067   {
00068     std::sort(m_events.begin(), m_events.end() );
00069   }
00070 
00071   bool EventDebugger::haveDebugEvent(G4int evtNum) const
00072   {
00073     for ( DebugEventList::const_iterator it = m_events.begin();
00074           it != m_events.end();
00075           it++ ) {
00076       if ( (*it) == evtNum ) {
00077         return true;
00078       }
00079     }
00080     return false;
00081   }
00082 
00083   void EventDebugger::beginRun(const G4Run*)
00084   {
00085     sortDebugEvents();
00086   }
00087 
00088   void EventDebugger::beginEvent(const G4Event* evt)
00089   {
00090     if ( m_forceDebugMode ||
00091          haveDebugEvent( evt->GetEventID() ) ) {
00092       m_debugging = true;
00093       execDebugMacro();
00094     }
00095   }
00096 
00097   void EventDebugger::endEvent(const G4Event*)
00098   {
00099     if ( m_debugging ) {
00100       execCleanupMacro();
00101       m_debugging = false;
00102     }
00103   }
00104 
00105   void EventDebugger::execDebugMacro()
00106   {
00107     if ( m_haveDebugMacro ) {
00108       G4UImanager::GetUIpointer()->ApplyCommand( "/control/execute " + m_debugMacro );
00109 
00110 #ifdef SLIC_LOG
00111       if ( !m_haveCleanupMacro ) {
00112         log() << "WARNING: Executed debugging macro, but cleanup macro was not set." << LOG::done;
00113       }
00114 #endif
00115     }
00116 #ifdef SLIC_LOG
00117     else {
00118       log() << LOG::error << "ERROR: debug macro not set" << LOG::done;
00119     }
00120 #endif
00121   }
00122 
00123   void EventDebugger::execCleanupMacro()
00124   {
00125     if ( m_haveCleanupMacro ) {
00126       G4UImanager::GetUIpointer()->ApplyCommand( "/control/execute " + m_cleanupMacro );
00127     }
00128 #ifdef SLIC_LOG
00129     else {
00130       log() << LOG::error << "ERROR: cleanup macro not set" << LOG::done;
00131     }
00132 #endif
00133   }
00134 } // namespace slic

Generated on Thu Nov 15 15:24:15 2007 for Simulator for the Linear Collider by  doxygen 1.5.4