7 void readElectronicsGain(
char* file,
float* eonl){
8 printf(
"Reading Electronics Gain file : %s\n",file);
9 FILE* F=fopen(file,
"r");
11 printf(
"Could not open %s\n",file);
19 while(fscanf(F,
"%d %d %d %d %f",&ehp,&ns,&dep,&ch,&gain) != EOF){
24 printf(
"ELECTRONICS GAIN ehp%1d ns%1d dep%02d ch%02d id=%3d idx=%4d gain=%f\n",
25 ehp,ns,dep,ch,
id,idx,eonl[idx]);
30 void fcsGain_db(
char* opt =
"",
char* input) {
31 gROOT->Macro(
"LoadLogger.C");
32 gSystem->Load(
"St_base.so");
33 gSystem->Load(
"libStDb_Tables.so");
34 gSystem->Load(
"StDbLib.so");
35 gSystem->Load(
"StChain");
36 gSystem->Load(
"StBFChain");
37 gSystem->Load(
"StUtilities");
38 gSystem->Load(
"StIOMaker");
39 gSystem->Load(
"StarClassLibrary");
40 gSystem->Load(
"St_Tables");
41 gSystem->Load(
"StDbLib");
42 gSystem->Load(
"StDbBroker");
43 gSystem->Load(
"St_db_Maker");
44 gSystem->Load(
"StFcsDbMaker.so");
48 mFcsDb->InitRun(23000000);
54 fcsEcalGainCorr_st ecorr;
55 fcsHcalGainCorr_st hcorr;
56 fcsPresValley_st pcorr;
57 fcsEcalGainOnline_st eonl;
58 fcsHcalGainOnline_st honl;
59 fcsPresThreshold_st ponl;
62 std::cout <<
"Opt =" << opt <<
"\n";
63 std::cout <<
"writedb = " << option.Contains(
"writedb") <<
"\n";
64 std::cout <<
"ecal = " << option.Contains(
"ecal") <<
"\n";
65 std::cout <<
"hcal = " << option.Contains(
"hcal") <<
"\n";
66 std::cout <<
"pres = " << option.Contains(
"pres") <<
"\n";
67 std::cout <<
"ehp = " << option.Contains(
"ehp") <<
"\n";
68 std::cout <<
"gain = " << option.Contains(
"gain") <<
"\n";
69 std::cout <<
"corr = " << option.Contains(
"corr") <<
"\n";
70 std::cout <<
"onl = " << option.Contains(
"onl") <<
"\n";
71 std::cout <<
"both = " << option.Contains(
"both") <<
"\n";
72 std::cout <<
"all = " << option.Contains(
"all") <<
"\n";
74 int ecal=0, hcal=0, pres=0, gain=0, corr=0, onl=0;
75 if(option.Contains(
"ecal") || option.Contains(
"ehp")) ecal=1;
76 if(option.Contains(
"hcal") || option.Contains(
"ehp")) hcal=1;
77 if(option.Contains(
"pres") || option.Contains(
"ehp")) pres=1;
78 if(option.Contains(
"gain") || option.Contains(
"both") || option.Contains(
"all")) gain=1;
79 if(option.Contains(
"corr") || option.Contains(
"both") || option.Contains(
"all")) corr=1;
80 if(option.Contains(
"onl") || option.Contains(
"all")) onl=1;
83 TString storeTime(
"");
85 if(
data.Contains(
"run22sim")){
86 storeTime =
"2021-10-15 00:00:00"; flavor=
"sim";
87 if(ecal && gain)
for(
int i=0; i<1496; i++) egain.gain[i]=0.0053;
88 if(hcal && gain)
for(
int i=0; i< 520; i++) hgain.gain[i]=0.0053;
89 if(pres && gain)
for(
int i=0; i< 384; i++) pgain.gain[i]=0.01;
90 if(ecal && corr)
for(
int i=0; i<1496; i++) ecorr.gaincorr[i]=1.0;
91 if(hcal && corr)
for(
int i=0; i< 520; i++) hcorr.gaincorr[i]=1.0;
92 if(pres && corr)
for(
int i=0; i< 384; i++) pcorr.valley[i]=0.5;
93 if(ecal && onl)
for(
int i=0; i<1496; i++) eonl.gainOnline[i]=1.0;
94 if(hcal && onl)
for(
int i=0; i< 520; i++) honl.gainOnline[i]=1.0;
95 if(pres && onl)
for(
int i=0; i< 384; i++) ponl.threshold[i]=200;
97 if(
data.Contains(
"run22ofl")){
98 storeTime =
"2021-10-25 00:00:10"; flavor=
"ofl";
99 if(ecal && gain)
for(
int i=0; i<1496; i++) egain.gain[i]=0.0053/5.31;
100 if(hcal && gain)
for(
int i=0; i< 520; i++) hgain.gain[i]=0.0053*1.3*1.21*1.65;
101 if(pres && gain)
for(
int i=0; i< 384; i++) pgain.gain[i]=1.0/600.0;
102 if(ecal && corr)
for(
int i=0; i<1496; i++) ecorr.gaincorr[i]=1.21;
103 if(hcal && corr)
for(
int i=0; i< 520; i++) hcorr.gaincorr[i]=1.0;
104 if(pres && corr)
for(
int i=0; i< 384; i++) pcorr.valley[i]=0.5;
105 if(ecal && onl)
for(
int i=0; i<1496; i++) eonl.gainOnline[i]=1.0;
106 if(hcal && onl)
for(
int i=0; i< 520; i++) honl.gainOnline[i]=1.0;
107 if(pres && onl)
for(
int i=0; i< 384; i++) ponl.threshold[i]=200;
109 if(
data.Contains(
"run22Dec01")){
110 storeTime =
"2021-12-01 00:00:10 "; flavor=
"ofl";
111 if(ecal && gain)
for(
int i=0; i<1496; i++) egain.gain[i]=0.0053/5.31*2.7;
113 if(
data.Contains(
"run22Dec21")){
114 storeTime =
"2021-12-22 03:50:10 "; flavor=
"ofl";
115 if(ecal && gain)
for(
int i=0; i<1496; i++) egain.gain[i]=0.0053;
116 if(hcal && onl)
for(
int i=0; i< 520; i++) honl.gainOnline[i]=1.3;
118 if(
data.Contains(
"run22Jan27")){
119 storeTime =
"2022-01-28 01:33:00 "; flavor=
"ofl";
120 if(hcal && gain)
for(
int i=0; i< 520; i++) hgain.gain[i]=0.0053*1.3*1.21;
121 if(pres && onl)
for(
int i=0; i< 384; i++) ponl.threshold[i]=250;
123 if(
data.Contains(
"run22Feb17")){
124 storeTime =
"2022-02-17 16:58:04"; flavor=
"ofl";
125 readElectronicsGain(
"ratio2_ecal_23047026_23005043.txt",eonl.gainOnline);
127 if(
data.Contains(
"run22Feb18")){
128 storeTime =
"2022-02-18 16:11:17"; flavor=
"ofl";
129 readElectronicsGain(
"ratio2a_ecal_23047026_23005043.txt",eonl.gainOnline);
131 if(
data.Contains(
"run22Feb28")){
132 storeTime =
"2022-02-28 17:26:56"; flavor=
"ofl";
133 readElectronicsGain(
"ratio2_ecal_23058015_23005043.txt",eonl.gainOnline);
135 if(
data.Contains(
"run22Mar07")){
136 storeTime =
"2022-03-07 20:52:07"; flavor=
"ofl";
137 readElectronicsGain(
"ratio2_ecal_23065037_23005043_0.5.txt",eonl.gainOnline);
139 if(
data.Contains(
"run22Mar14")){
140 storeTime =
"2022-03-14 20:26:28"; flavor=
"ofl";
141 if(ecal && onl)
for(
int i=0; i<1496; i++) eonl.gainOnline[i]=1.0;
145 std::cout<<
"Invalid year range"<<std::endl;
148 std::cout <<
"StoreTime="<<storeTime<<endl;
149 std::cout <<
"Flavor ="<<flavor<<endl;
150 if(ecal && gain) printf(
"INPUT EcalGain %f\n",egain.gain[0]);
151 if(hcal && gain) printf(
"INPUT HcalGain %f\n",hgain.gain[0]);
152 if(pres && gain) printf(
"INPUT PresGain %f\n",pgain.gain[0]);
153 if(ecal && corr) printf(
"INPUT EcalGainCorr %f\n",ecorr.gaincorr[0]);
154 if(hcal && corr) printf(
"INPUT HcalGainCorr %f\n",hcorr.gaincorr[0]);
155 if(pres && corr) printf(
"INPUT PresValley %f\n",pcorr.valley[0]);
156 if(ecal && onl) printf(
"INPUT EcalGainOnline %f\n",eonl.gainOnline[0]);
157 if(hcal && onl) printf(
"INPUT HcalGainOnline %f\n",honl.gainOnline[0]);
158 if(pres && onl) printf(
"INPUT PresThreshold %f\n",ponl.threshold[0]);
160 if(option.Contains(
"writedb")) {
161 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
162 cout <<
"DB_ACCESS_MODE="<<gSystem->Getenv(
"DB_ACCESS_MODE")<<endl;
165 mgr->setStoreTime(storeTime.Data());
167 StDbTable* table = node->addDbTable(
"fcsEcalGain");
169 table->setFlavor(flavor.Data());
170 mgr->storeDbTable(table);
173 StDbTable* table = node->addDbTable(
"fcsHcalGain");
175 table->setFlavor(flavor.Data());
176 mgr->storeDbTable(table);
179 StDbTable* table = node->addDbTable(
"fcsPresGain");
181 table->setFlavor(flavor.Data());
182 mgr->storeDbTable(table);
185 StDbTable* table = node->addDbTable(
"fcsEcalGainCorr");
187 table->setFlavor(flavor.Data());
188 mgr->storeDbTable(table);
191 StDbTable* table = node->addDbTable(
"fcsHcalGainCorr");
193 table->setFlavor(flavor.Data());
194 mgr->storeDbTable(table);
197 StDbTable* table = node->addDbTable(
"fcsPresValley");
199 table->setFlavor(flavor.Data());
200 mgr->storeDbTable(table);
203 StDbTable* table = node->addDbTable(
"fcsEcalGainOnline");
205 table->setFlavor(flavor.Data());
206 mgr->storeDbTable(table);
209 StDbTable* table = node->addDbTable(
"fcsHcalGainOnline");
211 table->setFlavor(flavor.Data());
212 mgr->storeDbTable(table);
215 StDbTable* table = node->addDbTable(
"fcsPresThreshold");
217 table->setFlavor(flavor.Data());
218 mgr->storeDbTable(table);
220 gSystem->Unsetenv(
"DB_ACCESS_MODE");
221 std::cout <<
"Done with database upload \n";
224 int date,time,from=0,n=0;
225 TString datetime(storeTime),token;
226 datetime.ReplaceAll(
"-",
"");
227 datetime.ReplaceAll(
":",
"");
228 while(datetime.Tokenize(token,from,
" ")){
229 if(n==0) date=atoi(token.Data());
230 if(n==1) time=atoi(token.Data());
233 std::cout <<
"Readout time="<<datetime<<
" Date="<<date<<
" Time="<<time<<endl;
237 dbMk->SetDateTime(date,time);
238 dbMk->SetFlavor(flavor.Data());
243 DB = dbMk->GetInputDB(
"Calibrations/fcs");
244 if(!DB){std::cout <<
"ERROR: no db maker or Calibrations/fcs" << std::endl; }
246 St_fcsEcalGain *dbTable_eg = (St_fcsEcalGain*) DB->
Find(
"fcsEcalGain");
248 std::cout <<
"Reading fcsEcalGain table from DB\n";
249 fcsEcalGain_st *dbSt_eg = dbTable_eg->GetTable();
250 Int_t rows = dbTable_eg->GetNRows();
251 for(
int i=0; i<rows; i++){
252 for(
int id=0;
id<1496;
id++){
253 printf(
"DbRead row=%2d id=%d gain=%10.6f\n",
254 i,
id,dbSt_eg[i].gain[
id]);
258 std::cout <<
"WARNING: No data in fcsEcalGain table\n";
262 St_fcsHcalGain *dbTable_hg = (St_fcsHcalGain*) DB->
Find(
"fcsHcalGain");
264 std::cout <<
"Reading fcsHcalGain table from DB\n";
265 fcsHcalGain_st *dbSt_hg = dbTable_hg->GetTable();
266 Int_t rows = dbTable_hg->GetNRows();
267 for(
int i=0; i<rows; i++){
268 for(
int id=0;
id<520;
id++){
269 printf(
"DbRead row=%2d id=%d gain=%10.6f\n",
270 i,
id,dbSt_hg[i].gain[
id]);
274 std::cout <<
"WARNING: No data in fcsHcalGain table\n";
278 St_fcsPresGain *dbTable_pg = (St_fcsPresGain*) DB->
Find(
"fcsPresGain");
280 std::cout <<
"Reading fcsPresGain table from DB\n";
281 fcsPresGain_st *dbSt_pg = dbTable_pg->GetTable();
282 Int_t rows = dbTable_pg->GetNRows();
283 for(
int i=0; i<rows; i++){
284 for(
int id=0;
id<384;
id++){
285 printf(
"DbRead row=%2d id=%d gain=%10.6f\n",
286 i,
id,dbSt_pg[i].gain[
id]);
290 std::cout <<
"WARNING: No data in fcsPresGain table\n";
294 St_fcsEcalGainCorr *dbTable_ec = (St_fcsEcalGainCorr*) DB->
Find(
"fcsEcalGainCorr");
296 std::cout <<
"Reading fcsEcalGainCorr table from DB\n";
297 fcsEcalGainCorr_st *dbSt_ec = dbTable_ec->GetTable();
298 Int_t rows = dbTable_ec->GetNRows();
299 for(
int i=0; i<rows; i++){
300 for(
int id=0;
id<1496;
id++){
301 printf(
"DbRead row=%2d id=%d gaincorr=%10.6f\n",
302 i,
id,dbSt_ec[i].gaincorr[
id]);
306 std::cout <<
"WARNING: No data in fcsEcalGainCorr table\n";
310 St_fcsHcalGainCorr *dbTable_hc = (St_fcsHcalGainCorr*) DB->
Find(
"fcsHcalGainCorr");
312 std::cout <<
"Reading fcsHcalGainCorr table from DB\n";
313 fcsHcalGainCorr_st *dbSt_hc = dbTable_hc->GetTable();
314 Int_t rows = dbTable_hc->GetNRows();
315 for(
int i=0; i<rows; i++){
316 for(
int id=0;
id<520;
id++){
317 printf(
"DbRead row=%2d id=%d gaincorr=%10.6f\n",
318 i,
id,dbSt_hc[i].gaincorr[
id]);
322 std::cout <<
"WARNING: No data in fcsHcalGainCorr table\n";
326 St_fcsPresValley *dbTable_pc = (St_fcsPresValley*) DB->
Find(
"fcsPresValley");
328 std::cout <<
"Reading fcsPresValley table from DB\n";
329 fcsPresValley_st *dbSt_pc = dbTable_pc->GetTable();
330 Int_t rows = dbTable_pc->GetNRows();
331 for(
int i=0; i<rows; i++){
332 for(
int id=0;
id<384;
id++){
333 printf(
"DbRead row=%2d id=%d valley=%10.6f\n",
334 i,
id,dbSt_pc[i].valley[
id]);
338 std::cout <<
"WARNING: No data in fcsPresValley table\n";
343 St_fcsEcalGainOnline *dbTable_ec = (St_fcsEcalGainOnline*) DB->
Find(
"fcsEcalGainOnline");
345 std::cout <<
"Reading fcsEcalGainOnline table from DB\n";
346 fcsEcalGainOnline_st *dbSt_ec = dbTable_ec->GetTable();
347 Int_t rows = dbTable_ec->GetNRows();
348 for(
int i=0; i<rows; i++){
349 for(
int id=0;
id<1496;
id++){
350 printf(
"DbRead row=%2d id=%d gainonl=%10.6f\n",
351 i,
id,dbSt_ec[i].gainOnline[
id]);
355 std::cout <<
"WARNING: No data in fcsEcalGainOnline table\n";
359 St_fcsHcalGainOnline *dbTable_hc = (St_fcsHcalGainOnline*) DB->
Find(
"fcsHcalGainOnline");
361 std::cout <<
"Reading fcsHcalGainOnline table from DB\n";
362 fcsHcalGainOnline_st *dbSt_hc = dbTable_hc->GetTable();
363 Int_t rows = dbTable_hc->GetNRows();
364 for(
int i=0; i<rows; i++){
365 for(
int id=0;
id<520;
id++){
366 printf(
"DbRead row=%2d id=%d gainonl=%10.6f\n",
367 i,
id,dbSt_hc[i].gainOnline[
id]);
371 std::cout <<
"WARNING: No data in fcsHcalGainOnline table\n";
375 St_fcsPresThreshold *dbTable_pc = (St_fcsPresThreshold*) DB->
Find(
"fcsPresThreshold");
377 std::cout <<
"Reading fcsPresThreshold table from DB\n";
378 fcsPresThreshold_st *dbSt_pc = dbTable_pc->GetTable();
379 Int_t rows = dbTable_pc->GetNRows();
380 for(
int i=0; i<rows; i++){
381 for(
int id=0;
id<384;
id++){
382 printf(
"DbRead row=%2d id=%d threshold=%10.6f\n",
383 i,
id,dbSt_pc[i].threshold[
id]);
387 std::cout <<
"WARNING: No data in fcsPresThreshold table\n";
void getIdfromDep(int ehp, int ns, int dep, int ch, int &detectorId, int &id, int &crt, int &slt) const
Get DEP map.
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