ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4HnMessenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4HnMessenger.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 
27 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
28 
29 #include "G4HnMessenger.hh"
30 #include "G4HnManager.hh"
31 #include "G4AnalysisUtilities.hh"
33 
34 #include "G4UIcommand.hh"
35 #include "G4UIparameter.hh"
36 #include "G4UIcmdWithAnInteger.hh"
37 #include "G4UIcmdWithABool.hh"
38 
39 using namespace G4Analysis;
40 
41 #include <iostream>
42 
44  : G4UImessenger(),
45  fManager(manager),
46  fHelper(nullptr),
47  fSetHnAsciiCmd(nullptr),
48  fSetHnActivationCmd(nullptr),
49  fSetHnActivationAllCmd(nullptr),
50  fSetHnPlottingCmd(nullptr),
51  fSetHnPlottingAllCmd(nullptr)
52 {
53  G4String hnType = fManager.GetHnType();
54  hnType.toLower();
55  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>(hnType);
56 
57  SetHnAsciiCmd();
62 }
63 
64 //_____________________________________________________________________________
66 {}
67 
68 //
69 // private functions
70 //
71 
72 //_____________________________________________________________________________
74 {
76  = G4Analysis::make_unique<G4UIcmdWithAnInteger>(fHelper->Update("/analysis/HNTYPE_/setAscii"), this);
77  fSetHnAsciiCmd->SetGuidance(
78  fHelper->Update("Print NDIM_D LOBJECT of given id on ascii file."));
79 
80  fSetHnAsciiCmd->SetParameterName("id",false);
81  fSetHnAsciiCmd->SetRange("id>=0");
82  fSetHnAsciiCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
83 }
84 
85 //_____________________________________________________________________________
87 {
88  auto hnId = new G4UIparameter("id", 'i', false);
89  hnId->SetGuidance(fHelper->Update("OBJECT id"));
90  hnId->SetParameterRange("id>=0");
91 
92  auto hnActivation = new G4UIparameter("hnActivation", 's', true);
93  hnActivation->SetGuidance(fHelper->Update("OBJECT activation"));
94  hnActivation->SetDefaultValue("none");
95 
97  = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setActivation"), this);
98  fSetHnActivationCmd->SetGuidance(
99  fHelper->Update("Set activation for the NDIM_D LOBJECT of given id"));
100  fSetHnActivationCmd->SetParameter(hnId);
101  fSetHnActivationCmd->SetParameter(hnActivation);
102  fSetHnActivationCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
103 }
104 
105 //_____________________________________________________________________________
107 {
109  = G4Analysis::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setActivationToAll"), this);
110  fSetHnActivationAllCmd->SetGuidance(
111  fHelper->Update("Set activation to all NDIM_D LOBJECTs"));
112  fSetHnActivationAllCmd->SetParameterName("Activation",false);
113 }
114 
115 //_____________________________________________________________________________
117 {
118  auto hnId = new G4UIparameter("id", 'i', false);
119  hnId->SetGuidance(fHelper->Update("OBJECT id"));
120  hnId->SetParameterRange("id>=0");
121 
122  auto hnPlotting = new G4UIparameter("hnPlotting", 's', true);
123  hnPlotting->SetGuidance(fHelper->Update("(In)Activate OBJECT plotting"));
124  hnPlotting->SetDefaultValue("none");
125 
127  = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setPlotting"), this);
128  fSetHnPlottingCmd->SetGuidance(
129  fHelper->Update("(In)Activate batch plotting of the NDIM_D LOBJECT of given id"));
130  fSetHnPlottingCmd->SetParameter(hnId);
131  fSetHnPlottingCmd->SetParameter(hnPlotting);
132  fSetHnPlottingCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
133 }
134 
135 //_____________________________________________________________________________
137 {
139  = G4Analysis::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setPlottingToAll"), this);
140  fSetHnPlottingAllCmd->SetGuidance(
141  fHelper->Update("(In)Activate batch plotting of all NDIM_D LOBJECTs"));
142  fSetHnPlottingAllCmd->SetParameterName("Plotting",false);
143 }
144 
145 //
146 // public methods
147 //
148 
149 //_____________________________________________________________________________
151 {
152  if ( command == fSetHnAsciiCmd.get() ) {
153  auto id = fSetHnAsciiCmd->GetNewIntValue(newValues);
154  fManager.SetAscii(id, true);
155  }
156  else if ( command == fSetHnActivationCmd.get() ) {
157  // tokenize parameters in a vector
158  std::vector<G4String> parameters;
159  G4Analysis::Tokenize(newValues, parameters);
160  // check consistency
161  if ( parameters.size() == command->GetParameterEntries() ) {
162  auto counter = 0;
163  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
164  auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
165  fManager.SetActivation(id, activation);
166  }
167  else {
168  // Should never happen but let's check anyway for consistency
169  fHelper->WarnAboutParameters(command, parameters.size());
170  }
171  }
172  else if ( command == fSetHnActivationAllCmd.get() ) {
173  auto activation = fSetHnActivationAllCmd->GetNewBoolValue(newValues);
174  fManager.SetActivation(activation);
175  }
176  else if ( command == fSetHnPlottingCmd.get() ) {
177  // tokenize parameters in a vector
178  std::vector<G4String> parameters;
179  G4Analysis::Tokenize(newValues, parameters);
180  // check consistency
181  if ( parameters.size() == command->GetParameterEntries() ) {
182  auto counter = 0;
183  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
184  auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
185  fManager.SetPlotting(id, activation);
186  }
187  else {
188  // Should never happen but let's check anyway for consistency
189  fHelper->WarnAboutParameters(command, parameters.size());
190  }
191  }
192  else if ( command == fSetHnPlottingAllCmd.get() ) {
193  auto activation = fSetHnPlottingAllCmd->GetNewBoolValue(newValues);
194  fManager.SetPlotting(activation);
195  }
196 }