StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fpsChannelGeometry_db.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fpsChannelGeometry_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 = 12;
32  fpsChannelGeometry_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("fpsChannelGeometry");
39  mgr->setStoreTime(storeTime.Data());
40 
41  table[ 0].quad = 1; table[ 0].layer = 1; table[ 0].nslat = 21;
42  table[ 1].quad = 1; table[ 1].layer = 2; table[ 1].nslat = 21;
43  table[ 2].quad = 1; table[ 2].layer = 3; table[ 2].nslat = 21;
44  table[ 3].quad = 2; table[ 3].layer = 1; table[ 3].nslat = 19;
45  table[ 4].quad = 2; table[ 4].layer = 2; table[ 4].nslat = 19;
46  table[ 5].quad = 2; table[ 5].layer = 3; table[ 5].nslat = 19;
47  table[ 6].quad = 3; table[ 6].layer = 1; table[ 6].nslat = 21;
48  table[ 7].quad = 3; table[ 7].layer = 2; table[ 7].nslat = 21;
49  table[ 8].quad = 3; table[ 8].layer = 3; table[ 8].nslat = 21;
50  table[ 9].quad = 4; table[ 9].layer = 1; table[ 9].nslat = 19;
51  table[10].quad = 4; table[10].layer = 2; table[10].nslat = 19;
52  table[11].quad = 4; table[11].layer = 3; table[11].nslat = 19;
53 
54  dbtable->SetTable((char*)&table, MAX_DB_INDEX);
55  if(yr.Contains("sim")) dbtable->setFlavor("sim");
56  mgr->storeDbTable(dbtable);
57  std::cout << "INFO: table saved to database" << std::endl;
58  }
59 
60  std::cout << "INFO: Reading database" << std::endl;
61  gSystem->Unsetenv("DB_ACCESS_MODE");
62  //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
63  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
64  dbMk->SetDebug();
65  dbMk->SetDateTime(date,time); // event or run start time, set to your liking
66  if(yr.Contains("ofl")) {dbMk->SetFlavor("ofl");}
67  else if(yr.Contains("sim")) {dbMk->SetFlavor("sim");}
68  dbMk->Init();
69  dbMk->Make();
70  TDataSet *DB = 0;
71  DB = dbMk->GetDataBase("Geometry/fps/fpsChannelGeometry");
72  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
73  St_fpsChannelGeometry *dataset = 0;
74  dataset = (St_fpsChannelGeometry*) DB->Find("fpsChannelGeometry");
75  if (!dataset) {
76  td::cout << "ERROR: dataset does not contain requested table" << std::endl;
77  return;
78  }
79  Int_t rows = dataset->GetNRows();
80  if (rows > 1) {
81  std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
82  }
83  TDatime val[2];
84  dbMk->GetValidity((TTable*)dataset,val);
85  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - "
86  << val[1].GetDate() << "." << val[1].GetTime() << " ] "
87  << std::endl;
88  fpsChannelGeometry_st *tbl = dataset->GetTable();
89  for (Int_t i = 0; i < rows; i++) {
90  std::cout << Form("Row=%4d quad=%1d layer=%1d nslat=%2d\n",i,
91  tbl[i].quad,tbl[i].layer,tbl[i].nslat);
92  }
93 }
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