14#include "TSystemDirectory.h"
18#include <boost/algorithm/string.hpp>
37 RepoInfo GetRepoInfo(std::string fileName) {
38 std::string svnInfo = gSystem->GetFromPipe(("svn info " + fileName).c_str()).Data();
40 if (std::regex_search(svnInfo, match, std::regex(R"(Last Changed Author: (.*)\nLast Changed Rev: (.*)\nLast Changed Date: (.*))")))
41 return {match[1], match[2], match[3]};
56 std::map<ECbmModuleId, DetInfo> detectorMap{
77 std::vector<std::string> ListDirectory(std::string path, std::string searchPattern)
79 TList* fileList = TSystemDirectory(
"", path.c_str()).GetListOfFiles();
81 std::regex setupRegex(searchPattern);
83 std::vector<std::string> result;
84 for (
const auto&& file : *fileList) {
85 std::string fileName = file->GetName();
87 if (std::regex_search(fileName, match, setupRegex)) result.push_back(match[1]);
98 std::string path = gSystem->Getenv(
"VMCWORKDIR");
99 path +=
"/geometry/setup";
100 return ListDirectory(path, R
"(setup_(.*).C)");
105 std::string path = gSystem->Getenv("VMCWORKDIR");
107 return ListDirectory(path, R
"(field_(.*).root)");
112 std::string path = gSystem->Getenv("VMCWORKDIR");
113 path +=
"/geometry/media";
114 return ListDirectory(path, R
"(media_(.*).geo)");
123 if (
fSetup.GetModuleMap().size()) {
124 LOG(warn) <<
"-W- LoadSetup " << setupTag <<
": overwriting existing setup " <<
fSetup.GetTag();
127 LOG(info) <<
"Loading CbmGeoSetup from repository.\nSetup tag: " << setupTag
128 <<
" Revision: " << (revision.empty() ?
"latest" : revision);
130 std::string base = gSystem->Getenv(
"VMCWORKDIR");
131 std::string geoDir = base +
"/geometry/";
132 std::string fieldDir = base +
"/input/";
133 std::string setupFilePath = base;
134 setupFilePath +=
"/geometry/setup/setup_" + setupTag +
".C";
135 std::ifstream setupFile(setupFilePath);
136 std::string fileContents((std::istreambuf_iterator<char>(setupFile)), std::istreambuf_iterator<char>());
139 std::regex commentRegex(
"/[/]+.*");
140 std::string replacementString{
""};
141 fileContents = std::regex_replace(fileContents, commentRegex, replacementString);
145 std::regex_search(fileContents, match, std::regex(R
"(.*setup->SetTitle\(\"(\w+)\"\);)"));
146 std::string setupName = match[1];
149 std::regex_search(fileContents, match, std::regex(R
"(fieldTag\s+=\s+\"(\w+)\";)"));
150 std::string fieldTag = match[1];
151 std::string fieldFilePath = fieldDir + "field_" + fieldTag +
".root";
154 Double_t fieldX = 0., fieldY = 0., fieldZ = 40., fieldScale = 1.;
156 if (std::regex_search(fileContents, match, std::regex(R
"(fieldX\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
157 fieldX = std::stod(match[1]);
158 if (std::regex_search(fileContents, match, std::regex(R
"(fieldY\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
159 fieldY = std::stod(match[1]);
160 if (std::regex_search(fileContents, match, std::regex(R
"(fieldZ\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
161 fieldZ = std::stod(match[1]);
162 if (std::regex_search(fileContents, match, std::regex(R
"(fieldScale\s+=\s+([-+]?(\d+)?(\.\d+)?(\.)?);)")))
163 fieldScale = std::stod(match[1]);
166 std::string mediaTag;
167 std::string mediaFilePath;
168 if (std::regex_search(fileContents, match, std::regex(R
"(mediaTag\s+=\s+\"(\w+)\";)"))) {
170 mediaFilePath = geoDir + "media/media_" + mediaTag +
".geo";
174 std::map<ECbmModuleId, CbmGeoSetupModule> moduleMap;
175 for (
auto detector : detectorMap) {
177 std::regex tagRegex(R
"(.*)" + detector.second.tag + R"(\s+=\s+\"([\w:]+)\";)");
178 std::regex setModuleRegex(R"(.*SetModule\(.*)" + detector.second.tag + R"(\);)");
181 if (std::regex_search(fileContents, match, tagRegex)) {
184 if (std::regex_search(fileContents, match, setModuleRegex)) {
188 if (tag.size() && added) {
201 field.
GetMatrix().SetTranslation(fieldX, fieldY, fieldZ);
224 std::string base = gSystem->Getenv(
"VMCWORKDIR");
225 std::string geoDir = base +
"/geometry/";
227 auto detector = detectorMap[moduleId];
229 std::string full_file_path;
232 std::vector<std::string> _geom;
233 boost::split(_geom, tag, [](
char c) {
return c ==
':'; });
234 for (
auto&
string : _geom) {
236 std::string geoFilePath =
237 geoDir + (detector.dir.size() ? detector.dir +
"/" : detector.dir) + detector.system +
"_" +
string +
".geo.root";
239 if (gSystem->AccessPathName(geoFilePath.c_str()) == kTRUE) {
240 geoFilePath.erase(geoFilePath.size() - 5);
241 if (gSystem->AccessPathName(geoFilePath.c_str()) == kTRUE) {
242 LOG(error) <<
"Geometry file not found for " << detector.system;
249 if (geoFilePath.find(geoDir) != std::string::npos) geoFilePath.replace(0, geoDir.size(),
"");
251 full_file_path += geoFilePath;
252 full_file_path +=
":";
254 full_file_path.pop_back();
257 module.SetName(detector.name);
258 module.SetFilePath(full_file_path);
260 module.SetModuleId(moduleId);
264 module.SetActive(kTRUE);
271 std::string base = std::string(gSystem->Getenv(
"VMCWORKDIR")) +
"/";
272 std::string fieldDir = base +
"input/";
274 std::string fieldFilePath = fieldDir +
"field_" + tag +
".root";
276 if (gSystem->AccessPathName(fieldFilePath.c_str()) == kTRUE) {
277 LOG(error) <<
"Field file not found for tag " << tag;
281 if (fieldFilePath.find(base) != std::string::npos) fieldFilePath.replace(0, base.size(),
"");
293 std::string base = std::string(gSystem->Getenv(
"VMCWORKDIR")) +
"/";
294 std::string geoDir = base +
"geometry/";
295 std::string mediaDir = base +
"geometry/media/";
297 std::string mediaFilePath = mediaDir +
"media_" + tag +
".geo";
299 if (gSystem->AccessPathName(mediaFilePath.c_str()) == kTRUE) {
300 LOG(warn) <<
"Media file not found for tag " << (tag.size() ?
"(empty)" : tag) <<
" using default media.geo";
302 mediaFilePath = geoDir +
"media.geo";
308 if (mediaFilePath.find(geoDir) != std::string::npos) mediaFilePath.replace(0, geoDir.size(),
"");
ECbmModuleId
Enumerator for module Identifiers.
@ 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.
@ kMust
MuSt detection 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)
void SetTag(std::string value)
void SetMedia(CbmGeoSetupMedia value)
void SetModuleMap(std::map< ECbmModuleId, CbmGeoSetupModule > value)