StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fpsSlatId_db.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fpsSlatId_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  std::cout << "year = " << year << "\n";
9  if(yr.Contains("15ofl")){
10  storeTime="2014-12-20 00:00:01";
11  date = 20141220; time = 1;
12  }else if(yr.Contains("15sim")){
13  storeTime="2014-12-10 00:00:01";
14  date = 20141210; time = 1;
15  }else if(yr.Contains("17ofl")){
16  storeTime="2016-12-20 00:00:00";
17  date = 20161220; time = 0;
18  }else if(yr.Contains("17sim")){
19  storeTime="2016-12-10 00:00:00";
20  date = 20161210; time = 0;
21  }else{
22  std::cout << "Please specify valid year tag\n"; exit;
23  }
24  std::cout << "Opt =" << opt << "\n";
25  std::cout << "write = " << option.Contains("writedb") << "\n";
26  std::cout << "storetime =" << storeTime << "\n";
27  std::cout << "date,time =" << date <<" "<< time << "\n";
28 
29  gROOT->Macro("loadlib.C");
30 
31  const Int_t MAX_DB_INDEX = 252;
32  fpsSlatId_st table[MAX_DB_INDEX];
33 
34  if(option.Contains("writedb")) {
35  gSystem->Setenv("DB_ACCESS_MODE","write");
37  StDbConfigNode* node = mgr->initConfig("Geometry_fps");
38  StDbTable* dbtable = node->addDbTable("fpsSlatId");
39  mgr->setStoreTime(storeTime.Data());
40 
41  int id=0;
42  for (Int_t q = 1; q <= 4; q++) {
43  for (Int_t l = 1; l <= 3; l++) {
44  for (Int_t s = 1; s <= 21; s++) {
45  table[id].slatid = id;
46  int flag=0;
47  if(q==2 || q==4){
48  if(s>=20) flag=1;
49  }
50  if(flag==0){table[id].quad = q; table[id].layer = l; table[id].slat = s;}
51  else {table[id].quad = 0; table[id].layer = 0; table[id].slat = 0;}
52  id++;
53  }
54  }
55  }
56 
57  dbtable->SetTable((char*)&table, MAX_DB_INDEX);
58  if(yr.Contains("sim")) dbtable->setFlavor("sim");
59  mgr->storeDbTable(dbtable);
60  std::cout << "INFO: table saved to database" << std::endl;
61  }
62 
63  std::cout << "INFO: Reading database" << std::endl;
64  gSystem->Unsetenv("DB_ACCESS_MODE");
65  //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
66  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
67  dbMk->SetDebug();
68  dbMk->SetDateTime(date,time); // event or run start time, set to your liking
69  if(yr.Contains("ofl")) {dbMk->SetFlavor("ofl");}
70  else if(yr.Contains("sim")) {dbMk->SetFlavor("sim");}
71  dbMk->Init();
72  dbMk->Make();
73  TDataSet *DB = 0;
74  DB = dbMk->GetDataBase("Geometry/fps/fpsSlatId");
75  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
76  St_fpsSlatId *dataset = 0;
77  dataset = (St_fpsSlatId*) DB->Find("fpsSlatId");
78  if (!dataset) {
79  td::cout << "ERROR: dataset does not contain requested table" << std::endl;
80  return;
81  }
82  Int_t rows = dataset->GetNRows();
83  if (rows > 1) {
84  std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
85  }
86  TDatime val[2];
87  dbMk->GetValidity((TTable*)dataset,val);
88  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - "
89  << val[1].GetDate() << "." << val[1].GetTime() << " ] "
90  << std::endl;
91  fpsSlatId_st *tbl = dataset->GetTable();
92  for (Int_t i = 0; i < rows; i++) {
93  std::cout << Form("Row=%4d slatid=%3d quad=%2d layer=%2d slat=%2d\n",i,
94  tbl[i].slatid,tbl[i].quad,tbl[i].layer,tbl[i].slat);
95  }
96 }
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