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 //____________________________________________ << 42 #include <iostream> >> 43 41 G4HnMessenger::G4HnMessenger(G4HnManager& mana 44 G4HnMessenger::G4HnMessenger(G4HnManager& manager) 42 : fManager(manager), << 45 : G4UImessenger(), 43 fHnType(manager.GetHnType()), << 46 fManager(manager), 44 fHnDimension(std::stoi(manager.GetHnType() << 47 fHelper(nullptr), 45 { << 48 fSetHnAsciiCmd(nullptr), >> 49 fSetHnActivationCmd(nullptr), >> 50 fSetHnActivationAllCmd(nullptr), >> 51 fSetHnPlottingCmd(nullptr), >> 52 fSetHnPlottingAllCmd(nullptr), >> 53 fSetHnFileNameCmd(nullptr), >> 54 fSetHnFileNameAllCmd(nullptr) >> 55 { >> 56 G4String hnType = fManager.GetHnType(); >> 57 hnType.toLower(); >> 58 fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>(hnType); >> 59 46 SetHnAsciiCmd(); 60 SetHnAsciiCmd(); 47 SetHnActivationCmd(); 61 SetHnActivationCmd(); 48 SetHnActivationToAllCmd(); 62 SetHnActivationToAllCmd(); 49 SetHnPlottingCmd(); 63 SetHnPlottingCmd(); 50 SetHnPlottingToAllCmd(); 64 SetHnPlottingToAllCmd(); 51 SetHnFileNameCmd(); 65 SetHnFileNameCmd(); 52 SetHnFileNameToAllCmd(); 66 SetHnFileNameToAllCmd(); 53 << 54 auto maxDim = (fHnDimension < kMaxDim) ? fHn << 55 for (unsigned int idim = 0; idim < maxDim; + << 56 fSetAxisLogCmd.push_back(CreateSetAxisLogC << 57 } << 58 } 67 } 59 68 60 //____________________________________________ 69 //_____________________________________________________________________________ 61 G4HnMessenger::~G4HnMessenger() = default; << 70 G4HnMessenger::~G4HnMessenger() >> 71 {} 62 72 63 // 73 // 64 // private functions 74 // private functions 65 // 75 // 66 76 67 //____________________________________________ 77 //_____________________________________________________________________________ 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() 78 void G4HnMessenger::SetHnAsciiCmd() 96 { 79 { 97 fSetAsciiCmd = << 80 fSetHnAsciiCmd 98 CreateCommand<G4UIcommand>("setAscii", "Pr << 81 = G4Analysis::make_unique<G4UIcmdWithAnInteger>(fHelper->Update("/analysis/HNTYPE_/setAscii"), this); 99 << 82 fSetHnAsciiCmd->SetGuidance( 100 AddIdParameter(*fSetAsciiCmd); << 83 fHelper->Update("Print NDIM_D LOBJECT of given id on ascii file.")); 101 AddOptionParameter(*fSetAsciiCmd, "hnAscii") << 84 102 << 85 fSetHnAsciiCmd->SetParameterName("id",false); >> 86 fSetHnAsciiCmd->SetRange("id>=0"); >> 87 fSetHnAsciiCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 103 } 88 } 104 89 105 //____________________________________________ 90 //_____________________________________________________________________________ 106 void G4HnMessenger::SetHnActivationCmd() 91 void G4HnMessenger::SetHnActivationCmd() 107 { 92 { 108 fSetActivationCmd = << 93 auto hnId = new G4UIparameter("id", 'i', false); 109 CreateCommand<G4UIcommand>("setActivation" << 94 hnId->SetGuidance(fHelper->Update("OBJECT id")); 110 << 95 hnId->SetParameterRange("id>=0"); 111 AddIdParameter(*fSetActivationCmd); << 96 112 AddOptionParameter(*fSetActivationCmd, "hnAc << 97 auto hnActivation = new G4UIparameter("hnActivation", 's', true); 113 } << 98 hnActivation->SetGuidance(fHelper->Update("OBJECT activation")); >> 99 hnActivation->SetDefaultValue("none"); >> 100 >> 101 fSetHnActivationCmd >> 102 = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setActivation"), this); >> 103 fSetHnActivationCmd->SetGuidance( >> 104 fHelper->Update("Set activation for the NDIM_D LOBJECT of given id")); >> 105 fSetHnActivationCmd->SetParameter(hnId); >> 106 fSetHnActivationCmd->SetParameter(hnActivation); >> 107 fSetHnActivationCmd->AvailableForStates(G4State_PreInit, G4State_Idle); >> 108 } 114 109 115 //____________________________________________ 110 //_____________________________________________________________________________ 116 void G4HnMessenger::SetHnActivationToAllCmd() 111 void G4HnMessenger::SetHnActivationToAllCmd() 117 { 112 { 118 fSetActivationAllCmd = << 113 fSetHnActivationAllCmd 119 CreateCommand<G4UIcmdWithABool>( << 114 = G4Analysis::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setActivationToAll"), this); 120 "setActivationToAll", "Set activation to << 115 fSetHnActivationAllCmd->SetGuidance( 121 fSetActivationAllCmd->SetParameterName("Acti << 116 fHelper->Update("Set activation to all NDIM_D LOBJECTs")); 122 } << 117 fSetHnActivationAllCmd->SetParameterName("Activation",false); 123 << 118 } >> 119 124 //____________________________________________ 120 //_____________________________________________________________________________ 125 void G4HnMessenger::SetHnPlottingCmd() 121 void G4HnMessenger::SetHnPlottingCmd() 126 { 122 { 127 fSetPlottingCmd = << 123 auto hnId = new G4UIparameter("id", 'i', false); 128 CreateCommand<G4UIcommand>("setPlotting", << 124 hnId->SetGuidance(fHelper->Update("OBJECT id")); 129 << 125 hnId->SetParameterRange("id>=0"); 130 AddIdParameter(*fSetPlottingCmd); << 126 131 AddOptionParameter(*fSetPlottingCmd, "hnPlot << 127 auto hnPlotting = new G4UIparameter("hnPlotting", 's', true); 132 } << 128 hnPlotting->SetGuidance(fHelper->Update("(In)Activate OBJECT plotting")); >> 129 hnPlotting->SetDefaultValue("none"); >> 130 >> 131 fSetHnPlottingCmd >> 132 = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setPlotting"), this); >> 133 fSetHnPlottingCmd->SetGuidance( >> 134 fHelper->Update("(In)Activate batch plotting of the NDIM_D LOBJECT of given id")); >> 135 fSetHnPlottingCmd->SetParameter(hnId); >> 136 fSetHnPlottingCmd->SetParameter(hnPlotting); >> 137 fSetHnPlottingCmd->AvailableForStates(G4State_PreInit, G4State_Idle); >> 138 } 133 139 134 //____________________________________________ 140 //_____________________________________________________________________________ 135 void G4HnMessenger::SetHnPlottingToAllCmd() 141 void G4HnMessenger::SetHnPlottingToAllCmd() 136 { 142 { 137 fSetPlottingAllCmd = << 143 fSetHnPlottingAllCmd 138 CreateCommand<G4UIcmdWithABool>( << 144 = G4Analysis::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setPlottingToAll"), this); 139 "setPlottingToAll", "(In)Activate batch << 145 fSetHnPlottingAllCmd->SetGuidance( 140 fSetPlottingAllCmd->SetParameterName("Plotti << 146 fHelper->Update("(In)Activate batch plotting of all NDIM_D LOBJECTs")); 141 } << 147 fSetHnPlottingAllCmd->SetParameterName("Plotting",false); >> 148 } 142 149 143 //____________________________________________ 150 //_____________________________________________________________________________ 144 void G4HnMessenger::SetHnFileNameCmd() 151 void G4HnMessenger::SetHnFileNameCmd() 145 { 152 { 146 fSetFileNameCmd = << 153 auto hnId = new G4UIparameter("id", 'i', false); 147 CreateCommand<G4UIcommand>("setFileName", << 154 hnId->SetGuidance(fHelper->Update("OBJECT id")); 148 << 155 hnId->SetParameterRange("id>=0"); 149 AddIdParameter(*fSetFileNameCmd); << 156 150 << 157 auto hnFileName = new G4UIparameter("hnFileName", 's', true); 151 auto param = new G4UIparameter("hnFileName", << 158 hnFileName->SetGuidance(fHelper->Update("OBJECT output file name")); 152 auto guidance = GetObjectType() + " output f << 159 hnFileName->SetDefaultValue("none"); 153 param->SetGuidance(guidance.c_str()); << 160 154 fSetFileNameCmd->SetParameter(param); << 161 fSetHnFileNameCmd >> 162 = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setFileName"), this); >> 163 fSetHnFileNameCmd->SetGuidance( >> 164 fHelper->Update("Set the NDIM_D LOBJECT of given id output file name")); >> 165 fSetHnFileNameCmd->SetParameter(hnId); >> 166 fSetHnFileNameCmd->SetParameter(hnFileName); >> 167 fSetHnFileNameCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 155 } 168 } 156 169 157 //____________________________________________ 170 //_____________________________________________________________________________ 158 void G4HnMessenger::SetHnFileNameToAllCmd() 171 void G4HnMessenger::SetHnFileNameToAllCmd() 159 { 172 { 160 fSetFileNameAllCmd = << 173 fSetHnFileNameAllCmd 161 CreateCommand<G4UIcmdWithAString>( << 174 = G4Analysis::make_unique<G4UIcmdWithAString>(fHelper->Update("/analysis/HNTYPE_/setFileNameToAll"), this); 162 "setFileNameToAll", "Set output file nam << 175 fSetHnFileNameAllCmd->SetGuidance( 163 fSetFileNameAllCmd->SetParameterName("FileN << 176 fHelper->Update("Set output file name for all NDIM_D LOBJECTs")); 164 } << 177 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 } 178 } 189 179 190 // 180 // 191 // public methods 181 // public methods 192 // 182 // 193 183 194 //____________________________________________ 184 //_____________________________________________________________________________ 195 void G4HnMessenger::SetNewValue(G4UIcommand* c 185 void G4HnMessenger::SetNewValue(G4UIcommand* command, G4String newValues) 196 { 186 { 197 // process "All" commands first << 187 if ( command == fSetHnAsciiCmd.get() ) { 198 if ( command == fSetActivationAllCmd.get() ) << 188 auto id = fSetHnAsciiCmd->GetNewIntValue(newValues); 199 fManager.SetActivation(fSetActivationAllCm << 189 fManager.SetAscii(id, true); 200 return; << 190 } 201 } << 191 else if ( command == fSetHnActivationCmd.get() ) { 202 << 192 // tokenize parameters in a vector 203 if ( command == fSetPlottingAllCmd.get() ) { << 193 std::vector<G4String> parameters; 204 fManager.SetPlotting(fSetPlottingAllCmd->G << 194 G4Analysis::Tokenize(newValues, parameters); 205 return; << 195 // check consistency 206 } << 196 if ( parameters.size() == command->GetParameterEntries() ) { 207 << 197 auto counter = 0; 208 if ( command == fSetFileNameAllCmd.get() ) { << 198 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); 209 fManager.SetFileName(newValues); << 199 auto activation = G4UIcommand::ConvertToBool(parameters[counter++]); 210 return; << 200 fManager.SetActivation(id, activation); 211 } << 201 } 212 << 202 else { 213 // Tokenize parameters in a vector << 203 // Should never happen but let's check anyway for consistency 214 std::vector<G4String> parameters; << 204 fHelper->WarnAboutParameters(command, parameters.size()); 215 G4Analysis::Tokenize(newValues, parameters); << 205 } 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 } 206 } 244 << 207 else if ( command == fSetHnActivationAllCmd.get() ) { 245 if ( command == fSetFileNameCmd.get() ) { << 208 auto activation = fSetHnActivationAllCmd->GetNewBoolValue(newValues); 246 fManager.SetFileName(id, parameters[counte << 209 fManager.SetActivation(activation); 247 return; << 210 } >> 211 else if ( command == fSetHnPlottingCmd.get() ) { >> 212 // tokenize parameters in a vector >> 213 std::vector<G4String> parameters; >> 214 G4Analysis::Tokenize(newValues, parameters); >> 215 // check consistency >> 216 if ( parameters.size() == command->GetParameterEntries() ) { >> 217 auto counter = 0; >> 218 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); >> 219 auto activation = G4UIcommand::ConvertToBool(parameters[counter++]); >> 220 fManager.SetPlotting(id, activation); >> 221 } >> 222 else { >> 223 // Should never happen but let's check anyway for consistency >> 224 fHelper->WarnAboutParameters(command, parameters.size()); >> 225 } 248 } 226 } 249 << 227 else if ( command == fSetHnPlottingAllCmd.get() ) { 250 auto maxDim = (fHnDimension < kMaxDim) ? fHn << 228 auto activation = fSetHnPlottingAllCmd->GetNewBoolValue(newValues); 251 for (unsigned int idim = 0; idim < maxDim; + << 229 fManager.SetPlotting(activation); 252 if ( command == fSetAxisLogCmd[idim].get() << 230 } 253 auto axisLog = G4UIcommand::ConvertToBoo << 231 else if ( command == fSetHnFileNameCmd.get() ) { 254 fManager.SetAxisIsLog(idim, id, axisLog) << 232 // tokenize parameters in a vector 255 return; << 233 std::vector<G4String> parameters; >> 234 G4Analysis::Tokenize(newValues, parameters); >> 235 // check consistency >> 236 if ( parameters.size() == command->GetParameterEntries() ) { >> 237 auto counter = 0; >> 238 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); >> 239 auto fileName = parameters[counter++]; >> 240 fManager.SetFileName(id, fileName); >> 241 } >> 242 else { >> 243 // Should never happen but let's check anyway for consistency >> 244 fHelper->WarnAboutParameters(command, parameters.size()); 256 } 245 } >> 246 } >> 247 else if ( command == fSetHnFileNameAllCmd.get() ) { >> 248 auto fileName = newValues; >> 249 fManager.SetFileName(fileName); 257 } 250 } 258 } 251 } 259 252