/[PAMELA software]/DarthVader/TrackerLevel2/src/TrkParams.cpp
ViewVC logotype

Contents of /DarthVader/TrackerLevel2/src/TrkParams.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Mon Mar 19 17:24:29 2007 UTC (17 years, 8 months ago) by pam-fi
Branch: MAIN
Changes since 1.3: +134 -1 lines
implemented calibration check (test purpose)

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 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<<" --> VALIDATION "<<q2.VALIDATION<<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
86 // return TrkParams::LoadCalib();
87 return true;
88 }
89
90 return false;
91 };
92
93 /**
94 * Method to "validate" tracker calibration. Implemented for test purpose. Effective implementation
95 * in YodaProfiler.
96 */
97 UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){
98
99 Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
100 // UInt_t timeaftercalib=120000; //2000;
101 TString classname = caltrk->GetName();
102 // ----------
103 // Check CRCs
104 // ----------
105 for(Int_t ipkt=0; ipkt<6; ipkt++){
106 if( caltrk->crc_hcal[ipkt] ){
107 cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl;
108 return 0; // :-(
109 }
110 for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){
111 cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl;
112 return 0; // :-(
113 }
114 }
115 // -----------------------
116 // Check missing packets:
117 // -----------------------
118 // Readout order:
119 // ------------------
120 // DSP packet board
121 // ------------------
122 // 12 0 1
123 // 10 1 1
124 // 8 2 1
125 // 4 3 1
126 // 6 4 1
127 // 2 5 1
128 // ------------------
129 // 11 0 2
130 // 9 1 2
131 // 7 2 2
132 // 3 3 2
133 // 5 4 2
134 // 1 5 2
135 // ------------------
136 // -------------------------------------------------
137 // Check if it is first or second calibration packet
138 // -------------------------------------------------
139 UInt_t build=0;
140 UInt_t base=0;
141 UInt_t mask=0;
142 if(classname.Contains("CalibTrk1Event")){
143 base=12;
144 mask=0x03F000;
145 }
146 if(classname.Contains("CalibTrk2Event")){
147 base=18;
148 mask=0xFC0000;
149 }
150 // -------------------------------------------------
151 // Count number of packets and set build variable
152 // -------------------------------------------------
153 Int_t npkts=0;
154 for(Int_t ipkt=0; ipkt<6; ipkt++){
155 if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
156 npkts++;
157 build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
158 };
159 }
160 if( npkts==6 )return 1; // :-)
161 else cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-( ( "<<npkts<<" instead of 6 ) --> "<<endl;
162
163 // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
164
165 // -----------------------------------------------
166 // If missing packets: check the acq configuration
167 // (some DSPs might be excluded from acquisition)
168 // -----------------------------------------------
169
170 // -----------------------------------------------
171 // retrieve the first run header after calib
172 // -----------------------------------------------
173 // PacketType *pctp;
174 // EventCounter *cod;
175 // cod = eh->GetCounter();
176 // Int_t irun = cod->Get(pctp->RunHeader);
177 // TTree *rh=(TTree*)file->Get("RunHeader");
178 // if ( !rh || rh->IsZombie() ) throw -17;
179 // if( rh->GetEntries() == irun ){
180 // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl;
181 // return 0; // :-(
182 // }
183
184 // RunHeaderEvent *run = 0;
185 // EventHeader *hrun = 0;
186 // rh->SetBranchAddress("RunHeader", &run);
187 // rh->SetBranchAddress("Header", &hrun);
188 // rh->GetEntry(irun);
189 // // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
190
191 // if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
192 // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
193 // return 0; // :-(
194 // }
195
196 // if( !run->RM_ACQ_AFTER_CALIB ){
197 // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl;
198 // return 0; // :-(
199 // }
200
201 // UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
202 // if( dtime > timeaftercalib ){
203 // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
204 // return 0; // :-(
205 // }
206
207 // if( (run->ACQ_BUILD_INFO & mask) != build ){
208 // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
209 // return 0; // :-(
210 // }
211 return 1; // :-)
212
213 }
214 /**
215 * Method to fill the tracker calibration-parameter struct from on-line calibrations
216 */
217 void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
218
219 cTrkCalib *ca = &pedsigbad_;
220
221 TTree *tr1 = (TTree*)f0->Get("CalibTrk1");
222 TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
223
224 CalibTrk1Event *calibdata1 = 0;
225 CalibTrk2Event *calibdata2 = 0;
226 tr1->SetBranchAddress("CalibTrk1",&calibdata1);
227 tr2->SetBranchAddress("CalibTrk2",&calibdata2);
228 tr1->GetEntry(ev_reg1);
229 tr2->GetEntry(ev_reg2);
230 Int_t dspn1(0),dspn2(0);
231
232 // --- TEST TEST TEST TEST --- //
233 TrkParams::ValidateTrkCalib(calibdata1);
234 TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
235
236 for(Int_t i=0;i<6;i++){
237 dspn1=calibdata1->DSPnumber[i]-1;
238 dspn2=calibdata2->DSPnumber[i]-1;
239 /* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */
240 for(Int_t ii=0;ii<3072;ii++){
241 Int_t j=(ii/128);
242 Int_t jj=ii-j*128;
243 ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
244 ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
245 ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
246 ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
247 ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
248 ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
249 ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
250 ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
251 // cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
252 // cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
253 // cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
254 // cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
255
256 //
257 // invert the bad
258 //
259 if(calibdata1->DSPbad_par[i][ii]==0)
260 ca->bad[jj][j][dspn1]=1;
261 else if(calibdata1->DSPbad_par[i][ii]==1)
262 ca->bad[jj][j][dspn1]=0;
263 if(calibdata2->DSPbad_par[i][ii]==0)
264 ca->bad[jj][j][dspn2]=1;
265 else if(calibdata2->DSPbad_par[i][ii]==1)
266 ca->bad[jj][j][dspn2]=0;
267 };
268 };
269
270 tr1->Delete();
271 tr2->Delete();
272 };
273 /**
274 * Method to fill the tracker calibration-parameter struct from on-line calibrations
275 */
276 void TrkParams::FillFCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
277
278 cTrkCalib *ca = &pedsigbad_;
279
280 TTree *tr1 = (TTree*)f0->Get("CalibTrk1");
281 TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
282
283 CalibTrk1Event *calibdata1 = 0;
284 CalibTrk2Event *calibdata2 = 0;
285 tr1->SetBranchAddress("CalibTrk1",&calibdata1);
286 tr2->SetBranchAddress("CalibTrk2",&calibdata2);
287 tr1->GetEntry(ev_reg1);
288 tr2->GetEntry(ev_reg2);
289 Int_t dspn1(0),dspn2(0);
290
291 // --- TEST TEST TEST TEST --- //
292 TrkParams::ValidateTrkCalib(calibdata1);
293 TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
294
295 for(Int_t i=0;i<6;i++){
296 dspn1=calibdata1->DSPnumber[i]-1;
297 dspn2=calibdata2->DSPnumber[i]-1;
298 /* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */
299 for(Int_t ii=0;ii<3072;ii++){
300 Int_t j=(ii/128);
301 Int_t jj=ii-j*128;
302 ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
303 ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
304 ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
305 ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
306 // cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
307 // cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
308 // cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
309 // cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
310
311 //
312 // invert the bad
313 //
314 if(calibdata1->DSPbad_par[i][ii]==0)
315 ca->bad[jj][j][dspn1]=1;
316 else if(calibdata1->DSPbad_par[i][ii]==1)
317 ca->bad[jj][j][dspn1]=0;
318 if(calibdata2->DSPbad_par[i][ii]==0)
319 ca->bad[jj][j][dspn2]=1;
320 else if(calibdata2->DSPbad_par[i][ii]==1)
321 ca->bad[jj][j][dspn2]=0;
322 };
323 };
324
325 tr1->Delete();
326 tr2->Delete();
327 };
328 /**
329 * Method to fill the tracker calibration-parameter struct from on-line calibrations
330 */
331 void TrkParams::FillTCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
332
333 cTrkCalib *ca = &pedsigbad_;
334
335 TTree *tr1 = (TTree*)f0->Get("CalibTrk1");
336 TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
337
338 CalibTrk1Event *calibdata1 = 0;
339 CalibTrk2Event *calibdata2 = 0;
340 tr1->SetBranchAddress("CalibTrk1",&calibdata1);
341 tr2->SetBranchAddress("CalibTrk2",&calibdata2);
342 tr1->GetEntry(ev_reg1);
343 tr2->GetEntry(ev_reg2);
344 Int_t dspn1(0),dspn2(0);
345
346 // --- TEST TEST TEST TEST --- //
347 TrkParams::ValidateTrkCalib(calibdata1);
348 TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
349
350 for(Int_t i=0;i<6;i++){
351 dspn1=calibdata1->DSPnumber[i]-1;
352 dspn2=calibdata2->DSPnumber[i]-1;
353 /* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */
354 for(Int_t ii=0;ii<3072;ii++){
355 Int_t j=(ii/128);
356 Int_t jj=ii-j*128;
357 ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
358 ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
359 ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
360 ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
361 };
362 };
363
364 tr1->Delete();
365 tr2->Delete();
366 };
367 /**
368 * Method to fill the tracker calibration-parameter struct from default calibration
369 */
370 void TrkParams::FillTCalibFrom(TString path){
371
372 path_.FillWith(path);
373 fillpedsigfromdefault_();
374 if(path_.error) throw -216;
375
376 };
377 /**
378 * Method to fill the tracker VA1-mask struct from calibration
379 */
380 void TrkParams::FillMask(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
381
382 cTrkMask *ma = &mask_;
383
384 TrkCalib *calib = new TrkCalib();
385
386 for(Int_t i=0; i<2; i++){
387 TTree *tr=0;
388 if(i==0){
389 //-------------------------
390 //read calibration packet 1
391 //-------------------------
392 tr = (TTree*)f0->Get("CalibTrk1");
393 tr->SetBranchAddress("CalibTrk1",calib->GetPointerTo());
394 tr->GetEntry(ev_reg1);
395 }
396 if(i==1){
397 //-------------------------
398 //read calibration packet 2
399 //-------------------------
400 tr = (TTree*)f0->Get("CalibTrk2");
401 tr->SetBranchAddress("CalibTrk2",calib->GetPointerTo());
402 tr->GetEntry(ev_reg2);
403 }
404 for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){
405 for(Int_t ivk=0; ivk<NVK; ivk++){
406 Int_t view = calib->GetView(ipkt);
407 Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1);
408 Float_t sigmin = 0.;
409 if(view%2)sigmin = 6.5;
410 else sigmin = 2.5;
411 Int_t mask = 1;
412 if( sigm<sigmin )mask = 0;
413
414 ma->mask_vk_run[ivk][view-1] = mask;
415
416 // if(mask==0)cout<< " VIEW "<<view<<" VK "<<ivk+1<<" -- <SIG> "<<sigm<<" ---> MASKED!"<<endl;
417 }
418 }
419 if(tr)tr->Delete();
420 }
421
422 if(calib)calib->Delete();
423
424 };
425
426 // Bool_t TrkParams::CalibIsLoaded(UInt_t time){
427
428 // if( !calibload ) return false;
429
430 // };
431
432
433 /**
434 * Static method to load calibration.
435 * Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the
436 * first time the method is called (but it does not work becouse I didn't set any
437 * default calibration for the moment) or after the method TrkParams::SetCalib(***) is called.
438 */
439 Bool_t TrkParams::LoadCalib( ){
440
441 if( TrkParams::CalibIsLoaded() )return false;
442
443 // cTrkCalib *ca = new cTrkCalib; //&pedsigbad_;
444
445 // extern cTrkCalib pedsigbad_;
446 // extern cTrkMask mask_;
447
448 cout << "--------------------------------------"<<endl;
449 cout << "Retrieve calibration (PED-SIG-BAD) ..."<<endl;
450 // =============================================================
451 // retrieve calibration file needed to reduce data
452 // =============================================================
453 // if run OBT is > last calibration "expiration date"
454 // - search for new calibration packet
455 // - load calibration parameters (full + truncated)
456 cout << "Full pedestals for cluster finding:";
457 cout << " >> Loading from LEVEL0 file: "<< calibpathf << endl;
458 FileStat_t t;
459 if( gSystem->GetPathInfo(calibpathf.Data(),t) )return false;
460
461 TFile *f0_c = new TFile(calibpathf);
462 if ( !f0_c ) return false;
463 cout << " calibration entries "<< calib.EV_ROOT_CALIBTRK1 << " " << calib.EV_ROOT_CALIBTRK2;
464 cout << " (from time "<< calib.FROM_TIME <<" to time "<< calib.TO_TIME <<")"<<endl;
465 // ca->FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
466 TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
467 TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
468 // mask_.Set(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
469 // for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal[64][12][i] << endl;
470
471 // };
472 // =============================================================
473 // retrieve calibration file needed to uncompress data
474 // =============================================================
475 // if the run was compressed using default calib
476 // load truncated pedestals from default
477 // otherwise reload them from on-line calibration
478 cout << "Truncated pedestals for uncompression:";
479 if( calib104 ){
480
481 cout << " >> Loading default calibration: "<< calibpatht << endl;
482 // ca->FillTCalibFrom(calibpatht);
483 TrkParams::FillTCalibFrom(calibpatht);
484
485 }else{
486
487 if ( !f0_c ) return false;
488 cout << ">> Loading on-line calibration " << endl;
489 // ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
490 TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
491 };
492 // for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal_t[64][12][i] << endl;
493 f0_c->Close();
494 // delete f0_c;
495 cout << "--------------------------------------"<<endl;
496
497 calibload = kTRUE;
498 return true;
499 };
500
501 Int_t TrkParams::GetIndex( UInt_t type ){
502 Int_t index = -1;
503 for (Int_t i=0; i< NTYPES; i++)if( type == trkparamtype[i] )index=i;
504 return index;
505 };
506
507 /**
508 * Set tracker parameters proper for a run querying the DB.
509 * @param glrun Input run info
510 * @param dbc Database
511 * @param type Parameter type
512 * @return FALSE if parameter set fails.
513 * If glrun==NULL the last parameter entry from GL_PARAM table is set.
514 * If dbc==NULL, try to open a connection taking DB-connection
515 * parameters from PAMELA environment variables.
516 */
517 Bool_t TrkParams::Set( GL_RUN* glrun , TSQLServer* dbc , UInt_t type){
518
519 // if( !dbc )return false;
520
521
522 if( !dbc || (dbc && !dbc->IsConnected()) ){
523
524 cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
525 TString host = "mysql://localhost/pamelaprod";
526 TString user = "anonymous";
527 TString psw = "";
528 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
529 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
530 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
531 if ( !pamdbhost ) pamdbhost = "";
532 if ( !pamdbuser ) pamdbuser = "";
533 if ( !pamdbpsw ) pamdbpsw = "";
534 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
535 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
536 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
537 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
538 cout<<"Connecting to DB"<<endl;
539 cout<<"HOST "<<host<<endl;
540 cout<<"USER "<<user<<endl;
541 cout<<"PSW "<<psw<<endl;
542 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
543 if( !dbc )return false;
544 if( !dbc->IsConnected() )return false;
545 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
546
547 }
548
549 UInt_t index = TrkParams::GetIndex( type );
550 if(index < 0)return false;
551
552 UInt_t runheadtime = numeric_limits<UInt_t>::max();
553 if(glrun)runheadtime = glrun->RUNHEADER_TIME;
554 else cout <<"Missing run info -- taking last entry "<<endl;
555
556 GL_PARAM q4;
557 if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;
558
559 gl[index] = q4;
560 glpath[index] = q4.PATH+q4.NAME;
561 glload[index] = false;
562 cout << "<< set TrkParams type "<<type<<" >> (from DB) "<<endl;
563 return true;
564 // return TrkParams::Load(type);
565
566 };
567 /**
568 * Set tracker parameters proper for the run, from input.
569 * @param path Path to parameters directory
570 * @param type Parameter type
571 * @return FALSE if parameter set fails.
572 */
573 Bool_t TrkParams::Set( TString path , UInt_t type){
574
575 UInt_t index = TrkParams::GetIndex( type );
576 if(index < 0)return false;
577
578 gl[index].TYPE= type;
579 glpath[index] = path;
580 cout << "<< set TrkParams type "<<type<<" >> (from input) "<<endl;
581 glload[index] = false;
582
583 // return TrkParams::Load(type);
584 return true;
585
586 };
587
588 /**
589 * Set and load tracker parameters.
590 * @param type Parameter type
591 * If no path as been yet specified, it set a default path.
592 * @return FALSE if parameter set fails.
593 */
594 Bool_t TrkParams::Set(UInt_t type){
595
596 UInt_t index = TrkParams::GetIndex( type );
597 if(index < 0)return false;
598
599 gl[index].TYPE= type;
600 glload[index] = false;
601
602 // -----------------------------------------
603 // check if enviroment variables are defined
604 // -----------------------------------------
605 glpath[index] = gSystem->Getenv("PAM_CALIB");
606
607 if( !glpath[index].IsNull() ){
608
609 switch(type){
610 case 1:
611 glpath[index].Append("/trk-param/field_param-0/");
612 break;
613 case 2:
614 glpath[index].Append("/trk-param/mip_param-0/");
615 break;
616 case 3:
617 glpath[index].Append("/trk-param/charge_param-1/");
618 break;
619 case 4:
620 glpath[index].Append("/trk-param/eta_param-0/");
621 break;
622 case 5:
623 glpath[index].Append("/trk-param/align_param-0/");
624 break;
625 case 6:
626 glpath[index].Append("/trk-param/mask_param-1/");
627 break;
628 case 7:
629 glpath[index].Append("/trk-param/default_calib/");
630 break;
631 }
632
633 }else{
634 cout << " TrkParams::Set( UInt_t type) ==> No PAMELA environment variables defined "<<endl;
635 return false;
636
637 }
638
639 cout << "<< set TrkParams type "<<type<<" (from env var PAM_CALIB) >>"<<endl;
640 // return TrkParams::Load(type);
641 return true;
642
643 };
644 /**
645 * Set tracker parameters.
646 * If no path as been yet specified, try to read from DB
647 * otherwise it set a default path.
648 * @return FALSE if parameter set fails.
649 */
650 Bool_t TrkParams::Set( ){
651
652 Bool_t connected = false;
653
654 cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
655 TString host = "mysql://localhost/pamelaprod";
656 TString user = "anonymous";
657 TString psw = "";
658 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
659 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
660 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
661 if ( !pamdbhost ) pamdbhost = "";
662 if ( !pamdbuser ) pamdbuser = "";
663 if ( !pamdbpsw ) pamdbpsw = "";
664 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
665 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
666 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
667 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
668 cout<<"Connecting to DB"<<endl;
669 cout<<"HOST "<<host<<endl;
670 cout<<"USER "<<user<<endl;
671 cout<<"PSW "<<psw<<endl;
672 TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
673 if( dbc || dbc->IsConnected() )connected = true;
674 else cout << " >> FAILED!!!"<<endl;
675 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
676
677 if(connected){
678 if ( !TrkParams::Set(0,dbc) )return false;
679 dbc->Close();
680 }else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false;
681
682 return true;
683 }
684
685 /**
686 * Load tracker parameter, if not already loaded.
687 * @param type Parameter type
688 * ( Any call to TrkParams::Set(...) forces reloading )
689 */
690 Bool_t TrkParams::Load(UInt_t type){
691
692 Int_t index = TrkParams::GetIndex( type );
693 if( index<0 )return false;
694 if( glload[index] )return true;
695
696 if( glpath[index].IsNull() )TrkParams::Set(type);
697
698 switch( type ){
699 //------------------------------------------
700 case 1:
701 cout <<type<<" -- Loading magnetic field "<<glpath[index]<<endl;
702 strcpy(path_.path,glpath[index].Data());
703 path_.pathlen = glpath[index].Length();
704 path_.error = 0;
705 readb_();
706 if(path_.error) return false;
707 glload[index]=true;
708 break;
709 //------------------------------------------
710 case 2:
711 cout <<type<<" -- Loading ADC-to-MIP conversion parameters "<<glpath[index]<<endl;
712 strcpy(path_.path,glpath[index].Data());
713 path_.pathlen = glpath[index].Length();
714 path_.error = 0;
715 readmipparam_();
716 if(path_.error) return false;
717 glload[index]=true;
718 break;
719 //------------------------------------------
720 case 3:
721 cout <<type<<" -- Loading charge-correlation parameters "<<glpath[index]<<endl;
722 strcpy(path_.path,glpath[index].Data());
723 path_.pathlen = glpath[index].Length();
724 path_.error = 0;
725 readchargeparam_();
726 if(path_.error) return false;
727 glload[index]=true;
728 break;
729 //------------------------------------------
730 case 4:
731 cout <<type<<" -- Loading p.f.a. parameters "<<glpath[index]<<endl;
732 strcpy(path_.path,glpath[index].Data());
733 path_.pathlen = glpath[index].Length();
734 path_.error = 0;
735 readetaparam_();
736 if(path_.error) return false;
737 glload[index]=true;
738 break;
739 //------------------------------------------
740 case 5:
741 cout <<type<<" -- Loading alignment parameters "<<glpath[index]<<endl;
742 strcpy(path_.path,glpath[index].Data());
743 path_.pathlen = glpath[index].Length();
744 path_.error = 0;
745 readalignparam_();
746 if(path_.error) return false;
747 glload[index]=true;
748 break;
749 //------------------------------------------
750 case 6:
751 cout <<type<<" -- Loading VK-mask parameters "<<glpath[index]<<endl;
752 strcpy(path_.path,glpath[index].Data());
753 path_.pathlen = glpath[index].Length();
754 path_.error = 0;
755 readvkmask_();
756 if(path_.error) return false;
757 glload[index]=true;
758 break;
759 //------------------------------------------
760 case 7:
761 cout <<type<<" -- Loading default calibration "<<glpath[index]<<endl;
762 strcpy(path_.path,glpath[index].Data());
763 path_.pathlen = glpath[index].Length();
764 path_.error = 0;
765 // fillpedsigfromdefault_();
766 cout << ">> not implemented <<"<<endl;
767 if(path_.error) return false;
768 glload[index]=true;
769 break;
770 default:
771 cout << " Bool_t TrkParams::Load(UInt_t type) -- type "<< type << "not yet implemented"<<endl;
772 return false;
773 };
774
775 return true;
776 }
777
778 Bool_t TrkParams::Load( ){
779 for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )if( !TrkParams::Load(trkparamtype[i]) )return false;
780 return true;
781 };
782 Bool_t TrkParams::IsLoaded( ){
783 for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )return false;
784 return true;
785 };
786
787 ClassImp(TrkParams);

  ViewVC Help
Powered by ViewVC 1.1.23