17#include "TSystemDirectory.h"
19#include <boost/algorithm/string.hpp>
38 RepoInfo GetRepoInfo(std::string fileName) {
39 std::string svnInfo = gSystem->GetFromPipe(("svn info " + fileName).c_str()).Data();
41 if (std::regex_search(svnInfo, match, std::regex(R"(Last Changed Author: (.*)\nLast Changed Rev: (.*)\nLast Changed Date: (.*))")))
42 return {match[1], match[2], match[3]};
57 std::map<ECbmModuleId, DetInfo> detectorMap {
78 std::vector<std::string> ListDirectory(std::string path, std::string searchPattern)
80 TList* fileList = TSystemDirectory(
"", path.c_str()).GetListOfFiles();
82 std::regex setupRegex(searchPattern);
84 std::vector<std::string> result;
85 for (
const auto&& file : *fileList) {
86 std::string fileName = file->GetName();
88 if (std::regex_search(fileName, match, setupRegex)) result.push_back(match[1]);
99 std::string path = gSystem->Getenv(
"VMCWORKDIR");
100 path +=
"/geometry/setup";
101 return ListDirectory(path, R
"(setup_(.*).C)");
106 std::string path = gSystem->Getenv("VMCWORKDIR");
108 return ListDirectory(path, R
"(field_(.*).root)");
113 std::string path = gSystem->Getenv("VMCWORKDIR");
114 path +=
"/geometry/media";
115 return ListDirectory(path, R
"(media_(.*).geo)");
125 LOG(warn) <<
"-W- LoadSetup " << setupTag <<
": overwriting existing setup " <<
fSetup.
GetTag();
128 LOG(info) <<
"Loading CbmGeoSetup from svn repository.\nSetup tag: " << setupTag
129 <<
" Revision: " << (revision.empty() ?
"latest" : revision);
131 std::string base = gSystem->Getenv(
"VMCWORKDIR");
132 std::string geoDir = base +
"/geometry/";
133 std::string fieldDir = base +
"/input/";
134 std::string setupFilePath = base;
135 setupFilePath +=
"/geometry/setup/setup_" + setupTag +
".C";
136 std::ifstream setupFile(setupFilePath);
137 std::string fileContents((std::istreambuf_iterator<char>(setupFile)), std::istreambuf_iterator<char>());
140 std::regex commentRegex(
"/[/]+.*");
141 std::string replacementString {
""};
142 fileContents = std::regex_replace(fileContents, commentRegex, replacementString);
146 std::regex_search(fileContents, match, std::regex(R
"(.*setup->SetTitle\(\"(\w+)\"\);)"));
147 std::string setupName = match[1];
150 std::regex_search(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(fileContents, match, std::regex(R
"(fieldX\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
158 fieldX = std::stod(match[1]);
159 if (std::regex_search(fileContents, match, std::regex(R
"(fieldY\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
160 fieldY = std::stod(match[1]);
161 if (std::regex_search(fileContents, match, std::regex(R
"(fieldZ\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
162 fieldZ = std::stod(match[1]);
163 if (std::regex_search(fileContents, match, std::regex(R
"(fieldScale\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
164 fieldScale = std::stod(match[1]);
167 std::string mediaTag;
168 std::string mediaFilePath;
169 if (std::regex_search(fileContents, match, std::regex(R
"(mediaTag\s+=\s+\"(\w+)\";)"))) {
171 mediaFilePath = geoDir + "media/media_" + mediaTag +
".geo";
175 std::map<ECbmModuleId, CbmGeoSetupModule> moduleMap;
176 for (
auto detector : detectorMap) {
178 std::regex tagRegex(R
"(.*)" + detector.second.tag + R"(\s+=\s+\"([\w:]+)\";)");
179 std::regex setModuleRegex(R"(.*SetModule\(.*)" + detector.second.tag + R"(\);)");
182 if (std::regex_search(fileContents, match, tagRegex)) { tag = match[1]; }
183 if (std::regex_search(fileContents, match, setModuleRegex)) { added =
true; }
185 if (tag.size() && added) {
198 field.
GetMatrix().SetTranslation(fieldX, fieldY, fieldZ);
221 std::string base = gSystem->Getenv(
"VMCWORKDIR");
222 std::string geoDir = base +
"/geometry/";
224 auto detector = detectorMap[moduleId];
226 std::string full_file_path;
229 std::vector<std::string> _geom;
230 boost::split(_geom, tag, [](
char c) {
return c ==
':'; });
231 for (
auto&
string : _geom) {
233 std::string geoFilePath =
234 geoDir + (detector.dir.size() ? detector.dir +
"/" : detector.dir) + detector.system +
"_" +
string +
".geo.root";
236 if (gSystem->AccessPathName(geoFilePath.c_str()) == kTRUE) {
237 geoFilePath.erase(geoFilePath.size() - 5);
238 if (gSystem->AccessPathName(geoFilePath.c_str()) == kTRUE) {
239 LOG(error) <<
"Geometry file not found for " << detector.system;
246 if (geoFilePath.find(geoDir) != std::string::npos) geoFilePath.replace(0, geoDir.size(),
"");
248 full_file_path += geoFilePath;
249 full_file_path +=
":";
251 full_file_path.pop_back();
254 module.SetName(detector.name);
255 module.SetFilePath(full_file_path);
257 module.SetModuleId(moduleId);
261 module.SetActive(kTRUE);
268 std::string base = std::string(gSystem->Getenv(
"VMCWORKDIR")) +
"/";
269 std::string fieldDir = base +
"input/";
271 std::string fieldFilePath = fieldDir +
"field_" + tag +
".root";
273 if (gSystem->AccessPathName(fieldFilePath.c_str()) == kTRUE) {
274 LOG(error) <<
"Field file not found for tag " << tag;
278 if (fieldFilePath.find(base) != std::string::npos) fieldFilePath.replace(0, base.size(),
"");
290 std::string base = std::string(gSystem->Getenv(
"VMCWORKDIR")) +
"/";
291 std::string geoDir = base +
"geometry/";
292 std::string mediaDir = base +
"geometry/media/";
294 std::string mediaFilePath = mediaDir +
"media_" + tag +
".geo";
296 if (gSystem->AccessPathName(mediaFilePath.c_str()) == kTRUE) {
297 LOG(warn) <<
"Media file not found for tag " << (tag.size() ?
"(empty)" : tag) <<
" using default media.geo";
299 mediaFilePath = geoDir +
"media.geo";
305 if (mediaFilePath.find(geoDir) != std::string::npos) mediaFilePath.replace(0, geoDir.size(),
"");
@ kMvd
Micro-Vertex Detector.
@ kHodo
Hodoscope (for test beam times)
@ kTrd
Transition Radiation Detector.
@ kShield
Beam pipe shielding in MUCH section.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kPlatform
RICH rail platform.
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kRich
Ring-Imaging Cherenkov Detector.
ClassImp(CbmGeoSetupRepoProvider)
TGeoTranslation & GetMatrix()
void SetScale(Double_t value)
void SetFilePath(std::string value)
void SetTag(std::string value)
CbmGeoSetupModule GetDefaultCaveModule()
Gets defauk cave if none was provided by the other means.
Setup provider with local (svn) repository functionality.
virtual CbmGeoSetupModule GetModuleByTag(ECbmModuleId moduleId, std::string tag)
Abstract method for constructing the module by id and tag.
virtual CbmGeoSetupField GetFieldByTag(std::string tag)
Abstract method for constructing the field by tag.
virtual std::vector< std::string > GetSetupTags()
Abstract method to get the list of setup tags.
virtual CbmGeoSetup GetSetupByTag(std::string setupTag, std::string revision)
virtual std::vector< std::string > GetFieldTags()
Abstract method to get the list of field tags.
virtual CbmGeoSetupMedia GetMediaByTag(std::string tag)
Abstract method for constructing the media by tag.
virtual std::vector< std::string > GetMediaTags()
Abstract method to get the list of media tags.
virtual void LoadSetup(std::string setupTag, std::string revision="")
Data transfer object to represent the CBM Detector setup.
void SetName(std::string value)
void SetField(CbmGeoSetupField value)
CbmGeoSetupField & GetField()
CbmGeoSetupMedia & GetMedia()
void SetTag(std::string value)
void SetMedia(CbmGeoSetupMedia value)
void SetModuleMap(std::map< ECbmModuleId, CbmGeoSetupModule > value)
std::map< ECbmModuleId, CbmGeoSetupModule > & GetModuleMap()