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