Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PersistencyCenterMessenger.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// G4PersistencyCenterMessenger implementation
27//
28// Author: Youhei Morita, 18.07.2001
29// --------------------------------------------------------------------
30
32
33// --------------------------------------------------------------------
36 : pc(p)
37{
38 G4String name = "/persistency/";
39 directory = new G4UIdirectory(name.c_str());
40 directory->SetGuidance("Control commands for Persistency package");
41
42 G4String cmd = name + "verbose";
43
44 verboseCmd = new G4UIcmdWithAnInteger(cmd.c_str(), this);
45 verboseCmd->SetGuidance("Set the verbose level of G4PersistencyManager.");
46 verboseCmd->SetGuidance(" 0 : Silent (default)");
47 verboseCmd->SetGuidance(" 1 : Display main topics");
48 verboseCmd->SetGuidance(" 2 : Display event-level topics");
49 verboseCmd->SetGuidance(" 3 : Display debug information");
50 verboseCmd->SetParameterName("level", true);
51 verboseCmd->SetDefaultValue(0);
52 verboseCmd->SetRange("level >=0 && level <=3");
53
54 G4String vname = name + "select";
55
56 cmd = vname;
57 select = new G4UIcmdWithAString(cmd.c_str(), this);
58 select->SetGuidance("Selection of a persistency package");
59 select->SetParameterName("Persistency package name", true, true);
60 select->SetCandidates("ODBMS ROOT None");
61
62 vname = name + "store/";
63
64 subdir1 = new G4UIdirectory(vname.c_str());
65 subdir1->SetGuidance("Specifiy object types for store");
66
67 wrObj.push_back("HepMC");
68 wrObj.push_back("MCTruth");
69 wrObj.push_back("Hits");
70
71 G4String guidance;
72 G4int i;
73
74 for(i = 0; i < 3; ++i)
75 {
76 cmd = vname + wrObj[i];
77 guidance = "Store " + wrObj[i] + " objects for output";
78 storeObj.push_back(new G4UIcmdWithAString(cmd.c_str(), this));
79 storeObj[i]->SetGuidance(guidance.c_str());
80 if(wrObj[i] == "HepMC")
81 {
82 storeObj[i]->SetCandidates("on off recycle");
83 }
84 else
85 {
86 storeObj[i]->SetCandidates("on off");
87 }
88 }
89
90 vname += "using/";
91 subdir2 = new G4UIdirectory(vname.c_str());
92 subdir2->SetGuidance("Select I/O manager for store");
93
94 cmd = vname + "hitIO";
95 regHitIO = new G4UIcmdWithAString(cmd.c_str(), this);
96 regHitIO->SetGuidance("Resiter Hits I/O Manager");
97 regHitIO->SetParameterName("Name of Hits I/O Manager", true, true);
98
99 vname = name + "set/";
100 subdir3 = new G4UIdirectory(vname.c_str());
101 subdir3->SetGuidance("Set various parameters");
102
103 vname += "writeFile/";
104 subdir4 = new G4UIdirectory(vname.c_str());
105 subdir4->SetGuidance("Set output file names for object types");
106
107 for(i = 0; i < 3; ++i)
108 {
109 cmd = vname + wrObj[i];
110 guidance = "Set an output file name for " + wrObj[i] + ".";
111 setWrFile.push_back(new G4UIcmdWithAString(cmd.c_str(), this));
112 setWrFile[i]->SetGuidance(guidance.c_str());
113 setWrFile[i]->SetParameterName("file name", true, true);
114 }
115
116 vname = name + "set/ReadFile/";
117 subdir5 = new G4UIdirectory(vname.c_str());
118 subdir5->SetGuidance("Set input file names for object types");
119
120 rdObj.push_back("Hits");
121
122 cmd = vname + rdObj[0];
123 guidance = "Set an input file name for " + rdObj[0] + ".";
124 setRdFile.push_back(new G4UIcmdWithAString(cmd.c_str(), this));
125 setRdFile[0]->SetGuidance(guidance.c_str());
126 setRdFile[0]->SetParameterName("file name", true, true);
127
128 cmd = name + "printall";
129 printAll = new G4UIcmdWithoutParameter(cmd.c_str(), this);
130 printAll->SetGuidance("Print all parameters.");
131}
132
133// --------------------------------------------------------------------
135{
136 delete directory;
137 delete subdir1;
138 delete subdir2;
139 delete subdir3;
140 delete subdir4;
141 delete subdir5;
142 delete verboseCmd;
143 delete select;
144 delete regHitIO;
145 for(G4int i = 0; i < 3; ++i)
146 {
147 delete storeObj[i];
148 delete setWrFile[i];
149 }
150 delete setRdFile[0];
151 delete printAll;
152}
153
154// --------------------------------------------------------------------
156 G4String newValues)
157{
158 if(command == verboseCmd)
159 {
160 pc->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues));
161 }
162 else if(command == select)
163 {
164 pc->SelectSystem(newValues);
165 }
166 else if(command == regHitIO)
167 {
168 pc->AddHCIOmanager(PopWord(newValues, 1, " "), PopWord(newValues, 2, " "));
169 }
170 else if(command == setRdFile[0])
171 {
172 pc->SetReadFile(rdObj[0], newValues);
173 }
174 else if(command == printAll)
175 {
176 pc->PrintAll();
177 }
178 else
179 {
180 for(G4int i = 0; i < 3; ++i)
181 {
182 if(command == storeObj[i])
183 {
184 StoreMode mode = kOff;
185 if(newValues == "on")
186 {
187 mode = kOn;
188 }
189 else if(newValues == "off")
190 {
191 mode = kOff;
192 }
193 else if(newValues == "recycle")
194 {
195 mode = kRecycle;
196 }
197 else
198 {
199 G4cerr << "Unrecognized keyword - \"" << newValues << "\"." << G4endl;
200 }
201 pc->SetStoreMode(wrObj[i], mode);
202 break;
203 }
204 else if(command == setWrFile[i])
205 {
206 pc->SetWriteFile(wrObj[i], newValues);
207 break;
208 }
209 }
210 }
211}
212
213// --------------------------------------------------------------------
215{
216 G4String ustr = "Undefined";
217
218 if(command == verboseCmd)
219 {
220 return G4UIcommand::ConvertToString(pc->VerboseLevel());
221 }
222 else if(command == select)
223 {
224 return pc->CurrentSystem();
225 }
226 else if(command == regHitIO)
227 {
228 return pc->CurrentHCIOmanager();
229 }
230 else if(command == setRdFile[0])
231 {
232 return pc->CurrentReadFile(rdObj[0]);
233 }
234 else
235 {
236 for(G4int i = 0; i < 3; ++i)
237 {
238 if(command == storeObj[i])
239 {
240 switch(pc->CurrentStoreMode(wrObj[i]))
241 {
242 case kOn:
243 return "on";
244 break;
245 case kOff:
246 return "off";
247 break;
248 case kRecycle:
249 return "recycle";
250 break;
251 default:
252 return "?????";
253 break;
254 };
255 }
256 else if(command == setWrFile[i])
257 {
258 return pc->CurrentWriteFile(wrObj[i]);
259 }
260 }
261 }
262
263 return ustr;
264}
265
266// --------------------------------------------------------------------
267G4String G4PersistencyCenterMessenger::PopWord(const G4String& text, G4int n,
268 const G4String& delim)
269{
270 if(text.length() <= 0)
271 return "";
272 std::size_t p = 0, p0 = 0;
273 std::size_t p1 = 0;
274 for(G4int i = 0; i < n; ++i)
275 {
276 p1 = text.find_first_of(delim, p0 + 1);
277 while(p1 == p0 + 1)
278 {
279 p0 = p1;
280 p1 = text.find_first_of(delim, p0 + 1);
281 }
282 p = p0;
283 if(p1 == G4String::npos)
284 {
285 if(i + 1 < n)
286 return "";
287 p1 = text.length();
288 break;
289 }
290 p0 = p1;
291 }
292 if(p > 0)
293 ++p;
294 return text.substr(p, p1 - p);
295}
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
void SetNewValue(G4UIcommand *command, G4String newValues)
G4String GetCurrentValue(G4UIcommand *command)
G4PersistencyCenterMessenger(G4PersistencyCenter *p)
void SetCandidates(const char *candidateList)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetDefaultValue(G4int defVal)
static G4String ConvertToString(G4bool boolVal)
void SetGuidance(const char *aGuidance)
void SetRange(const char *rs)