#include "RunAction.hh"

#include "HitOutputManager.hh"
#include "G4GenericMessenger.hh"

RunAction::RunAction()
: G4UserRunAction(),
  fMessenger(nullptr),
  fIncludeElectrons(false)
{
  DefineCommands();
}

RunAction::~RunAction()
{
  delete fMessenger;
}

void RunAction::DefineCommands()
{
  fMessenger = new G4GenericMessenger(this, "/anasen/output/", "ANASEN output controls");

  auto& includeElectronsCmd =
      fMessenger->DeclareProperty("includeElectrons",
                                  fIncludeElectrons,
                                  "Enable or disable recording electron and positron hits.");
  includeElectronsCmd.SetParameterName("includeElectrons", false);
  includeElectronsCmd.SetDefaultValue("false");
}

void RunAction::BeginOfRunAction(const G4Run*)
{
  HitOutputManager::Instance().SetIncludeElectrons(fIncludeElectrons);
  HitOutputManager::Instance().Open();
}

void RunAction::EndOfRunAction(const G4Run*)
{
  HitOutputManager::Instance().Close();
}
