4 void fpsGainSV_db(
char* opt=
"",
char* year=
"",
char* filename=
"fpsgain/pAu200_16125035.txt"){
5 TString option(opt), yr(year),f1(filename);
11 std::cout <<
"Opt =" << opt <<
"\n";
12 std::cout <<
"write = " << option.Contains(
"writedb") <<
"\n";
14 gROOT->Macro(
"loadlib.C");
16 const Int_t MAX_DB_INDEX = 252;
17 fpsGain_st table[MAX_DB_INDEX];
18 int idList[MAX_DB_INDEX];
19 memset(table,0,
sizeof(table));
20 memset(idList,0,
sizeof(idList));
22 int idx=f1.Index(
"_");
23 TString f2=f1(idx+1,8);
25 printf(
"%s idx=%d f2=%s run=%d\n",f1.Data(),idx,f2.Data(),run);
27 char *onlserver=
"onldb2",*bakserver=
"dbbak",*server=0;
37 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\"",
39 TString st=gSystem->GetFromPipe(cmd);
42 date=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%Y%%m%%d",starttime)).Atoi();
43 time=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%H%%M%%S",starttime)).Atoi();
45 cout <<
"start time="<<starttime<<
" date="<<date<<
" time="<<time<< endl;
46 if(yr.Contains(
"15ofl")){
47 storeTime=
"2014-12-20 00:00:01";
48 date = 20141225; time = 0;
50 }
else if(yr.Contains(
"15sim")){
51 storeTime=
"2014-12-10 00:00:02";
52 date = 20141215; time = 0;
56 std::cout <<
"unix storetime =" << starttime-10 << endl;
57 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
59 std::cout <<
"storetime =" << storeTime <<
"\n";
60 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
65 float mip,sigma,valley;
67 cout <<
"Reading "<<filename<<
" run#="<<run<<endl;
68 if(fp=fopen(filename,
"r")){
69 while(fscanf(fp,
"%d %f %f %f",&
id,&mip,&sigma,&valley) != EOF){
73 table[n].Valley=valley;
75 printf(
"n=%3d Id=%5d MIP=%6.2f Sigma=%6.2f Valley=%6.2f idList=%3d\n",
76 n,table[n].slatid,table[n].MIP,table[n].Sigma,table[n].Valley,idList[n]);
81 printf(
"read %d channels from %s\n",n,filename);
83 if(option.Contains(
"writedb")) {
84 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
87 StDbTable* dbtable = node->addDbTable(
"fpsGain");
89 mgr->setStoreTime(starttime-10);
91 mgr->setStoreTime(storeTime.Data());
93 dbtable->
SetTable((
char*)&table, n, idList);
94 if(yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
95 mgr->storeDbTable(dbtable);
96 std::cout <<
"INFO: table saved to database" << std::endl;
99 std::cout <<
"INFO: Reading database" << std::endl;
100 gSystem->Unsetenv(
"DB_ACCESS_MODE");
104 dbMk->SetDateTime(date,time);
105 if(yr.Contains(
"ofl")) {dbMk->SetFlavor(
"ofl");}
106 else if(yr.Contains(
"sim")) {dbMk->SetFlavor(
"sim");}
110 DB = dbMk->GetDataBase(
"Calibrations/fps/fpsGain");
111 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
112 St_fpsGain *dataset = 0;
113 dataset = (St_fpsGain*) DB->
Find(
"fpsGain");
115 td::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
118 Int_t rows = dataset->GetNRows();
120 std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
123 dbMk->GetValidity((
TTable*)dataset,val);
124 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
125 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] "
127 fpsGain_st *tbl = dataset->GetTable();
128 for (Int_t i = 0; i < rows; i++) {
129 std::cout << Form(
"Row=%4d slatid=%3d MIP=%8.4f Sig=%8.4f Val=%8.4f\n",i,
130 tbl[i].slatid,tbl[i].MIP,tbl[i].Sigma,tbl[i].Valley);
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