Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions gemc/gsystem/gsystemFactories/text/loadGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ void GSystemTextFactory::loadGeometry(GSystem* system) {
gutilities::getStringVectorFromStringWithDelimiter(dbline, "|");
system->addGVolume(gvolumePars);
}

IN->close();
// IN (unique_ptr<ifstream>) closes the file and frees the stream on scope exit.
}
}
3 changes: 1 addition & 2 deletions gemc/gsystem/gsystemFactories/text/loadMaterials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void GSystemTextFactory::loadMaterials(GSystem* system) {
gutilities::getStringVectorFromStringWithDelimiter(dbline, "|");
system->addGMaterial(gmaterialsPars);
}

IN->close();
// IN (unique_ptr<ifstream>) closes the file and frees the stream on scope exit.
}
}
5 changes: 3 additions & 2 deletions gemc/gsystem/gsystemFactories/text/systemTextFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

// cpp
#include <fstream>
#include <memory>

// returns the file stream, checking all possible directories.
// SYSTEMTYPE can be:
// - GTEXTGEOMTYPE (mandatory, exit if not found)
// - GTEXTMATSTYPE
std::ifstream* GSystemTextFactory::gSystemTextFileStream(GSystem* system, const std::string& SYSTEMTYPE) {
std::unique_ptr<std::ifstream> GSystemTextFactory::gSystemTextFileStream(GSystem* system, const std::string& SYSTEMTYPE) {
std::string fileName = system->getFilePath();
std::string variation = system->getVariation();
std::string fname = fileName + SYSTEMTYPE + variation + ".txt";

log->info(0, "gSystemTextFileStream filename is: ", fname);

// default dir is "."
auto IN = new std::ifstream(fname.c_str());
auto IN = std::make_unique<std::ifstream>(fname.c_str());

if (IN->good()) {
log->info(1, "Trying file ", fname);
Expand Down
6 changes: 5 additions & 1 deletion gemc/gsystem/gsystemFactories/text/systemTextFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// gsystem
#include <gemc/gsystem/gsystemFactories/systemFactory.h>

// c++
#include <fstream>
#include <memory>

// file types
#define GTEXTGEOMTYPE "__geometry_"
#define GTEXTMATSTYPE "__materials_"
Expand Down Expand Up @@ -76,5 +80,5 @@ class GSystemTextFactory : public GSystemFactory
* - For geometry, failure to locate a file triggers an error unless \c system->getAnnotations() is \c "mats_only".
* - For materials, failure to locate a file is treated as "no materials provided".
*/
std::ifstream* gSystemTextFileStream(GSystem* system, const std::string& SYSTEMTYPE);
std::unique_ptr<std::ifstream> gSystemTextFileStream(GSystem* system, const std::string& SYSTEMTYPE);
};