StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fcsGain_db.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 class StFcsDb;
5 StFcsDb* mFcsDb=0;
6 
7 void readElectronicsGain(char* file, float* eonl){
8  printf("Reading Electronics Gain file : %s\n",file);
9  FILE* F=fopen(file,"r");
10  if(F == NULL){
11  printf("Could not open %s\n",file);
12  return;
13  }
14  int ehp,ns,dep,ch;
15  float gain;
16  char dummy[100];
17  fgets(dummy,100,F);
18  printf("%s\n",dummy);
19  while(fscanf(F,"%d %d %d %d %f",&ehp,&ns,&dep,&ch,&gain) != EOF){
20  int det,id,crt,slt;
21  mFcsDb->getIdfromDep(ehp,ns,dep,ch,det,id,crt,slt);
22  int idx=det*748 + id;
23  eonl[idx]=gain;
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]);
26  }
27  fclose(F);
28 }
29 
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");
45 
46  mFcsDb=new StFcsDb;
47  mFcsDb->Init();
48  mFcsDb->InitRun(23000000);
49 
50  // structure to fill up
51  fcsEcalGain_st egain;
52  fcsHcalGain_st hgain;
53  fcsPresGain_st pgain;
54  fcsEcalGainCorr_st ecorr;
55  fcsHcalGainCorr_st hcorr;
56  fcsPresValley_st pcorr;
57  fcsEcalGainOnline_st eonl;
58  fcsHcalGainOnline_st honl;
59  fcsPresThreshold_st ponl;
60 
61  TString option(opt);
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";
73 
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;
81 
82  TString data(input);
83  TString storeTime("");
84  TString flavor;
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; //default 5.3MeV/ch
88  if(hcal && gain) for(int i=0; i< 520; i++) hgain.gain[i]=0.0053; //default 5.3MeV/ch
89  if(pres && gain) for(int i=0; i< 384; i++) pgain.gain[i]=0.01; //100ch for MIP
90  if(ecal && corr) for(int i=0; i<1496; i++) ecorr.gaincorr[i]=1.0; //default 1
91  if(hcal && corr) for(int i=0; i< 520; i++) hcorr.gaincorr[i]=1.0; //default 1
92  if(pres && corr) for(int i=0; i< 384; i++) pcorr.valley[i]=0.5; //0.5 for 1/2 MIP
93  if(ecal && onl) for(int i=0; i<1496; i++) eonl.gainOnline[i]=1.0; //default 1
94  if(hcal && onl) for(int i=0; i< 520; i++) honl.gainOnline[i]=1.0; //default 1
95  if(pres && onl) for(int i=0; i< 384; i++) ponl.threshold[i]=200; //200 for 1/2 MIP
96  }
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; //600ch for MIP
102  if(ecal && corr) for(int i=0; i<1496; i++) ecorr.gaincorr[i]=1.21; //avg gaincorr=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; //0.5 for 1/2 MIP
105  if(ecal && onl) for(int i=0; i<1496; i++) eonl.gainOnline[i]=1.0; //default 1
106  if(hcal && onl) for(int i=0; i< 520; i++) honl.gainOnline[i]=1.0; //default 1
107  if(pres && onl) for(int i=0; i< 384; i++) ponl.threshold[i]=200; //200 for 1/2 MIP
108  }
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; //Attenuator 1/2.7
112  }
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; //Attenuator 1/5.31
116  if(hcal && onl) for(int i=0; i< 520; i++) honl.gainOnline[i]=1.3; //changed to 1.3
117  }
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; //increased V for *1.65 gain
121  if(pres && onl) for(int i=0; i< 384; i++) ponl.threshold[i]=250; //250
122  }
123  if(data.Contains("run22Feb17")){
124  storeTime = "2022-02-17 16:58:04"; flavor="ofl";
125  readElectronicsGain("ratio2_ecal_23047026_23005043.txt",eonl.gainOnline);
126  }
127  if(data.Contains("run22Feb18")){
128  storeTime = "2022-02-18 16:11:17"; flavor="ofl";
129  readElectronicsGain("ratio2a_ecal_23047026_23005043.txt",eonl.gainOnline);
130  }
131  if(data.Contains("run22Feb28")){
132  storeTime = "2022-02-28 17:26:56"; flavor="ofl";
133  readElectronicsGain("ratio2_ecal_23058015_23005043.txt",eonl.gainOnline);
134  }
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);
138  }
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;
142  }
143 
144  if(storeTime==""){
145  std::cout<<"Invalid year range"<<std::endl;
146  exit;
147  }
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]);
159 
160  if(option.Contains("writedb")) {
161  gSystem->Setenv("DB_ACCESS_MODE","write");
162  cout << "DB_ACCESS_MODE="<<gSystem->Getenv("DB_ACCESS_MODE")<<endl;
164  StDbConfigNode* node = mgr->initConfig("Calibrations_fcs");
165  mgr->setStoreTime(storeTime.Data());
166  if(ecal && gain){
167  StDbTable* table = node->addDbTable("fcsEcalGain");
168  table->SetTable((char*)&egain,1);
169  table->setFlavor(flavor.Data());
170  mgr->storeDbTable(table);
171  }
172  if(hcal && gain){
173  StDbTable* table = node->addDbTable("fcsHcalGain");
174  table->SetTable((char*)&hgain,1);
175  table->setFlavor(flavor.Data());
176  mgr->storeDbTable(table);
177  }
178  if(pres && gain){
179  StDbTable* table = node->addDbTable("fcsPresGain");
180  table->SetTable((char*)&pgain,1);
181  table->setFlavor(flavor.Data());
182  mgr->storeDbTable(table);
183  }
184  if(ecal && corr){
185  StDbTable* table = node->addDbTable("fcsEcalGainCorr");
186  table->SetTable((char*)&ecorr,1);
187  table->setFlavor(flavor.Data());
188  mgr->storeDbTable(table);
189  }
190  if(hcal && corr){
191  StDbTable* table = node->addDbTable("fcsHcalGainCorr");
192  table->SetTable((char*)&hcorr,1);
193  table->setFlavor(flavor.Data());
194  mgr->storeDbTable(table);
195  }
196  if(pres && corr){
197  StDbTable* table = node->addDbTable("fcsPresValley");
198  table->SetTable((char*)&pcorr,1);
199  table->setFlavor(flavor.Data());
200  mgr->storeDbTable(table);
201  }
202  if(ecal && onl){
203  StDbTable* table = node->addDbTable("fcsEcalGainOnline");
204  table->SetTable((char*)&eonl,1);
205  table->setFlavor(flavor.Data());
206  mgr->storeDbTable(table);
207  }
208  if(hcal && onl){
209  StDbTable* table = node->addDbTable("fcsHcalGainOnline");
210  table->SetTable((char*)&honl,1);
211  table->setFlavor(flavor.Data());
212  mgr->storeDbTable(table);
213  }
214  if(pres && onl){
215  StDbTable* table = node->addDbTable("fcsPresThreshold");
216  table->SetTable((char*)&ponl,1);
217  table->setFlavor(flavor.Data());
218  mgr->storeDbTable(table);
219  }
220  gSystem->Unsetenv("DB_ACCESS_MODE");
221  std::cout << "Done with database upload \n";
222  }
223 
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());
231  n++;
232  }
233  std::cout << "Readout time="<<datetime<<" Date="<<date<<" Time="<<time<<endl;
234 
235  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
236  dbMk->SetDebug();
237  dbMk->SetDateTime(date,time);
238  dbMk->SetFlavor(flavor.Data());
239  dbMk->Init();
240  dbMk->Make();
241 
242  TDataSet *DB = 0;
243  DB = dbMk->GetInputDB("Calibrations/fcs");
244  if(!DB){std::cout << "ERROR: no db maker or Calibrations/fcs" << std::endl; }
245  if(ecal && gain){
246  St_fcsEcalGain *dbTable_eg = (St_fcsEcalGain*) DB->Find("fcsEcalGain");
247  if(dbTable_eg){
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]);
255  }
256  }
257  }else{
258  std::cout << "WARNING: No data in fcsEcalGain table\n";
259  }
260  }
261  if(hcal && gain){
262  St_fcsHcalGain *dbTable_hg = (St_fcsHcalGain*) DB->Find("fcsHcalGain");
263  if(dbTable_hg){
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]);
271  }
272  }
273  }else{
274  std::cout << "WARNING: No data in fcsHcalGain table\n";
275  }
276  }
277  if(pres && gain){
278  St_fcsPresGain *dbTable_pg = (St_fcsPresGain*) DB->Find("fcsPresGain");
279  if(dbTable_pg){
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]);
287  }
288  }
289  }else{
290  std::cout << "WARNING: No data in fcsPresGain table\n";
291  }
292  }
293  if(ecal && corr){
294  St_fcsEcalGainCorr *dbTable_ec = (St_fcsEcalGainCorr*) DB->Find("fcsEcalGainCorr");
295  if(dbTable_ec){
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]);
303  }
304  }
305  }else{
306  std::cout << "WARNING: No data in fcsEcalGainCorr table\n";
307  }
308  }
309  if(hcal && corr){
310  St_fcsHcalGainCorr *dbTable_hc = (St_fcsHcalGainCorr*) DB->Find("fcsHcalGainCorr");
311  if(dbTable_hc){
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]);
319  }
320  }
321  }else{
322  std::cout << "WARNING: No data in fcsHcalGainCorr table\n";
323  }
324  }
325  if(pres && corr){
326  St_fcsPresValley *dbTable_pc = (St_fcsPresValley*) DB->Find("fcsPresValley");
327  if(dbTable_pc){
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]);
335  }
336  }
337  }else{
338  std::cout << "WARNING: No data in fcsPresValley table\n";
339  }
340  }
341 
342  if(ecal && onl){
343  St_fcsEcalGainOnline *dbTable_ec = (St_fcsEcalGainOnline*) DB->Find("fcsEcalGainOnline");
344  if(dbTable_ec){
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]);
352  }
353  }
354  }else{
355  std::cout << "WARNING: No data in fcsEcalGainOnline table\n";
356  }
357  }
358  if(hcal && onl){
359  St_fcsHcalGainOnline *dbTable_hc = (St_fcsHcalGainOnline*) DB->Find("fcsHcalGainOnline");
360  if(dbTable_hc){
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]);
368  }
369  }
370  }else{
371  std::cout << "WARNING: No data in fcsHcalGainOnline table\n";
372  }
373  }
374  if(pres && onl){
375  St_fcsPresThreshold *dbTable_pc = (St_fcsPresThreshold*) DB->Find("fcsPresThreshold");
376  if(dbTable_pc){
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]);
384  }
385  }
386  }else{
387  std::cout << "WARNING: No data in fcsPresThreshold table\n";
388  }
389  }
390 }
391 
virtual Int_t Make()
void getIdfromDep(int ehp, int ns, int dep, int ch, int &detectorId, int &id, int &crt, int &slt) const
Get DEP map.
Definition: StFcsDb.cxx:1031
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc&#39;d version of data for StRoot
Definition: StDbTable.cc:550
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362