BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
loadSetup.C
Go to the documentation of this file.
1#include <cstring>
2#include <fcntl.h> // open
3#include <fstream>
4#include <iostream>
5#include <map>
6#include <sstream>
7#include <stdio.h>
8#include <stdlib.h>
9#include <string>
10#include <sys/sendfile.h> // sendfile
11#include <sys/stat.h> // fstat
12#include <sys/types.h> // fstat
13#include <time.h> /* time */
14#include <unistd.h> // close
15#include <unistd.h>
16typedef std::pair<int, TString> moduleP;
17
18#include "TXMLEngine.h"
19
20struct SETUPMODULE
21{
23 double xMove;
24 double yMove;
25 double zMove;
26 bool enable;
28
29struct MODULEREVISION
30{
31 TString class_name;
32 int idmr;
33 int idm;
34 int rev;
35 bool active;
38
39std::map<int, TString> m_modules_table;
40std::map<int, MODULEREVISION> m_modules_revision_table;
41
42// get path to the storage of the local geometry database given by GEOMPATH, with the trailing slash
43std::string getRootPath()
44{
45 const char* geomPath = getenv("GEOMPATH");
46 if (geomPath == nullptr || geomPath[0] == '\0') {
47 std::cerr << "Error: GEOMPATH variable is not set. Please, set GEOMPATH to the storage of the local geometry "
48 "database"
49 << std::endl;
50 std::exit(-1);
51 }
52 std::string rootPath = geomPath;
53 if (rootPath.back() != '/')
54 rootPath += "/";
55 return rootPath;
56}
57
58// get path to the local geometry database file, which is located in the parent directory of its storage
59std::string getLocalDbPath()
60{
61 std::string storagePath = getRootPath();
62 while (storagePath.size() > 1 && storagePath.back() == '/')
63 storagePath.pop_back();
64 size_t last = storagePath.find_last_of('/');
65 return (last == std::string::npos ? std::string(".") : storagePath.substr(0, last)) + "/local.db";
66}
67
68bool exists_file(const char* name)
69{
70 return (access(name, F_OK) != -1);
71}
72
73TString getModuleName(int dbNoduleUndex)
74{
75 std::map<int, TString>::iterator it = m_modules_table.find(dbNoduleUndex);
76 if (it != m_modules_table.end())
77 return it->second;
78 else {
79 std::cerr << "Unknown module type with id=" << dbNoduleUndex << std::endl;
80 return TString("Unknown");
81 }
82}
83
85{
86 std::map<int, TString>::iterator it;
87 for (it = m_modules_table.begin(); it != m_modules_table.end(); ++it)
88 if (it->second == name)
89 return it->first;
90
91 return -1;
92}
93
95{
96 std::map<int, MODULEREVISION>::iterator it = m_modules_revision_table.find(dbModuleRev);
97 if (it != m_modules_revision_table.end())
98 return it->second; //.class_name;
99
101 return mr;
102}
103
104int getModuleId(int dbModuleRev)
105{
106 std::map<int, MODULEREVISION>::iterator it = m_modules_revision_table.find(dbModuleRev);
107 if (it != m_modules_revision_table.end())
108 return it->second.idm;
109
110 return -1;
111}
112
113TString getModuleType(int dbModuleRev)
114{
115 return getModuleName(getModuleId(dbModuleRev));
116}
117
119 int dbModuleRev,
120 const char* path,
121 double psdx,
122 double psdz,
123 int iVerbose = 0) // KG psdx и psdz не используются?
124{
125 MODULEREVISION mr = getModuleRevision(dbModuleRev);
126 int dbNoduleUndex = mr.idm;
127 TString mName = getModuleType(dbModuleRev);
128 mName.ToUpper();
129
130 TString type_name;
132 // std::cout<<"TClass:"<<cl<<std::endl;
133 FairModule* f_cl = (FairModule*)cl->New();
134 if (mr.args.Length() > 0) {
135 type_name = mr.args;
136 // f_cl->SetName(mr.args);
137 } else {
138 // f_cl->SetName(getModuleType(dbModuleRev));
139 type_name = getModuleType(dbModuleRev);
140 }
141 TString command = "new " + mr.class_name + "(\"" + type_name + "\""; //,kTrue)";
142 if (mr.active)
143 command += ",kTRUE)";
144 else
145 command += ")";
146 if (iVerbose > 0)
147 std::cerr << "command:" << command << std::endl;
148 FairModule* obj = (FairModule*)gInterpreter->Calc(command);
149
150 // std::cerr<<"OBJ="<<obj<<std::endl;
151 obj->SetGeometryFileName(path);
152 fRun->AddModule(obj);
153
154 // obj->Dump();
155 // std::cerr<<"dbModuleRev="<<dbModuleRev<<" idmr="<<mr.idmr<<" idm="<<mr.idm<<"
156 // class_name="<<typeid(f_cl).name()<<std::endl; f_cl->Dump();
157 return true;
158}
159
161{
162 std::ostringstream stringStream;
163 stringStream << "select idmr,idm,class_name,revision,active,args from module_revision;";
164 TSQLResult* resQ2 = db.Query(stringStream.str().c_str());
165 if (resQ2 == 0) {
166 std::cout << "Error: SQL query was failed. "
167 "Please, check connection to the geometry database and that GEOMPATH variable is correct"
168 << std::endl;
169 return -1;
170 }
171 if (resQ2->GetRowCount() == 0) {
172 std::cout << "Error: no module revisions in the geometry database" << std::endl;
173 return -2;
174 }
175
176 TSQLRow* row;
177 while ((row = resQ2->Next()) != 0) {
178 int idmr = atoi(row->GetField(0));
179 int idm = atoi(row->GetField(1));
180 int rev = atoi(row->GetField(3));
181 int act = atoi(row->GetField(4));
182 TString class_name(row->GetField(2));
183 TString args(row->GetField(5));
184
186 mr.idmr = idmr;
187 mr.rev = rev;
188 mr.idm = idm;
189 mr.class_name = class_name;
190 mr.args = args;
191 if (act == 0)
192 mr.active = false;
193 else
194 mr.active = true;
195 m_modules_revision_table.insert(make_pair(idmr, mr));
196 }
197
198 return 0;
199}
200
202{
203 std::ostringstream stringStream;
204 stringStream << "select idm,mname from module;";
205 TSQLResult* resQ2 = db.Query(stringStream.str().c_str());
206 if (resQ2 == 0) {
207 std::cout << "Error: SQL query was failed. "
208 "Please, check connection to the geometry database and that GEOMPATH variable is correct"
209 << std::endl;
210 return -1;
211 }
212 if (resQ2->GetRowCount() == 0) {
213 std::cout << "Error: no modules in the geometry database" << std::endl;
214 return -2;
215 }
216
217 TSQLRow* row;
218 while ((row = resQ2->Next()) != 0) {
219 int id = atoi(row->GetField(0));
220 TString name(row->GetField(1));
221 m_modules_table.insert(make_pair(id, name));
222 }
223
224 return 0;
225}
226
227/*
228CbmFieldMap* CreateFieldMap(TString& fieldTag) {
229 TString mapName = "";//"field_";
230 mapName += fieldTag;
231 TString fileName = gSystem->Getenv("VMCWORKDIR");
232 fileName = fileName + "/input/" + mapName + ".root";
233 TFile mapFile(fileName);
234 if ( ! mapFile.IsOpen() ) {
235 LOG(ERROR) << "Could not open field map file " << fileName
236 << FairLogger::endl;
237 return NULL;
238 }
239 CbmFieldMapData* data = NULL;
240 mapFile.GetObject(mapName, data);
241 if ( ! data ) {
242 LOG(ERROR) << "Could not find CbmFieldMapData object " << mapName << " in file "
243 << fileName << FairLogger::endl;
244 return NULL;
245 }
246 Int_t fieldType = data->GetType();
247
248 CbmFieldMap* field = NULL;
249 switch (fieldType) {
250 case 2: field = new CbmFieldMapSym2(mapName); break;
251 case 3: field = new CbmFieldMapSym3(mapName); break;
252 default: LOG(ERROR) << "Unknown field type " << fieldType
253 << FairLogger::endl; break;
254 }
255 if ( field ) {
256 field->SetScale(fFieldScale);
257 field->SetPosition(fFieldPosition.X(),
258 fFieldPosition.Y(),
259 fFieldPosition.Z());
260 }
261
262 return field;
263}
264*/
265
266// TFile* f=new TFile(fileName);
268{
269 // TGeoManager* OldGeo=geoManeger;
270 TGeoManager* NewGeo = 0;
271 TGeoVolume* volume = 0;
272 ;
273 // TFile* f=new TFile(fileName);
274 TList* l = f->GetListOfKeys();
275 TKey* key;
276 TIter next(l);
277 TGeoNode* n = 0;
278 TGeoVolume* v1 = 0;
279 while ((key = (TKey*)next())) {
280 if (strcmp(key->GetClassName(), "TGeoManager") != 0)
281 continue;
282 // gGeoManager = 0;
283 NewGeo = (TGeoManager*)key->ReadObj();
284 break;
285 }
286
287 if (NewGeo != 0) {
288 NewGeo->cd();
289 // return NewGeo->GetNode(0);
290 return (TGeoVolume*)NewGeo->GetNode(0)->GetDaughter(0)->GetVolume();
291 // v1=volume->MakeCopyVolume(volume->GetShape());
292 // n=v1->GetNode(0);
293 } else {
294 key = (TKey*)l->At(0); // Get the first key in the list
295 volume = dynamic_cast<TGeoVolume*>(key->ReadObj());
296 return volume;
297 // if(volume!=0) { return volume->GetNode(0);}//n=volume->GetNode(0); }
298 // if(n!=0) { v1=n->GetVolume(); }
299 // return NULL;
300 }
301
302 // if(v1==0) {
303 // std::cerr<<"ConstructRootGeometry: could not find any geometry in File!!"<<fileName<<std::endl;
304 // }
305 // gGeoManager=OldGeo;
306 // gGeoManager->cd();
307 // TGeoVolume* Cave=NULL;
308 // if(NULL == Cave)
309 // return v1;
310 // else
311 // return Cave;
312}
313
314void copyFile(TString& in, TString& out)
315{
316 int source = open(in.Data(), O_RDONLY, 0);
317 int dest = open(out.Data(), O_WRONLY | O_CREAT /*| O_TRUNC*/, 0644);
318
319 // struct required, rationale: function stat() exists also
320 struct stat stat_source;
321 fstat(source, &stat_source);
322 sendfile(dest, source, 0, stat_source.st_size);
323 close(source);
324 close(dest);
325}
326
327bool hasEnding(std::string const& fullString, std::string const& ending)
328{
329 if (fullString.length() >= ending.length())
330 return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
331 else
332 return false;
333}
334
335int downloadModule(std::map<int, TString>* loadedModule,
336 TString& rootDir,
337 TSQLiteServer& db,
338 int idsm,
339 FairRunSim* fRun,
340 std::map<int, SETUPMODULE>& moduleMove,
341 int iVerbose = 0)
342{
343 int res = -1;
344 std::map<int, TString>::iterator it = loadedModule->find(idsm);
345 if (it != loadedModule->end())
346 return 0;
347
348 std::ostringstream stringStream;
349 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 "
350 "where sm.idsm="
351 << idsm << ";";
352 // std::cerr<<stringStream<<std::endl;
353 TSQLResult* resQ2 = db.Query(stringStream.str().c_str());
354 if (resQ2 == 0 || resQ2->GetRowCount() == 0) {
355 std::cout << "Error: no file for the module was found" << std::endl;
356 return res;
357 }
358
359 // std::cerr<<"rows="<<resQ2->GetRowCount()<<std::endl;
360 TSQLRow* row2 = resQ2->Next();
361 // const char* ccc = row2->GetField(1);
362 int idP = atoi(row2->GetField(2));
363 if (iVerbose > 1)
364 std::cerr << "idP=" << idP << std::endl;
365 if (idP != -1) {
366 res = downloadModule(loadedModule, rootDir, db, idP, fRun, moduleMove, iVerbose);
367 if (res < 0)
368 return res;
369 }
370 if (iVerbose > 1)
371 std::cerr << row2->GetField(1) << std::endl;
372 int dbModuleIndex = atoi(row2->GetField(0));
373 stringStream.str("");
374 stringStream << getRootPath().c_str() << row2->GetField(1);
375 std::string ends = ".geo";
376 // std::cerr<<"getRootPath()="<<getRootPath().c_str()<<std::endl;
377 // std::cerr<<"File path="<<stringStream.str().c_str()<<std::endl;
378
379 TString mName = getModuleType(dbModuleIndex), out;
380 mName.ToUpper();
381 if (mName == TString("CAVE") || hasEnding(stringStream.str(), ends))
382 loadFairModule(fRun, dbModuleIndex, stringStream.str().c_str(), atof(row2->GetField(3)),
383 atof(row2->GetField(5)));
384 else {
385 double mx = 0, my = 0, mz = 0;
386 std::map<int, SETUPMODULE>::iterator itr = moduleMove.find(dbModuleIndex);
387 if (iVerbose > 1)
388 std::cerr << "detector " << dbModuleIndex << std::endl;
389 if (itr != moduleMove.end()) {
390 if (iVerbose > 1)
391 std::cerr << "detector was found" << std::endl;
392 if (itr->second.enable) {
393 mx = itr->second.xMove;
394 my = itr->second.yMove;
395 mz = itr->second.zMove;
396 if (iVerbose > 1)
397 std::cerr << "Move detector " << dbModuleIndex << " to x:" << mx << " to y:" << my << " to z:" << mz
398 << std::endl;
399 }
400 }
401
402 TGeoManager* geom = new TGeoManager(mName, TString::Format("Geometry of the %s module", mName.Data()));
403 // std::cerr<<"import file"<<stringStream.str().c_str()<<std::endl;
404 // TGeoManager::Import(stringStream.str().c_str());
405 TFile* f = new TFile(stringStream.str().c_str());
407 double tx = (double)atoi(row2->GetField(3)) + mx;
408 double ty = (double)atoi(row2->GetField(4)) + my;
409 double tz = (double)atoi(row2->GetField(5)) + mz;
410 TGeoRotation rotM;
411 TGeoGenTrans* newMatrix = new TGeoGenTrans(tx, ty, tz, 1, 1, 1, &rotM);
412 if (std::strcmp(node->GetNode(0)->ClassName(), "TGeoNodeMatrix") == 0) {
413 TGeoNodeMatrix* v = (TGeoNodeMatrix*)(node->GetNode(0));
414 // std::cerr<<"Matrix changed"<<std::endl;
415 v->SetMatrix(newMatrix);
416 }
417 // geom->CloseGeometry();
418 out = rootDir + getModuleName(getModuleId(dbModuleIndex)) + ".root";
419 node->Export(out.Data());
420 // gGeoManager->Export(out.Data());
421 loadFairModule(fRun, dbModuleIndex, out.Data(), atof(row2->GetField(3)), atof(row2->GetField(5)), iVerbose);
422 if (iVerbose > 0)
423 std::cerr << "Exporting geometry to ROOT file: " << out << std::endl;
424 delete geom;
425 f->Close();
426 delete f;
427 // gGeoManager->Export(out.Data());
428 }
429 loadedModule->insert(std::pair<int, TString>(idsm, out));
430
431 row2->Delete();
432 resQ2->Delete();
433 return 0;
434}
435
436int loadSetup(const char* setupTag, int subSetup, const char* fileName = NULL, int iVerbose = 0)
437{
438 std::map<int, SETUPMODULE> moduleMove;
439 TString tag(setupTag);
440 if (fileName != NULL) {
441 TXMLEngine* xml = new TXMLEngine;
442 XMLDocPointer_t xmldoc = xml->ParseFile(fileName);
443 if (xmldoc == 0) {
444 std::cerr << "Selected file has not XML format: " << fileName << std::endl;
445 delete xml;
446 return -1;
447 }
448
449 XMLNodePointer_t mainnode = xml->DocGetRootElement(xmldoc);
450 // display attributes
451 /* XMLAttrPointer_t attr = xml->GetFirstAttr(mainnode);
452 while (attr!=0) {
453 printf(" attr: %s value: %s\n", xml->GetAttrName(attr), xml->GetAttrValue(attr));
454 TString aName = xml->GetAttrName(attr);
455 TString aValue = xml->GetAttrValue(attr);
456 if(aName.CompareTo("tag")==0){
457 tag=aValue;
458 break;
459 }
460 attr = xml->GetNextAttr(attr);
461 }
462 if(tag.Length()==0){
463 std::cerr<<"No tag attribute in root element in selected file"<<std::endl;
464 xml->FreeDoc(xmldoc);
465 delete xml;
466 return -1;
467 }
468 */
469 XMLAttrPointer_t attr;
470 XMLNodePointer_t child = xml->GetChild(mainnode);
471 while (child != 0) {
472 TString chName = xml->GetNodeName(child);
473 if (chName.CompareTo("setupModule") == 0) {
474 attr = xml->GetFirstAttr(child);
475
476 SETUPMODULE sNode;
477 sNode.xMove = 0;
478 sNode.yMove = 0;
479 sNode.zMove = 0;
480 sNode.enable = true;
481 sNode.type = TString("");
482 while (attr != 0) {
483 TString aName = xml->GetAttrName(attr);
484 TString aValue = xml->GetAttrValue(attr);
485
486 if (aName.CompareTo("type") == 0)
487 sNode.type = aValue;
488 else if (aName.CompareTo("moveX") == 0) {
489 sNode.xMove = aValue.Atof();
490 } else if (aName.CompareTo("moveY") == 0) {
491 sNode.yMove = aValue.Atof();
492 } else if (aName.CompareTo("moveZ") == 0) {
493 sNode.zMove = aValue.Atof();
494 }
495 if ((aName.CompareTo("enable") == 0)
496 && (aValue.CompareTo("false") == 0 || aValue.CompareTo("False") == 0
497 || aValue.CompareTo("FALSE") == 0))
498 sNode.enable = false;
499 printf(" attr: %s value: %s\n", xml->GetAttrName(attr), xml->GetAttrValue(attr));
500 attr = xml->GetNextAttr(attr);
501 }
502 int ii = getModuleIndex(sNode.type);
503 if (ii != -1)
504 moduleMove.insert(std::pair<int, SETUPMODULE>(ii, sNode));
505 }
506 child = xml->GetNext(child);
507 }
508 xml->FreeDoc(xmldoc);
509 delete xml;
510 }
511
512 FairRunSim* fRun = FairRunSim::Instance();
513 if (fRun == NULL) {
514 fRun = new FairRunSim();
515 std::cout << "Created new FairRunSim" << std::endl;
516 }
517 TString rootPath = getenv("TMP_PATH");
518 if (rootPath.Length() == 0) {
519 UserGroup_t* user = gSystem->GetUserInfo();
520 string login(user->fUser.Data());
521 rootPath = "/tmp/" + login + "/";
522 system("mkdir -p " + rootPath);
523 }
524
525 std::ostringstream stringStream;
526 stringStream << "sqlite://" << getLocalDbPath();
527 TSQLiteServer db(stringStream.str().c_str());
528 if (iVerbose > 0)
529 std::cerr << "Geometry Database Path: " << stringStream.str().c_str() << std::endl;
530 stringStream.str("");
531
532 if (putMudules4SQLite(db) != 0)
533 return -1;
534 if (putMudulesRevision4SQLite(db) != 0)
535 return -1;
536
537 stringStream
538 << "select idsd,status,idma,idfi from setup where stag='" << tag
539 << "' order by revision desc;"; // KG если я правильно понял, то нужно брать по-умолчанию, самый новый релиз?
540 TSQLResult* resQ = db.Query(stringStream.str().c_str());
541 if (resQ == 0) {
542 std::cerr << "SQL query was failed while searching the given tag: `" << tag << "`" << std::endl;
543 return -1;
544 }
545 TSQLRow* row = resQ->Next();
546 if (row == NULL) {
547 std::cerr << "No geometry setup found for the given tag: `" << tag << "`" << std::endl;
548 return -1;
549 }
550
551 const char* idsd = row->GetField(0);
552 int idma = atoi(row->GetField(2));
553 int idfi = atoi(row->GetField(3));
554 // cout<<"idsd = "<<idsd<<"; idma = "<<idma<<"; idfi = "<<idfi<<endl;
555 stringStream.str("");
556 stringStream << "select idsm from sms where idsd=" << idsd << ";";
557 row->Delete();
558 resQ->Delete();
559
560 resQ = db.Query(stringStream.str().c_str());
561 if (resQ == 0 || resQ->GetRowCount() == 0) {
562 std::cout << "Error: no modules found" << std::endl;
563 return -1;
564 }
565 std::map<int, TString>* loadedModule = new std::map<int, TString>();
566 while ((row = resQ->Next()) != 0) {
567 stringStream.str("");
568 const char* idsm = row->GetField(0);
569 int idsmI = atoi(idsm);
570 if (subSetup < 0 || subSetup == idsmI) { // check subset
571 int res = downloadModule(loadedModule, rootPath, db, idsmI, fRun, moduleMove, iVerbose);
572 if (res == -1) {
573 std::cout << "Error: no file for the module was found " << std::endl;
574 return -1;
575 }
576 }
577 row->Delete();
578 }
579 /* if(idfi>0){
580 stringStream.str("");
581 //stringStream.clear();
582 stringStream<<"select tag,scale,z from field where idfi="<<idfi<<";";
583 resQ = db.Query(stringStream.str().c_str());
584 if(resQ==0 || resQ->GetRowCount()==0){
585 std::cout <<"Field did not find"<<std::endl;
586 }else{
587 row= resQ->Next();
588 double fieldZ = atof(row->GetField(2));
589 double fieldScale = atof(row->GetField(1));
590 TString tagF="field_";
591 tagF+=(row->GetField(0));
592 //std::ofstream dest(rootPath+"field.txt", std::ofstream::out|std::ofstream::trunc);
593 //dest<<"field="<<row->GetField(0)<<std::endl<<"Position=(0.,
594 0.,"<<fieldZ<<")"<<std::endl<<"scale="<<fieldScale;
595 //dest.close();
596 CbmFieldMap* magField = CreateFieldMap(tagF);//new CbmFieldMapSym3(row->GetField(0));
597 magField->SetPosition(0., 0., fieldZ);
598 magField->SetScale(fieldScale);
599 fRun->SetField(magField);
600 //CbmFieldMap* CreateFieldMap
601 row->Delete();
602 resQ->Delete();
603 }
604 }*/
605
606 if (idma > 0) {
607 stringStream.str("");
608 stringStream << "select matag,url from material where idma=" << idma << ";";
609 resQ = db.Query(stringStream.str().c_str());
610 if (resQ == 0 || resQ->GetRowCount() == 0)
611 std::cout << "Materials did not find" << std::endl;
612 else {
613 row = resQ->Next();
614 const char* url = row->GetField(1);
615 stringStream.str("");
616 stringStream << url;
617 TString in(""); //("/../../..");
618 TString work = getenv("GEOMPATH");
619 TString Mat = "";
620 work.ReplaceAll("//", "/");
621 if (work.IsNull()) {
622 work = getenv("VMCWORKDIR");
623 Mat = work + "/geometry/";
624 Mat.ReplaceAll("//", "/");
625 } else {
626 Mat = work;
627 if (!Mat.EndsWith("/"))
628 Mat += "/";
629 }
630 std::string workP(Mat.Data());
631 if (iVerbose > 0)
632 std::cout << "Working geometry directory: " << workP << std::endl;
633 std::size_t found = workP.find('/');
634 if (found != std::string::npos) {
635 while ((found = workP.find('/', found + 1)) != std::string::npos) {
636 if (iVerbose > 1)
637 std::cout << "found:" << found << std::endl;
638 in += "../";
639 }
640 }
641 in += getRootPath() + stringStream.str();
642 fRun->SetMaterials(
643 in.Data()); // KG
644 // /home/soul/bmnroot/geometry/../../../..//home/soul/bmnroot/database/geo_db/storage/07022020_085550_media.geo?
645 resQ->Delete();
646 row->Delete();
647 }
648 }
649
650 db.Close();
651 if (iVerbose > 0)
652 std::cout << "The setup geometry was successfully loaded" << std::endl;
653 return 0;
654}
655
656int loadSetup(const char* setupTag, const char* url)
657{
658 if (url == NULL)
659 return loadSetup(setupTag, -1);
660
661 std::srand(time(NULL));
662 int random_variable = std::rand();
663 std::cout << random_variable << std::endl;
664 std::ostringstream stringStream;
665 // stringStream<<"wget -O test2.tar \""<<url<<"?type=s&tag="<<setupTag<<"&dirname="<<random_variable<<"\"";
666 // http://cbmdb.jinr.ru/geometry8/download_file.php?type=all&tag=all
667 stringStream << "wget -O test2.tar \"" << url << "/download_file.php?type=all&tag=all&dirname=" << random_variable
668 << "\" >/dev/null ";
669 system(stringStream.str().c_str());
670 stringStream.str("");
671 stringStream << "tar -xf test2.tar >/dev/null";
672 system(stringStream.str().c_str());
673 stringStream.str("");
674 stringStream << "rm test2.tar";
675 system(stringStream.str().c_str());
676 stringStream.str("");
677 // the downloaded database file is located in the parent directory of its storage
678 stringStream << gSystem->pwd() << "/" << random_variable << "/storage/";
679 gSystem->Setenv("GEOMPATH", stringStream.str().c_str());
680
681 loadSetup(setupTag, -1);
682
683 stringStream.str("");
684 stringStream << "rm -rf " << random_variable << "/local.db";
685 system(stringStream.str().c_str());
686 stringStream.str("");
687 stringStream << "rm -rf " << random_variable;
688 system(stringStream.str().c_str());
689 std::cout << "GEOMPATH=" << getRootPath() << std::endl;
690
691 return 0;
692}
693
694int loadSetup(const char* tag)
695{
696 return loadSetup(tag, -1, NULL, 0);
697}
698
699/*
700int main(int argc, char** argv)
701{
702 downloadSetup("test2.db","sis100_electron");
703}
704*/
struct SETUPMODULE setup_module
struct SETUPMODULE * setup_module_ptr
struct MODULEREVISION module_r
struct MODULEREVISION * module_r_ptr
__m128 v
Definition P4_F32vec4.h:1
#define gInterpreter
R__EXTERN TSystem * gSystem
void * XMLNodePointer_t
void * XMLDocPointer_t
void * XMLAttrPointer_t
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="")
virtual const char * GetClassName() const
virtual TObject * ReadObj()
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
Ssiz_t Length() const
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Double_t Atof() const
const char * Data() const
void ToUpper()
Bool_t IsNull() 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)
int downloadModule(std::map< int, TString > *loadedModule, TString &rootDir, TSQLiteServer &db, int idsm, FairRunSim *fRun, std::map< int, SETUPMODULE > &moduleMove, int iVerbose=0)
Definition loadSetup.C:335
TString getModuleType(int dbModuleRev)
Definition loadSetup.C:113
void copyFile(TString &in, TString &out)
Definition loadSetup.C:314
int getModuleIndex(TString &name)
Definition loadSetup.C:84
int loadSetup(const char *setupTag, int subSetup, const char *fileName=NULL, int iVerbose=0)
Definition loadSetup.C:436
std::pair< int, TString > moduleP
Definition loadSetup.C:16
MODULEREVISION getModuleRevision(int dbModuleRev)
Definition loadSetup.C:94
std::string getLocalDbPath()
Definition loadSetup.C:59
std::map< int, MODULEREVISION > m_modules_revision_table
Definition loadSetup.C:40
bool hasEnding(std::string const &fullString, std::string const &ending)
Definition loadSetup.C:327
std::map< int, TString > m_modules_table
Definition loadSetup.C:39
bool loadFairModule(FairRunSim *fRun, int dbModuleRev, const char *path, double psdx, double psdz, int iVerbose=0)
Definition loadSetup.C:118
TGeoVolume * constructRootGeometry(TFile *f)
Definition loadSetup.C:267
bool exists_file(const char *name)
Definition loadSetup.C:68
TString getModuleName(int dbNoduleUndex)
Definition loadSetup.C:73
int putMudules4SQLite(TSQLiteServer &db)
Definition loadSetup.C:201
int putMudulesRevision4SQLite(TSQLiteServer &db)
Definition loadSetup.C:160
int getModuleId(int dbModuleRev)
Definition loadSetup.C:104
std::string getRootPath()
Definition loadSetup.C:43
TString class_name
Definition GeoSetup.h:32
TString args
Definition loadSetup.C:36
TString type
Definition GeoSetup.h:24
double zMove
Definition GeoSetup.h:25
double xMove
Definition GeoSetup.h:25
double yMove
Definition GeoSetup.h:25
bool enable
Definition GeoSetup.h:26
TString fUser