660 |
UInt_t tjump = 50000; |
UInt_t tjump = 50000; |
661 |
//UInt_t tjump = 100; |
//UInt_t tjump = 100; |
662 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
663 |
pktlast = numeric_limits<UInt_t>::max(); |
// pktlast = numeric_limits<UInt_t>::max(); |
664 |
while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){ |
pktlast = chpktmax + 1; |
665 |
|
while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){ |
666 |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
667 |
T->GetEntry(nevent-1-it); |
T->GetEntry(nevent-1-it); |
668 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
670 |
} else { |
} else { |
671 |
pktlast = chpktmax + 1; |
pktlast = chpktmax + 1; |
672 |
}; |
}; |
673 |
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)); |
674 |
it += tjump; |
it += tjump; |
675 |
}; |
}; |
676 |
if ( tjump > 1 ) it -= 2*tjump; |
if ( tjump > 1 ) it -= 2*tjump; |
694 |
tjump = 50000; |
tjump = 50000; |
695 |
//tjump = 100; |
//tjump = 100; |
696 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
697 |
pktlast = 0; |
// pktlast = 0; |
698 |
while ( pktlast < chpktmin && it < (Int_t)nevent ){ |
pktlast = chpktmin - 1; |
699 |
|
if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin)); |
700 |
|
while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){ |
701 |
if ( it < (Int_t)nevent ){ |
if ( it < (Int_t)nevent ){ |
702 |
T->GetEntry(it); |
T->GetEntry(it); |
703 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1941 |
glroot.PATH = "$PAM_L0"; |
glroot.PATH = "$PAM_L0"; |
1942 |
}; |
}; |
1943 |
}; |
}; |
1944 |
// glroot.NAME = GetRootFile(); |
glroot.NAME = GetRootFile(); |
1945 |
|
|
1946 |
if ( insertPamelaRootFile(&glroot) )return 1; |
if ( insertPamelaRootFile(&glroot) )return 1; |
1947 |
|
|
2317 |
// |
// |
2318 |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
2319 |
// |
// |
2320 |
|
// what about pth=ptht-1 |
2321 |
}; |
}; |
2322 |
}; |
}; |
2323 |
// |
// |
2380 |
// if ( ptt+1 == rtev){ |
// if ( ptt+1 == rtev){ |
2381 |
if ( conptt+1 == nrtev ){ |
if ( conptt+1 == nrtev ){ |
2382 |
// if ( conptt+1 == (nrtev+nrtbef )){ |
// if ( conptt+1 == (nrtev+nrtbef )){ |
2383 |
|
if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); |
2384 |
ptht++; |
ptht++; |
2385 |
if ( ptht < rhev ){ |
if ( ptht < rhev ){ |
2386 |
rh->GetEntry(ptht); |
rh->GetEntry(ptht); |
2387 |
|
//pth++; |
2388 |
|
//if ( pth < rhev ){ |
2389 |
|
//rh->GetEntry(pth); |
2390 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2391 |
pkth = phh->GetCounter(); |
pkth = phh->GetCounter(); |
2392 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2411 |
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); |
2412 |
// |
// |
2413 |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
2414 |
rt->GetEntry(ptt-1); |
// rt->GetEntry(ptt-1); |
2415 |
|
rt->GetEntry(rtev-1); |
2416 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
2417 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics)+1; |
2418 |
evbefh = TMath::Max(chminentry,tcod); |
evbefh = TMath::Max(chminentry,tcod); |
2419 |
// evbefh = cod->Get(pctp->Physics); |
// evbefh = cod->Get(pctp->Physics); |
2420 |
rt->GetEntry(ptt); |
rt->GetEntry(ptt); |
3248 |
// |
// |
3249 |
} else { |
} else { |
3250 |
// |
// |
3251 |
if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n"); |
if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n"); |
3252 |
// |
// |
3253 |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
3254 |
// |
// |
3258 |
UInt_t check = 0; |
UInt_t check = 0; |
3259 |
UInt_t lastevtemp = lastev; |
UInt_t lastevtemp = lastev; |
3260 |
UInt_t firstevno = firstev; |
UInt_t firstevno = firstev; |
3261 |
|
UInt_t rhchko=0; |
3262 |
|
UInt_t rhchk=0; |
3263 |
// |
// |
3264 |
for (UInt_t i=firstev; i<=lastev; i++){ |
for (UInt_t i=firstev; i<=lastev; i++){ |
3265 |
// |
// |
3268 |
// |
// |
3269 |
check = 0; |
check = 0; |
3270 |
// |
// |
3271 |
|
|
3272 |
|
// if we have a runheader set lastev then exit |
3273 |
|
// |
3274 |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
3275 |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
3276 |
}; |
}; |
3277 |
|
// check here if we have a runheader |
3278 |
|
rhchko = rhchk; |
3279 |
|
rhchk = code->Get(GetPacketType("RunHeader")); |
3280 |
// |
// |
3281 |
if ( checkfirst < check || i == lastev ){ |
if ( checkfirst < check || i == lastev ){ |
3282 |
// |
// |
3693 |
// |
// |
3694 |
}; |
}; |
3695 |
// |
// |
3696 |
|
if ( i > firstev ){ |
3697 |
|
if ( rhchko != rhchk ){ |
3698 |
|
if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n"); |
3699 |
|
lastev = i; |
3700 |
|
return(false); |
3701 |
|
}; |
3702 |
|
}; |
3703 |
|
// |
3704 |
if ( check == checklast && i != lastev ){ |
if ( check == checklast && i != lastev ){ |
3705 |
lastevtemp = i - 1; |
lastevtemp = i - 1; |
3706 |
i = lastev - 1; |
i = lastev - 1; |
4917 |
// |
// |
4918 |
}; |
}; |
4919 |
// |
// |
4920 |
|
|
4921 |
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
4922 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4923 |
|
ncalib++; |
4924 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
4925 |
|
} |
4926 |
|
|
4927 |
|
|
4928 |
} else { |
} else { |
4929 |
// |
// |
4930 |
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); |
4931 |
// if ( PEDANTIC ) throw -79; |
// if ( PEDANTIC ) throw -79; |
4932 |
// |
// |
4933 |
}; |
}; |
4934 |
// |
// |
4935 |
|
|
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
|
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
|
|
ncalib++; |
|
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
|
|
} |
|
|
|
|
4936 |
}; //end loop on pkt1 |
}; //end loop on pkt1 |
4937 |
|
|
4938 |
|
|
5157 |
// ------------------------------------------------------ |
// ------------------------------------------------------ |
5158 |
// ... retrieve the calibration packets. |
// ... retrieve the calibration packets. |
5159 |
// ------------------------------------------------------ |
// ------------------------------------------------------ |
5160 |
TFile *file = new TFile((TString)gSystem->ExpandPathName(path)+"/"+name); // EM, path could be symbolic and we must expand it |
if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data()); |
5161 |
|
TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it |
5162 |
if(!file)throw -100; |
if(!file)throw -100; |
5163 |
if(file->IsZombie())throw -100; |
if(file->IsZombie())throw -100; |
5164 |
// |
// |
6518 |
stringstream myquery; |
stringstream myquery; |
6519 |
// |
// |
6520 |
myquery.str(""); |
myquery.str(""); |
6521 |
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() <<"';"; |
6522 |
// |
// |
6523 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
6524 |
// |
// |
6534 |
// |
// |
6535 |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
6536 |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
6537 |
|
UInt_t idtsy=(UInt_t)atoll(Row->GetField(2)); |
6538 |
// |
// |
6539 |
this->ValidationOFF(); |
this->ValidationOFF(); |
6540 |
// |
// |
6542 |
// |
// |
6543 |
this->RemoveRUNS(); |
this->RemoveRUNS(); |
6544 |
// |
// |
6545 |
this->RemoveFILES(); |
this->RemoveFILES(idtsy); |
6546 |
// |
// |
6547 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
6548 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
6762 |
* Rearrange calibration tables |
* Rearrange calibration tables |
6763 |
* |
* |
6764 |
**/ |
**/ |
6765 |
void PamelaDBOperations::RemoveFILES(){ |
void PamelaDBOperations::RemoveFILES(UInt_t idtsy){ |
6766 |
stringstream myquery; |
stringstream myquery; |
6767 |
// |
// |
6768 |
myquery.str(""); |
myquery.str(""); |
6772 |
// |
// |
6773 |
conn->Query(myquery.str().c_str()); |
conn->Query(myquery.str().c_str()); |
6774 |
// |
// |
6775 |
|
myquery.str(""); |
6776 |
|
myquery << " DELETE FROM GL_ROOT WHERE ID=" <<this->GetID_ROOT() <<";"; |
6777 |
|
// |
6778 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
6779 |
|
// |
6780 |
|
conn->Query(myquery.str().c_str()); // |
6781 |
|
// |
6782 |
|
if ( !chewbacca ){ |
6783 |
|
myquery.str(""); |
6784 |
|
myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";"; |
6785 |
|
// |
6786 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
6787 |
|
// |
6788 |
|
conn->Query(myquery.str().c_str()); |
6789 |
|
}; |
6790 |
|
// |
6791 |
}; |
}; |
6792 |
|
|
6793 |
/** |
/** |
7137 |
|
|
7138 |
|
|
7139 |
} |
} |
|
// 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; // :-) |
|
|
|
|
|
// } |
|
7140 |
|
|
7141 |
/** |
/** |
7142 |
* |
* |