gsystem
Loading...
Searching...
No Matches
systemTextFactory.cc
Go to the documentation of this file.
1
8// string for gexit
9#include "gutilities.h"
10
11// gsystem
12#include "systemTextFactory.h"
13#include "gsystemConventions.h"
14
15// cpp
16#include <fstream>
17
18// returns the file stream, checking all possible directories.
19// SYSTEMTYPE can be:
20// - GTEXTGEOMTYPE (mandatory, exit if not found)
21// - GTEXTMATSTYPE
22std::ifstream* GSystemTextFactory::gSystemTextFileStream(GSystem* system, const std::string& SYSTEMTYPE) {
23 std::string fileName = system->getFilePath();
24 std::string variation = system->getVariation();
25 std::string fname = fileName + SYSTEMTYPE + variation + ".txt";
26
27 log->info(0, "gSystemTextFileStream filename is: ", fname);
28
29 // default dir is "."
30 auto IN = new std::ifstream(fname.c_str());
31
32 if (IN->good()) {
33 log->info(1, "Trying file ", fname);
34 return IN;
35 }
36 else {
37 // file not good, now trying other locations
38 for (const auto& trialLocation : possibleLocationOfFiles) {
39 std::string newName = trialLocation + "/" + fname;
40
41 log->info(1, "Trying file ", newName);
42
43 IN->open(newName.c_str());
44 if (IN->good()) {
45 // file found, return stream
46 log->info(1, "Trying file ", newName);
47 return IN;
48 }
49 }
50 }
51
52 // at this point the file was not found
53 // this could be ok if we are looking for the material file - if the system annotation is 'mats_only'
54 if (SYSTEMTYPE == GTEXTGEOMTYPE) {
55 if (system->getAnnotations() == "mats_only") {
56 log->info(1, "File ", fname, " not found, but this is ok because the system annotation is 'mats_only'");
57 return nullptr;
58 }
59 log->error(ERR_GSETUPFILENOTOFOUND, "File ", fname, " not found.");
60 }
61
62 // the file was not found
63 return nullptr;
64}
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
std::vector< std::string > possibleLocationOfFiles
List of candidate directories used by file-based factories.
Represents a single detector system (e.g., calorimeter, tracker).
Definition gsystem.h:32
std::string getAnnotations() const
Definition gsystem.h:112
std::string getVariation() const
Definition gsystem.h:110
std::string getFilePath()
Gets the full file path of the system.
Definition gsystem.cc:194
Conventions and shared constants for the detector-system module.
#define ERR_GSETUPFILENOTOFOUND
#define GTEXTGEOMTYPE