58 |
* @param debug debug flag. |
* @param debug debug flag. |
59 |
* @param tlefilename ascii file with TLE 3 line elements. |
* @param tlefilename ascii file with TLE 3 line elements. |
60 |
*/ |
*/ |
61 |
PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput, Bool_t staticp, Bool_t gpamela){ |
PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput, Bool_t staticp, Bool_t gpamela, Bool_t keepenv){ |
62 |
// |
// |
63 |
|
RELAXED = false; |
64 |
chewbacca = false; |
chewbacca = false; |
65 |
chminentry = 0; |
chminentry = 0; |
66 |
chID = 0; |
chID = 0; |
77 |
// |
// |
78 |
}; |
}; |
79 |
// |
// |
80 |
|
KEEPENV = false; |
81 |
|
if ( keepenv ) KEEPENV=true; |
82 |
STATIC=false; |
STATIC=false; |
83 |
if ( staticp ) STATIC=true; |
if ( staticp ) STATIC=true; |
84 |
// |
// |
88 |
// |
// |
89 |
glrun = new GL_RUN(); |
glrun = new GL_RUN(); |
90 |
// |
// |
91 |
if ( !chewbacca ){ |
// if ( !chewbacca ){ |
92 |
if ( !boot ) SetNOBOOT(false); |
// if ( !boot ) SetNOBOOT(false); |
93 |
SetTsync(tsync,gpamela); |
// SetTsync(tsync,gpamela); |
94 |
SetBOOTnumber(boot,gpamela); |
// SetBOOTnumber(boot,gpamela); |
95 |
SetObt0(obt0); |
// SetObt0(obt0); |
96 |
}; |
// }; |
97 |
// |
// |
98 |
SetTLEPath(tlefilename); |
SetTLEPath(tlefilename); |
99 |
// |
// |
102 |
if (INSERT_RAW) SetRawName(filerawname); |
if (INSERT_RAW) SetRawName(filerawname); |
103 |
// |
// |
104 |
INSERT_ROOT = !filerootname.IsNull(); |
INSERT_ROOT = !filerootname.IsNull(); |
105 |
|
if ( INSERT_ROOT ) this->SetRootName(filerootname); |
106 |
this->SetOrbitNo(dwinput); |
this->SetOrbitNo(dwinput); |
107 |
// |
// |
108 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
126 |
// |
// |
127 |
// SETTERS |
// SETTERS |
128 |
// |
// |
129 |
|
void PamelaDBOperations::NotChewbacca(UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t gpamela){ |
130 |
|
if ( !boot ) SetNOBOOT(false); |
131 |
|
SetTsync(tsync,gpamela); |
132 |
|
SetBOOTnumber(boot,gpamela); |
133 |
|
SetObt0(obt0); |
134 |
|
}; |
135 |
|
|
136 |
void PamelaDBOperations::OpenL0File(TString filerootname){ |
void PamelaDBOperations::OpenL0File(TString filerootname){ |
137 |
if( INSERT_ROOT ){ |
if( INSERT_ROOT ){ |
142 |
stringstream qu; |
stringstream qu; |
143 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
144 |
TSQLResult *result2 = 0; |
TSQLResult *result2 = 0; |
145 |
|
TSQLResult *result3 = 0; |
146 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
147 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
148 |
|
TSQLRow *row3 = 0; |
149 |
TString chpath; |
TString chpath; |
150 |
TString chfile; |
TString chfile; |
151 |
UInt_t ridn = 0; |
UInt_t ridn = 0; |
152 |
qu.str(""); |
qu.str(""); |
153 |
qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; |
qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,INSERTED_BY,REAL_TIME_INIT from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; |
154 |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
155 |
result = conn->Query(qu.str().c_str()); |
result = conn->Query(qu.str().c_str()); |
156 |
if ( result ){ |
if ( result ){ |
161 |
chpktmax = (UInt_t)atoll(row->GetField(2)); |
chpktmax = (UInt_t)atoll(row->GetField(2)); |
162 |
chobtmin = (UInt_t)atoll(row->GetField(3)); |
chobtmin = (UInt_t)atoll(row->GetField(3)); |
163 |
chobtmax = (UInt_t)atoll(row->GetField(4)); |
chobtmax = (UInt_t)atoll(row->GetField(4)); |
164 |
|
chiby = (TString)(row->GetField(5)); |
165 |
|
chrtinit = (UInt_t)atoll(row->GetField(6)); |
166 |
} else { |
} else { |
167 |
throw -84; |
throw -84; |
168 |
}; |
}; |
171 |
}; |
}; |
172 |
delete result; |
delete result; |
173 |
qu.str(""); |
qu.str(""); |
174 |
qu << "SELECT FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,TIME_OFFSET,BOOT_NUMBER,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL from ROOT_TABLE where ID_N=" << ridn << ";"; |
qu << "SELECT FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,TIME_OFFSET,BOOT_NUMBER,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,REAL_TIME_INIT from ROOT_TABLE where ID_N=" << ridn << ";"; |
175 |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
176 |
result2 = conn->Query(qu.str().c_str()); |
result2 = conn->Query(qu.str().c_str()); |
177 |
if ( result2 ){ |
if ( result2 ){ |
178 |
row2 = result2->Next(); |
row2 = result2->Next(); |
179 |
if ( row2 ){ |
if ( row2 ){ |
180 |
chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; |
if ( KEEPENV ){ |
181 |
|
chpath = (TString)(row2->GetField(0))+'/'; |
182 |
|
} else { |
183 |
|
chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; |
184 |
|
}; |
185 |
chfile = (TString)(row2->GetField(1)); |
chfile = (TString)(row2->GetField(1)); |
186 |
chobtts = (UInt_t)atoll(row2->GetField(2)); |
chobtts = (UInt_t)atoll(row2->GetField(2)); |
187 |
chlastts = (UInt_t)atoll(row2->GetField(3)); |
chlastts = (UInt_t)atoll(row2->GetField(3)); |
188 |
chresursts = (UInt_t)atoll(row2->GetField(4)); |
chresursts = (UInt_t)atoll(row2->GetField(4)); |
189 |
chboot = (UInt_t)atoll(row2->GetField(5)); |
chboot = (UInt_t)atoll(row2->GetField(5)); |
190 |
// |
// |
191 |
|
if ( !chboot ){ |
192 |
|
if ( debug ) printf(" mmm... no BOOT number determined by chewbacca, try to find it looking at DB \n"); |
193 |
|
// |
194 |
|
// new feature: check in ROOT_TABLE (timewise) the previous and the next BOOT number != 0 , if it is the same we know this one! |
195 |
|
// if it is different roll back to the old behaviour |
196 |
|
// |
197 |
|
qu.str(""); |
198 |
|
qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND REAL_TIME_INIT>"<< row2->GetField(10) <<" order by REAL_TIME_INIT asc limit 1;"; |
199 |
|
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
200 |
|
UInt_t chbootA = 0; |
201 |
|
UInt_t chbootB = 1; |
202 |
|
result3 = conn->Query(qu.str().c_str()); |
203 |
|
if ( result3 ){ |
204 |
|
row3 = result3->Next(); |
205 |
|
if ( row3 ){ |
206 |
|
chbootA = (UInt_t)atoll(row3->GetField(0)); |
207 |
|
if ( debug ) printf(" Found boot_number A = %u \n",chbootA); |
208 |
|
}; |
209 |
|
}; |
210 |
|
delete result3; |
211 |
|
qu.str(""); |
212 |
|
qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND REAL_TIME_INIT<"<< row2->GetField(10) <<" order by REAL_TIME_INIT desc limit 1;"; |
213 |
|
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
214 |
|
result3 = conn->Query(qu.str().c_str()); |
215 |
|
if ( result3 ){ |
216 |
|
row3 = result3->Next(); |
217 |
|
if ( row3 ){ |
218 |
|
chbootB = (UInt_t)atoll(row3->GetField(0)); |
219 |
|
if ( debug ) printf(" Found boot_number B = %u \n",chbootB); |
220 |
|
}; |
221 |
|
}; |
222 |
|
if ( chbootA == chbootB ){ |
223 |
|
chboot = chbootA; |
224 |
|
if ( debug ) printf(" Found boot_number! it is %u \n",chboot); |
225 |
|
} else { |
226 |
|
qu.str(""); |
227 |
|
// qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< chlastts <<")<10000 AND ABS(REAL_TIME_INIT-"<< row2->GetField(10) <<")<7200 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; |
228 |
|
// qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< chlastts <<")<40000 AND ABS(REAL_TIME_INIT-"<< row2->GetField(10) <<")<40000 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; // relax conditions... 090112 [8RED: error -29] |
229 |
|
qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< chlastts <<")<50000 AND ABS(REAL_TIME_INIT-"<< row2->GetField(10) <<")<50000 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; // even more relaxed conditions... 091214 [9REDtest3: error -29] |
230 |
|
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
231 |
|
result3 = conn->Query(qu.str().c_str()); |
232 |
|
if ( result3 ){ |
233 |
|
row3 = result3->Next(); |
234 |
|
if ( row3 && result3->GetRowCount() == 1 ){ |
235 |
|
chboot = (UInt_t)atoll(row3->GetField(0)); |
236 |
|
if ( debug ) printf(" Found boot_number = %u \n",chboot); |
237 |
|
} else { |
238 |
|
if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n"); |
239 |
|
throw -29; |
240 |
|
}; |
241 |
|
}; |
242 |
|
}; |
243 |
|
}; |
244 |
|
// |
245 |
chpktinit = (UInt_t)atoll(row2->GetField(6)); |
chpktinit = (UInt_t)atoll(row2->GetField(6)); |
246 |
chpktfinal = (UInt_t)atoll(row2->GetField(7)); |
chpktfinal = (UInt_t)atoll(row2->GetField(7)); |
247 |
chobtinit = (UInt_t)atoll(row2->GetField(8)); |
chobtinit = (UInt_t)atoll(row2->GetField(8)); |
254 |
throw -85; |
throw -85; |
255 |
}; |
}; |
256 |
filerootname = chpath + chfile;// + ".root"; |
filerootname = chpath + chfile;// + ".root"; |
|
if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data()); |
|
257 |
}; |
}; |
258 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
|
file = TFile::Open(this->GetRootName().Data()); |
|
|
} else { |
|
|
this->SetRootName(""); |
|
259 |
}; |
}; |
260 |
|
if ( debug ) printf(" Filename is %s \n",filerootname.Data()); |
261 |
|
file = TFile::Open(this->GetRootName().Data()); |
262 |
|
// } else { |
263 |
|
// this->SetRootName(""); |
264 |
|
// this->SetRootName(filerootname); |
265 |
|
// }; |
266 |
} |
} |
267 |
|
|
268 |
// |
// |
462 |
return; |
return; |
463 |
}; |
}; |
464 |
// |
// |
465 |
TString name = this->GetRootFile(); |
if ( !chewbacca ){ |
466 |
Int_t nlength = name.Length(); |
TString name = this->GetRootFile(); |
467 |
if ( nlength < 5 ) return; |
Int_t nlength = name.Length(); |
468 |
TString dwo = 0; |
if ( nlength < 5 ){ |
469 |
for (Int_t i = 0; i<5; i++){ |
if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data()); |
470 |
dwo.Append(name[i],1); |
return; |
471 |
}; |
}; |
472 |
if ( dwo.IsDigit() ){ |
TString dwo = ""; |
473 |
dworbit = (UInt_t)dwo.Atoi(); |
for (Int_t i = 0; i<5; i++){ |
|
} else { |
|
|
dwo=""; |
|
|
for (Int_t i = 8; i<13; i++){ |
|
474 |
dwo.Append(name[i],1); |
dwo.Append(name[i],1); |
475 |
}; |
}; |
476 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ){ |
477 |
|
dworbit = (UInt_t)dwo.Atoi(); |
478 |
|
} else { |
479 |
|
dwo=""; |
480 |
|
for (Int_t i = 8; i<13; i++){ |
481 |
|
dwo.Append(name[i],1); |
482 |
|
}; |
483 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
484 |
|
}; |
485 |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
486 |
}; |
}; |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
|
487 |
return; |
return; |
488 |
}; |
}; |
489 |
|
|
514 |
|
|
515 |
TString PamelaDBOperations::GetRootPath(){ |
TString PamelaDBOperations::GetRootPath(){ |
516 |
if ( STATIC ){ |
if ( STATIC ){ |
517 |
return((TString)gSystem->DirName(filerootname.Data())+'/'); |
return((TString)gSystem->DirName(this->GetRootName().Data())+'/'); |
518 |
} else { |
} else { |
519 |
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
if ( KEEPENV ){ |
520 |
|
return((TString)gSystem->ExpandPathName(gSystem->DirName(filerootname.Data()))+'/'); |
521 |
|
} else { |
522 |
|
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
523 |
|
}; |
524 |
}; |
}; |
525 |
}; |
}; |
526 |
|
|
732 |
UInt_t tjump = 50000; |
UInt_t tjump = 50000; |
733 |
//UInt_t tjump = 100; |
//UInt_t tjump = 100; |
734 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
735 |
pktlast = numeric_limits<UInt_t>::max(); |
// pktlast = numeric_limits<UInt_t>::max(); |
736 |
while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){ |
pktlast = chpktmax + 1; |
737 |
|
while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){ |
738 |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
739 |
T->GetEntry(nevent-1-it); |
T->GetEntry(nevent-1-it); |
740 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
742 |
} else { |
} else { |
743 |
pktlast = chpktmax + 1; |
pktlast = chpktmax + 1; |
744 |
}; |
}; |
745 |
if ( (!(it%1000) || abs((int)pktlast - (int)chpktmax)<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it)); |
if ( (!(it%1000) || abs((int)(PKT(pktlast) - PKT(chpktmax)))<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it)); |
746 |
it += tjump; |
it += tjump; |
747 |
}; |
}; |
748 |
if ( tjump > 1 ) it -= 2*tjump; |
if ( tjump > 1 ) it -= 2*tjump; |
766 |
tjump = 50000; |
tjump = 50000; |
767 |
//tjump = 100; |
//tjump = 100; |
768 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
769 |
pktlast = 0; |
// pktlast = 0; |
770 |
while ( pktlast < chpktmin && it < (Int_t)nevent ){ |
pktlast = chpktmin - 1; |
771 |
|
if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin)); |
772 |
|
while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){ |
773 |
if ( it < (Int_t)nevent ){ |
if ( it < (Int_t)nevent ){ |
774 |
T->GetEntry(it); |
T->GetEntry(it); |
775 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
863 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
864 |
pktlast = ph->GetCounter(); |
pktlast = ph->GetCounter(); |
865 |
nevent = upperentry - chminentry; |
nevent = upperentry - chminentry; |
866 |
|
if ( ((Int_t)upperentry - (Int_t)chminentry) < 0 ) nevent = 0; // nevent is UInt_t! 090112 [8RED: error -88] |
867 |
|
if ( IsDebug() ) printf(" Setting nevent to %u - upperentry %i chminentry %i \n",nevent,upperentry,chminentry); |
868 |
// |
// |
869 |
} else { |
} else { |
870 |
upperpkt = PKT(pktlast); |
upperpkt = PKT(pktlast); |
873 |
}; |
}; |
874 |
// |
// |
875 |
if ( chewbacca && nevent < 1 ) { |
if ( chewbacca && nevent < 1 ) { |
876 |
|
if ( IsDebug() ) printf(" chewbacca and no events in the file \n"); |
877 |
pktfirst = chpktmin; |
pktfirst = chpktmin; |
878 |
upperpkt = PKT(chpktmax); |
upperpkt = PKT(chpktmax); |
879 |
pktlast = chpktmax; |
pktlast = chpktmax; |
899 |
// if ( nevent < jump ) jump = int(nevent/10); |
// if ( nevent < jump ) jump = int(nevent/10); |
900 |
// if ( !jump ) jump = 1; |
// if ( !jump ) jump = 1; |
901 |
// |
// |
902 |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){ |
|
903 |
|
if ( ((PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt)) && nevent > deltapkt ){ |
904 |
// |
// |
905 |
if ( IsDebug() ) printf(" starting jump %i \n",jump); |
if ( IsDebug() ) printf(" starting jump %i \n",jump); |
906 |
// if ( IsDebug() ) printf(" (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) %llu < %llu && %llu > %llu \n OR \n (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) %llu > %llu && %llu < %llu \n",PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst),PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst)); |
// if ( IsDebug() ) printf(" (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) %llu < %llu && %llu > %llu \n OR \n (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) %llu > %llu && %llu < %llu \n",PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst),PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst)); |
1215 |
stringstream oss; |
stringstream oss; |
1216 |
// |
// |
1217 |
oss.str(""); |
oss.str(""); |
1218 |
oss << "INSERT INTO _RUNID_GEN VALUES (NULL);"; |
if ( chewbacca ){// if chewbacca and tag=none then use chewbacca tag (chiby = chewbacca inserted by), if chewbacca and tag!=none then use tag, if not chewbacca use tag. |
1219 |
|
if ( !strcmp(tag.Data(),"NONE") ){ |
1220 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< chiby.Data() <<"');"; |
1221 |
|
} else { |
1222 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1223 |
|
}; |
1224 |
|
} else { |
1225 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1226 |
|
}; |
1227 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1228 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1229 |
oss.str(""); |
oss.str(""); |
1371 |
stringstream oss; |
stringstream oss; |
1372 |
// |
// |
1373 |
oss.str(""); |
oss.str(""); |
1374 |
oss << "lock table GL_RUN write, GL_ROOT write, GL_RAW write, GL_TIMESYNC write, GL_RESURS_OFFSET write, GL_PARAM write, GL_TLE write, GL_RUN_FRAGMENTS write, GL_RUN_TRASH write, GL_CALO_CALIB write, GL_CALOPULSE_CALIB write, GL_TRK_CALIB write, GL_S4_CALIB write, ROOT_TABLE_MERGING write, ROOT_TABLE write, _RUNID_GEN write;"; |
oss << "lock table GL_RUN write, GL_ROOT write, GL_RAW write, GL_TIMESYNC write, GL_RESURS_OFFSET write, GL_PARAM write, GL_TLE write, GL_RUN_FRAGMENTS write, GL_RUN_TRASH write, GL_CALO_CALIB write, GL_CALOPULSE_CALIB write, GL_TRK_CALIB write, GL_S4_CALIB write, ROOT_TABLE_MERGING write, ROOT_TABLE_BAD write, ROOT_TABLE write, _RUNID_GEN write;"; |
1375 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1376 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1377 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1428 |
// |
// |
1429 |
// if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits<UInt_t>::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits<UInt_t>::max()/2)); |
// if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits<UInt_t>::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits<UInt_t>::max()/2)); |
1430 |
// |
// |
1431 |
if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1432 |
// if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
// if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1433 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1434 |
}; |
}; |
1475 |
UInt_t lastPkt = 0; |
UInt_t lastPkt = 0; |
1476 |
UInt_t rhtime = 0; |
UInt_t rhtime = 0; |
1477 |
UInt_t rttime = 0; |
UInt_t rttime = 0; |
1478 |
|
// |
1479 |
|
if ( IsDebug() ) printf(" A firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1480 |
|
// |
1481 |
if ( !mishead ){ |
if ( !mishead ){ |
1482 |
codh = ehh->GetCounter(); |
codh = ehh->GetCounter(); |
1483 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1484 |
|
if ( IsDebug() ) printf(" B firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1485 |
firstev = 1; |
firstev = 1; |
1486 |
lastev = 0; |
lastev = 0; |
1487 |
} else { |
} else { |
1494 |
}; |
}; |
1495 |
if ( !mistrail ){ |
if ( !mistrail ){ |
1496 |
codt = eht->GetCounter(); |
codt = eht->GetCounter(); |
1497 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1)){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1)){ |
1498 |
|
if ( IsDebug() ) printf(" C firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1499 |
lastev = 0; |
lastev = 0; |
1500 |
firstev = lastev+1; |
firstev = lastev+1; |
1501 |
} else { |
} else { |
1512 |
if ( mishead ) { |
if ( mishead ) { |
1513 |
glrun->Set_GL_RUNH0(); |
glrun->Set_GL_RUNH0(); |
1514 |
// |
// |
1515 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1516 |
firstObt = lastObt; |
firstObt = lastObt; |
1517 |
firstPkt = lastPkt; |
firstPkt = lastPkt; |
1518 |
rhtime = rttime; |
rhtime = rttime; |
1531 |
if ( mistrail ){ |
if ( mistrail ){ |
1532 |
glrun->Set_GL_RUNT0(); |
glrun->Set_GL_RUNT0(); |
1533 |
// |
// |
1534 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1535 |
lastObt = firstObt; |
lastObt = firstObt; |
1536 |
lastPkt = firstPkt; |
lastPkt = firstPkt; |
1537 |
rttime = rhtime; |
rttime = rhtime; |
1547 |
glrun->SetRUNTRAILER_PKT(lastPkt); |
glrun->SetRUNTRAILER_PKT(lastPkt); |
1548 |
// |
// |
1549 |
}; |
}; |
1550 |
|
// |
1551 |
|
// ad hoc solution for INF EV_TO [8RED] 090113 |
1552 |
|
// |
1553 |
|
if ( !firstev && lastev == -1 ){ |
1554 |
|
if ( IsDebug() ) printf(" EE firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1555 |
|
firstev = 1; |
1556 |
|
lastev = 0; |
1557 |
|
}; |
1558 |
glrun->SetEV_FROM((UInt_t)firstev); |
glrun->SetEV_FROM((UInt_t)firstev); |
1559 |
glrun->SetEV_TO((UInt_t)lastev); |
glrun->SetEV_TO((UInt_t)lastev); |
1560 |
glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1); |
glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1); |
1574 |
* Insert a new row into GL_RAW table. |
* Insert a new row into GL_RAW table. |
1575 |
*/ |
*/ |
1576 |
Int_t PamelaDBOperations::insertPamelaRawFile(){ |
Int_t PamelaDBOperations::insertPamelaRawFile(){ |
1577 |
|
|
1578 |
|
// |
1579 |
|
Bool_t idr = this->SetID_RAW(); |
1580 |
|
if ( idr ) return(1); |
1581 |
|
|
1582 |
|
GL_RAW glraw = GL_RAW(); |
1583 |
|
|
1584 |
|
glraw.PATH = GetRawPath(); |
1585 |
|
glraw.NAME = GetRawFile(); |
1586 |
|
// glraw.BOOT_NUMBER = 0;//??? |
1587 |
|
glraw.BOOT_NUMBER = this->GetBOOTnumber(); |
1588 |
|
|
1589 |
|
if( insertPamelaRawFile(&glraw) )return(1); |
1590 |
|
// |
1591 |
|
idr = this->SetID_RAW(); |
1592 |
|
if ( !idr ) throw -11; |
1593 |
|
|
1594 |
|
return(0); |
1595 |
|
} |
1596 |
|
/** |
1597 |
|
* Insert a new row into GL_RAW table. |
1598 |
|
*/ |
1599 |
|
Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ |
1600 |
// |
// |
1601 |
stringstream oss; |
if(!glraw)return(1);//?? ok I think |
1602 |
// |
// |
1603 |
Bool_t idr = this->SetID_RAW(); |
stringstream oss; |
1604 |
if ( idr ) return(1); |
// |
1605 |
// |
oss.str(""); |
1606 |
oss.str(""); |
if ( STATIC ){ |
1607 |
if ( STATIC ){ |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
1608 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
<< glraw->PATH << "', '" << glraw->NAME << "')"; |
1609 |
<< this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; |
} else { |
1610 |
} else { |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << glraw->NAME << "')"; |
1611 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')"; |
}; |
1612 |
}; |
if ( debug ) cout <<oss.str().c_str() <<endl; |
1613 |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1614 |
// |
// |
1615 |
idr = this->SetID_RAW(); |
oss.str(""); |
1616 |
if ( !idr ) throw -11; |
oss << "SELECT ID FROM GL_RAW WHERE NAME=\""<<glraw->NAME<<"\";"; |
1617 |
// |
if ( debug ) cout << oss.str().c_str()<<endl; |
1618 |
return(0); |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1619 |
|
// |
1620 |
|
TSQLResult *result = 0; |
1621 |
|
TSQLRow *row = 0; |
1622 |
|
result = conn->Query(oss.str().c_str()); |
1623 |
|
if ( result == NULL ) throw -4; |
1624 |
|
row = result->Next(); |
1625 |
|
if ( !row ) return(1); |
1626 |
|
glraw->ID = (UInt_t)atoll(row->GetField(0)); |
1627 |
|
if ( debug ) printf(" The ID of the RAW file is %u \n",glraw->ID); |
1628 |
|
delete result; |
1629 |
|
delete row; |
1630 |
|
// |
1631 |
|
return(0); |
1632 |
} |
} |
1633 |
|
|
1634 |
|
|
1661 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1662 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1663 |
row = result->Next(); |
row = result->Next(); |
1664 |
|
if ( !row ) throw -92; |
1665 |
idresof = (UInt_t)atoll(row->GetField(0)); |
idresof = (UInt_t)atoll(row->GetField(0)); |
1666 |
existsts = true; |
existsts = true; |
1667 |
goto eout; |
goto eout; |
1683 |
if ( !row ){ |
if ( !row ){ |
1684 |
oss.str(""); |
oss.str(""); |
1685 |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1686 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< dworbit << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;"; |
1687 |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1688 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1689 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1941 |
* The raw file indicates in the parameters should be already been stored in the database. |
* The raw file indicates in the parameters should be already been stored in the database. |
1942 |
*/ |
*/ |
1943 |
Int_t PamelaDBOperations::insertPamelaRootFile(){ |
Int_t PamelaDBOperations::insertPamelaRootFile(){ |
1944 |
stringstream oss; |
|
1945 |
TSQLResult *result = 0; |
stringstream oss; |
1946 |
TSQLRow *row = 0; |
TSQLResult *result = 0; |
1947 |
UInt_t idtimesync = 0; |
TSQLRow *row = 0; |
|
// |
|
|
// |
|
|
if ( chewbacca ){ |
|
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
|
|
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -3; |
|
1948 |
// |
// |
1949 |
row = result->Next(); |
// ---------------------- |
1950 |
|
// determine the timesync |
1951 |
|
// ---------------------- |
1952 |
|
UInt_t idtimesync = 0; |
1953 |
// |
// |
1954 |
if ( !row ) throw -3; |
if ( chewbacca ){ |
1955 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
oss.str(""); |
1956 |
} else { |
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
1957 |
oss.str(""); |
if ( debug ) printf(" %s \n",oss.str().c_str()); |
1958 |
if ( STATIC ){ |
result = conn->Query(oss.str().c_str()); |
1959 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
// |
1960 |
<< " LEFT JOIN GL_ROOT " |
if ( !result ) throw -3; |
1961 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
// |
1962 |
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
row = result->Next(); |
1963 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
// |
1964 |
|
if ( !row ) throw -3; |
1965 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
1966 |
} else { |
} else { |
1967 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
oss.str(""); |
1968 |
<< " LEFT JOIN GL_ROOT " |
if ( STATIC ){ |
1969 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1970 |
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
<< " LEFT JOIN GL_ROOT " |
1971 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1972 |
|
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
1973 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1974 |
|
} else { |
1975 |
|
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1976 |
|
<< " LEFT JOIN GL_ROOT " |
1977 |
|
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1978 |
|
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
1979 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1980 |
|
}; |
1981 |
|
result = conn->Query(oss.str().c_str()); |
1982 |
|
// |
1983 |
|
if ( !result ) throw -12; |
1984 |
|
// |
1985 |
|
row = result->Next(); |
1986 |
|
// |
1987 |
|
if ( !row ) throw -10; |
1988 |
|
if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
1989 |
|
idroot = (UInt_t)atoll(row->GetField(2)); |
1990 |
|
delete row; |
1991 |
|
delete result; |
1992 |
|
return(1); |
1993 |
|
}; |
1994 |
|
// |
1995 |
|
// determine which timesync has to be used |
1996 |
|
// |
1997 |
|
oss.str(""); |
1998 |
|
oss << "SELECT GL_TIMESYNC.ID FROM GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW ORDER BY GL_TIMESYNC.ID DESC LIMIT 1;"; |
1999 |
|
result = conn->Query(oss.str().c_str()); |
2000 |
|
// |
2001 |
|
if ( !result ) throw -3; |
2002 |
|
// |
2003 |
|
row = result->Next(); |
2004 |
|
// |
2005 |
|
if ( !row ) throw -3; |
2006 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
2007 |
}; |
}; |
2008 |
result = conn->Query(oss.str().c_str()); |
|
2009 |
// |
delete row; |
2010 |
if ( !result ) throw -12; |
delete result; |
2011 |
// |
|
2012 |
row = result->Next(); |
// ---------------------- |
2013 |
// |
// insert root file |
2014 |
if ( !row ) throw -10; |
// ---------------------- |
2015 |
if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
|
2016 |
idroot = (UInt_t)atoll(row->GetField(2)); |
GL_ROOT glroot = GL_ROOT(); |
2017 |
return(1); |
|
2018 |
|
glroot.ID_RAW = GetID_RAW(); |
2019 |
|
glroot.ID_TIMESYNC = idtimesync; |
2020 |
|
if ( STATIC ){ |
2021 |
|
glroot.PATH = GetRootPath(); |
2022 |
|
} else { |
2023 |
|
if ( KEEPENV ){ |
2024 |
|
glroot.PATH = gSystem->DirName(filerootname.Data()); |
2025 |
|
} else { |
2026 |
|
glroot.PATH = "$PAM_L0"; |
2027 |
|
}; |
2028 |
}; |
}; |
2029 |
// |
glroot.NAME = GetRootFile(); |
2030 |
// determine which timesync has to be used |
|
2031 |
// |
if ( insertPamelaRootFile(&glroot) )return 1; |
2032 |
oss.str(""); |
|
2033 |
oss << "SELECT GL_TIMESYNC.ID FROM GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW ORDER BY GL_TIMESYNC.ID DESC LIMIT 1;"; |
SetID_ROOT(glroot.ID); |
2034 |
result = conn->Query(oss.str().c_str()); |
|
2035 |
// |
|
2036 |
if ( !result ) throw -3; |
return (0); |
2037 |
// |
} |
2038 |
row = result->Next(); |
/** |
2039 |
// |
* Insert all the new rows into GL_ROOT. |
2040 |
if ( !row ) throw -3; |
* The raw file indicates in the parameters should be already been stored in the database. |
2041 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
*/ |
2042 |
}; |
Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ |
2043 |
|
stringstream oss; |
2044 |
|
TSQLResult *result = 0; |
2045 |
|
TSQLRow *row = 0; |
2046 |
|
// |
2047 |
// |
// |
2048 |
oss.str(""); |
oss.str(""); |
2049 |
if ( STATIC ){ |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
2050 |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
<< glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')"; |
|
<< this->GetID_RAW() << "', '" << idtimesync << "', '" << this->GetRootPath().Data() << "', '" << this->GetRootFile().Data() << "')"; |
|
|
} else { |
|
|
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
|
|
<< this->GetID_RAW() << "', '" << idtimesync << "', '$PAM_L0', '" << this->GetRootFile().Data() << "')"; |
|
|
}; |
|
2051 |
// |
// |
2052 |
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
2053 |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
2054 |
// |
// |
2055 |
delete result; |
delete result; |
2056 |
// |
// |
2057 |
oss.str(""); |
oss.str(""); |
2058 |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
2059 |
if ( STATIC ){ |
oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';"; |
|
oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << this->GetRootPath().Data() << "' and NAME='"<< this->GetRootFile().Data() <<"';"; |
|
|
} else { |
|
|
oss << "SELECT ID FROM GL_ROOT WHERE PATH='$PAM_L0' and NAME='"<< this->GetRootFile().Data() <<"';"; |
|
|
}; |
|
2060 |
// |
// |
2061 |
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
2062 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
2063 |
if ( !result ) throw -12; |
if ( !result ) throw -12; |
2064 |
row = result->Next(); |
row = result->Next(); |
2065 |
if ( !row ) throw -3; |
if ( !row ) throw -3; |
2066 |
this->SetID_ROOT((UInt_t)atoll(row->GetField(0))); |
|
2067 |
if ( debug ) printf(" The ID of the ROOT file is %u \n",this->GetID_ROOT()); |
glroot->ID = (UInt_t)atoll(row->GetField(0)); |
2068 |
|
|
2069 |
|
if ( debug ) printf(" The ID of the ROOT file is %u \n",glroot->ID); |
2070 |
// |
// |
2071 |
delete result; |
delete result; |
2072 |
// |
// |
2324 |
ptht = cod->Get(pctp->RunHeader) - 1; |
ptht = cod->Get(pctp->RunHeader) - 1; |
2325 |
// evbeft = cod->Get(pctp->Physics); |
// evbeft = cod->Get(pctp->Physics); |
2326 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2327 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2328 |
evbeft = TMath::Min(upperentry,(tcod-1)); |
evbeft = TMath::Min(upperentry,(tcod-1)); |
2329 |
if ( debug ) printf(" Loop in runtrailers, evbeft is %u upperentry %u cod->getetc %u \n",evbeft,upperentry,cod->Get(pctp->Physics)); |
if ( debug ) printf(" Loop in runtrailers, evbeft is %u upperentry %u cod->getetc %u \n",evbeft,upperentry,cod->Get(pctp->Physics)); |
2330 |
// |
// |
2363 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2364 |
cod = ehh->GetCounter(); |
cod = ehh->GetCounter(); |
2365 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2366 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2367 |
evbefh = TMath::Max(chminentry,(tcod-1)); |
evbefh = TMath::Max(chminentry,(tcod-1)); |
2368 |
// |
// |
2369 |
if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){ |
if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){ |
2402 |
// |
// |
2403 |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
2404 |
// |
// |
2405 |
|
// what about pth=ptht-1 |
2406 |
}; |
}; |
2407 |
}; |
}; |
2408 |
// |
// |
2425 |
cod = ehh->GetCounter(); |
cod = ehh->GetCounter(); |
2426 |
// evbeft = cod->Get(pctp->Physics); |
// evbeft = cod->Get(pctp->Physics); |
2427 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2428 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2429 |
evbeft = TMath::Min(upperentry,(tcod-1)); |
evbeft = TMath::Min(upperentry,(tcod-1)); |
2430 |
rh->GetEntry(pth); |
rh->GetEntry(pth); |
2431 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2465 |
// if ( ptt+1 == rtev){ |
// if ( ptt+1 == rtev){ |
2466 |
if ( conptt+1 == nrtev ){ |
if ( conptt+1 == nrtev ){ |
2467 |
// if ( conptt+1 == (nrtev+nrtbef )){ |
// if ( conptt+1 == (nrtev+nrtbef )){ |
2468 |
|
if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); |
2469 |
ptht++; |
ptht++; |
2470 |
if ( ptht < rhev ){ |
if ( ptht < rhev ){ |
2471 |
rh->GetEntry(ptht); |
rh->GetEntry(ptht); |
2472 |
|
//pth++; |
2473 |
|
//if ( pth < rhev ){ |
2474 |
|
//rh->GetEntry(pth); |
2475 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2476 |
pkth = phh->GetCounter(); |
pkth = phh->GetCounter(); |
2477 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2495 |
if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){ |
if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){ |
2496 |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1); |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1); |
2497 |
// |
// |
2498 |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
// if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
2499 |
rt->GetEntry(ptt-1); |
if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here! |
2500 |
|
// rt->GetEntry(ptt-1); |
2501 |
|
rt->GetEntry(rtev-1); |
2502 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
2503 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics)+1; |
2504 |
evbefh = TMath::Max(chminentry,tcod); |
evbefh = TMath::Max(chminentry,tcod); |
2505 |
// evbefh = cod->Get(pctp->Physics); |
// evbefh = cod->Get(pctp->Physics); |
2506 |
rt->GetEntry(ptt); |
rt->GetEntry(ptt); |
2731 |
// |
// |
2732 |
// we have now the good first piece of a run, fill the glrun object |
// we have now the good first piece of a run, fill the glrun object |
2733 |
// |
// |
2734 |
if ( rhfirstev != firstev && !mishead ) mishead = true; |
if ( firstev != (lastev+1) ){ // could be a problem sometimes (?) |
2735 |
if ( rtlastev != lastev && !mistrail ) mistrail = true; |
if ( rhfirstev != firstev && !mishead ) mishead = true; |
2736 |
|
if ( rtlastev != lastev && !mistrail ) mistrail = true; |
2737 |
|
}; |
2738 |
// |
// |
2739 |
|
if ( IsDebug() ) printf(" bhere firstev is %i lastev is %i \n",firstev,lastev); |
2740 |
this->FillClass(mishead,mistrail,firstev,lastev); |
this->FillClass(mishead,mistrail,firstev,lastev); |
2741 |
|
if ( IsDebug() ) printf(" chere firstev is %i lastev is %i \n",firstev,lastev); |
2742 |
// |
// |
2743 |
if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); |
if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); |
2744 |
if ( IsDebug() ) printf(" C THIS RUN: RUNHEADER_OBT %u RUNTRAILER_OBT %u RUNHEADER_PKT %u RUNTRAILER_PKT %u \n", glrun->GetRUNHEADER_OBT(),glrun->GetRUNTRAILER_OBT(),glrun->GetRUNHEADER_PKT(),glrun->GetRUNTRAILER_PKT()); |
if ( IsDebug() ) printf(" C THIS RUN: RUNHEADER_OBT %u RUNTRAILER_OBT %u RUNHEADER_PKT %u RUNTRAILER_PKT %u \n", glrun->GetRUNHEADER_OBT(),glrun->GetRUNTRAILER_OBT(),glrun->GetRUNHEADER_PKT(),glrun->GetRUNTRAILER_PKT()); |
2780 |
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
2781 |
// |
// |
2782 |
} else { |
} else { |
2783 |
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
if ( IsDebug() ) printf(" The run is already present in the fragment table, relaxed %u \n",RELAXED); |
2784 |
if ( PEDANTIC ) throw -69; |
if ( !RELAXED ){ |
2785 |
return; |
if ( PEDANTIC ) throw -69; |
2786 |
|
return; |
2787 |
|
} else { |
2788 |
|
glrun->SetID((UInt_t)atoll(row->GetField(0))); |
2789 |
|
glrun->SetID_RUN_FRAG(0); |
2790 |
|
}; |
2791 |
}; |
}; |
2792 |
// |
// |
2793 |
if ( chewbacca && mishead && mistrail ) goto justcheck; |
if ( chewbacca && mishead && mistrail ) goto justcheck; |
2838 |
// |
// |
2839 |
found = false; // default value |
found = false; // default value |
2840 |
// |
// |
2841 |
if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); |
if ( IsDebug() ) printf(" A Found a possible candidate, checking if it is the good one... \n"); |
2842 |
// |
// |
2843 |
// if we have both runheader and runtrailer we can check with pkt_counter: |
// if we have both runheader and runtrailer we can check with pkt_counter: |
2844 |
// |
// |
2854 |
if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); |
if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); |
2855 |
// |
// |
2856 |
found = true; |
found = true; |
2857 |
|
if ( IsDebug() ) printf(" where firstev is %i lastev is %i \n",firstev,lastev); |
2858 |
// |
// |
2859 |
} else { |
} else { |
2860 |
// |
// |
2920 |
oss << " ID="<<row->GetField(0)<<";"; |
oss << " ID="<<row->GetField(0)<<";"; |
2921 |
// |
// |
2922 |
glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos |
glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos |
2923 |
|
if ( IsDebug() ) printf(" there firstev is %i lastev is %i \n",firstev,lastev); |
2924 |
// |
// |
2925 |
// merge infos |
// merge infos |
2926 |
// |
// |
2951 |
glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); |
glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); |
2952 |
glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); |
glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); |
2953 |
// |
// |
2954 |
|
if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev); |
2955 |
|
// |
2956 |
glrun->SetEV_FROM(firstev); |
glrun->SetEV_FROM(firstev); |
2957 |
glrun->SetNEVENTS(lastev-firstev+1); |
glrun->SetNEVENTS(lastev-firstev+1); |
2958 |
// |
// |
3045 |
// |
// |
3046 |
found = false; // default value |
found = false; // default value |
3047 |
// |
// |
3048 |
if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); |
if ( IsDebug() ) printf(" B Found a possible candidate, checking if it is the good one... \n"); |
3049 |
// |
// |
3050 |
// if we have both runheader and runtrailer we can check with pkt_counter: |
// if we have both runheader and runtrailer we can check with pkt_counter: |
3051 |
// |
// |
3145 |
apkt = PKT(ph->GetCounter()); |
apkt = PKT(ph->GetCounter()); |
3146 |
aobt = OBT(ph->GetOrbitalTime()); |
aobt = OBT(ph->GetOrbitalTime()); |
3147 |
lastev--; |
lastev--; |
3148 |
if ( PEDANTIC ) throw -72; |
if ( PEDANTIC && !RELAXED) throw -72; |
3149 |
}; |
}; |
3150 |
if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); |
if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); |
3151 |
// |
// |
3213 |
// not found, has this run already inserted in the GL_RUN or in the GL_RUN_FRAGMENTS table? |
// not found, has this run already inserted in the GL_RUN or in the GL_RUN_FRAGMENTS table? |
3214 |
// |
// |
3215 |
oss.str(""); |
oss.str(""); |
3216 |
oss << " SELECT ID FROM GL_RUN WHERE " |
oss << " SELECT ID,ID_ROOT_L0 FROM GL_RUN WHERE " |
3217 |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" |
3218 |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
3219 |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
3236 |
row = result->Next(); |
row = result->Next(); |
3237 |
// |
// |
3238 |
if ( row ){ |
if ( row ){ |
3239 |
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
// |
3240 |
if ( PEDANTIC ) throw -70; |
// we end up here if chewbacca and we have RH---| small gap |---RT, in this case the two pieces are attached and moved to GL_RUN. We are now processing the |
3241 |
|
// "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number. |
3242 |
|
// |
3243 |
|
// 090112 [8RED (-70): RUN ALREADY INSERTED] |
3244 |
|
// |
3245 |
|
Bool_t OK = false; |
3246 |
|
UInt_t IDRL2A = 0; |
3247 |
|
UInt_t IDRL2B = 0; |
3248 |
|
if ( chewbacca ){ |
3249 |
|
if ( result->GetRowCount() == 2 ){ |
3250 |
|
IDRL2A = (UInt_t)atoll(row->GetField(0)); |
3251 |
|
UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1)); |
3252 |
|
row = result->Next(); |
3253 |
|
IDRL2B = (UInt_t)atoll(row->GetField(0)); |
3254 |
|
UInt_t IDRL0B = (UInt_t)atoll(row->GetField(1)); |
3255 |
|
if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B); |
3256 |
|
if ( IDRL0A == IDRL0B ){ |
3257 |
|
TSQLResult *result2 = 0; |
3258 |
|
TSQLRow *row2 = 0; |
3259 |
|
oss.str(""); |
3260 |
|
oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;"; |
3261 |
|
if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
3262 |
|
result2 = conn->Query(oss.str().c_str()); |
3263 |
|
// |
3264 |
|
if ( !result2 ) throw -4; |
3265 |
|
// |
3266 |
|
row2 = result2->Next(); |
3267 |
|
// |
3268 |
|
if ( row2 ){ |
3269 |
|
UInt_t PKA = (UInt_t)atoll(row2->GetField(0)); |
3270 |
|
delete result2; |
3271 |
|
oss.str(""); |
3272 |
|
oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;"; |
3273 |
|
if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
3274 |
|
result2 = conn->Query(oss.str().c_str()); |
3275 |
|
// |
3276 |
|
if ( !result2 ) throw -4; |
3277 |
|
// |
3278 |
|
row2 = result2->Next(); |
3279 |
|
// |
3280 |
|
if ( row2 ){ |
3281 |
|
UInt_t PKB = (UInt_t)atoll(row2->GetField(0)); |
3282 |
|
// |
3283 |
|
if ( IsDebug() ) printf(" PKT(PKA) + 1 %llu == runheaderpkt %llu && PKB = runtrailer %llu + 1 %llu \n",PKT(PKA)+1LL, PKT(glrun->GetRUNHEADER_PKT()),PKT(PKB), PKT(glrun->GetRUNTRAILER_PKT())+1LL); |
3284 |
|
if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){ |
3285 |
|
if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); |
3286 |
|
OK = true; |
3287 |
|
}; |
3288 |
|
}; |
3289 |
|
}; |
3290 |
|
}; |
3291 |
|
}; |
3292 |
|
}; |
3293 |
|
if ( OK ){ |
3294 |
|
// |
3295 |
|
// this is the case in which we must insert a piece of run between two fragments in the GL_RUN table |
3296 |
|
// |
3297 |
|
// we have to update with runheader/trailer infos our run and we have to change the ROOT_ID_FRAG of the header piece ( 1/2 2/1 must become 1/3 3/2 2/1 ) |
3298 |
|
// |
3299 |
|
GL_RUN *glA = new GL_RUN(); |
3300 |
|
glA->Query_GL_RUN(IDRL2A,conn); |
3301 |
|
// |
3302 |
|
if ( glA->GetACQ_BUILD_INFO() != 0 ){ |
3303 |
|
// |
3304 |
|
// the first piece contains a good runheader we can update all the other runs with correct infos! |
3305 |
|
// |
3306 |
|
oss.str(""); |
3307 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3308 |
|
<< " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , " |
3309 |
|
<< " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
3310 |
|
<< " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , " |
3311 |
|
<< " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , " |
3312 |
|
<< " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , " |
3313 |
|
<< " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , " |
3314 |
|
<< " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , " |
3315 |
|
<< " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , " |
3316 |
|
<< " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , " |
3317 |
|
<< " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , " |
3318 |
|
<< " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , " |
3319 |
|
<< " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , " |
3320 |
|
<< " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , " |
3321 |
|
<< " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , " |
3322 |
|
<< " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , "; |
3323 |
|
// |
3324 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
3325 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , "; |
3326 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
3327 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , "; |
3328 |
|
// |
3329 |
|
oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC(); |
3330 |
|
oss << " WHERE ID=" << glrun->GetID() << ";"; |
3331 |
|
if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str()); |
3332 |
|
conn->Query(oss.str().c_str()); |
3333 |
|
// |
3334 |
|
} else { |
3335 |
|
// |
3336 |
|
// sig no runheader, let set anyway what is possible... |
3337 |
|
// |
3338 |
|
oss.str(""); |
3339 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3340 |
|
<< " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "; |
3341 |
|
// |
3342 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
3343 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; |
3344 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
3345 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
3346 |
|
// |
3347 |
|
oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
3348 |
|
<< " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT(); |
3349 |
|
oss << " WHERE ID=" << glrun->GetID() << ";"; |
3350 |
|
if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str()); |
3351 |
|
conn->Query(oss.str().c_str()); |
3352 |
|
}; |
3353 |
|
// |
3354 |
|
// update runheader ROOT_ID_FRAG |
3355 |
|
// |
3356 |
|
oss.str(""); |
3357 |
|
oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; |
3358 |
|
if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
3359 |
|
conn->Query(oss.str().c_str()); |
3360 |
|
// |
3361 |
|
// now let's look for runtrailer if any in the last run |
3362 |
|
// |
3363 |
|
glA->Query_GL_RUN(IDRL2B,conn); |
3364 |
|
// |
3365 |
|
if ( glA->GetPKT_READY_COUNTER() != 0 ){ |
3366 |
|
// |
3367 |
|
// the first piece contains a good runtrailer we can update all the other runs with correct infos! |
3368 |
|
// |
3369 |
|
oss.str(""); |
3370 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3371 |
|
<< " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
3372 |
|
<< " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , " |
3373 |
|
<< " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , " |
3374 |
|
<< " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , "; |
3375 |
|
// |
3376 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
3377 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
3378 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) { |
3379 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
3380 |
|
// |
3381 |
|
oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER() |
3382 |
|
<< " WHERE ID=" << glrun->GetID() << ";"; |
3383 |
|
if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str()); |
3384 |
|
conn->Query(oss.str().c_str()); |
3385 |
|
// |
3386 |
|
} else { |
3387 |
|
// |
3388 |
|
// sig no runtrailer, let set anyway what is possible... |
3389 |
|
// |
3390 |
|
oss.str(""); |
3391 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3392 |
|
<< " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
3393 |
|
<< " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "; |
3394 |
|
// |
3395 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
3396 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
3397 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){ |
3398 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
3399 |
|
// |
3400 |
|
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT() |
3401 |
|
<< " WHERE ID=" << glrun->GetID() << ";"; |
3402 |
|
if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str()); |
3403 |
|
conn->Query(oss.str().c_str()); |
3404 |
|
}; |
3405 |
|
// |
3406 |
|
UInt_t myi = glrun->GetID(); |
3407 |
|
oss.str(""); |
3408 |
|
oss << " ID= "<< myi; |
3409 |
|
// |
3410 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
3411 |
|
// |
3412 |
|
// fill the new run in GL_RUN |
3413 |
|
// |
3414 |
|
glrun->SetID_RUN_FRAG(IDRL2B); |
3415 |
|
glrun->Fill_GL_RUN(conn); |
3416 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
3417 |
|
delete glA; |
3418 |
|
// |
3419 |
|
} else { |
3420 |
|
// |
3421 |
|
// is just a repetition |
3422 |
|
// |
3423 |
|
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
3424 |
|
if ( PEDANTIC ) throw -70; |
3425 |
|
}; |
3426 |
|
// |
3427 |
} else { |
} else { |
3428 |
if ( NoFrag() ){ |
if ( NoFrag() ){ |
3429 |
glrun->SetID_RUN_FRAG(glrun->GetID()); |
glrun->SetID_RUN_FRAG(glrun->GetID()); |
3460 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
3461 |
glrun->SetID_RUN_FRAG(0); |
glrun->SetID_RUN_FRAG(0); |
3462 |
glrun->Fill_GL_RUN(conn); // it'ok we arrive here only inside a file hence in the middle of the runs... |
glrun->Fill_GL_RUN(conn); // it'ok we arrive here only inside a file hence in the middle of the runs... |
3463 |
}; |
}; |
3464 |
// |
// |
3465 |
}; |
}; |
3466 |
// |
// |
3504 |
if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! |
if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! |
3505 |
//if ( firstev <= lastev+1 ) { // no events inside the run! |
//if ( firstev <= lastev+1 ) { // no events inside the run! |
3506 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
3507 |
|
firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files |
3508 |
// return true is correct |
// return true is correct |
3509 |
return(true); |
return(true); |
3510 |
// |
// |
3534 |
// |
// |
3535 |
} else { |
} else { |
3536 |
// |
// |
3537 |
if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n"); |
if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n"); |
3538 |
// |
// |
3539 |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
3540 |
// |
// |
3544 |
UInt_t check = 0; |
UInt_t check = 0; |
3545 |
UInt_t lastevtemp = lastev; |
UInt_t lastevtemp = lastev; |
3546 |
UInt_t firstevno = firstev; |
UInt_t firstevno = firstev; |
3547 |
|
UInt_t rhchko=0; |
3548 |
|
UInt_t rhchk=0; |
3549 |
// |
// |
3550 |
for (UInt_t i=firstev; i<=lastev; i++){ |
for (UInt_t i=firstev; i<=lastev; i++){ |
3551 |
// |
// |
3554 |
// |
// |
3555 |
check = 0; |
check = 0; |
3556 |
// |
// |
3557 |
|
|
3558 |
|
// if we have a runheader set lastev then exit |
3559 |
|
// |
3560 |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
3561 |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
3562 |
}; |
}; |
3563 |
|
// check here if we have a runheader |
3564 |
|
rhchko = rhchk; |
3565 |
|
rhchk = code->Get(GetPacketType("RunHeader")); |
3566 |
// |
// |
3567 |
if ( checkfirst < check || i == lastev ){ |
if ( checkfirst < check || i == lastev ){ |
3568 |
// |
// |
3646 |
// this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments |
// this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments |
3647 |
// |
// |
3648 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3649 |
mishead = true; |
mishead = true; |
3650 |
|
|
3651 |
|
|
3760 |
// |
// |
3761 |
found = false; // default value |
found = false; // default value |
3762 |
// |
// |
3763 |
if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); |
if ( IsDebug() ) printf(" C Found a possible candidate, checking if it is the good one... \n"); |
3764 |
// |
// |
3765 |
// if we have both runheader and runtrailer we can check with pkt_counter: |
// if we have both runheader and runtrailer we can check with pkt_counter: |
3766 |
// |
// |
3965 |
}; // EEE |
}; // EEE |
3966 |
|
|
3967 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3968 |
} else { |
} else { |
3969 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
3970 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
3979 |
// |
// |
3980 |
}; |
}; |
3981 |
// |
// |
3982 |
|
if ( i > firstev ){ |
3983 |
|
if ( rhchko != rhchk ){ |
3984 |
|
if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n"); |
3985 |
|
lastev = i; |
3986 |
|
return(false); |
3987 |
|
}; |
3988 |
|
}; |
3989 |
|
// |
3990 |
if ( check == checklast && i != lastev ){ |
if ( check == checklast && i != lastev ){ |
3991 |
lastevtemp = i - 1; |
lastevtemp = i - 1; |
3992 |
i = lastev - 1; |
i = lastev - 1; |
4278 |
UInt_t totime = 0; |
UInt_t totime = 0; |
4279 |
UInt_t obt = 0; |
UInt_t obt = 0; |
4280 |
UInt_t pkt = 0; |
UInt_t pkt = 0; |
4281 |
|
Float_t totped = 0.; |
4282 |
// |
// |
4283 |
tr = (TTree*)file->Get("CalibCalPed"); |
tr = (TTree*)file->Get("CalibCalPed"); |
4284 |
if ( !tr || tr->IsZombie() ) throw -21; |
if ( !tr || tr->IsZombie() ) throw -21; |
4296 |
if ( calibCalPed->cstwerr[section] ){ |
if ( calibCalPed->cstwerr[section] ){ |
4297 |
valid = 1; |
valid = 1; |
4298 |
if ( calibCalPed->cperror[section] ) valid = 0; |
if ( calibCalPed->cperror[section] ) valid = 0; |
4299 |
|
// |
4300 |
|
// check pedestal values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.] |
4301 |
|
// |
4302 |
|
totped = 0.; |
4303 |
|
Int_t ns = 0; |
4304 |
|
if ( section == 2 ) ns = 3; |
4305 |
|
if ( section == 3 ) ns = 1; |
4306 |
|
if ( section == 1 ) ns = 2; |
4307 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4308 |
|
totped += fabs(calibCalPed->calped[ns][0][ss]); |
4309 |
|
} |
4310 |
|
if ( totped < 1. ){ |
4311 |
|
if ( IsDebug() ) printf(" Section %i totped %f - No calibration data! Calorimeter power problems? \n",section,totped); |
4312 |
|
valid = 0; |
4313 |
|
}; |
4314 |
|
// |
4315 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
4316 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
4317 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
4479 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
4480 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
4481 |
// |
// |
4482 |
|
Float_t totpul = 0.; |
4483 |
|
// |
4484 |
if ( nevents > 0 ){ |
if ( nevents > 0 ){ |
4485 |
// |
// |
4486 |
for (UInt_t i=0; i < nevents; i++){ |
for (UInt_t i=0; i < nevents; i++){ |
4490 |
if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){ |
if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){ |
4491 |
valid = 1; |
valid = 1; |
4492 |
if ( cp1->pperror[section] ) valid = 0; |
if ( cp1->pperror[section] ) valid = 0; |
4493 |
|
// |
4494 |
|
// check pulse values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.] |
4495 |
|
// |
4496 |
|
totpul = 0.; |
4497 |
|
Int_t ns = 0; |
4498 |
|
if ( section == 2 ) ns = 3; |
4499 |
|
if ( section == 3 ) ns = 1; |
4500 |
|
if ( section == 1 ) ns = 2; |
4501 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4502 |
|
totpul += cp1->calpuls[ns][0][ss]; |
4503 |
|
} |
4504 |
|
if ( totpul >= 3145632. ){ |
4505 |
|
if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f - No calibration data! Calorimeter power problems? \n",section,totpul); |
4506 |
|
valid = 0; |
4507 |
|
}; |
4508 |
|
// |
4509 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
4510 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
4511 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
4663 |
if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){ |
if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){ |
4664 |
valid = 1; |
valid = 1; |
4665 |
if ( cp2->pperror[section] ) valid = 0; |
if ( cp2->pperror[section] ) valid = 0; |
4666 |
|
// |
4667 |
|
// check pulse values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.] |
4668 |
|
// |
4669 |
|
totpul = 0.; |
4670 |
|
Int_t ns = 0; |
4671 |
|
if ( section == 2 ) ns = 3; |
4672 |
|
if ( section == 3 ) ns = 1; |
4673 |
|
if ( section == 1 ) ns = 2; |
4674 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4675 |
|
totpul += cp2->calpuls[ns][0][ss]; |
4676 |
|
} |
4677 |
|
if ( totpul >= 3145632. ){ |
4678 |
|
if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f - No calibration data! Calorimeter power problems? \n",section,totpul); |
4679 |
|
valid = 0; |
4680 |
|
}; |
4681 |
|
// |
4682 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
4683 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
4684 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
4858 |
* Fill the GL_TRK_CALIB table |
* Fill the GL_TRK_CALIB table |
4859 |
*/ |
*/ |
4860 |
void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
4861 |
// |
|
4862 |
TSQLResult *result = 0; |
GL_TRK_CALIB *glcal = new GL_TRK_CALIB(); |
|
TSQLRow *row = 0; |
|
|
// |
|
|
stringstream oss; |
|
|
oss.str(""); |
|
|
// |
|
|
UInt_t totime = 0; |
|
|
// |
|
|
if ( !pk1 && !pk2 ){ |
|
|
if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n"); |
|
|
return; |
|
|
}; |
|
|
// |
|
|
// check if the calibration has already been inserted |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_TRK_CALIB WHERE " |
|
|
<< " BOOT_NUMBER = "<< this->GetBOOTnumber(); // |
|
|
oss << " AND ( ( "; |
|
|
if ( pk1 ){ |
|
|
oss << " OBT1 = "<< obt1 << " AND " |
|
|
<< " PKT1 = "<< pkt1 |
|
|
<< " ) OR ( "; |
|
|
} else { |
|
|
oss << " PKT1 = "<< pkt2-1 |
|
|
<< " ) OR ( "; |
|
|
}; |
|
|
if ( pk2 ){ |
|
|
oss << " OBT2 = "<< obt2 << " AND " |
|
|
<< " PKT2 = "<< pkt2; |
|
|
} else { |
|
|
oss << " PKT2 = "<< pkt1+1; |
|
|
}; |
|
|
oss << " ) );"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Check if the trk calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -4; |
|
|
// |
|
|
row = result->Next(); |
|
|
// |
|
|
if ( row ){ |
|
|
// |
|
|
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
|
|
if ( PEDANTIC ) throw -80; |
|
4863 |
// |
// |
4864 |
} else { |
glcal->ID = 0; |
4865 |
|
glcal->ID_ROOT_L0 = GetID_ROOT(); |
4866 |
|
glcal->EV_ROOT_CALIBTRK1 = t1; |
4867 |
|
glcal->EV_ROOT_CALIBTRK2 = t2; |
4868 |
|
glcal->FROM_TIME = fromtime; |
4869 |
|
glcal->TO_TIME = 0; |
4870 |
|
glcal->OBT1 = obt1; |
4871 |
|
glcal->OBT2 = obt2; |
4872 |
|
glcal->PKT1 = pkt1; |
4873 |
|
glcal->PKT2 = pkt2; |
4874 |
|
glcal->BOOT_NUMBER = GetBOOTnumber(); |
4875 |
|
glcal->VALIDATION = valid; |
4876 |
// |
// |
4877 |
// we have to insert a new calibration, check where to place it |
HandleTRK_CALIB(glcal); |
4878 |
// |
// |
4879 |
oss.str(""); |
delete glcal; |
4880 |
oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
} |
4881 |
<< " FROM_TIME < "<< fromtime << " AND " |
/** |
4882 |
<< " TO_TIME > "<< fromtime << ";"; |
* Fill the GL_TRK_CALIB table |
4883 |
|
*/ |
4884 |
|
void PamelaDBOperations::HandleTRK_CALIB(GL_TRK_CALIB *glcal){ |
4885 |
|
|
4886 |
|
Bool_t pk1 = (glcal->OBT1>0&&glcal->PKT1>0); |
4887 |
|
Bool_t pk2 = (glcal->OBT2>0&&glcal->PKT2>0); |
4888 |
|
UInt_t boot_number = glcal->BOOT_NUMBER; |
4889 |
|
UInt_t obt1 = glcal->OBT1; |
4890 |
|
UInt_t obt2 = glcal->OBT2; |
4891 |
|
UInt_t pkt1 = glcal->PKT1; |
4892 |
|
UInt_t pkt2 = glcal->PKT2; |
4893 |
|
UInt_t fromtime = glcal->FROM_TIME; |
4894 |
|
UInt_t totime = 0; |
4895 |
|
UInt_t idroot = glcal->ID_ROOT_L0; |
4896 |
|
UInt_t t1 = glcal->EV_ROOT_CALIBTRK1; |
4897 |
|
UInt_t t2 = glcal->EV_ROOT_CALIBTRK2; |
4898 |
|
UInt_t valid = glcal->VALIDATION; |
4899 |
// |
// |
4900 |
if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str()); |
TSQLResult *result = 0; |
4901 |
result = conn->Query(oss.str().c_str()); |
TSQLRow *row = 0; |
4902 |
// |
// |
4903 |
if ( !result ) throw -4; |
stringstream oss; |
4904 |
|
oss.str(""); |
4905 |
// |
// |
|
row = result->Next(); |
|
4906 |
// |
// |
4907 |
if ( !row ){ |
if ( !pk1 && !pk2 ){ |
4908 |
// |
if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n"); |
4909 |
// no calibrations in the db contain our calibration |
return; |
|
// |
|
|
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); |
|
|
if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " |
|
|
<< " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Check the upper limit for calibration: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -4; |
|
|
// |
|
|
row = result->Next(); |
|
|
if ( !row ){ |
|
|
totime = numeric_limits<UInt_t>::max(); |
|
|
} else { |
|
|
totime = (UInt_t)atoll(row->GetField(0)); |
|
|
}; |
|
|
// |
|
|
} else { |
|
|
// |
|
|
// determine upper and lower limits and make space for the new calibration |
|
|
// |
|
|
totime = (UInt_t)atoll(row->GetField(1)); |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " UPDATE GL_TRK_CALIB SET " |
|
|
<< " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ |
|
|
<< " ID = "<< row->GetField(0) << ";"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Make space for the new trk calibration: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -4; |
|
|
// |
|
4910 |
}; |
}; |
4911 |
// |
// |
4912 |
oss.str(""); |
// check if the calibration has already been inserted |
|
oss << " INSERT INTO GL_TRK_CALIB (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) " |
|
|
<< " VALUES (NULL,' " |
|
|
<< idroot << "',"; |
|
4913 |
// |
// |
4914 |
if ( !pk1 ){ |
oss.str(""); |
4915 |
oss << "NULL,"; |
oss << " SELECT ID FROM GL_TRK_CALIB WHERE " |
4916 |
|
<< " BOOT_NUMBER = "<< boot_number; // |
4917 |
|
oss << " AND FROM_TIME="<<fromtime; /// NEWNEWNEW -- VA BENE ?!?!?!?! |
4918 |
|
oss << " AND ( ( "; |
4919 |
|
if ( pk1 ){ |
4920 |
|
oss << " OBT1 = "<< obt1 << " AND " |
4921 |
|
<< " PKT1 = "<< pkt1 |
4922 |
|
<< " ) OR ( "; |
4923 |
} else { |
} else { |
4924 |
oss << "'" |
oss << " PKT1 = "<< pkt2-1 |
4925 |
<< t1 << "',"; |
<< " ) OR ( "; |
4926 |
}; |
}; |
4927 |
// |
if ( pk2 ){ |
4928 |
if ( !pk2 ){ |
oss << " OBT2 = "<< obt2 << " AND " |
4929 |
oss << "NULL,'"; |
<< " PKT2 = "<< pkt2; |
4930 |
} else { |
} else { |
4931 |
oss << "'" |
oss << " PKT2 = "<< pkt1+1; |
4932 |
<< t2 << "','"; |
}; |
4933 |
}; |
oss << " ) );"; |
4934 |
// |
// |
4935 |
oss << fromtime << "','" |
if ( IsDebug() ) printf(" Check if the trk calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
4936 |
<< totime << "','" |
result = conn->Query(oss.str().c_str()); |
4937 |
<< obt1 << "','" |
// |
4938 |
<< pkt1 << "','" |
if ( !result ) throw -4; |
|
<< obt2 << "','" |
|
|
<< pkt2 << "','" |
|
|
<< this->GetBOOTnumber() << "','" |
|
|
<< valid << "');"; |
|
4939 |
// |
// |
4940 |
if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); |
row = result->Next(); |
4941 |
// |
// |
4942 |
|
if ( row ){ |
4943 |
|
// |
4944 |
|
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
4945 |
|
if ( PEDANTIC ) throw -80; |
4946 |
|
// |
4947 |
|
} else { |
4948 |
|
// |
4949 |
|
// we have to insert a new calibration, check where to place it |
4950 |
|
// |
4951 |
|
oss.str(""); |
4952 |
|
oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
4953 |
|
<< " FROM_TIME < "<< fromtime << " AND " |
4954 |
|
<< " TO_TIME > "<< fromtime << ";"; |
4955 |
|
// |
4956 |
|
if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str()); |
4957 |
|
result = conn->Query(oss.str().c_str()); |
4958 |
|
// |
4959 |
|
if ( !result ) throw -4; |
4960 |
|
// |
4961 |
|
row = result->Next(); |
4962 |
|
// |
4963 |
|
if ( !row ){ |
4964 |
|
// |
4965 |
|
// no calibrations in the db contain our calibration |
4966 |
|
// |
4967 |
|
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); |
4968 |
|
if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode |
4969 |
|
// |
4970 |
|
oss.str(""); |
4971 |
|
oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " |
4972 |
|
<< " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
4973 |
|
// |
4974 |
|
if ( IsDebug() ) printf(" Check the upper limit for calibration: query is \n %s \n",oss.str().c_str()); |
4975 |
|
result = conn->Query(oss.str().c_str()); |
4976 |
|
// |
4977 |
|
if ( !result ) throw -4; |
4978 |
|
// |
4979 |
|
row = result->Next(); |
4980 |
|
if ( !row ){ |
4981 |
|
totime = numeric_limits<UInt_t>::max(); |
4982 |
|
} else { |
4983 |
|
totime = (UInt_t)atoll(row->GetField(0)); |
4984 |
|
}; |
4985 |
|
// |
4986 |
|
} else { |
4987 |
|
// |
4988 |
|
// determine upper and lower limits and make space for the new calibration |
4989 |
|
// |
4990 |
|
totime = (UInt_t)atoll(row->GetField(1)); |
4991 |
|
// |
4992 |
|
oss.str(""); |
4993 |
|
oss << " UPDATE GL_TRK_CALIB SET " |
4994 |
|
<< " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ |
4995 |
|
<< " ID = "<< row->GetField(0) << ";"; |
4996 |
|
// |
4997 |
|
if ( IsDebug() ) printf(" Make space for the new trk calibration: query is \n %s \n",oss.str().c_str()); |
4998 |
|
result = conn->Query(oss.str().c_str()); |
4999 |
|
// |
5000 |
|
if ( !result ) throw -4; |
5001 |
|
// |
5002 |
|
}; |
5003 |
|
// |
5004 |
|
oss.str(""); |
5005 |
|
oss << " INSERT INTO GL_TRK_CALIB (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) " |
5006 |
|
<< " VALUES (NULL,' " |
5007 |
|
<< idroot << "',"; |
5008 |
|
// |
5009 |
|
if ( !pk1 ){ |
5010 |
|
oss << "NULL,"; |
5011 |
|
} else { |
5012 |
|
oss << "'" |
5013 |
|
<< t1 << "',"; |
5014 |
|
}; |
5015 |
|
// |
5016 |
|
if ( !pk2 ){ |
5017 |
|
oss << "NULL,'"; |
5018 |
|
} else { |
5019 |
|
oss << "'" |
5020 |
|
<< t2 << "','"; |
5021 |
|
}; |
5022 |
|
// |
5023 |
|
oss << fromtime << "','" |
5024 |
|
<< totime << "','" |
5025 |
|
<< obt1 << "','" |
5026 |
|
<< pkt1 << "','" |
5027 |
|
<< obt2 << "','" |
5028 |
|
<< pkt2 << "','" |
5029 |
|
<< boot_number << "','" |
5030 |
|
<< valid << "');"; |
5031 |
|
// |
5032 |
|
if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); |
5033 |
|
// |
5034 |
|
result = conn->Query(oss.str().c_str()); |
5035 |
|
// |
5036 |
|
if ( !result ) throw -4; |
5037 |
|
// |
5038 |
|
}; |
5039 |
|
|
5040 |
|
oss.str(""); |
5041 |
|
oss << " SELECT ID FROM GL_TRK_CALIB ORDER BY ID DESC LIMIT 1 ;"; |
5042 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5043 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
5044 |
|
if ( !result ) throw -4;; |
5045 |
|
row = result->Next(); |
5046 |
|
if(row)glcal->ID = (UInt_t)atoll(row->GetField(0)); |
5047 |
// |
// |
5048 |
if ( !result ) throw -4; |
delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5049 |
// |
// |
|
}; |
|
|
// |
|
5050 |
}; |
}; |
5051 |
|
|
5052 |
/** |
/** |
5053 |
* Scan tracker calibrations packets, fill the GL_TRK_CALIB table |
* Scan tracker calibrations packets, fill the GL_TRK_CALIB table |
5054 |
*/ |
*/ |
5055 |
Int_t PamelaDBOperations::insertTRK_CALIB(){ |
Int_t PamelaDBOperations::insertTRK_CALIB(){ |
|
// |
|
|
CalibTrk1Event *caltrk1 = 0; |
|
|
CalibTrk2Event *caltrk2 = 0; |
|
|
TTree *tr1 = 0; |
|
|
TTree *tr2 = 0; |
|
|
EventHeader *eh1 = 0; |
|
|
PscuHeader *ph1 = 0; |
|
|
EventHeader *eh2 = 0; |
|
|
PscuHeader *ph2 = 0; |
|
|
// |
|
|
PacketType *pctp=0; |
|
|
EventCounter *codt2=0; |
|
|
// |
|
|
Int_t nevents1 = 0; |
|
|
Int_t nevents2 = 0; |
|
|
// |
|
|
fromtime = 0; |
|
|
// |
|
|
obt1 = 0; |
|
|
pkt1 = 0; |
|
|
obt2 = 0; |
|
|
pkt2 = 0; |
|
|
// |
|
|
tr1 = (TTree*)file->Get("CalibTrk1"); |
|
|
if ( !tr1 || tr1->IsZombie() ) throw -22; |
|
|
tr2 = (TTree*)file->Get("CalibTrk2"); |
|
|
if ( !tr2 || tr2->IsZombie() ) throw -23; |
|
|
// |
|
|
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
|
|
tr1->SetBranchAddress("Header", &eh1); |
|
|
nevents1 = tr1->GetEntries(); |
|
|
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
|
|
tr2->SetBranchAddress("Header", &eh2); |
|
|
nevents2 = tr2->GetEntries(); |
|
|
// |
|
|
if ( !nevents1 && !nevents2 ) return(1); |
|
|
// |
|
|
t2 = -1; |
|
|
Int_t pret2 = 0; |
|
|
Int_t t2t1cal = 0; |
|
|
// |
|
|
for (t1=0; t1 < nevents1; t1++){ |
|
5056 |
// |
// |
5057 |
pret2 = t2; |
CalibTrk1Event *caltrk1 = 0; |
5058 |
tr1->GetEntry(t1); |
CalibTrk2Event *caltrk2 = 0; |
5059 |
|
TTree *tr1 = 0; |
5060 |
|
TTree *tr2 = 0; |
5061 |
|
EventHeader *eh1 = 0; |
5062 |
|
PscuHeader *ph1 = 0; |
5063 |
|
EventHeader *eh2 = 0; |
5064 |
|
PscuHeader *ph2 = 0; |
5065 |
// |
// |
5066 |
ph1 = eh1->GetPscuHeader(); |
PacketType *pctp=0; |
5067 |
obt1 = ph1->GetOrbitalTime(); |
EventCounter *codt2=0; |
|
pkt1 = ph1->GetCounter(); |
|
|
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
|
5068 |
// |
// |
5069 |
// valid = 1; |
Int_t nevents1 = 0; |
5070 |
// // |
Int_t nevents2 = 0; |
|
// if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
|
5071 |
// |
// |
5072 |
|
fromtime = 0; |
5073 |
// |
// |
5074 |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
obt1 = 0; |
5075 |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
pkt1 = 0; |
5076 |
// |
obt2 = 0; |
5077 |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u \n",fromtime,obt1,pkt1); |
pkt2 = 0; |
5078 |
// |
// |
5079 |
valid = ValidateTrkCalib( caltrk1, eh1 ); |
tr1 = (TTree*)file->Get("CalibTrk1"); |
5080 |
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
if ( !tr1 || tr1->IsZombie() ) throw -22; |
5081 |
// |
tr2 = (TTree*)file->Get("CalibTrk2"); |
5082 |
// Do we have the second calibration packet? |
if ( !tr2 || tr2->IsZombie() ) throw -23; |
5083 |
// |
// |
5084 |
while ( t2t1cal < t1+1 ){ // get the calibration packet2 that follows the packet1 |
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
5085 |
|
tr1->SetBranchAddress("Header", &eh1); |
5086 |
|
nevents1 = tr1->GetEntries(); |
5087 |
|
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
5088 |
|
tr2->SetBranchAddress("Header", &eh2); |
5089 |
|
nevents2 = tr2->GetEntries(); |
5090 |
|
// |
5091 |
|
if ( !nevents1 && !nevents2 ) return(1); |
5092 |
|
// |
5093 |
|
t2 = -1; |
5094 |
|
Int_t pret2 = 0; |
5095 |
|
Int_t t2t1cal = 0; |
5096 |
|
// |
5097 |
|
bool MISSING_pkt1 = true; |
5098 |
|
bool MISSING_pkt2 = true; |
5099 |
|
int ncalib = 0; |
5100 |
|
bool try_to_recover = false; |
5101 |
|
// |
5102 |
|
for (t1=0; t1 < nevents1; t1++){//loop over packet1 |
5103 |
// |
// |
5104 |
t2++; |
pret2 = t2; |
5105 |
|
tr1->GetEntry(t1); |
5106 |
// |
// |
5107 |
pret2 = t2 - 1; // EMILIANO |
ph1 = eh1->GetPscuHeader(); |
5108 |
|
obt1 = ph1->GetOrbitalTime(); |
5109 |
|
pkt1 = ph1->GetCounter(); |
5110 |
|
fromtime = GetAbsTime(ph1->GetOrbitalTime()); |
5111 |
// |
// |
5112 |
if ( t2 < nevents2 ){ |
// chek if the packet number and obt are consistent with the other packets ??? |
5113 |
tr2->GetEntry(t2); |
// |
5114 |
codt2 = eh2->GetCounter(); |
if ( PKT(pkt1) >= PKT(pktfirst) && PKT(pkt1) <= upperpkt && OBT(obt1) >= OBT(obtfirst) && OBT(obt1) <= upperobt ){ |
5115 |
t2t1cal = codt2->Get(pctp->CalibTrk1); |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
5116 |
// |
// |
5117 |
ph2 = eh2->GetPscuHeader(); |
if ( IsDebug() ) printf("\n Trk calibration1 %u at time %u obt %u pkt %u \n",t1,fromtime,obt1,pkt1); |
5118 |
obt2 = ph2->GetOrbitalTime(); |
// |
5119 |
pkt2 = ph2->GetCounter(); |
valid = ValidateTrkCalib( caltrk1, eh1 ); |
5120 |
// |
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
5121 |
if ( IsDebug() ) printf(" This is a trk calibration2 at obt %u pkt %u t2 is %u , t2t1cal is %u \n",obt2,pkt2,t2,t2t1cal); |
// |
5122 |
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
// Do we have the second calibration packet? |
5123 |
// |
// |
5124 |
|
if ( IsDebug() ) cout << " Loop over calibration2 to search associated calibration: "<<endl; |
5125 |
|
while ( t2t1cal < t1+1 ){ // get the calibration packet2 that follows the packet1 |
5126 |
|
// |
5127 |
|
t2++; |
5128 |
|
// |
5129 |
|
pret2 = t2 - 1; // EMILIANO |
5130 |
|
// |
5131 |
|
if ( t2 < nevents2 ){ |
5132 |
|
tr2->GetEntry(t2); |
5133 |
|
codt2 = eh2->GetCounter(); |
5134 |
|
t2t1cal = codt2->Get(pctp->CalibTrk1); |
5135 |
|
// |
5136 |
|
ph2 = eh2->GetPscuHeader(); |
5137 |
|
obt2 = ph2->GetOrbitalTime(); |
5138 |
|
pkt2 = ph2->GetCounter(); |
5139 |
|
// |
5140 |
|
if ( IsDebug() ) printf(" >> trk calibration2 at obt %u pkt %u t2 is %u , t2t1cal is %u \n",obt2,pkt2,t2,t2t1cal); |
5141 |
|
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
5142 |
|
// |
5143 |
|
} else { |
5144 |
|
// |
5145 |
|
// running out of vector without finding the corresponding calibration, sig |
5146 |
|
// |
5147 |
|
if ( IsDebug() ) printf(" t2 >= nevents2 \n"); |
5148 |
|
pret2 = t2; |
5149 |
|
obt2 = 0; |
5150 |
|
// pkt2 = pkt1+2; |
5151 |
|
pkt2 = 0; |
5152 |
|
t2t1cal = t1+1; |
5153 |
|
}; |
5154 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) && (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
5155 |
|
|
5156 |
|
// EMILIANO |
5157 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
5158 |
|
// // if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
5159 |
|
// if ( IsDebug() ) printf(" running out of vector without finding the corresponding calibration, sig \n"); |
5160 |
|
// // |
5161 |
|
// // running out of vector without finding the corresponding calibration, sig |
5162 |
|
// // |
5163 |
|
// pret2 = t2; |
5164 |
|
// obt2 = 0; |
5165 |
|
// // pkt2 = pkt1+2; |
5166 |
|
// pkt2 = 0; |
5167 |
|
// t2t1cal = t1+1; |
5168 |
|
// }; |
5169 |
|
|
5170 |
|
|
5171 |
|
// |
5172 |
|
}; |
5173 |
|
// |
5174 |
|
if ( IsDebug() ) printf(" Check if trk calibration2 is the right one \n"); |
5175 |
|
// |
5176 |
|
// EMILIANO |
5177 |
|
if ( ( PKT(pkt2) < PKT(pktfirst) || PKT(pkt2) > upperpkt) || (OBT(obt2) < OBT(obtfirst) || OBT(obt2) > upperobt) ){ |
5178 |
|
// if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
5179 |
|
if ( IsDebug() ) printf(" *WARNING* The calibration found is outside the interval, sig \n"); |
5180 |
|
// |
5181 |
|
// running out of vector without finding the corresponding calibration, sig |
5182 |
|
// |
5183 |
|
pret2 = t2; |
5184 |
|
obt2 = 0; |
5185 |
|
pkt2 = 0; |
5186 |
|
}; |
5187 |
|
if ( PKT(pkt2) == PKT(pkt1)+1 ){ |
5188 |
|
if ( IsDebug() ) cout << " ...OK"<<endl; |
5189 |
|
// ======================= |
5190 |
|
// The calibration is good |
5191 |
|
// ======================= |
5192 |
|
// |
5193 |
|
// if ( IsDebug() ) printf(" Found trk calibration2 at obt %u pkt %u t2 is %u \n",obt2,pkt2,t2); |
5194 |
|
// if ( IsDebug() ) printf(" Trk calibration2 at obt %u pkt %u t2 is %u is good \n",obt2,pkt2,t2); |
5195 |
|
// if ( IsDebug() ) printf("\n Trk calibration2 at time %u obt %u pkt %u \n",fromtime,obt2,pkt2); |
5196 |
|
if ( IsDebug() ) printf(" Trk calibration2 %u at time %u obt %u pkt %u \n",t2,fromtime,obt2,pkt2); |
5197 |
|
// |
5198 |
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
5199 |
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
5200 |
|
// valid = valid & valid2; |
5201 |
|
valid = valid & valid2; //QUESTO VA CAMBIATO |
5202 |
|
// |
5203 |
|
// Handle good calib |
5204 |
|
// |
5205 |
|
MISSING_pkt1 = false; |
5206 |
|
MISSING_pkt2 = false; |
5207 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5208 |
|
// |
5209 |
|
// Check for missing calibtrk1 |
5210 |
|
// |
5211 |
|
if ( t2 != pret2+1 ){ |
5212 |
|
// |
5213 |
|
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u pret2 is %u \n",obt2,pkt2,t2,pret2); |
5214 |
|
// |
5215 |
|
while ( t2 > pret2+1 ){ |
5216 |
|
// |
5217 |
|
// handle missing calib1 |
5218 |
|
// |
5219 |
|
pret2++; |
5220 |
|
// |
5221 |
|
obt1 = 0; |
5222 |
|
pkt1 = 0; |
5223 |
|
// |
5224 |
|
tr2->GetEntry(pret2); |
5225 |
|
ph2 = eh2->GetPscuHeader(); |
5226 |
|
obt2 = ph2->GetOrbitalTime(); |
5227 |
|
pkt2 = ph2->GetCounter(); |
5228 |
|
// |
5229 |
|
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
5230 |
|
// |
5231 |
|
valid = 0; |
5232 |
|
MISSING_pkt1 = true; |
5233 |
|
MISSING_pkt2 = false; |
5234 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5235 |
|
// |
5236 |
|
}; |
5237 |
|
// |
5238 |
|
}; |
5239 |
|
// |
5240 |
|
} else if ( this->PKT(pkt2) > this->PKT(pkt1)+1 ){ |
5241 |
|
// |
5242 |
|
// Check for missing calibtrk2 |
5243 |
|
// |
5244 |
|
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
5245 |
|
t2 = pret2; |
5246 |
|
// |
5247 |
|
// handle missing calib2 |
5248 |
|
// |
5249 |
|
obt2 = 0; |
5250 |
|
pkt2 = 0; |
5251 |
|
valid = 0; |
5252 |
|
MISSING_pkt1 = false; |
5253 |
|
MISSING_pkt2 = true; |
5254 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5255 |
|
// |
5256 |
|
}; |
5257 |
|
// |
5258 |
|
|
5259 |
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
5260 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5261 |
|
ncalib++; |
5262 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
5263 |
|
} |
5264 |
|
|
5265 |
|
|
5266 |
} else { |
} else { |
5267 |
// |
// |
5268 |
// running out of vector without finding the corresponding calibration, sig |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
5269 |
// |
// if ( PEDANTIC ) throw -79; |
5270 |
if ( IsDebug() ) printf(" t2 >= nevents2 \n"); |
// |
|
pret2 = t2; |
|
|
obt2 = 0; |
|
|
// pkt2 = pkt1+2; |
|
|
pkt2 = 0; |
|
|
t2t1cal = t1+1; |
|
5271 |
}; |
}; |
5272 |
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) && (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
// |
5273 |
|
|
5274 |
// EMILIANO |
}; //end loop on pkt1 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
|
|
// // if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
|
|
// if ( IsDebug() ) printf(" running out of vector without finding the corresponding calibration, sig \n"); |
|
|
// // |
|
|
// // running out of vector without finding the corresponding calibration, sig |
|
|
// // |
|
|
// pret2 = t2; |
|
|
// obt2 = 0; |
|
|
// // pkt2 = pkt1+2; |
|
|
// pkt2 = 0; |
|
|
// t2t1cal = t1+1; |
|
|
// }; |
|
5275 |
|
|
5276 |
|
|
5277 |
|
|
5278 |
|
// |
5279 |
|
// we have one more calib pkt2 ! |
5280 |
|
// |
5281 |
|
t2++; |
5282 |
|
while ( t2 < nevents2 ){ |
5283 |
// |
// |
5284 |
}; |
// handle missing calib1 |
|
// |
|
|
if ( IsDebug() ) printf(" Check if trk calibration2 exists \n"); |
|
|
// |
|
|
// EMILIANO |
|
|
if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
|
|
// if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
|
|
if ( IsDebug() ) printf(" The calibration found is outside the interval, sig \n"); |
|
|
// |
|
|
// running out of vector without finding the corresponding calibration, sig |
|
|
// |
|
|
pret2 = t2; |
|
|
obt2 = 0; |
|
|
pkt2 = 0; |
|
|
}; |
|
|
// |
|
|
// The calibration is good |
|
|
// |
|
|
if ( this->PKT(pkt2) == this->PKT(pkt1)+1 ){ |
|
|
// |
|
|
if ( IsDebug() ) printf(" Found trk calibration2 at obt %u pkt %u t2 is %u \n",obt2,pkt2,t2); |
|
|
if ( IsDebug() ) printf(" The trk calibration2 at obt %u pkt %u t2 is %u is good \n",obt2,pkt2,t2); |
|
|
// |
|
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
|
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
|
|
valid = valid & valid2; |
|
|
// |
|
|
// Handle good calib |
|
5285 |
// |
// |
5286 |
this->HandleTRK_CALIB(true,true); |
if ( IsDebug() ) printf(" t2 is %u nevents2 is %u \n",t2,nevents2); |
5287 |
|
obt1 = 0; |
5288 |
|
pkt1 = 0; |
5289 |
// |
// |
5290 |
// Check for missing calibtrk1 |
tr2->GetEntry(t2); |
5291 |
|
ph2 = eh2->GetPscuHeader(); |
5292 |
|
obt2 = ph2->GetOrbitalTime(); |
5293 |
|
pkt2 = ph2->GetCounter(); |
5294 |
// |
// |
5295 |
if ( t2 != pret2+1 ){ |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
5296 |
// |
valid = 0; |
5297 |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u pret2 is %u \n",obt2,pkt2,t2,pret2); |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
5298 |
// |
// EMILIANO |
5299 |
while ( t2 > pret2+1 ){ |
if ( this->PKT(pkt2) >= this->PKT(pktfirst) && this->PKT(pkt2 <= upperpkt) && this->OBT(obt2) >= this->OBT(obtfirst) && this->OBT(obt2) <= upperobt ){ |
5300 |
// |
// if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
|
// handle missing calib1 |
|
|
// |
|
|
pret2++; |
|
|
// |
|
|
obt1 = 0; |
|
|
pkt1 = 0; |
|
|
// |
|
|
tr2->GetEntry(pret2); |
|
|
ph2 = eh2->GetPscuHeader(); |
|
|
obt2 = ph2->GetOrbitalTime(); |
|
|
pkt2 = ph2->GetCounter(); |
|
5301 |
// |
// |
5302 |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
5303 |
// |
// |
5304 |
valid = 0; |
MISSING_pkt1 = true; |
5305 |
this->HandleTRK_CALIB(false,true); |
MISSING_pkt2 = false; |
5306 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5307 |
|
ncalib++; |
5308 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
5309 |
// |
// |
|
}; |
|
|
// |
|
5310 |
}; |
}; |
5311 |
// |
// |
5312 |
} else if ( this->PKT(pkt2) > this->PKT(pkt1)+1 ){ |
t2++; |
|
// |
|
|
// Check for missing calibtrk2 |
|
|
// |
|
|
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
|
|
t2 = pret2; |
|
5313 |
// |
// |
5314 |
// handle missing calib2 |
}; |
5315 |
|
|
5316 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
5317 |
|
// ----------------------------------------------------------------- |
5318 |
|
// in case of corruption, check if the calibration can be recovered |
5319 |
|
// from another chewbacca file |
5320 |
|
// ----------------------------------------------------------------- |
5321 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
5322 |
|
|
5323 |
|
// cout <<" TRY TO RECOVER ?? "<<try_to_recover<<endl; |
5324 |
|
|
5325 |
|
if(chewbacca&&try_to_recover){ |
5326 |
|
|
5327 |
|
|
5328 |
|
if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<<endl; |
5329 |
|
|
5330 |
|
TSQLResult *result = 0; |
5331 |
|
TSQLRow *row = 0; |
5332 |
// |
// |
5333 |
obt2 = 0; |
stringstream oss; |
5334 |
pkt2 = 0; |
oss.str(""); |
|
valid = 0; |
|
|
this->HandleTRK_CALIB(true,false); |
|
5335 |
// |
// |
5336 |
}; |
|
5337 |
// |
//////////////////////////////////////////////////////////////////////// |
5338 |
} else { |
// retrieve the name of the current file: |
5339 |
// |
//////////////////////////////////////////////////////////////////////// |
5340 |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
oss.str(""); |
5341 |
// if ( PEDANTIC ) throw -79; |
oss << "SELECT NAME FROM GL_ROOT where ID=" << GetID_ROOT() <<";"; |
5342 |
// |
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5343 |
}; |
|
5344 |
// |
result = conn->Query(oss.str().c_str()); |
5345 |
}; |
if ( !result ) throw -4;; |
5346 |
// |
row = result->Next(); |
5347 |
// we have one more calib pkt2 ! |
TString thisfilename = (TString)row->GetField(0); |
5348 |
// |
if ( IsDebug() ) cout << "Current file ==> "<<thisfilename<<endl; |
5349 |
t2++; |
|
5350 |
while ( t2 < nevents2 ){ |
//////////////////////////////////////////////////////////////////////// |
5351 |
// |
// read all the calibrations inserted |
5352 |
// handle missing calib1 |
//////////////////////////////////////////////////////////////////////// |
5353 |
// |
oss.str(""); |
5354 |
if ( IsDebug() ) printf(" t2 is %u nevents2 is %u \n",t2,nevents2); |
oss << " SELECT "; |
5355 |
obt1 = 0; |
oss << " ID,FROM_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,TO_TIME"; |
5356 |
pkt1 = 0; |
oss << " FROM GL_TRK_CALIB "; |
5357 |
// |
oss << " ORDER BY ID DESC LIMIT "<<ncalib<<"; "; |
5358 |
tr2->GetEntry(t2); |
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5359 |
ph2 = eh2->GetPscuHeader(); |
|
5360 |
obt2 = ph2->GetOrbitalTime(); |
result = conn->Query(oss.str().c_str()); |
5361 |
pkt2 = ph2->GetCounter(); |
if ( !result ) throw -4;; |
5362 |
// |
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5363 |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
|
5364 |
valid = 0; |
// ----------------------------------- |
5365 |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
// loop over calibrations ... |
5366 |
// EMILIANO |
// ----------------------------------- |
5367 |
if ( this->PKT(pkt2) >= this->PKT(pktfirst) && this->PKT(pkt2 <= upperpkt) && this->OBT(obt2) >= this->OBT(obtfirst) && this->OBT(obt2) <= upperobt ){ |
UInt_t nn=0; |
5368 |
// if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
do { |
5369 |
// |
row = result->Next(); |
5370 |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
if(!row)break; |
5371 |
// |
|
5372 |
this->HandleTRK_CALIB(false,true); |
UInt_t id = (UInt_t)atoll(row->GetField(0)); |
5373 |
// |
UInt_t fromtime = (UInt_t)atoll(row->GetField(1)); |
5374 |
}; |
UInt_t obt1 = (UInt_t)atoll(row->GetField(2)); |
5375 |
// |
UInt_t pkt1 = (UInt_t)atoll(row->GetField(3)); |
5376 |
t2++; |
UInt_t obt2 = (UInt_t)atoll(row->GetField(4)); |
5377 |
// |
UInt_t pkt2 = (UInt_t)atoll(row->GetField(5)); |
5378 |
}; |
UInt_t boot = (UInt_t)atoll(row->GetField(6)); |
5379 |
|
UInt_t valid = (UInt_t)atoll(row->GetField(7)); |
5380 |
|
bool MISSING_pkt1 = (row->GetFieldLength(8)==0); |
5381 |
|
bool MISSING_pkt2 = (row->GetFieldLength(9)==0); |
5382 |
|
UInt_t totime = (UInt_t)atoll(row->GetField(10)); |
5383 |
|
|
5384 |
|
// ------------------------------------- |
5385 |
|
// ...check if the entry is corrupted... |
5386 |
|
// ------------------------------------- |
5387 |
|
cout <<"*** "<< MISSING_pkt1 << MISSING_pkt2 << valid <<endl; |
5388 |
|
bool CORRUPTED = (MISSING_pkt1||MISSING_pkt2||!valid); |
5389 |
|
|
5390 |
|
if ( IsDebug() ) cout << "("<<nn<<") ID = "<<id<<" from GL_TRK_CALIB ==> corrupted ? "<<CORRUPTED<<endl; |
5391 |
|
|
5392 |
|
// if( !CORRUPTED )continue; // nothing to do |
5393 |
|
|
5394 |
|
///////////////////////////////////////////////////////// |
5395 |
|
// if it is corrupted, ...look for ather chewbacca files |
5396 |
|
// containing the same calibrations ... |
5397 |
|
///////////////////////////////////////////////////////// |
5398 |
|
|
5399 |
|
bool this_MISSING_pkt1 = false; |
5400 |
|
bool this_MISSING_pkt2 = false; |
5401 |
|
int this_t1=0; |
5402 |
|
int this_t2=0;; |
5403 |
|
UInt_t this_valid = 0; |
5404 |
|
|
5405 |
|
TString path = ""; |
5406 |
|
TString name = ""; |
5407 |
|
TString raw = ""; |
5408 |
|
UInt_t obt0 = 0; |
5409 |
|
UInt_t timesync = 0; |
5410 |
|
UInt_t boot_number = 0; |
5411 |
|
bool FOUND = false; |
5412 |
|
|
5413 |
|
if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl; |
5414 |
|
|
5415 |
|
// for(int itable=0; itable<2; itable++){ |
5416 |
|
for(int itable=0; itable<1; itable++){ |
5417 |
|
|
5418 |
|
// ------------------------------------------------------ |
5419 |
|
// loop over both ROOT_TABLE and ROOT_TABLE_BAD |
5420 |
|
// ------------------------------------------------------ |
5421 |
|
|
5422 |
|
TString table = "ROOT_TABLE"; |
5423 |
|
if(itable==1)table = "ROOT_TABLE_BAD"; |
5424 |
|
|
5425 |
|
oss.str(""); |
5426 |
|
oss << " SELECT "; |
5427 |
|
oss << " FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,BOOT_NUMBER,INPUT_NAME "; |
5428 |
|
oss << " FROM "<<table; |
5429 |
|
oss << " WHERE 1 " << endl; |
5430 |
|
oss << " AND FILE_NAME != \""<< thisfilename<<"\""; |
5431 |
|
if( !MISSING_pkt1 ){ |
5432 |
|
oss << " AND "; |
5433 |
|
oss << " PKT_NUMBER_INIT < "<<pkt1; |
5434 |
|
oss << " AND "; |
5435 |
|
oss << " PKT_NUMBER_FINAL > "<<pkt1; |
5436 |
|
oss << " AND "; |
5437 |
|
oss << " PKT_OBT_INIT < "<<obt1; |
5438 |
|
oss << " AND "; |
5439 |
|
oss << " PKT_OBT_FINAL > "<<obt1; |
5440 |
|
}else{ |
5441 |
|
if(pkt2>1) pkt1 = pkt2-1;//serve dopo |
5442 |
|
} |
5443 |
|
if( !MISSING_pkt2 ){ |
5444 |
|
oss << " AND "; |
5445 |
|
oss << " PKT_NUMBER_INIT < "<<pkt2; |
5446 |
|
oss << " AND "; |
5447 |
|
oss << " PKT_NUMBER_FINAL > "<<pkt2; |
5448 |
|
oss << " AND "; |
5449 |
|
oss << " PKT_OBT_INIT < "<<obt2; |
5450 |
|
oss << " AND "; |
5451 |
|
oss << " PKT_OBT_FINAL > "<<obt2; |
5452 |
|
}else{ |
5453 |
|
if(pkt1>0) pkt2 = pkt1+1;//serve dopo |
5454 |
|
} |
5455 |
|
if( boot> 0 ){ |
5456 |
|
oss << " AND "; |
5457 |
|
oss << " BOOT_NUMBER = "<<boot; |
5458 |
|
}else{ |
5459 |
|
} |
5460 |
|
oss << " ORDER BY BAD_PKT_CALREAD ASC; "; |
5461 |
|
|
5462 |
|
TSQLResult *result2 = 0; |
5463 |
|
TSQLRow *row2 = 0; |
5464 |
|
|
5465 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5466 |
|
result2 = conn->Query(oss.str().c_str()); |
5467 |
|
if ( !result2 ) throw -4;; |
5468 |
|
if ( IsDebug() ) cout <<"Rows: "<<result2->GetRowCount()<<endl; |
5469 |
|
|
5470 |
|
// ------------------------------------------------------ |
5471 |
|
// loop over files containing repetition (if any) |
5472 |
|
// ------------------------------------------------------ |
5473 |
|
do { |
5474 |
|
row2 = result2->Next(); |
5475 |
|
if(!row2)break; |
5476 |
|
|
5477 |
|
// ------------------------------------------------------ |
5478 |
|
// ... a repetition is found ... |
5479 |
|
// ------------------------------------------------------ |
5480 |
|
path = (TString)row2->GetField(0); |
5481 |
|
name = (TString)row2->GetField(1); |
5482 |
|
raw = (TString)row2->GetField(5); |
5483 |
|
obt0 = (UInt_t)atoll(row2->GetField(2)); |
5484 |
|
timesync = (UInt_t)atoll(row2->GetField(3)); |
5485 |
|
boot_number = (UInt_t)atoll(row2->GetField(4)); |
5486 |
|
|
5487 |
|
if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl; |
5488 |
|
// cout << path <<endl; |
5489 |
|
// cout << "File : " <<name <<endl; |
5490 |
|
// cout << obt0 <<endl; |
5491 |
|
// cout << timesync <<endl; |
5492 |
|
// cout << "boot n. : "<<boot_number <<endl; |
5493 |
|
// cout << raw <<endl; |
5494 |
|
|
5495 |
|
// ------------------------------------------------------ |
5496 |
|
// ... retrieve the calibration packets. |
5497 |
|
// ------------------------------------------------------ |
5498 |
|
if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data()); |
5499 |
|
TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it |
5500 |
|
if(!file)throw -100; |
5501 |
|
if(file->IsZombie())throw -100; |
5502 |
|
// |
5503 |
|
tr1 = (TTree*)file->Get("CalibTrk1"); |
5504 |
|
if ( !tr1 || tr1->IsZombie() ) throw -22; |
5505 |
|
tr2 = (TTree*)file->Get("CalibTrk2"); |
5506 |
|
if ( !tr2 || tr2->IsZombie() ) throw -23; |
5507 |
|
// |
5508 |
|
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
5509 |
|
tr1->SetBranchAddress("Header", &eh1); |
5510 |
|
nevents1 = tr1->GetEntries(); |
5511 |
|
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
5512 |
|
tr2->SetBranchAddress("Header", &eh2); |
5513 |
|
nevents2 = tr2->GetEntries(); |
5514 |
|
for(this_t1=0; this_t1<nevents1; this_t1++){ |
5515 |
|
tr1->GetEntry(this_t1); |
5516 |
|
if( |
5517 |
|
(UInt_t)eh1->GetPscuHeader()->GetCounter() == pkt1 && |
5518 |
|
true) break; |
5519 |
|
this_MISSING_pkt1 = true; |
5520 |
|
} |
5521 |
|
for(this_t2=0; this_t2<nevents2; this_t2++){ |
5522 |
|
tr2->GetEntry(this_t2); |
5523 |
|
if( |
5524 |
|
(UInt_t)eh2->GetPscuHeader()->GetCounter() == pkt2 && |
5525 |
|
true) break; |
5526 |
|
this_MISSING_pkt2 = true; |
5527 |
|
} |
5528 |
|
this_valid = |
5529 |
|
ValidateTrkCalib( caltrk1, eh1, file ) |
5530 |
|
* |
5531 |
|
ValidateTrkCalib( caltrk2, eh2, file ); |
5532 |
|
|
5533 |
|
// --------------------------------------------------------------------- |
5534 |
|
// accept the calibration if it is better than the previous: |
5535 |
|
// |
5536 |
|
// - if the new calibration is perfect (both valid packets) |
5537 |
|
// - if the new calibration has both the packets and the previous does not |
5538 |
|
// --------------------------------------------------------------------- |
5539 |
|
if( |
5540 |
|
( !this_MISSING_pkt1&&!this_MISSING_pkt2&&this_valid )|| |
5541 |
|
( (MISSING_pkt1||MISSING_pkt2) && (!this_MISSING_pkt1&&!this_MISSING_pkt2) )|| |
5542 |
|
false)FOUND=true; |
5543 |
|
|
5544 |
|
if(file)file->Close(); |
5545 |
|
|
5546 |
|
if(FOUND)break; |
5547 |
|
|
5548 |
|
}while(1);//endl loop over root table entries |
5549 |
|
|
5550 |
|
if(FOUND)break; |
5551 |
|
|
5552 |
|
}//end loop over tables |
5553 |
|
|
5554 |
|
if(FOUND){ |
5555 |
|
|
5556 |
|
if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl; |
5557 |
|
|
5558 |
|
//////////////////////////////////////////// |
5559 |
|
// insert a new entry in GL_TRK_CALIB and |
5560 |
|
// modify the time-tag of the previous one |
5561 |
|
//////////////////////////////////////////// |
5562 |
|
|
5563 |
|
// --------------------------------------------------------------------- |
5564 |
|
// step 1: insert a new raw file in GL_RAW |
5565 |
|
// --------------------------------------------------------------------- |
5566 |
|
// |
5567 |
|
// check if the raw file already exist |
5568 |
|
// |
5569 |
|
UInt_t id_raw = 0; // EM GL_RAW is there only for backward compatibility so we do not need to fill it when in "chewbacca" mode |
5570 |
|
// oss.str(""); |
5571 |
|
// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
5572 |
|
// if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5573 |
|
|
5574 |
|
// result = conn->Query(oss.str().c_str()); |
5575 |
|
// if ( !result ) throw -4;; |
5576 |
|
// if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5577 |
|
// if( result->GetRowCount() == 0){ |
5578 |
|
// if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
5579 |
|
// // - - - - - - - - - - - |
5580 |
|
// // insert new raw file |
5581 |
|
// // - - - - - - - - - - - |
5582 |
|
// GL_RAW glraw = GL_RAW(); |
5583 |
|
// glraw.PATH = gSystem->DirName(raw.Data()); |
5584 |
|
// glraw.NAME = gSystem->BaseName(raw.Data()); |
5585 |
|
// glraw.BOOT_NUMBER = boot_number; |
5586 |
|
// // |
5587 |
|
// insertPamelaRawFile( &glraw ); |
5588 |
|
// // |
5589 |
|
// id_raw = glraw.ID; |
5590 |
|
// }else{ |
5591 |
|
// row = result->Next(); |
5592 |
|
// id_raw = (UInt_t)atoll(row->GetField(0)); |
5593 |
|
// } |
5594 |
|
// if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
5595 |
|
|
5596 |
|
// --------------------------------------------------------------------- |
5597 |
|
// step 1(bis): retrieve the timesync id associated to the file |
5598 |
|
// (NB, uso lo stesso associato al file iniziale) |
5599 |
|
// --------------------------------------------------------------------- |
5600 |
|
UInt_t idtimesync = 0; |
5601 |
|
oss.str(""); |
5602 |
|
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
5603 |
|
if ( debug ) printf(" %s \n",oss.str().c_str()); |
5604 |
|
result = conn->Query(oss.str().c_str()); |
5605 |
|
if ( !result ) throw -3; |
5606 |
|
row = result->Next(); |
5607 |
|
if ( !row ) throw -3; |
5608 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
5609 |
|
if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl; |
5610 |
|
|
5611 |
|
delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5612 |
|
// --------------------------------------------------------------------- |
5613 |
|
// step 2: insert a new root file in GL_ROOT |
5614 |
|
// --------------------------------------------------------------------- |
5615 |
|
// |
5616 |
|
// check if the root file already exist |
5617 |
|
// |
5618 |
|
UInt_t id_root = 0; |
5619 |
|
oss.str(""); |
5620 |
|
oss << "SELECT ID FROM GL_ROOT where NAME=\"" << gSystem->BaseName(name.Data()) <<"\";"; |
5621 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5622 |
|
|
5623 |
|
result = conn->Query(oss.str().c_str()); |
5624 |
|
if ( !result ) throw -4;; |
5625 |
|
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5626 |
|
if( result->GetRowCount() == 0){ |
5627 |
|
if ( IsDebug() ) cout << " << Insert new ROOT file >> "<<endl; |
5628 |
|
// - - - - - - - - - - - |
5629 |
|
// insert new root file |
5630 |
|
// - - - - - - - - - - - |
5631 |
|
GL_ROOT glroot = GL_ROOT(); |
5632 |
|
glroot.ID_RAW = id_raw; |
5633 |
|
glroot.ID_TIMESYNC = idtimesync; |
5634 |
|
// |
5635 |
|
// EM STATIC = the full expanded path must be put in the DB, KEEPENV = the path given as input (or found in ROOT_TABLE) must be used, |
5636 |
|
// NOT STATIC NOT KEEPENV = $PAM_L0 must be used in the DB |
5637 |
|
// |
5638 |
|
if ( STATIC ){ |
5639 |
|
glroot.PATH = (TString)gSystem->ExpandPathName(path); |
5640 |
|
} else { |
5641 |
|
if ( KEEPENV ){ |
5642 |
|
glroot.PATH = path; |
5643 |
|
} else { |
5644 |
|
glroot.PATH = "$PAM_L0"; |
5645 |
|
}; |
5646 |
|
}; |
5647 |
|
// glroot.PATH = path; |
5648 |
|
glroot.NAME = name; |
5649 |
|
// |
5650 |
|
insertPamelaRootFile( &glroot ); |
5651 |
|
// |
5652 |
|
id_root = glroot.ID; |
5653 |
|
}else{ |
5654 |
|
row = result->Next(); |
5655 |
|
if(row)id_root = (UInt_t)atoll(row->GetField(0)); |
5656 |
|
} |
5657 |
|
if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl; |
5658 |
|
|
5659 |
|
delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5660 |
|
// --------------------------------------------------------------------- |
5661 |
|
// step 3: modify time-tag of corrupted GL_TRK_CALIB entry |
5662 |
|
// --------------------------------------------------------------------- |
5663 |
|
if ( IsDebug() ) cout << " << Modify time-tag of calibration ID="<<id<<" >> "<<endl; |
5664 |
|
oss.str(""); |
5665 |
|
oss << " UPDATE GL_TRK_CALIB SET " |
5666 |
|
<< " TO_TIME=0 , FROM_TIME=0 WHERE " |
5667 |
|
<< " ID = "<< id << ";"; |
5668 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5669 |
|
result = conn->Query(oss.str().c_str()); |
5670 |
|
if ( !result ) throw -4;; |
5671 |
|
|
5672 |
|
delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5673 |
|
|
5674 |
|
// --------------------------------------------------------------------- |
5675 |
|
// step 4: insert the new calibration: |
5676 |
|
// --------------------------------------------------------------------- |
5677 |
|
if ( IsDebug() ) cout << " << Insert new TRK calibration >> "<<endl; |
5678 |
|
// |
5679 |
|
GL_TRK_CALIB glcal = GL_TRK_CALIB(); |
5680 |
|
// |
5681 |
|
glcal.ID_ROOT_L0 = id_root; |
5682 |
|
glcal.EV_ROOT_CALIBTRK1 = this_t1; |
5683 |
|
glcal.EV_ROOT_CALIBTRK2 = this_t2; |
5684 |
|
glcal.FROM_TIME = fromtime; |
5685 |
|
glcal.TO_TIME = totime; |
5686 |
|
glcal.OBT1 = obt1; |
5687 |
|
glcal.OBT2 = obt2; |
5688 |
|
glcal.PKT1 = pkt1; |
5689 |
|
glcal.PKT2 = pkt1; |
5690 |
|
glcal.BOOT_NUMBER = GetBOOTnumber(); |
5691 |
|
glcal.VALIDATION = this_valid; |
5692 |
|
// |
5693 |
|
HandleTRK_CALIB(&glcal); |
5694 |
|
if ( IsDebug() ) cout << "ID = "<<glcal.ID<<endl; |
5695 |
|
// |
5696 |
|
|
5697 |
|
} |
5698 |
|
if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl; |
5699 |
|
|
5700 |
|
}while(1);//end loop over calibrations |
5701 |
|
|
5702 |
|
|
5703 |
|
if( result )delete result; |
5704 |
|
if( row )delete row; |
5705 |
|
|
5706 |
|
|
5707 |
|
|
5708 |
|
|
5709 |
|
|
5710 |
|
|
5711 |
|
} |
5712 |
|
|
5713 |
|
|
5714 |
|
// // ------------------------------ |
5715 |
|
// // try to recover the calibration |
5716 |
|
// // ------------------------------ |
5717 |
|
// cout << "TRY TO RECOVER TRACKER CALIBRATION"<<endl; |
5718 |
|
// // |
5719 |
|
// ULong64_t time = 0; //absolute time |
5720 |
|
// string path[100]; //mettere un limite massimo |
5721 |
|
// int nrows = 0; |
5722 |
|
// UInt_t pkt = 0; |
5723 |
|
// UInt_t obt = 0; |
5724 |
|
// char *type = ""; |
5725 |
|
// EventHeader *eh = new EventHeader(); |
5726 |
|
// CalibTrk1Event *c = new CalibTrk1Event(); |
5727 |
|
|
5728 |
|
// // |
5729 |
|
// if(which_is_not_valid==1 || which_is_not_valid==3){ |
5730 |
|
// // |
5731 |
|
// cout << "PKT1 --> missing or corrupted "<<endl; |
5732 |
|
// type = "CalibTrk1"; |
5733 |
|
// pkt = pkt1; |
5734 |
|
// obt = obt1; |
5735 |
|
// time = this->GetAbsTime(obt1); |
5736 |
|
// if( pkt1 == 0 ){//missing |
5737 |
|
// time = this->GetAbsTime(obt2); |
5738 |
|
// pkt = pkt2-1; |
5739 |
|
// } |
5740 |
|
// // |
5741 |
|
// }else if (which_is_not_valid==2 || which_is_not_valid==3){ |
5742 |
|
// // |
5743 |
|
// cout << "PKT2--> missing or corrupted "<<endl; |
5744 |
|
// type = "CalibTrk2 "; |
5745 |
|
// pkt = pkt2; |
5746 |
|
// obt = obt2; |
5747 |
|
// time = this->GetAbsTime(obt2); |
5748 |
|
// if( pkt2 == 0 ){//missing |
5749 |
|
// time = this->GetAbsTime(obt1); |
5750 |
|
// pkt = pkt1+1; |
5751 |
|
// } |
5752 |
|
// // |
5753 |
|
// }else{ |
5754 |
|
// cout << "this should not happen!!! "<<endl; |
5755 |
|
// trow -666; |
5756 |
|
// } |
5757 |
|
|
5758 |
|
// nrows = Query_ROOT_TABLE(time,conn,path);// get the list of file which might contain the packet |
5759 |
|
|
5760 |
|
|
5761 |
|
// for(int r=0; r<nrows; r++){ //loop over rows |
5762 |
|
// if(path)cout << r << " >>>> "<<(path+r)->c_str() << endl; |
5763 |
|
// /// verifica che il file non sia quello gia` aperto |
5764 |
|
// } |
5765 |
|
|
5766 |
|
// //////////////////////////////////////////////////////////////////////// |
5767 |
|
|
5768 |
|
// TSQLResult *result = 0; |
5769 |
|
// TSQLRow *row = 0; |
5770 |
|
// // |
5771 |
|
// stringstream oss; |
5772 |
|
// oss.str(""); |
5773 |
|
// // ---------------------------------------- |
5774 |
|
// // read the id of last calibration inserted |
5775 |
|
// // ---------------------------------------- |
5776 |
|
// oss.str(""); |
5777 |
|
// oss << " SELECT "; |
5778 |
|
// oss << " (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) "; |
5779 |
|
// oss << " ORDER BY ID DESC LIMIT 1; "; |
5780 |
|
|
5781 |
|
// result = conn->Query(oss.str().c_str()); |
5782 |
|
// row = result->Next(); |
5783 |
|
// if( !row )throw -666; |
5784 |
|
|
5785 |
|
// if( result )delete result; |
5786 |
|
// if( row )delete row; |
5787 |
|
|
5788 |
|
// UInt_t id = (UInt_t)atoll(row->GetField(0)); |
5789 |
|
|
5790 |
|
// // ------------------------------------- |
5791 |
|
// // ...and modify it with new parameters |
5792 |
|
// // ------------------------------------- |
5793 |
|
|
5794 |
|
|
5795 |
|
// } |
5796 |
// |
// |
5797 |
return(0); |
return(0); |
5798 |
}; |
}; |
6122 |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
6123 |
// |
// |
6124 |
oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " |
oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " |
6125 |
<< " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT()<< ";"; |
<< " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT(); |
6126 |
|
oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112 |
6127 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
6128 |
}; |
}; |
6129 |
}; |
}; |
6172 |
if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){ |
if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){ |
6173 |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6174 |
// |
// |
6175 |
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";"; |
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT(); |
6176 |
|
oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112 |
6177 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
6178 |
}; |
}; |
6179 |
}; |
}; |
6224 |
row2 = result2->Next(); |
row2 = result2->Next(); |
6225 |
// |
// |
6226 |
if ( row2 ){ |
if ( row2 ){ |
6227 |
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! \n"); |
6228 |
if ( PEDANTIC ) throw -83; |
if ( PEDANTIC ) throw -83; |
6229 |
row2->Close(); |
row2->Close(); |
6230 |
}; |
}; |
6301 |
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
6302 |
// |
// |
6303 |
oss.str(""); |
oss.str(""); |
6304 |
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " |
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER,ID_ROOT_L0 FROM GL_RUN WHERE " |
6305 |
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
6306 |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
6307 |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
6359 |
moved++; |
moved++; |
6360 |
// |
// |
6361 |
} else { |
} else { |
6362 |
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
|
6363 |
if ( PEDANTIC ) throw -83; |
// questa parte mah mah mah... da controllare |
6364 |
|
|
6365 |
|
// |
6366 |
|
// we end up here if chewbacca and we have RH---| small gap |---RT, in this case the two pieces are attached and moved to GL_RUN. We are now processing the |
6367 |
|
// "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number. |
6368 |
|
// |
6369 |
|
// 090112 [8RED (-70): RUN ALREADY INSERTED] |
6370 |
|
// |
6371 |
|
Bool_t OK = false; |
6372 |
|
UInt_t IDRL2A = 0; |
6373 |
|
UInt_t IDRL2B = 0; |
6374 |
|
if ( result2->GetRowCount() == 2 ){ |
6375 |
|
IDRL2A = (UInt_t)atoll(row2->GetField(0)); |
6376 |
|
UInt_t IDRL0A = (UInt_t)atoll(row2->GetField(4)); |
6377 |
|
row2 = result2->Next(); |
6378 |
|
IDRL2B = (UInt_t)atoll(row2->GetField(0)); |
6379 |
|
UInt_t IDRL0B = (UInt_t)atoll(row2->GetField(4)); |
6380 |
|
if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B); |
6381 |
|
// if ( IDRL0A == IDRL0B ){ |
6382 |
|
// TSQLResult *result2a = 0; |
6383 |
|
// TSQLRow *row2a = 0; |
6384 |
|
// oss.str(""); |
6385 |
|
// oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;"; |
6386 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
6387 |
|
// result2a = conn->Query(oss.str().c_str()); |
6388 |
|
// // |
6389 |
|
// if ( !result2a ) throw -4; |
6390 |
|
// // |
6391 |
|
// row2a = result2a->Next(); |
6392 |
|
// // |
6393 |
|
// if ( row2a ){ |
6394 |
|
// UInt_t PKA = (UInt_t)atoll(row2a->GetField(0)); |
6395 |
|
// delete result2a; |
6396 |
|
// oss.str(""); |
6397 |
|
// oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;"; |
6398 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
6399 |
|
// result2a = conn->Query(oss.str().c_str()); |
6400 |
|
// // |
6401 |
|
// if ( !result2a ) throw -4; |
6402 |
|
// // |
6403 |
|
// row2a = result2a->Next(); |
6404 |
|
// // |
6405 |
|
// if ( row2a ){ |
6406 |
|
// UInt_t PKB = (UInt_t)atoll(row2a->GetField(0)); |
6407 |
|
// // |
6408 |
|
// if ( IsDebug() ) printf(" PKT(PKA) + 1 %llu == runheaderpkt %llu && PKB = runtrailer %llu + 1 %llu \n",PKT(PKA)+1LL, PKT(glrun->GetRUNHEADER_PKT()),PKT(PKB), PKT(glrun->GetRUNTRAILER_PKT())+1LL); |
6409 |
|
// if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){ |
6410 |
|
// if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); |
6411 |
|
OK = true; |
6412 |
|
// }; |
6413 |
|
// }; |
6414 |
|
// }; |
6415 |
|
// }; |
6416 |
|
}; |
6417 |
|
if ( OK ){ |
6418 |
|
// |
6419 |
|
// this is the case in which we must insert a piece of run between two fragments in the GL_RUN table |
6420 |
|
// |
6421 |
|
// we have to update with runheader/trailer infos our run and we have to change the ROOT_ID_FRAG of the header piece ( 1/2 2/1 must become 1/3 3/2 2/1 ) |
6422 |
|
// |
6423 |
|
GL_RUN *glA = new GL_RUN(); |
6424 |
|
glA->Query_GL_RUN(IDRL2A,conn); |
6425 |
|
// |
6426 |
|
if ( glA->GetACQ_BUILD_INFO() != 0 ){ |
6427 |
|
// |
6428 |
|
// the first piece contains a good runheader we can update all the other runs with correct infos! |
6429 |
|
// |
6430 |
|
oss.str(""); |
6431 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6432 |
|
<< " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , " |
6433 |
|
<< " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
6434 |
|
<< " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , " |
6435 |
|
<< " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , " |
6436 |
|
<< " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , " |
6437 |
|
<< " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , " |
6438 |
|
<< " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , " |
6439 |
|
<< " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , " |
6440 |
|
<< " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , " |
6441 |
|
<< " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , " |
6442 |
|
<< " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , " |
6443 |
|
<< " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , " |
6444 |
|
<< " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , " |
6445 |
|
<< " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , " |
6446 |
|
<< " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , "; |
6447 |
|
// |
6448 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
6449 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , "; |
6450 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
6451 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , "; |
6452 |
|
// |
6453 |
|
oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC(); |
6454 |
|
oss << " WHERE ID=" << glrun->GetID() << ";"; |
6455 |
|
if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str()); |
6456 |
|
conn->Query(oss.str().c_str()); |
6457 |
|
// |
6458 |
|
} else { |
6459 |
|
// |
6460 |
|
// sig no runheader, let set anyway what is possible... |
6461 |
|
// |
6462 |
|
oss.str(""); |
6463 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6464 |
|
<< " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "; |
6465 |
|
// |
6466 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
6467 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; |
6468 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
6469 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
6470 |
|
// |
6471 |
|
oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
6472 |
|
<< " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT(); |
6473 |
|
oss << " WHERE ID=" << glrun->GetID() << ";"; |
6474 |
|
if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str()); |
6475 |
|
conn->Query(oss.str().c_str()); |
6476 |
|
}; |
6477 |
|
// |
6478 |
|
// update runheader ROOT_ID_FRAG |
6479 |
|
// |
6480 |
|
oss.str(""); |
6481 |
|
oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; |
6482 |
|
if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
6483 |
|
conn->Query(oss.str().c_str()); |
6484 |
|
// |
6485 |
|
// now let's look for runtrailer if any in the last run |
6486 |
|
// |
6487 |
|
glA->Query_GL_RUN(IDRL2B,conn); |
6488 |
|
// |
6489 |
|
if ( glA->GetPKT_READY_COUNTER() != 0 ){ |
6490 |
|
// |
6491 |
|
// the first piece contains a good runtrailer we can update all the other runs with correct infos! |
6492 |
|
// |
6493 |
|
oss.str(""); |
6494 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6495 |
|
<< " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
6496 |
|
<< " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , " |
6497 |
|
<< " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , " |
6498 |
|
<< " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , "; |
6499 |
|
// |
6500 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
6501 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
6502 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) { |
6503 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6504 |
|
// |
6505 |
|
oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER() |
6506 |
|
<< " WHERE ID=" << glrun->GetID() << ";"; |
6507 |
|
if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str()); |
6508 |
|
conn->Query(oss.str().c_str()); |
6509 |
|
// |
6510 |
|
} else { |
6511 |
|
// |
6512 |
|
// sig no runtrailer, let set anyway what is possible... |
6513 |
|
// |
6514 |
|
oss.str(""); |
6515 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6516 |
|
<< " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
6517 |
|
<< " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "; |
6518 |
|
// |
6519 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
6520 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
6521 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){ |
6522 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6523 |
|
// |
6524 |
|
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT() |
6525 |
|
<< " WHERE ID=" << glrun->GetID() << ";"; |
6526 |
|
if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str()); |
6527 |
|
conn->Query(oss.str().c_str()); |
6528 |
|
}; |
6529 |
|
// |
6530 |
|
UInt_t myi = glrun->GetID(); |
6531 |
|
oss.str(""); |
6532 |
|
oss << " ID= "<< myi; |
6533 |
|
// |
6534 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
6535 |
|
// |
6536 |
|
// fill the new run in GL_RUN |
6537 |
|
// |
6538 |
|
glrun->SetID_RUN_FRAG(IDRL2B); |
6539 |
|
glrun->Fill_GL_RUN(conn); |
6540 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
6541 |
|
delete glA; |
6542 |
|
moved++; |
6543 |
|
// |
6544 |
|
} else { |
6545 |
|
// |
6546 |
|
// is just a repetition |
6547 |
|
// |
6548 |
|
if ( IsDebug() ) printf(" The run %u is already present in the GL_RUN table...\n",glrun->GetID()); |
6549 |
|
// printf(" CCCCCCCCICCCCCCCCCCCCIOOOOOOOOOO si muove Ciccio! %u \n",glrun->GetID()); |
6550 |
|
// if ( PEDANTIC && glrun->GetID() != 61563 ) throw -83; |
6551 |
|
if ( PEDANTIC ) throw -83; |
6552 |
|
}; |
6553 |
|
// if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! ...\n"); |
6554 |
|
// if ( PEDANTIC ) throw -83; |
6555 |
}; |
}; |
6556 |
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
6557 |
// |
// |
6617 |
// 2) get the OBT of the last validated run |
// 2) get the OBT of the last validated run |
6618 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
6619 |
oss.str(""); |
oss.str(""); |
6620 |
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
// oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
6621 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start |
6622 |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
6623 |
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
6624 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
6761 |
if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration |
if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration |
6762 |
|
|
6763 |
if( !CHECK && this_run->VALIDATION ){ |
if( !CHECK && this_run->VALIDATION ){ |
6764 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
// for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
6765 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION); |
6766 |
nseq=0; |
nseq=0; |
6767 |
} |
} |
6768 |
|
|
6783 |
if( CHECK ){ |
if( CHECK ){ |
6784 |
// check if calibration exists |
// check if calibration exists |
6785 |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
6786 |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
// Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
6787 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
UInt_t MISSING = MissingTRK_CALIB(t1,t2); |
6788 |
|
UInt_t val = 0; |
6789 |
|
if ( MISSING == 1 ) val = 0; |
6790 |
|
if ( MISSING == 0 ) val = 1; |
6791 |
|
if ( MISSING == 2 ) val = 2; |
6792 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val); |
6793 |
nseq=0; |
nseq=0; |
6794 |
}; |
}; |
6795 |
//-------------- |
//-------------- |
6819 |
* @param t2 To absolute time |
* @param t2 To absolute time |
6820 |
* @return true if there might be a missing calibration |
* @return true if there might be a missing calibration |
6821 |
*/ |
*/ |
6822 |
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
//Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6823 |
|
UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6824 |
|
|
6825 |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
6826 |
|
|
6827 |
// get the closest VALIDATED calibration before the run start (t2) |
// get the closest calibration before the run start (t2) |
6828 |
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
// if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
6829 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1); //>>> missing |
6830 |
|
|
6831 |
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
// if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
6832 |
|
if ( trkcalib->TO_TIME < t2 ) return(1); //>>> missing |
6833 |
|
|
6834 |
//============================================================== |
//============================================================== |
6835 |
// Check is done first on the basis of time between calibration, |
// Check is done first on the basis of time between calibration, |
6846 |
//============================================================== |
//============================================================== |
6847 |
Bool_t DOWNLOAD = false; |
Bool_t DOWNLOAD = false; |
6848 |
// check if the calib was skipped becouse of download .... DA FARE!! |
// check if the calib was skipped becouse of download .... DA FARE!! |
6849 |
if(DOWNLOAD)return(false); |
// if(DOWNLOAD)return(false); |
6850 |
|
if(DOWNLOAD)return(0); |
6851 |
|
|
6852 |
return(true); //>>> missing |
// return(true); //>>> missing |
6853 |
|
return(1); //>>> missing |
6854 |
|
|
6855 |
}; |
}; |
6856 |
|
|
6860 |
//============================================================== |
//============================================================== |
6861 |
// the long time interval bewteen runs might be due to download |
// the long time interval bewteen runs might be due to download |
6862 |
if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
6863 |
return(false); |
if ( trkcalib->VALIDATION ) return(0); |
6864 |
|
if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n"); |
6865 |
|
return(2); |
6866 |
|
|
6867 |
}; |
}; |
6868 |
/** |
/** |
6871 |
* @param validation true/false |
* @param validation true/false |
6872 |
*/ |
*/ |
6873 |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
6874 |
|
return(this->assignVALIDATION(idrun,(UInt_t)validation)); |
6875 |
|
} |
6876 |
|
|
6877 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){ |
6878 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
6879 |
stringstream oss; |
stringstream oss; |
6880 |
oss.str(""); |
oss.str(""); |
7071 |
stringstream myquery; |
stringstream myquery; |
7072 |
// |
// |
7073 |
myquery.str(""); |
myquery.str(""); |
7074 |
myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<<remfile.Data() <<"';"; |
myquery << " SELECT ID,ID_RAW,ID_TIMESYNC FROM GL_ROOT where NAME='"<<remfile.Data() <<"';"; |
7075 |
// |
// |
7076 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
7077 |
// |
// |
7087 |
// |
// |
7088 |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
7089 |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
7090 |
|
UInt_t idtsy=(UInt_t)atoll(Row->GetField(2)); |
7091 |
// |
// |
7092 |
this->ValidationOFF(); |
this->ValidationOFF(); |
7093 |
// |
// |
7095 |
// |
// |
7096 |
this->RemoveRUNS(); |
this->RemoveRUNS(); |
7097 |
// |
// |
7098 |
this->RemoveFILES(); |
this->RemoveFILES(idtsy); |
7099 |
// |
// |
7100 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
7101 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
7315 |
* Rearrange calibration tables |
* Rearrange calibration tables |
7316 |
* |
* |
7317 |
**/ |
**/ |
7318 |
void PamelaDBOperations::RemoveFILES(){ |
void PamelaDBOperations::RemoveFILES(UInt_t idtsy){ |
7319 |
stringstream myquery; |
stringstream myquery; |
7320 |
// |
// |
7321 |
myquery.str(""); |
myquery.str(""); |
7325 |
// |
// |
7326 |
conn->Query(myquery.str().c_str()); |
conn->Query(myquery.str().c_str()); |
7327 |
// |
// |
7328 |
|
myquery.str(""); |
7329 |
|
myquery << " DELETE FROM GL_ROOT WHERE ID=" <<this->GetID_ROOT() <<";"; |
7330 |
|
// |
7331 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
7332 |
|
// |
7333 |
|
conn->Query(myquery.str().c_str()); // |
7334 |
|
// |
7335 |
|
if ( !chewbacca ){ |
7336 |
|
myquery.str(""); |
7337 |
|
myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";"; |
7338 |
|
// |
7339 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
7340 |
|
// |
7341 |
|
conn->Query(myquery.str().c_str()); |
7342 |
|
}; |
7343 |
|
// |
7344 |
}; |
}; |
7345 |
|
|
7346 |
/** |
/** |
7545 |
* Rearrange calibration tables |
* Rearrange calibration tables |
7546 |
* |
* |
7547 |
**/ |
**/ |
7548 |
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh , TFile *file){ |
7549 |
|
|
7550 |
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
if(!caltrk) return 0; |
|
UInt_t timeaftercalib=120000; //2000; |
|
|
// ---------- |
|
|
// Check CRCs |
|
|
// ---------- |
|
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
|
|
if( caltrk->crc_hcal[ipkt] )return 0; // :-( |
|
|
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( |
|
|
} |
|
|
// ----------------------- |
|
|
// Check missing packets: |
|
|
// ----------------------- |
|
|
// Readout order: |
|
|
// ------------------ |
|
|
// DSP packet board |
|
|
// ------------------ |
|
|
// 12 0 1 |
|
|
// 10 1 1 |
|
|
// 8 2 1 |
|
|
// 4 3 1 |
|
|
// 6 4 1 |
|
|
// 2 5 1 |
|
|
// ------------------ |
|
|
// 11 0 2 |
|
|
// 9 1 2 |
|
|
// 7 2 2 |
|
|
// 3 3 2 |
|
|
// 5 4 2 |
|
|
// 1 5 2 |
|
|
// ------------------ |
|
|
// ------------------------------------------------- |
|
|
// Check if it is first or second calibration packet |
|
|
// ------------------------------------------------- |
|
|
UInt_t build=0; |
|
|
TString classname = caltrk->GetName(); |
|
|
UInt_t base=0; |
|
|
UInt_t mask=0; |
|
|
if(classname.Contains("CalibTrk1Event")){ |
|
|
base=12; |
|
|
mask=0x03F000; |
|
|
} |
|
|
if(classname.Contains("CalibTrk2Event")){ |
|
|
base=18; |
|
|
mask=0xFC0000; |
|
|
} |
|
|
// ------------------------------------------------- |
|
|
// Count number of packets and set build variable |
|
|
// ------------------------------------------------- |
|
|
Int_t npkts=0; |
|
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
|
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
|
|
npkts++; |
|
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
|
|
} |
|
|
} |
|
|
// if( npkts==6 )return 1; // :-) |
|
7551 |
|
|
7552 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
if ( IsDebug() ) cout << "ValidateTrkCalib:"<<endl; |
7553 |
|
|
7554 |
// ----------------------------------------------- |
UInt_t validate = 1; |
7555 |
// If missing packets: check the acq configuration |
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
7556 |
// (some DSPs might be excluded from acquisition) |
UInt_t timeaftercalib=120000; //2000; |
7557 |
// ----------------------------------------------- |
TString classname = caltrk->GetName(); |
7558 |
|
|
7559 |
// ----------------------------------------------- |
// ---------------------------------- |
7560 |
// retrieve the first run header after calib |
// Check CRCs and failed calibrations |
7561 |
// ----------------------------------------------- |
// ---------------------------------- |
7562 |
PacketType *pctp; |
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
7563 |
EventCounter *cod; |
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
7564 |
cod = eh->GetCounter(); |
if( caltrk->crc_hcal[ipkt] ){ |
7565 |
Int_t irun = cod->Get(pctp->RunHeader); |
// if(IsDebug())cout<<"(CRC Header)"; |
7566 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
validate = 0; |
7567 |
if ( !rh || rh->IsZombie() ) throw -17; |
if(IsDebug())cout <<endl<<" *** CRC *** (header DSPn "<<caltrk->DSPnumber[ipkt]<<")"; |
7568 |
if( rh->GetEntries() == irun ){ |
|
7569 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
} |
7570 |
return 0; // :-( |
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){ |
7571 |
} |
// if(IsDebug())cout<<"(CRC Pkt-"<<ilad<<")"; |
7572 |
|
if(IsDebug())cout <<endl<<" *** CRC *** (data DSPn "<<caltrk->DSPnumber[ipkt]<<" ladder "<<ilad<<")"; |
7573 |
|
validate = 0; |
7574 |
|
} |
7575 |
|
if( !(caltrk->ncalib_event[ipkt]==0 && caltrk->cal_flag[ipkt]==0) ){ |
7576 |
|
if(IsDebug())cout <<endl<<" *** FAILURE *** (data DSPn "<<caltrk->DSPnumber[ipkt]<<")"; |
7577 |
|
validate = 0; |
7578 |
|
} |
7579 |
|
}else{ |
7580 |
|
// validate=0; |
7581 |
|
if(IsDebug())cout <<endl<<" *** DSPn *** ("<< caltrk->DSPnumber[ipkt] <<" @pkt "<<ipkt<<")"; |
7582 |
|
} |
7583 |
|
} |
7584 |
|
|
7585 |
RunHeaderEvent *run = 0; |
// ----------------------- |
7586 |
EventHeader *hrun = 0; |
// Check missing packets: |
7587 |
rh->SetBranchAddress("RunHeader", &run); |
// ----------------------- |
7588 |
rh->SetBranchAddress("Header", &hrun); |
// Readout order: |
7589 |
rh->GetEntry(irun); |
// ------------------ |
7590 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
// DSP packet board |
7591 |
|
// ------------------ |
7592 |
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
// 12 0 1 |
7593 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
// 10 1 1 |
7594 |
return 0; // :-( |
// 8 2 1 |
7595 |
} |
// 4 3 1 |
7596 |
|
// 6 4 1 |
7597 |
if( !run->RM_ACQ_AFTER_CALIB ){ |
// 2 5 1 |
7598 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
// ------------------ |
7599 |
return 0; // :-( |
// 11 0 2 |
7600 |
} |
// 9 1 2 |
7601 |
|
// 7 2 2 |
7602 |
|
// 3 3 2 |
7603 |
|
// 5 4 2 |
7604 |
|
// 1 5 2 |
7605 |
|
// ------------------ |
7606 |
|
// ------------------------------------------------- |
7607 |
|
// Check if it is first or second calibration packet |
7608 |
|
// ------------------------------------------------- |
7609 |
|
UInt_t build=0; |
7610 |
|
UInt_t base=0; |
7611 |
|
UInt_t mask=0; |
7612 |
|
if(classname.Contains("CalibTrk1Event")){ |
7613 |
|
base=12; |
7614 |
|
mask=0x03F000; |
7615 |
|
} |
7616 |
|
if(classname.Contains("CalibTrk2Event")){ |
7617 |
|
base=18; |
7618 |
|
mask=0xFC0000; |
7619 |
|
} |
7620 |
|
// ---------------------------------------------------- |
7621 |
|
// Count number of valid packets and set build variable |
7622 |
|
// ---------------------------------------------------- |
7623 |
|
if(IsDebug())cout <<endl<< " DSP: "; |
7624 |
|
Int_t npkts=0; |
7625 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
7626 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
7627 |
|
if(IsDebug())cout <<" "<<caltrk->DSPnumber[ipkt]; |
7628 |
|
npkts++; |
7629 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
7630 |
|
// cout << caltrk->DSPnumber[ipkt] |
7631 |
|
}; |
7632 |
|
} |
7633 |
|
if(IsDebug())cout << " ==> "<< hex << build << dec; |
7634 |
|
// ---------------------------------------------------- |
7635 |
|
// If the number of valid packets is 6, ok exit... |
7636 |
|
// ---------------------------------------------------- |
7637 |
|
if( npkts==6 ){ |
7638 |
|
return validate; // exit |
7639 |
|
} |
7640 |
|
//////////////////////////////////////////////////////// |
7641 |
|
// ...otherwise there might be some missing packets |
7642 |
|
// |
7643 |
|
// In this case check the acq configuration |
7644 |
|
// (some DSPs might be excluded from acquisition) |
7645 |
|
//////////////////////////////////////////////////////// |
7646 |
|
|
7647 |
|
if(!eh || !file || (file&&file->IsZombie()) ){ |
7648 |
|
if ( IsDebug() )cout << " *** MISSING VIEW *** eh="<<eh<<" file="<<file<<" cannot validate"<<endl; |
7649 |
|
return (0); |
7650 |
|
} |
7651 |
|
|
7652 |
|
// ----------------------------------------------- |
7653 |
|
// retrieve the first run header after calib |
7654 |
|
// ----------------------------------------------- |
7655 |
|
|
7656 |
|
PacketType *pctp; |
7657 |
|
EventCounter *cod; |
7658 |
|
cod = eh->GetCounter(); |
7659 |
|
Int_t irun = cod->Get(pctp->RunHeader); |
7660 |
|
TTree *rh=(TTree*)file->Get("RunHeader"); |
7661 |
|
if ( !rh || rh->IsZombie() ) throw -17; |
7662 |
|
if( rh->GetEntries() <= irun ){ |
7663 |
|
if ( IsDebug() ) cout << " *** MISSING-PKT *** no runs after calib (1) -- cannot validate :-( "<<endl; |
7664 |
|
return 0; // :-( |
7665 |
|
} |
7666 |
|
RunHeaderEvent *run = 0; |
7667 |
|
EventHeader *hrun = 0; |
7668 |
|
rh->SetBranchAddress("RunHeader", &run); |
7669 |
|
rh->SetBranchAddress("Header", &hrun); |
7670 |
|
rh->GetEntry(irun); |
7671 |
|
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
7672 |
|
if ( IsDebug() ) cout << " *** MISSING-PKT *** no runs after calib (2) -- cannot validate :-( "<<endl; |
7673 |
|
return 0; // :-( |
7674 |
|
} |
7675 |
|
|
7676 |
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
7677 |
if( dtime > timeaftercalib ){ |
if( dtime > timeaftercalib ){ |
7678 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
if ( IsDebug() ) cout << " *** MISSING-PKT *** run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
7679 |
return 0; // :-( |
return 0; // :-( |
7680 |
} |
} |
|
|
|
7681 |
|
|
7682 |
|
if ( IsDebug() ) cout <<endl<< " ACQ_BUILD_INFO ==> "<<hex<<(run->ACQ_BUILD_INFO & mask)<<dec; |
7683 |
|
|
7684 |
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
7685 |
|
validate=0; // :-( |
7686 |
|
cout <<endl<< " *** MISSING-PKT *** packet mismatch: ACQ_BUILD_INFO="<<hex<<(run->ACQ_BUILD_INFO&mask)<<" != "<<build<<dec; |
7687 |
|
}; |
7688 |
|
|
7689 |
|
return validate; |
7690 |
|
|
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
|
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
|
|
return 0; // :-( |
|
|
} |
|
|
return 1; // :-) |
|
7691 |
|
|
7692 |
} |
} |
7693 |
|
|