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, Bool_t keepenv){ |
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; |
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 |
// |
// |
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,INSERTED_BY 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 ){ |
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)); |
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 ){ |
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)); |
469 |
if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data()); |
if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data()); |
470 |
return; |
return; |
471 |
}; |
}; |
472 |
TString dwo = 0; |
TString dwo = ""; |
473 |
for (Int_t i = 0; i<5; i++){ |
for (Int_t i = 0; i<5; i++){ |
474 |
dwo.Append(name[i],1); |
dwo.Append(name[i],1); |
475 |
}; |
}; |
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)); |
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); |
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; |
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 ){ |
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(); |
2467 |
// if ( conptt+1 == (nrtev+nrtbef )){ |
// if ( conptt+1 == (nrtev+nrtbef )){ |
2468 |
if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); |
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++; |
//pth++; |
2473 |
//if ( pth < rhev ){ |
//if ( pth < rhev ){ |
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 |
|
if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here! |
2500 |
// rt->GetEntry(ptt-1); |
// rt->GetEntry(ptt-1); |
2501 |
rt->GetEntry(rtev-1); |
rt->GetEntry(rtev-1); |
2502 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
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 |
|
// 093012 [8RED (-70): RUN ALREADY INSERTED] try to be more general... the run has not been instered yet if the runheader-trailer PKT interval is not covered by already inserted runs, NOTICE: we must look in the GL_RUN_TRASH table! |
3245 |
|
// |
3246 |
|
Bool_t OK = false; |
3247 |
|
UInt_t IDRL2A = 0; |
3248 |
|
UInt_t IDRL2B = 0; |
3249 |
|
if ( chewbacca ){ |
3250 |
|
if ( result->GetRowCount() >= 2 ){ |
3251 |
|
// |
3252 |
|
if ( IsDebug() ) printf(" RH---| gap |---RT case, number of pieces in the GL_RUN table: %i \n",result->GetRowCount()); |
3253 |
|
OK = true; |
3254 |
|
IDRL2A = (UInt_t)atoll(row->GetField(0)); |
3255 |
|
// |
3256 |
|
while ( row ){ |
3257 |
|
// |
3258 |
|
TSQLResult *trresult = 0; |
3259 |
|
TSQLRow *trrow = 0; |
3260 |
|
// |
3261 |
|
stringstream tross; |
3262 |
|
tross.str(""); |
3263 |
|
// |
3264 |
|
tross << " SELECT RUNHEADER_PKT, RUNTRAILER_PKT FROM GL_RUN_TRASH where ID=" << row->GetField(0) << ";"; |
3265 |
|
if ( IsDebug() ) printf(" check in the gl_run_trash table for pkt intervals: query is \n %s \n",tross.str().c_str()); |
3266 |
|
trresult = conn->Query(tross.str().c_str()); |
3267 |
|
if ( !trresult ) throw -4; |
3268 |
|
trrow = trresult->Next(); |
3269 |
|
if ( !trrow || trresult->GetRowCount() != 1 ){ |
3270 |
|
OK = false; |
3271 |
|
if ( IsDebug() ) printf(" OPS! no such run (or multiple runs!) in GL_RUN_TRASH table, something wrong is going on! \n"); |
3272 |
|
break; |
3273 |
|
}; |
3274 |
|
// |
3275 |
|
UInt_t pktH = (UInt_t)atoll(row->GetField(0)); |
3276 |
|
UInt_t pktT = (UInt_t)atoll(row->GetField(1)); |
3277 |
|
delete trresult; |
3278 |
|
if ( |
3279 |
|
(PKT(pktH) >= PKT(glrun->GetRUNHEADER_PKT()) && PKT(pktH) <= PKT(glrun->GetRUNTRAILER_PKT())) || |
3280 |
|
(PKT(pktT) >= PKT(glrun->GetRUNHEADER_PKT()) && PKT(pktT) <= PKT(glrun->GetRUNTRAILER_PKT())) || |
3281 |
|
(PKT(pktH) <= PKT(glrun->GetRUNTRAILER_PKT()) && PKT(pktT) >= PKT(glrun->GetRUNTRAILER_PKT())) ){ |
3282 |
|
OK = false; |
3283 |
|
if ( IsDebug() ) printf(" The run is overlapping with already inserted ones!! \n"); |
3284 |
|
break; |
3285 |
|
}; |
3286 |
|
//PKT(glrun->GetRUNHEADER_PKT()) PKT(glrun->GetRUNTRAILER_PKT()) |
3287 |
|
row = result->Next(); |
3288 |
|
}; |
3289 |
|
|
3290 |
|
// if ( result->GetRowCount() == 2 ) { |
3291 |
|
// IDRL2A = (UInt_t)atoll(row->GetField(0)); |
3292 |
|
// UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1)); |
3293 |
|
// row = result->Next(); |
3294 |
|
// IDRL2B = (UInt_t)atoll(row->GetField(0)); |
3295 |
|
// UInt_t IDRL0B = (UInt_t)atoll(row->GetField(1)); |
3296 |
|
// if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B); |
3297 |
|
// // if ( IDRL0A == IDRL0B ){ //091230 why this condition???? RH could be in a file and RT in another one... |
3298 |
|
// if ( true ){ |
3299 |
|
// TSQLResult *result2 = 0; |
3300 |
|
// TSQLRow *row2 = 0; |
3301 |
|
// oss.str(""); |
3302 |
|
// oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;"; |
3303 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
3304 |
|
// result2 = conn->Query(oss.str().c_str()); |
3305 |
|
// // |
3306 |
|
// if ( !result2 ) throw -4; |
3307 |
|
// // |
3308 |
|
// row2 = result2->Next(); |
3309 |
|
// // |
3310 |
|
// if ( row2 ){ |
3311 |
|
// UInt_t PKA = (UInt_t)atoll(row2->GetField(0)); |
3312 |
|
// delete result2; |
3313 |
|
// oss.str(""); |
3314 |
|
// oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;"; |
3315 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
3316 |
|
// result2 = conn->Query(oss.str().c_str()); |
3317 |
|
// // |
3318 |
|
// if ( !result2 ) throw -4; |
3319 |
|
// // |
3320 |
|
// row2 = result2->Next(); |
3321 |
|
// // |
3322 |
|
// if ( row2 ){ |
3323 |
|
// UInt_t PKB = (UInt_t)atoll(row2->GetField(0)); |
3324 |
|
// // |
3325 |
|
// 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); |
3326 |
|
// if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){ |
3327 |
|
// if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); |
3328 |
|
// OK = true; |
3329 |
|
// }; |
3330 |
|
// }; |
3331 |
|
// }; |
3332 |
|
// }; |
3333 |
|
// }; |
3334 |
|
}; |
3335 |
|
}; |
3336 |
|
if ( OK ){ |
3337 |
|
// |
3338 |
|
// this is the case in which we must insert a piece of run between two fragments in the GL_RUN table // we arrive here ONLY with internal pieces of runs, never runheader or runtrailer by definition |
3339 |
|
// |
3340 |
|
// 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 ) |
3341 |
|
// |
3342 |
|
if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); |
3343 |
|
// |
3344 |
|
GL_RUN *glA = new GL_RUN(); |
3345 |
|
glA->Query_GL_RUN(IDRL2A,conn); |
3346 |
|
// |
3347 |
|
glrun->SetRUNHEADER_TIME(glA->GetRUNHEADER_TIME()); |
3348 |
|
glrun->SetRUNHEADER_OBT(glA->GetRUNHEADER_OBT()); |
3349 |
|
glrun->SetRUNHEADER_PKT(glA->GetRUNHEADER_PKT()); |
3350 |
|
// |
3351 |
|
glrun->SetRUNTRAILER_TIME(glA->GetRUNTRAILER_TIME()); |
3352 |
|
glrun->SetRUNTRAILER_OBT(glA->GetRUNTRAILER_OBT()); |
3353 |
|
glrun->SetRUNTRAILER_PKT(glA->GetRUNTRAILER_PKT()); |
3354 |
|
// |
3355 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) glrun->SetPHYSENDRUN_MASK_S3S2S12(glA->GetPHYSENDRUN_MASK_S3S2S12()); |
3356 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) glrun->SetPHYSENDRUN_MASK_S11CRC(glA->GetPHYSENDRUN_MASK_S11CRC()); |
3357 |
|
// |
3358 |
|
if ( glA->GetACQ_BUILD_INFO() != 0 ){ |
3359 |
|
// |
3360 |
|
// the first piece contains a good runheader we can update all the other runs with correct infos! |
3361 |
|
// |
3362 |
|
glrun->SetCOMPILATIONTIMESTAMP(glA->GetCOMPILATIONTIMESTAMP()); |
3363 |
|
glrun->SetFAV_WRK_SCHEDULE(glA->GetFAV_WRK_SCHEDULE()); |
3364 |
|
glrun->SetEFF_WRK_SCHEDULE(glA->GetEFF_WRK_SCHEDULE()); |
3365 |
|
glrun->SetPRH_VAR_TRG_MODE_A(glA->GetPRH_VAR_TRG_MODE_A()); |
3366 |
|
glrun->SetPRH_VAR_TRG_MODE_B(glA->GetPRH_VAR_TRG_MODE_B()); |
3367 |
|
glrun->SetACQ_BUILD_INFO(glA->GetACQ_BUILD_INFO()); |
3368 |
|
glrun->SetACQ_VAR_INFO(glA->GetACQ_VAR_INFO()); |
3369 |
|
glrun->SetRM_ACQ_AFTER_CALIB(glA->GetRM_ACQ_AFTER_CALIB()); |
3370 |
|
glrun->SetRM_ACQ_SETTING_MODE(glA->GetRM_ACQ_SETTING_MODE()); |
3371 |
|
glrun->SetTRK_CALIB_USED(glA->GetTRK_CALIB_USED()); |
3372 |
|
glrun->SetCAL_DSP_MASK(glA->GetCAL_DSP_MASK()); |
3373 |
|
glrun->SetLAST_TIMESYNC(glA->GetLAST_TIMESYNC()); |
3374 |
|
glrun->SetOBT_TIMESYNC(glA->GetOBT_TIMESYNC()); |
3375 |
|
// |
3376 |
|
}; |
3377 |
|
// |
3378 |
|
if ( glA->GetPKT_READY_COUNTER() != 0 ){ |
3379 |
|
// |
3380 |
|
// the first piece contains a good runtrailer we can update all the other runs with correct infos! |
3381 |
|
// |
3382 |
|
glrun->SetPKT_COUNTER(glA->GetPKT_COUNTER()); |
3383 |
|
glrun->SetPKT_READY_COUNTER(glA->GetPKT_READY_COUNTER()); |
3384 |
|
}; |
3385 |
|
// |
3386 |
|
// update runheader ROOT_ID_FRAG |
3387 |
|
// |
3388 |
|
oss.str(""); |
3389 |
|
oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; |
3390 |
|
if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
3391 |
|
conn->Query(oss.str().c_str()); |
3392 |
|
// |
3393 |
|
oss.str(""); |
3394 |
|
oss << "SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG = " << IDRL2A << ";"; |
3395 |
|
if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
3396 |
|
TSQLResult *tsresult = 0; |
3397 |
|
TSQLRow *tsrow = 0; |
3398 |
|
tsresult=conn->Query(oss.str().c_str()); |
3399 |
|
if ( !tsresult ) throw -4; |
3400 |
|
tsrow = tsresult->Next(); |
3401 |
|
if ( !tsrow || tsresult->GetRowCount() != 1 ) throw -4; |
3402 |
|
IDRL2B = (UInt_t)atoll(tsrow->GetField(0)); |
3403 |
|
glrun->SetID_RUN_FRAG(IDRL2B); |
3404 |
|
// |
3405 |
|
// fill the new run in GL_RUN |
3406 |
|
// |
3407 |
|
glrun->Fill_GL_RUN(conn); |
3408 |
|
// |
3409 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
3410 |
|
delete glA; |
3411 |
|
// |
3412 |
|
} else { |
3413 |
|
// // |
3414 |
|
// // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table |
3415 |
|
// // |
3416 |
|
// // 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 ) |
3417 |
|
// // |
3418 |
|
// GL_RUN *glA = new GL_RUN(); |
3419 |
|
// glA->Query_GL_RUN(IDRL2A,conn); |
3420 |
|
// // |
3421 |
|
// if ( glA->GetACQ_BUILD_INFO() != 0 ){ |
3422 |
|
// // |
3423 |
|
// // the first piece contains a good runheader we can update all the other runs with correct infos! |
3424 |
|
// // |
3425 |
|
// oss.str(""); |
3426 |
|
// oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3427 |
|
// << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , " |
3428 |
|
// << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
3429 |
|
// << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , " |
3430 |
|
// << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , " |
3431 |
|
// << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , " |
3432 |
|
// << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , " |
3433 |
|
// << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , " |
3434 |
|
// << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , " |
3435 |
|
// << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , " |
3436 |
|
// << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , " |
3437 |
|
// << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , " |
3438 |
|
// << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , " |
3439 |
|
// << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , " |
3440 |
|
// << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , " |
3441 |
|
// << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , "; |
3442 |
|
// // |
3443 |
|
// if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
3444 |
|
// oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , "; |
3445 |
|
// if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
3446 |
|
// oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , "; |
3447 |
|
// // |
3448 |
|
// oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC(); |
3449 |
|
// oss << " WHERE ID=" << glrun->GetID() << ";"; |
3450 |
|
// if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str()); |
3451 |
|
// conn->Query(oss.str().c_str()); |
3452 |
|
// // |
3453 |
|
// } else { |
3454 |
|
// // |
3455 |
|
// // sig no runheader, let set anyway what is possible... |
3456 |
|
// // |
3457 |
|
// oss.str(""); |
3458 |
|
// oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3459 |
|
// << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "; |
3460 |
|
// // |
3461 |
|
// if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
3462 |
|
// oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; |
3463 |
|
// if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
3464 |
|
// oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
3465 |
|
// // |
3466 |
|
// oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
3467 |
|
// << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT(); |
3468 |
|
// oss << " WHERE ID=" << glrun->GetID() << ";"; |
3469 |
|
// if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str()); |
3470 |
|
// conn->Query(oss.str().c_str()); |
3471 |
|
// }; |
3472 |
|
// // |
3473 |
|
// // update runheader ROOT_ID_FRAG |
3474 |
|
// // |
3475 |
|
// oss.str(""); |
3476 |
|
// oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; |
3477 |
|
// if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
3478 |
|
// conn->Query(oss.str().c_str()); |
3479 |
|
// // |
3480 |
|
// // now let's look for runtrailer if any in the last run |
3481 |
|
// // |
3482 |
|
// glA->Query_GL_RUN(IDRL2B,conn); |
3483 |
|
// // |
3484 |
|
// if ( glA->GetPKT_READY_COUNTER() != 0 ){ |
3485 |
|
// // |
3486 |
|
// // the first piece contains a good runtrailer we can update all the other runs with correct infos! |
3487 |
|
// // |
3488 |
|
// oss.str(""); |
3489 |
|
// oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3490 |
|
// << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
3491 |
|
// << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , " |
3492 |
|
// << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , " |
3493 |
|
// << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , "; |
3494 |
|
// // |
3495 |
|
// if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
3496 |
|
// oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
3497 |
|
// if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) { |
3498 |
|
// oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
3499 |
|
// // |
3500 |
|
// oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER() |
3501 |
|
// << " WHERE ID=" << glrun->GetID() << ";"; |
3502 |
|
// if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str()); |
3503 |
|
// conn->Query(oss.str().c_str()); |
3504 |
|
// // |
3505 |
|
// } else { |
3506 |
|
// // |
3507 |
|
// // sig no runtrailer, let set anyway what is possible... |
3508 |
|
// // |
3509 |
|
// oss.str(""); |
3510 |
|
// oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3511 |
|
// << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
3512 |
|
// << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "; |
3513 |
|
// // |
3514 |
|
// if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
3515 |
|
// oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
3516 |
|
// if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){ |
3517 |
|
// oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
3518 |
|
// // |
3519 |
|
// oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT() |
3520 |
|
// << " WHERE ID=" << glrun->GetID() << ";"; |
3521 |
|
// if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str()); |
3522 |
|
// conn->Query(oss.str().c_str()); |
3523 |
|
// }; |
3524 |
|
// // |
3525 |
|
// UInt_t myi = glrun->GetID(); |
3526 |
|
// oss.str(""); |
3527 |
|
// oss << " ID= "<< myi; |
3528 |
|
// // |
3529 |
|
// glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
3530 |
|
// // |
3531 |
|
// // fill the new run in GL_RUN |
3532 |
|
// // |
3533 |
|
// glrun->SetID_RUN_FRAG(IDRL2B); |
3534 |
|
// glrun->Fill_GL_RUN(conn); |
3535 |
|
// glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
3536 |
|
// delete glA; |
3537 |
|
// // |
3538 |
|
// } else { |
3539 |
|
// |
3540 |
|
// is just a repetition |
3541 |
|
// |
3542 |
|
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
3543 |
|
if ( PEDANTIC ) throw -70; |
3544 |
|
}; |
3545 |
|
// |
3546 |
} else { |
} else { |
3547 |
if ( NoFrag() ){ |
if ( NoFrag() ){ |
3548 |
glrun->SetID_RUN_FRAG(glrun->GetID()); |
glrun->SetID_RUN_FRAG(glrun->GetID()); |
3579 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
3580 |
glrun->SetID_RUN_FRAG(0); |
glrun->SetID_RUN_FRAG(0); |
3581 |
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... |
3582 |
}; |
}; |
3583 |
// |
// |
3584 |
}; |
}; |
3585 |
// |
// |
3623 |
if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! |
if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! |
3624 |
//if ( firstev <= lastev+1 ) { // no events inside the run! |
//if ( firstev <= lastev+1 ) { // no events inside the run! |
3625 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
3626 |
|
firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files |
3627 |
// return true is correct |
// return true is correct |
3628 |
return(true); |
return(true); |
3629 |
// |
// |
3879 |
// |
// |
3880 |
found = false; // default value |
found = false; // default value |
3881 |
// |
// |
3882 |
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"); |
3883 |
// |
// |
3884 |
// 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: |
3885 |
// |
// |
4397 |
UInt_t totime = 0; |
UInt_t totime = 0; |
4398 |
UInt_t obt = 0; |
UInt_t obt = 0; |
4399 |
UInt_t pkt = 0; |
UInt_t pkt = 0; |
4400 |
|
Float_t totped = 0.; |
4401 |
// |
// |
4402 |
tr = (TTree*)file->Get("CalibCalPed"); |
tr = (TTree*)file->Get("CalibCalPed"); |
4403 |
if ( !tr || tr->IsZombie() ) throw -21; |
if ( !tr || tr->IsZombie() ) throw -21; |
4415 |
if ( calibCalPed->cstwerr[section] ){ |
if ( calibCalPed->cstwerr[section] ){ |
4416 |
valid = 1; |
valid = 1; |
4417 |
if ( calibCalPed->cperror[section] ) valid = 0; |
if ( calibCalPed->cperror[section] ) valid = 0; |
4418 |
|
// |
4419 |
|
// 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.] |
4420 |
|
// |
4421 |
|
totped = 0.; |
4422 |
|
Int_t ns = 0; |
4423 |
|
if ( section == 2 ) ns = 3; |
4424 |
|
if ( section == 3 ) ns = 1; |
4425 |
|
if ( section == 1 ) ns = 2; |
4426 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4427 |
|
totped += fabs(calibCalPed->calped[ns][0][ss]); |
4428 |
|
} |
4429 |
|
if ( totped < 1. ){ |
4430 |
|
if ( IsDebug() ) printf(" Section %i totped %f - No calibration data! Calorimeter power problems? \n",section,totped); |
4431 |
|
valid = 0; |
4432 |
|
}; |
4433 |
|
// |
4434 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
4435 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
4436 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
4598 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
4599 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
4600 |
// |
// |
4601 |
|
Float_t totpul = 0.; |
4602 |
|
// |
4603 |
if ( nevents > 0 ){ |
if ( nevents > 0 ){ |
4604 |
// |
// |
4605 |
for (UInt_t i=0; i < nevents; i++){ |
for (UInt_t i=0; i < nevents; i++){ |
4609 |
if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){ |
if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){ |
4610 |
valid = 1; |
valid = 1; |
4611 |
if ( cp1->pperror[section] ) valid = 0; |
if ( cp1->pperror[section] ) valid = 0; |
4612 |
|
// |
4613 |
|
// 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.] |
4614 |
|
// |
4615 |
|
totpul = 0.; |
4616 |
|
Int_t ns = 0; |
4617 |
|
if ( section == 2 ) ns = 3; |
4618 |
|
if ( section == 3 ) ns = 1; |
4619 |
|
if ( section == 1 ) ns = 2; |
4620 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4621 |
|
totpul += cp1->calpuls[ns][0][ss]; |
4622 |
|
} |
4623 |
|
if ( totpul >= 3145632. ){ |
4624 |
|
if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f - No calibration data! Calorimeter power problems? \n",section,totpul); |
4625 |
|
valid = 0; |
4626 |
|
}; |
4627 |
|
// |
4628 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
4629 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
4630 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
4782 |
if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){ |
if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){ |
4783 |
valid = 1; |
valid = 1; |
4784 |
if ( cp2->pperror[section] ) valid = 0; |
if ( cp2->pperror[section] ) valid = 0; |
4785 |
|
// |
4786 |
|
// 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.] |
4787 |
|
// |
4788 |
|
totpul = 0.; |
4789 |
|
Int_t ns = 0; |
4790 |
|
if ( section == 2 ) ns = 3; |
4791 |
|
if ( section == 3 ) ns = 1; |
4792 |
|
if ( section == 1 ) ns = 2; |
4793 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4794 |
|
totpul += cp2->calpuls[ns][0][ss]; |
4795 |
|
} |
4796 |
|
if ( totpul >= 3145632. ){ |
4797 |
|
if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f - No calibration data! Calorimeter power problems? \n",section,totpul); |
4798 |
|
valid = 0; |
4799 |
|
}; |
4800 |
|
// |
4801 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
4802 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
4803 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
5163 |
if ( !result ) throw -4;; |
if ( !result ) throw -4;; |
5164 |
row = result->Next(); |
row = result->Next(); |
5165 |
if(row)glcal->ID = (UInt_t)atoll(row->GetField(0)); |
if(row)glcal->ID = (UInt_t)atoll(row->GetField(0)); |
5166 |
|
// |
5167 |
|
delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5168 |
// |
// |
5169 |
}; |
}; |
5170 |
|
|
5672 |
|
|
5673 |
if(FOUND){ |
if(FOUND){ |
5674 |
|
|
5675 |
if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl; |
if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl; |
|
|
|
|
//////////////////////////////////////////// |
|
|
// insert a new entry in GL_TRK_CALIB and |
|
|
// modify the time-tag of the previous one |
|
|
//////////////////////////////////////////// |
|
5676 |
|
|
5677 |
// --------------------------------------------------------------------- |
//////////////////////////////////////////// |
5678 |
// step 1: insert a new raw file in GL_RAW |
// insert a new entry in GL_TRK_CALIB and |
5679 |
// --------------------------------------------------------------------- |
// modify the time-tag of the previous one |
5680 |
// |
//////////////////////////////////////////// |
5681 |
// check if the raw file already exist |
|
5682 |
// |
// --------------------------------------------------------------------- |
5683 |
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 |
// step 1: insert a new raw file in GL_RAW |
5684 |
// oss.str(""); |
// --------------------------------------------------------------------- |
5685 |
// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
// |
5686 |
// if ( IsDebug() ) cout << oss.str().c_str() << endl; |
// check if the raw file already exist |
5687 |
|
// |
5688 |
|
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 |
5689 |
|
// oss.str(""); |
5690 |
|
// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
5691 |
|
// if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5692 |
|
|
5693 |
// result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
5694 |
// if ( !result ) throw -4;; |
// if ( !result ) throw -4;; |
5695 |
// if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
// if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5696 |
// if( result->GetRowCount() == 0){ |
// if( result->GetRowCount() == 0){ |
5697 |
// if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
// if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
5698 |
// // - - - - - - - - - - - |
// // - - - - - - - - - - - |
5699 |
// // insert new raw file |
// // insert new raw file |
5700 |
// // - - - - - - - - - - - |
// // - - - - - - - - - - - |
5701 |
// GL_RAW glraw = GL_RAW(); |
// GL_RAW glraw = GL_RAW(); |
5702 |
// glraw.PATH = gSystem->DirName(raw.Data()); |
// glraw.PATH = gSystem->DirName(raw.Data()); |
5703 |
// glraw.NAME = gSystem->BaseName(raw.Data()); |
// glraw.NAME = gSystem->BaseName(raw.Data()); |
5704 |
// glraw.BOOT_NUMBER = boot_number; |
// glraw.BOOT_NUMBER = boot_number; |
5705 |
// // |
// // |
5706 |
// insertPamelaRawFile( &glraw ); |
// insertPamelaRawFile( &glraw ); |
5707 |
// // |
// // |
5708 |
// id_raw = glraw.ID; |
// id_raw = glraw.ID; |
5709 |
// }else{ |
// }else{ |
5710 |
// row = result->Next(); |
// row = result->Next(); |
5711 |
// id_raw = (UInt_t)atoll(row->GetField(0)); |
// id_raw = (UInt_t)atoll(row->GetField(0)); |
5712 |
// } |
// } |
5713 |
// if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
// if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
5714 |
|
|
5715 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5716 |
// step 1(bis): retrieve the timesync id associated to the file |
// step 1(bis): retrieve the timesync id associated to the file |
5717 |
// (NB, uso lo stesso associato al file iniziale) |
// (NB, uso lo stesso associato al file iniziale) |
5718 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5719 |
UInt_t idtimesync = 0; |
UInt_t idtimesync = 0; |
5720 |
oss.str(""); |
oss.str(""); |
5721 |
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
5722 |
if ( debug ) printf(" %s \n",oss.str().c_str()); |
if ( debug ) printf(" %s \n",oss.str().c_str()); |
5723 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
5724 |
if ( !result ) throw -3; |
if ( !result ) throw -3; |
5725 |
row = result->Next(); |
row = result->Next(); |
5726 |
if ( !row ) throw -3; |
if ( !row ) throw -3; |
5727 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
5728 |
if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl; |
if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl; |
5729 |
|
|
5730 |
|
delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5731 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5732 |
// step 2: insert a new root file in GL_ROOT |
// step 2: insert a new root file in GL_ROOT |
5733 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5775 |
} |
} |
5776 |
if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl; |
if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl; |
5777 |
|
|
5778 |
|
delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5779 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5780 |
// step 3: modify time-tag of corrupted GL_TRK_CALIB entry |
// step 3: modify time-tag of corrupted GL_TRK_CALIB entry |
5781 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5788 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
5789 |
if ( !result ) throw -4;; |
if ( !result ) throw -4;; |
5790 |
|
|
5791 |
|
delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5792 |
|
|
5793 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5794 |
// step 4: insert the new calibration: |
// step 4: insert the new calibration: |
5795 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
6241 |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
6242 |
// |
// |
6243 |
oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " |
oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " |
6244 |
<< " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT()<< ";"; |
<< " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT(); |
6245 |
|
oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112 |
6246 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
6247 |
}; |
}; |
6248 |
}; |
}; |
6291 |
if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){ |
if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){ |
6292 |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6293 |
// |
// |
6294 |
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";"; |
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT(); |
6295 |
|
oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112 |
6296 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
6297 |
}; |
}; |
6298 |
}; |
}; |
6343 |
row2 = result2->Next(); |
row2 = result2->Next(); |
6344 |
// |
// |
6345 |
if ( row2 ){ |
if ( row2 ){ |
6346 |
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"); |
6347 |
if ( PEDANTIC ) throw -83; |
if ( PEDANTIC ) throw -83; |
6348 |
row2->Close(); |
row2->Close(); |
6349 |
}; |
}; |
6420 |
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
6421 |
// |
// |
6422 |
oss.str(""); |
oss.str(""); |
6423 |
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 " |
6424 |
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
6425 |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
6426 |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
6478 |
moved++; |
moved++; |
6479 |
// |
// |
6480 |
} else { |
} else { |
6481 |
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
|
6482 |
if ( PEDANTIC ) throw -83; |
// questa parte mah mah mah... da controllare |
6483 |
|
|
6484 |
|
// |
6485 |
|
// 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 |
6486 |
|
// "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number. |
6487 |
|
// |
6488 |
|
// 090112 [8RED (-70): RUN ALREADY INSERTED] |
6489 |
|
// |
6490 |
|
Bool_t OK = false; |
6491 |
|
UInt_t IDRL2A = 0; |
6492 |
|
UInt_t IDRL2B = 0; |
6493 |
|
if ( result2->GetRowCount() == 2 ){ |
6494 |
|
IDRL2A = (UInt_t)atoll(row2->GetField(0)); |
6495 |
|
UInt_t IDRL0A = (UInt_t)atoll(row2->GetField(4)); |
6496 |
|
row2 = result2->Next(); |
6497 |
|
IDRL2B = (UInt_t)atoll(row2->GetField(0)); |
6498 |
|
UInt_t IDRL0B = (UInt_t)atoll(row2->GetField(4)); |
6499 |
|
if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B); |
6500 |
|
// if ( IDRL0A == IDRL0B ){ |
6501 |
|
// TSQLResult *result2a = 0; |
6502 |
|
// TSQLRow *row2a = 0; |
6503 |
|
// oss.str(""); |
6504 |
|
// oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;"; |
6505 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
6506 |
|
// result2a = conn->Query(oss.str().c_str()); |
6507 |
|
// // |
6508 |
|
// if ( !result2a ) throw -4; |
6509 |
|
// // |
6510 |
|
// row2a = result2a->Next(); |
6511 |
|
// // |
6512 |
|
// if ( row2a ){ |
6513 |
|
// UInt_t PKA = (UInt_t)atoll(row2a->GetField(0)); |
6514 |
|
// delete result2a; |
6515 |
|
// oss.str(""); |
6516 |
|
// oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;"; |
6517 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
6518 |
|
// result2a = conn->Query(oss.str().c_str()); |
6519 |
|
// // |
6520 |
|
// if ( !result2a ) throw -4; |
6521 |
|
// // |
6522 |
|
// row2a = result2a->Next(); |
6523 |
|
// // |
6524 |
|
// if ( row2a ){ |
6525 |
|
// UInt_t PKB = (UInt_t)atoll(row2a->GetField(0)); |
6526 |
|
// // |
6527 |
|
// 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); |
6528 |
|
// if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){ |
6529 |
|
// if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); |
6530 |
|
OK = true; |
6531 |
|
// }; |
6532 |
|
// }; |
6533 |
|
// }; |
6534 |
|
// }; |
6535 |
|
}; |
6536 |
|
if ( OK ){ |
6537 |
|
// |
6538 |
|
// this is the case in which we must insert a piece of run between two fragments in the GL_RUN table |
6539 |
|
// |
6540 |
|
// 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 ) |
6541 |
|
// |
6542 |
|
GL_RUN *glA = new GL_RUN(); |
6543 |
|
glA->Query_GL_RUN(IDRL2A,conn); |
6544 |
|
// |
6545 |
|
if ( glA->GetACQ_BUILD_INFO() != 0 ){ |
6546 |
|
// |
6547 |
|
// the first piece contains a good runheader we can update all the other runs with correct infos! |
6548 |
|
// |
6549 |
|
oss.str(""); |
6550 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6551 |
|
<< " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , " |
6552 |
|
<< " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
6553 |
|
<< " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , " |
6554 |
|
<< " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , " |
6555 |
|
<< " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , " |
6556 |
|
<< " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , " |
6557 |
|
<< " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , " |
6558 |
|
<< " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , " |
6559 |
|
<< " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , " |
6560 |
|
<< " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , " |
6561 |
|
<< " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , " |
6562 |
|
<< " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , " |
6563 |
|
<< " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , " |
6564 |
|
<< " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , " |
6565 |
|
<< " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , "; |
6566 |
|
// |
6567 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
6568 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , "; |
6569 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
6570 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , "; |
6571 |
|
// |
6572 |
|
oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC(); |
6573 |
|
oss << " WHERE ID=" << glrun->GetID() << ";"; |
6574 |
|
if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str()); |
6575 |
|
conn->Query(oss.str().c_str()); |
6576 |
|
// |
6577 |
|
} else { |
6578 |
|
// |
6579 |
|
// sig no runheader, let set anyway what is possible... |
6580 |
|
// |
6581 |
|
oss.str(""); |
6582 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6583 |
|
<< " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "; |
6584 |
|
// |
6585 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
6586 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; |
6587 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
6588 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
6589 |
|
// |
6590 |
|
oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
6591 |
|
<< " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT(); |
6592 |
|
oss << " WHERE ID=" << glrun->GetID() << ";"; |
6593 |
|
if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str()); |
6594 |
|
conn->Query(oss.str().c_str()); |
6595 |
|
}; |
6596 |
|
// |
6597 |
|
// update runheader ROOT_ID_FRAG |
6598 |
|
// |
6599 |
|
oss.str(""); |
6600 |
|
oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; |
6601 |
|
if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
6602 |
|
conn->Query(oss.str().c_str()); |
6603 |
|
// |
6604 |
|
// now let's look for runtrailer if any in the last run |
6605 |
|
// |
6606 |
|
glA->Query_GL_RUN(IDRL2B,conn); |
6607 |
|
// |
6608 |
|
if ( glA->GetPKT_READY_COUNTER() != 0 ){ |
6609 |
|
// |
6610 |
|
// the first piece contains a good runtrailer we can update all the other runs with correct infos! |
6611 |
|
// |
6612 |
|
oss.str(""); |
6613 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6614 |
|
<< " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
6615 |
|
<< " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , " |
6616 |
|
<< " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , " |
6617 |
|
<< " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , "; |
6618 |
|
// |
6619 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
6620 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
6621 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) { |
6622 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6623 |
|
// |
6624 |
|
oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER() |
6625 |
|
<< " WHERE ID=" << glrun->GetID() << ";"; |
6626 |
|
if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str()); |
6627 |
|
conn->Query(oss.str().c_str()); |
6628 |
|
// |
6629 |
|
} else { |
6630 |
|
// |
6631 |
|
// sig no runtrailer, let set anyway what is possible... |
6632 |
|
// |
6633 |
|
oss.str(""); |
6634 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6635 |
|
<< " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
6636 |
|
<< " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "; |
6637 |
|
// |
6638 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
6639 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
6640 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){ |
6641 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6642 |
|
// |
6643 |
|
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT() |
6644 |
|
<< " WHERE ID=" << glrun->GetID() << ";"; |
6645 |
|
if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str()); |
6646 |
|
conn->Query(oss.str().c_str()); |
6647 |
|
}; |
6648 |
|
// |
6649 |
|
UInt_t myi = glrun->GetID(); |
6650 |
|
oss.str(""); |
6651 |
|
oss << " ID= "<< myi; |
6652 |
|
// |
6653 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
6654 |
|
// |
6655 |
|
// fill the new run in GL_RUN |
6656 |
|
// |
6657 |
|
glrun->SetID_RUN_FRAG(IDRL2B); |
6658 |
|
glrun->Fill_GL_RUN(conn); |
6659 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
6660 |
|
delete glA; |
6661 |
|
moved++; |
6662 |
|
// |
6663 |
|
} else { |
6664 |
|
// |
6665 |
|
// is just a repetition |
6666 |
|
// |
6667 |
|
if ( IsDebug() ) printf(" The run %u is already present in the GL_RUN table...\n",glrun->GetID()); |
6668 |
|
// printf(" CCCCCCCCICCCCCCCCCCCCIOOOOOOOOOO si muove Ciccio! %u \n",glrun->GetID()); |
6669 |
|
// if ( PEDANTIC && glrun->GetID() != 61563 ) throw -83; |
6670 |
|
if ( PEDANTIC ) throw -83; |
6671 |
|
}; |
6672 |
|
// if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! ...\n"); |
6673 |
|
// if ( PEDANTIC ) throw -83; |
6674 |
}; |
}; |
6675 |
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)); |
6676 |
// |
// |