Message: Re: the problem of SetRandomNumberStoreDir function in G4RunManager.hh Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: the problem of SetRandomNumberStoreDir function in G4RunManager.hh 

Forum: Run Management
Re: None the problem of SetRandomNumberStoreDir function in G4RunManager.hh (Fada Guan)
Date: 11 Oct, 2010
From: Michael H. Kelsey <Michael H. Kelsey>

On Tue, 12 Oct 2010 03:07:04 GMT, Fada Guan wrote:
> To dear developers:
> 
> In Geant4.9.3p02 and later version 4.9.4.b01, the content of
> SetRandomNumberStoreDir function in G4RunManager.hh is:
> 
>     inline void SetRandomNumberStoreDir(const G4String& dir)
>     { 
>       G4String dirStr = dir;
>       if( dirStr(dirStr.length()-1) != '/' ) dirStr += "/";
> #ifndef WIN32
>       G4String shellCmd = "mkdir -p ";
> #else
>       std::replace(dirStr.begin(), dirStr.end(),'/','\\');
>       G4String shellCmd = "mkdir ";
> #endif
>       shellCmd += dirStr;
>       randomNumberStatusDir = dirStr;
>       system(shellCmd); 
>     }
> 
> I have some doubts about this function:
> 
> 1)std::replace(dirStr.begin(), dirStr.end(),'/','\\');
> 
> I guess it should be std::replace(dirStr.begin(), dirStr.end(),'/','\');

No. The "\" character in C and C++ is an "escape" -- it is used to flag the next character as representing something special; for example, '\t' is the tab character, ASCII 0x09, and '\n' is the carriage return, ASCII 0x0d. Since "\" by itself "eats" the next character, in order to represent the literal backslash used in DOS-style directory paths, the code must escape it, '\\'.

[...] > I'm working on a Linux system, so I don't know the influence of it.

You will never see that code executed, since it is inside a #if-block which is only compiled for WIN32.

> 2)system(shellCmd);
> 
> shellCmd is a string, but not a const char*, which is the type of the
> argument in the system function
[...] > system(shellCmd.c_str());

You are correct about this. I'm creating a low-priority bug report, so that it can be tracked and fixed.

-- Michael Kelsey

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: the problem of SetRandomNumberStoreDir function in G4RunManager.hh   (Fada Guan - 12 Oct, 2010)
(_ More: Re: the problem of SetRandomNumberStoreDir function in G4RunManager.hh   (Michael H. Kelsey - 14 Oct, 2010)
(_ None: Re: the problem of SetRandomNumberStoreDir function in G4RunManager.hh   (Fada Guan - 14 Oct, 2010)
 Add Message Add Message
to: "Re: the problem of SetRandomNumberStoreDir function in G4RunManager.hh"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]