Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 26 27 // Author: Ivana Hrivnacova, 18/06/2013 (ivan 27 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr) 28 28 29 #include "G4HnMessenger.hh" 29 #include "G4HnMessenger.hh" 30 #include "G4HnManager.hh" 30 #include "G4HnManager.hh" 31 #include "G4AnalysisUtilities.hh" 31 #include "G4AnalysisUtilities.hh" >> 32 #include "G4AnalysisMessengerHelper.hh" 32 33 33 #include "G4UIcommand.hh" 34 #include "G4UIcommand.hh" 34 #include "G4UIparameter.hh" 35 #include "G4UIparameter.hh" >> 36 #include "G4UIcmdWithAnInteger.hh" 35 #include "G4UIcmdWithABool.hh" 37 #include "G4UIcmdWithABool.hh" 36 #include "G4UIcmdWithAString.hh" 38 #include "G4UIcmdWithAString.hh" 37 39 38 using namespace G4Analysis; 40 using namespace G4Analysis; 39 41 40 //____________________________________________ << 41 G4HnMessenger::G4HnMessenger(G4HnManager& mana 42 G4HnMessenger::G4HnMessenger(G4HnManager& manager) 42 : fManager(manager), << 43 : G4UImessenger(), 43 fHnType(manager.GetHnType()), << 44 fManager(manager) 44 fHnDimension(std::stoi(manager.GetHnType() << 45 { 45 { >> 46 G4String hnType = G4StrUtil::to_lower_copy(fManager.GetHnType()); >> 47 fHelper = std::make_unique<G4AnalysisMessengerHelper>(hnType); >> 48 46 SetHnAsciiCmd(); 49 SetHnAsciiCmd(); 47 SetHnActivationCmd(); 50 SetHnActivationCmd(); 48 SetHnActivationToAllCmd(); 51 SetHnActivationToAllCmd(); 49 SetHnPlottingCmd(); 52 SetHnPlottingCmd(); 50 SetHnPlottingToAllCmd(); 53 SetHnPlottingToAllCmd(); 51 SetHnFileNameCmd(); 54 SetHnFileNameCmd(); 52 SetHnFileNameToAllCmd(); 55 SetHnFileNameToAllCmd(); 53 << 54 auto maxDim = (fHnDimension < kMaxDim) ? fHn << 55 for (unsigned int idim = 0; idim < maxDim; + << 56 fSetAxisLogCmd.push_back(CreateSetAxisLogC << 57 } << 58 } 56 } 59 57 60 //____________________________________________ 58 //_____________________________________________________________________________ 61 G4HnMessenger::~G4HnMessenger() = default; 59 G4HnMessenger::~G4HnMessenger() = default; 62 60 63 // 61 // 64 // private functions 62 // private functions 65 // 63 // 66 64 67 //____________________________________________ 65 //_____________________________________________________________________________ 68 G4String G4HnMessenger::GetObjectType() const << 69 { << 70 return (fHnType[0] == 'h') ? << 71 fHnType.substr(1,1) + "D histogram" : << 72 fHnType.substr(1,1) + "D profile"; << 73 } << 74 << 75 //____________________________________________ << 76 void G4HnMessenger::AddIdParameter(G4UIcommand << 77 { << 78 auto htId = new G4UIparameter("id", 'i', fal << 79 htId->SetGuidance("Histogram id"); << 80 htId->SetParameterRange("id>=0"); << 81 command.SetParameter(htId); << 82 } << 83 << 84 //____________________________________________ << 85 void G4HnMessenger::AddOptionParameter(G4UIcom << 86 { << 87 auto param = new G4UIparameter(optionName, ' << 88 auto guidance = GetObjectType() + " " + opti << 89 param->SetGuidance(guidance.c_str()); << 90 param->SetDefaultValue("true"); << 91 command.SetParameter(param); << 92 } << 93 << 94 //____________________________________________ << 95 void G4HnMessenger::SetHnAsciiCmd() 66 void G4HnMessenger::SetHnAsciiCmd() 96 { 67 { 97 fSetAsciiCmd = << 68 fSetHnAsciiCmd 98 CreateCommand<G4UIcommand>("setAscii", "Pr << 69 = std::make_unique<G4UIcmdWithAnInteger>(fHelper->Update("/analysis/HNTYPE_/setAscii"), this); 99 << 70 fSetHnAsciiCmd->SetGuidance( 100 AddIdParameter(*fSetAsciiCmd); << 71 fHelper->Update("Print NDIM_D LOBJECT of given id on ascii file.")); 101 AddOptionParameter(*fSetAsciiCmd, "hnAscii") << 72 102 << 73 fSetHnAsciiCmd->SetParameterName("id",false); >> 74 fSetHnAsciiCmd->SetRange("id>=0"); >> 75 fSetHnAsciiCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 103 } 76 } 104 77 105 //____________________________________________ 78 //_____________________________________________________________________________ 106 void G4HnMessenger::SetHnActivationCmd() 79 void G4HnMessenger::SetHnActivationCmd() 107 { 80 { 108 fSetActivationCmd = << 81 auto hnId = new G4UIparameter("id", 'i', false); 109 CreateCommand<G4UIcommand>("setActivation" << 82 hnId->SetGuidance(fHelper->Update("OBJECT id")); 110 << 83 hnId->SetParameterRange("id>=0"); 111 AddIdParameter(*fSetActivationCmd); << 84 112 AddOptionParameter(*fSetActivationCmd, "hnAc << 85 auto hnActivation = new G4UIparameter("hnActivation", 's', true); >> 86 hnActivation->SetGuidance(fHelper->Update("OBJECT activation")); >> 87 hnActivation->SetDefaultValue("none"); >> 88 >> 89 fSetHnActivationCmd >> 90 = std::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setActivation"), this); >> 91 fSetHnActivationCmd->SetGuidance( >> 92 fHelper->Update("Set activation for the NDIM_D LOBJECT of given id")); >> 93 fSetHnActivationCmd->SetParameter(hnId); >> 94 fSetHnActivationCmd->SetParameter(hnActivation); >> 95 fSetHnActivationCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 113 } 96 } 114 97 115 //____________________________________________ 98 //_____________________________________________________________________________ 116 void G4HnMessenger::SetHnActivationToAllCmd() 99 void G4HnMessenger::SetHnActivationToAllCmd() 117 { 100 { 118 fSetActivationAllCmd = << 101 fSetHnActivationAllCmd 119 CreateCommand<G4UIcmdWithABool>( << 102 = std::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setActivationToAll"), this); 120 "setActivationToAll", "Set activation to << 103 fSetHnActivationAllCmd->SetGuidance( 121 fSetActivationAllCmd->SetParameterName("Acti << 104 fHelper->Update("Set activation to all NDIM_D LOBJECTs")); >> 105 fSetHnActivationAllCmd->SetParameterName("Activation",false); 122 } 106 } 123 107 124 //____________________________________________ 108 //_____________________________________________________________________________ 125 void G4HnMessenger::SetHnPlottingCmd() 109 void G4HnMessenger::SetHnPlottingCmd() 126 { 110 { 127 fSetPlottingCmd = << 111 auto hnId = new G4UIparameter("id", 'i', false); 128 CreateCommand<G4UIcommand>("setPlotting", << 112 hnId->SetGuidance(fHelper->Update("OBJECT id")); 129 << 113 hnId->SetParameterRange("id>=0"); 130 AddIdParameter(*fSetPlottingCmd); << 114 131 AddOptionParameter(*fSetPlottingCmd, "hnPlot << 115 auto hnPlotting = new G4UIparameter("hnPlotting", 's', true); >> 116 hnPlotting->SetGuidance(fHelper->Update("(In)Activate OBJECT plotting")); >> 117 hnPlotting->SetDefaultValue("none"); >> 118 >> 119 fSetHnPlottingCmd >> 120 = std::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setPlotting"), this); >> 121 fSetHnPlottingCmd->SetGuidance( >> 122 fHelper->Update("(In)Activate batch plotting of the NDIM_D LOBJECT of given id")); >> 123 fSetHnPlottingCmd->SetParameter(hnId); >> 124 fSetHnPlottingCmd->SetParameter(hnPlotting); >> 125 fSetHnPlottingCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 132 } 126 } 133 127 134 //____________________________________________ 128 //_____________________________________________________________________________ 135 void G4HnMessenger::SetHnPlottingToAllCmd() 129 void G4HnMessenger::SetHnPlottingToAllCmd() 136 { 130 { 137 fSetPlottingAllCmd = << 131 fSetHnPlottingAllCmd 138 CreateCommand<G4UIcmdWithABool>( << 132 = std::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setPlottingToAll"), this); 139 "setPlottingToAll", "(In)Activate batch << 133 fSetHnPlottingAllCmd->SetGuidance( 140 fSetPlottingAllCmd->SetParameterName("Plotti << 134 fHelper->Update("(In)Activate batch plotting of all NDIM_D LOBJECTs")); >> 135 fSetHnPlottingAllCmd->SetParameterName("Plotting",false); 141 } 136 } 142 137 143 //____________________________________________ 138 //_____________________________________________________________________________ 144 void G4HnMessenger::SetHnFileNameCmd() 139 void G4HnMessenger::SetHnFileNameCmd() 145 { 140 { 146 fSetFileNameCmd = << 141 auto hnId = new G4UIparameter("id", 'i', false); 147 CreateCommand<G4UIcommand>("setFileName", << 142 hnId->SetGuidance(fHelper->Update("OBJECT id")); 148 << 143 hnId->SetParameterRange("id>=0"); 149 AddIdParameter(*fSetFileNameCmd); << 144 150 << 145 auto hnFileName = new G4UIparameter("hnFileName", 's', true); 151 auto param = new G4UIparameter("hnFileName", << 146 hnFileName->SetGuidance(fHelper->Update("OBJECT output file name")); 152 auto guidance = GetObjectType() + " output f << 147 hnFileName->SetDefaultValue("none"); 153 param->SetGuidance(guidance.c_str()); << 148 154 fSetFileNameCmd->SetParameter(param); << 149 fSetHnFileNameCmd >> 150 = std::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setFileName"), this); >> 151 fSetHnFileNameCmd->SetGuidance( >> 152 fHelper->Update("Set the NDIM_D LOBJECT of given id output file name")); >> 153 fSetHnFileNameCmd->SetParameter(hnId); >> 154 fSetHnFileNameCmd->SetParameter(hnFileName); >> 155 fSetHnFileNameCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 155 } 156 } 156 157 157 //____________________________________________ 158 //_____________________________________________________________________________ 158 void G4HnMessenger::SetHnFileNameToAllCmd() 159 void G4HnMessenger::SetHnFileNameToAllCmd() 159 { 160 { 160 fSetFileNameAllCmd = << 161 fSetHnFileNameAllCmd 161 CreateCommand<G4UIcmdWithAString>( << 162 = std::make_unique<G4UIcmdWithAString>(fHelper->Update("/analysis/HNTYPE_/setFileNameToAll"), this); 162 "setFileNameToAll", "Set output file nam << 163 fSetHnFileNameAllCmd->SetGuidance( 163 fSetFileNameAllCmd->SetParameterName("FileN << 164 fHelper->Update("Set output file name for all NDIM_D LOBJECTs")); 164 } << 165 fSetHnFileNameAllCmd->SetParameterName("FileName",false); 165 << 166 //____________________________________________ << 167 std::unique_ptr<G4UIcommand> << 168 G4HnMessenger::CreateSetAxisLogCommand(unsigne << 169 { << 170 G4String xyz{"XYZ"}; << 171 auto axis = xyz.substr(idim, 1); << 172 << 173 G4String commandName = "set" + axis + "axisL << 174 G4String guidance = "Activate " + axis + "- << 175 << 176 auto command = CreateCommand<G4UIcommand>(st << 177 command->AvailableForStates(G4State_PreInit, << 178 << 179 // Add Id parameter << 180 AddIdParameter(*command); << 181 << 182 auto parAxisLog = new G4UIparameter("axis", << 183 guidance = GetObjectType() + " " + std::move << 184 parAxisLog->SetGuidance(guidance.c_str()); << 185 command->SetParameter(parAxisLog); << 186 << 187 return command; << 188 } 166 } 189 167 190 // 168 // 191 // public methods 169 // public methods 192 // 170 // 193 171 194 //____________________________________________ 172 //_____________________________________________________________________________ 195 void G4HnMessenger::SetNewValue(G4UIcommand* c 173 void G4HnMessenger::SetNewValue(G4UIcommand* command, G4String newValues) 196 { 174 { 197 // process "All" commands first << 175 if ( command == fSetHnAsciiCmd.get() ) { 198 if ( command == fSetActivationAllCmd.get() ) << 176 auto id = fSetHnAsciiCmd->GetNewIntValue(newValues); 199 fManager.SetActivation(fSetActivationAllCm << 177 fManager.SetAscii(id, true); 200 return; << 178 } 201 } << 179 else if ( command == fSetHnActivationCmd.get() ) { 202 << 180 // tokenize parameters in a vector 203 if ( command == fSetPlottingAllCmd.get() ) { << 181 std::vector<G4String> parameters; 204 fManager.SetPlotting(fSetPlottingAllCmd->G << 182 G4Analysis::Tokenize(newValues, parameters); 205 return; << 183 // check consistency 206 } << 184 if ( parameters.size() == command->GetParameterEntries() ) { 207 << 185 auto counter = 0; 208 if ( command == fSetFileNameAllCmd.get() ) { << 186 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); 209 fManager.SetFileName(newValues); << 187 auto activation = G4UIcommand::ConvertToBool(parameters[counter++]); 210 return; << 188 fManager.SetActivation(id, activation); 211 } << 189 } 212 << 190 else { 213 // Tokenize parameters in a vector << 191 // Should never happen but let's check anyway for consistency 214 std::vector<G4String> parameters; << 192 fHelper->WarnAboutParameters(command, parameters.size()); 215 G4Analysis::Tokenize(newValues, parameters); << 193 } 216 // check consistency << 217 if ( parameters.size() != command->GetParame << 218 // Should never happen but let's check any << 219 G4Analysis::Warn( << 220 "Got wrong number of \"" + command->GetC << 221 "\" parameters: " + std::to_string(param << 222 " instead of " + std::to_string(command- << 223 fkClass, "WarnAboutParameters"); << 224 return; << 225 } << 226 << 227 auto counter = 0; << 228 auto id = G4UIcommand::ConvertToInt(paramete << 229 << 230 if ( command == fSetAsciiCmd.get() ) { << 231 fManager.SetAscii(id, G4UIcommand::Convert << 232 return; << 233 } << 234 << 235 if ( command == fSetActivationCmd.get() ) { << 236 fManager.SetActivation(id, G4UIcommand::Co << 237 return; << 238 } << 239 << 240 if ( command == fSetPlottingCmd.get() ) { << 241 fManager.SetPlotting(id, G4UIcommand::Conv << 242 return; << 243 } 194 } 244 << 195 else if ( command == fSetHnActivationAllCmd.get() ) { 245 if ( command == fSetFileNameCmd.get() ) { << 196 auto activation = fSetHnActivationAllCmd->GetNewBoolValue(newValues); 246 fManager.SetFileName(id, parameters[counte << 197 fManager.SetActivation(activation); 247 return; << 198 } >> 199 else if ( command == fSetHnPlottingCmd.get() ) { >> 200 // tokenize parameters in a vector >> 201 std::vector<G4String> parameters; >> 202 G4Analysis::Tokenize(newValues, parameters); >> 203 // check consistency >> 204 if ( parameters.size() == command->GetParameterEntries() ) { >> 205 auto counter = 0; >> 206 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); >> 207 auto activation = G4UIcommand::ConvertToBool(parameters[counter++]); >> 208 fManager.SetPlotting(id, activation); >> 209 } >> 210 else { >> 211 // Should never happen but let's check anyway for consistency >> 212 fHelper->WarnAboutParameters(command, parameters.size()); >> 213 } 248 } 214 } 249 << 215 else if ( command == fSetHnPlottingAllCmd.get() ) { 250 auto maxDim = (fHnDimension < kMaxDim) ? fHn << 216 auto activation = fSetHnPlottingAllCmd->GetNewBoolValue(newValues); 251 for (unsigned int idim = 0; idim < maxDim; + << 217 fManager.SetPlotting(activation); 252 if ( command == fSetAxisLogCmd[idim].get() << 218 } 253 auto axisLog = G4UIcommand::ConvertToBoo << 219 else if ( command == fSetHnFileNameCmd.get() ) { 254 fManager.SetAxisIsLog(idim, id, axisLog) << 220 // tokenize parameters in a vector 255 return; << 221 std::vector<G4String> parameters; >> 222 G4Analysis::Tokenize(newValues, parameters); >> 223 // check consistency >> 224 if ( parameters.size() == command->GetParameterEntries() ) { >> 225 auto counter = 0; >> 226 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); >> 227 auto fileName = parameters[counter++]; >> 228 fManager.SetFileName(id, fileName); >> 229 } >> 230 else { >> 231 // Should never happen but let's check anyway for consistency >> 232 fHelper->WarnAboutParameters(command, parameters.size()); 256 } 233 } >> 234 } >> 235 else if ( command == fSetHnFileNameAllCmd.get() ) { >> 236 auto fileName = newValues; >> 237 fManager.SetFileName(fileName); 257 } 238 } 258 } 239 } 259 240