/**
 * @file SolidRunMessenger.cc
 * @author: Ibrahin Pinera
 * @date 2017 SoLid - University of Antwerp
 */


#include "SolidRunMessenger.hh"
#include "SolidRunAction.hh"

#include "G4UIdirectory.hh"


//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

SolidRunMessenger::SolidRunMessenger(SolidRunAction * SolidRA)
:SolidRunAct(SolidRA)
{

    m_treeT2Cmd = new G4UIcmdWithABool("/Solid/storeT2",this);
    m_treeT2Cmd->SetGuidance("Store (true) or not (false) the T2 tree in the output file");
    m_treeT2Cmd->SetGuidance("Default = false");
    m_treeT2Cmd->SetParameterName("storeT2", false);
    m_treeT2Cmd->AvailableForStates(G4State_Idle);

    m_treeT6Cmd = new G4UIcmdWithABool("/Solid/storeT6",this);
    m_treeT6Cmd->SetGuidance("Store (true) or not (false) the T6 tree in the output file");
    m_treeT6Cmd->SetGuidance("Default = false");
    m_treeT6Cmd->SetParameterName("storeT6", false);
    m_treeT6Cmd->AvailableForStates(G4State_Idle);

    m_treeT7Cmd = new G4UIcmdWithABool("/Solid/storeT7",this);
    m_treeT7Cmd->SetGuidance("Store (true) or not (false) the T7 tree in the output file");
    m_treeT7Cmd->SetGuidance("Default = false");
    m_treeT7Cmd->SetParameterName("storeT7", false);
    m_treeT7Cmd->AvailableForStates(G4State_Idle);

    m_treeT8Cmd = new G4UIcmdWithABool("/Solid/storeT8",this);
    m_treeT8Cmd->SetGuidance("Store (true) or not (false) the T8 tree in the output file");
    m_treeT8Cmd->SetGuidance("Default = false");
    m_treeT8Cmd->SetParameterName("storeT8", false);
    m_treeT8Cmd->AvailableForStates(G4State_Idle);

    m_treeT9Cmd = new G4UIcmdWithABool("/Solid/storeT9",this);
    m_treeT9Cmd->SetGuidance("Store (true) or not (false) the T9 tree. ");
    m_treeT9Cmd->SetGuidance("Default = true");
    m_treeT9Cmd->SetParameterName("storeT9", true);
    m_treeT9Cmd->AvailableForStates(G4State_Idle);

    m_treeT9cutCmd = new G4UIcmdWithAnInteger("/Solid/T9cut",this);
    m_treeT9cutCmd->SetGuidance("Choose between cut 0, 1, 2 or 3 to select which particle to store");
    m_treeT9cutCmd->SetGuidance("0 : No cut. All particles stored");
    m_treeT9cutCmd->SetGuidance("1 : only particles with 2 < VolID < 90 stored (default)");
    m_treeT9cutCmd->SetGuidance("2 : only electrons with 2 < VolID < 90 stored");
    m_treeT9cutCmd->SetGuidance("3 : particles (other than e^- from ionisation and photo-electric) with 2 < VolID < 90 stored");
    m_treeT9cutCmd->SetDefaultValue(1);
    m_treeT9cutCmd->SetParameterName("T9cut", true);
    m_treeT9cutCmd->SetRange("T9cut >= 0");
  
    m_treeLightCmd = new G4UIcmdWithABool("/Solid/LightOutput",this);
    m_treeLightCmd->SetGuidance("Use (true) or not (false) a light version of the output. True by default.  If true only events which produces a signal in the detector will be stored. ");
    m_treeLightCmd->SetGuidance("Default = true");
    m_treeLightCmd->SetParameterName("LightOutput", true);
    m_treeLightCmd->AvailableForStates(G4State_Idle);
    

    m_nevtCmd = new G4UIcmdWithAnInteger("/Solid/beamOn",this);
    m_nevtCmd->SetGuidance("Number of events to be simulated");
    m_nevtCmd->SetDefaultValue(1);
    m_nevtCmd->SetParameterName("Nevt", true);
    m_nevtCmd->SetRange("Nevt > 0");

}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

SolidRunMessenger::~SolidRunMessenger()
{
    delete m_treeT2Cmd;
    delete m_treeT6Cmd;
    delete m_treeT7Cmd;
    delete m_treeT8Cmd;
    delete m_treeT9Cmd;
    delete m_treeT9cutCmd;
    delete m_nevtCmd;
    delete m_treeLightCmd;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

void SolidRunMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
{

    if(command == m_treeT2Cmd)
        SolidRunAct->SetStoreT2(m_treeT2Cmd->GetNewBoolValue(newValue));
    
    if(command == m_treeT6Cmd)
        SolidRunAct->SetStoreT6(m_treeT6Cmd->GetNewBoolValue(newValue));

    if(command == m_treeT7Cmd)
        SolidRunAct->SetStoreT7(m_treeT7Cmd->GetNewBoolValue(newValue));

    if(command == m_treeT8Cmd)
        SolidRunAct->SetStoreT8(m_treeT8Cmd->GetNewBoolValue(newValue));

    if(command == m_treeT9Cmd)
        SolidRunAct->SetStoreT9(m_treeT9Cmd->GetNewBoolValue(newValue));

    if(command == m_treeT9cutCmd)
        SolidRunAct->SetStoreT9cut(m_treeT9cutCmd->GetNewIntValue(newValue));

    if(command == m_nevtCmd)
        SolidRunAct->SetStoreNevt(m_nevtCmd->GetNewIntValue(newValue));

     if(command == m_treeLightCmd)
        SolidRunAct->SetStoreLightOutput(m_treeLightCmd->GetNewBoolValue(newValue));

}



//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....