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 |
chewbacca = false; |
chewbacca = false; |
64 |
chminentry = 0; |
chminentry = 0; |
76 |
// |
// |
77 |
}; |
}; |
78 |
// |
// |
79 |
|
KEEPENV = false; |
80 |
|
if ( keepenv ) KEEPENV=true; |
81 |
STATIC=false; |
STATIC=false; |
82 |
if ( staticp ) STATIC=true; |
if ( staticp ) STATIC=true; |
83 |
// |
// |
101 |
if (INSERT_RAW) SetRawName(filerawname); |
if (INSERT_RAW) SetRawName(filerawname); |
102 |
// |
// |
103 |
INSERT_ROOT = !filerootname.IsNull(); |
INSERT_ROOT = !filerootname.IsNull(); |
104 |
|
if ( INSERT_ROOT ) this->SetRootName(filerootname); |
105 |
this->SetOrbitNo(dwinput); |
this->SetOrbitNo(dwinput); |
106 |
// |
// |
107 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
135 |
stringstream qu; |
stringstream qu; |
136 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
137 |
TSQLResult *result2 = 0; |
TSQLResult *result2 = 0; |
138 |
|
TSQLResult *result3 = 0; |
139 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
140 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
141 |
|
TSQLRow *row3 = 0; |
142 |
TString chpath; |
TString chpath; |
143 |
TString chfile; |
TString chfile; |
144 |
UInt_t ridn = 0; |
UInt_t ridn = 0; |
145 |
qu.str(""); |
qu.str(""); |
146 |
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 from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; |
147 |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
148 |
result = conn->Query(qu.str().c_str()); |
result = conn->Query(qu.str().c_str()); |
149 |
if ( result ){ |
if ( result ){ |
154 |
chpktmax = (UInt_t)atoll(row->GetField(2)); |
chpktmax = (UInt_t)atoll(row->GetField(2)); |
155 |
chobtmin = (UInt_t)atoll(row->GetField(3)); |
chobtmin = (UInt_t)atoll(row->GetField(3)); |
156 |
chobtmax = (UInt_t)atoll(row->GetField(4)); |
chobtmax = (UInt_t)atoll(row->GetField(4)); |
157 |
|
chiby = (TString)(row->GetField(5)); |
158 |
} else { |
} else { |
159 |
throw -84; |
throw -84; |
160 |
}; |
}; |
163 |
}; |
}; |
164 |
delete result; |
delete result; |
165 |
qu.str(""); |
qu.str(""); |
166 |
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 << ";"; |
167 |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
168 |
result2 = conn->Query(qu.str().c_str()); |
result2 = conn->Query(qu.str().c_str()); |
169 |
if ( result2 ){ |
if ( result2 ){ |
170 |
row2 = result2->Next(); |
row2 = result2->Next(); |
171 |
if ( row2 ){ |
if ( row2 ){ |
172 |
chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; |
if ( KEEPENV ){ |
173 |
|
chpath = (TString)(row2->GetField(0))+'/'; |
174 |
|
} else { |
175 |
|
chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; |
176 |
|
}; |
177 |
chfile = (TString)(row2->GetField(1)); |
chfile = (TString)(row2->GetField(1)); |
178 |
chobtts = (UInt_t)atoll(row2->GetField(2)); |
chobtts = (UInt_t)atoll(row2->GetField(2)); |
179 |
chlastts = (UInt_t)atoll(row2->GetField(3)); |
chlastts = (UInt_t)atoll(row2->GetField(3)); |
180 |
chresursts = (UInt_t)atoll(row2->GetField(4)); |
chresursts = (UInt_t)atoll(row2->GetField(4)); |
181 |
chboot = (UInt_t)atoll(row2->GetField(5)); |
chboot = (UInt_t)atoll(row2->GetField(5)); |
182 |
// |
// |
183 |
|
if ( !chboot ){ |
184 |
|
qu.str(""); |
185 |
|
qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< chlastts <<")<10000 AND (REAL_TIME_INIT-"<< row2->GetField(10) <<")<7200 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; |
186 |
|
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
187 |
|
result3 = conn->Query(qu.str().c_str()); |
188 |
|
if ( result3 ){ |
189 |
|
row3 = result3->Next(); |
190 |
|
if ( row3 && result3->GetRowCount() == 1 ){ |
191 |
|
chboot = (UInt_t)atoll(row3->GetField(0)); |
192 |
|
if ( debug ) printf(" Found boot_number = %u \n",chboot); |
193 |
|
} else { |
194 |
|
if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n"); |
195 |
|
throw -29; |
196 |
|
}; |
197 |
|
}; |
198 |
|
}; |
199 |
|
// |
200 |
chpktinit = (UInt_t)atoll(row2->GetField(6)); |
chpktinit = (UInt_t)atoll(row2->GetField(6)); |
201 |
chpktfinal = (UInt_t)atoll(row2->GetField(7)); |
chpktfinal = (UInt_t)atoll(row2->GetField(7)); |
202 |
chobtinit = (UInt_t)atoll(row2->GetField(8)); |
chobtinit = (UInt_t)atoll(row2->GetField(8)); |
209 |
throw -85; |
throw -85; |
210 |
}; |
}; |
211 |
filerootname = chpath + chfile;// + ".root"; |
filerootname = chpath + chfile;// + ".root"; |
|
if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data()); |
|
212 |
}; |
}; |
213 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
|
file = TFile::Open(this->GetRootName().Data()); |
|
|
} else { |
|
|
this->SetRootName(""); |
|
214 |
}; |
}; |
215 |
|
if ( debug ) printf(" Filename is %s \n",filerootname.Data()); |
216 |
|
file = TFile::Open(this->GetRootName().Data()); |
217 |
|
// } else { |
218 |
|
// this->SetRootName(""); |
219 |
|
// this->SetRootName(filerootname); |
220 |
|
// }; |
221 |
} |
} |
222 |
|
|
223 |
// |
// |
417 |
return; |
return; |
418 |
}; |
}; |
419 |
// |
// |
420 |
TString name = this->GetRootFile(); |
if ( !chewbacca ){ |
421 |
Int_t nlength = name.Length(); |
TString name = this->GetRootFile(); |
422 |
if ( nlength < 5 ) return; |
Int_t nlength = name.Length(); |
423 |
TString dwo = 0; |
if ( nlength < 5 ){ |
424 |
for (Int_t i = 0; i<5; i++){ |
if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data()); |
425 |
dwo.Append(name[i],1); |
return; |
426 |
}; |
}; |
427 |
if ( dwo.IsDigit() ){ |
TString dwo = 0; |
428 |
dworbit = (UInt_t)dwo.Atoi(); |
for (Int_t i = 0; i<5; i++){ |
|
} else { |
|
|
dwo=""; |
|
|
for (Int_t i = 8; i<13; i++){ |
|
429 |
dwo.Append(name[i],1); |
dwo.Append(name[i],1); |
430 |
}; |
}; |
431 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ){ |
432 |
|
dworbit = (UInt_t)dwo.Atoi(); |
433 |
|
} else { |
434 |
|
dwo=""; |
435 |
|
for (Int_t i = 8; i<13; i++){ |
436 |
|
dwo.Append(name[i],1); |
437 |
|
}; |
438 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
439 |
|
}; |
440 |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
441 |
}; |
}; |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
|
442 |
return; |
return; |
443 |
}; |
}; |
444 |
|
|
469 |
|
|
470 |
TString PamelaDBOperations::GetRootPath(){ |
TString PamelaDBOperations::GetRootPath(){ |
471 |
if ( STATIC ){ |
if ( STATIC ){ |
472 |
return((TString)gSystem->DirName(filerootname.Data())+'/'); |
return((TString)gSystem->DirName(this->GetRootName().Data())+'/'); |
473 |
} else { |
} else { |
474 |
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
if ( KEEPENV ){ |
475 |
|
return((TString)gSystem->ExpandPathName(gSystem->DirName(filerootname.Data()))+'/'); |
476 |
|
} else { |
477 |
|
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
478 |
|
}; |
479 |
}; |
}; |
480 |
}; |
}; |
481 |
|
|
687 |
UInt_t tjump = 50000; |
UInt_t tjump = 50000; |
688 |
//UInt_t tjump = 100; |
//UInt_t tjump = 100; |
689 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
690 |
pktlast = numeric_limits<UInt_t>::max(); |
// pktlast = numeric_limits<UInt_t>::max(); |
691 |
while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){ |
pktlast = chpktmax + 1; |
692 |
|
while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){ |
693 |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
694 |
T->GetEntry(nevent-1-it); |
T->GetEntry(nevent-1-it); |
695 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
697 |
} else { |
} else { |
698 |
pktlast = chpktmax + 1; |
pktlast = chpktmax + 1; |
699 |
}; |
}; |
700 |
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)); |
701 |
it += tjump; |
it += tjump; |
702 |
}; |
}; |
703 |
if ( tjump > 1 ) it -= 2*tjump; |
if ( tjump > 1 ) it -= 2*tjump; |
721 |
tjump = 50000; |
tjump = 50000; |
722 |
//tjump = 100; |
//tjump = 100; |
723 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
724 |
pktlast = 0; |
// pktlast = 0; |
725 |
while ( pktlast < chpktmin && it < (Int_t)nevent ){ |
pktlast = chpktmin - 1; |
726 |
|
if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin)); |
727 |
|
while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){ |
728 |
if ( it < (Int_t)nevent ){ |
if ( it < (Int_t)nevent ){ |
729 |
T->GetEntry(it); |
T->GetEntry(it); |
730 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1166 |
stringstream oss; |
stringstream oss; |
1167 |
// |
// |
1168 |
oss.str(""); |
oss.str(""); |
1169 |
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. |
1170 |
|
if ( !strcmp(tag.Data(),"NONE") ){ |
1171 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< chiby.Data() <<"');"; |
1172 |
|
} else { |
1173 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1174 |
|
}; |
1175 |
|
} else { |
1176 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1177 |
|
}; |
1178 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1179 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1180 |
oss.str(""); |
oss.str(""); |
1379 |
// |
// |
1380 |
// 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)); |
1381 |
// |
// |
1382 |
if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1383 |
// 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()); |
1384 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1385 |
}; |
}; |
1513 |
// PUBLIC FUNCTIONS |
// PUBLIC FUNCTIONS |
1514 |
// |
// |
1515 |
|
|
|
// /** |
|
|
// * Insert a new row into GL_RAW table. |
|
|
// */ |
|
|
// Int_t PamelaDBOperations::insertPamelaRawFile(){ |
|
|
// // |
|
|
// stringstream oss; |
|
|
// // |
|
|
// Bool_t idr = this->SetID_RAW(); |
|
|
// if ( idr ) return(1); |
|
|
// // |
|
|
// oss.str(""); |
|
|
// if ( STATIC ){ |
|
|
// oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
|
|
// << this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; |
|
|
// } else { |
|
|
// oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')"; |
|
|
// }; |
|
|
// if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
|
|
// // |
|
|
// idr = this->SetID_RAW(); |
|
|
// if ( !idr ) throw -11; |
|
|
// // |
|
|
// return(0); |
|
|
// } |
|
1516 |
/** |
/** |
1517 |
* Insert a new row into GL_RAW table. |
* Insert a new row into GL_RAW table. |
1518 |
*/ |
*/ |
1526 |
|
|
1527 |
glraw.PATH = GetRawPath(); |
glraw.PATH = GetRawPath(); |
1528 |
glraw.NAME = GetRawFile(); |
glraw.NAME = GetRawFile(); |
1529 |
glraw.BOOT_NUMBER = 0;//??? |
// glraw.BOOT_NUMBER = 0;//??? |
1530 |
|
glraw.BOOT_NUMBER = this->GetBOOTnumber(); |
1531 |
|
|
1532 |
if( insertPamelaRawFile(&glraw) )return(1); |
if( insertPamelaRawFile(&glraw) )return(1); |
1533 |
// |
// |
1541 |
*/ |
*/ |
1542 |
Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ |
Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ |
1543 |
// |
// |
1544 |
if(!glraw)return(1);//?? |
if(!glraw)return(1);//?? ok I think |
1545 |
// |
// |
1546 |
stringstream oss; |
stringstream oss; |
1547 |
// |
// |
1604 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1605 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1606 |
row = result->Next(); |
row = result->Next(); |
1607 |
|
if ( !row ) throw -92; |
1608 |
idresof = (UInt_t)atoll(row->GetField(0)); |
idresof = (UInt_t)atoll(row->GetField(0)); |
1609 |
existsts = true; |
existsts = true; |
1610 |
goto eout; |
goto eout; |
1879 |
return(signal); |
return(signal); |
1880 |
} |
} |
1881 |
|
|
|
// /** |
|
|
// * Insert all the new rows into GL_ROOT. |
|
|
// * The raw file indicates in the parameters should be already been stored in the database. |
|
|
// */ |
|
|
// Int_t PamelaDBOperations::insertPamelaRootFile(){ |
|
|
// stringstream oss; |
|
|
// TSQLResult *result = 0; |
|
|
// TSQLRow *row = 0; |
|
|
// UInt_t idtimesync = 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; |
|
|
// // |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// if ( !row ) throw -3; |
|
|
// idtimesync = (UInt_t)atoll(row->GetField(0)); |
|
|
// } else { |
|
|
// oss.str(""); |
|
|
// if ( STATIC ){ |
|
|
// oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
|
|
// << " LEFT JOIN GL_ROOT " |
|
|
// << " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
|
|
// << " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
|
|
// << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
|
|
// } else { |
|
|
// oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
|
|
// << " LEFT JOIN GL_ROOT " |
|
|
// << " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
|
|
// << " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
|
|
// << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
|
|
// }; |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// // |
|
|
// if ( !result ) throw -12; |
|
|
// // |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// if ( !row ) throw -10; |
|
|
// if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
|
|
// idroot = (UInt_t)atoll(row->GetField(2)); |
|
|
// return(1); |
|
|
// }; |
|
|
// // |
|
|
// // determine which timesync has to be used |
|
|
// // |
|
|
// oss.str(""); |
|
|
// 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;"; |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// // |
|
|
// if ( !result ) throw -3; |
|
|
// // |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// if ( !row ) throw -3; |
|
|
// idtimesync = (UInt_t)atoll(row->GetField(0)); |
|
|
// }; |
|
|
// // |
|
|
// oss.str(""); |
|
|
// if ( STATIC ){ |
|
|
// oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
|
|
// << 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() << "')"; |
|
|
// }; |
|
|
// // |
|
|
// if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
|
|
// if (conn->Query(oss.str().c_str()) == 0) throw -4; |
|
|
// // |
|
|
// delete result; |
|
|
// // |
|
|
// oss.str(""); |
|
|
// // oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
|
|
// if ( STATIC ){ |
|
|
// 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() <<"';"; |
|
|
// }; |
|
|
// // |
|
|
// if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -12; |
|
|
// row = result->Next(); |
|
|
// if ( !row ) throw -3; |
|
|
// this->SetID_ROOT((UInt_t)atoll(row->GetField(0))); |
|
|
// if ( debug ) printf(" The ID of the ROOT file is %u \n",this->GetID_ROOT()); |
|
|
// // |
|
|
// delete result; |
|
|
// // |
|
|
// return(0); |
|
|
// } |
|
1882 |
/** |
/** |
1883 |
* Insert all the new rows into GL_ROOT. |
* Insert all the new rows into GL_ROOT. |
1884 |
* 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. |
1888 |
stringstream oss; |
stringstream oss; |
1889 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1890 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1891 |
// |
// |
1892 |
// ---------------------- |
// ---------------------- |
1893 |
// determine the timesync |
// determine the timesync |
1894 |
// ---------------------- |
// ---------------------- |
1960 |
|
|
1961 |
glroot.ID_RAW = GetID_RAW(); |
glroot.ID_RAW = GetID_RAW(); |
1962 |
glroot.ID_TIMESYNC = idtimesync; |
glroot.ID_TIMESYNC = idtimesync; |
1963 |
glroot.PATH = GetRootPath(); |
if ( STATIC ){ |
1964 |
|
glroot.PATH = GetRootPath(); |
1965 |
|
} else { |
1966 |
|
if ( KEEPENV ){ |
1967 |
|
glroot.PATH = gSystem->DirName(filerootname.Data()); |
1968 |
|
} else { |
1969 |
|
glroot.PATH = "$PAM_L0"; |
1970 |
|
}; |
1971 |
|
}; |
1972 |
glroot.NAME = GetRootFile(); |
glroot.NAME = GetRootFile(); |
1973 |
|
|
1974 |
if ( insertPamelaRootFile(&glroot) )return 1; |
if ( insertPamelaRootFile(&glroot) )return 1; |
1983 |
* 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. |
1984 |
*/ |
*/ |
1985 |
Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ |
Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ |
|
|
|
|
|
|
|
|
|
1986 |
stringstream oss; |
stringstream oss; |
1987 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1988 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1989 |
// |
// |
1990 |
// |
// |
1991 |
oss.str(""); |
oss.str(""); |
1992 |
if ( STATIC ){ |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
1993 |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
<< glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')"; |
|
<< glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')"; |
|
|
} else { |
|
|
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
|
|
<< glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '$PAM_L0', '" << glroot->NAME << "')"; |
|
|
}; |
|
1994 |
// |
// |
1995 |
if ( debug ) printf("%s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
1996 |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
1999 |
// |
// |
2000 |
oss.str(""); |
oss.str(""); |
2001 |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
2002 |
if ( STATIC ){ |
oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';"; |
|
oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';"; |
|
|
} else { |
|
|
oss << "SELECT ID FROM GL_ROOT WHERE PATH='$PAM_L0' and NAME='"<< glroot->NAME <<"';"; |
|
|
}; |
|
2003 |
// |
// |
2004 |
if ( debug ) printf("%s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
2005 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
2267 |
ptht = cod->Get(pctp->RunHeader) - 1; |
ptht = cod->Get(pctp->RunHeader) - 1; |
2268 |
// evbeft = cod->Get(pctp->Physics); |
// evbeft = cod->Get(pctp->Physics); |
2269 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2270 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2271 |
evbeft = TMath::Min(upperentry,(tcod-1)); |
evbeft = TMath::Min(upperentry,(tcod-1)); |
2272 |
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)); |
2273 |
// |
// |
2306 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2307 |
cod = ehh->GetCounter(); |
cod = ehh->GetCounter(); |
2308 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2309 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2310 |
evbefh = TMath::Max(chminentry,(tcod-1)); |
evbefh = TMath::Max(chminentry,(tcod-1)); |
2311 |
// |
// |
2312 |
if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){ |
if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){ |
2345 |
// |
// |
2346 |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
2347 |
// |
// |
2348 |
|
// what about pth=ptht-1 |
2349 |
}; |
}; |
2350 |
}; |
}; |
2351 |
// |
// |
2368 |
cod = ehh->GetCounter(); |
cod = ehh->GetCounter(); |
2369 |
// evbeft = cod->Get(pctp->Physics); |
// evbeft = cod->Get(pctp->Physics); |
2370 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics); |
2371 |
if ( !tcod ) tcod = 1; |
if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT |
2372 |
evbeft = TMath::Min(upperentry,(tcod-1)); |
evbeft = TMath::Min(upperentry,(tcod-1)); |
2373 |
rh->GetEntry(pth); |
rh->GetEntry(pth); |
2374 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2408 |
// if ( ptt+1 == rtev){ |
// if ( ptt+1 == rtev){ |
2409 |
if ( conptt+1 == nrtev ){ |
if ( conptt+1 == nrtev ){ |
2410 |
// if ( conptt+1 == (nrtev+nrtbef )){ |
// if ( conptt+1 == (nrtev+nrtbef )){ |
2411 |
|
if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); |
2412 |
ptht++; |
ptht++; |
2413 |
if ( ptht < rhev ){ |
if ( ptht < rhev ){ |
2414 |
rh->GetEntry(ptht); |
rh->GetEntry(ptht); |
2415 |
|
//pth++; |
2416 |
|
//if ( pth < rhev ){ |
2417 |
|
//rh->GetEntry(pth); |
2418 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2419 |
pkth = phh->GetCounter(); |
pkth = phh->GetCounter(); |
2420 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2438 |
if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){ |
if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){ |
2439 |
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); |
2440 |
// |
// |
2441 |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
// if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
2442 |
rt->GetEntry(ptt-1); |
if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here! |
2443 |
|
// rt->GetEntry(ptt-1); |
2444 |
|
rt->GetEntry(rtev-1); |
2445 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
2446 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics)+1; |
2447 |
evbefh = TMath::Max(chminentry,tcod); |
evbefh = TMath::Max(chminentry,tcod); |
2448 |
// evbefh = cod->Get(pctp->Physics); |
// evbefh = cod->Get(pctp->Physics); |
2449 |
rt->GetEntry(ptt); |
rt->GetEntry(ptt); |
2674 |
// |
// |
2675 |
// 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 |
2676 |
// |
// |
2677 |
if ( rhfirstev != firstev && !mishead ) mishead = true; |
if ( firstev != (lastev+1) ){ // could be a problem sometimes (?) |
2678 |
if ( rtlastev != lastev && !mistrail ) mistrail = true; |
if ( rhfirstev != firstev && !mishead ) mishead = true; |
2679 |
|
if ( rtlastev != lastev && !mistrail ) mistrail = true; |
2680 |
|
}; |
2681 |
// |
// |
2682 |
|
if ( IsDebug() ) printf(" bhere firstev is %i lastev is %i \n",firstev,lastev); |
2683 |
this->FillClass(mishead,mistrail,firstev,lastev); |
this->FillClass(mishead,mistrail,firstev,lastev); |
2684 |
|
if ( IsDebug() ) printf(" chere firstev is %i lastev is %i \n",firstev,lastev); |
2685 |
// |
// |
2686 |
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"); |
2687 |
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()); |
2776 |
// |
// |
2777 |
found = false; // default value |
found = false; // default value |
2778 |
// |
// |
2779 |
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"); |
2780 |
// |
// |
2781 |
// 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: |
2782 |
// |
// |
2792 |
if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); |
if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); |
2793 |
// |
// |
2794 |
found = true; |
found = true; |
2795 |
|
if ( IsDebug() ) printf(" where firstev is %i lastev is %i \n",firstev,lastev); |
2796 |
// |
// |
2797 |
} else { |
} else { |
2798 |
// |
// |
2858 |
oss << " ID="<<row->GetField(0)<<";"; |
oss << " ID="<<row->GetField(0)<<";"; |
2859 |
// |
// |
2860 |
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 |
2861 |
|
if ( IsDebug() ) printf(" there firstev is %i lastev is %i \n",firstev,lastev); |
2862 |
// |
// |
2863 |
// merge infos |
// merge infos |
2864 |
// |
// |
2889 |
glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); |
glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); |
2890 |
glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); |
glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); |
2891 |
// |
// |
2892 |
|
if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev); |
2893 |
|
// |
2894 |
glrun->SetEV_FROM(firstev); |
glrun->SetEV_FROM(firstev); |
2895 |
glrun->SetNEVENTS(lastev-firstev+1); |
glrun->SetNEVENTS(lastev-firstev+1); |
2896 |
// |
// |
2983 |
// |
// |
2984 |
found = false; // default value |
found = false; // default value |
2985 |
// |
// |
2986 |
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"); |
2987 |
// |
// |
2988 |
// 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: |
2989 |
// |
// |
3212 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
3213 |
glrun->SetID_RUN_FRAG(0); |
glrun->SetID_RUN_FRAG(0); |
3214 |
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... |
3215 |
}; |
}; |
3216 |
// |
// |
3217 |
}; |
}; |
3218 |
// |
// |
3256 |
if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! |
if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! |
3257 |
//if ( firstev <= lastev+1 ) { // no events inside the run! |
//if ( firstev <= lastev+1 ) { // no events inside the run! |
3258 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
3259 |
|
firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files |
3260 |
// return true is correct |
// return true is correct |
3261 |
return(true); |
return(true); |
3262 |
// |
// |
3286 |
// |
// |
3287 |
} else { |
} else { |
3288 |
// |
// |
3289 |
if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n"); |
if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n"); |
3290 |
// |
// |
3291 |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
3292 |
// |
// |
3296 |
UInt_t check = 0; |
UInt_t check = 0; |
3297 |
UInt_t lastevtemp = lastev; |
UInt_t lastevtemp = lastev; |
3298 |
UInt_t firstevno = firstev; |
UInt_t firstevno = firstev; |
3299 |
|
UInt_t rhchko=0; |
3300 |
|
UInt_t rhchk=0; |
3301 |
// |
// |
3302 |
for (UInt_t i=firstev; i<=lastev; i++){ |
for (UInt_t i=firstev; i<=lastev; i++){ |
3303 |
// |
// |
3306 |
// |
// |
3307 |
check = 0; |
check = 0; |
3308 |
// |
// |
3309 |
|
|
3310 |
|
// if we have a runheader set lastev then exit |
3311 |
|
// |
3312 |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
3313 |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
3314 |
}; |
}; |
3315 |
|
// check here if we have a runheader |
3316 |
|
rhchko = rhchk; |
3317 |
|
rhchk = code->Get(GetPacketType("RunHeader")); |
3318 |
// |
// |
3319 |
if ( checkfirst < check || i == lastev ){ |
if ( checkfirst < check || i == lastev ){ |
3320 |
// |
// |
3398 |
// 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 |
3399 |
// |
// |
3400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3401 |
mishead = true; |
mishead = true; |
3402 |
|
|
3403 |
|
|
3512 |
// |
// |
3513 |
found = false; // default value |
found = false; // default value |
3514 |
// |
// |
3515 |
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"); |
3516 |
// |
// |
3517 |
// 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: |
3518 |
// |
// |
3717 |
}; // EEE |
}; // EEE |
3718 |
|
|
3719 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3720 |
} else { |
} else { |
3721 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
3722 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
3731 |
// |
// |
3732 |
}; |
}; |
3733 |
// |
// |
3734 |
|
if ( i > firstev ){ |
3735 |
|
if ( rhchko != rhchk ){ |
3736 |
|
if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n"); |
3737 |
|
lastev = i; |
3738 |
|
return(false); |
3739 |
|
}; |
3740 |
|
}; |
3741 |
|
// |
3742 |
if ( check == checklast && i != lastev ){ |
if ( check == checklast && i != lastev ){ |
3743 |
lastevtemp = i - 1; |
lastevtemp = i - 1; |
3744 |
i = lastev - 1; |
i = lastev - 1; |
4555 |
return(0); |
return(0); |
4556 |
}; |
}; |
4557 |
|
|
|
// /** |
|
|
// * Fill the GL_TRK_CALIB table |
|
|
// */ |
|
|
// void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
|
|
// // |
|
|
// TSQLResult *result = 0; |
|
|
// TSQLRow *row = 0; |
|
|
// // |
|
|
// stringstream oss; |
|
|
// oss.str(""); |
|
|
// // |
|
|
// UInt_t totime = 0; |
|
|
// // |
|
|
// if ( !pk1 && !pk2 ){ |
|
|
// if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n"); |
|
|
// return; |
|
|
// }; |
|
|
// // |
|
|
// // check if the calibration has already been inserted |
|
|
// // |
|
|
// oss.str(""); |
|
|
// oss << " SELECT ID FROM GL_TRK_CALIB WHERE " |
|
|
// << " BOOT_NUMBER = "<< this->GetBOOTnumber(); // |
|
|
// oss << " AND ( ( "; |
|
|
// if ( pk1 ){ |
|
|
// oss << " OBT1 = "<< obt1 << " AND " |
|
|
// << " PKT1 = "<< pkt1 |
|
|
// << " ) OR ( "; |
|
|
// } else { |
|
|
// oss << " PKT1 = "<< pkt2-1 |
|
|
// << " ) OR ( "; |
|
|
// }; |
|
|
// if ( pk2 ){ |
|
|
// oss << " OBT2 = "<< obt2 << " AND " |
|
|
// << " PKT2 = "<< pkt2; |
|
|
// } else { |
|
|
// oss << " PKT2 = "<< pkt1+1; |
|
|
// }; |
|
|
// oss << " ) );"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" Check if the trk calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// // |
|
|
// if ( !result ) throw -4; |
|
|
// // |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// if ( row ){ |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
|
|
// if ( PEDANTIC ) throw -80; |
|
|
// // |
|
|
// } else { |
|
|
// // |
|
|
// // we have to insert a new calibration, check where to place it |
|
|
// // |
|
|
// oss.str(""); |
|
|
// oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
|
|
// << " FROM_TIME < "<< fromtime << " AND " |
|
|
// << " TO_TIME > "<< fromtime << ";"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" Check where to place the trk 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 ){ |
|
|
// // |
|
|
// // no calibrations in the db contain our calibration |
|
|
// // |
|
|
// 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; |
|
|
// // |
|
|
// }; |
|
|
// // |
|
|
// oss.str(""); |
|
|
// 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 << "',"; |
|
|
// // |
|
|
// if ( !pk1 ){ |
|
|
// oss << "NULL,"; |
|
|
// } else { |
|
|
// oss << "'" |
|
|
// << t1 << "',"; |
|
|
// }; |
|
|
// // |
|
|
// if ( !pk2 ){ |
|
|
// oss << "NULL,'"; |
|
|
// } else { |
|
|
// oss << "'" |
|
|
// << t2 << "','"; |
|
|
// }; |
|
|
// // |
|
|
// oss << fromtime << "','" |
|
|
// << totime << "','" |
|
|
// << obt1 << "','" |
|
|
// << pkt1 << "','" |
|
|
// << obt2 << "','" |
|
|
// << pkt2 << "','" |
|
|
// << this->GetBOOTnumber() << "','" |
|
|
// << valid << "');"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); |
|
|
// // |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// // |
|
|
// if ( !result ) throw -4; |
|
|
// // |
|
|
// }; |
|
|
// // |
|
|
// }; |
|
4558 |
/** |
/** |
4559 |
* Fill the GL_TRK_CALIB table |
* Fill the GL_TRK_CALIB table |
4560 |
*/ |
*/ |
4955 |
// |
// |
4956 |
}; |
}; |
4957 |
// |
// |
4958 |
|
|
4959 |
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
4960 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4961 |
|
ncalib++; |
4962 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
4963 |
|
} |
4964 |
|
|
4965 |
|
|
4966 |
} else { |
} else { |
4967 |
// |
// |
4968 |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
4969 |
// if ( PEDANTIC ) throw -79; |
// if ( PEDANTIC ) throw -79; |
4970 |
// |
// |
4971 |
}; |
}; |
4972 |
// |
// |
4973 |
|
|
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
|
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
|
|
ncalib++; |
|
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
|
|
} |
|
|
|
|
4974 |
}; //end loop on pkt1 |
}; //end loop on pkt1 |
4975 |
|
|
4976 |
|
|
5186 |
|
|
5187 |
if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl; |
if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl; |
5188 |
// cout << path <<endl; |
// cout << path <<endl; |
5189 |
cout << "File : " <<name <<endl; |
// cout << "File : " <<name <<endl; |
5190 |
// cout << obt0 <<endl; |
// cout << obt0 <<endl; |
5191 |
// cout << timesync <<endl; |
// cout << timesync <<endl; |
5192 |
cout << "boot n. : "<<boot_number <<endl; |
// cout << "boot n. : "<<boot_number <<endl; |
5193 |
// cout << raw <<endl; |
// cout << raw <<endl; |
5194 |
|
|
5195 |
// ------------------------------------------------------ |
// ------------------------------------------------------ |
5196 |
// ... retrieve the calibration packets. |
// ... retrieve the calibration packets. |
5197 |
// ------------------------------------------------------ |
// ------------------------------------------------------ |
5198 |
TFile *file = new TFile(path+"/"+name); |
if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data()); |
5199 |
|
TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it |
5200 |
if(!file)throw -100; |
if(!file)throw -100; |
5201 |
if(file->IsZombie())throw -100; |
if(file->IsZombie())throw -100; |
5202 |
// |
// |
5266 |
// |
// |
5267 |
// check if the raw file already exist |
// check if the raw file already exist |
5268 |
// |
// |
5269 |
UInt_t id_raw = 0; |
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 |
5270 |
oss.str(""); |
// oss.str(""); |
5271 |
oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
5272 |
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
// if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5273 |
|
|
5274 |
result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
5275 |
if ( !result ) throw -4;; |
// if ( !result ) throw -4;; |
5276 |
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
// if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5277 |
if( result->GetRowCount() == 0){ |
// if( result->GetRowCount() == 0){ |
5278 |
if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
// if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
5279 |
// - - - - - - - - - - - |
// // - - - - - - - - - - - |
5280 |
// insert new raw file |
// // insert new raw file |
5281 |
// - - - - - - - - - - - |
// // - - - - - - - - - - - |
5282 |
GL_RAW glraw = GL_RAW(); |
// GL_RAW glraw = GL_RAW(); |
5283 |
glraw.PATH = gSystem->DirName(raw.Data()); |
// glraw.PATH = gSystem->DirName(raw.Data()); |
5284 |
glraw.NAME = gSystem->BaseName(raw.Data()); |
// glraw.NAME = gSystem->BaseName(raw.Data()); |
5285 |
glraw.BOOT_NUMBER = boot_number; |
// glraw.BOOT_NUMBER = boot_number; |
5286 |
// |
// // |
5287 |
insertPamelaRawFile( &glraw ); |
// insertPamelaRawFile( &glraw ); |
5288 |
// |
// // |
5289 |
id_raw = glraw.ID; |
// id_raw = glraw.ID; |
5290 |
}else{ |
// }else{ |
5291 |
row = result->Next(); |
// row = result->Next(); |
5292 |
id_raw = (UInt_t)atoll(row->GetField(0)); |
// id_raw = (UInt_t)atoll(row->GetField(0)); |
5293 |
} |
// } |
5294 |
if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
// if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
5295 |
|
|
5296 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5297 |
// step 1(bis): retrieve the timesync id associated to the file |
// step 1(bis): retrieve the timesync id associated to the file |
5312 |
// step 2: insert a new root file in GL_ROOT |
// step 2: insert a new root file in GL_ROOT |
5313 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5314 |
// |
// |
5315 |
// check if the raw file already exist |
// check if the root file already exist |
5316 |
// |
// |
5317 |
UInt_t id_root = 0; |
UInt_t id_root = 0; |
5318 |
oss.str(""); |
oss.str(""); |
5330 |
GL_ROOT glroot = GL_ROOT(); |
GL_ROOT glroot = GL_ROOT(); |
5331 |
glroot.ID_RAW = id_raw; |
glroot.ID_RAW = id_raw; |
5332 |
glroot.ID_TIMESYNC = idtimesync; |
glroot.ID_TIMESYNC = idtimesync; |
5333 |
glroot.PATH = path; |
// |
5334 |
|
// 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, |
5335 |
|
// NOT STATIC NOT KEEPENV = $PAM_L0 must be used in the DB |
5336 |
|
// |
5337 |
|
if ( STATIC ){ |
5338 |
|
glroot.PATH = (TString)gSystem->ExpandPathName(path); |
5339 |
|
} else { |
5340 |
|
if ( KEEPENV ){ |
5341 |
|
glroot.PATH = path; |
5342 |
|
} else { |
5343 |
|
glroot.PATH = "$PAM_L0"; |
5344 |
|
}; |
5345 |
|
}; |
5346 |
|
// glroot.PATH = path; |
5347 |
glroot.NAME = name; |
glroot.NAME = name; |
5348 |
// |
// |
5349 |
insertPamelaRootFile( &glroot ); |
insertPamelaRootFile( &glroot ); |
6120 |
// 2) get the OBT of the last validated run |
// 2) get the OBT of the last validated run |
6121 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
6122 |
oss.str(""); |
oss.str(""); |
6123 |
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 |
6124 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start |
6125 |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
6126 |
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()); |
6127 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
6264 |
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 |
6265 |
|
|
6266 |
if( !CHECK && this_run->VALIDATION ){ |
if( !CHECK && this_run->VALIDATION ){ |
6267 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
// for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
6268 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION); |
6269 |
nseq=0; |
nseq=0; |
6270 |
} |
} |
6271 |
|
|
6286 |
if( CHECK ){ |
if( CHECK ){ |
6287 |
// check if calibration exists |
// check if calibration exists |
6288 |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
6289 |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
// Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
6290 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
UInt_t MISSING = MissingTRK_CALIB(t1,t2); |
6291 |
|
UInt_t val = 0; |
6292 |
|
if ( MISSING == 1 ) val = 0; |
6293 |
|
if ( MISSING == 0 ) val = 1; |
6294 |
|
if ( MISSING == 2 ) val = 2; |
6295 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val); |
6296 |
nseq=0; |
nseq=0; |
6297 |
}; |
}; |
6298 |
//-------------- |
//-------------- |
6322 |
* @param t2 To absolute time |
* @param t2 To absolute time |
6323 |
* @return true if there might be a missing calibration |
* @return true if there might be a missing calibration |
6324 |
*/ |
*/ |
6325 |
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
//Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6326 |
|
UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6327 |
|
|
6328 |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
6329 |
|
|
6330 |
// get the closest calibration before the run start (t2) |
// get the closest calibration before the run start (t2) |
6331 |
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
// if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
6332 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1); //>>> missing |
6333 |
|
|
6334 |
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
// if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
6335 |
|
if ( trkcalib->TO_TIME < t2 ) return(1); //>>> missing |
6336 |
|
|
6337 |
//============================================================== |
//============================================================== |
6338 |
// Check is done first on the basis of time between calibration, |
// Check is done first on the basis of time between calibration, |
6349 |
//============================================================== |
//============================================================== |
6350 |
Bool_t DOWNLOAD = false; |
Bool_t DOWNLOAD = false; |
6351 |
// check if the calib was skipped becouse of download .... DA FARE!! |
// check if the calib was skipped becouse of download .... DA FARE!! |
6352 |
if(DOWNLOAD)return(false); |
// if(DOWNLOAD)return(false); |
6353 |
|
if(DOWNLOAD)return(0); |
6354 |
|
|
6355 |
return(true); //>>> missing |
// return(true); //>>> missing |
6356 |
|
return(1); //>>> missing |
6357 |
|
|
6358 |
}; |
}; |
6359 |
|
|
6363 |
//============================================================== |
//============================================================== |
6364 |
// the long time interval bewteen runs might be due to download |
// the long time interval bewteen runs might be due to download |
6365 |
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); |
6366 |
return(false); |
if ( trkcalib->VALIDATION ) return(0); |
6367 |
|
if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n"); |
6368 |
|
return(2); |
6369 |
|
|
6370 |
}; |
}; |
6371 |
/** |
/** |
6374 |
* @param validation true/false |
* @param validation true/false |
6375 |
*/ |
*/ |
6376 |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
6377 |
|
return(this->assignVALIDATION(idrun,(UInt_t)validation)); |
6378 |
|
} |
6379 |
|
|
6380 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){ |
6381 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
6382 |
stringstream oss; |
stringstream oss; |
6383 |
oss.str(""); |
oss.str(""); |
6574 |
stringstream myquery; |
stringstream myquery; |
6575 |
// |
// |
6576 |
myquery.str(""); |
myquery.str(""); |
6577 |
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() <<"';"; |
6578 |
// |
// |
6579 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
6580 |
// |
// |
6590 |
// |
// |
6591 |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
6592 |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
6593 |
|
UInt_t idtsy=(UInt_t)atoll(Row->GetField(2)); |
6594 |
// |
// |
6595 |
this->ValidationOFF(); |
this->ValidationOFF(); |
6596 |
// |
// |
6598 |
// |
// |
6599 |
this->RemoveRUNS(); |
this->RemoveRUNS(); |
6600 |
// |
// |
6601 |
this->RemoveFILES(); |
this->RemoveFILES(idtsy); |
6602 |
// |
// |
6603 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
6604 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
6818 |
* Rearrange calibration tables |
* Rearrange calibration tables |
6819 |
* |
* |
6820 |
**/ |
**/ |
6821 |
void PamelaDBOperations::RemoveFILES(){ |
void PamelaDBOperations::RemoveFILES(UInt_t idtsy){ |
6822 |
stringstream myquery; |
stringstream myquery; |
6823 |
// |
// |
6824 |
myquery.str(""); |
myquery.str(""); |
6828 |
// |
// |
6829 |
conn->Query(myquery.str().c_str()); |
conn->Query(myquery.str().c_str()); |
6830 |
// |
// |
6831 |
|
myquery.str(""); |
6832 |
|
myquery << " DELETE FROM GL_ROOT WHERE ID=" <<this->GetID_ROOT() <<";"; |
6833 |
|
// |
6834 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
6835 |
|
// |
6836 |
|
conn->Query(myquery.str().c_str()); // |
6837 |
|
// |
6838 |
|
if ( !chewbacca ){ |
6839 |
|
myquery.str(""); |
6840 |
|
myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";"; |
6841 |
|
// |
6842 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
6843 |
|
// |
6844 |
|
conn->Query(myquery.str().c_str()); |
6845 |
|
}; |
6846 |
|
// |
6847 |
}; |
}; |
6848 |
|
|
6849 |
/** |
/** |
7193 |
|
|
7194 |
|
|
7195 |
} |
} |
|
// UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
|
|
|
|
|
// if(!caltrk || !eh) return 0; |
|
|
|
|
|
// Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,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; // :-) |
|
|
|
|
|
// // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
|
|
|
|
|
// // ----------------------------------------------- |
|
|
// // If missing packets: check the acq configuration |
|
|
// // (some DSPs might be excluded from acquisition) |
|
|
// // ----------------------------------------------- |
|
|
|
|
|
// // ----------------------------------------------- |
|
|
// // retrieve the first run header after calib |
|
|
// // ----------------------------------------------- |
|
|
// PacketType *pctp; |
|
|
// EventCounter *cod; |
|
|
// cod = eh->GetCounter(); |
|
|
// Int_t irun = cod->Get(pctp->RunHeader); |
|
|
// TTree *rh=(TTree*)file->Get("RunHeader"); |
|
|
// if ( !rh || rh->IsZombie() ) throw -17; |
|
|
// if( rh->GetEntries() == irun ){ |
|
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
|
|
// return 0; // :-( |
|
|
// } |
|
|
|
|
|
// RunHeaderEvent *run = 0; |
|
|
// EventHeader *hrun = 0; |
|
|
// rh->SetBranchAddress("RunHeader", &run); |
|
|
// rh->SetBranchAddress("Header", &hrun); |
|
|
// rh->GetEntry(irun); |
|
|
// // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
|
|
|
|
|
// if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
|
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
|
|
// return 0; // :-( |
|
|
// } |
|
|
|
|
|
// if( !run->RM_ACQ_AFTER_CALIB ){ |
|
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
|
|
// return 0; // :-( |
|
|
// } |
|
|
|
|
|
// UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
|
|
// if( dtime > timeaftercalib ){ |
|
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
|
|
// return 0; // :-( |
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 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; // :-) |
|
|
|
|
|
// } |
|
7196 |
|
|
7197 |
/** |
/** |
7198 |
* |
* |