StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fmsPositionModel_db.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fmsPositionModel_db(char* opt="", char* year="15sim") {
5  TString option(opt), yr(year);
6  TString storeTime; // storetime is begin time for validity range for WRITING DB
7  int date,time; // time for READING DB
8  unsigned int model=0;
9  std::cout << "year = " << year << "\n";
10  if(yr.Contains("15pp")){
11  storeTime="2014-12-20 00:00:00";
12  date = 20141225; time = 0;
13  model=1;
14  }else if(yr.Contains("15pA")){
15  storeTime="2015-05-05 12:00:00";
16  date = 20150506; time = 0;
17  model=2;
18  }else if(yr.Contains("15sim")){
19  storeTime="2014-12-10 00:00:00";
20  date = 20141215; time = 0;
21  }else if(yr.Contains("17ofl")){
22  storeTime="2016-12-20 00:00:00";
23  date = 20161225; time = 0;
24  model=3;
25  }else if(yr.Contains("17sim")){
26  storeTime="2016-12-10 00:00:00";
27  date = 20161215; time = 0;
28  }else{
29  std::cout << "Please specify valid year tag\n"; exit;
30  }
31  std::cout << "Opt =" << opt << "\n";
32  std::cout << "writedb = " << option.Contains("write") << "\n";
33  std::cout << "storetime =" << storeTime << "\n";
34  std::cout << "date,time =" << date <<" "<< time << "\n";
35 
36  gROOT->Macro("loadlib.C");
37 
38  fmsPositionModel_st table;
39  if(option.Contains("writedb")) {
40  gSystem->Setenv("DB_ACCESS_MODE","write");
42  StDbConfigNode* node = mgr->initConfig("Geometry_fms");
43  StDbTable* dbtable = node->addDbTable("fmsPositionModel");
44  mgr->setStoreTime(storeTime.Data());
45 
46  table.model = model;
47 
48  dbtable->SetTable((char*)&table, 1);
49  if(yr.Contains("sim")) dbtable->setFlavor("sim");
50  mgr->storeDbTable(dbtable);
51  std::cout << "INFO: table saved to database" << std::endl;
52  }
53 
54  std::cout << "INFO: Reading database" << std::endl;
55  gSystem->Unsetenv("DB_ACCESS_MODE");
56  //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
57  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
58  dbMk->SetDebug();
59  dbMk->SetDateTime(date,time); // event or run start time, set to your liking
60  if(yr.Contains("ofl")) {dbMk->SetFlavor("ofl");}
61  else if(yr.Contains("sim")) {dbMk->SetFlavor("sim");}
62  dbMk->Init();
63  dbMk->Make();
64  TDataSet *DB = 0;
65  DB = dbMk->GetDataBase("Geometry/fms/fmsPositionModel");
66  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
67  St_fmsPositionModel *dataset = 0;
68  dataset = (St_fmsPositionModel*) DB->Find("fmsPositionModel");
69  if (!dataset) {
70  td::cout << "ERROR: dataset does not contain requested table" << std::endl;
71  return;
72  }
73  Int_t rows = dataset->GetNRows();
74  if (rows > 1) {
75  std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
76  }
77  TDatime val[2];
78  dbMk->GetValidity((TTable*)dataset,val);
79  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - "
80  << val[1].GetDate() << "." << val[1].GetTime() << " ] "
81  << std::endl;
82  fmsPositionModel_st *tbl = dataset->GetTable();
83  for (Int_t i = 0; i < rows; i++) {
84  std::cout << Form("Row=%d Model=%d\n",i,tbl[i].model);
85  }
86 }
virtual Int_t Make()
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc&#39;d version of data for StRoot
Definition: StDbTable.cc:550
Definition: TTable.h:48
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362