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