G4VScoreWriter Class Reference

#include <G4VScoreWriter.hh>


Public Member Functions

 G4VScoreWriter ()
virtual ~G4VScoreWriter ()
virtual void DumpQuantityToFile (const G4String &psName, const G4String &fileName, const G4String &option)
virtual void DumpAllQuantitiesToFile (const G4String &fileName, const G4String &option)
void SetScoringMesh (G4VScoringMesh *sm)
void SetVerboseLevel (G4int vl)

Protected Member Functions

G4int GetIndex (G4int x, G4int y, G4int z) const

Protected Attributes

G4int fNMeshSegments [3]
G4VScoringMeshfScoringMesh
G4int verboseLevel


Detailed Description

Definition at line 41 of file G4VScoreWriter.hh.


Constructor & Destructor Documentation

G4VScoreWriter::G4VScoreWriter (  ) 

Definition at line 40 of file G4VScoreWriter.cc.

References fNMeshSegments.

00041   : fScoringMesh(0), verboseLevel(0) {
00042   fNMeshSegments[0] = fNMeshSegments[1] = fNMeshSegments[2] = 0;
00043 }

G4VScoreWriter::~G4VScoreWriter (  )  [virtual]

Definition at line 45 of file G4VScoreWriter.cc.

00045                                 {
00046 }


Member Function Documentation

void G4VScoreWriter::DumpAllQuantitiesToFile ( const G4String fileName,
const G4String option 
) [virtual]

Definition at line 150 of file G4VScoreWriter.cc.

References fNMeshSegments, fScoringMesh, G4cerr, G4endl, G4VScoringMesh::GetDivisionAxisNames(), GetIndex(), G4VScoringMesh::GetPSUnit(), G4VScoringMesh::GetPSUnitValue(), G4VScoringMesh::GetScoreMap(), G4VScoringMesh::GetWorldName(), and ofile.

Referenced by G4ScoringManager::DumpAllQuantitiesToFile().

00151                                                                      {
00152 
00153   // change the option string into lowercase to the case-insensitive.
00154   G4String opt = option;
00155   std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
00156 
00157   // confirm the option
00158   if(opt.size() == 0) opt = "csv";
00159   if(opt.find("csv") == std::string::npos &&
00160      opt.find("sequence") == std::string::npos) {
00161     G4cerr << "ERROR : DumpToFile : Unknown option -> "
00162            << option << G4endl;
00163     return;
00164   }
00165 
00166   // open the file
00167   std::ofstream ofile(fileName);
00168   if(!ofile) {
00169     G4cerr << "ERROR : DumpToFile : File open error -> "
00170            << fileName << G4endl;
00171     return;
00172   }
00173   ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
00174 
00175   // retrieve the map
00176   MeshScoreMap fSMap = fScoringMesh->GetScoreMap();
00177   MeshScoreMap::const_iterator msMapItr = fSMap.begin();
00178   std::map<G4int, G4double*> * score;
00179   for(; msMapItr != fSMap.end(); msMapItr++) {
00180 
00181     G4String psname = msMapItr->first;
00182 
00183     score = msMapItr->second->GetMap();
00184     ofile << "# primitive scorer name: " << msMapItr->first << std::endl;
00185 
00186     G4double unitValue = fScoringMesh->GetPSUnitValue(psname);
00187     G4String unit = fScoringMesh->GetPSUnit(psname);
00188     G4String divisionAxisNames[3];
00189     fScoringMesh->GetDivisionAxisNames(divisionAxisNames);
00190     // index order
00191     ofile << "# i" << divisionAxisNames[0]
00192           << ", i" << divisionAxisNames[1]
00193           << ", i" << divisionAxisNames[2];
00194     // unit of scored value
00195     ofile << ", value ";
00196     if(unit.size() > 0) ofile << "[" << unit << "]";
00197     ofile << G4endl;
00198 
00199 
00200     // "sequence" option: write header info 
00201     if(opt.find("sequence") != std::string::npos) {
00202       ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << fNMeshSegments[2]
00203             << G4endl;
00204     }
00205 
00206     // write quantity
00207     long count = 0;
00208     ofile << std::setprecision(16); // for double value with 8 bytes
00209     for(int x = 0; x < fNMeshSegments[0]; x++) {
00210       for(int y = 0; y < fNMeshSegments[1]; y++) {
00211         for(int z = 0; z < fNMeshSegments[2]; z++) {
00212           G4int idx = GetIndex(x, y, z);
00213           
00214           if(opt.find("csv") != std::string::npos)
00215             ofile << x << "," << y << "," << z << ",";
00216           
00217           std::map<G4int, G4double*>::iterator value = score->find(idx);
00218           if(value == score->end()) {
00219             ofile << 0.;
00220           } else {
00221             ofile << *(value->second)/unitValue;
00222           }
00223 
00224           if(opt.find("csv") != std::string::npos) {
00225             ofile << G4endl;
00226           } else if(opt.find("sequence") != std::string::npos) {
00227             ofile << " ";
00228             if(count++%5 == 4) ofile << G4endl;
00229           }
00230 
00231         } // z
00232       } // y
00233     } // x
00234     ofile << std::setprecision(6);
00235 
00236   } // for(; msMapItr ....)
00237 
00238   // close the file
00239   ofile.close();
00240   
00241 }

void G4VScoreWriter::DumpQuantityToFile ( const G4String psName,
const G4String fileName,
const G4String option 
) [virtual]

Definition at line 53 of file G4VScoreWriter.cc.

References fNMeshSegments, fScoringMesh, G4cerr, G4endl, G4VScoringMesh::GetDivisionAxisNames(), GetIndex(), G4VScoringMesh::GetPSUnit(), G4VScoringMesh::GetPSUnitValue(), G4VScoringMesh::GetScoreMap(), G4VScoringMesh::GetWorldName(), and ofile.

