Import Geant4 11.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2025-06-26 09:17:29 +02:00
parent 20a218bbe1
commit a499fb82e9
1941 changed files with 203285 additions and 95593 deletions
+10
View File
@@ -6,6 +6,16 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2025-04-11 Makoto Asai (intercoms-V11-03-00)
- G4UImanager, G4UIcontrolMessenger
- Introducing "@@" keyword that can be placed in any UI command that takes
a macro file name. It creates a temporal macro file with following commands
until /control/endRecord command comes. This “@@” mechanism works recursively.
- If a file name is enclosed in a pair of "@", that macro file is created.
- This mechanism works for both interactive mode and batch mode. When used in
interactive mode with Qt GUI, you can use up-arrow, tab-key and clickable
menu in left-side bar to complement a command.
## 2024-07-29 John Allison (intercoms-V11-02-07)
- G4UImanager::ApplyCommand:
- Replace `isMaster` by `G4Threading::IsMasterThread()`.
+11
View File
@@ -244,6 +244,11 @@ class G4UImanager : public G4VStateDependent
inline bool IsLastCommandOutputTreated() { return fLastCommandOutputTreated; }
inline void SetLastCommandOutputTreated() { fLastCommandOutputTreated = true; }
void StartRecording(G4String fn, G4bool ifAppend,
G4bool ifTemp=false, G4String assocCmd="**NOCMD**");
void RecordCommand(const G4String& aCommand);
G4int EndRecording();
protected:
G4UImanager();
@@ -293,6 +298,12 @@ class G4UImanager : public G4VStateDependent
G4int lastRC = 0;
G4bool fLastCommandOutputTreated = true;
G4int fRecordDepth = -1;
std::vector<std::ofstream*> fRecordFile;
std::vector<std::pair<G4String,G4bool>> fRecordFileName;
std::vector<G4String> fAccosiatedCommand;
};
#endif
@@ -62,6 +62,8 @@
// /control/ifInteractive
// /control/doifBatch
// /control/doifInteractive
// /control/recordToMacro
// /control/endRecord
// Author: Makoto Asai, SLAC - 2001
// --------------------------------------------------------------------
@@ -119,6 +121,8 @@ class G4UIcontrolMessenger : public G4UImessenger
G4UIcmdWithAString* ifInteractiveCommand = nullptr;
G4UIcmdWithAString* doifBatchCommand = nullptr;
G4UIcmdWithAString* doifInteractiveCommand = nullptr;
G4UIcommand* recordToMacroCommand = nullptr;
G4UIcmdWithoutParameter* endRecordCommand = nullptr;
};
#endif
@@ -344,6 +344,24 @@ G4UIcontrolMessenger::G4UIcontrolMessenger()
"Execute a UI command if program is running in interactive mode.");
doifInteractiveCommand->SetParameterName("UIcommand", false);
doifInteractiveCommand->SetToBeBroadcasted(false);
recordToMacroCommand = new G4UIcommand("/control/recordToMacro",this);
recordToMacroCommand->SetGuidance(
"Record the following UI command(s) into a macro file instead of executing it/them.");
recordToMacroCommand->SetGuidance(
"Recording lasts until a command \"/control/endRecord\" comes.");
recordToMacroCommand->SetGuidance(
"if <ifAppend> is set to true (default false), commands are appended to the existing file.");
auto* recordToMacroCommandParam = new G4UIparameter("fileName",'s',false);
recordToMacroCommand->SetParameter(recordToMacroCommandParam);
recordToMacroCommandParam = new G4UIparameter("ifAppend",'b',true);
recordToMacroCommandParam->SetDefaultValue(false);
recordToMacroCommand->SetParameter(recordToMacroCommandParam);
recordToMacroCommand->SetToBeBroadcasted(false);
endRecordCommand = new G4UIcmdWithoutParameter("/control/endRecord", this);
endRecordCommand->SetGuidance("Stop recording to a macro");
endRecordCommand->SetToBeBroadcasted(false);
}
// --------------------------------------------------------------------
@@ -381,6 +399,8 @@ G4UIcontrolMessenger::~G4UIcontrolMessenger()
delete ifInteractiveCommand;
delete doifBatchCommand;
delete doifInteractiveCommand;
delete recordToMacroCommand;
delete endRecordCommand;
delete controlDirectory;
}
@@ -701,6 +721,15 @@ void G4UIcontrolMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
UI->ApplyCommand(newValue);
}
}
if (command == recordToMacroCommand) {
G4Tokenizer next(newValue);
const G4String& fn = next();
G4bool ifAppend = StoB(next());
UI->StartRecording(fn,ifAppend);
}
if (command == endRecordCommand) {
UI->ApplyCommand("/control/endRecord");
}
}
// --------------------------------------------------------------------
+107 -3
View File
@@ -43,10 +43,12 @@
#include "G4UIcontrolMessenger.hh"
#include "G4UIsession.hh"
#include "G4UnitsMessenger.hh"
#include "G4Filesystem.hh"
#include "G4ios.hh"
#include <fstream>
#include <sstream>
#include <system_error>
G4bool G4UImanager::doublePrecisionStr = false;
G4int G4UImanager::igThreadID = -1;
@@ -445,9 +447,14 @@ G4int G4UImanager::ApplyCommand(const G4String& aCmd)
// --------------------------------------------------------------------
G4int G4UImanager::ApplyCommand(const char* aCmd)
{
const G4String& aCommand = SolveAlias(aCmd);
if (aCommand.empty()) {
return fAliasNotFound;
G4String aCommand = aCmd;
if(fRecordDepth<0)
{
// while recording a command to a macro file, skip solving and record the command as-is
aCommand = SolveAlias(aCmd);
if (aCommand.empty()) {
return fAliasNotFound;
}
}
if (verboseLevel != 0) {
if (G4Threading::IsMasterThread()) {
@@ -458,6 +465,36 @@ G4int G4UImanager::ApplyCommand(const char* aCmd)
G4String commandString;
G4String commandParameter;
std::size_t iAt = aCommand.find('@');
if (iAt != std::string::npos) {
G4String commandStr1 = aCommand.substr(0,iAt);
G4String commandStr2 = aCommand.substr(iAt+1,aCommand.length() - (iAt + 1));
std::size_t iAt2 = commandStr2.find('@');
G4String tmpFileName;
G4bool tmpFile = false;
if (iAt2 != std::string::npos) {
if(iAt2 == 0) {
// Two '@'s are connected. temporal file will be created
tmpFileName = "tmptmp_";
tmpFileName += G4UIcommand::ConvertToString(fRecordDepth+1);
tmpFileName += ".tmpmac";
tmpFile = true;
} else {
tmpFileName = commandStr2.substr(0,iAt2);
}
} else {
return fAliasNotFound;
}
G4String commandStr3 = commandStr2.substr(iAt2+1,commandStr2.length()-(iAt2+1));
G4String revisedCommand = commandStr1;
revisedCommand += " ";
revisedCommand += tmpFileName;
revisedCommand += " ";
revisedCommand += commandStr3;
StartRecording(tmpFileName,false,tmpFile,revisedCommand);
return fCommandSucceeded;
}
std::size_t i = aCommand.find(' ');
if (i != std::string::npos) {
commandString = aCommand.substr(0, i);
@@ -527,6 +564,16 @@ G4int G4UImanager::ApplyCommand(const char* aCmd)
}
histVec.push_back(aCommand);
if(fRecordDepth>=0) {
if(aCommand == "/control/endRecord") {
EndRecording();
return fCommandSucceeded;
} else if(commandString != "/control/recordToMacro") {
RecordCommand(aCommand);
return fCommandSucceeded;
}
}
targetCommand->ResetFailure();
G4int commandFailureCode = targetCommand->DoIt(commandParameter);
if (commandFailureCode == 0) {
@@ -877,6 +924,7 @@ void G4UImanager::SetThreadIgnoreInit(G4bool flg)
threadCout->SetIgnoreInit(flg);
}
// --------------------------------------------------------------------
G4UIsession* G4UImanager::GetBaseSession() const
{
// There may be no session - pure batch mode (session == nullptr)
@@ -896,3 +944,59 @@ G4UIsession* G4UImanager::GetBaseSession() const
}
return baseSession;
}
// --------------------------------------------------------------------
void G4UImanager::StartRecording(G4String fn, G4bool ifAppend, G4bool ifTemp, G4String assocCmd)
{
fRecordDepth++;
fRecordFileName.push_back(std::pair<G4String,G4bool>(fn,ifTemp));
fAccosiatedCommand.push_back(assocCmd);
G4cout << "G4UImanager::StartRecording [" << fRecordDepth << "] " << fn << G4endl;
auto mode = std::ios_base::out;
if(ifAppend) mode = std::ios_base::app;
auto rf = new std::ofstream;
rf->open(fn,mode);
fRecordFile.push_back(rf);
}
// --------------------------------------------------------------------
void G4UImanager::RecordCommand(const G4String& aCommand)
{
*(fRecordFile[fRecordDepth]) << aCommand << G4endl;
}
// --------------------------------------------------------------------
G4int G4UImanager::EndRecording()
{
G4int retVal = fCommandSucceeded;
fRecordFile[fRecordDepth]->close();
delete fRecordFile[fRecordDepth];
fRecordFile.pop_back();
G4String assocCmd = fAccosiatedCommand[fRecordDepth];
fAccosiatedCommand.pop_back();
G4cout << "G4UImanager::EndRecording [" << fRecordDepth << "] "
<< fRecordFileName[fRecordDepth].first << G4endl;
fRecordDepth--;
if(assocCmd!="**NOCMD**") {
retVal = ApplyCommand(assocCmd);
}
if(fRecordDepth<0) {
while(fRecordFileName.size()>0) {
G4String fn = fRecordFileName.back().first;
G4bool ifTemp = fRecordFileName.back().second;
fRecordFileName.pop_back();
if(ifTemp) {
std::error_code ec;
G4bool res = G4fs::remove(fn.c_str(), ec);
if(!res) {
G4ExceptionDescription ed;
ed << "Error removing temporary macro file " << fn << " : "
<< ec.message();
G4Exception("G4UImanager::EndRecording()", "UIMAN0801", JustWarning, ed);
}
}
}
}
return retVal;
}