Skip to content
Snippets Groups Projects
Commit 25d3a9a8 authored by Joseph Boudreau's avatar Joseph Boudreau
Browse files

Merge branch 'The-track-file-name-update' into 'master'

The tracks output file name update

See merge request !165
parents 129e775c 75431293
Branches
Tags v95r2p5g1
1 merge request!165The tracks output file name update
#include "TrksRunAction.h"
#include "TrksHDF5Factory.h"
#include <string>
#include <filesystem>
#include <set>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::map<G4int, G4int> TrksRunAction::fgTrkNums;
......@@ -26,8 +30,37 @@ void TrksRunAction::BeginOfRunAction(const G4Run* /*aRun*/)
{
if (IsMaster())
{
using namespace std;
namespace fs = std::filesystem;
set<string> fileNames;
string outputFileName;
fs::path pwdPath = fs::current_path();
for (const auto & entry : fs::directory_iterator(pwdPath))
{
fileNames.insert(entry.path());
}
for (int i=0; true; ++i)
{
outputFileName = "Tracks_data";
outputFileName += i == 0 ? "" : string("_") + to_string(i);
outputFileName+=".h5";
if (fileNames.find( string(pwdPath) + "/" + outputFileName) == fileNames.end())
{
break;
}
cout << "A file " << outputFileName << " already exists in the working directory. "
<< "Looking for another file name.\n";
}
TrksHDF5Factory* hdf5Factory = TrksHDF5Factory::GetInstance();
hdf5Factory->OpenFile("Tracks_data.h5");
hdf5Factory->OpenFile(outputFileName.c_str());
}
}
......@@ -60,7 +93,11 @@ void TrksRunAction::EndOfRunAction(const G4Run* /*aRun*/)
delete dataSet;
G4String outputFileName = file->getFileName();
file->close();
G4cout << "The file " << outputFileName << " has been created." << G4endl;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment