56 |
* @param debug debug flag. |
* @param debug debug flag. |
57 |
* @param tlefilename ascii file with TLE 3 line elements. |
* @param tlefilename ascii file with TLE 3 line elements. |
58 |
*/ |
*/ |
59 |
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){ |
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){ |
60 |
// |
// |
61 |
// |
// |
62 |
SetConnection(host,user,password); |
SetConnection(host,user,password); |
79 |
INSERT_ROOT = !filerootname.IsNull(); |
INSERT_ROOT = !filerootname.IsNull(); |
80 |
if( INSERT_ROOT ){ |
if( INSERT_ROOT ){ |
81 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
82 |
this->SetOrbitNo(); |
this->SetOrbitNo(dwinput); |
83 |
file = TFile::Open(this->GetRootName().Data()); |
file = TFile::Open(this->GetRootName().Data()); |
84 |
} else { |
} else { |
85 |
this->SetRootName(""); |
this->SetRootName(""); |
157 |
}; |
}; |
158 |
|
|
159 |
/** |
/** |
160 |
|
* Set the autoboot flag |
161 |
|
* |
162 |
|
*/ |
163 |
|
void PamelaDBOperations::SetAutoBoot(Bool_t dbg){ |
164 |
|
AUTOBOOT = dbg; |
165 |
|
}; |
166 |
|
|
167 |
|
/** |
168 |
* Set the nofrag flag |
* Set the nofrag flag |
169 |
* |
* |
170 |
*/ |
*/ |
215 |
/** |
/** |
216 |
* Store the downlink orbit number from filename. |
* Store the downlink orbit number from filename. |
217 |
*/ |
*/ |
218 |
void PamelaDBOperations::SetOrbitNo(){ |
void PamelaDBOperations::SetOrbitNo(UInt_t dwinput){ |
219 |
dworbit = 0; |
dworbit = 0; |
220 |
|
// |
221 |
|
if ( dwinput ){ |
222 |
|
dworbit = dwinput; |
223 |
|
if ( IsDebug() ) printf(" Downlink orbit given by hand: %i \n",dworbit); |
224 |
|
return; |
225 |
|
}; |
226 |
|
// |
227 |
TString name = this->GetRootFile(); |
TString name = this->GetRootFile(); |
228 |
Int_t nlength = name.Length(); |
Int_t nlength = name.Length(); |
229 |
if ( nlength < 5 ) return; |
if ( nlength < 5 ) return; |
280 |
oss << "SELECT ID FROM GL_RAW WHERE " |
oss << "SELECT ID FROM GL_RAW WHERE " |
281 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
282 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
283 |
|
|
284 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
285 |
if ( result == NULL ) throw -4; |
if ( result == NULL ) throw -4; |
286 |
row = result->Next(); |
row = result->Next(); |
311 |
UInt_t nevent = 0; |
UInt_t nevent = 0; |
312 |
UInt_t pktlast = 0; |
UInt_t pktlast = 0; |
313 |
UInt_t obtlast = 0; |
UInt_t obtlast = 0; |
314 |
UInt_t t_pktlast = 0; |
Long64_t t_pktlast = 0LL; |
315 |
UInt_t t_obtlast = 0; |
// UInt_t t_obtlast = 0; |
316 |
UInt_t upperpkt2 = 0; |
Long64_t t_obtlast = 0LL; |
317 |
ULong64_t upperobt2 = 0; |
Long64_t upperpkt2 = 0LL; |
318 |
|
Long64_t upperobt2 = 0LL; |
319 |
UInt_t zomp = 0; |
UInt_t zomp = 0; |
320 |
UInt_t jump = 50000; // was 5000 |
UInt_t jump = 50000; // was 5000 |
321 |
EventCounter *code=0; |
EventCounter *code=0; |
322 |
// |
// |
323 |
UInt_t deltapkt = 5000; |
Long64_t deltapkt = 5000LL; |
324 |
ULong64_t deltaobt = 50000; |
Long64_t deltaobt = 50000LL; |
325 |
// |
// |
326 |
// pcksList packetsNames; |
pcksList packetsNames; |
327 |
// pcksList::iterator Iter; |
pcksList::iterator Iter; |
328 |
// getPacketsNames(packetsNames); |
getPacketsNames(packetsNames); |
329 |
// |
// |
330 |
pktfirst = 0; |
pktfirst = 0; |
331 |
obtfirst = 0; |
obtfirst = 0; |
332 |
|
ppktfirst = 0; |
333 |
|
pobtfirst = 0; |
334 |
// |
// |
335 |
TTree *T = 0; |
TTree *T = 0; |
336 |
T = (TTree*)file->Get("Physics"); |
T = (TTree*)file->Get("Physics"); |
344 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
345 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
346 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
347 |
|
ppktfirst = pktfirst; |
348 |
|
pobtfirst = obtfirst; |
349 |
// |
// |
350 |
// code = eh->GetCounter(); |
code = eh->GetCounter(); |
351 |
// UInt_t en = 0; |
UInt_t en = 0; |
352 |
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
353 |
// en = code->Get(GetPacketType(*Iter)); |
en = code->Get(GetPacketType(*Iter)); |
354 |
// if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en); |
if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
355 |
//}; |
if ( IsDebug() ) printf(" We have a calibration before the first physic packet: packet type is %s, entries: %i \n",*Iter,en); |
356 |
|
// |
357 |
|
TTree *TC = 0; |
358 |
|
TC = (TTree*)file->Get("CalibCalPed"); |
359 |
|
if ( !TC || TC->IsZombie() ) throw -16; |
360 |
|
EventHeader *ehc = 0; |
361 |
|
PscuHeader *phc = 0; |
362 |
|
TC->SetBranchAddress("Header", &ehc); |
363 |
|
TC->GetEntry(0); |
364 |
|
phc = ehc->GetPscuHeader(); |
365 |
|
pktfirst = phc->GetCounter(); |
366 |
|
obtfirst = phc->GetOrbitalTime(); |
367 |
|
// |
368 |
|
}; |
369 |
|
}; |
370 |
// |
// |
371 |
T->GetEntry(nevent-1); |
T->GetEntry(nevent-1); |
372 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
377 |
upperobt = OBT(obtlast); |
upperobt = OBT(obtlast); |
378 |
upperentry = nevent-1; |
upperentry = nevent-1; |
379 |
// |
// |
380 |
if ( IsDebug() ) printf(" First entries are: OBT %llu pkt_num %i \n",obtfirst,pktfirst); |
if ( IsDebug() ) printf(" First entries are: OBT %i pkt_num %i \n",obtfirst,pktfirst); |
381 |
// |
// |
382 |
if ( IsDebug() ) printf(" Last entries are: OBT %llu pkt_num %i entry %i\n",upperobt,upperpkt,upperentry); |
if ( IsDebug() ) printf(" Last entries are: OBT %lld pkt_num %lld entry %i\n",upperobt,upperpkt,upperentry); |
383 |
// |
// |
384 |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) || (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) ) return(1); |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) || (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) ) return(1); |
385 |
// |
// |
386 |
if ( !nevent ) return(2); |
if ( !nevent ) return(2); |
387 |
// |
// |
388 |
if ( nevent < 2 ) return(4); |
if ( nevent < 2 ) return(4); |
389 |
|
if ( nevent < jump ) jump = 1; |
390 |
|
// if ( nevent < jump ) jump = int(nevent/10); |
391 |
|
// if ( !jump ) jump = 1; |
392 |
// |
// |
393 |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) ){ |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){ |
394 |
// |
// |
395 |
|
if ( IsDebug() ) printf(" starting jump %i \n",jump); |
396 |
// go back |
// go back |
397 |
zomp = nevent - 2; |
zomp = nevent - 2; |
398 |
// |
// |
414 |
upperpkt2 = PKT(ph->GetCounter()); |
upperpkt2 = PKT(ph->GetCounter()); |
415 |
upperobt2 = OBT(ph->GetOrbitalTime()); |
upperobt2 = OBT(ph->GetOrbitalTime()); |
416 |
// |
// |
417 |
if ( (t_pktlast < upperpkt && t_obtlast > upperobt) || (t_pktlast < upperpkt2 && t_obtlast > upperobt2) ) throw -13; |
if ( (t_pktlast < upperpkt && t_obtlast > upperobt) || (t_pktlast < upperpkt2 && t_obtlast > upperobt2) ){ |
418 |
|
if ( IsDebug() ) printf(" .-. upperpkt2 %lld upperobt2 %lld \n",upperpkt2,upperobt2); |
419 |
|
if ( IsDebug() ) printf(" .-. upperpkt %lld t_pktlast %lld upperobt %lld t_obtlast %lld \n",upperpkt,t_pktlast,upperobt,t_obtlast); |
420 |
|
if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %lld pktlast %u upperobt %lld obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); |
421 |
|
throw -13; |
422 |
|
}; |
423 |
// |
// |
424 |
if ( t_pktlast < upperpkt && t_obtlast < upperobt && t_pktlast < upperpkt2 && t_obtlast < upperobt2 ){ |
if ( t_pktlast < upperpkt && t_obtlast < upperobt && t_pktlast < upperpkt2 && t_obtlast < upperobt2 ){ |
425 |
zomp = i + jump + 1; |
zomp = i + jump + 1; |
426 |
if ( zomp > nevent-2 ) zomp = nevent - 2; |
if ( zomp > nevent-2 ) zomp = nevent - 2; |
427 |
if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %i pktlast %i upperobt %llu obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); |
if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %lld pktlast %i upperobt %lld obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); |
428 |
break; |
break; |
429 |
}; |
}; |
430 |
// |
// |
459 |
// |
// |
460 |
rhev = rh->GetEntries(); |
rhev = rh->GetEntries(); |
461 |
rtev = rt->GetEntries(); |
rtev = rt->GetEntries(); |
462 |
UInt_t sobtt = 0; |
Long64_t sobtt = 0LL; |
463 |
UInt_t sobth = 0; |
Long64_t sobth = 0LL; |
464 |
UInt_t spktt = 0; |
Long64_t spktt = 0LL; |
465 |
UInt_t spkth = 0; |
Long64_t spkth = 0LL; |
466 |
UInt_t pktt = 0; |
Long64_t pktt = 0LL; |
467 |
ULong64_t obtt = 0; |
Long64_t obtt = 0LL; |
468 |
UInt_t pkth = 0; |
Long64_t pkth = 0LL; |
469 |
ULong64_t obth = 0; |
Long64_t obth = 0LL; |
|
// |
|
|
T->GetEntry(upperentry); |
|
|
code = eh->GetCounter(); |
|
|
Int_t lasttrail = code->Get(pctp->RunTrailer); |
|
|
Int_t lasthead = code->Get(pctp->RunHeader); |
|
|
if ( lasttrail < rtev ){ |
|
|
rt->GetEntry(lasttrail); |
|
|
pht = eht->GetPscuHeader(); |
|
|
pktt = PKT(pht->GetCounter()); |
|
|
obtt = OBT(pht->GetOrbitalTime()); |
|
|
}; |
|
|
// |
|
|
if ( lasthead < rhev ){ |
|
|
rh->GetEntry(lasthead); |
|
|
phh = ehh->GetPscuHeader(); |
|
|
pkth = PKT(phh->GetCounter()); |
|
|
obth = OBT(phh->GetOrbitalTime()); |
|
|
}; |
|
|
// |
|
|
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
|
|
if ( pkth > upperpkt && obth > upperobt ){ |
|
|
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt); |
|
|
upperpkt = pkth; |
|
|
upperobt = obth; |
|
|
rhev = lasthead+1; |
|
|
} else { |
|
|
rhev = lasthead; |
|
|
}; |
|
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
|
|
// |
|
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
|
if ( pktt > upperpkt && obtt > upperobt ){ |
|
|
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
|
|
upperpkt = pktt; |
|
|
upperobt = obtt; |
|
|
rtev = lasttrail+1; |
|
|
} else { |
|
|
rtev = lasttrail; |
|
|
}; |
|
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
|
// goto kikko; |
|
|
// |
|
|
// |
|
|
// Check if runtrailer/runheader are within lower limits |
|
|
// |
|
470 |
// |
// |
471 |
pkth = 0; |
if ( rhev || rtev ){ |
472 |
obth = 0; |
|
473 |
spkth = 0; |
T->GetEntry(upperentry); |
474 |
sobth = 0; |
code = eh->GetCounter(); |
475 |
for (Int_t k=0; k<rhev; k++){ |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
476 |
if ( k > 0 ){ |
Int_t lasthead = code->Get(pctp->RunHeader); |
477 |
spkth = pkth; |
if ( lasttrail < rtev ){ |
478 |
sobth = obth; |
rt->GetEntry(lasttrail); |
479 |
}; |
pht = eht->GetPscuHeader(); |
480 |
rh->GetEntry(k); |
pktt = PKT(pht->GetCounter()); |
481 |
phh = ehh->GetPscuHeader(); |
obtt = OBT(pht->GetOrbitalTime()); |
482 |
pkth = PKT(phh->GetCounter()); |
}; |
483 |
obth = OBT(phh->GetOrbitalTime()); |
// |
484 |
// |
if ( lasthead < rhev ){ |
485 |
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); |
rh->GetEntry(lasthead); |
486 |
// |
phh = ehh->GetPscuHeader(); |
487 |
if ( pkth < spkth && obth < sobth ){ |
pkth = PKT(phh->GetCounter()); |
488 |
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
obth = OBT(phh->GetOrbitalTime()); |
489 |
// |
}; |
490 |
rhev = k-1; |
// |
491 |
rh->GetEntry(rhev); |
if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
492 |
pkth = spkth; |
if ( pkth > upperpkt && obth > upperobt ){ |
493 |
obth = sobth; |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); |
494 |
// |
upperpkt = pkth; |
495 |
UInt_t evbefh = 0; |
upperobt = obth; |
496 |
code = ehh->GetCounter(); |
rhev = lasthead+1; |
497 |
evbefh = code->Get(pctp->Physics); |
} else { |
498 |
if ( evbefh >= 0 ){ |
rhev = lasthead; |
499 |
T->GetEntry(evbefh); |
}; |
500 |
ph = eh->GetPscuHeader(); |
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
501 |
t_pktlast = PKT(ph->GetCounter()); |
// |
502 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
503 |
if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump |
if ( pktt > upperpkt && obtt > upperobt ){ |
504 |
upperpkt = pkth; |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); |
505 |
upperobt = obth; |
upperpkt = pktt; |
506 |
upperentry = evbefh-1; |
upperobt = obtt; |
507 |
} else { |
rtev = lasttrail+1; |
508 |
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
} else { |
509 |
evbefh++; |
rtev = lasttrail; |
510 |
T->GetEntry(evbefh); |
}; |
511 |
ph = eh->GetPscuHeader(); |
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
512 |
t_pktlast = PKT(ph->GetCounter()); |
// goto kikko; |
513 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
// |
514 |
}; |
// |
515 |
T->GetEntry(evbefh-1); |
// Check if runtrailer/runheader are within lower limits |
516 |
|
// |
517 |
|
// |
518 |
|
pkth = 0LL; |
519 |
|
obth = 0LL; |
520 |
|
spkth = 0LL; |
521 |
|
sobth = 0LL; |
522 |
|
for (Int_t k=0; k<rhev; k++){ |
523 |
|
if ( k > 0 ){ |
524 |
|
spkth = pkth; |
525 |
|
sobth = obth; |
526 |
|
}; |
527 |
|
rh->GetEntry(k); |
528 |
|
phh = ehh->GetPscuHeader(); |
529 |
|
pkth = PKT(phh->GetCounter()); |
530 |
|
obth = OBT(phh->GetOrbitalTime()); |
531 |
|
// |
532 |
|
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); |
533 |
|
// |
534 |
|
if ( pkth < spkth && obth < sobth ){ |
535 |
|
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
536 |
|
// |
537 |
|
rhev = k-1; |
538 |
|
rh->GetEntry(rhev); |
539 |
|
pkth = spkth; |
540 |
|
obth = sobth; |
541 |
|
// |
542 |
|
UInt_t evbefh = 0; |
543 |
|
code = ehh->GetCounter(); |
544 |
|
evbefh = code->Get(pctp->Physics); |
545 |
|
if ( evbefh >= 0 ){ |
546 |
|
T->GetEntry(evbefh); |
547 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
548 |
upperpkt = PKT(ph->GetCounter()); |
t_pktlast = PKT(ph->GetCounter()); |
549 |
upperobt = OBT(ph->GetOrbitalTime()); |
t_obtlast = OBT(ph->GetOrbitalTime()); |
550 |
upperentry = evbefh-1; |
if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump |
551 |
}; |
upperpkt = pkth; |
552 |
|
upperobt = obth; |
553 |
|
upperentry = evbefh-1; |
554 |
|
} else { |
555 |
|
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
556 |
|
evbefh++; |
557 |
|
T->GetEntry(evbefh); |
558 |
|
ph = eh->GetPscuHeader(); |
559 |
|
t_pktlast = PKT(ph->GetCounter()); |
560 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
561 |
|
}; |
562 |
|
T->GetEntry(evbefh-1); |
563 |
|
ph = eh->GetPscuHeader(); |
564 |
|
upperpkt = PKT(ph->GetCounter()); |
565 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
566 |
|
upperentry = evbefh-1; |
567 |
|
}; |
568 |
|
}; |
569 |
|
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
570 |
|
goto kikko0; |
571 |
}; |
}; |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
|
|
goto kikko0; |
|
|
}; |
|
|
}; |
|
|
kikko0: |
|
|
// |
|
|
// |
|
|
// |
|
|
pktt = 0; |
|
|
obtt = 0; |
|
|
spktt = 0; |
|
|
sobtt = 0; |
|
|
for (Int_t k=0; k<rtev; k++){ |
|
|
if ( k > 0 ){ |
|
|
spktt = pktt; |
|
|
sobtt = obtt; |
|
572 |
}; |
}; |
573 |
rt->GetEntry(k); |
kikko0: |
574 |
pht = eht->GetPscuHeader(); |
// |
|
pktt = PKT(pht->GetCounter()); |
|
|
obtt = OBT(pht->GetOrbitalTime()); |
|
575 |
// |
// |
|
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
|
576 |
// |
// |
577 |
if ( pktt < spktt && obtt < sobtt ){ |
pktt = 0LL; |
578 |
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
obtt = 0LL; |
579 |
|
spktt = 0LL; |
580 |
|
sobtt = 0LL; |
581 |
|
for (Int_t k=0; k<rtev; k++){ |
582 |
|
if ( k > 0 ){ |
583 |
|
spktt = pktt; |
584 |
|
sobtt = obtt; |
585 |
|
}; |
586 |
|
rt->GetEntry(k); |
587 |
|
pht = eht->GetPscuHeader(); |
588 |
|
pktt = PKT(pht->GetCounter()); |
589 |
|
obtt = OBT(pht->GetOrbitalTime()); |
590 |
// |
// |
591 |
rtev = k-1; |
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
|
rt->GetEntry(rtev); |
|
|
pktt = spktt; |
|
|
obtt = sobtt; |
|
|
if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
592 |
// |
// |
593 |
UInt_t evbeft = 0; |
if ( pktt < spktt && obtt < sobtt ){ |
594 |
code = eht->GetCounter(); |
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
595 |
evbeft = code->Get(pctp->Physics); |
// |
596 |
if ( evbeft >= 0 ){ |
rtev = k-1; |
597 |
T->GetEntry(evbeft); |
rt->GetEntry(rtev); |
598 |
ph = eh->GetPscuHeader(); |
pktt = spktt; |
599 |
t_pktlast = PKT(ph->GetCounter()); |
obtt = sobtt; |
600 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
if ( IsDebug() ) printf(" lasttrail %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
601 |
if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump |
// |
602 |
upperpkt = pktt; |
UInt_t evbeft = 0; |
603 |
upperobt = obtt; |
code = eht->GetCounter(); |
604 |
upperentry = evbeft-1; |
evbeft = code->Get(pctp->Physics); |
605 |
} else { |
if ( evbeft >= 0 ){ |
606 |
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
T->GetEntry(evbeft); |
607 |
evbeft++; |
ph = eh->GetPscuHeader(); |
608 |
T->GetEntry(evbeft); |
t_pktlast = PKT(ph->GetCounter()); |
609 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
610 |
|
if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump |
611 |
|
upperpkt = pktt; |
612 |
|
upperobt = obtt; |
613 |
|
upperentry = evbeft-1; |
614 |
|
} else { |
615 |
|
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
616 |
|
evbeft++; |
617 |
|
T->GetEntry(evbeft); |
618 |
|
ph = eh->GetPscuHeader(); |
619 |
|
t_pktlast = PKT(ph->GetCounter()); |
620 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
621 |
|
}; |
622 |
|
T->GetEntry(evbeft-1); |
623 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
624 |
t_pktlast = PKT(ph->GetCounter()); |
upperpkt = PKT(ph->GetCounter()); |
625 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
upperobt = OBT(ph->GetOrbitalTime()); |
626 |
|
upperentry = evbeft-1; |
627 |
}; |
}; |
|
T->GetEntry(evbeft-1); |
|
|
ph = eh->GetPscuHeader(); |
|
|
upperpkt = PKT(ph->GetCounter()); |
|
|
upperobt = OBT(ph->GetOrbitalTime()); |
|
|
upperentry = evbeft-1; |
|
628 |
}; |
}; |
629 |
|
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
630 |
|
goto kikko; |
631 |
|
// break; |
632 |
|
// |
633 |
}; |
}; |
634 |
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
// |
|
goto kikko; |
|
|
// break; |
|
|
// |
|
635 |
}; |
}; |
636 |
// |
// |
637 |
}; |
kikko: |
638 |
// |
// |
639 |
kikko: |
T->GetEntry(upperentry); |
640 |
// |
code = eh->GetCounter(); |
641 |
T->GetEntry(upperentry); |
lasttrail = code->Get(pctp->RunTrailer); |
642 |
code = eh->GetCounter(); |
lasthead = code->Get(pctp->RunHeader); |
643 |
lasttrail = code->Get(pctp->RunTrailer); |
if ( lasttrail < rtev ){ |
644 |
lasthead = code->Get(pctp->RunHeader); |
rt->GetEntry(lasttrail); |
645 |
if ( lasttrail < rtev ){ |
pht = eht->GetPscuHeader(); |
646 |
rt->GetEntry(lasttrail); |
pktt = PKT(pht->GetCounter()); |
647 |
pht = eht->GetPscuHeader(); |
obtt = OBT(pht->GetOrbitalTime()); |
648 |
pktt = PKT(pht->GetCounter()); |
}; |
649 |
obtt = OBT(pht->GetOrbitalTime()); |
// |
650 |
}; |
if ( lasthead < rhev ){ |
651 |
// |
rh->GetEntry(lasthead); |
652 |
if ( lasthead < rhev ){ |
phh = ehh->GetPscuHeader(); |
653 |
rh->GetEntry(lasthead); |
pkth = PKT(phh->GetCounter()); |
654 |
phh = ehh->GetPscuHeader(); |
obth = OBT(phh->GetOrbitalTime()); |
655 |
pkth = PKT(phh->GetCounter()); |
}; |
656 |
obth = OBT(phh->GetOrbitalTime()); |
// |
657 |
}; |
if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
658 |
// |
if ( pkth > upperpkt && obth > upperobt ){ |
659 |
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); |
660 |
if ( pkth > upperpkt && obth > upperobt ){ |
upperpkt = pkth; |
661 |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt); |
upperobt = obth; |
662 |
upperpkt = pkth; |
rhev = lasthead+1; |
663 |
upperobt = obth; |
} else { |
664 |
rhev = lasthead+1; |
rhev = lasthead; |
665 |
} else { |
}; |
666 |
rhev = lasthead; |
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
667 |
}; |
// |
668 |
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
669 |
// |
if ( pktt > upperpkt && obtt > upperobt ){ |
670 |
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); |
671 |
if ( pktt > upperpkt && obtt > upperobt ){ |
upperpkt = pktt; |
672 |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
upperobt = obtt; |
673 |
upperpkt = pktt; |
rtev = lasttrail+1; |
674 |
upperobt = obtt; |
} else { |
675 |
rtev = lasttrail+1; |
rtev = lasttrail; |
676 |
} else { |
}; |
677 |
rtev = lasttrail; |
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
678 |
|
// |
679 |
}; |
}; |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
680 |
// |
// |
681 |
if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry); |
if ( IsDebug() ) printf(" Upper limits are: OBT %lld pkt_num %lld upper entry %i \n",upperobt,upperpkt,upperentry); |
682 |
// |
// |
683 |
return(0); |
return(0); |
684 |
} |
} |
812 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
813 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
814 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
815 |
|
// |
816 |
|
if ( IsDebug() ) printf("\n DB INFORMATIONS:\n SQL: %s Version: %s Host %s Port %i \n\n",conn->GetDBMS(),conn->ServerInfo(),conn->GetHost(),conn->GetPort()); |
817 |
|
// |
818 |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
819 |
// |
// |
820 |
// set DB timezone to UTC |
// set DB timezone to UTC |
826 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
827 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
828 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
829 |
|
oss.str(""); |
830 |
|
oss << "SET wait_timeout=173000;"; |
831 |
|
conn->Query(oss.str().c_str()); |
832 |
// |
// |
833 |
}; |
}; |
834 |
|
|
835 |
/** |
/** |
836 |
* Return the correct packet number if we went back to zero |
* Return the correct packet number if we went back to zero |
837 |
*/ |
*/ |
838 |
UInt_t PamelaDBOperations::PKT(UInt_t pkt_num){ |
Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){ |
839 |
// |
// |
840 |
// if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (pktfirst - (UInt_t)(16777212/2)) is %u \n",pkt_num,pktfirst,(pktfirst - (UInt_t)(16777212/2))); |
if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (UInt_t)(16777214/2)) is %u \n",pkt_num,ppktfirst,(UInt_t)(16777214/2)); |
841 |
// |
// |
842 |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
if ( pkt_num < (ppktfirst/2) && ppktfirst > (16777214/2) ){ |
843 |
|
if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL); |
844 |
|
return((Long64_t)pkt_num+16777215LL); |
845 |
|
}; |
846 |
// |
// |
847 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( pkt_num > ppktfirst*2 && pkt_num > (16777214/2) ){ |
848 |
if ( (pkt_num-16777215) < 0 ){ |
if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL); |
849 |
return((16777215-pkt_num)); |
return((Long64_t)pkt_num-16777215LL); |
|
} else { |
|
|
return((pkt_num-16777215)); |
|
|
}; |
|
850 |
}; |
}; |
851 |
// |
// |
852 |
return(pkt_num); |
if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)pkt_num); |
853 |
|
return((Long64_t)pkt_num); |
854 |
// |
// |
855 |
}; |
}; |
856 |
|
|
857 |
/** |
/** |
858 |
* Return the correct On Board Time if we went back to zero |
* Return the correct On Board Time if we went back to zero |
859 |
*/ |
*/ |
860 |
ULong64_t PamelaDBOperations::OBT(UInt_t obt){ |
Long64_t PamelaDBOperations::OBT(UInt_t obt){ |
861 |
// |
// |
862 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max())); |
863 |
// |
// |
864 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt > (pobtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
865 |
if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
|
return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
|
|
} else { |
|
|
return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
|
|
}; |
|
866 |
}; |
}; |
867 |
// |
// |
868 |
return((ULong64_t)obt); |
return((Long64_t)obt); |
869 |
}; |
}; |
870 |
|
|
871 |
/** |
/** |
1044 |
if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){ |
if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){ |
1045 |
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
1046 |
toffset = (UInt_t)atoll(row->GetField(2)) - (UInt_t)(this->OBT((UInt_t)atoll(row->GetField(1)))/1000) + t0; |
toffset = (UInt_t)atoll(row->GetField(2)) - (UInt_t)(this->OBT((UInt_t)atoll(row->GetField(1)))/1000) + t0; |
1047 |
|
// |
1048 |
|
tsync = (UInt_t)atoll(row->GetField(2)); |
1049 |
|
obt0 = (UInt_t)atoll(row->GetField(1)); |
1050 |
|
// |
1051 |
return(1); |
return(1); |
1052 |
}; |
}; |
1053 |
// |
// |
1244 |
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
1245 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
1246 |
// |
// |
1247 |
|
tsync = TSYNC; |
1248 |
|
obt0 = OBT; |
1249 |
|
// |
1250 |
delete result; |
delete result; |
1251 |
return(signal); |
return(signal); |
1252 |
} |
} |
1346 |
VarDumpEvent *vde = 0; |
VarDumpEvent *vde = 0; |
1347 |
VarDumpRecord *vdr = 0; |
VarDumpRecord *vdr = 0; |
1348 |
// |
// |
1349 |
|
Bool_t found = false; |
1350 |
trDumpEv->SetBranchAddress("VarDump", &vde); |
trDumpEv->SetBranchAddress("VarDump", &vde); |
1351 |
if ( trDumpEv->GetEntries() > 0 ){ |
if ( trDumpEv->GetEntries() > 0 ){ |
1352 |
Bool_t found = false; |
found = false; |
1353 |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
1354 |
trDumpEv->GetEntry(i); |
trDumpEv->GetEntry(i); |
1355 |
vde->Records->GetEntries(); |
// vde->Records->GetEntries(); |
1356 |
if ( vde->Records->GetEntries()>0 ){ |
if ( vde->Records->GetEntries()>5 ){ |
1357 |
found = true; |
found = true; |
1358 |
goto fill; |
goto fill; |
1359 |
}; |
}; |
1366 |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
1367 |
// |
// |
1368 |
} else { |
} else { |
1369 |
if ( !this->GetBOOTnumber() ) return(4); |
if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(4); |
1370 |
|
}; |
1371 |
|
} else { |
1372 |
|
if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(2); |
1373 |
|
}; |
1374 |
|
// |
1375 |
|
UInt_t bn = 0; |
1376 |
|
Bool_t afound = false; |
1377 |
|
if ( !found && this->AutoBoot()){ |
1378 |
|
afound = true; |
1379 |
|
// |
1380 |
|
// Search for other files with similar timesync |
1381 |
|
// |
1382 |
|
if ( IsDebug() ) printf(" tsync %u obt0 %u \n",tsync,obt0); |
1383 |
|
UInt_t upperts = tsync-(obt0/1000)+5; |
1384 |
|
UInt_t lowerts = tsync-(obt0/1000)-5; |
1385 |
|
oss.str(""); |
1386 |
|
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)<" |
1387 |
|
<< upperts |
1388 |
|
<< " AND TIMESYNC-(OBT0/1000)>" |
1389 |
|
<< lowerts |
1390 |
|
<< " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;"; |
1391 |
|
result = conn->Query(oss.str().c_str()); |
1392 |
|
if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to find boot number:\n %s \n",oss.str().c_str()); |
1393 |
|
// |
1394 |
|
if ( !result ) throw -4;; |
1395 |
|
found = true; |
1396 |
|
if ( result->GetRowCount()<3 ){ |
1397 |
|
if ( IsDebug() ) printf(" AGH! no results!\n"); |
1398 |
|
found = false; |
1399 |
|
} else { |
1400 |
|
row = result->Next(); |
1401 |
|
bn = (UInt_t)atoll(row->GetField(0)); |
1402 |
|
for ( Int_t r=1; r<result->GetRowCount() ;r++){ |
1403 |
|
if ( !row ) throw -4; |
1404 |
|
if ( IsDebug() ) printf(" BOOT number is %s \n",row->GetField(0)); |
1405 |
|
if ( bn != (UInt_t)atoll(row->GetField(0)) ){ |
1406 |
|
if ( IsDebug() ) printf(" AGH! bn = %u here instead %u \n",bn,(UInt_t)atoll(row->GetField(0))); |
1407 |
|
found = false; |
1408 |
|
}; |
1409 |
|
row = result->Next(); |
1410 |
|
}; |
1411 |
}; |
}; |
1412 |
|
}; |
1413 |
|
// |
1414 |
|
Int_t sgn = 0; |
1415 |
|
// |
1416 |
|
if ( !found && !BOOTNO ){ |
1417 |
|
throw -29; |
1418 |
} else { |
} else { |
1419 |
if ( !this->GetBOOTnumber() ) return(2); |
if ( afound ){ |
1420 |
|
this->SetBOOTnumber(bn); |
1421 |
|
sgn = 8; |
1422 |
|
}; |
1423 |
}; |
}; |
1424 |
// |
// |
1425 |
oss.str(""); |
oss.str(""); |
1429 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
1430 |
// |
// |
1431 |
delete result; |
delete result; |
1432 |
return(0); |
return(sgn); |
1433 |
}; |
}; |
1434 |
|
|
1435 |
/** |
/** |
1747 |
delete result; |
delete result; |
1748 |
// |
// |
1749 |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
1750 |
|
if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n"); |
1751 |
return(signal); |
return(signal); |
1752 |
}; |
}; |
1753 |
|
|
1861 |
// |
// |
1862 |
} else { |
} else { |
1863 |
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 \n"); |
1864 |
|
return; |
1865 |
}; |
}; |
1866 |
// |
// |
1867 |
// |
// |
2923 |
// |
// |
2924 |
} else { |
} else { |
2925 |
// |
// |
2926 |
if ( IsDebug() ) printf(" Repetead calo calibration for section %i at time %i obt %i pkt %i \n",section,fromtime,obt,pkt); |
if ( IsDebug() ) printf(" Repeated calo calibration for section %i at time %i obt %i pkt %i \n",section,fromtime,obt,pkt); |
2927 |
// |
// |
2928 |
}; |
}; |
2929 |
// |
// |
3134 |
pkt1 = ph1->GetCounter(); |
pkt1 = ph1->GetCounter(); |
3135 |
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
3136 |
// |
// |
3137 |
valid = 1; |
// valid = 1; |
3138 |
// |
// // |
3139 |
if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
// if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
3140 |
// |
// |
3141 |
// |
// |
3142 |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
3143 |
// |
// |
3144 |
if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); |
if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); |
3145 |
|
// |
3146 |
|
valid = ValidateTrkCalib( caltrk1, eh1 ); |
3147 |
|
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
3148 |
// |
// |
3149 |
// Do we have the second calibration packet? |
// Do we have the second calibration packet? |
3150 |
// |
// |
3161 |
obt2 = ph2->GetOrbitalTime(); |
obt2 = ph2->GetOrbitalTime(); |
3162 |
pkt2 = ph2->GetCounter(); |
pkt2 = ph2->GetCounter(); |
3163 |
// |
// |
3164 |
if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
3165 |
// |
// |
3166 |
} else { |
} else { |
3167 |
// |
// |
3192 |
// |
// |
3193 |
if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2); |
if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2); |
3194 |
// |
// |
3195 |
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
3196 |
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
3197 |
|
valid = valid & valid2; |
3198 |
|
// |
3199 |
// Handle good calib |
// Handle good calib |
3200 |
// |
// |
3201 |
this->HandleTRK_CALIB(true,true); |
this->HandleTRK_CALIB(true,true); |
4464 |
// |
// |
4465 |
}; |
}; |
4466 |
}; |
}; |
4467 |
|
|
4468 |
|
/** |
4469 |
|
* |
4470 |
|
* Rearrange calibration tables |
4471 |
|
* |
4472 |
|
**/ |
4473 |
|
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
4474 |
|
|
4475 |
|
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
4476 |
|
UInt_t timeaftercalib=120000; //2000; |
4477 |
|
// ---------- |
4478 |
|
// Check CRCs |
4479 |
|
// ---------- |
4480 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
4481 |
|
if( caltrk->crc_hcal[ipkt] )return 0; // :-( |
4482 |
|
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( |
4483 |
|
} |
4484 |
|
// ----------------------- |
4485 |
|
// Check missing packets: |
4486 |
|
// ----------------------- |
4487 |
|
// Readout order: |
4488 |
|
// ------------------ |
4489 |
|
// DSP packet board |
4490 |
|
// ------------------ |
4491 |
|
// 12 0 1 |
4492 |
|
// 10 1 1 |
4493 |
|
// 8 2 1 |
4494 |
|
// 4 3 1 |
4495 |
|
// 6 4 1 |
4496 |
|
// 2 5 1 |
4497 |
|
// ------------------ |
4498 |
|
// 11 0 2 |
4499 |
|
// 9 1 2 |
4500 |
|
// 7 2 2 |
4501 |
|
// 3 3 2 |
4502 |
|
// 5 4 2 |
4503 |
|
// 1 5 2 |
4504 |
|
// ------------------ |
4505 |
|
// ------------------------------------------------- |
4506 |
|
// Check if it is first or second calibration packet |
4507 |
|
// ------------------------------------------------- |
4508 |
|
UInt_t build=0; |
4509 |
|
TString classname = caltrk->GetName(); |
4510 |
|
UInt_t base=0; |
4511 |
|
UInt_t mask=0; |
4512 |
|
if(classname.Contains("CalibTrk1Event")){ |
4513 |
|
base=12; |
4514 |
|
mask=0x03F000; |
4515 |
|
} |
4516 |
|
if(classname.Contains("CalibTrk2Event")){ |
4517 |
|
base=18; |
4518 |
|
mask=0xFC0000; |
4519 |
|
} |
4520 |
|
// ------------------------------------------------- |
4521 |
|
// Count number of packets and set build variable |
4522 |
|
// ------------------------------------------------- |
4523 |
|
Int_t npkts=0; |
4524 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
4525 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
4526 |
|
npkts++; |
4527 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
4528 |
|
} |
4529 |
|
} |
4530 |
|
// if( npkts==6 )return 1; // :-) |
4531 |
|
|
4532 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
4533 |
|
|
4534 |
|
// ----------------------------------------------- |
4535 |
|
// If missing packets: check the acq configuration |
4536 |
|
// (some DSPs might be excluded from acquisition) |
4537 |
|
// ----------------------------------------------- |
4538 |
|
|
4539 |
|
// ----------------------------------------------- |
4540 |
|
// retrieve the first run header after calib |
4541 |
|
// ----------------------------------------------- |
4542 |
|
PacketType *pctp; |
4543 |
|
EventCounter *cod; |
4544 |
|
cod = eh->GetCounter(); |
4545 |
|
Int_t irun = cod->Get(pctp->RunHeader); |
4546 |
|
TTree *rh=(TTree*)file->Get("RunHeader"); |
4547 |
|
if ( !rh || rh->IsZombie() ) throw -17; |
4548 |
|
if( rh->GetEntries() == irun ){ |
4549 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
4550 |
|
return 0; // :-( |
4551 |
|
} |
4552 |
|
|
4553 |
|
RunHeaderEvent *run = 0; |
4554 |
|
EventHeader *hrun = 0; |
4555 |
|
rh->SetBranchAddress("RunHeader", &run); |
4556 |
|
rh->SetBranchAddress("Header", &hrun); |
4557 |
|
rh->GetEntry(irun); |
4558 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
4559 |
|
|
4560 |
|
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
4561 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
4562 |
|
return 0; // :-( |
4563 |
|
} |
4564 |
|
|
4565 |
|
if( !run->RM_ACQ_AFTER_CALIB ){ |
4566 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
4567 |
|
return 0; // :-( |
4568 |
|
} |
4569 |
|
|
4570 |
|
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
4571 |
|
if( dtime > timeaftercalib ){ |
4572 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
4573 |
|
return 0; // :-( |
4574 |
|
} |
4575 |
|
|
4576 |
|
|
4577 |
|
|
4578 |
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
4579 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
4580 |
|
return 0; // :-( |
4581 |
|
} |
4582 |
|
return 1; // :-) |
4583 |
|
|
4584 |
|
} |
4585 |
|
|
4586 |
|
/** |
4587 |
|
* |
4588 |
|
* Check the DB (only for overlapping runs at the moment) |
4589 |
|
* |
4590 |
|
**/ |
4591 |
|
UInt_t PamelaDBOperations::Check(){ |
4592 |
|
// |
4593 |
|
UInt_t test = 0; |
4594 |
|
// |
4595 |
|
UInt_t thisrht = 0; |
4596 |
|
UInt_t thisrtt = 0; |
4597 |
|
UInt_t thisid = 0; |
4598 |
|
UInt_t prevrht = 0; |
4599 |
|
UInt_t prevrtt = 0; |
4600 |
|
UInt_t previd = 0; |
4601 |
|
// |
4602 |
|
UInt_t prevl0id = 0; |
4603 |
|
UInt_t thisl0id = 0; |
4604 |
|
// |
4605 |
|
stringstream oss; |
4606 |
|
TSQLResult *result = 0; |
4607 |
|
TSQLRow *row = 0; |
4608 |
|
TSQLResult *result2 = 0; |
4609 |
|
TSQLRow *row2 = 0; |
4610 |
|
oss.str(""); |
4611 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;"; |
4612 |
|
// oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; |
4613 |
|
result = conn->Query(oss.str().c_str()); |
4614 |
|
// |
4615 |
|
if ( !result ) throw -4;; |
4616 |
|
// |
4617 |
|
row = result->Next(); |
4618 |
|
// |
4619 |
|
while ( row ){ |
4620 |
|
thisid = (UInt_t)atoll(row->GetField(0)); |
4621 |
|
thisl0id = (UInt_t)atoll(row->GetField(1)); |
4622 |
|
thisrht = (UInt_t)atoll(row->GetField(2)); |
4623 |
|
thisrtt = (UInt_t)atoll(row->GetField(3)); |
4624 |
|
// |
4625 |
|
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
4626 |
|
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
4627 |
|
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
4628 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4629 |
|
printf(" CHECK n.1 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid); |
4630 |
|
TString prevf = ""; |
4631 |
|
TString thisf = ""; |
4632 |
|
oss.str(""); |
4633 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4634 |
|
result2 = conn->Query(oss.str().c_str()); |
4635 |
|
if ( !result2 ) throw -4;; |
4636 |
|
row2 = result2->Next(); |
4637 |
|
prevf = (TString)row2->GetField(0); |
4638 |
|
oss.str(""); |
4639 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4640 |
|
result2 = conn->Query(oss.str().c_str()); |
4641 |
|
if ( !result2 ) throw -4;; |
4642 |
|
row2 = result2->Next(); |
4643 |
|
thisf = (TString)row2->GetField(0); |
4644 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4645 |
|
test = 1; |
4646 |
|
}; |
4647 |
|
// |
4648 |
|
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
4649 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4650 |
|
printf(" CHECK n.2 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid); |
4651 |
|
TString prevf = ""; |
4652 |
|
TString thisf = ""; |
4653 |
|
oss.str(""); |
4654 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4655 |
|
result2 = conn->Query(oss.str().c_str()); |
4656 |
|
if ( !result2 ) throw -4;; |
4657 |
|
row2 = result2->Next(); |
4658 |
|
prevf = (TString)row2->GetField(0); |
4659 |
|
oss.str(""); |
4660 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4661 |
|
result2 = conn->Query(oss.str().c_str()); |
4662 |
|
if ( !result2 ) throw -4;; |
4663 |
|
row2 = result2->Next(); |
4664 |
|
thisf = (TString)row2->GetField(0); |
4665 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4666 |
|
test = 1; |
4667 |
|
}; |
4668 |
|
// |
4669 |
|
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
4670 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4671 |
|
printf(" CHECK n.3 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid); |
4672 |
|
TString prevf = ""; |
4673 |
|
TString thisf = ""; |
4674 |
|
oss.str(""); |
4675 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4676 |
|
result2 = conn->Query(oss.str().c_str()); |
4677 |
|
if ( !result2 ) throw -4;; |
4678 |
|
row2 = result2->Next(); |
4679 |
|
prevf = (TString)row2->GetField(0); |
4680 |
|
oss.str(""); |
4681 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4682 |
|
result2 = conn->Query(oss.str().c_str()); |
4683 |
|
if ( !result2 ) throw -4;; |
4684 |
|
row2 = result2->Next(); |
4685 |
|
thisf = (TString)row2->GetField(0); |
4686 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4687 |
|
test = 1; |
4688 |
|
}; |
4689 |
|
|
4690 |
|
// |
4691 |
|
prevrht = thisrht; |
4692 |
|
prevrtt = thisrtt; |
4693 |
|
previd = thisid; |
4694 |
|
prevl0id = thisl0id; |
4695 |
|
row = result->Next(); |
4696 |
|
}; |
4697 |
|
// |
4698 |
|
return(test); |
4699 |
|
// |
4700 |
|
}; |