5 static const Int_t MAX = 2500;
6 static const Int_t MAXD = 14;
7 static const Int_t MAXCH= 578;
9 int getDetectorId(
int ew,
int nstb) {
return (ew-1)*8+nstb-1;}
10 int getEW(
int detid) {
return detid/8 + 1;}
11 int getNSTB(
int detid) {
return detid%8 + 1;}
13 void fms_db_fmsgaincorrB_chong(
char* option =
"",
14 char* filename =
"chong/FmsGainCorr_16066033.txt",
15 char* flavor=
"fmsGainCorr-BNL-C",
19 TString opt(option), file(filename);
20 int idx=file.Index(
"_");
21 TString f2=file(idx+1,8);
23 int year=run/1000000-1;
25 printf(
"%s run=%d year=%d port=%d\n",file.Data(),run,year,port);
27 gROOT->Macro(
"loadlib.C");
28 gSystem->Load(
"St_base.so");
29 gSystem->Load(
"libStDb_Tables.so");
30 gSystem->Load(
"StDbLib.so");
32 char cmd[300]=Form(
"mysql -h db04.star.bnl.gov --port=%d -N -s -e \"SELECT startRunTime FROM RunLog.runDescriptor WHERE runNumber=%d LIMIT 1\"",
34 TString st=gSystem->GetFromPipe(cmd);
35 int starttime=st.Atoi();
36 int readDate=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%Y%%m%%d",starttime)).Atoi();
37 int readTime=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%H%%M%%S",starttime)).Atoi();
38 printf(
"For run %d, online DB run starttime=%d - %d(secOffset) and DB readig date=%d time=%d\n",
39 run,starttime,secOffset,readDate,readTime);
42 fmsGainCorrectionB_st corr;
43 memset(&corr,0,
sizeof(corr));
49 cout <<
"Reading "<<filename<<
"\n";
50 if(fp=fopen(filename,
"r")){
51 while(fscanf(fp,
"%d %d %d %f",&rew,&rnstb,&rch,&rcorr) != EOF){
52 int detid=getDetectorId(rew,rnstb);
53 if(detid<0 || rch<1) {
54 printf(
"Invalid ch#: det=%d ew=%d nstb=%d rch=%d\n",detid,rew,rnstb,rch,rcorr);
58 corr.detectorId[nread]=detid;
60 corr.corr[nread]=rcorr;
61 printf(
"n=%4d det=%2d ew=%1d nstb=%1d ch=%3d corr=%8.6f\n",nread,detid,rew,rnstb,rch,rcorr);
66 printf(
"read %d channels of gain corr\n",nread);
68 if(opt.Contains(
"writedb")) {
69 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
75 StDbTable* table = node->addDbTable(
"fmsGainCorrectionB");
76 mgr->setStoreTime(starttime - secOffset);
81 table->setFlavor(flavor);
82 mgr->storeDbTable(table);
85 gSystem->Unsetenv(
"DB_ACCESS_MODE");
87 std::cout <<
"Done with database upload"<< endl;
90 if(opt.Contains(
"readdb")){
91 gSystem->Load(
"StChain");
92 gSystem->Load(
"StBFChain");
93 gSystem->Load(
"StUtilities");
94 gSystem->Load(
"StIOMaker");
95 gSystem->Load(
"StarClassLibrary");
96 gSystem->Load(
"St_Tables");
97 gSystem->Load(
"StDbLib");
98 gSystem->Load(
"StDbBroker");
99 gSystem->Load(
"St_db_Maker");
103 dbMk->SetDateTime(readDate,readTime);
104 dbMk->SetFlavor(flavor);
113 DB = dbMk->GetInputDB(
"Calibrations/fms");
114 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
117 St_fmsGainCorrectionB *dbppmap = 0;
118 dbppmap = (St_fmsGainCorrectionB*) DB->
Find(
"fmsGainCorrectionB");
122 std::cout <<
"Reading fmsGainCorrectionB table\n";
123 fmsGainCorrectionB_st *pptable = dbppmap->GetTable();
124 for(
int i=0; i<MAX; i++){
125 if(pptable[0].ch[i]>0){
126 printf(
"%3d%8d%8d%8.4f\n",
127 int(pptable[0].detectorId[i]/8+1),
int(pptable[0].detectorId[i]%8+1),
128 int(pptable[0].ch[i]),
float(pptable[0].corr[i]) );
133 std::cout <<
"WARNING: No data in fmsGainCorr table (wrong timestamp?). Nothing to return, then.\n";
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