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 // $Id: G4HepRepMessenger.cc,v 1.13 2010-06-21 04:43:07 perl Exp $ >> 27 // GEANT4 tag $Name: not supported by cvs2svn $ 26 // 28 // 27 #include "G4HepRepMessenger.hh" 29 #include "G4HepRepMessenger.hh" 28 30 29 G4HepRepMessenger* G4HepRepMessenger::fpInstan << 31 G4HepRepMessenger* >> 32 G4HepRepMessenger::fpInstance = 0; 30 33 31 G4HepRepMessenger* G4HepRepMessenger::GetInsta << 34 G4HepRepMessenger* >> 35 G4HepRepMessenger::GetInstance() 32 { 36 { 33 if(!fpInstance) << 37 if (!fpInstance) fpInstance = new G4HepRepMessenger; 34 fpInstance = new G4HepRepMessenger; << 38 return fpInstance; 35 return fpInstance; << 39 } 36 } << 37 << 38 G4HepRepMessenger::G4HepRepMessenger() << 39 : fileDir("") << 40 , fileName("G4Data") << 41 , overwrite(false) << 42 , cullInvisibles(false) << 43 , cylAsPolygons(false) << 44 , scale(1.) << 45 , suffix("") << 46 , geometry(true) << 47 , pointAttributes(false) << 48 , solids(true) << 49 , invisibles(true) << 50 { << 51 heprepDirectory = new G4UIdirectory("/vis/he << 52 heprepDirectory->SetGuidance("HepRep command << 53 40 54 setFileDirCommand = new G4UIcmdWithAString(" << 41 G4HepRepMessenger::G4HepRepMessenger() : 55 setFileDirCommand->SetGuidance("Set director << 42 fileDir(""), 56 setFileDirCommand->SetGuidance( << 43 fileName("G4Data"), 57 "This command is used by HepRepFile, not b << 44 overwrite(false), 58 setFileDirCommand->SetParameterName("directo << 45 cullInvisibles(false), 59 if(std::getenv("G4HEPREPFILE_DIR") == NULL) << 46 cylAsPolygons(false), 60 { << 47 suffix (""), 61 setFileDirCommand->SetDefaultValue(""); << 48 geometry(true), 62 } << 49 solids(true), 63 else << 50 invisibles(true) { 64 { << 51 65 setFileDirCommand->SetDefaultValue(std::ge << 52 heprepDirectory = new G4UIdirectory("/vis/heprep/"); 66 fileDir = std::getenv("G4HEPREPFILE_DIR"); << 53 heprepDirectory->SetGuidance("HepRep commands."); 67 } << 54 68 setFileDirCommand->AvailableForStates(G4Stat << 55 setFileDirCommand = new G4UIcmdWithAString("/vis/heprep/setFileDir", this); 69 << 56 setFileDirCommand->SetGuidance("Set directory for output."); 70 setFileNameCommand = new G4UIcmdWithAString( << 57 setFileDirCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML."); 71 setFileNameCommand->SetGuidance("Set file na << 58 setFileDirCommand->SetParameterName("directory",false); 72 setFileNameCommand->SetGuidance( << 59 if ( getenv( "G4HEPREPFILE_DIR" ) == NULL ) { 73 "This command is used by HepRepFile, not b << 60 setFileDirCommand->SetDefaultValue(""); 74 setFileNameCommand->SetParameterName("direct << 61 } else { 75 if(std::getenv("G4HEPREPFILE_NAME") == NULL) << 62 setFileDirCommand->SetDefaultValue(getenv("G4HEPREPFILE_DIR")); 76 { << 63 fileDir = getenv("G4HEPREPFILE_DIR"); 77 setFileNameCommand->SetDefaultValue("G4Dat << 64 } 78 } << 65 setFileDirCommand->AvailableForStates(G4State_Idle); 79 else << 66 80 { << 67 setFileNameCommand = new G4UIcmdWithAString("/vis/heprep/setFileName", this); 81 setFileNameCommand->SetDefaultValue(std::g << 68 setFileNameCommand->SetGuidance("Set file name for output."); 82 fileName = std::getenv("G4HEPREPFILE_NAME" << 69 setFileNameCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML."); 83 } << 70 setFileNameCommand->SetParameterName("directory",false); 84 setFileNameCommand->AvailableForStates(G4Sta << 71 if ( getenv( "G4HEPREPFILE_NAME" ) == NULL ) { 85 << 72 setFileNameCommand->SetDefaultValue("G4Data"); 86 setOverwriteCommand = new G4UIcmdWithABool(" << 73 } else { 87 setOverwriteCommand->SetGuidance( << 74 setFileNameCommand->SetDefaultValue(getenv("G4HEPREPFILE_NAME")); 88 "Set true to write all output to exact sam << 75 fileName = getenv("G4HEPREPFILE_NAME"); 89 setOverwriteCommand->SetGuidance( << 76 } 90 "Set false to increment the file name for << 77 setFileNameCommand->AvailableForStates(G4State_Idle); 91 setOverwriteCommand->SetGuidance( << 78 92 "This command is used by HepRepFile, not b << 79 setOverwriteCommand = new G4UIcmdWithABool("/vis/heprep/setOverwrite", this); 93 setOverwriteCommand->SetParameterName("flag" << 80 setOverwriteCommand->SetGuidance("Set true to write all output to exact same file name."); 94 if(std::getenv("G4HEPREPFILE_OVERWRITE") == << 81 setOverwriteCommand->SetGuidance("Set false to increment the file name for each new output."); 95 { << 82 setOverwriteCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML."); 96 setOverwriteCommand->SetDefaultValue(false << 83 setOverwriteCommand->SetParameterName("flag",false); 97 } << 84 if ( getenv( "G4HEPREPFILE_OVERWRITE" ) == NULL ) { 98 else << 85 setOverwriteCommand->SetDefaultValue(false); 99 { << 86 } else { 100 setOverwriteCommand->SetDefaultValue(std:: << 87 setOverwriteCommand->SetDefaultValue(getenv("G4HEPREPFILE_OVERWRITE")); 101 overwrite = << 88 overwrite = setOverwriteCommand->ConvertToBool(getenv("G4HEPREPFILE_OVERWRITE")); 102 setOverwriteCommand->ConvertToBool(std:: << 89 } 103 } << 90 setOverwriteCommand->AvailableForStates(G4State_Idle); 104 setOverwriteCommand->AvailableForStates(G4St << 91 105 << 92 setCullInvisiblesCommand = new G4UIcmdWithABool("/vis/heprep/setCullInvisibles", this); 106 setCullInvisiblesCommand = << 93 setCullInvisiblesCommand->SetGuidance("Remove invisible objects from output file."); 107 new G4UIcmdWithABool("/vis/heprep/setCullI << 94 setCullInvisiblesCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML."); 108 setCullInvisiblesCommand->SetGuidance( << 95 setCullInvisiblesCommand->SetParameterName("flag",false); 109 "Remove invisible objects from output file << 96 if ( getenv( "G4HEPREPFILE_CULL" ) == NULL ) { 110 setCullInvisiblesCommand->SetGuidance( << 97 setCullInvisiblesCommand->SetDefaultValue(false); 111 "This command is used by HepRepFile, not b << 98 } else { 112 setCullInvisiblesCommand->SetParameterName(" << 99 setCullInvisiblesCommand->SetDefaultValue(getenv("G4HEPREPFILE_CULL")); 113 if(std::getenv("G4HEPREPFILE_CULL") == NULL) << 100 cullInvisibles = setCullInvisiblesCommand->ConvertToBool(getenv("G4HEPREPFILE_CULL")); 114 { << 101 } 115 setCullInvisiblesCommand->SetDefaultValue( << 102 setCullInvisiblesCommand->AvailableForStates(G4State_Idle); 116 } << 103 117 else << 104 renderCylAsPolygonsCommand = new G4UIcmdWithABool("/vis/heprep/renderCylAsPolygons", this); 118 { << 105 renderCylAsPolygonsCommand->SetGuidance("Render cylinders and cones as polygons."); 119 setCullInvisiblesCommand->SetDefaultValue( << 106 renderCylAsPolygonsCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML."); 120 cullInvisibles = << 107 renderCylAsPolygonsCommand->SetParameterName("flag",false); 121 setCullInvisiblesCommand->ConvertToBool( << 108 renderCylAsPolygonsCommand->SetDefaultValue(false); 122 } << 109 renderCylAsPolygonsCommand->AvailableForStates(G4State_Idle); 123 setCullInvisiblesCommand->AvailableForStates << 110 124 << 111 setEventNumberSuffixCommand = new G4UIcmdWithAString("/vis/heprep/setEventNumberSuffix", this); 125 renderCylAsPolygonsCommand = << 112 setEventNumberSuffixCommand->SetGuidance("Write separate event files, appended with given suffix."); 126 new G4UIcmdWithABool("/vis/heprep/renderCy << 113 setEventNumberSuffixCommand->SetGuidance("Define the suffix with a pattern such as '-0000'."); 127 renderCylAsPolygonsCommand->SetGuidance( << 114 setEventNumberSuffixCommand->SetGuidance("This command is used by HepRepXML, not by HepRepFile."); 128 "Render cylinders and cones as polygons.") << 115 setEventNumberSuffixCommand->SetParameterName("suffix",false); 129 renderCylAsPolygonsCommand->SetGuidance( << 116 setEventNumberSuffixCommand->SetDefaultValue(""); 130 "This command is used by HepRepFile, not b << 117 setEventNumberSuffixCommand->AvailableForStates(G4State_Idle); 131 renderCylAsPolygonsCommand->SetParameterName << 118 132 renderCylAsPolygonsCommand->SetDefaultValue( << 119 appendGeometryCommand = new G4UIcmdWithABool("/vis/heprep/appendGeometry", this); 133 renderCylAsPolygonsCommand->AvailableForStat << 120 appendGeometryCommand->SetGuidance("Appends copy of geometry to every event."); 134 << 121 appendGeometryCommand->SetGuidance("This command is used by HepRepXML, not by HepRepFile."); 135 setScaleCommand = new G4UIcmdWithADouble("/v << 122 appendGeometryCommand->SetParameterName("flag",false); 136 setScaleCommand->SetGuidance("Re-Scale coord << 123 appendGeometryCommand->SetDefaultValue(true); 137 setScaleCommand->SetParameterName("Scale", t << 124 appendGeometryCommand->AvailableForStates(G4State_Idle); 138 setScaleCommand->SetDefaultValue(1.); << 125 139 setScaleCommand->SetRange("Scale > 0"); << 126 addPointAttributesCommand = new G4UIcmdWithABool("/vis/heprep/addPointAttributes", this); 140 << 127 addPointAttributesCommand->SetGuidance("Adds point attributes to the points of trajectories."); 141 setCenterCommand = new G4UIcmdWith3VectorAnd << 128 addPointAttributesCommand->SetGuidance("This command is used by HepRepXML, not by HepRepFile."); 142 setCenterCommand->SetGuidance("Re-Center coo << 129 addPointAttributesCommand->SetParameterName("flag",false); 143 setCenterCommand->SetParameterName("CenterX" << 130 addPointAttributesCommand->SetDefaultValue(false); 144 setCenterCommand->SetDefaultValue(G4ThreeVec << 131 addPointAttributesCommand->AvailableForStates(G4State_Idle); 145 setCenterCommand->SetDefaultUnit("m"); << 132 146 << 133 useSolidsCommand = new G4UIcmdWithABool("/vis/heprep/useSolids", this); 147 setEventNumberSuffixCommand = << 134 useSolidsCommand->SetGuidance("Use HepRep Solids, rather than Geant4 Primitives."); 148 new G4UIcmdWithAString("/vis/heprep/setEve << 135 useSolidsCommand->SetGuidance("This command is used by HepRepXML, not by HepRepFile.."); 149 setEventNumberSuffixCommand->SetGuidance( << 136 useSolidsCommand->SetParameterName("flag",false); 150 "Write separate event files, appended with << 137 useSolidsCommand->SetDefaultValue(true); 151 setEventNumberSuffixCommand->SetGuidance( << 138 useSolidsCommand->AvailableForStates(G4State_Idle); 152 "Define the suffix with a pattern such as << 153 setEventNumberSuffixCommand->SetGuidance( << 154 "This command is used by HepRepXML, not by << 155 setEventNumberSuffixCommand->SetParameterNam << 156 setEventNumberSuffixCommand->SetDefaultValue << 157 setEventNumberSuffixCommand->AvailableForSta << 158 << 159 appendGeometryCommand = << 160 new G4UIcmdWithABool("/vis/heprep/appendGe << 161 appendGeometryCommand->SetGuidance( << 162 "Appends copy of geometry to every event." << 163 appendGeometryCommand->SetGuidance( << 164 "This command is used by HepRepXML, not by << 165 appendGeometryCommand->SetParameterName("fla << 166 appendGeometryCommand->SetDefaultValue(true) << 167 appendGeometryCommand->AvailableForStates(G4 << 168 << 169 addPointAttributesCommand = << 170 new G4UIcmdWithABool("/vis/heprep/addPoint << 171 addPointAttributesCommand->SetGuidance( << 172 "Adds point attributes to the points of tr << 173 addPointAttributesCommand->SetGuidance( << 174 "This command is used by HepRepXML, not by << 175 addPointAttributesCommand->SetParameterName( << 176 addPointAttributesCommand->SetDefaultValue(f << 177 addPointAttributesCommand->AvailableForState << 178 << 179 useSolidsCommand = new G4UIcmdWithABool("/vi << 180 useSolidsCommand->SetGuidance( << 181 "Use HepRep Solids, rather than Geant4 Pri << 182 useSolidsCommand->SetGuidance( << 183 "This command is used by HepRepXML, not by << 184 useSolidsCommand->SetParameterName("flag", f << 185 useSolidsCommand->SetDefaultValue(true); << 186 useSolidsCommand->AvailableForStates(G4State << 187 } 139 } 188 140 189 G4HepRepMessenger::~G4HepRepMessenger() << 141 G4HepRepMessenger::~G4HepRepMessenger() { 190 { << 142 delete setFileDirCommand; 191 delete setFileDirCommand; << 143 delete setFileNameCommand; 192 delete setFileNameCommand; << 144 delete setOverwriteCommand; 193 delete setOverwriteCommand; << 145 delete setCullInvisiblesCommand; 194 delete setCullInvisiblesCommand; << 146 delete renderCylAsPolygonsCommand; 195 delete renderCylAsPolygonsCommand; << 147 delete setEventNumberSuffixCommand; 196 delete setScaleCommand; << 148 delete appendGeometryCommand; 197 delete setCenterCommand; << 149 delete addPointAttributesCommand; 198 delete setEventNumberSuffixCommand; << 150 delete useSolidsCommand; 199 delete appendGeometryCommand; << 151 delete heprepDirectory; 200 delete addPointAttributesCommand; << 201 delete useSolidsCommand; << 202 delete heprepDirectory; << 203 } 152 } 204 153 205 G4String G4HepRepMessenger::GetCurrentValue(G4 << 154 G4String G4HepRepMessenger::GetCurrentValue(G4UIcommand * command) { 206 { << 155 if (command==setFileDirCommand) { 207 if(command == setFileDirCommand) << 156 return fileDir; 208 { << 157 } else if (command==setFileNameCommand) { >> 158 return fileName; >> 159 } else if (command==setOverwriteCommand) { >> 160 return overwrite; >> 161 } else if (command==setCullInvisiblesCommand) { >> 162 return cullInvisibles; >> 163 } else if (command==renderCylAsPolygonsCommand) { >> 164 return renderCylAsPolygonsCommand->ConvertToString(cylAsPolygons); >> 165 } else if (command==setEventNumberSuffixCommand) { >> 166 return suffix; >> 167 } else if (command==appendGeometryCommand) { >> 168 return appendGeometryCommand->ConvertToString(geometry); >> 169 } else if (command==addPointAttributesCommand) { >> 170 return addPointAttributesCommand->ConvertToString(pointAttributes); >> 171 } else if (command==useSolidsCommand) { >> 172 return useSolidsCommand->ConvertToString(solids); >> 173 } else { >> 174 return ""; >> 175 } >> 176 } >> 177 >> 178 void G4HepRepMessenger::SetNewValue(G4UIcommand * command, G4String newValue) { >> 179 if (command==setFileDirCommand) { >> 180 fileDir = newValue; >> 181 } else if (command==setFileNameCommand) { >> 182 fileName = newValue; >> 183 } else if (command==setOverwriteCommand) { >> 184 overwrite = setOverwriteCommand->GetNewBoolValue(newValue); >> 185 } else if (command==setCullInvisiblesCommand) { >> 186 cullInvisibles = setCullInvisiblesCommand->GetNewBoolValue(newValue); >> 187 } else if (command==renderCylAsPolygonsCommand) { >> 188 cylAsPolygons = renderCylAsPolygonsCommand->GetNewBoolValue(newValue); >> 189 } else if (command==setEventNumberSuffixCommand) { >> 190 suffix = newValue; >> 191 } else if (command==appendGeometryCommand) { >> 192 geometry = appendGeometryCommand->GetNewBoolValue(newValue); >> 193 } else if (command==addPointAttributesCommand) { >> 194 pointAttributes = addPointAttributesCommand->GetNewBoolValue(newValue); >> 195 } else if (command==useSolidsCommand) { >> 196 solids = useSolidsCommand->GetNewBoolValue(newValue); >> 197 } >> 198 } >> 199 >> 200 G4String G4HepRepMessenger::getFileDir() { 209 return fileDir; 201 return fileDir; 210 } << 202 } 211 else if(command == setFileNameCommand) << 203 212 { << 204 G4String G4HepRepMessenger::getFileName() { 213 return fileName; 205 return fileName; 214 } << 206 } 215 else if(command == setOverwriteCommand) << 207 216 { << 208 G4bool G4HepRepMessenger::getOverwrite() { 217 return G4UIcommand::ConvertToString(overwr << 209 return overwrite; 218 } << 210 } 219 else if(command == setCullInvisiblesCommand) << 211 220 { << 212 G4bool G4HepRepMessenger::getCullInvisibles() { 221 return G4UIcommand::ConvertToString(cullIn << 213 return cullInvisibles; 222 } << 214 } 223 else if(command == renderCylAsPolygonsComman << 215 224 { << 216 G4bool G4HepRepMessenger::renderCylAsPolygons() { 225 return renderCylAsPolygonsCommand->Convert << 217 return cylAsPolygons; 226 } << 218 } 227 else if(command == setScaleCommand) << 219 228 { << 220 G4String G4HepRepMessenger::getEventNumberSuffix() { 229 return setScaleCommand->ConvertToString(sc << 230 } << 231 else if(command == setCenterCommand) << 232 { << 233 return setCenterCommand->ConvertToString(c << 234 } << 235 else if(command == setEventNumberSuffixComma << 236 { << 237 return suffix; 221 return suffix; 238 } << 239 else if(command == appendGeometryCommand) << 240 { << 241 return appendGeometryCommand->ConvertToStr << 242 } << 243 else if(command == addPointAttributesCommand << 244 { << 245 return addPointAttributesCommand->ConvertT << 246 } << 247 else if(command == useSolidsCommand) << 248 { << 249 return useSolidsCommand->ConvertToString(s << 250 } << 251 else << 252 { << 253 return ""; << 254 } << 255 } 222 } 256 223 257 void G4HepRepMessenger::SetNewValue(G4UIcomman << 224 G4bool G4HepRepMessenger::appendGeometry() { 258 { << 225 return geometry; 259 if(command == setFileDirCommand) << 226 } 260 { << 261 fileDir = newValue; << 262 } << 263 else if(command == setFileNameCommand) << 264 { << 265 fileName = newValue; << 266 } << 267 else if(command == setOverwriteCommand) << 268 { << 269 overwrite = setOverwriteCommand->GetNewBoo << 270 } << 271 else if(command == setCullInvisiblesCommand) << 272 { << 273 cullInvisibles = setCullInvisiblesCommand- << 274 } << 275 else if(command == renderCylAsPolygonsComman << 276 { << 277 cylAsPolygons = renderCylAsPolygonsCommand << 278 } << 279 else if(command == setScaleCommand) << 280 { << 281 scale = setScaleCommand->GetNewDoubleValue << 282 } << 283 else if(command == setCenterCommand) << 284 { << 285 center = setCenterCommand->GetNew3VectorVa << 286 } << 287 else if(command == setEventNumberSuffixComma << 288 { << 289 suffix = newValue; << 290 } << 291 else if(command == appendGeometryCommand) << 292 { << 293 geometry = appendGeometryCommand->GetNewBo << 294 } << 295 else if(command == addPointAttributesCommand << 296 { << 297 pointAttributes = addPointAttributesComman << 298 } << 299 else if(command == useSolidsCommand) << 300 { << 301 solids = useSolidsCommand->GetNewBoolValue << 302 } << 303 } << 304 << 305 G4String G4HepRepMessenger::getFileDir() { ret << 306 << 307 G4String G4HepRepMessenger::getFileName() { re << 308 << 309 G4bool G4HepRepMessenger::getOverwrite() { ret << 310 << 311 G4bool G4HepRepMessenger::getCullInvisibles() << 312 << 313 G4bool G4HepRepMessenger::renderCylAsPolygons( << 314 << 315 G4double G4HepRepMessenger::getScale() { retur << 316 << 317 G4ThreeVector G4HepRepMessenger::getCenter() { << 318 << 319 G4String G4HepRepMessenger::getEventNumberSuff << 320 227 321 G4bool G4HepRepMessenger::appendGeometry() { r << 228 G4bool G4HepRepMessenger::addPointAttributes() { >> 229 return pointAttributes; >> 230 } 322 231 323 G4bool G4HepRepMessenger::addPointAttributes() << 232 G4bool G4HepRepMessenger::useSolids() { >> 233 return solids; >> 234 } 324 235 325 G4bool G4HepRepMessenger::useSolids() { return << 236 G4bool G4HepRepMessenger::writeInvisibles() { >> 237 return invisibles; >> 238 } 326 239 327 G4bool G4HepRepMessenger::writeInvisibles() { << 328 240