Geant4_10
HistoMessenger.cc
Go to the documentation of this file.
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 // $Id: HistoMessenger.cc 68740 2013-04-05 09:56:39Z gcosmo $
27 //
28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30 
31 #include "HistoMessenger.hh"
32 
33 #include <sstream>
34 
35 #include "HistoManager.hh"
36 #include "G4UIdirectory.hh"
37 #include "G4UIcommand.hh"
38 #include "G4UIparameter.hh"
39 #include "G4UIcmdWithAString.hh"
40 #include "G4UIcmdWithAnInteger.hh"
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 
45 :histoManager (manager)
46 {
47  histoDir = new G4UIdirectory("/ams/histo/");
48  histoDir->SetGuidance("histograms control");
49 
50  factoryCmd = new G4UIcmdWithAString("/ams/histo/setFileName",this);
51  factoryCmd->SetGuidance("set name for the histograms file");
52 
53  typeCmd = new G4UIcmdWithAString("/ams/histo/setFileType",this);
54  typeCmd->SetGuidance("set histograms file type: hbook, root, XML");
55  typeCmd->SetCandidates("hbook root XML");
56 
57  optionCmd = new G4UIcmdWithAString("/ams/histo/setFileOption",this);
58  optionCmd->SetGuidance("set option for the histograms file");
59 
60  histoCmd = new G4UIcommand("/ams/histo/setHisto",this);
61  histoCmd->SetGuidance("Set bining of the histo number ih :");
62  histoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)");
63  //
64  G4UIparameter* ih = new G4UIparameter("ih",'i',false);
65  ih->SetGuidance("histo number : from 1 to MaxHisto-1");
66  ih->SetParameterRange("ih>0");
67  histoCmd->SetParameter(ih);
68  //
69  G4UIparameter* nbBins = new G4UIparameter("nbBins",'i',false);
70  nbBins->SetGuidance("number of bins");
71  nbBins->SetParameterRange("nbBins>0");
72  histoCmd->SetParameter(nbBins);
73  //
74  G4UIparameter* valMin = new G4UIparameter("valMin",'d',false);
75  valMin->SetGuidance("valMin, expressed in choosen unit");
76  histoCmd->SetParameter(valMin);
77  //
78  G4UIparameter* valMax = new G4UIparameter("valMax",'d',false);
79  valMax->SetGuidance("valMax, expressed in choosen unit");
80  histoCmd->SetParameter(valMax);
81  //
82  G4UIparameter* unit = new G4UIparameter("unit",'s',true);
83  unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless");
84  unit->SetDefaultValue("none");
85  histoCmd->SetParameter(unit);
86 
87  prhistoCmd = new G4UIcmdWithAnInteger("/ams/histo/printHisto",this);
88  prhistoCmd->SetGuidance("print histo #id on ascii file");
89  prhistoCmd->SetParameterName("id",false);
90  prhistoCmd->SetRange("id>0");
91 
92  rmhistoCmd = new G4UIcmdWithAnInteger("/ams/histo/removeHisto",this);
93  rmhistoCmd->SetGuidance("desactivate histo #id");
94  rmhistoCmd->SetParameterName("id",false);
95  rmhistoCmd->SetRange("id>0");
96 
97  ntuplCmd = new G4UIcmdWithAnInteger("/ams/histo/setNtuple",this);
98  ntuplCmd->SetGuidance("set nTuple #id");
99  ntuplCmd->SetParameterName("id",false);
100  ntuplCmd->SetRange("id>0");
101 }
102 
103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
104 
106 {
107  delete rmhistoCmd;
108  delete prhistoCmd;
109  delete histoCmd;
110  delete ntuplCmd;
111  delete optionCmd;
112  delete typeCmd;
113  delete factoryCmd;
114  delete histoDir;
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118 
120 {
121  if (command == factoryCmd)
122  histoManager->SetFileName(newValues);
123 
124  if (command == typeCmd)
125  histoManager->SetFileType(newValues);
126 
127  if (command == optionCmd)
128  histoManager->SetFileOption(newValues);
129 
130  if (command == histoCmd)
131  { G4int ih,nbBins; G4double vmin,vmax;
132  std::istringstream is(newValues);
133  G4String unts;
134  is >> ih >> nbBins >> vmin >> vmax >> unts;
135  G4String unit = unts;
136  G4double vUnit = 1. ;
137  if (unit != "none") vUnit = G4UIcommand::ValueOf(unit);
138  histoManager->SetHisto (ih,nbBins,vmin*vUnit,vmax*vUnit,unit);
139  }
140 
141  if (command == prhistoCmd)
142  histoManager->PrintHisto(prhistoCmd->GetNewIntValue(newValues));
143 
144  if (command == rmhistoCmd)
145  { histoManager->RemoveHisto(rmhistoCmd->GetNewIntValue(newValues));}
146 
147  if (command == ntuplCmd)
148  { histoManager->SetNtuple(ntuplCmd->GetNewIntValue(newValues));}
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152 
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetNewValue(G4UIcommand *, G4String)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
void SetDefaultValue(const char *theDefaultValue)
void SetFileType(const G4String &name)
Definition: HistoManager.hh:59
int G4int
Definition: G4Types.hh:78
HistoMessenger(HistoManager *)
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetHisto(G4int, G4int, G4double, G4double, const G4String &unit="none")
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:294
void SetFileOption(const G4String &name)
Definition: HistoManager.hh:60
void SetFileName(const G4String &name)
Definition: HistoManager.hh:58
void SetCandidates(const char *candidateList)
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
void RemoveHisto(G4int)
void PrintHisto(G4int)
void SetNtuple(G4int)