Problem 1266 - example crashes for undefined environment variable
Summary: example crashes for undefined environment variable
Status: RESOLVED FIXED
Alias: None
Product: Examples/Advanced
Classification: Unclassified
Component: xray_fluorescence (show other problems)
Version: other
Hardware: PC Linux
: P5 trivial
Assignee: alfonso.mantero
URL:
Depends on:
Blocks:
 
Reported: 2011-12-08 01:33 CET by jcook
Modified: 2012-08-15 17:38 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description jcook 2011-12-08 01:33:58 CET
Steps to reproduce:

Install Geant 4.9.5 on a RedHat 4 system with cmake 2.6.  Get confused about the new manner of handling data files and decided to forget about them for the moment.  Compile xray_fluorescence.  Start bin/Linux-g++/XrayFluo.  Select 1.


Actual result:

Program crashes with the following report:

...
DeviceSizeY(cm): 0.632456
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct NULL not valid
Aborted

User is confused.


Expected result:

G4Exception thrown.

...
DeviceSizeY(cm): 0.632456

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : example-xray_fluorescence07
      issued by : XrayFluoSiLiDetectorType::LoadResponseData()
XrayFluoSiLiDetectorType - environment variable XRAYDATA not set.
*** Fatal Exception *** core dump ***
-------- EEEE -------- G4Exception-END --------- EEEE -------

User is not confused.


Solution:

The problem is that getenv() returns a NULL if the environment variable is not found.  In XrayFluoSiLiDetectorType.cc, XrayFluoSiLiDetectorType::LoadResponseData(G4String fileName), make the following change.

  char* path = getenv("XRAYDATA");
  
  if (path==NULL)
    {
      G4ExceptionDescription execp;
      execp <<  "XrayFluoSiLiDetectorType - environment variable XRAYDATA not set.";
      G4Exception("XrayFluoSiLiDetectorType::LoadResponseData()","example-xray_fluorescence07",
		  FatalException, execp);
    }
  
  G4String pathString(path);



This is a quite trivial bug, but I suspect that I won't be the only person working without data files (even if only briefly) and the fix would be helpful to novice users.
Comment 1 alfonso.mantero 2012-08-15 17:38:22 CEST
Thank you for reporting the bug. Actually, it is sufficient to go to the xray_flurescence directory and issue "setenv XRAYDATA=$PWD" in tcsh or the equivalent in bash.

actually necessary data files are in the example dir.

best regards,

Alf