BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
GeoSetup.h
Go to the documentation of this file.
1#ifndef _GEO_SETUP_INCLUDED
2#define _GEO_SETUP_INCLUDED
3
4#include "BmnFieldMap.h"
5#include "FairRunSim.h"
6#include "TFile.h"
7#include "TGeoVolume.h"
8#include "TSQLRow.h"
9#include "TSQLServer.h"
10#include "TString.h"
11#include "geo_db_settings.h"
12
13#include <map>
14#include <string>
15#include <utility>
16
17using namespace std;
18
26
27typedef struct MODULEREVISION
28{
30 int idmr{-1}, idm{-1}, rev{-1};
31 bool active{true};
35
36/**
37 * GeoSetup class. It is used for loading necessary setup geometries from the Geometry Database.
38 */
40{
41 public:
42 // default constructor
44 : m_db(nullptr)
45 , m_field(nullptr)
46 , m_fid(-1)
47 , m_sid(-1)
48 , m_tmpFolder("")
49 {}
50
51 /**
52 * Destructor method
53 */
54 ~GeoSetup();
55
56 /**
57 * Load selected geometry setup from the Local Geometry Database and create gGeoManager instance.
58 * Use for Reconstruction and Analysis
59 * @param setup_tag the name of the setup tag.
60 * @return 0, if the setup is loaded. Error code, if the setup is not loaded.
61 */
62 int LoadSetupToGeoManager(string_view setup_tag);
63
64 /**
65 * Load selected geometry setup from the Local or Central (defined by url) Geometry Database and add it to the
66 * FairRunSim instance. Use for Simulation
67 * @param setupTag the name of the setup tag.
68 * @param localSettings path to local setting file that can disable or move some detector in selected geometry.
69 * @return 0, if the setup is loaded. Error code, if the setup is not loaded.
70 */
71 int LoadSetupToFairRunSim(string_view setupTag, const char* localSettings = nullptr);
72
73 /**
74 * Get magnetic field of the current setup geometry.
75 * @param scale the scale of the field. Default value is -1 (any negative value), which means that the default scale
76 * of the field from the Geometry Database is used. Zero value turns the magnetic field off.
77 * @return Instance of the magnetic field class inherited from FairField. nullptr if no field
78 */
79 FairField* GetMagneticField(double scale = -1);
80
81 /**
82 * Get path to parameter file for the given detector name of the current setup.
83 * @param detector_name the name of the detector, for which the parameter file is needed.
84 * @return Path to parameter file. "" if file did not set.
85 */
86 string GetParameterFile(string_view detector_name);
87
88 /**
89 * Get the material file of the current setup, which defines the media of the setup geometry.
90 * @return Name of the material file in the Geometry Database. "" if the setup is not loaded or has no materials.
91 */
92 string GetMaterialFile();
93
94 /**
95 * Get tag for the last approved setup corresponding to the pattern.
96 * @param tag_prefix The prefix string to match against approved setup tags.
97 * @return Tag of last approved setup corresponding to the prefix string.
98 */
99 string GetLastApprovedSetupTag(string_view tag_prefix);
100 /**
101 * Get tag for the loaded setup.
102 * @return The Tag of loaded setup.
103 */
104 string_view GetSetupTag() { return m_setupTag; }
105
106 private:
107 map<int, TString> m_modules_table;
108 map<int, module_r_ptr> m_modules_revision_table;
109 map<int, TString> m_loadedModule;
110 map<TString, setup_module_ptr> m_moduleEdit;
111 vector<module_r_ptr> m_moduleAdd;
112
113 // connection to the Geometry Database
115 // magnetic field of the geometry setup
117 // id of the current magnetic field
118 int m_fid;
119 // id of the current geometry setup
120 int m_sid;
121 // current tmp directory (/tmp/$USER/)
123 // tag name of setup
124 string m_setupTag = "";
125 // name of the material file of the setup in the Geometry Database
126 string m_materialFile = "";
127
128 unsigned long int GetServerRevision(const char* url = GEO_SERVER_HOST);
129 std::pair<int, string> GetTagName4PatternServer(string_view pattern_tag, const char* url = GEO_SERVER_HOST);
130 std::pair<int, uint64_t> CheckTagOnServer(string_view setup_tag, const char* url = GEO_SERVER_HOST);
131 unsigned long int GetLocalRevision(TString& localDbPath);
132 std::pair<int, string> GetTagName4PatternLocal(string_view pattern_tag, TString& localDbPath);
133 int installLocalDB(string_view setup_tag, const char* url = GEO_SERVER_HOST);
134 void CloseDB();
136
137 // create connection to the Local Geometry Database and fill the tables with modules and their revisions
139 bool IsEqlMatrix(const char* fileName, TSQLRow* row);
140 TGeoNode* ConstructRootGeometry(const char* fileName);
141 static bool exists_file(const char* name);
142 // check that the directory can be modified, e.g. it is not a part of a read-only file system
143 static bool IsWritableDir(const char* path);
144 // get a writable directory (a unique folder in $DBL_CACHE_PATH, $TMPDIR, /tmp/$USER) to install
145 // the Local Geometry Database to, when the directory of the database is read-only
147 // get path to the location of the Local Geometry Database
148 string GetRootPath();
149 string GetLocalDbPath();
150 // get expanded value of the DBL_FILE_PATH environment variable; "" if not set or cannot be expanded
151 string ExpandDbFilePath();
152 // get path to a temporary directory (/tmp/$USER/), and create if absent
154 // get unique name of a temporary file in the temporary directory
155 TString GetTmpFileName(const char* baseName);
156 // get root volume in the TFile object
158
159 // get module name by index; return "Unknown" if not found
160 TString GetModuleName(int dbModuleUndex);
161 // get module index by name; return -1 if not found
162 int GetModuleIndex(TString& name);
163 // get module ID by revision number; return -1 if not found
164 int GetModuleId(int dbModuleRev);
165 // get module type by revision number
166 TString GetModuleType(int dbModuleRev);
167 // get module_r_ptr (pointer to the module revision) by revision number
168 module_r_ptr GetModuleRevision(int dbModuleRev);
169
170 // load local settings from the file for all setup modules
171 bool LoadLocalSettings(const char* fileName);
172
173 // load module from the Geometry Database and add to the FairRunSim instance
174 int LoadModuleToFairRunSim(int idsm, FairRunSim* fRun);
175 // add FairModule defined by revision number and geometry file path to the FairRunSim instance
176 bool AddModuleToFairRunSim(int dbModuleRev, const char* path, FairRunSim* fRun);
177
178 // fill map with modules from the Geometry Database
179 int PutModules();
180 // fill map with module revisions from the Geometry Database
181 int PutModuleRevisions();
182};
183
184#endif
TString & GetTmpPath()
int GetModuleId(int dbModuleRev)
TGeoNode * ConstructRootGeometry(const char *fileName)
string GetParameterFile(string_view detector_name)
Get path to parameter file for the given detector name of the current setup.
Definition GeoSetup.cxx:933
string m_setupTag
Definition GeoSetup.h:124
bool OpenLocalGeoDatabase()
Definition GeoSetup.cxx:459
string ExpandDbFilePath()
int m_sid
Definition GeoSetup.h:120
TString GetModuleName(int dbModuleUndex)
int LoadModuleToFairRunSim(int idsm, FairRunSim *fRun)
int PutModules()
TString GetTmpFileName(const char *baseName)
Definition GeoSetup.cxx:97
int LoadSetupToGeoManager(string_view setup_tag)
Load selected geometry setup from the Local Geometry Database and create gGeoManager instance.
Definition GeoSetup.cxx:512
string GetLocalDbPath()
bool LoadLocalSettings(const char *fileName)
string GetMaterialFile()
Get the material file of the current setup, which defines the media of the setup geometry.
Definition GeoSetup.cxx:985
string GetRootPath()
map< int, TString > m_modules_table
Definition GeoSetup.h:107
map< TString, setup_module_ptr > m_moduleEdit
Definition GeoSetup.h:110
std::pair< int, uint64_t > CheckTagOnServer(string_view setup_tag, const char *url=GEO_SERVER_HOST)
Definition GeoSetup.cxx:178
TGeoVolume * GetRootVolume(TFile *f)
FairField * m_field
Definition GeoSetup.h:116
int installLocalDB(string_view setup_tag, const char *url=GEO_SERVER_HOST)
Definition GeoSetup.cxx:331
unsigned long int GetServerRevision(const char *url=GEO_SERVER_HOST)
Definition GeoSetup.cxx:102
vector< module_r_ptr > m_moduleAdd
Definition GeoSetup.h:111
string_view GetSetupTag()
Get tag for the loaded setup.
Definition GeoSetup.h:104
map< int, module_r_ptr > m_modules_revision_table
Definition GeoSetup.h:108
TSQLServer * m_db
Definition GeoSetup.h:114
TString GetModuleType(int dbModuleRev)
GeoSetup()
Definition GeoSetup.h:43
void CloseDB()
Definition GeoSetup.cxx:441
int PutModuleRevisions()
TString PrepareWritableDbDir()
Definition GeoSetup.cxx:300
int m_fid
Definition GeoSetup.h:118
module_r_ptr GetModuleRevision(int dbModuleRev)
static bool exists_file(const char *name)
Definition GeoSetup.cxx:31
static bool IsWritableDir(const char *path)
Definition GeoSetup.cxx:276
map< int, TString > m_loadedModule
Definition GeoSetup.h:109
int GetModuleIndex(TString &name)
TString m_tmpFolder
Definition GeoSetup.h:122
FairField * GetMagneticField(double scale=-1)
Get magnetic field of the current setup geometry.
Definition GeoSetup.cxx:877
bool IsEqlMatrix(const char *fileName, TSQLRow *row)
~GeoSetup()
Destructor method.
Definition GeoSetup.cxx:453
unsigned long int GetLocalRevision(TString &localDbPath)
Definition GeoSetup.cxx:248
std::pair< int, string > GetTagName4PatternLocal(string_view pattern_tag, TString &localDbPath)
Definition GeoSetup.cxx:224
bool AddModuleToFairRunSim(module_r_ptr module, FairRunSim *fRun)
std::pair< int, string > GetTagName4PatternServer(string_view pattern_tag, const char *url=GEO_SERVER_HOST)
Definition GeoSetup.cxx:137
string GetLastApprovedSetupTag(string_view tag_prefix)
Get tag for the last approved setup corresponding to the pattern.
Definition GeoSetup.cxx:122
string m_materialFile
Definition GeoSetup.h:126
int LoadSetupToFairRunSim(string_view setupTag, const char *localSettings=nullptr)
Load selected geometry setup from the Local or Central (defined by url) Geometry Database and add it ...
Definition GeoSetup.cxx:643
struct SETUPMODULE setup_module
struct SETUPMODULE * setup_module_ptr
struct MODULEREVISION module_r
struct MODULEREVISION * module_r_ptr
const char *const GEO_SERVER_HOST
Definition json.hpp:4446
TString class_name
Definition GeoSetup.h:29
TString args
Definition GeoSetup.h:32
TString file_path
Definition GeoSetup.h:33
TString type
Definition GeoSetup.h:21
double zMove
Definition GeoSetup.h:22
TString file_path
Definition GeoSetup.h:24
double xMove
Definition GeoSetup.h:22
double yMove
Definition GeoSetup.h:22
bool enable
Definition GeoSetup.h:23