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 // G4LocatorChangeRecord class implementation 26 // G4LocatorChangeRecord class implementation 27 // 27 // 28 // Author: John Apostolakis, 28.08.19 - First 28 // Author: John Apostolakis, 28.08.19 - First version 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 31 #include <iostream> 31 #include <iostream> 32 #include <iomanip> 32 #include <iomanip> 33 #include <locale> 33 #include <locale> 34 // #include <cassert> 34 // #include <cassert> 35 35 36 #include "G4LocatorChangeRecord.hh" 36 #include "G4LocatorChangeRecord.hh" 37 37 38 // Must correspond exactly with the count of t 38 // Must correspond exactly with the count of the enum EChangeLocation 39 // 39 // 40 const char * G4LocatorChangeRecord::fNameChang 40 const char * G4LocatorChangeRecord::fNameChangeLocation[] = 41 { "Invalid", "Unknown", "Initialising", "Int 41 { "Invalid", "Unknown", "Initialising", "IntersectsAF", "IntersectsFB", // 5 42 "NoIntersections-AForFB", "RecalculatedB" 42 "NoIntersections-AForFB", "RecalculatedB", // 2 43 "InsertingMidPoint", "RecalculatedB-2ndHal 43 "InsertingMidPoint", "RecalculatedB-2ndHalf", // 2 44 "Level Pop" }; 44 "Level Pop" }; 45 45 46 // ------------------------------------------- 46 // -------------------------------------------------------------------- 47 // 47 // 48 std::ostream& G4LocatorChangeRecord::ReportVec 48 std::ostream& G4LocatorChangeRecord::ReportVector ( std::ostream& os, 49 49 const std::string & name, 50 const std::vector<G4Loc 50 const std::vector<G4LocatorChangeRecord> & vecRec ) 51 { 51 { 52 using std::setw; 52 using std::setw; 53 G4int prec= 16; 53 G4int prec= 16; 54 if( vecRec.empty() ) << 54 if( vecRec.size() == 0 ) 55 { 55 { 56 os << "Locator Change Record for " << nam 56 os << "Locator Change Record for " << name << " is empty" << G4endl; 57 return os; 57 return os; 58 } 58 } 59 59 60 G4long oldprc = os.precision(prec); << 60 G4int oldprc = os.precision(prec); 61 61 62 // std::vector<G4LocatorChangeRecord>::const 62 // std::vector<G4LocatorChangeRecord>::const_iterator 63 auto itRec 63 auto itRec 64 = std::vector<G4LocatorChangeRecord>::con 64 = std::vector<G4LocatorChangeRecord>::const_iterator(vecRec.cbegin()); 65 65 66 os << setw( 7 ) << "Change#" << " " 66 os << setw( 7 ) << "Change#" << " " 67 << setw( 4 ) << "Iter" << " " 67 << setw( 4 ) << "Iter" << " " 68 << std::left 68 << std::left 69 << setw( prec+9 ) << "Length" << " " 69 << setw( prec+9 ) << "Length" << " " 70 << setw( 15 ) << "Code-Location" << " " 70 << setw( 15 ) << "Code-Location" << " " 71 << G4endl; 71 << G4endl; 72 os << "===================================== 72 os << "=====================================================================" 73 << G4endl; 73 << G4endl; 74 74 75 do 75 do 76 { 76 { 77 auto locationCode= (*itRec).GetLocation() 77 auto locationCode= (*itRec).GetLocation(); 78 os << std::internal 78 os << std::internal 79 << setw( 7 ) << (*itRec).GetCount() << 79 << setw( 7 ) << (*itRec).GetCount() << " " // Event Count 80 << setw( 4 ) << (*itRec).GetIteration( 80 << setw( 4 ) << (*itRec).GetIteration() << " " 81 << std::left 81 << std::left 82 << setw( prec+9 ) << (*itRec).GetLengt 82 << setw( prec+9 ) << (*itRec).GetLength() << " " 83 << setw( 2 ) << locationCode << " " 83 << setw( 2 ) << locationCode << " " // location enum 84 << setw( 15 ) << fNameChangeLocation[ 84 << setw( 15 ) << fNameChangeLocation[ locationCode ] 85 << std::internal 85 << std::internal 86 ; 86 ; 87 os << G4endl; 87 os << G4endl; 88 ++itRec; 88 ++itRec; 89 89 90 } while ( itRec != vecRec.cend() ); 90 } while ( itRec != vecRec.cend() ); 91 91 92 os.precision(oldprc); 92 os.precision(oldprc); 93 return os; 93 return os; 94 } 94 } 95 95 96 // ------------------------------------------- 96 // -------------------------------------------------------------------- 97 // 97 // 98 std::ostream& 98 std::ostream& 99 G4LocatorChangeRecord::ReportEndChanges ( 99 G4LocatorChangeRecord::ReportEndChanges ( 100 std::ostream& os, 100 std::ostream& os, 101 const std::vector<G4LocatorChangeRecord> & 101 const std::vector<G4LocatorChangeRecord> & startA, 102 const std::vector<G4LocatorChangeRecord> & 102 const std::vector<G4LocatorChangeRecord> & endB ) 103 { 103 { 104 using std::setw; 104 using std::setw; 105 G4int prec= 16; 105 G4int prec= 16; 106 const G4bool confirm = true; 106 const G4bool confirm = true; 107 G4long oldprc = os.precision(prec); << 107 G4int oldprc = os.precision(prec); 108 108 109 std::vector<G4LocatorChangeRecord>::const_it 109 std::vector<G4LocatorChangeRecord>::const_iterator itrecA, itrecB; 110 itrecA= startA.begin(); 110 itrecA= startA.begin(); 111 itrecB= endB.begin(); 111 itrecB= endB.begin(); 112 os << G4endl; << 112 113 os << "===================================== << 113 os << "=====================================================================" 114 os << G4endl << " ** Change records: " << G4 << 114 << G4endl; 115 os << " * endPoints A (start) and B (en << 115 os << " Size of individual change record: startA : " << startA.size() 116 os << " * Sizes of change records: star << 116 << " endB : " << endB.size() << G4endl; 117 << " end(B) : " << endB.size() << G4en << 117 os << "=====================================================================" 118 os << "===================================== << 119 << G4endl; 118 << G4endl; 120 119 121 os << setw( 7 ) << "Change#" << " " 120 os << setw( 7 ) << "Change#" << " " 122 << setw( 4 ) << "Iter" << " " 121 << setw( 4 ) << "Iter" << " " 123 << setw( 20 ) << "CodeLocation" << " " 122 << setw( 20 ) << "CodeLocation" << " " 124 << setw( prec+9 ) << "Length-A (start)" < 123 << setw( prec+9 ) << "Length-A (start)" << " " 125 << setw( prec+9 ) << "Length-B (end)" << 124 << setw( prec+9 ) << "Length-B (end)" << " " 126 << G4endl; 125 << G4endl; 127 os << "===================================== 126 os << "====================================================================="; 128 127 129 128 130 auto eventA = (*itrecA).GetCount(); 129 auto eventA = (*itrecA).GetCount(); 131 auto eventB = (*itrecB).GetCount(); 130 auto eventB = (*itrecB).GetCount(); 132 131 133 G4bool isLastA= false; 132 G4bool isLastA= false; 134 G4bool isLastB= false; 133 G4bool isLastB= false; 135 134 >> 135 G4int jA=0, jB=0; >> 136 136 G4int maxEvent = std::max( startA[ startA.si 137 G4int maxEvent = std::max( startA[ startA.size() - 1 ].GetCount() , 137 endB[ endB.size 138 endB[ endB.size() - 1 ].GetCount() ); 138 G4int prevA = -1; 139 G4int prevA = -1; 139 G4int prevB = -1; 140 G4int prevB = -1; 140 141 141 G4bool advanceA= false, advanceB= false; 142 G4bool advanceA= false, advanceB= false; 142 do 143 do 143 { 144 { 144 advanceA= false; 145 advanceA= false; 145 advanceB= false; 146 advanceB= false; 146 147 147 if( ((G4int)eventA>prevA) && ((G4int)even 148 if( ((G4int)eventA>prevA) && ((G4int)eventB>prevB) ) 148 { 149 { 149 auto codeLocA= (*itrecA).GetLocation() 150 auto codeLocA= (*itrecA).GetLocation(); 150 151 151 os << G4endl; 152 os << G4endl; 152 os << setw( 7 ) << eventA << " " 153 os << setw( 7 ) << eventA << " " 153 << setw( 4 ) << (*itrecA).GetIterat 154 << setw( 4 ) << (*itrecA).GetIteration() << " " 154 << setw( 3 ) << codeLocA << " " 155 << setw( 3 ) << codeLocA << " " 155 << setw( 15 ) << fNameChangeLocatio 156 << setw( 15 ) << fNameChangeLocation[ codeLocA ] << " " 156 << setw( prec+9 ) << (*itrecA).GetL 157 << setw( prec+9 ) << (*itrecA).GetLength() << " " 157 << setw( prec+9 ) << (*itrecB).GetL 158 << setw( prec+9 ) << (*itrecB).GetLength() << " "; 158 if( confirm ) 159 if( confirm ) 159 { 160 { 160 os << setw( 4 ) << (*itrecB).GetIter 161 os << setw( 4 ) << (*itrecB).GetIteration() << " " 161 << setw( 15 ) << (*itrecB).GetLoc 162 << setw( 15 ) << (*itrecB).GetLocation(); 162 } 163 } 163 } 164 } 164 else 165 else 165 { 166 { 166 if ( (G4int)eventA > prevA ) 167 if ( (G4int)eventA > prevA ) 167 { 168 { 168 auto codeLocA = (*itrecA).GetLocati 169 auto codeLocA = (*itrecA).GetLocation(); 169 os << G4endl; 170 os << G4endl; 170 os << setw( 7 ) << (*itrecA).GetCou 171 os << setw( 7 ) << (*itrecA).GetCount() << " " 171 << setw( 4 ) << (*itrecA).GetIte 172 << setw( 4 ) << (*itrecA).GetIteration() << " " 172 << setw( 3 ) << codeLocA << " " 173 << setw( 3 ) << codeLocA << " " 173 << setw( 15 ) << fNameChangeLoca 174 << setw( 15 ) << fNameChangeLocation[ codeLocA ] << " " 174 << setw( prec+9 ) << (*itrecA).G 175 << setw( prec+9 ) << (*itrecA).GetLength() << " " 175 << setw( prec+9 ) << " " < 176 << setw( prec+9 ) << " " << " "; 176 } 177 } 177 else 178 else 178 { 179 { 179 // assert( (G4int)eventB > prevB ); 180 // assert( (G4int)eventB > prevB ); 180 auto codeLocB = (*itrecB).GetLocati 181 auto codeLocB = (*itrecB).GetLocation(); 181 182 182 os << G4endl; 183 os << G4endl; 183 os << setw( 7 ) << eventB << " " 184 os << setw( 7 ) << eventB << " " 184 << setw( 4 ) << (*itrecB).GetIte 185 << setw( 4 ) << (*itrecB).GetIteration() << " " 185 << setw( 3 ) << codeLocB << " " 186 << setw( 3 ) << codeLocB << " " 186 << setw( 15 ) << fNameChangeLoca 187 << setw( 15 ) << fNameChangeLocation[ codeLocB ] << " " 187 << setw( prec+9 ) << " " < 188 << setw( prec+9 ) << " " << " " 188 << setw( prec+9 ) << (*itrecB).G 189 << setw( prec+9 ) << (*itrecB).GetLength() << " " ; 189 } 190 } 190 } 191 } 191 192 192 prevA= eventA; 193 prevA= eventA; 193 prevB= eventB; 194 prevB= eventB; 194 195 195 auto nextA= itrecA; 196 auto nextA= itrecA; 196 auto nextB= itrecB; 197 auto nextB= itrecB; 197 198 198 G4int nextAct = maxEvent, nextBct = maxEv 199 G4int nextAct = maxEvent, nextBct = maxEvent; 199 ++nextA; 200 ++nextA; 200 ++nextB; 201 ++nextB; 201 if ( nextA != startA.end() ) { nextAct = 202 if ( nextA != startA.end() ) { nextAct = (*nextA).GetCount(); } 202 if ( nextB != endB.end() ) { nextBct = 203 if ( nextB != endB.end() ) { nextBct = (*nextB).GetCount(); } 203 204 204 isLastA= ( nextA >= startA.end() ); 205 isLastA= ( nextA >= startA.end() ); 205 isLastB= ( nextB >= endB.end() ); 206 isLastB= ( nextB >= endB.end() ); 206 207 207 advanceA= ( nextAct <= nextBct ) && !isLa 208 advanceA= ( nextAct <= nextBct ) && !isLastA; 208 advanceB= ( nextBct <= nextAct ) && !isLa 209 advanceB= ( nextBct <= nextAct ) && !isLastB; 209 210 210 if( advanceA ) 211 if( advanceA ) 211 { 212 { 212 ++itrecA; 213 ++itrecA; 213 if( !isLastA ) { eventA = (*itrecA).Ge << 214 if( !isLastA ) { ++jA; eventA = (*itrecA).GetCount(); } 214 else { eventA = maxEvent; } 215 else { eventA = maxEvent; } 215 } 216 } 216 217 217 if( advanceB ) 218 if( advanceB ) 218 { 219 { 219 ++itrecB; 220 ++itrecB; 220 if( !isLastB ) { eventB = (*itrecB).Ge << 221 if( !isLastB ) { ++jB; eventB = (*itrecB).GetCount(); } 221 else { eventB = maxEvent; } 222 else { eventB = maxEvent; } 222 } 223 } 223 224 224 // Checks 225 // Checks 225 if( isLastA != ( nextA == startA.end() ) 226 if( isLastA != ( nextA == startA.end() ) ) 226 { 227 { 227 os << G4endl; 228 os << G4endl; 228 os << " Checking isLastA= " << isLast 229 os << " Checking isLastA= " << isLastA << " vs expected : " 229 << ( itrecA == startA.end() ); 230 << ( itrecA == startA.end() ); 230 os << " BAD --- ERROR " << G4endl; 231 os << " BAD --- ERROR " << G4endl; 231 } 232 } 232 if( isLastB != ( nextB == endB.end() ) ) 233 if( isLastB != ( nextB == endB.end() ) ) 233 { 234 { 234 os << G4endl; 235 os << G4endl; 235 os << " Checking isLastB= " << isLast 236 os << " Checking isLastB= " << isLastB << " vs expected : " 236 << ( itrecB == endB.end() ); 237 << ( itrecB == endB.end() ); 237 os << " BAD --- ERROR " << G4endl; 238 os << " BAD --- ERROR " << G4endl; 238 } 239 } 239 240 240 } while ( ! ( isLastA && isLastB ) ); 241 } while ( ! ( isLastA && isLastB ) ); 241 242 242 os << G4endl; 243 os << G4endl; 243 os.precision(oldprc); 244 os.precision(oldprc); 244 return os; 245 return os; 245 } 246 } 246 247 247 // ------------------------------------------- 248 // -------------------------------------------------------------------- 248 // Streaming operator dumping record 249 // Streaming operator dumping record 249 // 250 // 250 std::ostream& operator<< ( std::ostream& os, c 251 std::ostream& operator<< ( std::ostream& os, const G4LocatorChangeRecord& e ) 251 { 252 { 252 return e.StreamInfo(os); 253 return e.StreamInfo(os); 253 } 254 } 254 255 255 // ------------------------------------------- 256 // -------------------------------------------------------------------- 256 // Stream object contents to an output stream 257 // Stream object contents to an output stream 257 // 258 // 258 std::ostream& G4LocatorChangeRecord::StreamInf 259 std::ostream& G4LocatorChangeRecord::StreamInfo(std::ostream& os) const 259 { 260 { 260 G4long oldprc = os.precision(16); << 261 G4int oldprc = os.precision(16); 261 os << " count = " << fEventCount 262 os << " count = " << fEventCount 262 << " iter= " << fIteration 263 << " iter= " << fIteration 263 << " Location code = " << fCodeLocation 264 << " Location code = " << fCodeLocation 264 << " Length = " << GetLength() << G4endl 265 << " Length = " << GetLength() << G4endl; 265 os.precision(oldprc); 266 os.precision(oldprc); 266 return os; 267 return os; 267 } 268 } 268 269 269 // ------------------------------------------- 270 // -------------------------------------------------------------------- 270 // Streaming operator 271 // Streaming operator 271 // 272 // 272 std::ostream& operator << ( std::ostream& os, 273 std::ostream& operator << ( std::ostream& os, 273 const std::vector< 274 const std::vector<G4LocatorChangeRecord> & vecR ) 274 { 275 { 275 G4LocatorChangeRecord::ReportVector( os, "", 276 G4LocatorChangeRecord::ReportVector( os, "", vecR ); 276 return os; 277 return os; 277 } 278 } 278 279 279 // ------------------------------------------- 280 // -------------------------------------------------------------------- 280 // 281 // 281 const char *G4LocatorChangeRecord::GetNameChan 282 const char *G4LocatorChangeRecord::GetNameChangeLocation( EChangeLocation loc ) 282 { 283 { 283 return fNameChangeLocation[loc]; 284 return fNameChangeLocation[loc]; 284 } 285 } 285 286