10#include <sys/sendfile.h>
45 std::string rootPath = getenv(
"DBL_FILE_PATH");
47 if (stat(rootPath.c_str(), &st) == 0)
48 if ((st.st_mode & S_IFDIR) != 0) {
49 std::cerr <<
"Error: DBL_FILE_PATH variable points to the folder. Please, set DBL_FILE_PATH to file path "
50 "with local geometry database"
55 last = rootPath.find_last_of(
"/\\");
61 fileName = rootPath.substr(last + 1);
62 rootPath = rootPath.substr(0, last);
64 rootPath +=
"/storage/";
71 return (access(name, F_OK) != -1);
76 std::map<int, TString>::iterator it =
m_modules_table.find(dbNoduleUndex);
80 std::cerr <<
"Unknown module type with id=" << dbNoduleUndex << std::endl;
87 std::map<int, TString>::iterator it;
89 if (it->second == name)
109 return it->second.idm;
127 int dbNoduleUndex = mr.
idm;
144 command +=
",kTRUE)";
148 std::cerr <<
"command:" << command << std::endl;
152 obj->SetGeometryFileName(path);
153 fRun->AddModule(obj);
163 std::ostringstream stringStream;
164 stringStream <<
"select idmr,idm,class_name,revision,active,args from module_revision;";
167 std::cout <<
"Error: SQL query was failed. "
168 "Please, check connection to the geometry database and that DBL_FILE_PATH variable is correct"
173 std::cout <<
"Error: no module revisions in the geometry database" << std::endl;
178 while ((row = resQ2->
Next()) != 0) {
204 std::ostringstream stringStream;
205 stringStream <<
"select idm,mname from module;";
208 std::cout <<
"Error: SQL query was failed. "
209 "Please, check connection to the geometry database and that DBL_FILE_PATH variable is correct"
214 std::cout <<
"Error: no modules in the geometry database" << std::endl;
219 while ((row = resQ2->
Next()) != 0) {
275 TList* l = f->GetListOfKeys();
280 while ((key = (
TKey*)next())) {
281 if (strcmp(key->GetClassName(),
"TGeoManager") != 0)
296 volume =
dynamic_cast<TGeoVolume*
>(key->ReadObj());
317 int source = open(in.
Data(), O_RDONLY, 0);
318 int dest = open(out.
Data(), O_WRONLY | O_CREAT , 0644);
321 struct stat stat_source;
322 fstat(source, &stat_source);
323 sendfile(dest, source, 0, stat_source.st_size);
328bool hasEnding(std::string
const& fullString, std::string
const& ending)
330 if (fullString.length() >= ending.length())
331 return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
341 std::map<int, SETUPMODULE>& moduleMove,
345 std::map<int, TString>::iterator it = loadedModule->find(idsm);
346 if (it != loadedModule->end())
349 std::ostringstream stringStream;
350 stringStream <<
"select f.idm,f.url,sm.idp,sm.tx,sm.ty,sm.tz from setupmodule sm INNER JOIN file f ON f.idf=sm.idf "
356 std::cout <<
"Error: no file for the module was found" << std::endl;
365 std::cerr <<
"idP=" << idP << std::endl;
367 res =
downloadModule(loadedModule, rootDir, db, idP, fRun, moduleMove, iVerbose);
372 std::cerr << row2->
GetField(1) << std::endl;
373 int dbModuleIndex = atoi(row2->
GetField(0));
374 stringStream.str(
"");
376 std::string ends =
".geo";
386 double mx = 0, my = 0, mz = 0;
387 std::map<int, SETUPMODULE>::iterator itr = moduleMove.find(dbModuleIndex);
389 std::cerr <<
"detector " << dbModuleIndex << std::endl;
390 if (itr != moduleMove.end()) {
392 std::cerr <<
"detector was found" << std::endl;
393 if (itr->second.enable) {
394 mx = itr->second.xMove;
395 my = itr->second.yMove;
396 mz = itr->second.zMove;
398 std::cerr <<
"Move detector " << dbModuleIndex <<
" to x:" << mx <<
" to y:" << my <<
" to z:" << mz
406 TFile* f =
new TFile(stringStream.str().c_str());
408 double tx = (double)atoi(row2->
GetField(3)) + mx;
409 double ty = (double)atoi(row2->
GetField(4)) + my;
410 double tz = (double)atoi(row2->
GetField(5)) + mz;
416 v->SetMatrix(newMatrix);
424 std::cerr <<
"Exporting geometry to ROOT file: " << out << std::endl;
430 loadedModule->insert(std::pair<int, TString>(idsm, out));
437int loadSetup(
const char* setupTag,
int subSetup,
const char* fileName = NULL,
int iVerbose = 0)
439 std::map<int, SETUPMODULE> moduleMove;
441 if (fileName != NULL) {
445 std::cerr <<
"Selected file has not XML format: " << fileName << std::endl;
474 if (chName.
CompareTo(
"setupModule") == 0) {
489 else if (aName.
CompareTo(
"moveX") == 0) {
491 }
else if (aName.
CompareTo(
"moveY") == 0) {
493 }
else if (aName.
CompareTo(
"moveZ") == 0) {
505 moduleMove.insert(std::pair<int, SETUPMODULE>(ii, sNode));
516 std::cout <<
"Created new FairRunSim" << std::endl;
518 TString rootPath = getenv(
"TMP_PATH");
519 if (rootPath.
Length() == 0) {
522 rootPath =
"/tmp/" + login +
"/";
523 system(
"mkdir -p " + rootPath);
526 std::ostringstream stringStream;
527 stringStream <<
"sqlite://"
528 << getenv(
"DBL_FILE_PATH");
531 std::cerr <<
"Geometry Database Path: " << stringStream.str().c_str() << std::endl;
532 stringStream.str(
"");
540 <<
"select idsd,status,idma,idfi from setup where stag='" << tag
541 <<
"' order by revision desc;";
544 std::cerr <<
"SQL query was failed while searching the given tag: `" << tag <<
"`" << std::endl;
549 std::cerr <<
"No geometry setup found for the given tag: `" << tag <<
"`" << std::endl;
553 const char* idsd = row->
GetField(0);
557 stringStream.str(
"");
558 stringStream <<
"select idsm from sms where idsd=" << idsd <<
";";
562 resQ = db.
Query(stringStream.str().c_str());
564 std::cout <<
"Error: no modules found" << std::endl;
567 std::map<int, TString>* loadedModule =
new std::map<int, TString>();
568 while ((row = resQ->
Next()) != 0) {
569 stringStream.str(
"");
570 const char* idsm = row->
GetField(0);
571 int idsmI = atoi(idsm);
572 if (subSetup < 0 || subSetup == idsmI) {
573 int res =
downloadModule(loadedModule, rootPath, db, idsmI, fRun, moduleMove, iVerbose);
575 std::cout <<
"Error: no file for the module was found " << std::endl;
609 stringStream.str(
"");
610 stringStream <<
"select matag,url from material where idma=" << idma <<
";";
611 resQ = db.
Query(stringStream.str().c_str());
613 std::cout <<
"Materials did not find" << std::endl;
617 stringStream.str(
"");
620 TString work = getenv(
"GEOMPATH");
624 work = getenv(
"VMCWORKDIR");
625 Mat = work +
"/geometry/";
632 std::string workP(Mat.
Data());
634 std::cout <<
"Working geometry directory: " << workP << std::endl;
635 std::size_t found = workP.find(
'/');
636 if (found != std::string::npos) {
637 while ((found = workP.find(
'/', found + 1)) != std::string::npos) {
639 std::cout <<
"found:" << found << std::endl;
654 std::cout <<
"The setup geometry was successfully loaded" << std::endl;
663 std::srand(time(NULL));
664 int random_variable = std::rand();
665 std::cout << random_variable << std::endl;
666 std::ostringstream stringStream;
669 stringStream <<
"wget -O test2.tar \"" << url <<
"/download_file.php?type=all&tag=all&dirname=" << random_variable
671 system(stringStream.str().c_str());
672 stringStream.str(
"");
673 stringStream <<
"tar -xf test2.tar >/dev/null";
674 system(stringStream.str().c_str());
675 stringStream.str(
"");
676 stringStream <<
"rm test2.tar";
677 system(stringStream.str().c_str());
678 stringStream.str(
"");
679 stringStream <<
gSystem->pwd() <<
"/" << random_variable <<
"/storage/";
680 gSystem->Setenv(
"DBL_ROOT_PATH", stringStream.str().c_str());
681 stringStream.str(
"");
682 stringStream <<
gSystem->pwd() <<
"/" << random_variable <<
"/local.db";
683 gSystem->Setenv(
"DBL_FILE_PATH", stringStream.str().c_str());
687 stringStream.str(
"");
688 stringStream <<
"rm -rf " << random_variable <<
"/local.db";
689 system(stringStream.str().c_str());
690 stringStream.str(
"");
691 stringStream <<
"rm -rf " << random_variable;
692 system(stringStream.str().c_str());
693 std::cout <<
"DBL_ROOT_PATH=" <<
getRootPath() << std::endl;
R__EXTERN TSystem * gSystem
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
virtual Bool_t cd(const char *path="")
TGeoNode * GetNode(Int_t level) const
TGeoVolume * GetVolume() const
TGeoNode * GetDaughter(Int_t ind) const
TGeoNode * GetNode(const char *name) const
Int_t Export(const char *filename, const char *name="", Option_t *option="")
TObject * At(Int_t idx) const override
virtual const char * ClassName() const
virtual void Delete(Option_t *option="")
virtual Int_t GetRowCount() const
virtual TSQLRow * Next()=0
virtual const char * GetField(Int_t field)=0
TSQLResult * Query(const char *sql) final
void Close(Option_t *opt="") final
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
static TString Format(const char *fmt,...)
TString & ReplaceAll(const char *s1, const char *s2)
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
void FreeDoc(XMLDocPointer_t xmldoc)
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
XMLAttrPointer_t GetNextAttr(XMLAttrPointer_t xmlattr)
const char * GetAttrName(XMLAttrPointer_t xmlattr)
XMLAttrPointer_t GetFirstAttr(XMLNodePointer_t xmlnode)
const char * GetNodeName(XMLNodePointer_t xmlnode)
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
const char * GetAttrValue(XMLAttrPointer_t xmlattr)
XMLNodePointer_t GetNext(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
struct SETUPMODULE setup_module
struct SETUPMODULE * setup_module_ptr
struct MODULEREVISION module_r
struct MODULEREVISION * module_r_ptr
std::pair< int, TString > moduleP
std::map< int, MODULEREVISION > m_modules_revision_table
std::map< int, TString > m_modules_table
int downloadModule(std::map< int, TString > *loadedModule, TString &rootDir, TSQLiteServer &db, int idsm, FairRunSim *fRun, std::map< int, SETUPMODULE > &moduleMove, int iVerbose=0)
TString getModuleType(int dbModuleRev)
void copyFile(TString &in, TString &out)
int getModuleIndex(TString &name)
int loadSetup(const char *setupTag, int subSetup, const char *fileName=NULL, int iVerbose=0)
MODULEREVISION getModuleRevision(int dbModuleRev)
bool hasEnding(std::string const &fullString, std::string const &ending)
bool loadFairModule(FairRunSim *fRun, int dbModuleRev, const char *path, double psdx, double psdz, int iVerbose=0)
TGeoVolume * constructRootGeometry(TFile *f)
bool exists_file(const char *name)
TString getModuleName(int dbNoduleUndex)
int putMudules4SQLite(TSQLiteServer &db)
int putMudulesRevision4SQLite(TSQLiteServer &db)
int getModuleId(int dbModuleRev)
std::string getRootPath()
*brief user defined string literal for JSON values *sa std::size_t n