Problem 908 - G4IonTable::IsLightIon is not optimized
Summary: G4IonTable::IsLightIon is not optimized
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: particles (show other problems)
Version: 8.1
Hardware: PC Linux
: P2 normal
Assignee: kurasige
URL:
Depends on:
Blocks:
 
Reported: 2006-11-11 02:47 CET by vincenzo.innocente
Modified: 2006-11-16 01:28 CET (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description vincenzo.innocente 2006-11-11 02:47:23 CET
In some simple examples run on slc3 G4IonTable::IsLightIon ends up eating most of the cpu due to too
many string creation
Although more modern compilers may mitigate the problem I wish to suggest to modify the code
as follows (I think that for all practical use cases a linear search is better than a binary one)

#include <algorithm>
G4bool G4IonTable::IsLightIon(G4ParticleDefinition* particle) const
{
  static const std::string names[] = { "proton", "neutron", "alpha", "deuteron",
                           "triton", "He3", "GenericIon"};

   // return true if the particle is pre-defined ion
  return std::find(names, names+7, particle->GetParticleName())!=names+7;
}
Comment 1 Gabriele Cosmo 2006-11-16 01:28:59 CET
Thanks. The fix will be included in release 8.2.