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: G4tgrFileReader.cc 69803 2013-05-15 15:24:50Z gcosmo $ 00028 // 00029 // 00030 // class G4tgrFileReader 00031 00032 // History: 00033 // - Created. P.Arce, CIEMAT (November 2007) 00034 // ------------------------------------------------------------------------- 00035 00036 #include "G4tgrFileReader.hh" 00037 #include "G4tgrParameterMgr.hh" 00038 #include "G4tgrFileIn.hh" 00039 #include "G4tgrElementSimple.hh" 00040 #include "G4tgrElementFromIsotopes.hh" 00041 #include "G4tgrVolume.hh" 00042 #include "G4tgrPlaceDivRep.hh" 00043 #include "G4tgrPlaceParameterisation.hh" 00044 #include "G4tgrVolumeDivision.hh" 00045 #include "G4tgrVolumeMgr.hh" 00046 #include "G4tgrUtils.hh" 00047 #include "G4tgrMaterialFactory.hh" 00048 #include "G4tgrRotationMatrixFactory.hh" 00049 #include "G4tgrLineProcessor.hh" 00050 #include "G4tgrMessenger.hh" 00051 00052 00053 G4tgrFileReader* G4tgrFileReader::theInstance = 0; 00054 00055 00056 //--------------------------------------------------------------- 00057 G4tgrFileReader::G4tgrFileReader() 00058 { 00059 theLineProcessor = new G4tgrLineProcessor; 00060 } 00061 00062 00063 //--------------------------------------------------------------- 00064 G4tgrFileReader::~G4tgrFileReader() 00065 { 00066 delete theLineProcessor; 00067 delete theInstance; 00068 } 00069 00070 00071 //--------------------------------------------------------------- 00072 G4tgrFileReader* G4tgrFileReader::GetInstance() 00073 { 00074 if( !theInstance ) { 00075 theInstance = new G4tgrFileReader; 00076 } 00077 return theInstance; 00078 } 00079 00080 //--------------------------------------------------------------- 00081 G4bool G4tgrFileReader::ReadFiles() 00082 { 00083 00084 std::vector< G4String > wl,wlnew; 00085 00086 #ifdef G4VERBOSE 00087 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 00088 { 00089 G4cout << " Number of geometry data files = " << theTextFiles.size() 00090 << G4endl; 00091 } 00092 #endif 00093 00094 if( theTextFiles.size() == 0 ) 00095 { 00096 G4Exception("G4tgrFileReader::ReadFiles()", "InvalidInput", 00097 FatalException, "No files to read ..."); 00098 } 00099 00100 for( size_t ii = 0; ii < theTextFiles.size(); ii++ ) 00101 { 00102 #ifdef G4VERBOSE 00103 if( G4tgrMessenger::GetVerboseLevel() >= 1 ) 00104 { 00105 G4cout << " Reading data file " << theTextFiles[ii] << G4endl; 00106 } 00107 #endif 00108 00109 G4tgrFileIn fin = G4tgrFileIn::GetInstance( theTextFiles[ii] ); 00110 00111 G4int nlines = 0; 00112 for(;;) 00113 { 00114 nlines++; 00115 if(! fin.GetWordsInLine( wlnew ) ) { break; } 00116 // Check if it is continuation line or first line 00117 if( wlnew[0].c_str()[0] != ':' ) 00118 { 00119 wl.insert( wl.end(), wlnew.begin(), wlnew.end() ); 00120 #ifdef G4VERBOSE 00121 if( G4tgrMessenger::GetVerboseLevel() >= 4 ) 00122 { 00123 G4tgrUtils::DumpVS(wl, "!!!! adding line"); 00124 } 00125 #endif 00126 continue; 00127 } 00128 else 00129 { 00130 //----- Process previous tag 00131 #ifdef G4VERBOSE 00132 if( G4tgrMessenger::GetVerboseLevel() >= 4 ) 00133 { 00134 G4tgrUtils::DumpVS(wl, "!!!! line read"); 00135 } 00136 #endif 00137 if( nlines != 1) // first line has no previous tag 00138 { 00139 if( ! theLineProcessor->ProcessLine( wl ) ) 00140 { 00141 fin.DumpException( "Tag not found: " + wl[0]); 00142 } 00143 } 00144 wl = wlnew; 00145 } 00146 } 00147 00148 if( wl.size() != 0 ) 00149 { 00150 if( ! theLineProcessor->ProcessLine( wl ) ) 00151 { 00152 fin.DumpException( "Tag not found: " + wl[0]); 00153 } 00154 } 00155 } 00156 return 1; 00157 }