4 void fmsBitShiftGain_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 = 1732;
17 fmsBitShiftGain_st table[MAX_DB_INDEX];
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=
"onldb2",*bakserver=
"dbbak",*server=0;
36 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\"",
38 TString st=gSystem->GetFromPipe(cmd);
41 date=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%Y%%m%%d",starttime)).Atoi();
42 time=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%H%%M%%S",starttime)).Atoi();
44 cout <<
"start time="<<starttime<<
" date="<<date<<
" time="<<time<< endl;
46 if(yr.Contains(
"15ofl")){
47 storeTime=
"2014-12-20 00:00:00";
48 date = 20141225; time = 0;
50 }
else if(yr.Contains(
"15sim")){
51 storeTime=
"2014-12-10 00:00:00";
52 date = 20141215; time = 0;
54 }
else if(yr.Contains(
"16ofl")){
55 storeTime=
"2015-12-20 00:00:00";
56 date = 20151225; time = 0;
58 }
else if(yr.Contains(
"16sim")){
59 storeTime=
"2015-12-10 00:00:00";
60 date = 20151215; time = 0;
62 }
else if(yr.Contains(
"17ofl")){
63 storeTime=
"2016-12-20 00:00:00";
64 date = 20161225; time = 0;
66 }
else if(yr.Contains(
"17sim")){
67 storeTime=
"2016-12-10 00:00:00";
68 date = 20161215; time = 0;
72 std::cout <<
"unix storetime =" << starttime-10 << endl;
73 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
75 std::cout <<
"storetime =" << storeTime <<
"\n";
76 std::cout <<
"read date,time =" << date <<
" "<< time <<
"\n";
82 cout <<
"Reading "<<filename<<
" run#="<<run<<endl;
83 if(fp=fopen(filename,
"r")){
84 while(fscanf(fp,
"%d %d %d",&d,&c,&s) != EOF){
85 table[n].detectorId=d;
88 printf(
"n=%3d d=%3d c=%3d bitshift=%3d\n",
89 n,table[n].detectorId,table[n].ch,table[n].bitshift);
94 printf(
"read %d channels from %s\n",n,filename);
96 if(option.Contains(
"writedb")) {
97 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
100 StDbTable* dbtable = node->addDbTable(
"fmsBitShiftGain");
102 mgr->setStoreTime(starttime-10);
104 mgr->setStoreTime(storeTime.Data());
106 dbtable->
SetTable((
char*)&table, n);
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/fms/fmsBitShiftGain");
124 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
125 St_fmsBitShiftGain *dataset = 0;
126 dataset = (St_fmsBitShiftGain*) DB->
Find(
"fmsBitShiftGain");
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 fmsBitShiftGain_st *tbl = dataset->GetTable();
141 for (Int_t i = 0; i < rows; i++) {
142 std::cout << Form(
"Row=%4d d=%3d c=%3d bitshift=%3d\n",i,
143 tbl[i].detectorId,tbl[i].ch,tbl[i].bitshift);
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