/[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.5 - (show annotations) (download)
Wed Mar 21 11:05:39 2007 UTC (17 years, 11 months ago) by pam-fi
Branch: MAIN
Changes since 1.4: +10 -7 lines
some printouts

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

  ViewVC Help
Powered by ViewVC 1.1.23