4 void fpostPedSV2017_db(
char* opt=
"",
char* year=
"",
char* filename=
"fpost_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 = 241;
18 fpostPed_st table[MAX_DB_INDEX];
19 int idList[MAX_DB_INDEX];
20 memset(table,0,
sizeof(table));
21 memset(idList,0,
sizeof(idList));
27 int idx = f1.str().find(
"/");
28 cout <<
"idx: " << idx << endl;
29 stringstream f2(f1.str().substr(idx+1,8));
30 cout << f2.str() << endl;
34 cout << f1.str() <<
" idx="<<idx <<
" f2="<<f2.str() <<
" run="<<run << endl;
36 char *onlserver=
"onldb2", *bakserver=
"dbbak", *server=0;
47 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\"",
49 TString st=gSystem->GetFromPipe(cmd);
52 date=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%Y%%m%%d",starttime)).Atoi();
53 time=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%H%%M%%S",starttime)).Atoi();
55 cout <<
"start time="<<starttime<<
" date="<<date<<
" time="<<time<< endl;
56 if(yr.Contains(
"17ofl")){
57 storeTime=
"2016-12-20 00:00:01";
58 date = 20161220; time = 0;
60 }
else if(yr.Contains(
"17sim")){
61 storeTime=
"2016-12-10 00:00:02";
62 date = 20161210; time = 0;
66 std::cout <<
"unix storetime =" << starttime-10 << endl;
67 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
69 std::cout <<
"storetime =" << storeTime <<
"\n";
70 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
73 ifstream fp(filename);
75 cout <<
"Reading "<<filename<<
" run#="<<run<<endl;
79 float mip=-1,sigma=-1;
81 fp >>
id >> mip >> sigma;
82 if(
id == -1 ){
continue;}
87 printf(
"n=%3d Id=%5d MIP=%6.2f Sigma=%6.2f idList=%3d\n",
88 n,table[n].slatid,table[n].Mean,table[n].Sigma,idList[n]);
92 printf(
"read %d channels from %s\n",n,filename);
96 cout <<
"Could not open: " << filename << endl;
100 if(option.Contains(
"writedb")) {
101 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
104 StDbTable* dbtable = node->addDbTable(
"fpostPed");
106 mgr->setStoreTime(starttime-10);
108 mgr->setStoreTime(storeTime.Data());
110 dbtable->
SetTable((
char*)&table, n, idList);
111 if(yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
112 mgr->storeDbTable(dbtable);
113 std::cout <<
"INFO: table saved to database" << std::endl;
116 std::cout <<
"INFO: Reading database" << std::endl;
117 gSystem->Unsetenv(
"DB_ACCESS_MODE");
121 dbMk->SetDateTime(date,time);
122 if(yr.Contains(
"ofl")) {dbMk->SetFlavor(
"ofl");}
123 else if(yr.Contains(
"sim")) {dbMk->SetFlavor(
"sim");}
127 DB = dbMk->GetDataBase(
"Calibrations/fps/fpostPed");
128 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
129 St_fpostPed *dataset = 0;
130 dataset = (St_fpostPed*) DB->
Find(
"fpostPed");
132 td::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
135 Int_t rows = dataset->GetNRows();
137 std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
140 dbMk->GetValidity((
TTable*)dataset,val);
141 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
142 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] "
144 fpostPed_st *tbl = dataset->GetTable();
145 for (Int_t i = 0; i < rows; i++) {
146 std::cout << Form(
"Row=%4d slatid=%3d MIP=%8.4f Sig=%8.4f\n",i,
147 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