Skip to content
Snippets Groups Projects

The tracks output file name update

Merged Denys Klekots requested to merge The-track-file-name-update into master
1 file
+ 38
1
Compare changes
  • Side-by-side
  • Inline
#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;
}
}
Loading