StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fpsConstant_db.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fpsConstant_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:02";
14  date = 20141210; time = 2;
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 << "writedb = " << option.Contains("write") << "\n";
26  std::cout << "storetime =" << storeTime << "\n";
27  std::cout << "date,time =" << date <<" "<< time << "\n";
28 
29  gROOT->Macro("loadlib.C");
30 
31  fpsConstant_st table;
32  if(option.Contains("writedb")) {
33  gSystem->Setenv("DB_ACCESS_MODE","write");
35  StDbConfigNode* node = mgr->initConfig("Geometry_fps");
36  StDbTable* dbtable = node->addDbTable("fpsConstant");
37  mgr->setStoreTime(storeTime.Data());
38 
39  table.nQuad = 4;
40  table.nLayer = 3;
41  table.maxSlat = 21;
42  table.maxQTaddr = 8;
43  table.maxQTch = 32;
44 
45  dbtable->SetTable((char*)&table, 1);
46  if(yr.Contains("sim")) dbtable->setFlavor("sim");
47  mgr->storeDbTable(dbtable);
48  std::cout << "INFO: table saved to database" << std::endl;
49  }
50 
51  std::cout << "INFO: Reading database" << std::endl;
52  gSystem->Unsetenv("DB_ACCESS_MODE");
53  //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
54  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
55  dbMk->SetDebug();
56  dbMk->SetDateTime(date,time); // event or run start time, set to your liking
57  if(yr.Contains("ofl")) {dbMk->SetFlavor("ofl");}
58  else if(yr.Contains("sim")) {dbMk->SetFlavor("sim");}
59  dbMk->Init();
60  dbMk->Make();
61  TDataSet *DB = 0;
62  DB = dbMk->GetDataBase("Geometry/fps/fpsConstant");
63  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
64  St_fpsConstant *dataset = 0;
65  dataset = (St_fpsConstant*) DB->Find("fpsConstant");
66  if (!dataset) {
67  td::cout << "ERROR: dataset does not contain requested table" << std::endl;
68  return;
69  }
70  Int_t rows = dataset->GetNRows();
71  if (rows > 1) {
72  std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
73  }
74  TDatime val[2];
75  dbMk->GetValidity((TTable*)dataset,val);
76  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - "
77  << val[1].GetDate() << "." << val[1].GetTime() << " ] "
78  << std::endl;
79  fpsConstant_st *tbl = dataset->GetTable();
80  for (Int_t i = 0; i < rows; i++) {
81  std::cout << Form("Row=%d nQuad=%1d nLayer=%1d maxSlat=%2d maxQTaddr=%1d maxQTch=%2d\n",i,
82  tbl[i].nQuad,tbl[i].nLayer,tbl[i].maxSlat,
83  tbl[i].maxQTaddr,tbl[i].maxQTch);
84  }
85 }
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