Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4LocatorChangeLogger.cc
Go to the documentation of this file.
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// G4LocatorChangeLogger class implementation
27//
28// Author: John Apostolakis (CERN), 04 September 2019
29// --------------------------------------------------------------------
30
31#include <iostream>
32#include <iomanip>
33#include <locale>
34
36
37// --------------------------------------------------------------------
38// Constructor
39//
41 : fName(name)
42{
43}
44
45// --------------------------------------------------------------------
46// Streaming operator dumping record
47//
48std::ostream& operator<< ( std::ostream& os,
49 const G4LocatorChangeLogger& logger )
50{
51 return logger.StreamInfo(os);
52}
53
54// --------------------------------------------------------------------
55// Stream object contents to an output stream
56//
57std::ostream& G4LocatorChangeLogger::StreamInfo(std::ostream& os) const
58{
59 G4long oldprc = os.precision(16);
60 G4LocatorChangeRecord::ReportVector( os, this->fName, *this );
61 os.precision(oldprc);
62 return os;
63}
64
65// --------------------------------------------------------------------
66// Print the changes in start, end points in columns -- one event per row
67//
68std::ostream& G4LocatorChangeLogger::ReportEndChanges( std::ostream& os,
69 const G4LocatorChangeLogger & startA,
70 const G4LocatorChangeLogger & endB )
71{
72 using std::setw;
73 G4int prec= 16;
74 const G4bool confirm = true;
75 G4long oldprc = os.precision(prec);
76
77 auto itrecA= startA.cbegin();
78 auto itrecB= endB.cbegin();
79
80 os << "====================================================================="
81 << G4endl;
82 os << " Size of individual change record: startA : " << startA.size()
83 << " endB : " << endB.size() << G4endl;
84 os << "====================================================================="
85 << G4endl;
86
87 os << setw( 7 ) << "Change#" << " "
88 << setw( 4 ) << "Iter" << " "
89 << setw( 20 ) << "CodeLocation" << " "
90 << setw( prec+9 ) << "Length-A (start)" << " "
91 << setw( prec+9 ) << "Length-B (end)" << " "
92 << G4endl;
93 os << "=====================================================================";
94
95 auto eventA = (*itrecA).GetCount();
96 auto eventB = (*itrecB).GetCount();
97
98 G4bool isLastA= false;
99 G4bool isLastB= false;
100
101 G4int maxEvent = std::max( startA[ startA.size() - 1 ].GetCount() ,
102 endB[ endB.size() - 1 ].GetCount() );
103 G4int prevA = -1;
104 G4int prevB = -1;
105
106 G4bool advanceA= false, advanceB= false;
107 do
108 {
109 advanceA= false;
110 advanceB= false;
111
112 if( ((G4int)eventA>prevA) && ((G4int)eventB>prevB) )
113 {
114 auto codeLocA= (*itrecA).GetLocation();
115
116 os << G4endl;
117 os << setw( 7 ) << eventA << " "
118 << setw( 4 ) << (*itrecA).GetIteration() << " "
119 << setw( 3 ) << codeLocA << " "
120 << setw( 15 )
122 << setw( prec+9 ) << (*itrecA).GetLength() << " "
123 << setw( prec+9 ) << (*itrecB).GetLength() << " ";
124 if( confirm )
125 {
126 os << setw( 4 ) << (*itrecB).GetIteration() << " "
127 << setw( 15 ) << (*itrecB).GetLocation();
128 }
129 }
130 else
131 {
132 if ( (G4int)eventA > prevA )
133 {
134 auto codeLocA= (*itrecA).GetLocation();
135 os << G4endl;
136 os << setw( 7 ) << (*itrecA).GetCount() << " "
137 << setw( 4 ) << (*itrecA).GetIteration() << " "
138 << setw( 3 ) << codeLocA << " "
139 << setw( 15 )
141 << setw( prec+9 ) << (*itrecA).GetLength() << " "
142 << setw( prec+9 ) << " " << " ";
143 }
144 else
145 {
146 // assert( (G4int)eventB > prevB );
147 auto codeLocB= (*itrecB).GetLocation();
148
149 os << G4endl;
150 os << setw( 7 ) << eventB << " "
151 << setw( 4 ) << (*itrecB).GetIteration() << " "
152 << setw( 3 ) << codeLocB << " "
153 << setw( 15 )
155 << setw( prec+9 ) << " " << " "
156 << setw( prec+9 ) << (*itrecB).GetLength() << " " ;
157 }
158 }
159
160 prevA= eventA;
161 prevB= eventB;
162
163 auto nextA= itrecA;
164 auto nextB= itrecB;
165
166 G4int nextAct = maxEvent, nextBct = maxEvent;
167 ++nextA;
168 ++nextB;
169 if ( nextA != startA.end() ) { nextAct = (*nextA).GetCount(); }
170 if ( nextB != endB.end() ) { nextBct = (*nextB).GetCount(); }
171
172 isLastA= ( nextA >= startA.end() );
173 isLastB= ( nextB >= endB.end() );
174
175 advanceA= ( nextAct <= nextBct ) && !isLastA;
176 advanceB= ( nextBct <= nextAct ) && !isLastB;
177
178 if( advanceA )
179 {
180 ++itrecA;
181 eventA = isLastA ? maxEvent : (*itrecA).GetCount();
182 }
183
184 if( advanceB )
185 {
186 ++itrecB;
187 eventB = isLastB ? maxEvent : (*itrecB).GetCount();
188 }
189
190 // Checks
191 if( isLastA != ( nextA == startA.end() ) )
192 {
193 os << G4endl;
194 os << " Checking isLastA= " << isLastA
195 << " vs expected : " << ( itrecA == startA.end() );
196 os << " BAD --- ERROR " << G4endl;
197 }
198 if( isLastB != ( nextB == endB.end() ) )
199 {
200 os << G4endl;
201 os << " Checking isLastB= " << isLastB
202 << " vs expected : " << ( itrecB == endB.end() );
203 os << " BAD --- ERROR " << G4endl;
204 }
205 } while ( ! ( isLastA && isLastB ) );
206
207 os << G4endl;
208 os.precision(oldprc);
209 return os;
210}
std::ostream & operator<<(std::ostream &os, const G4LocatorChangeLogger &logger)
long G4long
Definition G4Types.hh:87
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
std::ostream & StreamInfo(std::ostream &os) const
G4LocatorChangeLogger(const std::string &name)
static std::ostream & ReportEndChanges(std::ostream &os, const G4LocatorChangeLogger &startA, const G4LocatorChangeLogger &endB)
static const char * GetNameChangeLocation(EChangeLocation)
static std::ostream & ReportVector(std::ostream &os, const std::string &nameOfRecord, const std::vector< G4LocatorChangeRecord > &lcr)