4 void fpsPedSV2017_db(
char* opt=
"",
char* year=
"",
char* filename=
"fps_good_physics_ped/18080012.txt"){
5 TString option(opt), yr(year);
6 stringstream f1(filename);
12 std::cout <<
"Opt =" << opt <<
"\n";
13 std::cout <<
"write = " << option.Contains(
"writedb") <<
"\n";
15 gROOT->Macro(
"loadlib.C");
17 const Int_t MAX_DB_INDEX = 252;
18 fpsPed_st table[MAX_DB_INDEX];
19 int idList[MAX_DB_INDEX];
20 memset(table,0,
sizeof(table));
21 memset(idList,0,
sizeof(idList));
23 int idx = f1.str().find(
"/");
24 cout <<
"idx: " << idx << endl;
25 stringstream f2(f1.str().substr(idx+1,8));
26 cout << f2.str() << endl;
30 cout << f1.str() <<
" idx="<<idx <<
" f2="<<f2.str() <<
" run="<<run << endl;
32 char *onlserver=
"onldb2", *bakserver=
"dbbak", *server=0;
43 char cmd[300]=Form(
"mysql -h %s.starp.bnl.gov --port=%d -N -s -e \"SELECT startRunTime FROM RunLog.runDescriptor WHERE runNumber=%d LIMIT 1\"",
45 TString st=gSystem->GetFromPipe(cmd);
48 date=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%Y%%m%%d",starttime)).Atoi();
49 time=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%H%%M%%S",starttime)).Atoi();
51 cout <<
"start time="<<starttime<<
" date="<<date<<
" time="<<time<< endl;
52 if(yr.Contains(
"17ofl")){
53 storeTime=
"2016-12-20 00:00:01";
54 date = 20161220; time = 0;
56 }
else if(yr.Contains(
"17sim")){
57 storeTime=
"2016-12-10 00:00:02";
58 date = 20161210; time = 0;
62 std::cout <<
"unix storetime =" << starttime-10 << endl;
63 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
65 std::cout <<
"storetime =" << storeTime <<
"\n";
66 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
69 ifstream fp(filename);
71 cout <<
"Reading "<<filename<<
" run#="<<run<<endl;
75 float mip=-1,sigma=-1;
77 fp >>
id >> mip >> sigma;
78 if(
id == -1 ){
continue;}
83 printf(
"n=%3d Id=%5d MIP=%6.2f Sigma=%6.2f idList=%3d\n",
84 n,table[n].slatid,table[n].Mean,table[n].Sigma,idList[n]);
88 printf(
"read %d channels from %s\n",n,filename);
92 cout <<
"Could not open: " << filename << endl;
96 if(option.Contains(
"writedb")) {
97 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
100 StDbTable* dbtable = node->addDbTable(
"fpsPed");
102 mgr->setStoreTime(starttime-10);
104 mgr->setStoreTime(storeTime.Data());
106 dbtable->
SetTable((
char*)&table, n, idList);
107 if(yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
108 mgr->storeDbTable(dbtable);
109 std::cout <<
"INFO: table saved to database" << std::endl;
112 std::cout <<
"INFO: Reading database" << std::endl;
113 gSystem->Unsetenv(
"DB_ACCESS_MODE");
117 dbMk->SetDateTime(date,time);
118 if(yr.Contains(
"ofl")) {dbMk->SetFlavor(
"ofl");}
119 else if(yr.Contains(
"sim")) {dbMk->SetFlavor(
"sim");}
123 DB = dbMk->GetDataBase(
"Calibrations/fps/fpsPed");
124 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
125 St_fpsPed *dataset = 0;
126 dataset = (St_fpsPed*) DB->
Find(
"fpsPed");
128 td::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
131 Int_t rows = dataset->GetNRows();
133 std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
136 dbMk->GetValidity((
TTable*)dataset,val);
137 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
138 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] "
140 fpsPed_st *tbl = dataset->GetTable();
141 for (Int_t i = 0; i < rows; i++) {
142 std::cout << Form(
"Row=%4d slatid=%3d MIP=%8.4f Sig=%8.4f\n",i,
143 tbl[i].slatid,tbl[i].Mean,tbl[i].Sigma);
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