source: trunk/examples/extended/electromagnetic/TestEm16/src/HistoMessenger.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 5.2 KB
RevLine 
[807]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//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
28//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29
30#include "HistoMessenger.hh"
31
32#include <sstream>
33
34#include "HistoManager.hh"
35#include "G4UIdirectory.hh"
36#include "G4UIcommand.hh"
37#include "G4UIparameter.hh"
38#include "G4UIcmdWithAString.hh"
39#include "G4UIcmdWithAnInteger.hh"
40
41//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42
43HistoMessenger::HistoMessenger(HistoManager* manager)
44:histoManager (manager)
45{
46 histoDir = new G4UIdirectory("/testem/histo/");
47 histoDir->SetGuidance("histograms control");
48
49 factoryCmd = new G4UIcmdWithAString("/testem/histo/setFileName",this);
50 factoryCmd->SetGuidance("set name for the histograms file");
51
52 typeCmd = new G4UIcmdWithAString("/testem/histo/setFileType",this);
53 typeCmd->SetGuidance("set histograms file type: hbook, root, XML");
54 typeCmd->SetCandidates("hbook root XML");
55
56 optionCmd = new G4UIcmdWithAString("/testem/histo/setFileOption",this);
57 optionCmd->SetGuidance("set option for the histograms file");
58
59 histoCmd = new G4UIcommand("/testem/histo/setHisto",this);
60 histoCmd->SetGuidance("Set bining of the histo number ih :");
61 histoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)");
62 //
63 G4UIparameter* ih = new G4UIparameter("ih",'i',false);
64 ih->SetGuidance("histo number : from 1 to MaxHisto");
65 ih->SetParameterRange("ih>0");
66 histoCmd->SetParameter(ih);
67 //
68 G4UIparameter* nbBins = new G4UIparameter("nbBins",'i',false);
69 nbBins->SetGuidance("number of bins");
70 nbBins->SetParameterRange("nbBins>0");
71 histoCmd->SetParameter(nbBins);
72 //
73 G4UIparameter* valMin = new G4UIparameter("valMin",'d',false);
74 valMin->SetGuidance("valMin, expressed in unit");
75 histoCmd->SetParameter(valMin);
76 //
77 G4UIparameter* valMax = new G4UIparameter("valMax",'d',false);
78 valMax->SetGuidance("valMax, expressed in unit");
79 histoCmd->SetParameter(valMax);
80 //
81 G4UIparameter* unit = new G4UIparameter("unit",'s',true);
82 unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless");
83 unit->SetDefaultValue("none");
84 histoCmd->SetParameter(unit);
85
86 rmhistoCmd = new G4UIcmdWithAnInteger("/testem/histo/removeHisto",this);
87 rmhistoCmd->SetGuidance("desactivate histo #id");
88 rmhistoCmd->SetParameterName("id",false);
89 rmhistoCmd->SetRange("id>0");
90}
91
92//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93
94HistoMessenger::~HistoMessenger()
95{
96 delete rmhistoCmd;
97 delete histoCmd;
98 delete optionCmd;
99 delete typeCmd;
100 delete factoryCmd;
101 delete histoDir;
102}
103
104//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105
106void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
107{
108 if (command == factoryCmd)
109 histoManager->SetFileName(newValues);
110
111 if (command == typeCmd)
112 histoManager->SetFileType(newValues);
113
114 if (command == optionCmd)
115 histoManager->SetFileOption(newValues);
116
117 if (command == histoCmd)
118 { G4int ih,nbBins; G4double vmin,vmax; char unts[30];
119 const char* t = newValues;
120 std::istringstream is(t);
121 is >> ih >> nbBins >> vmin >> vmax >> unts;
122 G4String unit = unts;
123 G4double vUnit = 1. ;
124 if (unit != "none") vUnit = G4UIcommand::ValueOf(unit);
125 histoManager->SetHisto (ih,nbBins,vmin*vUnit,vmax*vUnit,unit);
126 }
127
128 if (command == rmhistoCmd)
129 histoManager->RemoveHisto(rmhistoCmd->GetNewIntValue(newValues));
130}
131
132//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.