Referenced by G4ScoringManager::DumpQuantityToFile().

00055                                                                 {
00056 
00057   // change the option string into lowercase to the case-insensitive.
00058   G4String opt = option;
00059   std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
00060 
00061   // confirm the option
00062   if(opt.size() == 0) opt = "csv";
00063   if(opt.find("csv") == std::string::npos &&
00064      opt.find("sequence") == std::string::npos) {
00065     G4cerr << "ERROR : DumpToFile : Unknown option -> "
00066            << option << G4endl;
00067     return;
00068   }
00069 
00070   // open the file
00071   std::ofstream ofile(fileName);
00072   if(!ofile) {
00073     G4cerr << "ERROR : DumpToFile : File open error -> "
00074            << fileName << G4endl;
00075     return;
00076   }
00077   ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
00078 
00079   
00080   // retrieve the map
00081   MeshScoreMap fSMap = fScoringMesh->GetScoreMap();
00082   
00083 
00084   MeshScoreMap::const_iterator msMapItr = fSMap.find(psName);
00085   if(msMapItr == fSMap.end()) {
00086     G4cerr << "ERROR : DumpToFile : Unknown quantity, \""
00087            << psName << "\"." << G4endl;
00088     return;
00089   }
00090 
00091 
00092   std::map<G4int, G4double*> * score = msMapItr->second->GetMap();
00093   ofile << "# primitive scorer name: " << msMapItr->first << std::endl;
00094 
00095 
00096   G4double unitValue = fScoringMesh->GetPSUnitValue(psName);
00097   G4String unit = fScoringMesh->GetPSUnit(psName);
00098   G4String divisionAxisNames[3];
00099   fScoringMesh->GetDivisionAxisNames(divisionAxisNames);
00100   // index order
00101   ofile << "# i" << divisionAxisNames[0]
00102         << ", i" << divisionAxisNames[1]
00103         << ", i" << divisionAxisNames[2];
00104   // unit of scored value
00105   ofile << ", value ";
00106   if(unit.size() > 0) ofile << "[" << unit << "]";
00107   ofile << G4endl;
00108 
00109   // "sequence" option: write header info 
00110   if(opt.find("sequence") != std::string::npos) {
00111     ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << fNMeshSegments[2]
00112           << G4endl;
00113   }
00114 
00115   // write quantity
00116   long count = 0;
00117   ofile << std::setprecision(16); // for double value with 8 bytes
00118   for(int x = 0; x < fNMeshSegments[0]; x++) {
00119     for(int y = 0; y < fNMeshSegments[1]; y++) {
00120       for(int z = 0; z < fNMeshSegments[2]; z++) {
00121         G4int idx = GetIndex(x, y, z);
00122         
00123         if(opt.find("csv") != std::string::npos)
00124           ofile << x << "," << y << "," << z << ",";
00125 
00126         std::map<G4int, G4double*>::iterator value = score->find(idx);
00127         if(value == score->end()) {
00128           ofile << 0.;
00129         } else {
00130           ofile << *(value->second)/unitValue;
00131         }
00132 
00133         if(opt.find("csv") != std::string::npos) {
00134           ofile << G4endl;
00135         } else if(opt.find("sequence") != std::string::npos) {
00136           ofile << " ";
00137           if(count++%5 == 4) ofile << G4endl;
00138         }
00139 
00140       } // z
00141     } // y
00142   } // x
00143   ofile << std::setprecision(6);
00144 
00145   // close the file
00146   ofile.close();
00147   
00148 }

G4int G4VScoreWriter::GetIndex ( G4int  x,
G4int  y,
G4int  z 
) const [protected]

Definition at line 243 of file G4VScoreWriter.cc.

References fNMeshSegments.

Referenced by DumpAllQuantitiesToFile(), and DumpQuantityToFile().

00243                                                               {
00244     //return x + y*fNMeshSegments[0] + z*fNMeshSegments[0]*fNMeshSegments[1];
00245     return x*fNMeshSegments[1]*fNMeshSegments[2] +y*fNMeshSegments[2]+z;
00246 }

void G4VScoreWriter::SetScoringMesh ( G4VScoringMesh sm  ) 

Definition at line 48 of file G4VScoreWriter.cc.

References fNMeshSegments, fScoringMesh, G4VScoringMesh::GetNumberOfSegments(), and G4InuclParticleNames::sm.

Referenced by G4ScoringManager::DumpAllQuantitiesToFile(), and G4ScoringManager::DumpQuantityToFile().

void G4VScoreWriter::SetVerboseLevel ( G4int  vl  )  [inline]

Definition at line 59 of file G4VScoreWriter.hh.

References verboseLevel.

Referenced by G4ScoringManager::SetScoreWriter(), and G4ScoringManager::SetVerboseLevel().

00059                                         {
00060     verboseLevel = vl;
00061   }


Field Documentation

G4int G4VScoreWriter::fNMeshSegments[3] [protected]

Definition at line 68 of file G4VScoreWriter.hh.

Referenced by DumpAllQuantitiesToFile(), DumpQuantityToFile(), G4VScoreWriter(), GetIndex(), and SetScoringMesh().

G4VScoringMesh* G4VScoreWriter::fScoringMesh [protected]

Definition at line 69 of file G4VScoreWriter.hh.

Referenced by DumpAllQuantitiesToFile(), DumpQuantityToFile(), and SetScoringMesh().

G4int G4VScoreWriter::verboseLevel [protected]

Definition at line 70 of file G4VScoreWriter.hh.

Referenced by SetVerboseLevel().


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:55 2013 for Geant4 by  doxygen 1.4.7