Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4PersistencyCenterMessenger implementation << 26 // File: G4PersistencyCenterMessenger.cc 27 // 27 // 28 // Author: Youhei Morita, 18.07.2001 << 28 // History: 29 // ------------------------------------------- << 29 // 01.07.18 Youhei Morita Initial creation (with "fadsclass") 30 30 31 #include "G4PersistencyCenterMessenger.hh" 31 #include "G4PersistencyCenterMessenger.hh" 32 32 33 // ------------------------------------------- << 33 // Implementation of Constructor #1 34 G4PersistencyCenterMessenger:: << 34 G4PersistencyCenterMessenger::G4PersistencyCenterMessenger(G4PersistencyCenter* p) 35 G4PersistencyCenterMessenger(G4PersistencyCent << 35 : pc(p) 36 : pc(p) << 37 { 36 { 38 G4String name = "/persistency/"; << 37 std::string name = "/persistency/"; 39 directory = new G4UIdirectory(name.c_ << 38 directory=new G4UIdirectory(name.c_str()); 40 directory->SetGuidance("Control commands for 39 directory->SetGuidance("Control commands for Persistency package"); 41 40 42 G4String cmd = name + "verbose"; << 41 std::string cmd = name + "verbose"; 43 42 44 verboseCmd = new G4UIcmdWithAnInteger(cmd.c_ << 43 verboseCmd = new G4UIcmdWithAnInteger(cmd.c_str(),this); 45 verboseCmd->SetGuidance("Set the verbose lev 44 verboseCmd->SetGuidance("Set the verbose level of G4PersistencyManager."); 46 verboseCmd->SetGuidance(" 0 : Silent (defaul 45 verboseCmd->SetGuidance(" 0 : Silent (default)"); 47 verboseCmd->SetGuidance(" 1 : Display main t 46 verboseCmd->SetGuidance(" 1 : Display main topics"); 48 verboseCmd->SetGuidance(" 2 : Display event- 47 verboseCmd->SetGuidance(" 2 : Display event-level topics"); 49 verboseCmd->SetGuidance(" 3 : Display debug 48 verboseCmd->SetGuidance(" 3 : Display debug information"); 50 verboseCmd->SetParameterName("level", true); << 49 verboseCmd->SetParameterName("level",true); 51 verboseCmd->SetDefaultValue(0); 50 verboseCmd->SetDefaultValue(0); 52 verboseCmd->SetRange("level >=0 && level <=3 51 verboseCmd->SetRange("level >=0 && level <=3"); 53 52 54 G4String vname = name + "select"; << 53 std::string vname = name + "select"; 55 54 56 cmd = vname; << 55 cmd = vname; 57 select = new G4UIcmdWithAString(cmd.c_str(), << 56 select = new G4UIcmdWithAString(cmd.c_str(),this); 58 select->SetGuidance("Selection of a persiste 57 select->SetGuidance("Selection of a persistency package"); 59 select->SetParameterName("Persistency packag 58 select->SetParameterName("Persistency package name", true, true); 60 select->SetCandidates("ODBMS ROOT None"); 59 select->SetCandidates("ODBMS ROOT None"); 61 60 62 vname = name + "store/"; 61 vname = name + "store/"; 63 62 64 subdir1 = new G4UIdirectory(vname.c_str()); 63 subdir1 = new G4UIdirectory(vname.c_str()); 65 subdir1->SetGuidance("Specifiy object types 64 subdir1->SetGuidance("Specifiy object types for store"); 66 65 67 wrObj.push_back("HepMC"); 66 wrObj.push_back("HepMC"); 68 wrObj.push_back("MCTruth"); 67 wrObj.push_back("MCTruth"); 69 wrObj.push_back("Hits"); 68 wrObj.push_back("Hits"); 70 69 71 G4String guidance; << 70 std::string guidance; 72 G4int i; << 71 int i; 73 72 74 for(i = 0; i < 3; ++i) << 73 for ( i = 0; i < 3; i++ ) 75 { 74 { 76 cmd = vname + wrObj[i]; << 75 cmd = vname + wrObj[i]; 77 guidance = "Store " + wrObj[i] + " objects 76 guidance = "Store " + wrObj[i] + " objects for output"; 78 storeObj.push_back(new G4UIcmdWithAString( << 77 storeObj.push_back(new G4UIcmdWithAString(cmd.c_str(),this)); 79 storeObj[i]->SetGuidance(guidance.c_str()) 78 storeObj[i]->SetGuidance(guidance.c_str()); 80 if(wrObj[i] == "HepMC") << 79 if ( wrObj[i] == "HepMC" ) { 81 { << 82 storeObj[i]->SetCandidates("on off recyc 80 storeObj[i]->SetCandidates("on off recycle"); 83 } << 81 } else { 84 else << 85 { << 86 storeObj[i]->SetCandidates("on off"); 82 storeObj[i]->SetCandidates("on off"); 87 } 83 } 88 } 84 } 89 85 90 vname += "using/"; 86 vname += "using/"; 91 subdir2 = new G4UIdirectory(vname.c_str()); 87 subdir2 = new G4UIdirectory(vname.c_str()); 92 subdir2->SetGuidance("Select I/O manager for 88 subdir2->SetGuidance("Select I/O manager for store"); 93 89 94 cmd = vname + "hitIO"; << 90 cmd = vname + "hitIO"; 95 regHitIO = new G4UIcmdWithAString(cmd.c_str( << 91 regHitIO = new G4UIcmdWithAString(cmd.c_str(),this); 96 regHitIO->SetGuidance("Resiter Hits I/O Mana 92 regHitIO->SetGuidance("Resiter Hits I/O Manager"); 97 regHitIO->SetParameterName("Name of Hits I/O 93 regHitIO->SetParameterName("Name of Hits I/O Manager", true, true); 98 94 99 vname = name + "set/"; << 95 vname = name + "set/"; 100 subdir3 = new G4UIdirectory(vname.c_str()); 96 subdir3 = new G4UIdirectory(vname.c_str()); 101 subdir3->SetGuidance("Set various parameters << 97 subdir3->SetGuidance("Set various parameters"); 102 98 103 vname += "writeFile/"; 99 vname += "writeFile/"; 104 subdir4 = new G4UIdirectory(vname.c_str()); 100 subdir4 = new G4UIdirectory(vname.c_str()); 105 subdir4->SetGuidance("Set output file names 101 subdir4->SetGuidance("Set output file names for object types"); 106 102 107 for(i = 0; i < 3; ++i) << 103 for ( i = 0; i < 3; i++ ) 108 { 104 { 109 cmd = vname + wrObj[i]; << 105 cmd = vname + wrObj[i]; 110 guidance = "Set an output file name for " 106 guidance = "Set an output file name for " + wrObj[i] + "."; 111 setWrFile.push_back(new G4UIcmdWithAString << 107 setWrFile.push_back(new G4UIcmdWithAString(cmd.c_str(),this)); 112 setWrFile[i]->SetGuidance(guidance.c_str() 108 setWrFile[i]->SetGuidance(guidance.c_str()); 113 setWrFile[i]->SetParameterName("file name" 109 setWrFile[i]->SetParameterName("file name", true, true); 114 } 110 } 115 111 116 vname = name + "set/ReadFile/"; << 112 vname = name + "set/ReadFile/"; 117 subdir5 = new G4UIdirectory(vname.c_str()); 113 subdir5 = new G4UIdirectory(vname.c_str()); 118 subdir5->SetGuidance("Set input file names f 114 subdir5->SetGuidance("Set input file names for object types"); 119 115 120 rdObj.push_back("Hits"); 116 rdObj.push_back("Hits"); 121 117 122 cmd = vname + rdObj[0]; << 118 cmd = vname + rdObj[0]; 123 guidance = "Set an input file name for " + r 119 guidance = "Set an input file name for " + rdObj[0] + "."; 124 setRdFile.push_back(new G4UIcmdWithAString(c << 120 setRdFile.push_back(new G4UIcmdWithAString(cmd.c_str(),this)); 125 setRdFile[0]->SetGuidance(guidance.c_str()); 121 setRdFile[0]->SetGuidance(guidance.c_str()); 126 setRdFile[0]->SetParameterName("file name", 122 setRdFile[0]->SetParameterName("file name", true, true); 127 123 128 cmd = name + "printall"; << 124 cmd = name + "printall"; 129 printAll = new G4UIcmdWithoutParameter(cmd.c << 125 printAll = new G4UIcmdWithoutParameter(cmd.c_str(),this); 130 printAll->SetGuidance("Print all parameters. 126 printAll->SetGuidance("Print all parameters."); >> 127 131 } 128 } 132 129 133 // ------------------------------------------- << 130 // Implementation of Destructor #1 134 G4PersistencyCenterMessenger::~G4PersistencyCe 131 G4PersistencyCenterMessenger::~G4PersistencyCenterMessenger() 135 { 132 { 136 delete directory; 133 delete directory; 137 delete subdir1; 134 delete subdir1; 138 delete subdir2; 135 delete subdir2; 139 delete subdir3; 136 delete subdir3; 140 delete subdir4; 137 delete subdir4; 141 delete subdir5; 138 delete subdir5; 142 delete verboseCmd; 139 delete verboseCmd; 143 delete select; 140 delete select; 144 delete regHitIO; 141 delete regHitIO; 145 for(G4int i = 0; i < 3; ++i) << 142 for ( int i = 0; i < 3; i++ ) 146 { 143 { 147 delete storeObj[i]; 144 delete storeObj[i]; 148 delete setWrFile[i]; 145 delete setWrFile[i]; 149 } 146 } 150 delete setRdFile[0]; 147 delete setRdFile[0]; 151 delete printAll; 148 delete printAll; 152 } 149 } 153 150 154 // ------------------------------------------- << 151 // Implementation of SetNewValue 155 void G4PersistencyCenterMessenger::SetNewValue << 152 void G4PersistencyCenterMessenger::SetNewValue(G4UIcommand* command, G4String newValues) 156 << 157 { 153 { 158 if(command == verboseCmd) << 154 if (command==verboseCmd) 159 { 155 { 160 pc->SetVerboseLevel(verboseCmd->GetNewIntV 156 pc->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues)); 161 } 157 } 162 else if(command == select) << 158 else if (command==select) 163 { 159 { 164 pc->SelectSystem(newValues); 160 pc->SelectSystem(newValues); 165 } 161 } 166 else if(command == regHitIO) << 162 else if (command==regHitIO) 167 { 163 { 168 pc->AddHCIOmanager(PopWord(newValues, 1, " << 164 pc->AddHCIOmanager(PopWord(newValues,1," "),PopWord(newValues,2," ")); 169 } 165 } 170 else if(command == setRdFile[0]) << 166 else if (command==setRdFile[0]) 171 { 167 { 172 pc->SetReadFile(rdObj[0], newValues); << 168 pc -> SetReadFile ( rdObj[0],newValues); 173 } 169 } 174 else if(command == printAll) << 170 else if (command==printAll) 175 { 171 { 176 pc->PrintAll(); 172 pc->PrintAll(); 177 } 173 } 178 else 174 else 179 { 175 { 180 for(G4int i = 0; i < 3; ++i) << 176 for( int i=0; i<3; i++ ) { 181 { << 177 if( command==storeObj[i] ) 182 if(command == storeObj[i]) << 183 { 178 { 184 StoreMode mode = kOff; 179 StoreMode mode = kOff; 185 if(newValues == "on") << 180 if( newValues == "on" ) { 186 { << 187 mode = kOn; 181 mode = kOn; 188 } << 182 } else if ( newValues == "off" ) { 189 else if(newValues == "off") << 190 { << 191 mode = kOff; 183 mode = kOff; 192 } << 184 } else if ( newValues == "recycle" ) { 193 else if(newValues == "recycle") << 194 { << 195 mode = kRecycle; 185 mode = kRecycle; >> 186 } else { >> 187 G4cerr << "Unrecognized keyword - \"" << newValues << "\"." >> 188 << G4endl; 196 } 189 } 197 else << 190 pc->SetStoreMode(wrObj[i],mode); 198 { << 199 G4cerr << "Unrecognized keyword - \" << 200 } << 201 pc->SetStoreMode(wrObj[i], mode); << 202 break; 191 break; 203 } 192 } 204 else if(command == setWrFile[i]) << 193 else if( command==setWrFile[i] ) 205 { 194 { 206 pc->SetWriteFile(wrObj[i], newValues); << 195 pc->SetWriteFile(wrObj[i],newValues); 207 break; 196 break; 208 } 197 } 209 } 198 } 210 } 199 } 211 } 200 } 212 201 213 // ------------------------------------------- << 202 // Implementation of GetCurrentValue 214 G4String G4PersistencyCenterMessenger::GetCurr 203 G4String G4PersistencyCenterMessenger::GetCurrentValue(G4UIcommand* command) 215 { 204 { 216 G4String ustr = "Undefined"; << 205 G4String ustr="Undefined"; 217 206 218 if(command == verboseCmd) << 207 if (command==select) 219 { 208 { 220 return G4UIcommand::ConvertToString(pc->Ve << 209 return pc->VerboseLevel(); 221 } 210 } 222 else if(command == select) << 211 else if (command==select) 223 { 212 { 224 return pc->CurrentSystem(); 213 return pc->CurrentSystem(); 225 } 214 } 226 else if(command == regHitIO) << 215 else if (command==regHitIO) 227 { 216 { 228 return pc->CurrentHCIOmanager(); 217 return pc->CurrentHCIOmanager(); 229 } 218 } 230 else if(command == setRdFile[0]) << 219 else if (command==setRdFile[0]) 231 { 220 { 232 return pc->CurrentReadFile(rdObj[0]); 221 return pc->CurrentReadFile(rdObj[0]); 233 } 222 } 234 else 223 else 235 { 224 { 236 for(G4int i = 0; i < 3; ++i) << 225 for( int i=0; i<3; i++ ) { 237 { << 226 if( command==storeObj[i] ) 238 if(command == storeObj[i]) << 239 { 227 { 240 switch(pc->CurrentStoreMode(wrObj[i])) << 228 switch (pc->CurrentStoreMode(wrObj[i])) { 241 { << 242 case kOn: 229 case kOn: 243 return "on"; 230 return "on"; 244 break; 231 break; 245 case kOff: 232 case kOff: 246 return "off"; 233 return "off"; 247 break; 234 break; 248 case kRecycle: 235 case kRecycle: 249 return "recycle"; 236 return "recycle"; 250 break; 237 break; 251 default: 238 default: 252 return "?????"; 239 return "?????"; 253 break; 240 break; 254 }; 241 }; 255 } 242 } 256 else if(command == setWrFile[i]) << 243 else if( command==setWrFile[i] ) 257 { 244 { 258 return pc->CurrentWriteFile(wrObj[i]); 245 return pc->CurrentWriteFile(wrObj[i]); 259 } 246 } 260 } 247 } 261 } 248 } 262 249 263 return ustr; 250 return ustr; 264 } 251 } 265 252 266 // ------------------------------------------- << 253 // Implementation of PopWord 267 G4String G4PersistencyCenterMessenger::PopWord << 254 std::string G4PersistencyCenterMessenger::PopWord(std::string text, int n, std::string delim) 268 << 269 { 255 { 270 if(text.length() <= 0) << 256 if ( text.length() <= 0 ) return ""; 271 return ""; << 257 int p = 0, p0 = 0; 272 std::size_t p = 0, p0 = 0; << 258 int p1 = 0; 273 std::size_t p1 = 0; << 259 for ( int i = 0; i < n; i++ ) { 274 for(G4int i = 0; i < n; ++i) << 260 p1 = text.find_first_of(delim,p0+1); 275 { << 261 while( p1 == p0+1 ) { 276 p1 = text.find_first_of(delim, p0 + 1); << 277 while(p1 == p0 + 1) << 278 { << 279 p0 = p1; 262 p0 = p1; 280 p1 = text.find_first_of(delim, p0 + 1); << 263 p1 = text.find_first_of(delim,p0+1); 281 } 264 } 282 p = p0; << 265 p = p0; 283 if(p1 == G4String::npos) << 266 if ( p1 < 0 ) { 284 { << 267 if ( i+1 < n ) return ""; 285 if(i + 1 < n) << 286 return ""; << 287 p1 = text.length(); 268 p1 = text.length(); 288 break; 269 break; 289 } 270 } 290 p0 = p1; 271 p0 = p1; 291 } 272 } 292 if(p > 0) << 273 if (p > 0) p++; 293 ++p; << 274 return text.substr(p,p1-p); 294 return text.substr(p, p1 - p); << 295 } 275 } >> 276 >> 277 // End of G4PersistencyCenterMessenger.cc >> 278 296 279