|
1 | 1 | #include <cstdlib> |
2 | 2 | #include <filesystem> |
| 3 | +#include <fstream> |
3 | 4 | #include <iostream> |
4 | 5 | #include <stdexcept> |
5 | 6 | #include <string> |
@@ -28,8 +29,22 @@ bool FileExists(const std::string &path) |
28 | 29 | return std::filesystem::exists(path, ec) && !ec; |
29 | 30 | } |
30 | 31 |
|
| 32 | +std::filesystem::path DefaultOutputDir() |
| 33 | +{ |
| 34 | + return std::filesystem::current_path(); |
| 35 | +} |
| 36 | + |
| 37 | +std::filesystem::path ReadOutputDir(const nlohmann::json& event) |
| 38 | +{ |
| 39 | + if (event.contains("output_dir")) |
| 40 | + return event["output_dir"].get<std::string>(); |
| 41 | + |
| 42 | + return DefaultOutputDir(); |
| 43 | +} |
| 44 | + |
31 | 45 | Config::Config(std::string config_name) : |
32 | | - name{std::getenv("GPHOX_CONFIG") ? std::getenv("GPHOX_CONFIG") : config_name} |
| 46 | + name{config_name}, |
| 47 | + output_dir{DefaultOutputDir()} |
33 | 48 | { |
34 | 49 | ReadConfig(Locate(name + ".json")); |
35 | 50 | } |
@@ -111,31 +126,36 @@ void Config::ReadConfig(std::string filepath) |
111 | 126 | std::ifstream ifs(filepath); |
112 | 127 | ifs >> json; |
113 | 128 |
|
114 | | - nlohmann::json torch_ = json["torch"]; |
115 | | - |
116 | | - torch = { |
117 | | - .gentype = OpticksGenstep_::Type(torch_["gentype"]), |
118 | | - .trackid = torch_["trackid"], |
119 | | - .matline = torch_["matline"], |
120 | | - .numphoton = torch_["numphoton"], |
121 | | - .pos = make_float3(torch_["pos"][0], torch_["pos"][1], torch_["pos"][2]), |
122 | | - .time = torch_["time"], |
123 | | - .mom = normalize(make_float3(torch_["mom"][0], torch_["mom"][1], torch_["mom"][2])), |
124 | | - .weight = torch_["weight"], |
125 | | - .pol = make_float3(torch_["pol"][0], torch_["pol"][1], torch_["pol"][2]), |
126 | | - .wavelength = torch_["wavelength"], |
127 | | - .zenith = make_float2(torch_["zenith"][0], torch_["zenith"][1]), |
128 | | - .azimuth = make_float2(torch_["azimuth"][0], torch_["azimuth"][1]), |
129 | | - .radius = torch_["radius"], |
130 | | - .distance = torch_["distance"], |
131 | | - .mode = torch_["mode"], |
132 | | - .type = storchtype::Type(torch_["type"]) |
133 | | - }; |
| 129 | + if (json.contains("torch")) { |
| 130 | + nlohmann::json torch_ = json["torch"]; |
| 131 | + |
| 132 | + torch = { |
| 133 | + .gentype = OpticksGenstep_::Type(torch_["gentype"]), |
| 134 | + .trackid = torch_["trackid"], |
| 135 | + .matline = torch_["matline"], |
| 136 | + .numphoton = torch_["numphoton"], |
| 137 | + .pos = make_float3(torch_["pos"][0], torch_["pos"][1], torch_["pos"][2]), |
| 138 | + .time = torch_["time"], |
| 139 | + .mom = normalize(make_float3(torch_["mom"][0], torch_["mom"][1], torch_["mom"][2])), |
| 140 | + .weight = torch_["weight"], |
| 141 | + .pol = make_float3(torch_["pol"][0], torch_["pol"][1], torch_["pol"][2]), |
| 142 | + .wavelength = torch_["wavelength"], |
| 143 | + .zenith = make_float2(torch_["zenith"][0], torch_["zenith"][1]), |
| 144 | + .azimuth = make_float2(torch_["azimuth"][0], torch_["azimuth"][1]), |
| 145 | + .radius = torch_["radius"], |
| 146 | + .distance = torch_["distance"], |
| 147 | + .mode = torch_["mode"], |
| 148 | + .type = storchtype::Type(torch_["type"]) |
| 149 | + }; |
| 150 | + } |
134 | 151 |
|
135 | 152 | nlohmann::json event_ = json["event"]; |
136 | 153 |
|
| 154 | + output_dir = ReadOutputDir(event_); |
| 155 | + |
137 | 156 | SEventConfig::SetEventMode( string(event_["mode"]).c_str() ); |
138 | 157 | SEventConfig::SetMaxSlot( event_["maxslot"] ); |
| 158 | + SEventConfig::SetOutFold(output_dir.string().c_str()); |
139 | 159 | } |
140 | 160 | catch (nlohmann::json::exception& e) { |
141 | 161 | std::string errmsg{"Failed reading config parameters from " + filepath + "\n" + e.what()}; |
|
0 commit comments