8 |
#include <list> |
#include <list> |
9 |
#include <errno.h> |
#include <errno.h> |
10 |
// |
// |
11 |
|
#include <TFile.h> |
12 |
|
#include <TSystem.h> |
13 |
#include <TSQLResult.h> |
#include <TSQLResult.h> |
|
#include <TRFIOFile.h> |
|
14 |
#include <TSQLRow.h> |
#include <TSQLRow.h> |
15 |
#include <TTree.h> |
#include <TTree.h> |
16 |
#include <TGraph.h> |
#include <TGraph.h> |
30 |
#include <varDump/VarDumpEvent.h> |
#include <varDump/VarDumpEvent.h> |
31 |
#include <varDump/VarDumpRecord.h> |
#include <varDump/VarDumpRecord.h> |
32 |
#include <physics/S4/S4Event.h> |
#include <physics/S4/S4Event.h> |
|
|
|
33 |
// |
// |
34 |
#include <PamelaDBOperations.h> |
#include <PamelaDBOperations.h> |
35 |
// |
// |
36 |
using namespace std; |
using namespace std; |
37 |
using namespace pamela; |
using namespace pamela; |
|
//using namespace yngn::util; |
|
38 |
|
|
39 |
/** |
/** |
40 |
* Constructor. |
* Constructor. |
169 |
}; |
}; |
170 |
|
|
171 |
/** |
/** |
172 |
|
* Store the olderthan variable |
173 |
|
* @param olderthan |
174 |
|
*/ |
175 |
|
void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
176 |
|
olderthan = oldthan; |
177 |
|
}; |
178 |
|
|
179 |
|
/** |
180 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
181 |
*/ |
*/ |
182 |
Bool_t PamelaDBOperations::SetID_RAW(){ |
Bool_t PamelaDBOperations::SetID_RAW(){ |
188 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
189 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
190 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
191 |
if (result == NULL) throw -4; |
if ( result == NULL ) throw -4; |
192 |
row = result->Next(); |
row = result->Next(); |
193 |
if (row == NULL) return false; |
if ( !row ) return(false); |
194 |
delete result; |
delete result; |
195 |
id = (UInt_t)atoll(row->GetField(0)); |
id = (UInt_t)atoll(row->GetField(0)); |
196 |
return(true); |
return(true); |
223 |
ULong64_t upperobt2 = 0; |
ULong64_t upperobt2 = 0; |
224 |
UInt_t zomp = 0; |
UInt_t zomp = 0; |
225 |
UInt_t jump = 50000; // was 5000 |
UInt_t jump = 50000; // was 5000 |
226 |
|
EventCounter *code=0; |
227 |
|
// |
228 |
|
// pcksList packetsNames; |
229 |
|
// pcksList::iterator Iter; |
230 |
|
// getPacketsNames(packetsNames); |
231 |
// |
// |
232 |
pktfirst = 0; |
pktfirst = 0; |
233 |
obtfirst = 0; |
obtfirst = 0; |
245 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
246 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
247 |
// |
// |
248 |
|
// code = eh->GetCounter(); |
249 |
|
// UInt_t en = 0; |
250 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
251 |
|
// en = code->Get(GetPacketType(*Iter)); |
252 |
|
// if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en); |
253 |
|
//}; |
254 |
|
// |
255 |
T->GetEntry(nevent-1); |
T->GetEntry(nevent-1); |
256 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
257 |
pktlast = ph->GetCounter(); |
pktlast = ph->GetCounter(); |
320 |
// check if last runtrailer is within limits, if not extend limits (one should check for all packets but we need only runtrailer) |
// check if last runtrailer is within limits, if not extend limits (one should check for all packets but we need only runtrailer) |
321 |
// |
// |
322 |
PacketType *pctp=0; |
PacketType *pctp=0; |
|
EventCounter *code=0; |
|
323 |
T->GetEntry(upperentry); |
T->GetEntry(upperentry); |
324 |
code = eh->GetCounter(); |
code = eh->GetCounter(); |
325 |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
337 |
// |
// |
338 |
rhev = rh->GetEntries(); |
rhev = rh->GetEntries(); |
339 |
rtev = rt->GetEntries(); |
rtev = rt->GetEntries(); |
340 |
|
UInt_t sobtt = 0; |
341 |
|
UInt_t sobth = 0; |
342 |
|
UInt_t spktt = 0; |
343 |
|
UInt_t spkth = 0; |
344 |
UInt_t pktt = 0; |
UInt_t pktt = 0; |
345 |
ULong64_t obtt = 0; |
ULong64_t obtt = 0; |
346 |
UInt_t pkth = 0; |
UInt_t pkth = 0; |
353 |
obtt = OBT(pht->GetOrbitalTime()); |
obtt = OBT(pht->GetOrbitalTime()); |
354 |
}; |
}; |
355 |
// |
// |
|
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); |
|
|
// |
|
356 |
if ( lasthead < rhev ){ |
if ( lasthead < rhev ){ |
357 |
rh->GetEntry(lasthead); |
rh->GetEntry(lasthead); |
358 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
371 |
}; |
}; |
372 |
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
373 |
// |
// |
374 |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
375 |
|
if ( pktt > upperpkt && obtt > upperobt ){ |
376 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
377 |
|
upperpkt = pktt; |
378 |
|
upperobt = obtt; |
379 |
|
rtev = lasttrail+1; |
380 |
|
} else { |
381 |
|
rtev = lasttrail; |
382 |
|
}; |
383 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
384 |
|
// goto kikko; |
385 |
|
// |
386 |
|
// |
387 |
|
// Check if runtrailer/runheader are within lower limits |
388 |
|
// |
389 |
|
// |
390 |
|
pkth = 0; |
391 |
|
obth = 0; |
392 |
|
spkth = 0; |
393 |
|
sobth = 0; |
394 |
|
for (Int_t k=0; k<rhev; k++){ |
395 |
|
if ( k > 0 ){ |
396 |
|
spkth = pkth; |
397 |
|
sobth = obth; |
398 |
|
}; |
399 |
|
rh->GetEntry(k); |
400 |
|
phh = ehh->GetPscuHeader(); |
401 |
|
pkth = PKT(phh->GetCounter()); |
402 |
|
obth = OBT(phh->GetOrbitalTime()); |
403 |
|
// |
404 |
|
if ( pkth < spkth && obth < sobth ){ |
405 |
|
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
406 |
|
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
407 |
|
// |
408 |
|
rhev--; |
409 |
|
rh->GetEntry(rhev); |
410 |
|
pkth = spkth; |
411 |
|
obth = sobth; |
412 |
|
if ( IsDebug() ) printf(" lasthead %i pt %i p1 %i ot %u o1 %u \n",rhev,pkth,spkth,obth,sobth); |
413 |
|
// |
414 |
|
UInt_t evbefh = 0; |
415 |
|
code = ehh->GetCounter(); |
416 |
|
evbefh = code->Get(pctp->Physics); |
417 |
|
if ( evbefh >= 0 ){ |
418 |
|
T->GetEntry(evbefh); |
419 |
|
ph = eh->GetPscuHeader(); |
420 |
|
t_pktlast = PKT(ph->GetCounter()); |
421 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
422 |
|
if ( t_pktlast < spkth && t_obtlast < sobth ){ // jump |
423 |
|
upperpkt = pkth; |
424 |
|
upperobt = obth; |
425 |
|
upperentry = evbefh-1; |
426 |
|
} else { |
427 |
|
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
428 |
|
evbefh++; |
429 |
|
T->GetEntry(evbefh); |
430 |
|
ph = eh->GetPscuHeader(); |
431 |
|
t_pktlast = PKT(ph->GetCounter()); |
432 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
433 |
|
}; |
434 |
|
T->GetEntry(evbefh-1); |
435 |
|
ph = eh->GetPscuHeader(); |
436 |
|
upperpkt = PKT(ph->GetCounter()); |
437 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
438 |
|
upperentry = evbefh-1; |
439 |
|
}; |
440 |
|
}; |
441 |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
442 |
|
}; |
443 |
|
}; |
444 |
|
// |
445 |
|
// |
446 |
|
// |
447 |
|
pktt = 0; |
448 |
|
obtt = 0; |
449 |
|
spktt = 0; |
450 |
|
sobtt = 0; |
451 |
|
for (Int_t k=0; k<rtev; k++){ |
452 |
|
if ( k > 0 ){ |
453 |
|
spktt = pktt; |
454 |
|
sobtt = obtt; |
455 |
|
}; |
456 |
|
rt->GetEntry(k); |
457 |
|
pht = eht->GetPscuHeader(); |
458 |
|
pktt = PKT(pht->GetCounter()); |
459 |
|
obtt = OBT(pht->GetOrbitalTime()); |
460 |
|
// |
461 |
|
if ( pktt < spktt && obtt < sobtt ){ |
462 |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
463 |
|
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
464 |
|
// |
465 |
|
rtev--; |
466 |
|
rt->GetEntry(rtev); |
467 |
|
pktt = spktt; |
468 |
|
obtt = sobtt; |
469 |
|
if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
470 |
|
// |
471 |
|
UInt_t evbeft = 0; |
472 |
|
code = eht->GetCounter(); |
473 |
|
evbeft = code->Get(pctp->Physics); |
474 |
|
if ( evbeft >= 0 ){ |
475 |
|
T->GetEntry(evbeft); |
476 |
|
ph = eh->GetPscuHeader(); |
477 |
|
t_pktlast = PKT(ph->GetCounter()); |
478 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
479 |
|
if ( t_pktlast < spktt && t_obtlast < sobtt ){ // jump |
480 |
|
upperpkt = pktt; |
481 |
|
upperobt = obtt; |
482 |
|
upperentry = evbeft-1; |
483 |
|
} else { |
484 |
|
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
485 |
|
evbeft++; |
486 |
|
T->GetEntry(evbeft); |
487 |
|
ph = eh->GetPscuHeader(); |
488 |
|
t_pktlast = PKT(ph->GetCounter()); |
489 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
490 |
|
}; |
491 |
|
T->GetEntry(evbeft-1); |
492 |
|
ph = eh->GetPscuHeader(); |
493 |
|
upperpkt = PKT(ph->GetCounter()); |
494 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
495 |
|
upperentry = evbeft-1; |
496 |
|
}; |
497 |
|
}; |
498 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
499 |
|
break; |
500 |
|
// |
501 |
|
}; |
502 |
|
// |
503 |
|
}; |
504 |
|
// |
505 |
|
// kikko: |
506 |
|
// |
507 |
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 %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry); |
508 |
// |
// |
509 |
return(0); |
return(0); |
694 |
lastPkt = glrun->GetRUNTRAILER_PKT(); |
lastPkt = glrun->GetRUNTRAILER_PKT(); |
695 |
}; |
}; |
696 |
// |
// |
697 |
if ( mishead && mistrail && lastev+1 == firstev ) throw -14; // run with no events, no runtrailer, no runheader... unsupported |
if ( mishead && mistrail && lastev+1 == firstev ) throw -14; // run with no events, no runtrailer, no runheader... unsupported should never arrive here |
698 |
// |
// |
699 |
if ( mishead ) { |
if ( mishead ) { |
700 |
glrun->Set_GL_RUNH0(); |
glrun->Set_GL_RUNH0(); |
812 |
}; |
}; |
813 |
// |
// |
814 |
TTree *T = 0; |
TTree *T = 0; |
815 |
|
Int_t signal = 0; |
816 |
// |
// |
817 |
UInt_t nevent = 0; |
UInt_t nevent = 0; |
818 |
UInt_t recEntries = 0; |
UInt_t recEntries = 0; |
866 |
// |
// |
867 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
868 |
existsts = true; |
existsts = true; |
869 |
goto out; |
goto eout; |
870 |
}; |
}; |
871 |
// |
// |
872 |
}; |
}; |
874 |
}; |
}; |
875 |
if ( !existsts ) { // try with runheader and runtrailer |
if ( !existsts ) { // try with runheader and runtrailer |
876 |
// |
// |
877 |
|
if ( IsDebug() ) printf(" No ts mcmd \n"); |
878 |
|
signal = 2; |
879 |
|
// |
880 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
881 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
882 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
886 |
// |
// |
887 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
888 |
// |
// |
|
// Int_t rhev = rh->GetEntries(); |
|
|
// Int_t rtev = rt->GetEntries(); |
|
|
// |
|
889 |
if ( rhev > 0 ){ |
if ( rhev > 0 ){ |
890 |
rh->GetEntry(0); |
rh->GetEntry(0); |
891 |
// |
// |
896 |
// |
// |
897 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
898 |
existsts = true; |
existsts = true; |
899 |
goto out; |
goto eout; |
900 |
}; |
}; |
901 |
// |
// |
902 |
}; |
}; |
903 |
if ( rtev > 0 ){ |
if ( rtev > 0 ){ |
904 |
|
// |
905 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
906 |
|
signal = 6; |
907 |
|
// |
908 |
rt->GetEntry(0); |
rt->GetEntry(0); |
909 |
// |
// |
910 |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
914 |
// |
// |
915 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
916 |
existsts = true; |
existsts = true; |
917 |
goto out; |
goto eout; |
918 |
}; |
}; |
919 |
// |
// |
920 |
|
} else { |
921 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
922 |
}; |
}; |
923 |
}; |
}; |
924 |
// |
// |
925 |
if ( !existsts ){ // try with inclination mcmd |
if ( !existsts ){ // try with inclination mcmd |
926 |
|
// |
927 |
|
if ( IsDebug() ) printf(" No runtrailer \n"); |
928 |
|
signal = 14; |
929 |
|
// |
930 |
Double_t timesync = 0.; |
Double_t timesync = 0.; |
931 |
for (UInt_t i=0; i<nevent;i++){ |
for (UInt_t i=0; i<nevent;i++){ |
932 |
// |
// |
955 |
TYPE = 666; |
TYPE = 666; |
956 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
957 |
existsts = true; |
existsts = true; |
958 |
goto out; |
goto eout; |
959 |
}; |
}; |
960 |
}; |
}; |
961 |
}; |
}; |
962 |
// |
// |
963 |
if ( !existsts && obt0 ){ // insert timesync by hand |
if ( !existsts && obt0 ){ // insert timesync by hand |
964 |
|
// |
965 |
|
if ( IsDebug() ) printf(" No incl mcmd \n"); |
966 |
|
signal = 30; |
967 |
|
// |
968 |
OBT = obt0; |
OBT = obt0; |
969 |
TSYNC = tsync; |
TSYNC = tsync; |
970 |
TYPE = 999; |
TYPE = 999; |
971 |
existsts = true; |
existsts = true; |
972 |
goto out; |
goto eout; |
973 |
}; |
}; |
974 |
// |
// |
975 |
out: |
eout: |
976 |
// |
// |
977 |
if ( !existsts ) throw -3; |
if ( !existsts ) throw -3; |
978 |
// |
// |
988 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
989 |
// |
// |
990 |
delete result; |
delete result; |
991 |
return(0); |
return(signal); |
992 |
} |
} |
993 |
|
|
994 |
/** |
/** |
1066 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
1067 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1068 |
// |
// |
1069 |
if ( !result ) return(8); |
if ( !result ) throw -4;; |
1070 |
row = result->Next(); |
row = result->Next(); |
1071 |
if ( !row ) return(16); |
if ( !row ) return(16); |
1072 |
if ( row->GetField(1) ){ |
if ( row->GetField(1) ){ |
1073 |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
1074 |
return(1); |
return(1); |
1075 |
}; |
}; |
1076 |
if ( !row->GetField(0) ) return(8); |
if ( !row->GetField(0) ) throw -26; |
1077 |
// |
// |
1078 |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
1079 |
// |
// |
1083 |
trDumpEv = (TTree*)file->Get("VarDump"); |
trDumpEv = (TTree*)file->Get("VarDump"); |
1084 |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
1085 |
// |
// |
|
if (trDumpEv == NULL) return(2); |
|
|
// |
|
1086 |
VarDumpEvent *vde = 0; |
VarDumpEvent *vde = 0; |
1087 |
VarDumpRecord *vdr = 0; |
VarDumpRecord *vdr = 0; |
1088 |
// |
// |
1089 |
trDumpEv->SetBranchAddress("VarDump", &vde); |
trDumpEv->SetBranchAddress("VarDump", &vde); |
1090 |
if (trDumpEv->GetEntries() > 0){ |
if ( trDumpEv->GetEntries() > 0 ){ |
1091 |
trDumpEv->GetEntry(0); |
Bool_t found = false; |
1092 |
vde->Records->GetEntries(); |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
1093 |
if ( !vde->Records->GetEntries() ){ |
trDumpEv->GetEntry(i); |
1094 |
if ( !this->GetBOOTnumber() ) return(4); |
vde->Records->GetEntries(); |
1095 |
} else { |
if ( vde->Records->GetEntries()>0 ){ |
1096 |
|
found = true; |
1097 |
|
goto fill; |
1098 |
|
}; |
1099 |
|
}; |
1100 |
|
fill: |
1101 |
|
if ( found ){ |
1102 |
|
// |
1103 |
vdr = (VarDumpRecord*)vde->Records->At(6); |
vdr = (VarDumpRecord*)vde->Records->At(6); |
1104 |
|
// |
1105 |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
1106 |
|
// |
1107 |
|
} else { |
1108 |
|
if ( !this->GetBOOTnumber() ) return(4); |
1109 |
}; |
}; |
1110 |
} else { |
} else { |
1111 |
if ( !this->GetBOOTnumber() ) return(2); |
if ( !this->GetBOOTnumber() ) return(2); |
1191 |
// |
// |
1192 |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
1193 |
// |
// |
1194 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1195 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1196 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
1197 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
1297 |
if ( (UInt_t)evbeft < upperentry-1 ){ |
if ( (UInt_t)evbeft < upperentry-1 ){ |
1298 |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER!\n"); |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER!\n"); |
1299 |
// |
// |
1300 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1301 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1302 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
1303 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
2274 |
if ( firstev == lastev+1 ) { // no events inside the run! |
if ( firstev == lastev+1 ) { // no events inside the run! |
2275 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
2276 |
// |
// |
|
// if ( IsDebug() ) printf(" -> fill the DB \n"); |
|
|
// |
|
2277 |
this->FillClass(); |
this->FillClass(); |
2278 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
2279 |
// |
// |
2484 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
2485 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
2486 |
// |
// |
2487 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
2488 |
// |
// |
2489 |
for (UInt_t i=0; i < nevents; i++){ |
for (UInt_t i=0; i < nevents; i++){ |
2490 |
tr->GetEntry(i); |
tr->GetEntry(i); |
2801 |
tr2->SetBranchAddress("Header", &eh2); |
tr2->SetBranchAddress("Header", &eh2); |
2802 |
nevents2 = tr2->GetEntries(); |
nevents2 = tr2->GetEntries(); |
2803 |
// |
// |
2804 |
if ( !nevents1 && !nevents2 ) return(0); |
if ( !nevents1 && !nevents2 ) return(1); |
2805 |
// |
// |
2806 |
t2 = -1; |
t2 = -1; |
2807 |
Int_t pret2 = 0; |
Int_t pret2 = 0; |
2973 |
stringstream oss; |
stringstream oss; |
2974 |
oss.str(""); |
oss.str(""); |
2975 |
// |
// |
|
CalibS4Event *calibS4 = new CalibS4Event(); |
|
2976 |
TTree *tr = 0; |
TTree *tr = 0; |
2977 |
EventHeader *eh = 0; |
EventHeader *eh = 0; |
2978 |
PscuHeader *ph = 0; |
PscuHeader *ph = 0; |
2986 |
tr = (TTree*)file->Get("CalibS4"); |
tr = (TTree*)file->Get("CalibS4"); |
2987 |
if ( !tr || tr->IsZombie() ) throw -24; |
if ( !tr || tr->IsZombie() ) throw -24; |
2988 |
// |
// |
|
tr->SetBranchAddress("CalibS4", &calibS4); |
|
2989 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
2990 |
// |
// |
2991 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
2992 |
// |
// |
2993 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
2994 |
// |
// |
2995 |
for (UInt_t i = 0; i < nevents; i++){ |
for (UInt_t i = 0; i < nevents; i++){ |
2996 |
// |
// |
2997 |
tr->GetEntry(i); |
tr->GetEntry(i); |
|
TArrayD params = S4_paramfit(calibS4); |
|
2998 |
// |
// |
2999 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
3000 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
3084 |
}; |
}; |
3085 |
// |
// |
3086 |
oss.str(""); |
oss.str(""); |
3087 |
oss << " INSERT INTO GL_S4_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,PARAM_FIT0,PARAM_FIT1,OBT,PKT,BOOT_NUMBER,VALIDATION) " |
oss << " INSERT INTO GL_S4_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,OBT,PKT,BOOT_NUMBER) " |
3088 |
<< " VALUES (NULL,' " |
<< " VALUES (NULL,' " |
3089 |
<< idroot << "','" |
<< idroot << "','" |
3090 |
<< i << "','" |
<< i << "','" |
3091 |
<< fromtime << "','" |
<< fromtime << "','" |
3092 |
<< totime << "','" |
<< totime << "','" |
|
<< dec << params.At(0) << "','" |
|
|
<< dec << params.At(1) << "','" |
|
3093 |
<< obt << "','" |
<< obt << "','" |
3094 |
<< pkt << "','" |
<< pkt << "','" |
3095 |
<< this->GetBOOTnumber() << "','" |
<< this->GetBOOTnumber() << "');"; |
|
<< valid << "');"; |
|
3096 |
// |
// |
3097 |
if ( IsDebug() ) printf(" Insert the new calibration: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Insert the new calibration: query is \n %s \n",oss.str().c_str()); |
3098 |
// |
// |
3113 |
return(0); |
return(0); |
3114 |
}; |
}; |
3115 |
|
|
3116 |
|
/** |
3117 |
/* |
* Scan the fragment table and move old fragments to the GL_RUN table |
|
* Fit function Received from Valeria Malvezzi 06/02/2006 |
|
3118 |
*/ |
*/ |
3119 |
Double_t fitf(Double_t *x, Double_t *par){ |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
3120 |
Double_t fitval =(par[0]*x[0])+par[1]; |
// |
3121 |
return fitval; |
TSQLResult *result = 0; |
3122 |
} |
TSQLRow *row = 0; |
3123 |
|
TSQLResult *result2 = 0; |
3124 |
|
TSQLRow *row2 = 0; |
3125 |
|
// |
3126 |
|
UInt_t moved = 0; |
3127 |
|
UInt_t timelim = 0; |
3128 |
|
TDatime *time = new TDatime(); |
3129 |
|
// |
3130 |
|
stringstream oss; |
3131 |
|
oss.str(""); |
3132 |
|
// |
3133 |
|
// |
3134 |
|
// |
3135 |
|
if ( olderthan < 0 ){ |
3136 |
|
if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n"); |
3137 |
|
return(1); |
3138 |
|
}; |
3139 |
|
// |
3140 |
|
// timelim = now - olderthan |
3141 |
|
// |
3142 |
|
time->Set(); |
3143 |
|
timelim = (UInt_t)time->Convert() - olderthan; |
3144 |
|
time->Set(timelim,false); |
3145 |
|
// |
3146 |
|
// check if there are entries older than "olderthan" seconds from now |
3147 |
|
// |
3148 |
|
oss.str(""); |
3149 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3150 |
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
3151 |
|
// |
3152 |
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
3153 |
|
result = conn->Query(oss.str().c_str()); |
3154 |
|
// |
3155 |
|
if ( result ){ |
3156 |
|
// |
3157 |
|
row = result->Next(); |
3158 |
|
// |
3159 |
|
if ( row ){ |
3160 |
|
// |
3161 |
|
oss.str(""); |
3162 |
|
oss << " ID= "<< row->GetField(0); |
3163 |
|
// |
3164 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
3165 |
|
// |
3166 |
|
oss.str(""); |
3167 |
|
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " |
3168 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
3169 |
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
3170 |
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
3171 |
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
3172 |
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
3173 |
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
3174 |
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
3175 |
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
3176 |
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
3177 |
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
3178 |
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
3179 |
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
3180 |
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
3181 |
|
// |
3182 |
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
3183 |
|
result2 = conn->Query(oss.str().c_str()); |
3184 |
|
// |
3185 |
|
if ( !result2 ) throw -4; |
3186 |
|
// |
3187 |
|
row2 = result2->Next(); |
3188 |
|
// |
3189 |
|
if ( !row2 ){ |
3190 |
|
// |
3191 |
|
if ( IsDebug() ) printf(" The run is new \n"); |
3192 |
|
if ( IsDebug() ) printf(" -> fill the DB \n"); |
3193 |
|
// |
3194 |
|
glrun->SetID(0); |
3195 |
|
glrun->Fill_GL_RUN(conn); |
3196 |
|
// |
3197 |
|
oss.str(""); |
3198 |
|
oss << " SELECT ID FROM GL_RUN WHERE " |
3199 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
3200 |
|
<< " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
3201 |
|
<< " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
3202 |
|
<< " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
3203 |
|
<< " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
3204 |
|
// |
3205 |
|
if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str()); |
3206 |
|
result2 = conn->Query(oss.str().c_str()); |
3207 |
|
// |
3208 |
|
if ( !result2 ) throw -4; |
3209 |
|
// |
3210 |
|
row2 = result2->Next(); |
3211 |
|
// |
3212 |
|
if ( !row2 ) throw -25; |
3213 |
|
// |
3214 |
|
oss.str(""); |
3215 |
|
oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); |
3216 |
|
if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); |
3217 |
|
result2 = conn->Query(oss.str().c_str()); |
3218 |
|
// |
3219 |
|
if ( !result2 ) throw -4; |
3220 |
|
// |
3221 |
|
moved++; |
3222 |
|
// |
3223 |
|
} else { |
3224 |
|
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
3225 |
|
}; |
3226 |
|
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
3227 |
|
// |
3228 |
|
// |
3229 |
|
oss.str(""); |
3230 |
|
oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); |
3231 |
|
if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); |
3232 |
|
result2 = conn->Query(oss.str().c_str()); |
3233 |
|
// |
3234 |
|
if ( !result2 ) throw -4; |
3235 |
|
// |
3236 |
|
}; |
3237 |
|
}; |
3238 |
|
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
3239 |
|
return(0); |
3240 |
|
}; |
3241 |
|
|
3242 |
/* |
/** |
3243 |
* Fit the S4 calibration with a straight line - Received from Valeria Malvezzi 06/02/2006 |
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
3244 |
*/ |
*/ |
3245 |
TArrayD PamelaDBOperations::S4_paramfit(pamela::CalibS4Event *S4CalibEvent){ |
Int_t PamelaDBOperations::ValidateRuns(){ |
3246 |
|
// |
3247 |
//----------- variable initialization ------------------------------------------------- |
TSQLResult *result = 0; |
3248 |
|
TSQLRow *row = 0; |
3249 |
Double_t mip[3]={1, 30, 300}; |
// |
3250 |
Double_t adc[3] = {0.,0.,0.}; |
UInt_t timelim = 0; |
3251 |
|
TDatime *time = new TDatime(); |
3252 |
|
// |
3253 |
|
stringstream oss; |
3254 |
|
oss.str(""); |
3255 |
|
// |
3256 |
|
// |
3257 |
|
// |
3258 |
|
if ( olderthan < 0 ){ |
3259 |
|
if ( IsDebug() ) printf(" Do not validate runs \n"); |
3260 |
|
return(1); |
3261 |
|
}; |
3262 |
|
// |
3263 |
|
// timelim = now - olderthan |
3264 |
|
// |
3265 |
|
time->Set(); |
3266 |
|
timelim = (UInt_t)time->Convert() - olderthan; |
3267 |
|
time->Set(timelim,false); |
3268 |
|
|
3269 |
|
printf("Validate runs older than %s \n",time->AsSQLString()); |
3270 |
|
|
3271 |
|
// ======================================================= |
3272 |
|
// validate runs by checking missing calibrations |
3273 |
|
// ======================================================= |
3274 |
|
UInt_t t_stop = 0; |
3275 |
|
UInt_t t_start = 0; |
3276 |
|
// -------------------------------------------------------------- |
3277 |
|
// 1) get the OBT of the last run inserted after clean-time limit |
3278 |
|
// -------------------------------------------------------------- |
3279 |
|
oss.str(""); |
3280 |
|
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << time->AsSQLString() |
3281 |
|
<< "' ORDER BY INSERT_TIME DESC LIMIT 1;"; |
3282 |
|
printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
3283 |
|
result = conn->Query(oss.str().c_str()); |
3284 |
|
if ( !result ) throw -4; |
3285 |
|
if ( !result->GetRowCount() ) { |
3286 |
|
printf(" No runs to validate \n"); |
3287 |
|
return(1); |
3288 |
|
}else{ |
3289 |
|
row = result->Next(); |
3290 |
|
t_start = (UInt_t)atoll(row->GetField(4)); |
3291 |
|
printf("t_start %i\n",t_start); |
3292 |
|
}; |
3293 |
|
// -------------------------------------------------------------- |
3294 |
|
// 2) get the OBT of the last validated run |
3295 |
|
// -------------------------------------------------------------- |
3296 |
|
oss.str(""); |
3297 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
3298 |
|
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3299 |
|
printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
3300 |
|
result = conn->Query(oss.str().c_str()); |
3301 |
|
if ( !result ) throw -4; |
3302 |
|
if ( result->GetRowCount() ){ |
3303 |
|
row = result->Next(); |
3304 |
|
t_stop = (UInt_t)atoll(row->GetField(4)); |
3305 |
|
}; |
3306 |
|
printf("t_stop %i\n",t_stop); |
3307 |
|
// -------------------------------------------------------------- |
3308 |
|
// now retrieves runs to be validated |
3309 |
|
// -------------------------------------------------------------- |
3310 |
|
oss.str(""); |
3311 |
|
oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; |
3312 |
|
oss << " AND RUNHEADER_TIME >="<< t_stop; |
3313 |
|
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
3314 |
|
// if ( IsDebug() ) |
3315 |
|
printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
3316 |
|
result = conn->Query(oss.str().c_str()); |
3317 |
|
if ( !result ) throw -4; |
3318 |
|
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
3319 |
|
printf("------------------------------------------------------------------------------- \n"); |
3320 |
|
|
3321 |
TArrayD parametri(2); |
Int_t nrow = 0; |
3322 |
|
GL_RUN* this_run = new GL_RUN(); |
3323 |
valid = 1; |
GL_RUN* next_run = new GL_RUN(); |
3324 |
|
Int_t nseq_max = 100; |
3325 |
//------------ Fit calibrations and find parameters to calibrate data ------------------ |
// UInt_t* sequence = new UInt_t[100]; |
3326 |
pamela::S4::S4Event *s4Record; |
vector<UInt_t> sequence(nseq_max); |
3327 |
|
Int_t nseq = 0; |
3328 |
|
Bool_t CHECK = false; |
3329 |
|
Bool_t this_ONLINE = false; |
3330 |
|
Bool_t next_ONLINE = false; |
3331 |
|
UInt_t t1=0,t2=0; |
3332 |
|
// --------------------------------------------------------------------------------- |
3333 |
|
// - loop over runs, back in time, |
3334 |
|
// - select sequences of runs close in time (less than 60 s apart), |
3335 |
|
// which could be preceeded by a calibration |
3336 |
|
// - check if there might be a missing calibration |
3337 |
|
// --------------------------------------------------------------------------------- |
3338 |
|
while(1){ |
3339 |
|
|
3340 |
|
row = result->Next(); |
3341 |
|
if( row == NULL ) break; |
3342 |
|
|
3343 |
|
//------------ |
3344 |
|
//get run info |
3345 |
|
//------------ |
3346 |
|
this_run->Set_GL_RUN(row); |
3347 |
|
|
3348 |
|
printf(" RUN ID %i --- TRK_CALIB_USED %i --- RM_ACQ_AFTER_CALIB %i --- TIME %i %i \n",this_run->ID,this_run->TRK_CALIB_USED,this_run->RM_ACQ_AFTER_CALIB,this_run->RUNHEADER_TIME, this_run->RUNTRAILER_TIME); |
3349 |
|
|
3350 |
|
Bool_t this_BAD = false; |
3351 |
|
if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; |
3352 |
|
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
3353 |
|
else{ |
3354 |
|
printf("Missing or corrupted header!! \n"); |
3355 |
|
this_ONLINE = false; |
3356 |
|
this_BAD = true; |
3357 |
|
}; |
3358 |
|
|
3359 |
for (Int_t j = 0; j < 4; j++){ |
//----------------------------------- |
3360 |
for (Int_t i = 0; i < 128; i++){ |
//compare with previous(next in time) |
3361 |
s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i)); |
//----------------------------------- |
3362 |
switch (j) { |
CHECK = false; |
3363 |
case 0 :{ |
UInt_t interval=0; |
3364 |
adc[0]=adc[0]+((s4Record->S4_DATA)-32); |
|
3365 |
break; |
if( nrow != 0){ |
3366 |
}; |
|
3367 |
case 1 :{ |
|
3368 |
adc[1]=adc[1]+((s4Record->S4_DATA)-32); |
t1 = this_run->GetRUNTRAILER_TIME(); |
3369 |
break; |
t2 = next_run->GetRUNHEADER_TIME(); |
3370 |
}; |
interval = (t2-t1); |
3371 |
case 3 :{ |
|
3372 |
adc[2]=adc[2]+((s4Record->S4_DATA)-32); |
if(this_ONLINE && next_ONLINE){ // this: ON-LINE + next: ON-LINE |
3373 |
break; |
|
3374 |
}; |
if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments |
3375 |
}; |
|
3376 |
}; |
if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration |
3377 |
|
|
3378 |
|
/* if( CHECK && !next_run->GetRM_ACQ_AFTER_CALIB() ) |
3379 |
|
printf(" ValidateRuns ***WARNING*** : DT = %i but RM_ACQ_AFTER_CALIB = %i \n",(t2-t1),next_run->GetRM_ACQ_AFTER_CALIB());*/ |
3380 |
|
|
3381 |
|
|
3382 |
|
if( !CHECK && this_run->VALIDATION ){ |
3383 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
3384 |
|
nseq=0; |
3385 |
|
} |
3386 |
|
|
3387 |
|
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
3388 |
|
|
3389 |
|
CHECK = true; |
3390 |
|
// if( interval < 60 ) printf(" ValidateRuns ***WARNING*** : kkkkkk DT = %i \n",interval); |
3391 |
|
|
3392 |
|
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
3393 |
|
|
3394 |
|
assignVALIDATION(next_run->ID,true); |
3395 |
|
nseq=0; |
3396 |
|
} |
3397 |
|
} |
3398 |
|
|
3399 |
|
//---------------------------- |
3400 |
|
//check run sequence for calib |
3401 |
|
//---------------------------- |
3402 |
|
if( CHECK ){ |
3403 |
|
// check if calibration exists |
3404 |
|
printf("DT %i ===> CHECK Missing calibration\n",interval); |
3405 |
|
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
3406 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
3407 |
|
nseq=0; |
3408 |
|
} else printf("DT %i\n",interval); |
3409 |
|
//-------------- |
3410 |
|
//store run info |
3411 |
|
//-------------- |
3412 |
|
*next_run = *this_run; |
3413 |
|
next_ONLINE = this_ONLINE; |
3414 |
|
if( !this_BAD ){ |
3415 |
|
if(nseq < nseq_max){ |
3416 |
|
sequence[nseq] = this_run->ID; |
3417 |
|
nseq++; |
3418 |
|
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
3419 |
|
}; |
3420 |
|
|
3421 |
|
nrow++; |
3422 |
|
|
3423 |
}; |
}; |
3424 |
|
delete this_run; |
3425 |
adc[0]=adc[0]/128; |
delete next_run; |
3426 |
adc[1]=adc[1]/128; |
// |
3427 |
adc[2]=adc[2]/128; |
return(0); |
3428 |
|
}; |
3429 |
TGraph *fitpar = new TGraph (3, adc, mip); |
/** |
3430 |
TF1 *func = new TF1("fitf", fitf, -0., 1000., 2); // definizione della funzione, 2 = num. parametri |
* Check if there might be a missing tracker calibration in a given time interval |
3431 |
|
* @param t1 From absolute time |
3432 |
func->SetParameters(0.3,1.); //inizializzazione dei parametri a 1 |
* @param t2 To absolute time |
3433 |
func->SetParNames("m","q"); //definisce il nome dei parametri |
* @return true if there might be a missing calibration |
3434 |
fitpar->Fit(func,"qr"); //fitta fitpar con la funzione func nel range definito nella funzione |
*/ |
3435 |
//fitpar->Fit(func,"r"); //fitta fitpar con la funzione func nel range definito nella funzione |
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
3436 |
|
|
3437 |
parametri[0] = func -> GetParameter(0); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
3438 |
parametri[1] = func -> GetParameter(1); |
|
3439 |
|
// get the closest VALIDATED calibration before the run start (t2) |
3440 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
3441 |
|
|
3442 |
|
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
3443 |
|
|
3444 |
|
//============================================================== |
3445 |
|
// Check is done first on the basis of time between calibration, |
3446 |
|
// which should be equal to the time between ascending-nodes. |
3447 |
|
//============================================================== |
3448 |
|
if ( t2 - trkcalib->FROM_TIME > 5700) { |
3449 |
|
printf("Long time to previous calib %i :-( \n",t2 - trkcalib->FROM_TIME); |
3450 |
|
//============================================================== |
3451 |
|
// there might be a missing calibration, due to: |
3452 |
|
// - MM full |
3453 |
|
// - corrupted packets |
3454 |
|
// - loss of data |
3455 |
|
// There is an exception in case a download was done during ascending node |
3456 |
|
//============================================================== |
3457 |
|
Bool_t DOWNLOAD = false; |
3458 |
|
// check if the calib was skipped becouse of download .... DA FARE!! |
3459 |
|
if(DOWNLOAD)return(false); |
3460 |
|
|
3461 |
|
return(true); //>>> missing |
3462 |
|
|
3463 |
|
}; |
3464 |
|
|
3465 |
|
//============================================================== |
3466 |
|
// If the last calibration is close to the run less than this time, |
3467 |
|
// it is enough to say that there are no missing calibrations |
3468 |
|
//============================================================== |
3469 |
|
// the long time interval bewteen runs might be due to download |
3470 |
|
printf("Short time to previous calib %i :-) \n",t2 - trkcalib->FROM_TIME); |
3471 |
|
return(false); |
3472 |
|
|
3473 |
|
}; |
3474 |
|
/** |
3475 |
|
* Assign VALIDATION value to a GL_RUN entry |
3476 |
|
* @param idrun Run ID |
3477 |
|
* @param validation true/false |
3478 |
|
*/ |
3479 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
3480 |
|
TSQLResult *result = 0; |
3481 |
|
stringstream oss; |
3482 |
|
oss.str(""); |
3483 |
|
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << "';"; |
3484 |
|
// |
3485 |
|
// if ( IsDebug() ) |
3486 |
|
printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
3487 |
|
// printf(" Set VALIDATION = %i for run %i : query is \n %s \n",validation,idrun,oss.str().c_str()); |
3488 |
|
// result = conn->Query(oss.str().c_str()); |
3489 |
|
// if ( !result ) throw -4; |
3490 |
|
return(0); |
3491 |
|
} |
3492 |
|
|
3493 |
|
|
|
if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.8 || parametri[1] > 1. ) valid = 0; |
|
3494 |
|
|
|
if ( IsDebug() ) printf(" par1 = %g par2 = %g\n",parametri[0],parametri[1]); |
|
|
|
|
|
return parametri; |
|
|
}; |
|