11 #include <boost/algorithm/string.hpp>
14 #include "TSystemDirectory.h"
16 #include "FairLogger.h"
52 std::map<ECbmModuleId, DetInfo> detectorMap {
70 {
"platGeoTag",
"passive",
"platform",
"PLATFORM"}},
74 std::vector<std::string> ListDirectory(std::string path,
75 std::string searchPattern) {
76 TList* fileList = TSystemDirectory(
"", path.c_str()).GetListOfFiles();
78 std::regex setupRegex(searchPattern);
80 std::vector<std::string> result;
81 for (
const auto& file : *fileList) {
82 std::string fileName = file->GetName();
84 if (std::regex_search(fileName, match, setupRegex))
85 result.push_back(match[1]);
95 std::string path = gSystem->Getenv(
"VMCWORKDIR");
96 path +=
"/geometry/setup";
97 return ListDirectory(path, R
"(setup_(.*).C)");
101 std::string path = gSystem->Getenv("VMCWORKDIR");
103 return ListDirectory(path, R
"(field_(.*).root)");
107 std::string path = gSystem->Getenv("VMCWORKDIR");
108 path +=
"/geometry/media";
109 return ListDirectory(path, R
"(media_(.*).geo)");
117 std::string revision) {
119 LOG(warn) <<
"-W- LoadSetup " << setupTag <<
": overwriting existing setup "
123 LOG(info) <<
"Loading CbmGeoSetup from svn repository.\nSetup tag: "
125 <<
" Revision: " << (revision.empty() ?
"latest" : revision);
127 std::string base = gSystem->Getenv(
"VMCWORKDIR");
128 std::string geoDir = base +
"/geometry/";
129 std::string fieldDir = base +
"/input/";
130 std::string setupFilePath = base;
131 setupFilePath +=
"/geometry/setup/setup_" + setupTag +
".C";
132 std::ifstream setupFile(setupFilePath);
133 std::string fileContents((std::istreambuf_iterator<char>(setupFile)),
134 std::istreambuf_iterator<char>());
137 std::regex commentRegex(
"/[/]+.*");
138 std::string replacementString {
""};
140 std::regex_replace(fileContents, commentRegex, replacementString);
145 fileContents, match, std::regex(R
"(.*setup->SetTitle\(\"(\w+)\"\);)"));
146 std::string setupName = match[1];
150 fileContents, match, std::regex(R
"(fieldTag\s+=\s+\"(\w+)\";)"));
151 std::string fieldTag = match[1];
152 std::string fieldFilePath = fieldDir + "field_" + fieldTag +
".root";
155 Double_t fieldX = 0., fieldY = 0., fieldZ = 40., fieldScale = 1.;
157 if (std::regex_search(
160 std::regex(R
"(fieldX\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
161 fieldX = std::stod(match[1]);
162 if (std::regex_search(
165 std::regex(R
"(fieldY\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
166 fieldY = std::stod(match[1]);
167 if (std::regex_search(
170 std::regex(R
"(fieldZ\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
171 fieldZ = std::stod(match[1]);
172 if (std::regex_search(
175 std::regex(R
"(fieldScale\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
176 fieldScale = std::stod(match[1]);
179 std::string mediaTag;
180 std::string mediaFilePath;
181 if (std::regex_search(
182 fileContents, match, std::regex(R
"(mediaTag\s+=\s+\"(\w+)\";)"))) {
184 mediaFilePath = geoDir + "media/media_" + mediaTag +
".geo";
188 std::map<ECbmModuleId, CbmGeoSetupModule> moduleMap;
189 for (
auto detector : detectorMap) {
191 std::regex tagRegex(R
"(.*)" + detector.second.tag
192 + R"(\s+=\s+\"([\w:]+)\";)");
193 std::regex setModuleRegex(R"(.*SetModule\(.*)" + detector.second.tag
197 if (std::regex_search(fileContents, match, tagRegex)) { tag = match[1]; }
198 if (std::regex_search(fileContents, match, setModuleRegex)) {
202 if (tag.size() && added) {
215 field.
GetMatrix().SetTranslation(fieldX, fieldY, fieldZ);
238 std::string base = gSystem->Getenv(
"VMCWORKDIR");
239 std::string geoDir = base +
"/geometry/";
241 auto detector = detectorMap[moduleId];
243 std::string full_file_path;
246 std::vector<std::string> _geom;
247 boost::split(_geom, tag, [](
char c) {
return c ==
':'; });
248 for (
auto&
string : _geom) {
250 std::string geoFilePath =
251 geoDir + (detector.dir.size() ? detector.dir +
"/" : detector.dir)
252 + detector.system +
"_" +
string +
".geo.root";
254 if (gSystem->AccessPathName(geoFilePath.c_str())
256 geoFilePath.erase(geoFilePath.size() - 5);
257 if (gSystem->AccessPathName(geoFilePath.c_str()) == kTRUE) {
258 LOG(error) <<
"Geometry file not found for " << detector.system;
265 if (geoFilePath.find(geoDir) != std::string::npos)
266 geoFilePath.replace(0, geoDir.size(),
"");
268 full_file_path += geoFilePath;
269 full_file_path +=
":";
271 full_file_path.pop_back();
287 std::string base = std::string(gSystem->Getenv(
"VMCWORKDIR")) +
"/";
288 std::string fieldDir = base +
"input/";
290 std::string fieldFilePath = fieldDir +
"field_" + tag +
".root";
292 if (gSystem->AccessPathName(fieldFilePath.c_str())
294 LOG(error) <<
"Field file not found for tag " << tag;
298 if (fieldFilePath.find(base) != std::string::npos)
299 fieldFilePath.replace(0, base.size(),
"");
310 std::string base = std::string(gSystem->Getenv(
"VMCWORKDIR")) +
"/";
311 std::string geoDir = base +
"geometry/";
312 std::string mediaDir = base +
"geometry/media/";
314 std::string mediaFilePath = mediaDir +
"media_" + tag +
".geo";
316 if (gSystem->AccessPathName(mediaFilePath.c_str())
318 LOG(warn) <<
"Media file not found for tag "
319 << (tag.size() ?
"(empty)" : tag) <<
" using default media.geo";
321 mediaFilePath = geoDir +
"media.geo";
327 if (mediaFilePath.find(geoDir) != std::string::npos)
328 mediaFilePath.replace(0, geoDir.size(),
"");
344 std::string revision) {