4 void fpsStatus_db(
char* opt=
"",
char* year=
"15ofl",
int badch=0,
int readdate=0,
int readtime=0) {
5 TString option(opt), yr(year);
8 std::cout <<
"year = " << year <<
"\n";
9 if(yr.Contains(
"15ofl")){
10 storeTime=
"2014-12-20 00:00:00";
11 date = 20141220; time = 1;
12 }
else if(yr.Contains(
"15sim")){
13 storeTime=
"2014-12-10 00:00:00";
14 date = 20141210; time = 1;
16 std::cout <<
"Please specify valid year tag\n"; exit;
18 if(readdate>0) date=readdate;
19 if(readtime>0) time=readtime;
20 std::cout <<
"Opt =" << opt <<
"\n";
21 std::cout <<
"write = " << option.Contains(
"writedb") <<
"\n";
22 std::cout <<
"storetime =" << storeTime <<
"\n";
23 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
25 TString storeTime1, storeTime2;
26 int badq,badl,bads,status1,status2;
28 badq=3; badl=3; bads=16;
29 storeTime1=
"2015-02-20 00:00:00"; status1=1;
30 storeTime2=
"2015-07-04 00:00:00"; status2=0;
32 badq=1; badl=1; bads=1;
33 storeTime1=
"2015-04-15 12:00:00"; status1=1;
34 storeTime2=
"2015-04-27 12:00:00"; status2=0;
36 badq=4; badl=1; bads=14;
37 storeTime1=
"2015-04-15 12:00:01"; status1=1;
38 storeTime2=
"2015-04-22 12:00:00"; status2=0;
41 gROOT->Macro(
"loadlib.C");
43 const Int_t MAX_DB_INDEX = 252;
44 fpsStatus_st table[MAX_DB_INDEX];
47 if(option.Contains(
"writedb")) {
48 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
51 StDbTable* dbtable = node->addDbTable(
"fpsStatus");
52 if(yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
55 mgr->setStoreTime(storeTime.Data());
57 for (Int_t q = 1; q <= 4; q++) {
58 for (Int_t l = 1; l <= 3; l++) {
59 for (Int_t s = 1; s <= 21; s++) {
60 table[id].slatid = id;
65 if(flag==0){table[id].slatid = id; table[id].status=0;}
66 else {table[id].slatid = id; table[id].status=9;}
71 dbtable->
SetTable((
char*)&table, MAX_DB_INDEX);
72 mgr->storeDbTable(dbtable);
73 std::cout <<
"INFO: table saved to database" << std::endl;
76 id=(badq-1)*3*21+(badl-1)*21+(bads-1);
80 table[0].status= status1;
81 mgr->setStoreTime(storeTime1.Data());
82 dbtable->
SetTable((
char*)&table,1,idList);
83 mgr->storeDbTable(dbtable);
84 printf(
"Q%1dL%1dS%02d SlatId=%3d Row=%3d Stat=%d saved on %s\n",
85 badq,badl,bads,
id,idList[0],table[0].status,storeTime1.Data());
87 table[0].status= status2;
88 mgr->setStoreTime(storeTime2.Data());
89 dbtable->
SetTable((
char*)&table,1,idList);
90 mgr->storeDbTable(dbtable);
91 printf(
"Q%1dL%1dS%02d SlatId=%3d Row=%3d Stat=%d saved on %s\n",
92 badq,badl,bads,
id,idList[0],table[0].status,storeTime2.Data());
96 std::cout <<
"INFO: Reading database" << std::endl;
97 gSystem->Unsetenv(
"DB_ACCESS_MODE");
101 dbMk->SetDateTime(date,time);
102 if(yr.Contains(
"ofl")) {dbMk->SetFlavor(
"ofl");}
103 else if(yr.Contains(
"sim")) {dbMk->SetFlavor(
"sim");}
107 DB = dbMk->GetDataBase(
"Calibrations/fps/fpsStatus");
108 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
109 St_fpsStatus *dataset = 0;
110 dataset = (St_fpsStatus*) DB->
Find(
"fpsStatus");
112 td::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
115 Int_t rows = dataset->GetNRows();
117 std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
120 dbMk->GetValidity((
TTable*)dataset,val);
121 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
122 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] "
124 fpsStatus_st *tbl = dataset->GetTable();
125 id=(badq-1)*3*21+(badl-1)*21+(bads-1);
126 for (Int_t i = 0; i < rows; i++) {
127 if(badch>0 && i!=
id)
continue;
128 std::cout << Form(
"Row=%4d slatid=%3d status=%d\n",i,
129 tbl[i].slatid,tbl[i].status);
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc'd version of data for StRoot
static StDbManager * Instance()
strdup(..) is not ANSI
virtual TDataSet * Find(const char *path) const