Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 ////////////////////////////////////////////// 23 /////////////////////////////////////////////////////////////////////////////// 27 // File: CCalutils.cc 24 // File: CCalutils.cc 28 // Description: General utilities. 25 // Description: General utilities. 29 ////////////////////////////////////////////// 26 /////////////////////////////////////////////////////////////////////////////// 30 #include "CCalutils.hh" 27 #include "CCalutils.hh" 31 #include "G4ios.hh" 28 #include "G4ios.hh" 32 #include "G4UnitsTable.hh" 29 #include "G4UnitsTable.hh" 33 30 34 #include <sstream> 31 #include <sstream> 35 32 36 33 37 G4String operator+(const G4String& str, const << 34 G4String operator+(const G4String& str, const int i) { 38 std::ostringstream os; 35 std::ostringstream os; 39 os << str << i <<'\0'; 36 os << str << i <<'\0'; 40 G4String back = os.str(); 37 G4String back = os.str(); 41 return back; 38 return back; 42 } 39 } 43 40 44 41 45 G4String operator+(const G4String& str, const << 42 G4String operator+(const G4String& str, const double i) { 46 std::ostringstream os; 43 std::ostringstream os; 47 os << str << i <<'\0'; 44 os << str << i <<'\0'; 48 G4String back = os.str(); 45 G4String back = os.str(); 49 return back; 46 return back; 50 } 47 } 51 48 52 49 53 std::ifstream& readName(std::ifstream& is, G4S 50 std::ifstream& readName(std::ifstream& is, G4String& name){ 54 is >> name; 51 is >> name; 55 if ( name != "*ENDDO" ) { 52 if ( name != "*ENDDO" ) { 56 while ( name.find("#.") != G4String::npos 53 while ( name.find("#.") != G4String::npos ) { // It is a comment. Skip line. 57 is.ignore(999,'\n'); 54 is.ignore(999,'\n'); 58 is >> name; 55 is >> name; 59 }; 56 }; 60 while ( name.rfind('\"') != name.length()- 57 while ( name.rfind('\"') != name.length()-1 ) { 61 G4String other; 58 G4String other; 62 is >> other; 59 is >> other; 63 name += " "; 60 name += " "; 64 name += other; 61 name += other; 65 }; 62 }; 66 G4StrUtil::strip(name, '\"'); << 63 name = name.strip(G4String::both, '\"'); 67 } 64 } 68 return is; 65 return is; 69 } 66 } 70 67 71 68 72 std::ifstream& findDO(std::ifstream& is, const 69 std::ifstream& findDO(std::ifstream& is, const G4String& str){ 73 // Loop until *DO str is found 70 // Loop until *DO str is found 74 G4String firstwd, dowhat; 71 G4String firstwd, dowhat; 75 dowhat = ""; 72 dowhat = ""; 76 while (dowhat != str && is) { 73 while (dowhat != str && is) { 77 is >> firstwd; 74 is >> firstwd; 78 while (firstwd != "*DO" && is) { 75 while (firstwd != "*DO" && is) { 79 is.ignore(999,'\n'); 76 is.ignore(999,'\n'); 80 is >> firstwd; 77 is >> firstwd; 81 }; 78 }; 82 is >> dowhat; 79 is >> dowhat; 83 }; 80 }; 84 is.ignore(999,'\n'); 81 is.ignore(999,'\n'); 85 return is; 82 return is; 86 } 83 } 87 84 88 85 89 std::ostream& tab(std::ostream& os) { 86 std::ostream& tab(std::ostream& os) { 90 os << '\t'; 87 os << '\t'; 91 return os; 88 return os; 92 } 89 } 93 90 94 91 95 std::istream& jump(std::istream& is) { 92 std::istream& jump(std::istream& is) { 96 char first = ' '; << 93 char first, second; 97 char second = ' '; << 98 is.ignore(999,'\n'); 94 is.ignore(999,'\n'); 99 do { 95 do { 100 is.get(first); 96 is.get(first); 101 second = is.peek(); 97 second = is.peek(); 102 if (first == '#' && second =='.') { 98 if (first == '#' && second =='.') { 103 is.ignore(999,'\n'); 99 is.ignore(999,'\n'); 104 } 100 } 105 else if (first == '\n'); //it was already 101 else if (first == '\n'); //it was already picked 106 else { 102 else { 107 is.putback(first); 103 is.putback(first); 108 return is; 104 return is; 109 } 105 } 110 } 106 } 111 while (is); 107 while (is); 112 return is; 108 return is; 113 } 109 } 114 110 115 111 116 G4bool openGeomFile(std::ifstream& is, << 112 bool openGeomFile(std::ifstream& is, 117 const G4String& pathname, << 113 const G4String& pathname, const G4String& filename) { 118 G4String fullname = pathname+"/"+filename; 114 G4String fullname = pathname+"/"+filename; 119 is.open( fullname.c_str() ); 115 is.open( fullname.c_str() ); 120 if (!is) { 116 if (!is) { 121 G4cerr << "ERROR: Could not open file " << 117 G4cerr << "ERROR: Could not open file " << filename << G4endl; 122 return false; 118 return false; 123 } 119 } 124 return true; 120 return true; 125 } 121 } 126 122