G4GeomTestStreamLogger.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // --------------------------------------------------------------------
00030 // GEANT 4 class source file
00031 //
00032 // G4GeomTestStreamLogger
00033 //
00034 // Author: D.C.Williams, UCSC (davidw@scipp.ucsc.edu)
00035 // --------------------------------------------------------------------
00036 
00037 #include <iomanip>
00038 
00039 #include "G4SystemOfUnits.hh"
00040 #include "G4GeomTestStreamLogger.hh"
00041 #include "G4VSolid.hh"
00042 #include "G4VPhysicalVolume.hh"
00043 #include "G4GeomTestOverlapList.hh"
00044 #include "G4GeomTestOvershootList.hh"
00045 
00046 //
00047 // Constructor and destructor
00048 //
00049 G4GeomTestStreamLogger::G4GeomTestStreamLogger( std::ostream &o,
00050                                                 G4int theMaxPointsPerError )
00051   : out(o), maxPointsPerError(theMaxPointsPerError)
00052 {;}
00053 
00054 G4GeomTestStreamLogger::~G4GeomTestStreamLogger()
00055 {;}
00056 
00057 //
00058 // ::PrintPos
00059 //
00060 // Utility class for printing a 3 vector position
00061 //
00062 void G4GeomTestStreamLogger::PrintPos::Print( std::ostream &o ) const
00063 {
00064   o << std::setprecision(6) << std::setw(14) << p.x()/cm;
00065   o << std::setprecision(6) << std::setw(14) << p.y()/cm;
00066   o << std::setprecision(6) << std::setw(14) << p.z()/cm;
00067   if (unit) o << " cm";
00068 }
00069 
00070 std::ostream &operator<<(      std::ostream &o,
00071                            const G4GeomTestStreamLogger::PrintPos &p )
00072 {
00073   p.Print(o);
00074   return o;
00075 }
00076 
00077 //
00078 // ::VolumeNameAndCopy
00079 //
00080 // Utility class for printing a volume's name and copy number
00081 //
00082 void
00083 G4GeomTestStreamLogger::VolumeNameAndCopy::Print( std::ostream &o ) const
00084 {
00085         o << volume->GetName() << "[" << volume->GetCopyNo() << "]";
00086 }
00087 
00088 std::ostream &operator<<( std::ostream &o,
00089                             const G4GeomTestStreamLogger::VolumeNameAndCopy &p )
00090 {
00091   p.Print(o);
00092   return o;
00093 }
00094 
00095 
00096 //
00097 // SolidProblem
00098 //
00099 void G4GeomTestStreamLogger::SolidProblem( const G4VSolid *solid, 
00100                                            const G4String &message,
00101                                            const G4ThreeVector &point )
00102 {
00103   out << "GeomTest Error: SolidProblem\n"
00104       << "    " << message << "\n"
00105       << "    Solid name = " << solid->GetName() << "\n"
00106       << "    Local position = " << PrintPos(point) << std::endl;
00107 }
00108 
00109 
00110 //
00111 // NoProblem
00112 //
00113 void G4GeomTestStreamLogger::NoProblem( const G4String &message )
00114 {
00115   out << message << std::endl;
00116 }
00117 
00118 
00119 //
00120 // OverlappingDaughters
00121 //
00122 void
00123 G4GeomTestStreamLogger::OverlappingDaughters(const G4GeomTestOverlapList *list)
00124 {
00125   G4int n = list->NumError();
00126   if (n <= 0) return;
00127 
00128   out << "GeomTest Error: Overlapping daughter volumes\n"
00129    << "    The volumes " << VolumeNameAndCopy(list->GetDaughter1())
00130    << " and " << VolumeNameAndCopy(list->GetDaughter2()) << ",\n"
00131    << "    both daughters of volume " << VolumeNameAndCopy(list->GetMother())
00132    << ",\n"
00133    << "    appear to overlap at the following " << (n>1 ? "points" : "point")
00134    << " in global coordinates:";
00135 
00136   G4int nInterval, nStop;
00137 
00138   if (n <= maxPointsPerError) {
00139     out << "\n";
00140     nInterval = 1;
00141     nStop = n;
00142   }
00143   else {
00144     out << " (list truncated)\n";
00145     nInterval = n/maxPointsPerError;
00146     nStop = maxPointsPerError*nInterval;
00147   }
00148 
00149   G4int i;
00150   G4ThreeVector s1, s2;
00151   
00152   PrintSegmentListHeader();
00153   for(i=0;i<nStop;i+=nInterval) {
00154     list->GetGlobalPoints( i, s1, s2 );
00155     PrintSegmentListElement( s1, s2 );
00156   }
00157 
00158   out << "    Which in the mother coordinate system " << IsAre(n) << ":\n";
00159 
00160   PrintSegmentListHeader();
00161   for(i=0;i<nStop;i+=nInterval) {
00162     list->GetMotherPoints( i, s1, s2 );
00163     PrintSegmentListElement( s1, s2 );
00164   }
00165 
00166   out << "    Which in the coordinate system of " 
00167       << VolumeNameAndCopy(list->GetDaughter1()) << " " << IsAre(n) << ":\n";
00168 
00169   PrintSegmentListHeader();
00170   for(i=0;i<nStop;i+=nInterval) {
00171     list->GetDaught1Points( i, s1, s2 );
00172     PrintSegmentListElement( s1, s2 );
00173   }
00174 
00175   out << "    Which in the coordinate system of " 
00176       << VolumeNameAndCopy(list->GetDaughter2()) << " " << IsAre(n) << ":\n";
00177   
00178   PrintSegmentListHeader();
00179   for(i=0;i<nStop;i+=nInterval) {
00180     list->GetDaught2Points( i, s1, s2 );
00181     PrintSegmentListElement( s1, s2 );
00182   }
00183   
00184   out << std::endl;
00185 }
00186 
00187 
00188 //
00189 // OvershootingDaughter
00190 //
00191 void G4GeomTestStreamLogger::
00192 OvershootingDaughter( const G4GeomTestOvershootList *list )
00193 {
00194   G4int n = list->NumError();
00195   if (n <= 0) return;
00196 
00197   out << "GeomTest Error: Overshooting daughter volume\n"
00198       << "    The volume " << VolumeNameAndCopy(list->GetDaughter())
00199       << " appears to extend outside the mother volume " 
00200       << VolumeNameAndCopy(list->GetMother()) << "\n"
00201       << "    at the following " << (n>1 ? "points" : "point")
00202       << " in global coordinates:";
00203 
00204 
00205   G4int nInterval, nStop;
00206 
00207   if (n <= maxPointsPerError) {
00208     out << "\n";
00209     nInterval = 1;
00210     nStop = n;
00211   }
00212   else {
00213     out << " (list truncated)\n";
00214     nInterval = n/maxPointsPerError;
00215     nStop = maxPointsPerError*nInterval;
00216   }
00217 
00218   G4int i;
00219   G4ThreeVector s1, s2;
00220   
00221   PrintSegmentListHeader();
00222   for(i=0;i<nStop;i+=nInterval) {
00223     list->GetGlobalPoints( i, s1, s2 );
00224     PrintSegmentListElement( s1, s2 );
00225   }
00226 
00227   out << "    Which in the mother coordinate system " << IsAre(n) << ":\n";
00228 
00229   PrintSegmentListHeader();
00230   for(i=0;i<nStop;i+=nInterval) {
00231     list->GetMotherPoints( i, s1, s2 );
00232     PrintSegmentListElement( s1, s2 );
00233   }
00234 
00235   out << "    Which in the coordinate system of " 
00236       << VolumeNameAndCopy(list->GetDaughter()) << " " << IsAre(n) << ":\n";
00237 
00238   PrintSegmentListHeader();
00239   for(i=0;i<nStop;i+=nInterval) {
00240     list->GetDaughtPoints( i, s1, s2 );
00241     PrintSegmentListElement( s1, s2 );
00242   }
00243   
00244   out << std::endl;
00245 }
00246 
00247 
00248 
00249 //
00250 // PrintSegmentListHeader (protected)
00251 //
00252 // Print out a header for a segment list
00253 //
00254 void G4GeomTestStreamLogger::PrintSegmentListHeader()
00255 {
00256   static const char *header =
00257      "       length (cm)    ---------- start position (cm) -----------   ----------- end position (cm) ------------\n";
00258   //      .............|    .............|.............|.............|   .............|.............|.............|
00259   //  1234              1234                                          123
00260 
00261   out << header;
00262 }
00263 
00264 
00265 //
00266 // PrintSegmentListElement (protected)
00267 //
00268 // Print out one segment value
00269 //
00270 void G4GeomTestStreamLogger::PrintSegmentListElement( const G4ThreeVector &s1,
00271                                                       const G4ThreeVector &s2 )
00272 {
00273   out << "    " << std::setprecision(6) << std::setw(14)
00274       << (s1-s2).mag()/cm
00275       << "    " << PrintPos(s1,false) << "   " << PrintPos(s2,false) << "\n";
00276 }
00277 
00278 
00279 //
00280 // IsAre (protected)
00281 //
00282 // Return a pointer to the string "is" if the argument
00283 // is equal to 1, otherwise return a pointer to "are"
00284 //
00285 const char *G4GeomTestStreamLogger::IsAre( G4int n )
00286 {
00287   const char *is = "is";
00288   const char *are = "are";
00289   
00290   return n > 1 ? are : is;
00291 }

Generated on Mon May 27 17:48:22 2013 for Geant4 by  doxygen 1.4.7