StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fpsGain_db.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fpsGain_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 = 20141225; time = 0;
12  }else if(yr.Contains("15sim")){
13  storeTime="2014-12-10 00:00:02";
14  date = 20141215; time = 0;
15  }else{
16  std::cout << "Please specify valid year tag\n"; exit;
17  }
18  std::cout << "Opt =" << opt << "\n";
19  std::cout << "write = " << option.Contains("writedb") << "\n";
20  std::cout << "storetime =" << storeTime << "\n";
21  std::cout << "date,time =" << date <<" "<< time << "\n";
22 
23  gROOT->Macro("loadlib.C");
24 
25  const Int_t MAX_DB_INDEX = 252;
26  fpsGain_st table[MAX_DB_INDEX];
27 
28  if(option.Contains("writedb")) {
29  gSystem->Setenv("DB_ACCESS_MODE","write");
31  StDbConfigNode* node = mgr->initConfig("Calibrations_fps");
32  StDbTable* dbtable = node->addDbTable("fpsGain");
33  mgr->setStoreTime(storeTime.Data());
34 
35  int id=0;
36  for (Int_t q = 1; q <= 4; q++) {
37  for (Int_t l = 1; l <= 3; l++) {
38  for (Int_t s = 1; s <= 21; s++) {
39  table[id].slatid = id;
40  int flag=0;
41  if(q==2 || q==4){
42  if(s>=20) flag=1;
43  }
44  float mip=100.0;
45  if(l==3) mip=50.0;
46  if(flag==0){table[id].slatid = id; table[id].MIP=mip;}
47  else {table[id].slatid = id; table[id].MIP=0;}
48  printf("id=%3d Q%1dL%1dS%2d mip=%f\n",id,q,l,s,table[id].MIP);
49  id++;
50  }
51  }
52  }
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("Calibrations/fps/fpsGain");
72  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
73  St_fpsGain *dataset = 0;
74  dataset = (St_fpsGain*) DB->Find("fpsGain");
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  fpsGain_st *tbl = dataset->GetTable();
89  for (Int_t i = 0; i < rows; i++) {
90  std::cout << Form("Row=%4d slatid=%3d MIP=%8.4f\n",i,
91  tbl[i].slatid,tbl[i].MIP);
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