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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Fri Apr 27 10:39:57 2007 UTC (17 years, 7 months ago) by pam-fi
Branch: MAIN
Changes since 1.5: +116 -95 lines
v3r00: new hough parameters, new variables, and other things...

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

  ViewVC Help
Powered by ViewVC 1.1.23