1 |
pam-fi |
1.1 |
/** |
2 |
|
|
* \file TrkParams.cpp |
3 |
|
|
* \author Elena Vannuccini |
4 |
|
|
*/ |
5 |
|
|
|
6 |
|
|
#include <TrkParams.h> |
7 |
|
|
#include <iostream> |
8 |
|
|
using namespace std; |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
// ------------------------- |
12 |
|
|
// CALIBRATION (PED,SIG,BAD) |
13 |
|
|
// ------------------------- |
14 |
|
|
GL_TRK_CALIB TrkParams::calib = GL_TRK_CALIB(); |
15 |
|
|
TString TrkParams::calibpatht = ""; |
16 |
|
|
TString TrkParams::calibpathf = ""; |
17 |
|
|
Bool_t TrkParams::calib104 = 0; |
18 |
|
|
Bool_t TrkParams::calibload = false; |
19 |
|
|
UInt_t TrkParams::trkparamtype[] = {1,2,3,4,5,6,7}; |
20 |
|
|
GL_PARAM TrkParams::gl[] = {GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM()}; |
21 |
|
|
TString TrkParams::glpath[] = {"","","","","","",""}; |
22 |
|
|
Bool_t TrkParams::glload[] = {false,false,false,false,false,false,false}; |
23 |
|
|
|
24 |
|
|
TrkParams::TrkParams(){ |
25 |
|
|
|
26 |
|
|
cout<<"TrkParams::TrkParams()"<<endl; |
27 |
|
|
|
28 |
|
|
} |
29 |
|
|
float aint(float f){ |
30 |
|
|
int ret = (int)f; |
31 |
|
|
float ret1 = 0; |
32 |
|
|
ret1=(float)ret; |
33 |
|
|
return ret1; |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
float anint(float f){ |
37 |
|
|
int ret = (int)(f+0.5); |
38 |
|
|
float ret1 = 0; |
39 |
|
|
ret1=(float)ret; |
40 |
|
|
return ret1; |
41 |
|
|
} |
42 |
|
|
/** |
43 |
|
|
* Static method to set the calibration to be loaded. |
44 |
|
|
|
45 |
|
|
* It retrieves the calibration associated to a given run, from |
46 |
|
|
* a given DB. It fills the F77 common. |
47 |
|
|
* @param glrun Pointer to a GL_RUN row |
48 |
|
|
* @param dbc Pointer to a DB connection |
49 |
|
|
*/ |
50 |
|
|
Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){ |
51 |
|
|
|
52 |
pam-fi |
1.3 |
if( !CalibIsLoaded() || |
53 |
|
|
(glrun->TRK_CALIB_USED==104 && !calib104) || |
54 |
|
|
(glrun->TRK_CALIB_USED!=104 && calib104) || |
55 |
|
|
glrun->RUNHEADER_TIME < calib.FROM_TIME || |
56 |
|
|
glrun->RUNHEADER_TIME > calib.TO_TIME || |
57 |
|
|
false ){ |
58 |
|
|
|
59 |
|
|
GL_TRK_CALIB q2; |
60 |
|
|
GL_ROOT q3; |
61 |
|
|
GL_PARAM q4; |
62 |
|
|
|
63 |
|
|
cout << " UPDATING calibration -- run-header time "<< glrun->RUNHEADER_TIME <<endl; |
64 |
|
|
if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) ){ |
65 |
|
|
cout << "Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_TRK_CALIB "<<endl; |
66 |
|
|
return false; |
67 |
|
|
} |
68 |
|
|
if( q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2 ) |
69 |
|
|
printf("WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2); |
70 |
|
|
if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) ){ |
71 |
|
|
cout << "Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_ROOT "<<endl; |
72 |
|
|
return false; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
// cout << "selected "<<q2.ID<<" from_time "<<q2.FROM_TIME<<" to time "<<q2.TO_TIME<<endl; |
76 |
|
|
calib = q2; |
77 |
|
|
calibpathf = q3.PATH + q3.NAME; |
78 |
|
|
calib104 = (glrun->TRK_CALIB_USED==104); |
79 |
|
|
calibload = kFALSE; |
80 |
|
|
if(calib104){ |
81 |
|
|
if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false; |
82 |
|
|
calibpatht = q4.PATH + q4.NAME; |
83 |
|
|
} |
84 |
|
|
|
85 |
pam-fi |
1.1 |
|
86 |
pam-fi |
1.3 |
// return TrkParams::LoadCalib(); |
87 |
|
|
return true; |
88 |
pam-fi |
1.1 |
} |
89 |
|
|
|
90 |
pam-fi |
1.3 |
return false; |
91 |
pam-fi |
1.1 |
}; |
92 |
|
|
|
93 |
|
|
/** |
94 |
|
|
* Method to fill the tracker calibration-parameter struct from on-line calibrations |
95 |
|
|
*/ |
96 |
|
|
void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
97 |
|
|
|
98 |
|
|
cTrkCalib *ca = &pedsigbad_; |
99 |
|
|
|
100 |
|
|
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
101 |
|
|
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
102 |
|
|
|
103 |
|
|
CalibTrk1Event *calibdata1 = 0; |
104 |
|
|
CalibTrk2Event *calibdata2 = 0; |
105 |
|
|
tr1->SetBranchAddress("CalibTrk1",&calibdata1); |
106 |
|
|
tr2->SetBranchAddress("CalibTrk2",&calibdata2); |
107 |
|
|
tr1->GetEntry(ev_reg1); |
108 |
|
|
tr2->GetEntry(ev_reg2); |
109 |
|
|
Int_t dspn1(0),dspn2(0); |
110 |
|
|
|
111 |
|
|
for(Int_t i=0;i<6;i++){ |
112 |
|
|
dspn1=calibdata1->DSPnumber[i]-1; |
113 |
|
|
dspn2=calibdata2->DSPnumber[i]-1; |
114 |
|
|
/* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */ |
115 |
|
|
for(Int_t ii=0;ii<3072;ii++){ |
116 |
|
|
Int_t j=(ii/128); |
117 |
|
|
Int_t jj=ii-j*128; |
118 |
|
|
ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii]; |
119 |
|
|
ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii]; |
120 |
|
|
ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]); |
121 |
|
|
ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]); |
122 |
|
|
ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii]; |
123 |
|
|
ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii]; |
124 |
|
|
ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]); |
125 |
|
|
ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]); |
126 |
|
|
// cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl; |
127 |
|
|
// cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl; |
128 |
|
|
// cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl; |
129 |
|
|
// cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl; |
130 |
|
|
|
131 |
|
|
// |
132 |
|
|
// invert the bad |
133 |
|
|
// |
134 |
|
|
if(calibdata1->DSPbad_par[i][ii]==0) |
135 |
|
|
ca->bad[jj][j][dspn1]=1; |
136 |
|
|
else if(calibdata1->DSPbad_par[i][ii]==1) |
137 |
|
|
ca->bad[jj][j][dspn1]=0; |
138 |
|
|
if(calibdata2->DSPbad_par[i][ii]==0) |
139 |
|
|
ca->bad[jj][j][dspn2]=1; |
140 |
|
|
else if(calibdata2->DSPbad_par[i][ii]==1) |
141 |
|
|
ca->bad[jj][j][dspn2]=0; |
142 |
|
|
}; |
143 |
|
|
}; |
144 |
|
|
|
145 |
|
|
tr1->Delete(); |
146 |
|
|
tr2->Delete(); |
147 |
|
|
}; |
148 |
|
|
/** |
149 |
|
|
* Method to fill the tracker calibration-parameter struct from on-line calibrations |
150 |
|
|
*/ |
151 |
|
|
void TrkParams::FillFCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
152 |
|
|
|
153 |
|
|
cTrkCalib *ca = &pedsigbad_; |
154 |
|
|
|
155 |
|
|
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
156 |
|
|
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
157 |
|
|
|
158 |
|
|
CalibTrk1Event *calibdata1 = 0; |
159 |
|
|
CalibTrk2Event *calibdata2 = 0; |
160 |
|
|
tr1->SetBranchAddress("CalibTrk1",&calibdata1); |
161 |
|
|
tr2->SetBranchAddress("CalibTrk2",&calibdata2); |
162 |
|
|
tr1->GetEntry(ev_reg1); |
163 |
|
|
tr2->GetEntry(ev_reg2); |
164 |
|
|
Int_t dspn1(0),dspn2(0); |
165 |
|
|
|
166 |
|
|
for(Int_t i=0;i<6;i++){ |
167 |
|
|
dspn1=calibdata1->DSPnumber[i]-1; |
168 |
|
|
dspn2=calibdata2->DSPnumber[i]-1; |
169 |
|
|
/* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */ |
170 |
|
|
for(Int_t ii=0;ii<3072;ii++){ |
171 |
|
|
Int_t j=(ii/128); |
172 |
|
|
Int_t jj=ii-j*128; |
173 |
|
|
ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii]; |
174 |
|
|
ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii]; |
175 |
|
|
ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii]; |
176 |
|
|
ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii]; |
177 |
|
|
// cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl; |
178 |
|
|
// cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl; |
179 |
|
|
// cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl; |
180 |
|
|
// cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl; |
181 |
|
|
|
182 |
|
|
// |
183 |
|
|
// invert the bad |
184 |
|
|
// |
185 |
|
|
if(calibdata1->DSPbad_par[i][ii]==0) |
186 |
|
|
ca->bad[jj][j][dspn1]=1; |
187 |
|
|
else if(calibdata1->DSPbad_par[i][ii]==1) |
188 |
|
|
ca->bad[jj][j][dspn1]=0; |
189 |
|
|
if(calibdata2->DSPbad_par[i][ii]==0) |
190 |
|
|
ca->bad[jj][j][dspn2]=1; |
191 |
|
|
else if(calibdata2->DSPbad_par[i][ii]==1) |
192 |
|
|
ca->bad[jj][j][dspn2]=0; |
193 |
|
|
}; |
194 |
|
|
}; |
195 |
|
|
|
196 |
|
|
tr1->Delete(); |
197 |
|
|
tr2->Delete(); |
198 |
|
|
}; |
199 |
|
|
/** |
200 |
|
|
* Method to fill the tracker calibration-parameter struct from on-line calibrations |
201 |
|
|
*/ |
202 |
|
|
void TrkParams::FillTCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
203 |
|
|
|
204 |
|
|
cTrkCalib *ca = &pedsigbad_; |
205 |
|
|
|
206 |
|
|
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
207 |
|
|
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
208 |
|
|
|
209 |
|
|
CalibTrk1Event *calibdata1 = 0; |
210 |
|
|
CalibTrk2Event *calibdata2 = 0; |
211 |
|
|
tr1->SetBranchAddress("CalibTrk1",&calibdata1); |
212 |
|
|
tr2->SetBranchAddress("CalibTrk2",&calibdata2); |
213 |
|
|
tr1->GetEntry(ev_reg1); |
214 |
|
|
tr2->GetEntry(ev_reg2); |
215 |
|
|
Int_t dspn1(0),dspn2(0); |
216 |
|
|
|
217 |
|
|
for(Int_t i=0;i<6;i++){ |
218 |
|
|
dspn1=calibdata1->DSPnumber[i]-1; |
219 |
|
|
dspn2=calibdata2->DSPnumber[i]-1; |
220 |
|
|
/* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */ |
221 |
|
|
for(Int_t ii=0;ii<3072;ii++){ |
222 |
|
|
Int_t j=(ii/128); |
223 |
|
|
Int_t jj=ii-j*128; |
224 |
|
|
ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]); |
225 |
|
|
ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]); |
226 |
|
|
ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]); |
227 |
|
|
ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]); |
228 |
|
|
}; |
229 |
|
|
}; |
230 |
|
|
|
231 |
|
|
tr1->Delete(); |
232 |
|
|
tr2->Delete(); |
233 |
|
|
}; |
234 |
|
|
/** |
235 |
|
|
* Method to fill the tracker calibration-parameter struct from default calibration |
236 |
|
|
*/ |
237 |
|
|
void TrkParams::FillTCalibFrom(TString path){ |
238 |
|
|
|
239 |
|
|
path_.FillWith(path); |
240 |
|
|
fillpedsigfromdefault_(); |
241 |
|
|
if(path_.error) throw -216; |
242 |
|
|
|
243 |
|
|
}; |
244 |
|
|
/** |
245 |
|
|
* Method to fill the tracker VA1-mask struct from calibration |
246 |
|
|
*/ |
247 |
|
|
void TrkParams::FillMask(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
248 |
|
|
|
249 |
|
|
cTrkMask *ma = &mask_; |
250 |
|
|
|
251 |
|
|
TrkCalib *calib = new TrkCalib(); |
252 |
|
|
|
253 |
|
|
for(Int_t i=0; i<2; i++){ |
254 |
|
|
TTree *tr=0; |
255 |
|
|
if(i==0){ |
256 |
|
|
//------------------------- |
257 |
|
|
//read calibration packet 1 |
258 |
|
|
//------------------------- |
259 |
|
|
tr = (TTree*)f0->Get("CalibTrk1"); |
260 |
|
|
tr->SetBranchAddress("CalibTrk1",calib->GetPointerTo()); |
261 |
|
|
tr->GetEntry(ev_reg1); |
262 |
|
|
} |
263 |
|
|
if(i==1){ |
264 |
|
|
//------------------------- |
265 |
|
|
//read calibration packet 2 |
266 |
|
|
//------------------------- |
267 |
|
|
tr = (TTree*)f0->Get("CalibTrk2"); |
268 |
|
|
tr->SetBranchAddress("CalibTrk2",calib->GetPointerTo()); |
269 |
|
|
tr->GetEntry(ev_reg2); |
270 |
|
|
} |
271 |
|
|
for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){ |
272 |
|
|
for(Int_t ivk=0; ivk<NVK; ivk++){ |
273 |
|
|
Int_t view = calib->GetView(ipkt); |
274 |
|
|
Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1); |
275 |
|
|
Float_t sigmin = 0.; |
276 |
|
|
if(view%2)sigmin = 6.5; |
277 |
|
|
else sigmin = 2.5; |
278 |
|
|
Int_t mask = 1; |
279 |
|
|
if( sigm<sigmin )mask = 0; |
280 |
|
|
|
281 |
|
|
ma->mask_vk_run[ivk][view-1] = mask; |
282 |
|
|
|
283 |
|
|
// if(mask==0)cout<< " VIEW "<<view<<" VK "<<ivk+1<<" -- <SIG> "<<sigm<<" ---> MASKED!"<<endl; |
284 |
|
|
} |
285 |
|
|
} |
286 |
|
|
if(tr)tr->Delete(); |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
if(calib)calib->Delete(); |
290 |
|
|
|
291 |
|
|
}; |
292 |
|
|
|
293 |
pam-fi |
1.3 |
// Bool_t TrkParams::CalibIsLoaded(UInt_t time){ |
294 |
|
|
|
295 |
|
|
// if( !calibload ) return false; |
296 |
|
|
|
297 |
|
|
// }; |
298 |
|
|
|
299 |
|
|
|
300 |
pam-fi |
1.1 |
/** |
301 |
|
|
* Static method to load calibration. |
302 |
|
|
* Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the |
303 |
|
|
* first time the method is called (but it does not work becouse I didn't set any |
304 |
|
|
* default calibration for the moment) or after the method TrkParams::SetCalib(***) is called. |
305 |
|
|
*/ |
306 |
|
|
Bool_t TrkParams::LoadCalib( ){ |
307 |
|
|
|
308 |
|
|
if( TrkParams::CalibIsLoaded() )return false; |
309 |
|
|
|
310 |
|
|
// cTrkCalib *ca = new cTrkCalib; //&pedsigbad_; |
311 |
|
|
|
312 |
|
|
// extern cTrkCalib pedsigbad_; |
313 |
|
|
// extern cTrkMask mask_; |
314 |
|
|
|
315 |
|
|
cout << "--------------------------------------"<<endl; |
316 |
|
|
cout << "Retrieve calibration (PED-SIG-BAD) ..."<<endl; |
317 |
|
|
// ============================================================= |
318 |
|
|
// retrieve calibration file needed to reduce data |
319 |
|
|
// ============================================================= |
320 |
|
|
// if run OBT is > last calibration "expiration date" |
321 |
|
|
// - search for new calibration packet |
322 |
|
|
// - load calibration parameters (full + truncated) |
323 |
|
|
cout << "Full pedestals for cluster finding:"; |
324 |
|
|
cout << " >> Loading from LEVEL0 file: "<< calibpathf << endl; |
325 |
|
|
FileStat_t t; |
326 |
|
|
if( gSystem->GetPathInfo(calibpathf.Data(),t) )return false; |
327 |
|
|
|
328 |
|
|
TFile *f0_c = new TFile(calibpathf); |
329 |
|
|
if ( !f0_c ) return false; |
330 |
|
|
cout << " calibration entries "<< calib.EV_ROOT_CALIBTRK1 << " " << calib.EV_ROOT_CALIBTRK2; |
331 |
|
|
cout << " (from time "<< calib.FROM_TIME <<" to time "<< calib.TO_TIME <<")"<<endl; |
332 |
|
|
// ca->FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
333 |
|
|
TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
334 |
|
|
TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
335 |
|
|
// mask_.Set(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
336 |
pam-fi |
1.2 |
// for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal[64][12][i] << endl; |
337 |
pam-fi |
1.1 |
|
338 |
|
|
// }; |
339 |
|
|
// ============================================================= |
340 |
|
|
// retrieve calibration file needed to uncompress data |
341 |
|
|
// ============================================================= |
342 |
|
|
// if the run was compressed using default calib |
343 |
|
|
// load truncated pedestals from default |
344 |
|
|
// otherwise reload them from on-line calibration |
345 |
|
|
cout << "Truncated pedestals for uncompression:"; |
346 |
|
|
if( calib104 ){ |
347 |
|
|
|
348 |
|
|
cout << " >> Loading default calibration: "<< calibpatht << endl; |
349 |
|
|
// ca->FillTCalibFrom(calibpatht); |
350 |
|
|
TrkParams::FillTCalibFrom(calibpatht); |
351 |
|
|
|
352 |
|
|
}else{ |
353 |
|
|
|
354 |
|
|
if ( !f0_c ) return false; |
355 |
|
|
cout << ">> Loading on-line calibration " << endl; |
356 |
|
|
// ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
357 |
|
|
TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
358 |
|
|
}; |
359 |
pam-fi |
1.3 |
// for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal_t[64][12][i] << endl; |
360 |
pam-fi |
1.1 |
f0_c->Close(); |
361 |
|
|
// delete f0_c; |
362 |
|
|
cout << "--------------------------------------"<<endl; |
363 |
|
|
|
364 |
|
|
calibload = kTRUE; |
365 |
|
|
return true; |
366 |
|
|
}; |
367 |
|
|
|
368 |
|
|
Int_t TrkParams::GetIndex( UInt_t type ){ |
369 |
|
|
Int_t index = -1; |
370 |
|
|
for (Int_t i=0; i< NTYPES; i++)if( type == trkparamtype[i] )index=i; |
371 |
|
|
return index; |
372 |
|
|
}; |
373 |
|
|
|
374 |
|
|
/** |
375 |
|
|
* Set tracker parameters proper for a run querying the DB. |
376 |
|
|
* @param glrun Input run info |
377 |
|
|
* @param dbc Database |
378 |
|
|
* @param type Parameter type |
379 |
|
|
* @return FALSE if parameter set fails. |
380 |
|
|
* If glrun==NULL the last parameter entry from GL_PARAM table is set. |
381 |
|
|
* If dbc==NULL, try to open a connection taking DB-connection |
382 |
|
|
* parameters from PAMELA environment variables. |
383 |
|
|
*/ |
384 |
|
|
Bool_t TrkParams::Set( GL_RUN* glrun , TSQLServer* dbc , UInt_t type){ |
385 |
|
|
|
386 |
|
|
// if( !dbc )return false; |
387 |
|
|
|
388 |
|
|
|
389 |
|
|
if( !dbc || (dbc && !dbc->IsConnected()) ){ |
390 |
|
|
|
391 |
|
|
cout <<" Missing DB connection -- check PAMELA environment variables "<<endl; |
392 |
|
|
TString host = "mysql://localhost/pamelaprod"; |
393 |
|
|
TString user = "anonymous"; |
394 |
|
|
TString psw = ""; |
395 |
|
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
396 |
|
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
397 |
|
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
398 |
|
|
if ( !pamdbhost ) pamdbhost = ""; |
399 |
|
|
if ( !pamdbuser ) pamdbuser = ""; |
400 |
|
|
if ( !pamdbpsw ) pamdbpsw = ""; |
401 |
|
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
402 |
|
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
403 |
|
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
404 |
|
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
405 |
|
|
cout<<"Connecting to DB"<<endl; |
406 |
|
|
cout<<"HOST "<<host<<endl; |
407 |
|
|
cout<<"USER "<<user<<endl; |
408 |
|
|
cout<<"PSW "<<psw<<endl; |
409 |
|
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
410 |
|
|
if( !dbc )return false; |
411 |
|
|
if( !dbc->IsConnected() )return false; |
412 |
|
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
413 |
|
|
|
414 |
|
|
} |
415 |
|
|
|
416 |
|
|
UInt_t index = TrkParams::GetIndex( type ); |
417 |
|
|
if(index < 0)return false; |
418 |
|
|
|
419 |
|
|
UInt_t runheadtime = numeric_limits<UInt_t>::max(); |
420 |
|
|
if(glrun)runheadtime = glrun->RUNHEADER_TIME; |
421 |
|
|
else cout <<"Missing run info -- taking last entry "<<endl; |
422 |
|
|
|
423 |
|
|
GL_PARAM q4; |
424 |
|
|
if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false; |
425 |
|
|
|
426 |
|
|
gl[index] = q4; |
427 |
|
|
glpath[index] = q4.PATH+q4.NAME; |
428 |
|
|
glload[index] = false; |
429 |
pam-fi |
1.2 |
cout << "<< set TrkParams type "<<type<<" >> (from DB) "<<endl; |
430 |
pam-fi |
1.1 |
return true; |
431 |
|
|
// return TrkParams::Load(type); |
432 |
|
|
|
433 |
|
|
}; |
434 |
|
|
/** |
435 |
pam-fi |
1.2 |
* Set tracker parameters proper for the run, from input. |
436 |
pam-fi |
1.1 |
* @param path Path to parameters directory |
437 |
|
|
* @param type Parameter type |
438 |
|
|
* @return FALSE if parameter set fails. |
439 |
|
|
*/ |
440 |
|
|
Bool_t TrkParams::Set( TString path , UInt_t type){ |
441 |
|
|
|
442 |
|
|
UInt_t index = TrkParams::GetIndex( type ); |
443 |
|
|
if(index < 0)return false; |
444 |
|
|
|
445 |
|
|
gl[index].TYPE= type; |
446 |
|
|
glpath[index] = path; |
447 |
pam-fi |
1.2 |
cout << "<< set TrkParams type "<<type<<" >> (from input) "<<endl; |
448 |
pam-fi |
1.1 |
glload[index] = false; |
449 |
|
|
|
450 |
|
|
// return TrkParams::Load(type); |
451 |
|
|
return true; |
452 |
|
|
|
453 |
|
|
}; |
454 |
|
|
|
455 |
|
|
/** |
456 |
|
|
* Set and load tracker parameters. |
457 |
|
|
* @param type Parameter type |
458 |
|
|
* If no path as been yet specified, it set a default path. |
459 |
|
|
* @return FALSE if parameter set fails. |
460 |
|
|
*/ |
461 |
|
|
Bool_t TrkParams::Set(UInt_t type){ |
462 |
|
|
|
463 |
|
|
UInt_t index = TrkParams::GetIndex( type ); |
464 |
|
|
if(index < 0)return false; |
465 |
|
|
|
466 |
|
|
gl[index].TYPE= type; |
467 |
|
|
glload[index] = false; |
468 |
|
|
|
469 |
|
|
// ----------------------------------------- |
470 |
|
|
// check if enviroment variables are defined |
471 |
|
|
// ----------------------------------------- |
472 |
|
|
glpath[index] = gSystem->Getenv("PAM_CALIB"); |
473 |
|
|
|
474 |
|
|
if( !glpath[index].IsNull() ){ |
475 |
|
|
|
476 |
|
|
switch(type){ |
477 |
|
|
case 1: |
478 |
|
|
glpath[index].Append("/trk-param/field_param-0/"); |
479 |
|
|
break; |
480 |
|
|
case 2: |
481 |
|
|
glpath[index].Append("/trk-param/mip_param-0/"); |
482 |
|
|
break; |
483 |
|
|
case 3: |
484 |
|
|
glpath[index].Append("/trk-param/charge_param-1/"); |
485 |
|
|
break; |
486 |
|
|
case 4: |
487 |
|
|
glpath[index].Append("/trk-param/eta_param-0/"); |
488 |
|
|
break; |
489 |
|
|
case 5: |
490 |
|
|
glpath[index].Append("/trk-param/align_param-0/"); |
491 |
|
|
break; |
492 |
|
|
case 6: |
493 |
|
|
glpath[index].Append("/trk-param/mask_param-1/"); |
494 |
|
|
break; |
495 |
|
|
case 7: |
496 |
|
|
glpath[index].Append("/trk-param/default_calib/"); |
497 |
|
|
break; |
498 |
|
|
} |
499 |
|
|
|
500 |
|
|
}else{ |
501 |
|
|
cout << " TrkParams::Set( UInt_t type) ==> No PAMELA environment variables defined "<<endl; |
502 |
|
|
return false; |
503 |
|
|
|
504 |
|
|
} |
505 |
|
|
|
506 |
pam-fi |
1.2 |
cout << "<< set TrkParams type "<<type<<" (from env var PAM_CALIB) >>"<<endl; |
507 |
pam-fi |
1.1 |
// return TrkParams::Load(type); |
508 |
|
|
return true; |
509 |
|
|
|
510 |
|
|
}; |
511 |
|
|
/** |
512 |
|
|
* Set tracker parameters. |
513 |
|
|
* If no path as been yet specified, try to read from DB |
514 |
|
|
* otherwise it set a default path. |
515 |
|
|
* @return FALSE if parameter set fails. |
516 |
|
|
*/ |
517 |
|
|
Bool_t TrkParams::Set( ){ |
518 |
|
|
|
519 |
|
|
Bool_t connected = false; |
520 |
|
|
|
521 |
|
|
cout <<" Missing DB connection -- check PAMELA environment variables "<<endl; |
522 |
|
|
TString host = "mysql://localhost/pamelaprod"; |
523 |
|
|
TString user = "anonymous"; |
524 |
|
|
TString psw = ""; |
525 |
|
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
526 |
|
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
527 |
|
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
528 |
|
|
if ( !pamdbhost ) pamdbhost = ""; |
529 |
|
|
if ( !pamdbuser ) pamdbuser = ""; |
530 |
|
|
if ( !pamdbpsw ) pamdbpsw = ""; |
531 |
|
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
532 |
|
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
533 |
|
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
534 |
|
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
535 |
|
|
cout<<"Connecting to DB"<<endl; |
536 |
|
|
cout<<"HOST "<<host<<endl; |
537 |
|
|
cout<<"USER "<<user<<endl; |
538 |
|
|
cout<<"PSW "<<psw<<endl; |
539 |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
540 |
|
|
if( dbc || dbc->IsConnected() )connected = true; |
541 |
|
|
else cout << " >> FAILED!!!"<<endl; |
542 |
|
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
543 |
|
|
|
544 |
|
|
if(connected){ |
545 |
|
|
if ( !TrkParams::Set(0,dbc) )return false; |
546 |
|
|
dbc->Close(); |
547 |
|
|
}else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false; |
548 |
pam-fi |
1.3 |
|
549 |
|
|
return true; |
550 |
pam-fi |
1.1 |
} |
551 |
|
|
|
552 |
|
|
/** |
553 |
|
|
* Load tracker parameter, if not already loaded. |
554 |
|
|
* @param type Parameter type |
555 |
|
|
* ( Any call to TrkParams::Set(...) forces reloading ) |
556 |
|
|
*/ |
557 |
|
|
Bool_t TrkParams::Load(UInt_t type){ |
558 |
|
|
|
559 |
|
|
Int_t index = TrkParams::GetIndex( type ); |
560 |
|
|
if( index<0 )return false; |
561 |
|
|
if( glload[index] )return true; |
562 |
|
|
|
563 |
|
|
if( glpath[index].IsNull() )TrkParams::Set(type); |
564 |
|
|
|
565 |
|
|
switch( type ){ |
566 |
|
|
//------------------------------------------ |
567 |
|
|
case 1: |
568 |
|
|
cout <<type<<" -- Loading magnetic field "<<glpath[index]<<endl; |
569 |
|
|
strcpy(path_.path,glpath[index].Data()); |
570 |
|
|
path_.pathlen = glpath[index].Length(); |
571 |
|
|
path_.error = 0; |
572 |
|
|
readb_(); |
573 |
|
|
if(path_.error) return false; |
574 |
|
|
glload[index]=true; |
575 |
|
|
break; |
576 |
|
|
//------------------------------------------ |
577 |
|
|
case 2: |
578 |
|
|
cout <<type<<" -- Loading ADC-to-MIP conversion parameters "<<glpath[index]<<endl; |
579 |
|
|
strcpy(path_.path,glpath[index].Data()); |
580 |
|
|
path_.pathlen = glpath[index].Length(); |
581 |
|
|
path_.error = 0; |
582 |
|
|
readmipparam_(); |
583 |
|
|
if(path_.error) return false; |
584 |
|
|
glload[index]=true; |
585 |
|
|
break; |
586 |
|
|
//------------------------------------------ |
587 |
|
|
case 3: |
588 |
|
|
cout <<type<<" -- Loading charge-correlation parameters "<<glpath[index]<<endl; |
589 |
|
|
strcpy(path_.path,glpath[index].Data()); |
590 |
|
|
path_.pathlen = glpath[index].Length(); |
591 |
|
|
path_.error = 0; |
592 |
|
|
readchargeparam_(); |
593 |
|
|
if(path_.error) return false; |
594 |
|
|
glload[index]=true; |
595 |
|
|
break; |
596 |
|
|
//------------------------------------------ |
597 |
|
|
case 4: |
598 |
|
|
cout <<type<<" -- Loading p.f.a. parameters "<<glpath[index]<<endl; |
599 |
|
|
strcpy(path_.path,glpath[index].Data()); |
600 |
|
|
path_.pathlen = glpath[index].Length(); |
601 |
|
|
path_.error = 0; |
602 |
|
|
readetaparam_(); |
603 |
|
|
if(path_.error) return false; |
604 |
|
|
glload[index]=true; |
605 |
|
|
break; |
606 |
|
|
//------------------------------------------ |
607 |
|
|
case 5: |
608 |
|
|
cout <<type<<" -- Loading alignment parameters "<<glpath[index]<<endl; |
609 |
|
|
strcpy(path_.path,glpath[index].Data()); |
610 |
|
|
path_.pathlen = glpath[index].Length(); |
611 |
|
|
path_.error = 0; |
612 |
|
|
readalignparam_(); |
613 |
|
|
if(path_.error) return false; |
614 |
|
|
glload[index]=true; |
615 |
|
|
break; |
616 |
|
|
//------------------------------------------ |
617 |
|
|
case 6: |
618 |
|
|
cout <<type<<" -- Loading VK-mask parameters "<<glpath[index]<<endl; |
619 |
|
|
strcpy(path_.path,glpath[index].Data()); |
620 |
|
|
path_.pathlen = glpath[index].Length(); |
621 |
|
|
path_.error = 0; |
622 |
|
|
readvkmask_(); |
623 |
|
|
if(path_.error) return false; |
624 |
|
|
glload[index]=true; |
625 |
|
|
break; |
626 |
|
|
//------------------------------------------ |
627 |
|
|
case 7: |
628 |
|
|
cout <<type<<" -- Loading default calibration "<<glpath[index]<<endl; |
629 |
|
|
strcpy(path_.path,glpath[index].Data()); |
630 |
|
|
path_.pathlen = glpath[index].Length(); |
631 |
|
|
path_.error = 0; |
632 |
|
|
// fillpedsigfromdefault_(); |
633 |
|
|
cout << ">> not implemented <<"<<endl; |
634 |
|
|
if(path_.error) return false; |
635 |
|
|
glload[index]=true; |
636 |
|
|
break; |
637 |
|
|
default: |
638 |
|
|
cout << " Bool_t TrkParams::Load(UInt_t type) -- type "<< type << "not yet implemented"<<endl; |
639 |
|
|
return false; |
640 |
|
|
}; |
641 |
|
|
|
642 |
|
|
return true; |
643 |
|
|
} |
644 |
|
|
|
645 |
|
|
Bool_t TrkParams::Load( ){ |
646 |
|
|
for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )if( !TrkParams::Load(trkparamtype[i]) )return false; |
647 |
|
|
return true; |
648 |
|
|
}; |
649 |
|
|
Bool_t TrkParams::IsLoaded( ){ |
650 |
|
|
for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )return false; |
651 |
|
|
return true; |
652 |
|
|
}; |
653 |
|
|
|
654 |
|
|
ClassImp(TrkParams); |