Ignore:
Timestamp:
Dec 22, 2010, 3:52:27 PM (13 years ago)
Author:
garnier
Message:

geant4 tag 9.4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/materials/src/G4ExtDEDXTable.cc

    r1196 r1347  
    2424// ********************************************************************
    2525//
     26// $Id: G4ExtDEDXTable.cc,v 1.4 2010/11/01 18:18:57 vnivanch Exp $
     27// GEANT4 tag $Name: geant4-09-04-ref-00 $
    2628//
    2729// ===========================================================================
     
    3941// 03.11.2009 A. Lechner:  Added new methods BuildPhysicsVector according
    4042//            to interface changes in base class G4VIonDEDXTable.
     43// 25.10.2010 V.Ivanchenko fixed bug in usage of iterators reported by the
     44//            Coverity tool
     45// 01.11.2010 V.Ivanchenko fixed remaining bugs reported by Coverity
    4146//
    4247//
     
    220225
    221226#ifdef G4VERBOSE
    222      G4cerr << "G4IonDEDXTable::AddPhysicsVector() Error: Pointer to vector"
     227     G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: Pointer to vector"
    223228            << " is null-pointer."
    224229            << G4endl;
     
    231236
    232237#ifdef G4VERBOSE
    233      G4cerr << "G4IonDEDXTable::AddPhysicsVector() Error: "
     238     G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: "
    234239            << "Cannot add physics vector. Invalid name."
    235240            << G4endl;
     
    242247
    243248#ifdef G4VERBOSE
    244      G4cerr << "G4IonDEDXTable::AddPhysicsVector() Error: "
     249     G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: "
    245250            << "Cannot add physics vector. Illegal atomic number."
    246251            << G4endl;
     
    257262
    258263#ifdef G4VERBOSE
    259         G4cerr << "G4IonDEDXTable::AddPhysicsVector() Error: "
     264        G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: "
    260265               << "Vector already exists. Remove first before replacing."
    261266               << G4endl;
     
    272277
    273278#ifdef G4VERBOSE
    274      G4cerr << "G4IonDEDXTable::AddPhysicsVector() Error: "
     279     G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: "
    275280            << "Vector already exists. Remove first before replacing."
    276281            << G4endl;
     
    302307
    303308#ifdef G4VERBOSE
    304     G4cerr << "G4IonDEDXTable::RemovePhysicsVector() Warning: "
    305             << "Cannot remove physics vector. Vector not found."
    306              << G4endl;
    307 #endif
    308 
    309      return false;
     309    G4cout << "G4IonDEDXTable::RemovePhysicsVector() Warning: "
     310           << "Cannot remove physics vector. Vector not found."
     311           << G4endl;
     312#endif
     313
     314    return false;
    310315  }
    311316
     
    314319
    315320  // Deleting key of physics vector from elemental material map (if it exists)
    316   G4IonDEDXMapElem::iterator iter_beg = dedxMapElements.begin();
    317   G4IonDEDXMapElem::iterator iter_end = dedxMapElements.end();
     321  G4IonDEDXMapElem::iterator it;
    318322 
    319   for(;iter_beg != iter_end; iter_beg++) {
    320 
    321      if( (*iter_beg).second == physicsVector ) {
    322 
    323         dedxMapElements.erase(iter_beg);
     323  for(it=dedxMapElements.begin(); it!=dedxMapElements.end(); ++it) {
     324
     325     if( (*it).second == physicsVector ) {
     326        dedxMapElements.erase(it);
     327        break;
    324328     }
    325329  }
     
    345349
    346350#ifdef G4VERBOSE
    347      G4cerr << "G4ExtDEDXTable::StorePhysicsVector() "
     351     G4cout << "G4ExtDEDXTable::StorePhysicsVector() "
    348352            << " Cannot open file "<< fileName
    349353            << G4endl;
     
    388392
    389393#ifdef G4VERBOSE
    390               G4cerr << "G4ExtDEDXTable::StorePhysicsVector() "
     394              G4cout << "G4ExtDEDXTable::StorePhysicsVector() "
    391395                     << " Cannot store physics vector."
    392396                     << G4endl;
     
    409413
    410414  std::ifstream ifilestream;
    411 
    412415  ifilestream.open( fileName, std::ios::in );
    413 
    414   if( !ifilestream ) {
    415 
    416 #ifdef G4VERBOSE
    417      G4cerr << "G4ExtDEDXTable::RetrievePhysicsVector() "
    418             << " Cannot open file "<< fileName
    419             << G4endl;
    420 #endif
    421      
    422      return false;
     416  if( ! ifilestream ) {
     417#ifdef G4VERBOSE
     418    G4cout << "G4ExtDEDXTable::RetrievePhysicsVector() "
     419           << " Cannot open file "<< fileName
     420           << G4endl;
     421#endif
     422    return false;
    423423  }   
    424424
    425   G4int nmbVectors;
    426 
     425  std::string::size_type nmbVectors = 0;
    427426  ifilestream >> nmbVectors;
    428  
    429   for(G4int i = 0; i < nmbVectors; i++) {
    430 
    431       G4String line = "";
    432 
    433       while( line.empty() ) {
    434 
    435          getline( ifilestream, line );
    436 
    437          if( ifilestream.fail() ) {
    438 
     427
     428  if(nmbVectors == std::string::npos || nmbVectors == 0) {
     429#ifdef G4VERBOSE
     430    G4cout << "G4ExtDEDXTable::RetrievePhysicsVector() "
     431           << " The file is empty "<< nmbVectors
     432           << G4endl;
     433#endif
     434    return false;
     435  } 
     436  for(size_t i = 0; i<nmbVectors; ++i) {
     437
     438    G4String line = "";
     439    while( line.empty() ) {
     440
     441      getline( ifilestream, line );
     442      if( ifilestream.fail() ) {
    439443#ifdef G4VERBOSE 
    440             G4cerr << "G4ExtDEDXTable::RetrievePhysicsTable() "
    441                    << " File content of " << fileName << " ill-formated."
    442                    << G4endl;
     444        G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
     445               << " File content of " << fileName << " ill-formated."
     446               << G4endl;
    443447#endif         
    444             ifilestream.close();
    445             return false;
    446          }
    447 
    448          size_t pos = line.find_first_of("#");
    449          line = line.substr(0, pos);
     448        ifilestream.close();
     449        return false;
    450450      }
    451451
    452       std::istringstream headerstream( line );     
    453 
    454       G4int atomicNumberIon;
    455       headerstream >> atomicNumberIon;
    456 
    457       G4String materialName;
    458       headerstream >> materialName;
    459 
    460       if( headerstream.fail() ) {
     452      std::string::size_type pos = line.find_first_of("#");
     453      if(pos != std::string::npos && pos > 0) {
     454        line = line.substr(0, pos);
     455      }
     456    }
     457
     458    std::istringstream headerstream( line );     
     459
     460    std::string::size_type atomicNumberIon;
     461    headerstream >> atomicNumberIon;
     462
     463    G4String materialName;
     464    headerstream >> materialName;
     465
     466    if( headerstream.fail() || std::string::npos == atomicNumberIon) {
    461467 
    462468#ifdef G4VERBOSE 
    463          G4cerr << "G4ExtDEDXTable::RetrievePhysicsTable() "
    464                 << " File content of " << fileName << " ill-formated "
    465                 << " (vector header)."
    466                 << G4endl;
     469      G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
     470             << " File content of " << fileName << " ill-formated "
     471             << " (vector header)."
     472             << G4endl;
    467473#endif         
    468          ifilestream.close();
    469          return false;
    470       }
    471 
    472       G4int atomicNumberMat;
    473       headerstream >> atomicNumberMat;
    474 
    475       if( headerstream.eof() ) atomicNumberMat = 0;
    476 
    477       G4int vectorType;
    478 
    479       ifilestream >>  vectorType;
     474      ifilestream.close();
     475      return false;
     476    }
     477
     478    std::string::size_type atomicNumberMat;
     479    headerstream >> atomicNumberMat;
     480
     481    if( headerstream.eof() || std::string::npos == atomicNumberMat) {
     482      atomicNumberMat = 0;
     483    }
     484
     485    G4int vectorType;
     486    ifilestream >> vectorType;
    480487     
    481       G4PhysicsVector* physicsVector = CreatePhysicsVector(vectorType);
    482 
    483       if(physicsVector == 0) {
    484 
     488    G4PhysicsVector* physicsVector = CreatePhysicsVector(vectorType);
     489
     490    if(physicsVector == 0) {
    485491#ifdef G4VERBOSE 
    486          G4cerr << "G4ExtDEDXTable::RetrievePhysicsTable  "
    487                 << " illegal physics Vector type " << vectorType
    488                 << " in  " << fileName
    489                 << G4endl;
     492      G4cout << "G4ExtDEDXTable::RetrievePhysicsTable  "
     493             << " illegal physics Vector type " << vectorType
     494             << " in  " << fileName
     495             << G4endl;
    490496#endif         
    491          ifilestream.close();
    492          return false;
    493       }
    494 
    495       if( !physicsVector -> Retrieve(ifilestream, true) ) {
    496  
     497      ifilestream.close();
     498      return false;
     499    }
     500
     501    if( !physicsVector -> Retrieve(ifilestream, true) ) {
     502       
    497503#ifdef G4VERBOSE 
    498          G4cerr << "G4ExtDEDXTable::RetrievePhysicsTable() "
    499                 << " File content of " << fileName << " ill-formated."
    500                 << G4endl;
     504      G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
     505             << " File content of " << fileName << " ill-formated."
     506             << G4endl;
    501507#endif         
    502          ifilestream.close();
    503          return false;
    504       }
    505 
    506       physicsVector -> SetSpline(true);
    507 
    508       // Retrieved vector is added to material store
    509       if( !AddPhysicsVector(physicsVector, atomicNumberIon,
    510                             materialName, atomicNumberMat) ) {
    511 
    512         delete physicsVector;
    513          ifilestream.close();
    514          return false;
    515       }
     508      ifilestream.close();
     509      return false;
     510    }
     511
     512    physicsVector -> SetSpline(true);
     513
     514    // Retrieved vector is added to material store
     515    if( !AddPhysicsVector(physicsVector, (G4int)atomicNumberIon,
     516                          materialName, (G4int)atomicNumberMat) ) {
     517
     518      delete physicsVector;
     519      ifilestream.close();
     520      return false;
     521    }
    516522  }
    517523
Note: See TracChangeset for help on using the changeset viewer.