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-"<< (float)chlastts <<")<50000 AND ABS(REAL_TIME_INIT-"<< atof(row2->GetField(10)) <<")<50000 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; // even more relaxed conditions... 091214 [9REDtest3: error -29] // 10RED MYSQL operators BUG: |
230 |
|
/* |
231 |
|
|
232 |
|
mysql> select CAST(1322000646 AS UNSIGNED INTEGER)-1322017203.; |
233 |
|
+--------------------------------------------------+ |
234 |
|
| CAST(1322000646 AS UNSIGNED INTEGER)-1322017203. | |
235 |
|
+--------------------------------------------------+ |
236 |
|
| -16557 | |
237 |
|
+--------------------------------------------------+ |
238 |
|
1 row in set (0.06 sec) |
239 |
|
|
240 |
|
mysql> select CAST(1322000646 AS UNSIGNED INTEGER)-1322017203; |
241 |
|
+-------------------------------------------------+ |
242 |
|
| CAST(1322000646 AS UNSIGNED INTEGER)-1322017203 | |
243 |
|
+-------------------------------------------------+ |
244 |
|
| 18446744073709535059 | |
245 |
|
+-------------------------------------------------+ |
246 |
|
1 row in set (0.02 sec) |
247 |
|
|
248 |
|
*/ |
249 |
|
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
250 |
|
result3 = conn->Query(qu.str().c_str()); |
251 |
|
if ( result3 ){ |
252 |
|
row3 = result3->Next(); |
253 |
|
if ( row3 && result3->GetRowCount() == 1 ){ |
254 |
|
chboot = (UInt_t)atoll(row3->GetField(0)); |
255 |
|
if ( debug ) printf(" Found boot_number = %u \n",chboot); |
256 |
|
} else { |
257 |
|
if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n"); |
258 |
|
throw -29; |
259 |
|
}; |
260 |
|
}; |
261 |
|
}; |
262 |
|
}; |
263 |
|
// |
264 |
chpktinit = (UInt_t)atoll(row2->GetField(6)); |
chpktinit = (UInt_t)atoll(row2->GetField(6)); |
265 |
chpktfinal = (UInt_t)atoll(row2->GetField(7)); |
chpktfinal = (UInt_t)atoll(row2->GetField(7)); |
266 |
chobtinit = (UInt_t)atoll(row2->GetField(8)); |
chobtinit = (UInt_t)atoll(row2->GetField(8)); |
273 |
throw -85; |
throw -85; |
274 |
}; |
}; |
275 |
filerootname = chpath + chfile;// + ".root"; |
filerootname = chpath + chfile;// + ".root"; |
|
if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data()); |
|
276 |
}; |
}; |
277 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
|
file = TFile::Open(this->GetRootName().Data()); |
|
|
} else { |
|
|
this->SetRootName(""); |
|
278 |
}; |
}; |
279 |
|
if ( debug ) printf(" Filename is %s \n",filerootname.Data()); |
280 |
|
file = TFile::Open(this->GetRootName().Data()); |
281 |
|
// } else { |
282 |
|
// this->SetRootName(""); |
283 |
|
// this->SetRootName(filerootname); |
284 |
|
// }; |
285 |
} |
} |
286 |
|
|
287 |
// |
// |
481 |
return; |
return; |
482 |
}; |
}; |
483 |
// |
// |
484 |
TString name = this->GetRootFile(); |
if ( !chewbacca ){ |
485 |
Int_t nlength = name.Length(); |
TString name = this->GetRootFile(); |
486 |
if ( nlength < 5 ) return; |
Int_t nlength = name.Length(); |
487 |
TString dwo = 0; |
if ( nlength < 5 ){ |
488 |
for (Int_t i = 0; i<5; i++){ |
if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data()); |
489 |
dwo.Append(name[i],1); |
return; |
490 |
}; |
}; |
491 |
if ( dwo.IsDigit() ){ |
TString dwo = ""; |
492 |
dworbit = (UInt_t)dwo.Atoi(); |
for (Int_t i = 0; i<5; i++){ |
|
} else { |
|
|
dwo=""; |
|
|
for (Int_t i = 8; i<13; i++){ |
|
493 |
dwo.Append(name[i],1); |
dwo.Append(name[i],1); |
494 |
}; |
}; |
495 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ){ |
496 |
|
dworbit = (UInt_t)dwo.Atoi(); |
497 |
|
} else { |
498 |
|
dwo=""; |
499 |
|
for (Int_t i = 8; i<13; i++){ |
500 |
|
dwo.Append(name[i],1); |
501 |
|
}; |
502 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
503 |
|
}; |
504 |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
505 |
}; |
}; |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
|
506 |
return; |
return; |
507 |
}; |
}; |
508 |
|
|
533 |
|
|
534 |
TString PamelaDBOperations::GetRootPath(){ |
TString PamelaDBOperations::GetRootPath(){ |
535 |
if ( STATIC ){ |
if ( STATIC ){ |
536 |
return((TString)gSystem->DirName(filerootname.Data())+'/'); |
return((TString)gSystem->DirName(this->GetRootName().Data())+'/'); |
537 |
} else { |
} else { |
538 |
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
if ( KEEPENV ){ |
539 |
|
return((TString)gSystem->ExpandPathName(gSystem->DirName(filerootname.Data()))+'/'); |
540 |
|
} else { |
541 |
|
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
542 |
|
}; |
543 |
}; |
}; |
544 |
}; |
}; |
545 |
|
|
751 |
UInt_t tjump = 50000; |
UInt_t tjump = 50000; |
752 |
//UInt_t tjump = 100; |
//UInt_t tjump = 100; |
753 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
754 |
pktlast = numeric_limits<UInt_t>::max(); |
// pktlast = numeric_limits<UInt_t>::max(); |
755 |
while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){ |
pktlast = chpktmax + 1; |
756 |
|
while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){ |
757 |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
758 |
T->GetEntry(nevent-1-it); |
T->GetEntry(nevent-1-it); |
759 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
761 |
} else { |
} else { |
762 |
pktlast = chpktmax + 1; |
pktlast = chpktmax + 1; |
763 |
}; |
}; |
764 |
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)); |
765 |
it += tjump; |
it += tjump; |
766 |
}; |
}; |
767 |
if ( tjump > 1 ) it -= 2*tjump; |
if ( tjump > 1 ) it -= 2*tjump; |
785 |
tjump = 50000; |
tjump = 50000; |
786 |
//tjump = 100; |
//tjump = 100; |
787 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
788 |
pktlast = 0; |
// pktlast = 0; |
789 |
while ( pktlast < chpktmin && it < (Int_t)nevent ){ |
pktlast = chpktmin - 1; |
790 |
|
if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin)); |
791 |
|
while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){ |
792 |
if ( it < (Int_t)nevent ){ |
if ( it < (Int_t)nevent ){ |
793 |
T->GetEntry(it); |
T->GetEntry(it); |
794 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
882 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
883 |
pktlast = ph->GetCounter(); |
pktlast = ph->GetCounter(); |
884 |
nevent = upperentry - chminentry; |
nevent = upperentry - chminentry; |
885 |
|
if ( ((Int_t)upperentry - (Int_t)chminentry) < 0 ) nevent = 0; // nevent is UInt_t! 090112 [8RED: error -88] |
886 |
|
if ( IsDebug() ) printf(" Setting nevent to %u - upperentry %i chminentry %i \n",nevent,upperentry,chminentry); |
887 |
// |
// |
888 |
} else { |
} else { |
889 |
upperpkt = PKT(pktlast); |
upperpkt = PKT(pktlast); |
892 |
}; |
}; |
893 |
// |
// |
894 |
if ( chewbacca && nevent < 1 ) { |
if ( chewbacca && nevent < 1 ) { |
895 |
|
if ( IsDebug() ) printf(" chewbacca and no events in the file \n"); |
896 |
pktfirst = chpktmin; |
pktfirst = chpktmin; |
897 |
upperpkt = PKT(chpktmax); |
upperpkt = PKT(chpktmax); |
898 |
pktlast = chpktmax; |
pktlast = chpktmax; |
918 |
// if ( nevent < jump ) jump = int(nevent/10); |
// if ( nevent < jump ) jump = int(nevent/10); |
919 |
// if ( !jump ) jump = 1; |
// if ( !jump ) jump = 1; |
920 |
// |
// |
921 |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){ |
|
922 |
|
if ( ((PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt)) && nevent > deltapkt ){ |
923 |
// |
// |
924 |
if ( IsDebug() ) printf(" starting jump %i \n",jump); |
if ( IsDebug() ) printf(" starting jump %i \n",jump); |
925 |
// 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)); |
1234 |
stringstream oss; |
stringstream oss; |
1235 |
// |
// |
1236 |
oss.str(""); |
oss.str(""); |
1237 |
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. |
1238 |
|
if ( !strcmp(tag.Data(),"NONE") ){ |
1239 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< chiby.Data() <<"');"; |
1240 |
|
} else { |
1241 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1242 |
|
}; |
1243 |
|
} else { |
1244 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1245 |
|
}; |
1246 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1247 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1248 |
oss.str(""); |
oss.str(""); |
1366 |
stringstream oss; |
stringstream oss; |
1367 |
// |
// |
1368 |
oss.str(""); |
oss.str(""); |
1369 |
oss << "SET time_zone='+0:00';"; |
oss << "SET time_zone='+0:00'; SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"; |
1370 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1371 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1372 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1390 |
stringstream oss; |
stringstream oss; |
1391 |
// |
// |
1392 |
oss.str(""); |
oss.str(""); |
1393 |
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;"; |
1394 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1395 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1396 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1447 |
// |
// |
1448 |
// 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)); |
1449 |
// |
// |
1450 |
if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1451 |
// 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()); |
1452 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1453 |
}; |
}; |
1494 |
UInt_t lastPkt = 0; |
UInt_t lastPkt = 0; |
1495 |
UInt_t rhtime = 0; |
UInt_t rhtime = 0; |
1496 |
UInt_t rttime = 0; |
UInt_t rttime = 0; |
1497 |
|
// |
1498 |
|
if ( IsDebug() ) printf(" A firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1499 |
|
// |
1500 |
if ( !mishead ){ |
if ( !mishead ){ |
1501 |
codh = ehh->GetCounter(); |
codh = ehh->GetCounter(); |
1502 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1503 |
|
if ( IsDebug() ) printf(" B firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1504 |
firstev = 1; |
firstev = 1; |
1505 |
lastev = 0; |
lastev = 0; |
1506 |
} else { |
} else { |
1513 |
}; |
}; |
1514 |
if ( !mistrail ){ |
if ( !mistrail ){ |
1515 |
codt = eht->GetCounter(); |
codt = eht->GetCounter(); |
1516 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1)){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1)){ |
1517 |
|
if ( IsDebug() ) printf(" C firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1518 |
lastev = 0; |
lastev = 0; |
1519 |
firstev = lastev+1; |
firstev = lastev+1; |
1520 |
} else { |
} else { |
1531 |
if ( mishead ) { |
if ( mishead ) { |
1532 |
glrun->Set_GL_RUNH0(); |
glrun->Set_GL_RUNH0(); |
1533 |
// |
// |
1534 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1535 |
firstObt = lastObt; |
firstObt = lastObt; |
1536 |
firstPkt = lastPkt; |
firstPkt = lastPkt; |
1537 |
rhtime = rttime; |
rhtime = rttime; |
1550 |
if ( mistrail ){ |
if ( mistrail ){ |
1551 |
glrun->Set_GL_RUNT0(); |
glrun->Set_GL_RUNT0(); |
1552 |
// |
// |
1553 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1554 |
lastObt = firstObt; |
lastObt = firstObt; |
1555 |
lastPkt = firstPkt; |
lastPkt = firstPkt; |
1556 |
rttime = rhtime; |
rttime = rhtime; |
1566 |
glrun->SetRUNTRAILER_PKT(lastPkt); |
glrun->SetRUNTRAILER_PKT(lastPkt); |
1567 |
// |
// |
1568 |
}; |
}; |
1569 |
|
// |
1570 |
|
// ad hoc solution for INF EV_TO [8RED] 090113 |
1571 |
|
// |
1572 |
|
if ( !firstev && lastev == -1 ){ |
1573 |
|
if ( IsDebug() ) printf(" EE firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1574 |
|
firstev = 1; |
1575 |
|
lastev = 0; |
1576 |
|
}; |
1577 |
glrun->SetEV_FROM((UInt_t)firstev); |
glrun->SetEV_FROM((UInt_t)firstev); |
1578 |
glrun->SetEV_TO((UInt_t)lastev); |
glrun->SetEV_TO((UInt_t)lastev); |
1579 |
glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1); |
glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1); |
1593 |
* Insert a new row into GL_RAW table. |
* Insert a new row into GL_RAW table. |
1594 |
*/ |
*/ |
1595 |
Int_t PamelaDBOperations::insertPamelaRawFile(){ |
Int_t PamelaDBOperations::insertPamelaRawFile(){ |
1596 |
|
|
1597 |
|
// |
1598 |
|
Bool_t idr = this->SetID_RAW(); |
1599 |
|
if ( idr ) return(1); |
1600 |
|
|
1601 |
|
GL_RAW glraw = GL_RAW(); |
1602 |
|
|
1603 |
|
glraw.PATH = GetRawPath(); |
1604 |
|
glraw.NAME = GetRawFile(); |
1605 |
|
// glraw.BOOT_NUMBER = 0;//??? |
1606 |
|
glraw.BOOT_NUMBER = this->GetBOOTnumber(); |
1607 |
|
|
1608 |
|
if( insertPamelaRawFile(&glraw) )return(1); |
1609 |
|
// |
1610 |
|
idr = this->SetID_RAW(); |
1611 |
|
if ( !idr ) throw -11; |
1612 |
|
|
1613 |
|
return(0); |
1614 |
|
} |
1615 |
|
/** |
1616 |
|
* Insert a new row into GL_RAW table. |
1617 |
|
*/ |
1618 |
|
Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ |
1619 |
// |
// |
1620 |
stringstream oss; |
if(!glraw)return(1);//?? ok I think |
1621 |
// |
// |
1622 |
Bool_t idr = this->SetID_RAW(); |
stringstream oss; |
1623 |
if ( idr ) return(1); |
// |
1624 |
// |
oss.str(""); |
1625 |
oss.str(""); |
if ( STATIC ){ |
1626 |
if ( STATIC ){ |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
1627 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
<< glraw->PATH << "', '" << glraw->NAME << "')"; |
1628 |
<< this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; |
} else { |
1629 |
} else { |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << glraw->NAME << "')"; |
1630 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')"; |
}; |
1631 |
}; |
if ( debug ) cout <<oss.str().c_str() <<endl; |
1632 |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1633 |
// |
// |
1634 |
idr = this->SetID_RAW(); |
oss.str(""); |
1635 |
if ( !idr ) throw -11; |
oss << "SELECT ID FROM GL_RAW WHERE NAME=\""<<glraw->NAME<<"\";"; |
1636 |
// |
if ( debug ) cout << oss.str().c_str()<<endl; |
1637 |
return(0); |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1638 |
|
// |
1639 |
|
TSQLResult *result = 0; |
1640 |
|
TSQLRow *row = 0; |
1641 |
|
result = conn->Query(oss.str().c_str()); |
1642 |
|
if ( result == NULL ) throw -4; |
1643 |
|
row = result->Next(); |
1644 |
|
if ( !row ) return(1); |
1645 |
|
glraw->ID = (UInt_t)atoll(row->GetField(0)); |
1646 |
|
if ( debug ) printf(" The ID of the RAW file is %u \n",glraw->ID); |
1647 |
|
delete result; |
1648 |
|
delete row; |
1649 |
|
// |
1650 |
|
return(0); |
1651 |
} |
} |
1652 |
|
|
1653 |
|
|
1680 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1681 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1682 |
row = result->Next(); |
row = result->Next(); |
1683 |
|
if ( !row ) throw -92; |
1684 |
idresof = (UInt_t)atoll(row->GetField(0)); |
idresof = (UInt_t)atoll(row->GetField(0)); |
1685 |
existsts = true; |
existsts = true; |
1686 |
goto eout; |
goto eout; |
1702 |
if ( !row ){ |
if ( !row ){ |
1703 |
oss.str(""); |
oss.str(""); |
1704 |
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< " |
1705 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< dworbit << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;"; |
1706 |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1707 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1708 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1749 |
TYPE = 0; |
TYPE = 0; |
1750 |
TSYNC = 0; |
TSYNC = 0; |
1751 |
// |
// |
1752 |
Double_t minimum = 0.; |
// Double_t minimum = 0.; |
1753 |
Double_t maximum = 0.; |
// Double_t maximum = 0.; |
1754 |
Double_t minimum2 = 0.; |
//Double_t minimum2 = 0.; |
1755 |
Double_t maximum2 = 0.; |
Double_t maximum2 = 0.; |
1756 |
// |
// |
1757 |
// |
// |
1759 |
pamela::McmdRecord *mcrc = 0; |
pamela::McmdRecord *mcrc = 0; |
1760 |
TArrayC *mcmddata = 0; |
TArrayC *mcmddata = 0; |
1761 |
// |
// |
1762 |
minimum = numeric_limits<Double_t>::max(); |
// minimum = numeric_limits<Double_t>::max(); |
1763 |
maximum = numeric_limits<Double_t>::min(); |
// maximum = numeric_limits<Double_t>::min(); |
1764 |
minimum2 = numeric_limits<Double_t>::max(); |
// minimum2 = numeric_limits<Double_t>::max(); |
1765 |
maximum2 = numeric_limits<Double_t>::min(); |
maximum2 = numeric_limits<Double_t>::min(); |
1766 |
// |
// |
1767 |
T = (TTree*)file->Get("Mcmd"); |
T = (TTree*)file->Get("Mcmd"); |
1960 |
* 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. |
1961 |
*/ |
*/ |
1962 |
Int_t PamelaDBOperations::insertPamelaRootFile(){ |
Int_t PamelaDBOperations::insertPamelaRootFile(){ |
1963 |
stringstream oss; |
|
1964 |
TSQLResult *result = 0; |
stringstream oss; |
1965 |
TSQLRow *row = 0; |
TSQLResult *result = 0; |
1966 |
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; |
|
1967 |
// |
// |
1968 |
row = result->Next(); |
// ---------------------- |
1969 |
|
// determine the timesync |
1970 |
|
// ---------------------- |
1971 |
|
UInt_t idtimesync = 0; |
1972 |
// |
// |
1973 |
if ( !row ) throw -3; |
if ( chewbacca ){ |
1974 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
oss.str(""); |
1975 |
} else { |
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
1976 |
oss.str(""); |
if ( debug ) printf(" %s \n",oss.str().c_str()); |
1977 |
if ( STATIC ){ |
result = conn->Query(oss.str().c_str()); |
1978 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
// |
1979 |
<< " LEFT JOIN GL_ROOT " |
if ( !result ) throw -3; |
1980 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
// |
1981 |
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
row = result->Next(); |
1982 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
// |
1983 |
|
if ( !row ) throw -3; |
1984 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
1985 |
} else { |
} else { |
1986 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
oss.str(""); |
1987 |
<< " LEFT JOIN GL_ROOT " |
if ( STATIC ){ |
1988 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1989 |
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
<< " LEFT JOIN GL_ROOT " |
1990 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1991 |
|
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
1992 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1993 |
|
} else { |
1994 |
|
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1995 |
|
<< " LEFT JOIN GL_ROOT " |
1996 |
|
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1997 |
|
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
1998 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1999 |
|
}; |
2000 |
|
result = conn->Query(oss.str().c_str()); |
2001 |
|
// |
2002 |
|
if ( !result ) throw -12; |
2003 |
|
// |
2004 |
|
row = result->Next(); |
2005 |
|
// |
2006 |
|
if ( !row ) throw -10; |
2007 |
|
if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
2008 |
|
idroot = (UInt_t)atoll(row->GetField(2)); |
2009 |
|
delete row; |
2010 |
|
delete result; |
2011 |
|
return(1); |
2012 |
|
}; |
2013 |
|
// |
2014 |
|
// determine which timesync has to be used |
2015 |
|
// |
2016 |
|
oss.str(""); |
2017 |
|
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;"; |
2018 |
|
result = conn->Query(oss.str().c_str()); |
2019 |
|
// |
2020 |
|
if ( !result ) throw -3; |
2021 |
|
// |
2022 |
|
row = result->Next(); |
2023 |
|
// |
2024 |
|
if ( !row ) throw -3; |
2025 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
2026 |
}; |
}; |
2027 |
result = conn->Query(oss.str().c_str()); |
|
2028 |
// |
delete row; |
2029 |
if ( !result ) throw -12; |
delete result; |
2030 |
// |
|
2031 |
row = result->Next(); |
// ---------------------- |
2032 |
// |
// insert root file |
2033 |
if ( !row ) throw -10; |
// ---------------------- |
2034 |
if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
|
2035 |
idroot = (UInt_t)atoll(row->GetField(2)); |
GL_ROOT glroot = GL_ROOT(); |
2036 |
return(1); |
|
2037 |
|
glroot.ID_RAW = GetID_RAW(); |
2038 |
|
glroot.ID_TIMESYNC = idtimesync; |
2039 |
|
if ( STATIC ){ |
2040 |
|
glroot.PATH = GetRootPath(); |
2041 |
|
} else { |
2042 |
|
if ( KEEPENV ){ |
2043 |
|
glroot.PATH = gSystem->DirName(filerootname.Data()); |
2044 |
|
} else { |
2045 |
|
glroot.PATH = "$PAM_L0"; |
2046 |
|
}; |
2047 |
}; |
}; |
2048 |
// |
glroot.NAME = GetRootFile(); |
2049 |
// determine which timesync has to be used |
|
2050 |
// |
if ( insertPamelaRootFile(&glroot) )return 1; |
2051 |
oss.str(""); |
|
2052 |
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); |
2053 |
result = conn->Query(oss.str().c_str()); |
|
2054 |
// |
|
2055 |
if ( !result ) throw -3; |
return (0); |
2056 |
// |
} |
2057 |
row = result->Next(); |
/** |
2058 |
// |
* Insert all the new rows into GL_ROOT. |
2059 |
if ( !row ) throw -3; |
* The raw file indicates in the parameters should be already been stored in the database. |
2060 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
*/ |
2061 |
}; |
Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ |
2062 |
|
stringstream oss; |
2063 |
|
TSQLResult *result = 0; |
2064 |
|
TSQLRow *row = 0; |
2065 |
|
// |
2066 |
// |
// |
2067 |
oss.str(""); |
oss.str(""); |
2068 |
if ( STATIC ){ |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
2069 |
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() << "')"; |
|
|
}; |
|
2070 |
// |
// |
2071 |
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
2072 |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
2073 |
// |
// |
2074 |
delete result; |
delete result; |
2075 |
// |
// |
2076 |
oss.str(""); |
oss.str(""); |
2077 |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
2078 |
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() <<"';"; |
|
|
}; |
|
2079 |
// |
// |
2080 |
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
2081 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
2082 |
if ( !result ) throw -12; |
if ( !result ) throw -12; |
2083 |
row = result->Next(); |
row = result->Next(); |
2084 |
if ( !row ) throw -3; |
if ( !row ) throw -3; |
2085 |
this->SetID_ROOT((UInt_t)atoll(row->GetField(0))); |
|
2086 |
if ( debug ) printf(" The ID of the ROOT file is %u \n",this->GetID_ROOT()); |
glroot->ID = (UInt_t)atoll(row->GetField(0)); |
2087 |
|
|
2088 |
|
if ( debug ) printf(" The ID of the ROOT file is %u \n",glroot->ID); |
2089 |
// |
// |
2090 |
delete result; |
delete result; |
2091 |
// |
// |
2181 |
UInt_t lowerts = tsync-(obt0/1000)-5; |
UInt_t lowerts = tsync-(obt0/1000)-5; |
2182 |
if ( chewbacca ){ |
if ( chewbacca ){ |
2183 |
oss.str(""); |
oss.str(""); |
2184 |
oss << "select BOOT_NUMBER from ROOT_TABLE where LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)<" |
oss << "select BOOT_NUMBER from ROOT_TABLE where CAST((LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)) AS SIGNED INT)<" // 10RED MYSQL OPERATORS BUG |
2185 |
<< upperts |
<< upperts |
2186 |
<< " AND LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)>" |
<< " AND CAST((LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)) AS SIGNED INT)>" // 10RED MYSQL OPERATORS BUG |
2187 |
<< lowerts |
<< lowerts |
2188 |
<< " AND BOOT_NUMBER>1;"; |
<< " AND BOOT_NUMBER>1;"; |
2189 |
} else { |
} else { |
2190 |
oss.str(""); |
oss.str(""); |
2191 |
oss << "select GL_RAW.BOOT_NUMBER from GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW where TIMESYNC-(OBT0/1000)<" |
oss << "select GL_RAW.BOOT_NUMBER from GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW where CAST((TIMESYNC-(OBT0/1000)) AS SIGNED INT)<" // 10RED MYSQL OPERATORS BUG |
2192 |
<< upperts |
<< upperts |
2193 |
<< " AND TIMESYNC-(OBT0/1000)>" |
<< " AND CAST((TIMESYNC-(OBT0/1000)) AS SIGNED INT)>" // 10RED MYSQL OPERATORS BUG |
2194 |
<< lowerts |
<< lowerts |
2195 |
<< " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;"; |
<< " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;"; |
2196 |
}; |
}; |
2289 |
// |
// |
2290 |
// no runtrailers in the file! |
// no runtrailers in the file! |
2291 |
// |
// |
2292 |
if ( !rtev ){ |
if ( IsDebug() ) printf(" Start rtev %i rhev %i nrtev %i nrhev %i \n",rtev,rhev,nrtev,nrhev); |
2293 |
if ( !rhev ){ |
if ( !rtev || (chewbacca && !nrtev) ){ |
2294 |
|
if ( IsDebug() ) printf(" No runtrailers \n"); |
2295 |
|
if ( !rhev || (chewbacca && !nrhev) ){ |
2296 |
if ( IsDebug() ) printf(" No runheaders nor runtrailers!! \n"); |
if ( IsDebug() ) printf(" No runheaders nor runtrailers!! \n"); |
2297 |
if ( !(upperentry-chminentry) ){ |
if ( !(upperentry-chminentry) ){ |
2298 |
if ( IsDebug() ) printf(" No physics events nor runs in the file \n"); // di nuovo potrebbe esserci un runtrailer senza eventi (riempimento MM) |
if ( IsDebug() ) printf(" No physics events nor runs in the file \n"); // di nuovo potrebbe esserci un runtrailer senza eventi (riempimento MM) |
2329 |
// |
// |
2330 |
} else { |
} else { |
2331 |
// |
// |
2332 |
|
if ( IsDebug() ) printf(" We have runtrailers \n"); |
2333 |
Int_t conptt = -1; |
Int_t conptt = -1; |
2334 |
for (Int_t ptt=0; ptt<rtev; ptt++){ |
for (Int_t ptt=0; ptt<rtev; ptt++){ |
2335 |
// |
// |
2346 |
ptht = cod->Get(pctp->RunHeader) - 1; |
ptht = cod->Get(pctp->RunHeader) - 1; |
2347 |
// evbeft = cod->Get(pctp->Physics); |
// evbeft = cod->Get(pctp->Physics); |
2348 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2349 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2350 |
evbeft = TMath::Min(upperentry,(tcod-1)); |
evbeft = TMath::Min(upperentry,(tcod-1)); |
2351 |
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)); |
2352 |
// |
// |
2385 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2386 |
cod = ehh->GetCounter(); |
cod = ehh->GetCounter(); |
2387 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2388 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2389 |
evbefh = TMath::Max(chminentry,(tcod-1)); |
evbefh = TMath::Max(chminentry,(tcod-1)); |
2390 |
// |
// |
2391 |
if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){ |
if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){ |
2424 |
// |
// |
2425 |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
2426 |
// |
// |
2427 |
|
// what about pth=ptht-1 |
2428 |
}; |
}; |
2429 |
}; |
}; |
2430 |
// |
// |
2447 |
cod = ehh->GetCounter(); |
cod = ehh->GetCounter(); |
2448 |
// evbeft = cod->Get(pctp->Physics); |
// evbeft = cod->Get(pctp->Physics); |
2449 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2450 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2451 |
evbeft = TMath::Min(upperentry,(tcod-1)); |
evbeft = TMath::Min(upperentry,(tcod-1)); |
2452 |
rh->GetEntry(pth); |
rh->GetEntry(pth); |
2453 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2487 |
// if ( ptt+1 == rtev){ |
// if ( ptt+1 == rtev){ |
2488 |
if ( conptt+1 == nrtev ){ |
if ( conptt+1 == nrtev ){ |
2489 |
// if ( conptt+1 == (nrtev+nrtbef )){ |
// if ( conptt+1 == (nrtev+nrtbef )){ |
2490 |
|
if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); |
2491 |
ptht++; |
ptht++; |
2492 |
if ( ptht < rhev ){ |
if ( ptht < rhev ){ |
2493 |
rh->GetEntry(ptht); |
rh->GetEntry(ptht); |
2494 |
|
//pth++; |
2495 |
|
//if ( pth < rhev ){ |
2496 |
|
//rh->GetEntry(pth); |
2497 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2498 |
pkth = phh->GetCounter(); |
pkth = phh->GetCounter(); |
2499 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2517 |
if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){ |
if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){ |
2518 |
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); |
2519 |
// |
// |
2520 |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
// if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
2521 |
rt->GetEntry(ptt-1); |
if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here! |
2522 |
|
// rt->GetEntry(ptt-1); |
2523 |
|
rt->GetEntry(rtev-1); |
2524 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
2525 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics)+1; |
2526 |
evbefh = TMath::Max(chminentry,tcod); |
evbefh = TMath::Max(chminentry,tcod); |
2527 |
// evbefh = cod->Get(pctp->Physics); |
// evbefh = cod->Get(pctp->Physics); |
2528 |
rt->GetEntry(ptt); |
rt->GetEntry(ptt); |
2753 |
// |
// |
2754 |
// 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 |
2755 |
// |
// |
2756 |
if ( rhfirstev != firstev && !mishead ) mishead = true; |
if ( firstev != (lastev+1) ){ // could be a problem sometimes (?) |
2757 |
if ( rtlastev != lastev && !mistrail ) mistrail = true; |
if ( rhfirstev != firstev && !mishead ) mishead = true; |
2758 |
|
if ( rtlastev != lastev && !mistrail ) mistrail = true; |
2759 |
|
}; |
2760 |
// |
// |
2761 |
|
if ( IsDebug() ) printf(" bhere firstev is %i lastev is %i \n",firstev,lastev); |
2762 |
this->FillClass(mishead,mistrail,firstev,lastev); |
this->FillClass(mishead,mistrail,firstev,lastev); |
2763 |
|
if ( IsDebug() ) printf(" chere firstev is %i lastev is %i \n",firstev,lastev); |
2764 |
// |
// |
2765 |
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"); |
2766 |
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()); |
2802 |
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
2803 |
// |
// |
2804 |
} else { |
} else { |
2805 |
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); |
2806 |
if ( PEDANTIC ) throw -69; |
if ( !RELAXED ){ |
2807 |
return; |
if ( PEDANTIC ) throw -69; |
2808 |
|
return; |
2809 |
|
} else { |
2810 |
|
glrun->SetID((UInt_t)atoll(row->GetField(0))); |
2811 |
|
glrun->SetID_RUN_FRAG(0); |
2812 |
|
}; |
2813 |
}; |
}; |
2814 |
// |
// |
2815 |
if ( chewbacca && mishead && mistrail ) goto justcheck; |
if ( chewbacca && mishead && mistrail ) goto justcheck; |
2860 |
// |
// |
2861 |
found = false; // default value |
found = false; // default value |
2862 |
// |
// |
2863 |
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"); |
2864 |
// |
// |
2865 |
// 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: |
2866 |
// |
// |
2876 |
if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); |
if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); |
2877 |
// |
// |
2878 |
found = true; |
found = true; |
2879 |
|
if ( IsDebug() ) printf(" where firstev is %i lastev is %i \n",firstev,lastev); |
2880 |
// |
// |
2881 |
} else { |
} else { |
2882 |
// |
// |
2942 |
oss << " ID="<<row->GetField(0)<<";"; |
oss << " ID="<<row->GetField(0)<<";"; |
2943 |
// |
// |
2944 |
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 |
2945 |
|
if ( IsDebug() ) printf(" there firstev is %i lastev is %i \n",firstev,lastev); |
2946 |
// |
// |
2947 |
// merge infos |
// merge infos |
2948 |
// |
// |
2973 |
glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); |
glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); |
2974 |
glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); |
glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); |
2975 |
// |
// |
2976 |
|
if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev); |
2977 |
|
// |
2978 |
glrun->SetEV_FROM(firstev); |
glrun->SetEV_FROM(firstev); |
2979 |
|
glrun->SetEV_TO(lastev); // EM 10 RED ghost run bug |
2980 |
glrun->SetNEVENTS(lastev-firstev+1); |
glrun->SetNEVENTS(lastev-firstev+1); |
2981 |
// |
// |
2982 |
glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); |
glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); |
3068 |
// |
// |
3069 |
found = false; // default value |
found = false; // default value |
3070 |
// |
// |
3071 |
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"); |
3072 |
// |
// |
3073 |
// 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: |
3074 |
// |
// |
3168 |
apkt = PKT(ph->GetCounter()); |
apkt = PKT(ph->GetCounter()); |
3169 |
aobt = OBT(ph->GetOrbitalTime()); |
aobt = OBT(ph->GetOrbitalTime()); |
3170 |
lastev--; |
lastev--; |
3171 |
if ( PEDANTIC ) throw -72; |
if ( PEDANTIC && !RELAXED) throw -72; |
3172 |
}; |
}; |
3173 |
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); |
3174 |
// |
// |
3175 |
|
glrun->SetEV_FROM(firstev); // EM 10RED ghost run bug |
3176 |
glrun->SetEV_TO(lastev); |
glrun->SetEV_TO(lastev); |
3177 |
glrun->SetNEVENTS(lastev-firstev+1); |
glrun->SetNEVENTS(lastev-firstev+1); |
3178 |
glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER()); |
glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER()); |
3237 |
// 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? |
3238 |
// |
// |
3239 |
oss.str(""); |
oss.str(""); |
3240 |
oss << " SELECT ID FROM GL_RUN WHERE " |
oss << " SELECT ID,ID_ROOT_L0 FROM GL_RUN WHERE " |
3241 |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" |
3242 |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
3243 |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
3260 |
row = result->Next(); |
row = result->Next(); |
3261 |
// |
// |
3262 |
if ( row ){ |
if ( row ){ |
3263 |
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
// |
3264 |
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 |
3265 |
|
// "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number. |
3266 |
|
// |
3267 |
|
// 090112 [8RED (-70): RUN ALREADY INSERTED] |
3268 |
|
// 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! |
3269 |
|
// |
3270 |
|
Bool_t OK = false; |
3271 |
|
UInt_t IDRL2A = 0; |
3272 |
|
UInt_t IDRL2B = 0; |
3273 |
|
if ( chewbacca ){ |
3274 |
|
if ( result->GetRowCount() >= 2 ){ |
3275 |
|
// |
3276 |
|
if ( IsDebug() ) printf(" RH---| gap |---RT case, number of pieces in the GL_RUN table: %i \n",result->GetRowCount()); |
3277 |
|
OK = true; |
3278 |
|
IDRL2A = (UInt_t)atoll(row->GetField(0)); |
3279 |
|
// |
3280 |
|
while ( row ){ |
3281 |
|
// |
3282 |
|
TSQLResult *trresult = 0; |
3283 |
|
TSQLRow *trrow = 0; |
3284 |
|
// |
3285 |
|
stringstream tross; |
3286 |
|
tross.str(""); |
3287 |
|
// |
3288 |
|
tross << " SELECT RUNHEADER_PKT, RUNTRAILER_PKT FROM GL_RUN_TRASH where ID=" << row->GetField(0) << ";"; |
3289 |
|
if ( IsDebug() ) printf(" check in the gl_run_trash table for pkt intervals: query is \n %s \n",tross.str().c_str()); |
3290 |
|
trresult = conn->Query(tross.str().c_str()); |
3291 |
|
if ( !trresult ) throw -4; |
3292 |
|
trrow = trresult->Next(); |
3293 |
|
if ( !trrow || trresult->GetRowCount() != 1 ){ |
3294 |
|
OK = false; |
3295 |
|
if ( IsDebug() ) printf(" OPS! no such run (or multiple runs!) in GL_RUN_TRASH table, something wrong is going on! \n"); |
3296 |
|
break; |
3297 |
|
}; |
3298 |
|
// |
3299 |
|
UInt_t pktH = (UInt_t)atoll(row->GetField(0)); |
3300 |
|
UInt_t pktT = (UInt_t)atoll(row->GetField(1)); |
3301 |
|
delete trresult; |
3302 |
|
if ( |
3303 |
|
(PKT(pktH) >= PKT(glrun->GetRUNHEADER_PKT()) && PKT(pktH) <= PKT(glrun->GetRUNTRAILER_PKT())) || |
3304 |
|
(PKT(pktT) >= PKT(glrun->GetRUNHEADER_PKT()) && PKT(pktT) <= PKT(glrun->GetRUNTRAILER_PKT())) || |
3305 |
|
(PKT(pktH) <= PKT(glrun->GetRUNTRAILER_PKT()) && PKT(pktT) >= PKT(glrun->GetRUNTRAILER_PKT())) ){ |
3306 |
|
OK = false; |
3307 |
|
if ( IsDebug() ) printf(" The run is overlapping with already inserted ones!! \n"); |
3308 |
|
break; |
3309 |
|
}; |
3310 |
|
//PKT(glrun->GetRUNHEADER_PKT()) PKT(glrun->GetRUNTRAILER_PKT()) |
3311 |
|
row = result->Next(); |
3312 |
|
}; |
3313 |
|
|
3314 |
|
// if ( result->GetRowCount() == 2 ) { |
3315 |
|
// IDRL2A = (UInt_t)atoll(row->GetField(0)); |
3316 |
|
// UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1)); |
3317 |
|
// row = result->Next(); |
3318 |
|
// IDRL2B = (UInt_t)atoll(row->GetField(0)); |
3319 |
|
// UInt_t IDRL0B = (UInt_t)atoll(row->GetField(1)); |
3320 |
|
// if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B); |
3321 |
|
// // if ( IDRL0A == IDRL0B ){ //091230 why this condition???? RH could be in a file and RT in another one... |
3322 |
|
// if ( true ){ |
3323 |
|
// TSQLResult *result2 = 0; |
3324 |
|
// TSQLRow *row2 = 0; |
3325 |
|
// oss.str(""); |
3326 |
|
// oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;"; |
3327 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
3328 |
|
// result2 = conn->Query(oss.str().c_str()); |
3329 |
|
// // |
3330 |
|
// if ( !result2 ) throw -4; |
3331 |
|
// // |
3332 |
|
// row2 = result2->Next(); |
3333 |
|
// // |
3334 |
|
// if ( row2 ){ |
3335 |
|
// UInt_t PKA = (UInt_t)atoll(row2->GetField(0)); |
3336 |
|
// delete result2; |
3337 |
|
// oss.str(""); |
3338 |
|
// oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;"; |
3339 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
3340 |
|
// result2 = conn->Query(oss.str().c_str()); |
3341 |
|
// // |
3342 |
|
// if ( !result2 ) throw -4; |
3343 |
|
// // |
3344 |
|
// row2 = result2->Next(); |
3345 |
|
// // |
3346 |
|
// if ( row2 ){ |
3347 |
|
// UInt_t PKB = (UInt_t)atoll(row2->GetField(0)); |
3348 |
|
// // |
3349 |
|
// 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); |
3350 |
|
// if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){ |
3351 |
|
// if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); |
3352 |
|
// OK = true; |
3353 |
|
// }; |
3354 |
|
// }; |
3355 |
|
// }; |
3356 |
|
// }; |
3357 |
|
// }; |
3358 |
|
}; |
3359 |
|
}; |
3360 |
|
if ( OK ){ |
3361 |
|
// |
3362 |
|
// 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 |
3363 |
|
// |
3364 |
|
// 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 ) |
3365 |
|
// |
3366 |
|
if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); |
3367 |
|
// |
3368 |
|
GL_RUN *glA = new GL_RUN(); |
3369 |
|
glA->Query_GL_RUN(IDRL2A,conn); |
3370 |
|
// |
3371 |
|
glrun->SetRUNHEADER_TIME(glA->GetRUNHEADER_TIME()); |
3372 |
|
glrun->SetRUNHEADER_OBT(glA->GetRUNHEADER_OBT()); |
3373 |
|
glrun->SetRUNHEADER_PKT(glA->GetRUNHEADER_PKT()); |
3374 |
|
// |
3375 |
|
glrun->SetRUNTRAILER_TIME(glA->GetRUNTRAILER_TIME()); |
3376 |
|
glrun->SetRUNTRAILER_OBT(glA->GetRUNTRAILER_OBT()); |
3377 |
|
glrun->SetRUNTRAILER_PKT(glA->GetRUNTRAILER_PKT()); |
3378 |
|
// |
3379 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) glrun->SetPHYSENDRUN_MASK_S3S2S12(glA->GetPHYSENDRUN_MASK_S3S2S12()); |
3380 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) glrun->SetPHYSENDRUN_MASK_S11CRC(glA->GetPHYSENDRUN_MASK_S11CRC()); |
3381 |
|
// |
3382 |
|
if ( glA->GetACQ_BUILD_INFO() != 0 ){ |
3383 |
|
// |
3384 |
|
// the first piece contains a good runheader we can update all the other runs with correct infos! |
3385 |
|
// |
3386 |
|
glrun->SetCOMPILATIONTIMESTAMP(glA->GetCOMPILATIONTIMESTAMP()); |
3387 |
|
glrun->SetFAV_WRK_SCHEDULE(glA->GetFAV_WRK_SCHEDULE()); |
3388 |
|
glrun->SetEFF_WRK_SCHEDULE(glA->GetEFF_WRK_SCHEDULE()); |
3389 |
|
glrun->SetPRH_VAR_TRG_MODE_A(glA->GetPRH_VAR_TRG_MODE_A()); |
3390 |
|
glrun->SetPRH_VAR_TRG_MODE_B(glA->GetPRH_VAR_TRG_MODE_B()); |
3391 |
|
glrun->SetACQ_BUILD_INFO(glA->GetACQ_BUILD_INFO()); |
3392 |
|
glrun->SetACQ_VAR_INFO(glA->GetACQ_VAR_INFO()); |
3393 |
|
glrun->SetRM_ACQ_AFTER_CALIB(glA->GetRM_ACQ_AFTER_CALIB()); |
3394 |
|
glrun->SetRM_ACQ_SETTING_MODE(glA->GetRM_ACQ_SETTING_MODE()); |
3395 |
|
glrun->SetTRK_CALIB_USED(glA->GetTRK_CALIB_USED()); |
3396 |
|
glrun->SetCAL_DSP_MASK(glA->GetCAL_DSP_MASK()); |
3397 |
|
glrun->SetLAST_TIMESYNC(glA->GetLAST_TIMESYNC()); |
3398 |
|
glrun->SetOBT_TIMESYNC(glA->GetOBT_TIMESYNC()); |
3399 |
|
// |
3400 |
|
}; |
3401 |
|
// |
3402 |
|
if ( glA->GetPKT_READY_COUNTER() != 0 ){ |
3403 |
|
// |
3404 |
|
// the first piece contains a good runtrailer we can update all the other runs with correct infos! |
3405 |
|
// |
3406 |
|
glrun->SetPKT_COUNTER(glA->GetPKT_COUNTER()); |
3407 |
|
glrun->SetPKT_READY_COUNTER(glA->GetPKT_READY_COUNTER()); |
3408 |
|
}; |
3409 |
|
// |
3410 |
|
// update runheader ROOT_ID_FRAG |
3411 |
|
// |
3412 |
|
oss.str(""); |
3413 |
|
oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; |
3414 |
|
if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
3415 |
|
conn->Query(oss.str().c_str()); |
3416 |
|
// |
3417 |
|
oss.str(""); |
3418 |
|
oss << "SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG = " << IDRL2A << ";"; |
3419 |
|
if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
3420 |
|
TSQLResult *tsresult = 0; |
3421 |
|
TSQLRow *tsrow = 0; |
3422 |
|
tsresult=conn->Query(oss.str().c_str()); |
3423 |
|
if ( !tsresult ) throw -4; |
3424 |
|
tsrow = tsresult->Next(); |
3425 |
|
if ( !tsrow || tsresult->GetRowCount() != 1 ) throw -4; |
3426 |
|
IDRL2B = (UInt_t)atoll(tsrow->GetField(0)); |
3427 |
|
glrun->SetID_RUN_FRAG(IDRL2B); |
3428 |
|
// |
3429 |
|
// fill the new run in GL_RUN |
3430 |
|
// |
3431 |
|
glrun->Fill_GL_RUN(conn); |
3432 |
|
// |
3433 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
3434 |
|
delete glA; |
3435 |
|
// |
3436 |
|
} else { |
3437 |
|
// // |
3438 |
|
// // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table |
3439 |
|
// // |
3440 |
|
// // 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 ) |
3441 |
|
// // |
3442 |
|
// GL_RUN *glA = new GL_RUN(); |
3443 |
|
// glA->Query_GL_RUN(IDRL2A,conn); |
3444 |
|
// // |
3445 |
|
// if ( glA->GetACQ_BUILD_INFO() != 0 ){ |
3446 |
|
// // |
3447 |
|
// // the first piece contains a good runheader we can update all the other runs with correct infos! |
3448 |
|
// // |
3449 |
|
// oss.str(""); |
3450 |
|
// oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3451 |
|
// << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , " |
3452 |
|
// << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
3453 |
|
// << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , " |
3454 |
|
// << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , " |
3455 |
|
// << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , " |
3456 |
|
// << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , " |
3457 |
|
// << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , " |
3458 |
|
// << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , " |
3459 |
|
// << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , " |
3460 |
|
// << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , " |
3461 |
|
// << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , " |
3462 |
|
// << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , " |
3463 |
|
// << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , " |
3464 |
|
// << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , " |
3465 |
|
// << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , "; |
3466 |
|
// // |
3467 |
|
// if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
3468 |
|
// oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , "; |
3469 |
|
// if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
3470 |
|
// oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , "; |
3471 |
|
// // |
3472 |
|
// oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC(); |
3473 |
|
// oss << " WHERE ID=" << glrun->GetID() << ";"; |
3474 |
|
// if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str()); |
3475 |
|
// conn->Query(oss.str().c_str()); |
3476 |
|
// // |
3477 |
|
// } else { |
3478 |
|
// // |
3479 |
|
// // sig no runheader, let set anyway what is possible... |
3480 |
|
// // |
3481 |
|
// oss.str(""); |
3482 |
|
// oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3483 |
|
// << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "; |
3484 |
|
// // |
3485 |
|
// if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
3486 |
|
// oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; |
3487 |
|
// if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
3488 |
|
// oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
3489 |
|
// // |
3490 |
|
// oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
3491 |
|
// << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT(); |
3492 |
|
// oss << " WHERE ID=" << glrun->GetID() << ";"; |
3493 |
|
// if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str()); |
3494 |
|
// conn->Query(oss.str().c_str()); |
3495 |
|
// }; |
3496 |
|
// // |
3497 |
|
// // update runheader ROOT_ID_FRAG |
3498 |
|
// // |
3499 |
|
// oss.str(""); |
3500 |
|
// oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; |
3501 |
|
// if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
3502 |
|
// conn->Query(oss.str().c_str()); |
3503 |
|
// // |
3504 |
|
// // now let's look for runtrailer if any in the last run |
3505 |
|
// // |
3506 |
|
// glA->Query_GL_RUN(IDRL2B,conn); |
3507 |
|
// // |
3508 |
|
// if ( glA->GetPKT_READY_COUNTER() != 0 ){ |
3509 |
|
// // |
3510 |
|
// // the first piece contains a good runtrailer we can update all the other runs with correct infos! |
3511 |
|
// // |
3512 |
|
// oss.str(""); |
3513 |
|
// oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3514 |
|
// << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
3515 |
|
// << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , " |
3516 |
|
// << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , " |
3517 |
|
// << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , "; |
3518 |
|
// // |
3519 |
|
// if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
3520 |
|
// oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
3521 |
|
// if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) { |
3522 |
|
// oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
3523 |
|
// // |
3524 |
|
// oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER() |
3525 |
|
// << " WHERE ID=" << glrun->GetID() << ";"; |
3526 |
|
// if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str()); |
3527 |
|
// conn->Query(oss.str().c_str()); |
3528 |
|
// // |
3529 |
|
// } else { |
3530 |
|
// // |
3531 |
|
// // sig no runtrailer, let set anyway what is possible... |
3532 |
|
// // |
3533 |
|
// oss.str(""); |
3534 |
|
// oss << "UPDATE GL_RUN_FRAGMENTS SET " |
3535 |
|
// << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
3536 |
|
// << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "; |
3537 |
|
// // |
3538 |
|
// if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
3539 |
|
// oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
3540 |
|
// if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){ |
3541 |
|
// oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
3542 |
|
// // |
3543 |
|
// oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT() |
3544 |
|
// << " WHERE ID=" << glrun->GetID() << ";"; |
3545 |
|
// if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str()); |
3546 |
|
// conn->Query(oss.str().c_str()); |
3547 |
|
// }; |
3548 |
|
// // |
3549 |
|
// UInt_t myi = glrun->GetID(); |
3550 |
|
// oss.str(""); |
3551 |
|
// oss << " ID= "<< myi; |
3552 |
|
// // |
3553 |
|
// glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
3554 |
|
// // |
3555 |
|
// // fill the new run in GL_RUN |
3556 |
|
// // |
3557 |
|
// glrun->SetID_RUN_FRAG(IDRL2B); |
3558 |
|
// glrun->Fill_GL_RUN(conn); |
3559 |
|
// glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
3560 |
|
// delete glA; |
3561 |
|
// // |
3562 |
|
// } else { |
3563 |
|
// |
3564 |
|
// is just a repetition |
3565 |
|
// |
3566 |
|
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
3567 |
|
if ( PEDANTIC ) throw -70; |
3568 |
|
}; |
3569 |
|
// |
3570 |
} else { |
} else { |
3571 |
if ( NoFrag() ){ |
if ( NoFrag() ){ |
3572 |
glrun->SetID_RUN_FRAG(glrun->GetID()); |
glrun->SetID_RUN_FRAG(glrun->GetID()); |
3603 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
3604 |
glrun->SetID_RUN_FRAG(0); |
glrun->SetID_RUN_FRAG(0); |
3605 |
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... |
3606 |
}; |
}; |
3607 |
// |
// |
3608 |
}; |
}; |
3609 |
// |
// |
3619 |
// |
// |
3620 |
EventCounter *code=0; |
EventCounter *code=0; |
3621 |
// |
// |
3622 |
UInt_t nevent = 0; |
// UInt_t nevent = 0; |
3623 |
UInt_t checkfirst = 0; |
UInt_t checkfirst = 0; |
3624 |
UInt_t checklast = 0; |
UInt_t checklast = 0; |
3625 |
UInt_t firstentry = 0; |
UInt_t firstentry = 0; |
3641 |
EventHeader *eh = 0; |
EventHeader *eh = 0; |
3642 |
PscuHeader *ph = 0; |
PscuHeader *ph = 0; |
3643 |
T->SetBranchAddress("Header", &eh); |
T->SetBranchAddress("Header", &eh); |
3644 |
nevent = T->GetEntries(); |
// nevent = T->GetEntries(); |
3645 |
// |
// |
3646 |
// |
// |
3647 |
if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! |
if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! |
3648 |
//if ( firstev <= lastev+1 ) { // no events inside the run! |
//if ( firstev <= lastev+1 ) { // no events inside the run! |
3649 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
3650 |
|
firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files |
3651 |
// return true is correct |
// return true is correct |
3652 |
return(true); |
return(true); |
3653 |
// |
// |
3677 |
// |
// |
3678 |
} else { |
} else { |
3679 |
// |
// |
3680 |
if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n"); |
if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n"); |
3681 |
// |
// |
3682 |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
3683 |
// |
// |
3687 |
UInt_t check = 0; |
UInt_t check = 0; |
3688 |
UInt_t lastevtemp = lastev; |
UInt_t lastevtemp = lastev; |
3689 |
UInt_t firstevno = firstev; |
UInt_t firstevno = firstev; |
3690 |
|
UInt_t rhchko=0; |
3691 |
|
UInt_t rhchk=0; |
3692 |
// |
// |
3693 |
for (UInt_t i=firstev; i<=lastev; i++){ |
for (UInt_t i=firstev; i<=lastev; i++){ |
3694 |
// |
// |
3697 |
// |
// |
3698 |
check = 0; |
check = 0; |
3699 |
// |
// |
3700 |
|
|
3701 |
|
// if we have a runheader set lastev then exit |
3702 |
|
// |
3703 |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
3704 |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
3705 |
}; |
}; |
3706 |
|
// check here if we have a runheader |
3707 |
|
rhchko = rhchk; |
3708 |
|
rhchk = code->Get(GetPacketType("RunHeader")); |
3709 |
// |
// |
3710 |
if ( checkfirst < check || i == lastev ){ |
if ( checkfirst < check || i == lastev ){ |
3711 |
// |
// |
3789 |
// 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 |
3790 |
// |
// |
3791 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3792 |
mishead = true; |
mishead = true; |
3793 |
|
|
3794 |
|
|
3903 |
// |
// |
3904 |
found = false; // default value |
found = false; // default value |
3905 |
// |
// |
3906 |
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"); |
3907 |
// |
// |
3908 |
// 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: |
3909 |
// |
// |
4015 |
glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); |
glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); |
4016 |
// |
// |
4017 |
glrun->SetEV_FROM(firstev); |
glrun->SetEV_FROM(firstev); |
4018 |
|
glrun->SetEV_TO(lastev); // 10 RED ghost run bug |
4019 |
glrun->SetNEVENTS(lastev-firstev+1); |
glrun->SetNEVENTS(lastev-firstev+1); |
4020 |
// |
// |
4021 |
glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); |
glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); |
4109 |
}; // EEE |
}; // EEE |
4110 |
|
|
4111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4112 |
} else { |
} else { |
4113 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
4114 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
4123 |
// |
// |
4124 |
}; |
}; |
4125 |
// |
// |
4126 |
|
if ( i > firstev ){ |
4127 |
|
if ( rhchko != rhchk ){ |
4128 |
|
if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n"); |
4129 |
|
lastev = i; |
4130 |
|
return(false); |
4131 |
|
}; |
4132 |
|
}; |
4133 |
|
// |
4134 |
if ( check == checklast && i != lastev ){ |
if ( check == checklast && i != lastev ){ |
4135 |
lastevtemp = i - 1; |
lastevtemp = i - 1; |
4136 |
i = lastev - 1; |
i = lastev - 1; |
4163 |
EventCounter *code=0; |
EventCounter *code=0; |
4164 |
UInt_t firstev = 0; |
UInt_t firstev = 0; |
4165 |
UInt_t lastev = 0; |
UInt_t lastev = 0; |
4166 |
UInt_t nevent = 0; |
// UInt_t nevent = 0; |
4167 |
UInt_t checkfirst = 0; |
UInt_t checkfirst = 0; |
4168 |
UInt_t checklast = 0; |
UInt_t checklast = 0; |
4169 |
UInt_t firstentry = 0; |
UInt_t firstentry = 0; |
4188 |
EventHeader *eh = 0; |
EventHeader *eh = 0; |
4189 |
PscuHeader *ph = 0; |
PscuHeader *ph = 0; |
4190 |
T->SetBranchAddress("Header", &eh); |
T->SetBranchAddress("Header", &eh); |
4191 |
nevent = T->GetEntries(); |
// nevent = T->GetEntries(); |
4192 |
// |
// |
4193 |
codt = eht->GetCounter(); |
codt = eht->GetCounter(); |
4194 |
codh = ehh->GetCounter(); |
codh = ehh->GetCounter(); |
4422 |
UInt_t totime = 0; |
UInt_t totime = 0; |
4423 |
UInt_t obt = 0; |
UInt_t obt = 0; |
4424 |
UInt_t pkt = 0; |
UInt_t pkt = 0; |
4425 |
|
Float_t totped = 0.; |
4426 |
// |
// |
4427 |
tr = (TTree*)file->Get("CalibCalPed"); |
tr = (TTree*)file->Get("CalibCalPed"); |
4428 |
if ( !tr || tr->IsZombie() ) throw -21; |
if ( !tr || tr->IsZombie() ) throw -21; |
4440 |
if ( calibCalPed->cstwerr[section] ){ |
if ( calibCalPed->cstwerr[section] ){ |
4441 |
valid = 1; |
valid = 1; |
4442 |
if ( calibCalPed->cperror[section] ) valid = 0; |
if ( calibCalPed->cperror[section] ) valid = 0; |
4443 |
ph = eh->GetPscuHeader(); |
// |
4444 |
obt = ph->GetOrbitalTime(); |
// 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.] |
4445 |
|
// |
4446 |
|
totped = 0.; |
4447 |
|
Int_t ns = 0; |
4448 |
|
if ( section == 2 ) ns = 3; |
4449 |
|
if ( section == 3 ) ns = 1; |
4450 |
|
if ( section == 1 ) ns = 2; |
4451 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4452 |
|
totped += fabs(calibCalPed->calped[ns][0][ss]); |
4453 |
|
} |
4454 |
|
if ( totped < 1. ){ |
4455 |
|
if ( IsDebug() ) printf(" Section %i totped %f - No calibration data! Calorimeter power problems? \n",section,totped); |
4456 |
|
valid = 0; |
4457 |
|
}; |
4458 |
|
// |
4459 |
|
ph = eh->GetPscuHeader(); |
4460 |
|
obt = ph->GetOrbitalTime(); |
4461 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
4462 |
fromtime = this->GetAbsTime(ph->GetOrbitalTime()); |
fromtime = this->GetAbsTime(ph->GetOrbitalTime()); |
4463 |
if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->PKT(pkt) <= upperpkt && this->OBT(obt) >= this->OBT(obtfirst) && this->OBT(obt) <= upperobt ){ |
if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->PKT(pkt) <= upperpkt && this->OBT(obt) >= this->OBT(obtfirst) && this->OBT(obt) <= upperobt ){ |
4623 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
4624 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
4625 |
// |
// |
4626 |
|
Float_t totpul = 0.; |
4627 |
|
// |
4628 |
if ( nevents > 0 ){ |
if ( nevents > 0 ){ |
4629 |
// |
// |
4630 |
for (UInt_t i=0; i < nevents; i++){ |
for (UInt_t i=0; i < nevents; i++){ |
4634 |
if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){ |
if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){ |
4635 |
valid = 1; |
valid = 1; |
4636 |
if ( cp1->pperror[section] ) valid = 0; |
if ( cp1->pperror[section] ) valid = 0; |
4637 |
|
// |
4638 |
|
// 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.] |
4639 |
|
// |
4640 |
|
totpul = 0.; |
4641 |
|
Int_t ns = 0; |
4642 |
|
if ( section == 2 ) ns = 3; |
4643 |
|
if ( section == 3 ) ns = 1; |
4644 |
|
if ( section == 1 ) ns = 2; |
4645 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4646 |
|
totpul += cp1->calpuls[ns][0][ss]; |
4647 |
|
} |
4648 |
|
if ( totpul >= 3145632. ){ |
4649 |
|
if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f - No calibration data! Calorimeter power problems? \n",section,totpul); |
4650 |
|
valid = 0; |
4651 |
|
}; |
4652 |
|
// |
4653 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
4654 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
4655 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
4807 |
if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){ |
if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){ |
4808 |
valid = 1; |
valid = 1; |
4809 |
if ( cp2->pperror[section] ) valid = 0; |
if ( cp2->pperror[section] ) valid = 0; |
4810 |
|
// |
4811 |
|
// 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.] |
4812 |
|
// |
4813 |
|
totpul = 0.; |
4814 |
|
Int_t ns = 0; |
4815 |
|
if ( section == 2 ) ns = 3; |
4816 |
|
if ( section == 3 ) ns = 1; |
4817 |
|
if ( section == 1 ) ns = 2; |
4818 |
|
for (UInt_t ss=0; ss<96; ss++){ |
4819 |
|
totpul += cp2->calpuls[ns][0][ss]; |
4820 |
|
} |
4821 |
|
if ( totpul >= 3145632. ){ |
4822 |
|
if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f - No calibration data! Calorimeter power problems? \n",section,totpul); |
4823 |
|
valid = 0; |
4824 |
|
}; |
4825 |
|
// |
4826 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
4827 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
4828 |
pkt = ph->GetCounter(); |
pkt = ph->GetCounter(); |
5002 |
* Fill the GL_TRK_CALIB table |
* Fill the GL_TRK_CALIB table |
5003 |
*/ |
*/ |
5004 |
void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
5005 |
// |
|
5006 |
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 ){ |
|
5007 |
// |
// |
5008 |
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
glcal->ID = 0; |
5009 |
if ( PEDANTIC ) throw -80; |
glcal->ID_ROOT_L0 = GetID_ROOT(); |
5010 |
|
glcal->EV_ROOT_CALIBTRK1 = t1; |
5011 |
|
glcal->EV_ROOT_CALIBTRK2 = t2; |
5012 |
|
glcal->FROM_TIME = fromtime; |
5013 |
|
glcal->TO_TIME = 0; |
5014 |
|
glcal->OBT1 = obt1; |
5015 |
|
glcal->OBT2 = obt2; |
5016 |
|
glcal->PKT1 = pkt1; |
5017 |
|
glcal->PKT2 = pkt2; |
5018 |
|
glcal->BOOT_NUMBER = GetBOOTnumber(); |
5019 |
|
glcal->VALIDATION = valid; |
5020 |
// |
// |
5021 |
} else { |
HandleTRK_CALIB(glcal); |
|
// |
|
|
// we have to insert a new calibration, check where to place it |
|
5022 |
// |
// |
5023 |
oss.str(""); |
delete glcal; |
5024 |
oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
} |
5025 |
<< " FROM_TIME < "<< fromtime << " AND " |
/** |
5026 |
<< " TO_TIME > "<< fromtime << ";"; |
* Fill the GL_TRK_CALIB table |
5027 |
|
*/ |
5028 |
|
void PamelaDBOperations::HandleTRK_CALIB(GL_TRK_CALIB *glcal){ |
5029 |
|
|
5030 |
|
Bool_t pk1 = (glcal->OBT1>0&&glcal->PKT1>0); |
5031 |
|
Bool_t pk2 = (glcal->OBT2>0&&glcal->PKT2>0); |
5032 |
|
UInt_t boot_number = glcal->BOOT_NUMBER; |
5033 |
|
UInt_t obt1 = glcal->OBT1; |
5034 |
|
UInt_t obt2 = glcal->OBT2; |
5035 |
|
UInt_t pkt1 = glcal->PKT1; |
5036 |
|
UInt_t pkt2 = glcal->PKT2; |
5037 |
|
UInt_t fromtime = glcal->FROM_TIME; |
5038 |
|
UInt_t totime = 0; |
5039 |
|
UInt_t idroot = glcal->ID_ROOT_L0; |
5040 |
|
UInt_t t1 = glcal->EV_ROOT_CALIBTRK1; |
5041 |
|
UInt_t t2 = glcal->EV_ROOT_CALIBTRK2; |
5042 |
|
UInt_t valid = glcal->VALIDATION; |
5043 |
// |
// |
5044 |
if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str()); |
TSQLResult *result = 0; |
5045 |
result = conn->Query(oss.str().c_str()); |
TSQLRow *row = 0; |
5046 |
// |
// |
5047 |
if ( !result ) throw -4; |
stringstream oss; |
5048 |
|
oss.str(""); |
5049 |
// |
// |
|
row = result->Next(); |
|
5050 |
// |
// |
5051 |
if ( !row ){ |
if ( !pk1 && !pk2 ){ |
5052 |
// |
if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n"); |
5053 |
// 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; |
|
|
// |
|
5054 |
}; |
}; |
5055 |
// |
// |
5056 |
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 << "',"; |
|
5057 |
// |
// |
5058 |
if ( !pk1 ){ |
oss.str(""); |
5059 |
oss << "NULL,"; |
oss << " SELECT ID FROM GL_TRK_CALIB WHERE " |
5060 |
|
<< " BOOT_NUMBER = "<< boot_number; // |
5061 |
|
oss << " AND FROM_TIME="<<fromtime; /// NEWNEWNEW -- VA BENE ?!?!?!?! |
5062 |
|
oss << " AND ( ( "; |
5063 |
|
if ( pk1 ){ |
5064 |
|
oss << " OBT1 = "<< obt1 << " AND " |
5065 |
|
<< " PKT1 = "<< pkt1 |
5066 |
|
<< " ) OR ( "; |
5067 |
} else { |
} else { |
5068 |
oss << "'" |
oss << " PKT1 = "<< pkt2-1 |
5069 |
<< t1 << "',"; |
<< " ) OR ( "; |
5070 |
}; |
}; |
5071 |
// |
if ( pk2 ){ |
5072 |
if ( !pk2 ){ |
oss << " OBT2 = "<< obt2 << " AND " |
5073 |
oss << "NULL,'"; |
<< " PKT2 = "<< pkt2; |
5074 |
} else { |
} else { |
5075 |
oss << "'" |
oss << " PKT2 = "<< pkt1+1; |
5076 |
<< t2 << "','"; |
}; |
5077 |
}; |
oss << " ) );"; |
5078 |
|
// |
5079 |
|
if ( IsDebug() ) printf(" Check if the trk calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
5080 |
|
result = conn->Query(oss.str().c_str()); |
5081 |
// |
// |
5082 |
oss << fromtime << "','" |
if ( !result ) throw -4; |
|
<< totime << "','" |
|
|
<< obt1 << "','" |
|
|
<< pkt1 << "','" |
|
|
<< obt2 << "','" |
|
|
<< pkt2 << "','" |
|
|
<< this->GetBOOTnumber() << "','" |
|
|
<< valid << "');"; |
|
5083 |
// |
// |
5084 |
if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); |
row = result->Next(); |
5085 |
// |
// |
5086 |
|
if ( row ){ |
5087 |
|
// |
5088 |
|
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
5089 |
|
if ( PEDANTIC ) throw -80; |
5090 |
|
// |
5091 |
|
} else { |
5092 |
|
// |
5093 |
|
// we have to insert a new calibration, check where to place it |
5094 |
|
// |
5095 |
|
oss.str(""); |
5096 |
|
oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
5097 |
|
<< " FROM_TIME < "<< fromtime << " AND " |
5098 |
|
<< " TO_TIME > "<< fromtime << ";"; |
5099 |
|
// |
5100 |
|
if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str()); |
5101 |
|
result = conn->Query(oss.str().c_str()); |
5102 |
|
// |
5103 |
|
if ( !result ) throw -4; |
5104 |
|
// |
5105 |
|
row = result->Next(); |
5106 |
|
// |
5107 |
|
if ( !row ){ |
5108 |
|
// |
5109 |
|
// no calibrations in the db contain our calibration |
5110 |
|
// |
5111 |
|
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); |
5112 |
|
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 |
5113 |
|
// |
5114 |
|
oss.str(""); |
5115 |
|
oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " |
5116 |
|
<< " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
5117 |
|
// |
5118 |
|
if ( IsDebug() ) printf(" Check the upper limit for calibration: query is \n %s \n",oss.str().c_str()); |
5119 |
|
result = conn->Query(oss.str().c_str()); |
5120 |
|
// |
5121 |
|
if ( !result ) throw -4; |
5122 |
|
// |
5123 |
|
row = result->Next(); |
5124 |
|
if ( !row ){ |
5125 |
|
totime = numeric_limits<UInt_t>::max(); |
5126 |
|
} else { |
5127 |
|
totime = (UInt_t)atoll(row->GetField(0)); |
5128 |
|
}; |
5129 |
|
// |
5130 |
|
} else { |
5131 |
|
// |
5132 |
|
// determine upper and lower limits and make space for the new calibration |
5133 |
|
// |
5134 |
|
totime = (UInt_t)atoll(row->GetField(1)); |
5135 |
|
// |
5136 |
|
oss.str(""); |
5137 |
|
oss << " UPDATE GL_TRK_CALIB SET " |
5138 |
|
<< " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ |
5139 |
|
<< " ID = "<< row->GetField(0) << ";"; |
5140 |
|
// |
5141 |
|
if ( IsDebug() ) printf(" Make space for the new trk calibration: query is \n %s \n",oss.str().c_str()); |
5142 |
|
result = conn->Query(oss.str().c_str()); |
5143 |
|
// |
5144 |
|
if ( !result ) throw -4; |
5145 |
|
// |
5146 |
|
}; |
5147 |
|
// |
5148 |
|
oss.str(""); |
5149 |
|
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) " |
5150 |
|
<< " VALUES (NULL,' " |
5151 |
|
<< idroot << "',"; |
5152 |
|
// |
5153 |
|
if ( !pk1 ){ |
5154 |
|
oss << "NULL,"; |
5155 |
|
} else { |
5156 |
|
oss << "'" |
5157 |
|
<< t1 << "',"; |
5158 |
|
}; |
5159 |
|
// |
5160 |
|
if ( !pk2 ){ |
5161 |
|
oss << "NULL,'"; |
5162 |
|
} else { |
5163 |
|
oss << "'" |
5164 |
|
<< t2 << "','"; |
5165 |
|
}; |
5166 |
|
// |
5167 |
|
oss << fromtime << "','" |
5168 |
|
<< totime << "','" |
5169 |
|
<< obt1 << "','" |
5170 |
|
<< pkt1 << "','" |
5171 |
|
<< obt2 << "','" |
5172 |
|
<< pkt2 << "','" |
5173 |
|
<< boot_number << "','" |
5174 |
|
<< valid << "');"; |
5175 |
|
// |
5176 |
|
if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); |
5177 |
|
// |
5178 |
|
result = conn->Query(oss.str().c_str()); |
5179 |
|
// |
5180 |
|
if ( !result ) throw -4; |
5181 |
|
// |
5182 |
|
}; |
5183 |
|
|
5184 |
|
oss.str(""); |
5185 |
|
oss << " SELECT ID FROM GL_TRK_CALIB ORDER BY ID DESC LIMIT 1 ;"; |
5186 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5187 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
5188 |
|
if ( !result ) throw -4;; |
5189 |
|
row = result->Next(); |
5190 |
|
if(row)glcal->ID = (UInt_t)atoll(row->GetField(0)); |
5191 |
// |
// |
5192 |
if ( !result ) throw -4; |
delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5193 |
// |
// |
|
}; |
|
|
// |
|
5194 |
}; |
}; |
5195 |
|
|
5196 |
/** |
/** |
5197 |
* Scan tracker calibrations packets, fill the GL_TRK_CALIB table |
* Scan tracker calibrations packets, fill the GL_TRK_CALIB table |
5198 |
*/ |
*/ |
5199 |
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++){ |
|
5200 |
// |
// |
5201 |
pret2 = t2; |
CalibTrk1Event *caltrk1 = 0; |
5202 |
tr1->GetEntry(t1); |
CalibTrk2Event *caltrk2 = 0; |
5203 |
|
TTree *tr1 = 0; |
5204 |
|
TTree *tr2 = 0; |
5205 |
|
EventHeader *eh1 = 0; |
5206 |
|
PscuHeader *ph1 = 0; |
5207 |
|
EventHeader *eh2 = 0; |
5208 |
|
PscuHeader *ph2 = 0; |
5209 |
// |
// |
5210 |
ph1 = eh1->GetPscuHeader(); |
PacketType *pctp=0; |
5211 |
obt1 = ph1->GetOrbitalTime(); |
EventCounter *codt2=0; |
|
pkt1 = ph1->GetCounter(); |
|
|
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
|
5212 |
// |
// |
5213 |
// valid = 1; |
Int_t nevents1 = 0; |
5214 |
// // |
Int_t nevents2 = 0; |
|
// if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
|
5215 |
// |
// |
5216 |
|
fromtime = 0; |
5217 |
// |
// |
5218 |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
obt1 = 0; |
5219 |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
pkt1 = 0; |
5220 |
// |
obt2 = 0; |
5221 |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u \n",fromtime,obt1,pkt1); |
pkt2 = 0; |
5222 |
// |
// |
5223 |
valid = ValidateTrkCalib( caltrk1, eh1 ); |
tr1 = (TTree*)file->Get("CalibTrk1"); |
5224 |
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
if ( !tr1 || tr1->IsZombie() ) throw -22; |
5225 |
// |
tr2 = (TTree*)file->Get("CalibTrk2"); |
5226 |
// Do we have the second calibration packet? |
if ( !tr2 || tr2->IsZombie() ) throw -23; |
5227 |
// |
// |
5228 |
while ( t2t1cal < t1+1 ){ // get the calibration packet2 that follows the packet1 |
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
5229 |
|
tr1->SetBranchAddress("Header", &eh1); |
5230 |
|
nevents1 = tr1->GetEntries(); |
5231 |
|
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
5232 |
|
tr2->SetBranchAddress("Header", &eh2); |
5233 |
|
nevents2 = tr2->GetEntries(); |
5234 |
|
// |
5235 |
|
if ( !nevents1 && !nevents2 ) return(1); |
5236 |
|
// |
5237 |
|
t2 = -1; |
5238 |
|
Int_t pret2 = 0; |
5239 |
|
Int_t t2t1cal = 0; |
5240 |
|
// |
5241 |
|
bool MISSING_pkt1 = true; |
5242 |
|
bool MISSING_pkt2 = true; |
5243 |
|
int ncalib = 0; |
5244 |
|
bool try_to_recover = false; |
5245 |
|
// |
5246 |
|
for (t1=0; t1 < nevents1; t1++){//loop over packet1 |
5247 |
// |
// |
5248 |
t2++; |
pret2 = t2; |
5249 |
|
tr1->GetEntry(t1); |
5250 |
// |
// |
5251 |
pret2 = t2 - 1; // EMILIANO |
ph1 = eh1->GetPscuHeader(); |
5252 |
|
obt1 = ph1->GetOrbitalTime(); |
5253 |
|
pkt1 = ph1->GetCounter(); |
5254 |
|
fromtime = GetAbsTime(ph1->GetOrbitalTime()); |
5255 |
// |
// |
5256 |
if ( t2 < nevents2 ){ |
// chek if the packet number and obt are consistent with the other packets ??? |
5257 |
tr2->GetEntry(t2); |
// |
5258 |
codt2 = eh2->GetCounter(); |
if ( PKT(pkt1) >= PKT(pktfirst) && PKT(pkt1) <= upperpkt && OBT(obt1) >= OBT(obtfirst) && OBT(obt1) <= upperobt ){ |
5259 |
t2t1cal = codt2->Get(pctp->CalibTrk1); |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
5260 |
// |
// |
5261 |
ph2 = eh2->GetPscuHeader(); |
if ( IsDebug() ) printf("\n Trk calibration1 %u at time %u obt %u pkt %u \n",t1,fromtime,obt1,pkt1); |
5262 |
obt2 = ph2->GetOrbitalTime(); |
// |
5263 |
pkt2 = ph2->GetCounter(); |
valid = ValidateTrkCalib( caltrk1, eh1 ); |
5264 |
// |
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
5265 |
if ( IsDebug() ) printf(" This is a trk calibration2 at obt %u pkt %u t2 is %u , t2t1cal is %u \n",obt2,pkt2,t2,t2t1cal); |
// |
5266 |
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
// Do we have the second calibration packet? |
5267 |
// |
// |
5268 |
|
if ( IsDebug() ) cout << " Loop over calibration2 to search associated calibration: "<<endl; |
5269 |
|
while ( t2t1cal < t1+1 ){ // get the calibration packet2 that follows the packet1 |
5270 |
|
// |
5271 |
|
t2++; |
5272 |
|
// |
5273 |
|
pret2 = t2 - 1; // EMILIANO |
5274 |
|
// |
5275 |
|
if ( t2 < nevents2 ){ |
5276 |
|
tr2->GetEntry(t2); |
5277 |
|
codt2 = eh2->GetCounter(); |
5278 |
|
t2t1cal = codt2->Get(pctp->CalibTrk1); |
5279 |
|
// |
5280 |
|
ph2 = eh2->GetPscuHeader(); |
5281 |
|
obt2 = ph2->GetOrbitalTime(); |
5282 |
|
pkt2 = ph2->GetCounter(); |
5283 |
|
// |
5284 |
|
if ( IsDebug() ) printf(" >> trk calibration2 at obt %u pkt %u t2 is %u , t2t1cal is %u \n",obt2,pkt2,t2,t2t1cal); |
5285 |
|
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
5286 |
|
// |
5287 |
|
} else { |
5288 |
|
// |
5289 |
|
// running out of vector without finding the corresponding calibration, sig |
5290 |
|
// |
5291 |
|
if ( IsDebug() ) printf(" t2 >= nevents2 \n"); |
5292 |
|
pret2 = t2; |
5293 |
|
obt2 = 0; |
5294 |
|
// pkt2 = pkt1+2; |
5295 |
|
pkt2 = 0; |
5296 |
|
t2t1cal = t1+1; |
5297 |
|
}; |
5298 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) && (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
5299 |
|
|
5300 |
|
// EMILIANO |
5301 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
5302 |
|
// // if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
5303 |
|
// if ( IsDebug() ) printf(" running out of vector without finding the corresponding calibration, sig \n"); |
5304 |
|
// // |
5305 |
|
// // running out of vector without finding the corresponding calibration, sig |
5306 |
|
// // |
5307 |
|
// pret2 = t2; |
5308 |
|
// obt2 = 0; |
5309 |
|
// // pkt2 = pkt1+2; |
5310 |
|
// pkt2 = 0; |
5311 |
|
// t2t1cal = t1+1; |
5312 |
|
// }; |
5313 |
|
|
5314 |
|
|
5315 |
|
// |
5316 |
|
}; |
5317 |
|
// |
5318 |
|
if ( IsDebug() ) printf(" Check if trk calibration2 is the right one \n"); |
5319 |
|
// |
5320 |
|
// EMILIANO |
5321 |
|
if ( ( PKT(pkt2) < PKT(pktfirst) || PKT(pkt2) > upperpkt) || (OBT(obt2) < OBT(obtfirst) || OBT(obt2) > upperobt) ){ |
5322 |
|
// if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
5323 |
|
if ( IsDebug() ) printf(" *WARNING* The calibration found is outside the interval, sig \n"); |
5324 |
|
// |
5325 |
|
// running out of vector without finding the corresponding calibration, sig |
5326 |
|
// |
5327 |
|
pret2 = t2; |
5328 |
|
obt2 = 0; |
5329 |
|
pkt2 = 0; |
5330 |
|
}; |
5331 |
|
if ( PKT(pkt2) == PKT(pkt1)+1 ){ |
5332 |
|
if ( IsDebug() ) cout << " ...OK"<<endl; |
5333 |
|
// ======================= |
5334 |
|
// The calibration is good |
5335 |
|
// ======================= |
5336 |
|
// |
5337 |
|
// if ( IsDebug() ) printf(" Found trk calibration2 at obt %u pkt %u t2 is %u \n",obt2,pkt2,t2); |
5338 |
|
// if ( IsDebug() ) printf(" Trk calibration2 at obt %u pkt %u t2 is %u is good \n",obt2,pkt2,t2); |
5339 |
|
// if ( IsDebug() ) printf("\n Trk calibration2 at time %u obt %u pkt %u \n",fromtime,obt2,pkt2); |
5340 |
|
if ( IsDebug() ) printf(" Trk calibration2 %u at time %u obt %u pkt %u \n",t2,fromtime,obt2,pkt2); |
5341 |
|
// |
5342 |
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
5343 |
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
5344 |
|
// valid = valid & valid2; |
5345 |
|
valid = valid & valid2; //QUESTO VA CAMBIATO |
5346 |
|
// |
5347 |
|
// Handle good calib |
5348 |
|
// |
5349 |
|
MISSING_pkt1 = false; |
5350 |
|
MISSING_pkt2 = false; |
5351 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5352 |
|
// |
5353 |
|
// Check for missing calibtrk1 |
5354 |
|
// |
5355 |
|
if ( t2 != pret2+1 ){ |
5356 |
|
// |
5357 |
|
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); |
5358 |
|
// |
5359 |
|
while ( t2 > pret2+1 ){ |
5360 |
|
// |
5361 |
|
// handle missing calib1 |
5362 |
|
// |
5363 |
|
pret2++; |
5364 |
|
// |
5365 |
|
obt1 = 0; |
5366 |
|
pkt1 = 0; |
5367 |
|
// |
5368 |
|
tr2->GetEntry(pret2); |
5369 |
|
ph2 = eh2->GetPscuHeader(); |
5370 |
|
obt2 = ph2->GetOrbitalTime(); |
5371 |
|
pkt2 = ph2->GetCounter(); |
5372 |
|
// |
5373 |
|
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
5374 |
|
// |
5375 |
|
valid = 0; |
5376 |
|
MISSING_pkt1 = true; |
5377 |
|
MISSING_pkt2 = false; |
5378 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5379 |
|
// |
5380 |
|
}; |
5381 |
|
// |
5382 |
|
}; |
5383 |
|
// |
5384 |
|
} else if ( this->PKT(pkt2) > this->PKT(pkt1)+1 ){ |
5385 |
|
// |
5386 |
|
// Check for missing calibtrk2 |
5387 |
|
// |
5388 |
|
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
5389 |
|
t2 = pret2; |
5390 |
|
// |
5391 |
|
// handle missing calib2 |
5392 |
|
// |
5393 |
|
obt2 = 0; |
5394 |
|
pkt2 = 0; |
5395 |
|
valid = 0; |
5396 |
|
MISSING_pkt1 = false; |
5397 |
|
MISSING_pkt2 = true; |
5398 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5399 |
|
// |
5400 |
|
}; |
5401 |
|
// |
5402 |
|
|
5403 |
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
5404 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5405 |
|
ncalib++; |
5406 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
5407 |
|
} |
5408 |
|
|
5409 |
|
|
5410 |
} else { |
} else { |
5411 |
// |
// |
5412 |
// 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); |
5413 |
// |
// if ( PEDANTIC ) throw -79; |
5414 |
if ( IsDebug() ) printf(" t2 >= nevents2 \n"); |
// |
|
pret2 = t2; |
|
|
obt2 = 0; |
|
|
// pkt2 = pkt1+2; |
|
|
pkt2 = 0; |
|
|
t2t1cal = t1+1; |
|
5415 |
}; |
}; |
5416 |
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) && (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
// |
5417 |
|
|
5418 |
// 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; |
|
|
// }; |
|
5419 |
|
|
5420 |
|
|
5421 |
|
|
5422 |
|
// |
5423 |
|
// we have one more calib pkt2 ! |
5424 |
|
// |
5425 |
|
t2++; |
5426 |
|
while ( t2 < nevents2 ){ |
5427 |
// |
// |
5428 |
}; |
// 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 |
|
5429 |
// |
// |
5430 |
this->HandleTRK_CALIB(true,true); |
if ( IsDebug() ) printf(" t2 is %u nevents2 is %u \n",t2,nevents2); |
5431 |
|
obt1 = 0; |
5432 |
|
pkt1 = 0; |
5433 |
// |
// |
5434 |
// Check for missing calibtrk1 |
tr2->GetEntry(t2); |
5435 |
|
ph2 = eh2->GetPscuHeader(); |
5436 |
|
obt2 = ph2->GetOrbitalTime(); |
5437 |
|
pkt2 = ph2->GetCounter(); |
5438 |
// |
// |
5439 |
if ( t2 != pret2+1 ){ |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
5440 |
// |
valid = 0; |
5441 |
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 ){ |
5442 |
// |
// EMILIANO |
5443 |
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 ){ |
5444 |
// |
// 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(); |
|
5445 |
// |
// |
5446 |
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); |
5447 |
// |
// |
5448 |
valid = 0; |
MISSING_pkt1 = true; |
5449 |
this->HandleTRK_CALIB(false,true); |
MISSING_pkt2 = false; |
5450 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
5451 |
|
ncalib++; |
5452 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
5453 |
// |
// |
|
}; |
|
|
// |
|
5454 |
}; |
}; |
5455 |
// |
// |
5456 |
} 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; |
|
5457 |
// |
// |
5458 |
// handle missing calib2 |
}; |
5459 |
|
|
5460 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
5461 |
|
// ----------------------------------------------------------------- |
5462 |
|
// in case of corruption, check if the calibration can be recovered |
5463 |
|
// from another chewbacca file |
5464 |
|
// ----------------------------------------------------------------- |
5465 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
5466 |
|
|
5467 |
|
// cout <<" TRY TO RECOVER ?? "<<try_to_recover<<endl; |
5468 |
|
|
5469 |
|
if(chewbacca&&try_to_recover){ |
5470 |
|
|
5471 |
|
|
5472 |
|
if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<<endl; |
5473 |
|
|
5474 |
|
TSQLResult *rresult = 0; // 10RED bug, result is re-used inside result looop... |
5475 |
|
TSQLResult *result = 0; // 10RED bug, result is re-used inside result looop... |
5476 |
|
TSQLRow *row = 0; |
5477 |
// |
// |
5478 |
obt2 = 0; |
stringstream oss; |
5479 |
pkt2 = 0; |
oss.str(""); |
|
valid = 0; |
|
|
this->HandleTRK_CALIB(true,false); |
|
5480 |
// |
// |
5481 |
}; |
|
5482 |
// |
//////////////////////////////////////////////////////////////////////// |
5483 |
} else { |
// retrieve the name of the current file: |
5484 |
// |
//////////////////////////////////////////////////////////////////////// |
5485 |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
oss.str(""); |
5486 |
// if ( PEDANTIC ) throw -79; |
oss << "SELECT NAME FROM GL_ROOT where ID=" << GetID_ROOT() <<";"; |
5487 |
// |
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5488 |
}; |
|
5489 |
// |
result = conn->Query(oss.str().c_str()); |
5490 |
}; |
if ( !result ) throw -4;; |
5491 |
// |
row = result->Next(); |
5492 |
// we have one more calib pkt2 ! |
TString thisfilename = (TString)row->GetField(0); |
5493 |
// |
if ( IsDebug() ) cout << "Current file ==> "<<thisfilename<<endl; |
5494 |
t2++; |
|
5495 |
while ( t2 < nevents2 ){ |
//////////////////////////////////////////////////////////////////////// |
5496 |
// |
// read all the calibrations inserted |
5497 |
// handle missing calib1 |
//////////////////////////////////////////////////////////////////////// |
5498 |
// |
oss.str(""); |
5499 |
if ( IsDebug() ) printf(" t2 is %u nevents2 is %u \n",t2,nevents2); |
oss << " SELECT "; |
5500 |
obt1 = 0; |
oss << " ID,FROM_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,TO_TIME"; |
5501 |
pkt1 = 0; |
oss << " FROM GL_TRK_CALIB "; |
5502 |
// |
oss << " ORDER BY ID DESC LIMIT "<<ncalib<<"; "; |
5503 |
tr2->GetEntry(t2); |
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5504 |
ph2 = eh2->GetPscuHeader(); |
|
5505 |
obt2 = ph2->GetOrbitalTime(); |
rresult = conn->Query(oss.str().c_str()); |
5506 |
pkt2 = ph2->GetCounter(); |
if ( !result ) throw -4;; |
5507 |
// |
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5508 |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
|
5509 |
valid = 0; |
// ----------------------------------- |
5510 |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
// loop over calibrations ... |
5511 |
// EMILIANO |
// ----------------------------------- |
5512 |
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; |
5513 |
// if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
do { |
5514 |
// |
row = rresult->Next(); |
5515 |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
if(!row)break; |
5516 |
// |
|
5517 |
this->HandleTRK_CALIB(false,true); |
UInt_t id = (UInt_t)atoll(row->GetField(0)); |
5518 |
// |
UInt_t fromtime = (UInt_t)atoll(row->GetField(1)); |
5519 |
}; |
UInt_t obt1 = (UInt_t)atoll(row->GetField(2)); |
5520 |
// |
UInt_t pkt1 = (UInt_t)atoll(row->GetField(3)); |
5521 |
t2++; |
UInt_t obt2 = (UInt_t)atoll(row->GetField(4)); |
5522 |
// |
UInt_t pkt2 = (UInt_t)atoll(row->GetField(5)); |
5523 |
}; |
UInt_t boot = (UInt_t)atoll(row->GetField(6)); |
5524 |
|
UInt_t valid = (UInt_t)atoll(row->GetField(7)); |
5525 |
|
bool MISSING_pkt1 = (row->GetFieldLength(8)==0); |
5526 |
|
bool MISSING_pkt2 = (row->GetFieldLength(9)==0); |
5527 |
|
UInt_t totime = (UInt_t)atoll(row->GetField(10)); |
5528 |
|
|
5529 |
|
// ------------------------------------- |
5530 |
|
// ...check if the entry is corrupted... |
5531 |
|
// ------------------------------------- |
5532 |
|
cout <<"*** "<< MISSING_pkt1 << MISSING_pkt2 << valid <<endl; |
5533 |
|
bool CORRUPTED = (MISSING_pkt1||MISSING_pkt2||!valid); |
5534 |
|
|
5535 |
|
if ( IsDebug() ) cout << "("<<nn<<") ID = "<<id<<" from GL_TRK_CALIB ==> corrupted ? "<<CORRUPTED<<endl; |
5536 |
|
|
5537 |
|
// if( !CORRUPTED )continue; // nothing to do |
5538 |
|
|
5539 |
|
///////////////////////////////////////////////////////// |
5540 |
|
// if it is corrupted, ...look for ather chewbacca files |
5541 |
|
// containing the same calibrations ... |
5542 |
|
///////////////////////////////////////////////////////// |
5543 |
|
|
5544 |
|
bool this_MISSING_pkt1 = false; |
5545 |
|
bool this_MISSING_pkt2 = false; |
5546 |
|
int this_t1=0; |
5547 |
|
int this_t2=0;; |
5548 |
|
UInt_t this_valid = 0; |
5549 |
|
|
5550 |
|
TString path = ""; |
5551 |
|
TString name = ""; |
5552 |
|
TString raw = ""; |
5553 |
|
// UInt_t obt0 = 0; |
5554 |
|
// UInt_t timesync = 0; |
5555 |
|
// UInt_t boot_number = 0; |
5556 |
|
bool FOUND = false; |
5557 |
|
|
5558 |
|
if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl; |
5559 |
|
|
5560 |
|
// for(int itable=0; itable<2; itable++){ |
5561 |
|
for(int itable=0; itable<1; itable++){ |
5562 |
|
|
5563 |
|
// ------------------------------------------------------ |
5564 |
|
// loop over both ROOT_TABLE and ROOT_TABLE_BAD |
5565 |
|
// ------------------------------------------------------ |
5566 |
|
|
5567 |
|
TString table = "ROOT_TABLE"; |
5568 |
|
if(itable==1)table = "ROOT_TABLE_BAD"; |
5569 |
|
|
5570 |
|
oss.str(""); |
5571 |
|
oss << " SELECT "; |
5572 |
|
oss << " FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,BOOT_NUMBER,INPUT_NAME "; |
5573 |
|
oss << " FROM "<<table; |
5574 |
|
oss << " WHERE 1 " << endl; |
5575 |
|
oss << " AND FILE_NAME != \""<< thisfilename<<"\""; |
5576 |
|
if( !MISSING_pkt1 ){ |
5577 |
|
oss << " AND "; |
5578 |
|
oss << " PKT_NUMBER_INIT < "<<pkt1; |
5579 |
|
oss << " AND "; |
5580 |
|
oss << " PKT_NUMBER_FINAL > "<<pkt1; |
5581 |
|
oss << " AND "; |
5582 |
|
oss << " PKT_OBT_INIT < "<<obt1; |
5583 |
|
oss << " AND "; |
5584 |
|
oss << " PKT_OBT_FINAL > "<<obt1; |
5585 |
|
}else{ |
5586 |
|
if(pkt2>1) pkt1 = pkt2-1;//serve dopo |
5587 |
|
} |
5588 |
|
if( !MISSING_pkt2 ){ |
5589 |
|
oss << " AND "; |
5590 |
|
oss << " PKT_NUMBER_INIT < "<<pkt2; |
5591 |
|
oss << " AND "; |
5592 |
|
oss << " PKT_NUMBER_FINAL > "<<pkt2; |
5593 |
|
oss << " AND "; |
5594 |
|
oss << " PKT_OBT_INIT < "<<obt2; |
5595 |
|
oss << " AND "; |
5596 |
|
oss << " PKT_OBT_FINAL > "<<obt2; |
5597 |
|
}else{ |
5598 |
|
if(pkt1>0) pkt2 = pkt1+1;//serve dopo |
5599 |
|
} |
5600 |
|
if( boot> 0 ){ |
5601 |
|
oss << " AND "; |
5602 |
|
oss << " BOOT_NUMBER = "<<boot; |
5603 |
|
}else{ |
5604 |
|
} |
5605 |
|
oss << " ORDER BY BAD_PKT_CALREAD ASC; "; |
5606 |
|
|
5607 |
|
TSQLResult *result2 = 0; |
5608 |
|
TSQLRow *row2 = 0; |
5609 |
|
|
5610 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5611 |
|
result2 = conn->Query(oss.str().c_str()); |
5612 |
|
if ( !result2 ) throw -4;; |
5613 |
|
if ( IsDebug() ) cout <<"Rows: "<<result2->GetRowCount()<<endl; |
5614 |
|
|
5615 |
|
// ------------------------------------------------------ |
5616 |
|
// loop over files containing repetition (if any) |
5617 |
|
// ------------------------------------------------------ |
5618 |
|
do { |
5619 |
|
row2 = result2->Next(); |
5620 |
|
if(!row2)break; |
5621 |
|
|
5622 |
|
// ------------------------------------------------------ |
5623 |
|
// ... a repetition is found ... |
5624 |
|
// ------------------------------------------------------ |
5625 |
|
path = (TString)row2->GetField(0); |
5626 |
|
name = (TString)row2->GetField(1); |
5627 |
|
raw = (TString)row2->GetField(5); |
5628 |
|
// obt0 = (UInt_t)atoll(row2->GetField(2)); |
5629 |
|
// timesync = (UInt_t)atoll(row2->GetField(3)); |
5630 |
|
// boot_number = (UInt_t)atoll(row2->GetField(4)); |
5631 |
|
|
5632 |
|
if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl; |
5633 |
|
// cout << path <<endl; |
5634 |
|
// cout << "File : " <<name <<endl; |
5635 |
|
// cout << obt0 <<endl; |
5636 |
|
// cout << timesync <<endl; |
5637 |
|
// cout << "boot n. : "<<boot_number <<endl; |
5638 |
|
// cout << raw <<endl; |
5639 |
|
|
5640 |
|
// ------------------------------------------------------ |
5641 |
|
// ... retrieve the calibration packets. |
5642 |
|
// ------------------------------------------------------ |
5643 |
|
if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data()); |
5644 |
|
TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it |
5645 |
|
if(!file)throw -100; |
5646 |
|
if(file->IsZombie())throw -100; |
5647 |
|
// |
5648 |
|
tr1 = (TTree*)file->Get("CalibTrk1"); |
5649 |
|
if ( !tr1 || tr1->IsZombie() ) throw -22; |
5650 |
|
tr2 = (TTree*)file->Get("CalibTrk2"); |
5651 |
|
if ( !tr2 || tr2->IsZombie() ) throw -23; |
5652 |
|
// |
5653 |
|
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
5654 |
|
tr1->SetBranchAddress("Header", &eh1); |
5655 |
|
nevents1 = tr1->GetEntries(); |
5656 |
|
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
5657 |
|
tr2->SetBranchAddress("Header", &eh2); |
5658 |
|
nevents2 = tr2->GetEntries(); |
5659 |
|
for(this_t1=0; this_t1<nevents1; this_t1++){ |
5660 |
|
tr1->GetEntry(this_t1); |
5661 |
|
if( |
5662 |
|
(UInt_t)eh1->GetPscuHeader()->GetCounter() == pkt1 && |
5663 |
|
true) break; |
5664 |
|
this_MISSING_pkt1 = true; |
5665 |
|
} |
5666 |
|
for(this_t2=0; this_t2<nevents2; this_t2++){ |
5667 |
|
tr2->GetEntry(this_t2); |
5668 |
|
if( |
5669 |
|
(UInt_t)eh2->GetPscuHeader()->GetCounter() == pkt2 && |
5670 |
|
true) break; |
5671 |
|
this_MISSING_pkt2 = true; |
5672 |
|
} |
5673 |
|
this_valid = |
5674 |
|
ValidateTrkCalib( caltrk1, eh1, file ) |
5675 |
|
* |
5676 |
|
ValidateTrkCalib( caltrk2, eh2, file ); |
5677 |
|
|
5678 |
|
// --------------------------------------------------------------------- |
5679 |
|
// accept the calibration if it is better than the previous: |
5680 |
|
// |
5681 |
|
// - if the new calibration is perfect (both valid packets) |
5682 |
|
// - if the new calibration has both the packets and the previous does not |
5683 |
|
// --------------------------------------------------------------------- |
5684 |
|
if( |
5685 |
|
( !this_MISSING_pkt1&&!this_MISSING_pkt2&&this_valid )|| |
5686 |
|
( (MISSING_pkt1||MISSING_pkt2) && (!this_MISSING_pkt1&&!this_MISSING_pkt2) )|| |
5687 |
|
false)FOUND=true; |
5688 |
|
|
5689 |
|
if(file)file->Close(); |
5690 |
|
|
5691 |
|
if(FOUND)break; |
5692 |
|
|
5693 |
|
}while(1);//endl loop over root table entries |
5694 |
|
|
5695 |
|
delete result2; // 10RED potential memory leak |
5696 |
|
if(FOUND)break; |
5697 |
|
|
5698 |
|
}//end loop over tables |
5699 |
|
|
5700 |
|
if(FOUND){ |
5701 |
|
|
5702 |
|
if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl; |
5703 |
|
|
5704 |
|
//////////////////////////////////////////// |
5705 |
|
// insert a new entry in GL_TRK_CALIB and |
5706 |
|
// modify the time-tag of the previous one |
5707 |
|
//////////////////////////////////////////// |
5708 |
|
|
5709 |
|
// --------------------------------------------------------------------- |
5710 |
|
// step 1: insert a new raw file in GL_RAW |
5711 |
|
// --------------------------------------------------------------------- |
5712 |
|
// |
5713 |
|
// check if the raw file already exist |
5714 |
|
// |
5715 |
|
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 |
5716 |
|
// oss.str(""); |
5717 |
|
// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
5718 |
|
// if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5719 |
|
|
5720 |
|
// result = conn->Query(oss.str().c_str()); |
5721 |
|
// if ( !result ) throw -4;; |
5722 |
|
// if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5723 |
|
// if( result->GetRowCount() == 0){ |
5724 |
|
// if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
5725 |
|
// // - - - - - - - - - - - |
5726 |
|
// // insert new raw file |
5727 |
|
// // - - - - - - - - - - - |
5728 |
|
// GL_RAW glraw = GL_RAW(); |
5729 |
|
// glraw.PATH = gSystem->DirName(raw.Data()); |
5730 |
|
// glraw.NAME = gSystem->BaseName(raw.Data()); |
5731 |
|
// glraw.BOOT_NUMBER = boot_number; |
5732 |
|
// // |
5733 |
|
// insertPamelaRawFile( &glraw ); |
5734 |
|
// // |
5735 |
|
// id_raw = glraw.ID; |
5736 |
|
// }else{ |
5737 |
|
// row = result->Next(); |
5738 |
|
// id_raw = (UInt_t)atoll(row->GetField(0)); |
5739 |
|
// } |
5740 |
|
// if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
5741 |
|
|
5742 |
|
// --------------------------------------------------------------------- |
5743 |
|
// step 1(bis): retrieve the timesync id associated to the file |
5744 |
|
// (NB, uso lo stesso associato al file iniziale) |
5745 |
|
// --------------------------------------------------------------------- |
5746 |
|
UInt_t idtimesync = 0; |
5747 |
|
oss.str(""); |
5748 |
|
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
5749 |
|
if ( debug ) printf(" %s \n",oss.str().c_str()); |
5750 |
|
result = conn->Query(oss.str().c_str()); |
5751 |
|
if ( !result ) throw -3; |
5752 |
|
row = result->Next(); |
5753 |
|
if ( !row ) throw -3; |
5754 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
5755 |
|
if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl; |
5756 |
|
|
5757 |
|
delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5758 |
|
// --------------------------------------------------------------------- |
5759 |
|
// step 2: insert a new root file in GL_ROOT |
5760 |
|
// --------------------------------------------------------------------- |
5761 |
|
// |
5762 |
|
// check if the root file already exist |
5763 |
|
// |
5764 |
|
UInt_t id_root = 0; |
5765 |
|
oss.str(""); |
5766 |
|
oss << "SELECT ID FROM GL_ROOT where NAME=\"" << gSystem->BaseName(name.Data()) <<"\";"; |
5767 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5768 |
|
|
5769 |
|
result = conn->Query(oss.str().c_str()); |
5770 |
|
if ( !result ) throw -4;; |
5771 |
|
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5772 |
|
if( result->GetRowCount() == 0){ |
5773 |
|
if ( IsDebug() ) cout << " << Insert new ROOT file >> "<<endl; |
5774 |
|
// - - - - - - - - - - - |
5775 |
|
// insert new root file |
5776 |
|
// - - - - - - - - - - - |
5777 |
|
GL_ROOT glroot = GL_ROOT(); |
5778 |
|
glroot.ID_RAW = id_raw; |
5779 |
|
glroot.ID_TIMESYNC = idtimesync; |
5780 |
|
// |
5781 |
|
// 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, |
5782 |
|
// NOT STATIC NOT KEEPENV = $PAM_L0 must be used in the DB |
5783 |
|
// |
5784 |
|
if ( STATIC ){ |
5785 |
|
glroot.PATH = (TString)gSystem->ExpandPathName(path); |
5786 |
|
} else { |
5787 |
|
if ( KEEPENV ){ |
5788 |
|
glroot.PATH = path; |
5789 |
|
} else { |
5790 |
|
glroot.PATH = "$PAM_L0"; |
5791 |
|
}; |
5792 |
|
}; |
5793 |
|
// glroot.PATH = path; |
5794 |
|
glroot.NAME = name; |
5795 |
|
// |
5796 |
|
insertPamelaRootFile( &glroot ); |
5797 |
|
// |
5798 |
|
id_root = glroot.ID; |
5799 |
|
}else{ |
5800 |
|
row = result->Next(); |
5801 |
|
if(row)id_root = (UInt_t)atoll(row->GetField(0)); |
5802 |
|
} |
5803 |
|
if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl; |
5804 |
|
|
5805 |
|
delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5806 |
|
// --------------------------------------------------------------------- |
5807 |
|
// step 3: modify time-tag of corrupted GL_TRK_CALIB entry |
5808 |
|
// --------------------------------------------------------------------- |
5809 |
|
if ( IsDebug() ) cout << " << Modify time-tag of calibration ID="<<id<<" >> "<<endl; |
5810 |
|
oss.str(""); |
5811 |
|
oss << " UPDATE GL_TRK_CALIB SET " |
5812 |
|
<< " TO_TIME=0 , FROM_TIME=0 WHERE " |
5813 |
|
<< " ID = "<< id << ";"; |
5814 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5815 |
|
result = conn->Query(oss.str().c_str()); |
5816 |
|
if ( !result ) throw -4;; |
5817 |
|
|
5818 |
|
delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages] |
5819 |
|
|
5820 |
|
// --------------------------------------------------------------------- |
5821 |
|
// step 4: insert the new calibration: |
5822 |
|
// --------------------------------------------------------------------- |
5823 |
|
if ( IsDebug() ) cout << " << Insert new TRK calibration >> "<<endl; |
5824 |
|
// |
5825 |
|
GL_TRK_CALIB glcal = GL_TRK_CALIB(); |
5826 |
|
// |
5827 |
|
glcal.ID_ROOT_L0 = id_root; |
5828 |
|
glcal.EV_ROOT_CALIBTRK1 = this_t1; |
5829 |
|
glcal.EV_ROOT_CALIBTRK2 = this_t2; |
5830 |
|
glcal.FROM_TIME = fromtime; |
5831 |
|
glcal.TO_TIME = totime; |
5832 |
|
glcal.OBT1 = obt1; |
5833 |
|
glcal.OBT2 = obt2; |
5834 |
|
glcal.PKT1 = pkt1; |
5835 |
|
glcal.PKT2 = pkt1; |
5836 |
|
glcal.BOOT_NUMBER = GetBOOTnumber(); |
5837 |
|
glcal.VALIDATION = this_valid; |
5838 |
|
// |
5839 |
|
HandleTRK_CALIB(&glcal); |
5840 |
|
if ( IsDebug() ) cout << "ID = "<<glcal.ID<<endl; |
5841 |
|
// |
5842 |
|
|
5843 |
|
} |
5844 |
|
if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl; |
5845 |
|
|
5846 |
|
}while(1);//end loop over calibrations |
5847 |
|
|
5848 |
|
|
5849 |
|
if( rresult )delete rresult; // 10RED bug |
5850 |
|
if( row )delete row; |
5851 |
|
|
5852 |
|
|
5853 |
|
|
5854 |
|
|
5855 |
|
|
5856 |
|
|
5857 |
|
} |
5858 |
|
|
5859 |
|
|
5860 |
|
// // ------------------------------ |
5861 |
|
// // try to recover the calibration |
5862 |
|
// // ------------------------------ |
5863 |
|
// cout << "TRY TO RECOVER TRACKER CALIBRATION"<<endl; |
5864 |
|
// // |
5865 |
|
// ULong64_t time = 0; //absolute time |
5866 |
|
// string path[100]; //mettere un limite massimo |
5867 |
|
// int nrows = 0; |
5868 |
|
// UInt_t pkt = 0; |
5869 |
|
// UInt_t obt = 0; |
5870 |
|
// char *type = ""; |
5871 |
|
// EventHeader *eh = new EventHeader(); |
5872 |
|
// CalibTrk1Event *c = new CalibTrk1Event(); |
5873 |
|
|
5874 |
|
// // |
5875 |
|
// if(which_is_not_valid==1 || which_is_not_valid==3){ |
5876 |
|
// // |
5877 |
|
// cout << "PKT1 --> missing or corrupted "<<endl; |
5878 |
|
// type = "CalibTrk1"; |
5879 |
|
// pkt = pkt1; |
5880 |
|
// obt = obt1; |
5881 |
|
// time = this->GetAbsTime(obt1); |
5882 |
|
// if( pkt1 == 0 ){//missing |
5883 |
|
// time = this->GetAbsTime(obt2); |
5884 |
|
// pkt = pkt2-1; |
5885 |
|
// } |
5886 |
|
// // |
5887 |
|
// }else if (which_is_not_valid==2 || which_is_not_valid==3){ |
5888 |
|
// // |
5889 |
|
// cout << "PKT2--> missing or corrupted "<<endl; |
5890 |
|
// type = "CalibTrk2 "; |
5891 |
|
// pkt = pkt2; |
5892 |
|
// obt = obt2; |
5893 |
|
// time = this->GetAbsTime(obt2); |
5894 |
|
// if( pkt2 == 0 ){//missing |
5895 |
|
// time = this->GetAbsTime(obt1); |
5896 |
|
// pkt = pkt1+1; |
5897 |
|
// } |
5898 |
|
// // |
5899 |
|
// }else{ |
5900 |
|
// cout << "this should not happen!!! "<<endl; |
5901 |
|
// trow -666; |
5902 |
|
// } |
5903 |
|
|
5904 |
|
// nrows = Query_ROOT_TABLE(time,conn,path);// get the list of file which might contain the packet |
5905 |
|
|
5906 |
|
|
5907 |
|
// for(int r=0; r<nrows; r++){ //loop over rows |
5908 |
|
// if(path)cout << r << " >>>> "<<(path+r)->c_str() << endl; |
5909 |
|
// /// verifica che il file non sia quello gia` aperto |
5910 |
|
// } |
5911 |
|
|
5912 |
|
// //////////////////////////////////////////////////////////////////////// |
5913 |
|
|
5914 |
|
// TSQLResult *result = 0; |
5915 |
|
// TSQLRow *row = 0; |
5916 |
|
// // |
5917 |
|
// stringstream oss; |
5918 |
|
// oss.str(""); |
5919 |
|
// // ---------------------------------------- |
5920 |
|
// // read the id of last calibration inserted |
5921 |
|
// // ---------------------------------------- |
5922 |
|
// oss.str(""); |
5923 |
|
// oss << " SELECT "; |
5924 |
|
// oss << " (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) "; |
5925 |
|
// oss << " ORDER BY ID DESC LIMIT 1; "; |
5926 |
|
|
5927 |
|
// result = conn->Query(oss.str().c_str()); |
5928 |
|
// row = result->Next(); |
5929 |
|
// if( !row )throw -666; |
5930 |
|
|
5931 |
|
// if( result )delete result; |
5932 |
|
// if( row )delete row; |
5933 |
|
|
5934 |
|
// UInt_t id = (UInt_t)atoll(row->GetField(0)); |
5935 |
|
|
5936 |
|
// // ------------------------------------- |
5937 |
|
// // ...and modify it with new parameters |
5938 |
|
// // ------------------------------------- |
5939 |
|
|
5940 |
|
|
5941 |
|
// } |
5942 |
// |
// |
5943 |
return(0); |
return(0); |
5944 |
}; |
}; |
6147 |
memset(myid,0,500*sizeof(UInt_t)); |
memset(myid,0,500*sizeof(UInt_t)); |
6148 |
// |
// |
6149 |
oss.str(""); |
oss.str(""); |
6150 |
oss << "SELECT ID,RUNTRAILER_TIME,RUNTRAILER_PKT,BOOT_NUMBER FROM GL_RUN_FRAGMENTS WHERE INSERT_TIME <= '" << clean_time->AsSQLString() << "'order BY RUNHEADER_TIME asc;"; |
oss << "SELECT ID,RUNTRAILER_TIME,RUNTRAILER_PKT,BOOT_NUMBER FROM GL_RUN_FRAGMENTS WHERE INSERT_TIME <= '" << clean_time->AsSQLString() << "' order BY RUNHEADER_TIME asc;"; |
6151 |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
6152 |
nresult = conn->Query(oss.str().c_str()); |
nresult = conn->Query(oss.str().c_str()); |
6153 |
// |
// |
6178 |
while ( anr ){ |
while ( anr ){ |
6179 |
// |
// |
6180 |
oss.str(""); |
oss.str(""); |
6181 |
oss << "SELECT ID,RUNTRAILER_TIME,RUNTRAILER_PKT,BOOT_NUMBER FROM GL_RUN_FRAGMENTS WHERE BOOT_NUMBER=" << mbo << " AND RUNHEADER_PKT=" << mrhp << "+1 AND ABS(RUNHEADER_TIME-"<< mrht <<")<=1 AND INSERT_TIME <= '" << clean_time->AsSQLString() << "' order BY RUNHEADER_TIME asc;"; |
oss << "SELECT ID,RUNTRAILER_TIME,RUNTRAILER_PKT,BOOT_NUMBER FROM GL_RUN_FRAGMENTS WHERE BOOT_NUMBER=" << mbo << " AND RUNHEADER_PKT=" << mrhp << "+1 AND ABS(RUNHEADER_TIME-"<< (float)mrht <<")<=1 AND INSERT_TIME <= '" << clean_time->AsSQLString() << "' order BY RUNHEADER_TIME asc;"; // 10RED MYSQL OPERATOR BUG |
6182 |
if ( IsDebug() ) printf(" In the loop searching for fragmented runs : query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" In the loop searching for fragmented runs : query is \n %s \n",oss.str().c_str()); |
6183 |
// |
// |
6184 |
nresult1 = conn->Query(oss.str().c_str()); |
nresult1 = conn->Query(oss.str().c_str()); |
6268 |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
6269 |
// |
// |
6270 |
oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " |
oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " |
6271 |
<< " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT()<< ";"; |
<< " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT(); |
6272 |
|
oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112 |
6273 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
6274 |
}; |
}; |
6275 |
}; |
}; |
6318 |
if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){ |
if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){ |
6319 |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6320 |
// |
// |
6321 |
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";"; |
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT(); |
6322 |
|
oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112 |
6323 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
6324 |
}; |
}; |
6325 |
}; |
}; |
6370 |
row2 = result2->Next(); |
row2 = result2->Next(); |
6371 |
// |
// |
6372 |
if ( row2 ){ |
if ( row2 ){ |
6373 |
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"); |
6374 |
if ( PEDANTIC ) throw -83; |
if ( PEDANTIC ) throw -83; |
6375 |
row2->Close(); |
row2->Close(); |
6376 |
}; |
}; |
6447 |
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
6448 |
// |
// |
6449 |
oss.str(""); |
oss.str(""); |
6450 |
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 " |
6451 |
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
6452 |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
6453 |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
6505 |
moved++; |
moved++; |
6506 |
// |
// |
6507 |
} else { |
} else { |
6508 |
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
|
6509 |
if ( PEDANTIC ) throw -83; |
// questa parte mah mah mah... da controllare |
6510 |
|
|
6511 |
|
// |
6512 |
|
// 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 |
6513 |
|
// "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number. |
6514 |
|
// |
6515 |
|
// 090112 [8RED (-70): RUN ALREADY INSERTED] |
6516 |
|
// |
6517 |
|
Bool_t OK = false; |
6518 |
|
UInt_t IDRL2A = 0; |
6519 |
|
UInt_t IDRL2B = 0; |
6520 |
|
if ( result2->GetRowCount() == 2 ){ |
6521 |
|
IDRL2A = (UInt_t)atoll(row2->GetField(0)); |
6522 |
|
UInt_t IDRL0A = (UInt_t)atoll(row2->GetField(4)); |
6523 |
|
row2 = result2->Next(); |
6524 |
|
IDRL2B = (UInt_t)atoll(row2->GetField(0)); |
6525 |
|
UInt_t IDRL0B = (UInt_t)atoll(row2->GetField(4)); |
6526 |
|
if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B); |
6527 |
|
// if ( IDRL0A == IDRL0B ){ |
6528 |
|
// TSQLResult *result2a = 0; |
6529 |
|
// TSQLRow *row2a = 0; |
6530 |
|
// oss.str(""); |
6531 |
|
// oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;"; |
6532 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
6533 |
|
// result2a = conn->Query(oss.str().c_str()); |
6534 |
|
// // |
6535 |
|
// if ( !result2a ) throw -4; |
6536 |
|
// // |
6537 |
|
// row2a = result2a->Next(); |
6538 |
|
// // |
6539 |
|
// if ( row2a ){ |
6540 |
|
// UInt_t PKA = (UInt_t)atoll(row2a->GetField(0)); |
6541 |
|
// delete result2a; |
6542 |
|
// oss.str(""); |
6543 |
|
// oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;"; |
6544 |
|
// if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str()); |
6545 |
|
// result2a = conn->Query(oss.str().c_str()); |
6546 |
|
// // |
6547 |
|
// if ( !result2a ) throw -4; |
6548 |
|
// // |
6549 |
|
// row2a = result2a->Next(); |
6550 |
|
// // |
6551 |
|
// if ( row2a ){ |
6552 |
|
// UInt_t PKB = (UInt_t)atoll(row2a->GetField(0)); |
6553 |
|
// // |
6554 |
|
// 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); |
6555 |
|
// if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){ |
6556 |
|
// if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); |
6557 |
|
OK = true; |
6558 |
|
// }; |
6559 |
|
// }; |
6560 |
|
// }; |
6561 |
|
// }; |
6562 |
|
}; |
6563 |
|
if ( OK ){ |
6564 |
|
// |
6565 |
|
// this is the case in which we must insert a piece of run between two fragments in the GL_RUN table |
6566 |
|
// |
6567 |
|
// 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 ) |
6568 |
|
// |
6569 |
|
GL_RUN *glA = new GL_RUN(); |
6570 |
|
glA->Query_GL_RUN(IDRL2A,conn); |
6571 |
|
// |
6572 |
|
if ( glA->GetACQ_BUILD_INFO() != 0 ){ |
6573 |
|
// |
6574 |
|
// the first piece contains a good runheader we can update all the other runs with correct infos! |
6575 |
|
// |
6576 |
|
oss.str(""); |
6577 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6578 |
|
<< " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , " |
6579 |
|
<< " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
6580 |
|
<< " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , " |
6581 |
|
<< " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , " |
6582 |
|
<< " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , " |
6583 |
|
<< " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , " |
6584 |
|
<< " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , " |
6585 |
|
<< " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , " |
6586 |
|
<< " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , " |
6587 |
|
<< " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , " |
6588 |
|
<< " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , " |
6589 |
|
<< " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , " |
6590 |
|
<< " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , " |
6591 |
|
<< " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , " |
6592 |
|
<< " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , "; |
6593 |
|
// |
6594 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
6595 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , "; |
6596 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
6597 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , "; |
6598 |
|
// |
6599 |
|
oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC(); |
6600 |
|
oss << " WHERE ID=" << glrun->GetID() << ";"; |
6601 |
|
if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str()); |
6602 |
|
conn->Query(oss.str().c_str()); |
6603 |
|
// |
6604 |
|
} else { |
6605 |
|
// |
6606 |
|
// sig no runheader, let set anyway what is possible... |
6607 |
|
// |
6608 |
|
oss.str(""); |
6609 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6610 |
|
<< " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "; |
6611 |
|
// |
6612 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) |
6613 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; |
6614 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) |
6615 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; |
6616 |
|
// |
6617 |
|
oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " |
6618 |
|
<< " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT(); |
6619 |
|
oss << " WHERE ID=" << glrun->GetID() << ";"; |
6620 |
|
if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str()); |
6621 |
|
conn->Query(oss.str().c_str()); |
6622 |
|
}; |
6623 |
|
// |
6624 |
|
// update runheader ROOT_ID_FRAG |
6625 |
|
// |
6626 |
|
oss.str(""); |
6627 |
|
oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; |
6628 |
|
if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); |
6629 |
|
conn->Query(oss.str().c_str()); |
6630 |
|
// |
6631 |
|
// now let's look for runtrailer if any in the last run |
6632 |
|
// |
6633 |
|
glA->Query_GL_RUN(IDRL2B,conn); |
6634 |
|
// |
6635 |
|
if ( glA->GetPKT_READY_COUNTER() != 0 ){ |
6636 |
|
// |
6637 |
|
// the first piece contains a good runtrailer we can update all the other runs with correct infos! |
6638 |
|
// |
6639 |
|
oss.str(""); |
6640 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6641 |
|
<< " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
6642 |
|
<< " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , " |
6643 |
|
<< " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , " |
6644 |
|
<< " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , "; |
6645 |
|
// |
6646 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
6647 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
6648 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) { |
6649 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6650 |
|
// |
6651 |
|
oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER() |
6652 |
|
<< " WHERE ID=" << glrun->GetID() << ";"; |
6653 |
|
if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str()); |
6654 |
|
conn->Query(oss.str().c_str()); |
6655 |
|
// |
6656 |
|
} else { |
6657 |
|
// |
6658 |
|
// sig no runtrailer, let set anyway what is possible... |
6659 |
|
// |
6660 |
|
oss.str(""); |
6661 |
|
oss << "UPDATE GL_RUN_FRAGMENTS SET " |
6662 |
|
<< " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , " |
6663 |
|
<< " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "; |
6664 |
|
// |
6665 |
|
if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){ |
6666 |
|
oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; |
6667 |
|
if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){ |
6668 |
|
oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; |
6669 |
|
// |
6670 |
|
oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT() |
6671 |
|
<< " WHERE ID=" << glrun->GetID() << ";"; |
6672 |
|
if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str()); |
6673 |
|
conn->Query(oss.str().c_str()); |
6674 |
|
}; |
6675 |
|
// |
6676 |
|
UInt_t myi = glrun->GetID(); |
6677 |
|
oss.str(""); |
6678 |
|
oss << " ID= "<< myi; |
6679 |
|
// |
6680 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
6681 |
|
// |
6682 |
|
// fill the new run in GL_RUN |
6683 |
|
// |
6684 |
|
glrun->SetID_RUN_FRAG(IDRL2B); |
6685 |
|
glrun->Fill_GL_RUN(conn); |
6686 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
6687 |
|
delete glA; |
6688 |
|
moved++; |
6689 |
|
// |
6690 |
|
} else { |
6691 |
|
// |
6692 |
|
// is just a repetition |
6693 |
|
// |
6694 |
|
if ( IsDebug() ) printf(" The run %u is already present in the GL_RUN table...\n",glrun->GetID()); |
6695 |
|
// printf(" CCCCCCCCICCCCCCCCCCCCIOOOOOOOOOO si muove Ciccio! %u \n",glrun->GetID()); |
6696 |
|
// if ( PEDANTIC && glrun->GetID() != 61563 ) throw -83; |
6697 |
|
if ( PEDANTIC ) throw -83; |
6698 |
|
}; |
6699 |
|
// if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! ...\n"); |
6700 |
|
// if ( PEDANTIC ) throw -83; |
6701 |
}; |
}; |
6702 |
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)); |
6703 |
// |
// |
6763 |
// 2) get the OBT of the last validated run |
// 2) get the OBT of the last validated run |
6764 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
6765 |
oss.str(""); |
oss.str(""); |
6766 |
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 |
6767 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start |
6768 |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
6769 |
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()); |
6770 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
6907 |
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 |
6908 |
|
|
6909 |
if( !CHECK && this_run->VALIDATION ){ |
if( !CHECK && this_run->VALIDATION ){ |
6910 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
// for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
6911 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION); |
6912 |
nseq=0; |
nseq=0; |
6913 |
} |
} |
6914 |
|
|
6929 |
if( CHECK ){ |
if( CHECK ){ |
6930 |
// check if calibration exists |
// check if calibration exists |
6931 |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
6932 |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
// Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
6933 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
UInt_t MISSING = MissingTRK_CALIB(t1,t2); |
6934 |
|
UInt_t val = 0; |
6935 |
|
if ( MISSING == 1 ) val = 0; |
6936 |
|
if ( MISSING == 0 ) val = 1; |
6937 |
|
if ( MISSING == 2 ) val = 2; |
6938 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val); |
6939 |
nseq=0; |
nseq=0; |
6940 |
}; |
}; |
6941 |
//-------------- |
//-------------- |
6965 |
* @param t2 To absolute time |
* @param t2 To absolute time |
6966 |
* @return true if there might be a missing calibration |
* @return true if there might be a missing calibration |
6967 |
*/ |
*/ |
6968 |
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
//Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6969 |
|
UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6970 |
|
|
6971 |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
6972 |
|
|
6973 |
// get the closest VALIDATED calibration before the run start (t2) |
// get the closest calibration before the run start (t2) |
6974 |
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
// if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
6975 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1); //>>> missing |
6976 |
|
|
6977 |
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
// if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
6978 |
|
if ( trkcalib->TO_TIME < t2 ) return(1); //>>> missing |
6979 |
|
|
6980 |
//============================================================== |
//============================================================== |
6981 |
// Check is done first on the basis of time between calibration, |
// Check is done first on the basis of time between calibration, |
6992 |
//============================================================== |
//============================================================== |
6993 |
Bool_t DOWNLOAD = false; |
Bool_t DOWNLOAD = false; |
6994 |
// check if the calib was skipped becouse of download .... DA FARE!! |
// check if the calib was skipped becouse of download .... DA FARE!! |
6995 |
if(DOWNLOAD)return(false); |
// if(DOWNLOAD)return(false); |
6996 |
|
if(DOWNLOAD)return(0); |
6997 |
|
|
6998 |
return(true); //>>> missing |
// return(true); //>>> missing |
6999 |
|
return(1); //>>> missing |
7000 |
|
|
7001 |
}; |
}; |
7002 |
|
|
7006 |
//============================================================== |
//============================================================== |
7007 |
// the long time interval bewteen runs might be due to download |
// the long time interval bewteen runs might be due to download |
7008 |
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); |
7009 |
return(false); |
if ( trkcalib->VALIDATION ) return(0); |
7010 |
|
if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n"); |
7011 |
|
return(2); |
7012 |
|
|
7013 |
}; |
}; |
7014 |
/** |
/** |
7017 |
* @param validation true/false |
* @param validation true/false |
7018 |
*/ |
*/ |
7019 |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
7020 |
|
return(this->assignVALIDATION(idrun,(UInt_t)validation)); |
7021 |
|
} |
7022 |
|
|
7023 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){ |
7024 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
7025 |
stringstream oss; |
stringstream oss; |
7026 |
oss.str(""); |
oss.str(""); |
7217 |
stringstream myquery; |
stringstream myquery; |
7218 |
// |
// |
7219 |
myquery.str(""); |
myquery.str(""); |
7220 |
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() <<"';"; |
7221 |
// |
// |
7222 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
7223 |
// |
// |
7233 |
// |
// |
7234 |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
7235 |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
7236 |
|
UInt_t idtsy=(UInt_t)atoll(Row->GetField(2)); |
7237 |
// |
// |
7238 |
this->ValidationOFF(); |
this->ValidationOFF(); |
7239 |
// |
// |
7241 |
// |
// |
7242 |
this->RemoveRUNS(); |
this->RemoveRUNS(); |
7243 |
// |
// |
7244 |
this->RemoveFILES(); |
this->RemoveFILES(idtsy); |
7245 |
// |
// |
7246 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
7247 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
7461 |
* Rearrange calibration tables |
* Rearrange calibration tables |
7462 |
* |
* |
7463 |
**/ |
**/ |
7464 |
void PamelaDBOperations::RemoveFILES(){ |
void PamelaDBOperations::RemoveFILES(UInt_t idtsy){ |
7465 |
stringstream myquery; |
stringstream myquery; |
7466 |
// |
// |
7467 |
myquery.str(""); |
myquery.str(""); |
7471 |
// |
// |
7472 |
conn->Query(myquery.str().c_str()); |
conn->Query(myquery.str().c_str()); |
7473 |
// |
// |
7474 |
|
myquery.str(""); |
7475 |
|
myquery << " DELETE FROM GL_ROOT WHERE ID=" <<this->GetID_ROOT() <<";"; |
7476 |
|
// |
7477 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
7478 |
|
// |
7479 |
|
conn->Query(myquery.str().c_str()); // |
7480 |
|
// |
7481 |
|
if ( !chewbacca ){ |
7482 |
|
myquery.str(""); |
7483 |
|
myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";"; |
7484 |
|
// |
7485 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
7486 |
|
// |
7487 |
|
conn->Query(myquery.str().c_str()); |
7488 |
|
}; |
7489 |
|
// |
7490 |
}; |
}; |
7491 |
|
|
7492 |
/** |
/** |
7691 |
* Rearrange calibration tables |
* Rearrange calibration tables |
7692 |
* |
* |
7693 |
**/ |
**/ |
7694 |
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh , TFile *file){ |
7695 |
|
|
7696 |
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; // :-) |
|
7697 |
|
|
7698 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
if ( IsDebug() ) cout << "ValidateTrkCalib:"<<endl; |
7699 |
|
|
7700 |
// ----------------------------------------------- |
UInt_t validate = 1; |
7701 |
// If missing packets: check the acq configuration |
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
7702 |
// (some DSPs might be excluded from acquisition) |
UInt_t timeaftercalib=120000; //2000; |
7703 |
// ----------------------------------------------- |
TString classname = caltrk->GetName(); |
7704 |
|
|
7705 |
// ----------------------------------------------- |
// ---------------------------------- |
7706 |
// retrieve the first run header after calib |
// Check CRCs and failed calibrations |
7707 |
// ----------------------------------------------- |
// ---------------------------------- |
7708 |
PacketType *pctp; |
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
7709 |
EventCounter *cod; |
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
7710 |
cod = eh->GetCounter(); |
if( caltrk->crc_hcal[ipkt] ){ |
7711 |
Int_t irun = cod->Get(pctp->RunHeader); |
// if(IsDebug())cout<<"(CRC Header)"; |
7712 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
validate = 0; |
7713 |
if ( !rh || rh->IsZombie() ) throw -17; |
if(IsDebug())cout <<endl<<" *** CRC *** (header DSPn "<<caltrk->DSPnumber[ipkt]<<")"; |
7714 |
if( rh->GetEntries() == irun ){ |
|
7715 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
} |
7716 |
return 0; // :-( |
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){ |
7717 |
} |
// if(IsDebug())cout<<"(CRC Pkt-"<<ilad<<")"; |
7718 |
|
if(IsDebug())cout <<endl<<" *** CRC *** (data DSPn "<<caltrk->DSPnumber[ipkt]<<" ladder "<<ilad<<")"; |
7719 |
|
validate = 0; |
7720 |
|
} |
7721 |
|
if( !(caltrk->ncalib_event[ipkt]==0 && caltrk->cal_flag[ipkt]==0) ){ |
7722 |
|
if(IsDebug())cout <<endl<<" *** FAILURE *** (data DSPn "<<caltrk->DSPnumber[ipkt]<<")"; |
7723 |
|
validate = 0; |
7724 |
|
} |
7725 |
|
}else{ |
7726 |
|
// validate=0; |
7727 |
|
if(IsDebug())cout <<endl<<" *** DSPn *** ("<< caltrk->DSPnumber[ipkt] <<" @pkt "<<ipkt<<")"; |
7728 |
|
} |
7729 |
|
} |
7730 |
|
|
7731 |
RunHeaderEvent *run = 0; |
// ----------------------- |
7732 |
EventHeader *hrun = 0; |
// Check missing packets: |
7733 |
rh->SetBranchAddress("RunHeader", &run); |
// ----------------------- |
7734 |
rh->SetBranchAddress("Header", &hrun); |
// Readout order: |
7735 |
rh->GetEntry(irun); |
// ------------------ |
7736 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
// DSP packet board |
7737 |
|
// ------------------ |
7738 |
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
// 12 0 1 |
7739 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
// 10 1 1 |
7740 |
return 0; // :-( |
// 8 2 1 |
7741 |
} |
// 4 3 1 |
7742 |
|
// 6 4 1 |
7743 |
if( !run->RM_ACQ_AFTER_CALIB ){ |
// 2 5 1 |
7744 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
// ------------------ |
7745 |
return 0; // :-( |
// 11 0 2 |
7746 |
} |
// 9 1 2 |
7747 |
|
// 7 2 2 |
7748 |
|
// 3 3 2 |
7749 |
|
// 5 4 2 |
7750 |
|
// 1 5 2 |
7751 |
|
// ------------------ |
7752 |
|
// ------------------------------------------------- |
7753 |
|
// Check if it is first or second calibration packet |
7754 |
|
// ------------------------------------------------- |
7755 |
|
UInt_t build=0; |
7756 |
|
UInt_t base=0; |
7757 |
|
UInt_t mask=0; |
7758 |
|
if(classname.Contains("CalibTrk1Event")){ |
7759 |
|
base=12; |
7760 |
|
mask=0x03F000; |
7761 |
|
} |
7762 |
|
if(classname.Contains("CalibTrk2Event")){ |
7763 |
|
base=18; |
7764 |
|
mask=0xFC0000; |
7765 |
|
} |
7766 |
|
// ---------------------------------------------------- |
7767 |
|
// Count number of valid packets and set build variable |
7768 |
|
// ---------------------------------------------------- |
7769 |
|
if(IsDebug())cout <<endl<< " DSP: "; |
7770 |
|
Int_t npkts=0; |
7771 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
7772 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
7773 |
|
if(IsDebug())cout <<" "<<caltrk->DSPnumber[ipkt]; |
7774 |
|
npkts++; |
7775 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
7776 |
|
// cout << caltrk->DSPnumber[ipkt] |
7777 |
|
}; |
7778 |
|
} |
7779 |
|
if(IsDebug())cout << " ==> "<< hex << build << dec; |
7780 |
|
// ---------------------------------------------------- |
7781 |
|
// If the number of valid packets is 6, ok exit... |
7782 |
|
// ---------------------------------------------------- |
7783 |
|
if( npkts==6 ){ |
7784 |
|
return validate; // exit |
7785 |
|
} |
7786 |
|
//////////////////////////////////////////////////////// |
7787 |
|
// ...otherwise there might be some missing packets |
7788 |
|
// |
7789 |
|
// In this case check the acq configuration |
7790 |
|
// (some DSPs might be excluded from acquisition) |
7791 |
|
//////////////////////////////////////////////////////// |
7792 |
|
|
7793 |
|
if(!eh || !file || (file&&file->IsZombie()) ){ |
7794 |
|
if ( IsDebug() )cout << " *** MISSING VIEW *** eh="<<eh<<" file="<<file<<" cannot validate"<<endl; |
7795 |
|
return (0); |
7796 |
|
} |
7797 |
|
|
7798 |
|
// ----------------------------------------------- |
7799 |
|
// retrieve the first run header after calib |
7800 |
|
// ----------------------------------------------- |
7801 |
|
|
7802 |
|
PacketType *pctp; |
7803 |
|
EventCounter *cod; |
7804 |
|
cod = eh->GetCounter(); |
7805 |
|
Int_t irun = cod->Get(pctp->RunHeader); |
7806 |
|
TTree *rh=(TTree*)file->Get("RunHeader"); |
7807 |
|
if ( !rh || rh->IsZombie() ) throw -17; |
7808 |
|
if( rh->GetEntries() <= irun ){ |
7809 |
|
if ( IsDebug() ) cout << " *** MISSING-PKT *** no runs after calib (1) -- cannot validate :-( "<<endl; |
7810 |
|
return 0; // :-( |
7811 |
|
} |
7812 |
|
RunHeaderEvent *run = 0; |
7813 |
|
EventHeader *hrun = 0; |
7814 |
|
rh->SetBranchAddress("RunHeader", &run); |
7815 |
|
rh->SetBranchAddress("Header", &hrun); |
7816 |
|
rh->GetEntry(irun); |
7817 |
|
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
7818 |
|
if ( IsDebug() ) cout << " *** MISSING-PKT *** no runs after calib (2) -- cannot validate :-( "<<endl; |
7819 |
|
return 0; // :-( |
7820 |
|
} |
7821 |
|
|
7822 |
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
7823 |
if( dtime > timeaftercalib ){ |
if( dtime > timeaftercalib ){ |
7824 |
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; |
7825 |
return 0; // :-( |
return 0; // :-( |
7826 |
} |
} |
|
|
|
7827 |
|
|
7828 |
|
if ( IsDebug() ) cout <<endl<< " ACQ_BUILD_INFO ==> "<<hex<<(run->ACQ_BUILD_INFO & mask)<<dec; |
7829 |
|
|
7830 |
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
7831 |
|
validate=0; // :-( |
7832 |
|
cout <<endl<< " *** MISSING-PKT *** packet mismatch: ACQ_BUILD_INFO="<<hex<<(run->ACQ_BUILD_INFO&mask)<<" != "<<build<<dec; |
7833 |
|
}; |
7834 |
|
|
7835 |
|
return validate; |
7836 |
|
|
|
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; // :-) |
|
7837 |
|
|
7838 |
} |
} |
7839 |
|
|