4 void fmsBitShiftGainB_db(
char* opt=
"",
char* year=
"15ofl",
char* filename=
"bitshift/fmsBitShiftGain_all0.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 = 2500;
17 fmsBitShiftGainB_st table;
18 memset(&table,0,
sizeof(table));
20 int idx=f1.Index(
"run");
21 TString f2=f1(idx+3,8);
23 printf(
"%s idx=%d f2=%s run=%d\n",f1.Data(),idx,f2.Data(),run);
26 char *onlserver=
"heston",*bakserver=
"db04",*server=0;
36 char cmd[300]=Form(
"mysql -h %s.star.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;
47 if(yr.Contains(
"11ofl")){
48 storeTime=
"2010-12-20 00:00:00";
49 date = 20101225; time = 0;
51 }
else if(yr.Contains(
"11sim")){
52 storeTime=
"2010-12-10 00:00:00";
53 date = 20101215; time = 0;
55 }
else if(yr.Contains(
"15ofl")){
56 storeTime=
"2014-12-20 00:00:00";
57 date = 20141225; time = 0;
59 }
else if(yr.Contains(
"15sim")){
60 storeTime=
"2014-12-10 00:00:00";
61 date = 20141215; time = 0;
63 }
else if(yr.Contains(
"16ofl")){
64 storeTime=
"2015-12-20 00:00:00";
65 date = 20151225; time = 0;
67 }
else if(yr.Contains(
"16sim")){
68 storeTime=
"2015-12-10 00:00:00";
69 date = 20151215; time = 0;
71 }
else if(yr.Contains(
"17ofl")){
72 storeTime=
"2016-12-20 00:00:00";
73 date = 20161225; time = 0;
75 }
else if(yr.Contains(
"17sim")){
76 storeTime=
"2016-12-10 00:00:00";
77 date = 20161215; time = 0;
81 std::cout <<
"unix storetime =" << starttime-10 << endl;
82 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
84 std::cout <<
"storetime =" << storeTime <<
"\n";
85 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
91 cout <<
"Reading "<<filename<<
" run#="<<run<<endl;
92 if(fp=fopen(filename,
"r")){
93 while(fscanf(fp,
"%d %d %d",&d,&c,&s) != EOF){
94 table.detectorId[n]=d;
97 printf(
"n=%3d d=%3d c=%3d bitshift=%3d\n",
98 n,table.detectorId[n],table.ch[n],table.bitshift[n]);
103 printf(
"read %d channels from %s\n",n,filename);
105 if(option.Contains(
"writedb")) {
106 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
109 StDbTable* dbtable = node->addDbTable(
"fmsBitShiftGainB");
111 mgr->setStoreTime(starttime-10);
113 mgr->setStoreTime(storeTime.Data());
115 dbtable->
SetTable((
char*)&table, 1);
116 if(yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
117 mgr->storeDbTable(dbtable);
118 std::cout <<
"INFO: table saved to database" << std::endl;
121 std::cout <<
"INFO: Reading database" << std::endl;
122 gSystem->Unsetenv(
"DB_ACCESS_MODE");
126 dbMk->SetDateTime(date,time);
127 if(yr.Contains(
"ofl")) {dbMk->SetFlavor(
"ofl");}
128 else if(yr.Contains(
"sim")) {dbMk->SetFlavor(
"sim");}
132 DB = dbMk->GetDataBase(
"Calibrations/fms/fmsBitShiftGainB");
133 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
134 St_fmsBitShiftGainB *dataset = 0;
135 dataset = (St_fmsBitShiftGainB*) DB->
Find(
"fmsBitShiftGainB");
137 td::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
140 Int_t rows = dataset->GetNRows();
142 std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
145 dbMk->GetValidity((
TTable*)dataset,val);
146 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
147 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] "
149 fmsBitShiftGainB_st *tbl = dataset->GetTable();
150 for (Int_t i = 0; i < MAX_DB_INDEX; i++) {
152 std::cout << Form(
"%2d %3d %2d\n",
153 tbl.detectorId[i],tbl.ch[i],tbl.bitshift[i]);
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