31 |
#include <varDump/VarDumpRecord.h> |
#include <varDump/VarDumpRecord.h> |
32 |
#include <physics/S4/S4Event.h> |
#include <physics/S4/S4Event.h> |
33 |
// |
// |
34 |
|
#include <sgp4.h> |
35 |
|
|
36 |
#include <PamelaDBOperations.h> |
#include <PamelaDBOperations.h> |
37 |
// |
// |
38 |
using namespace std; |
using namespace std; |
39 |
using namespace pamela; |
using namespace pamela; |
40 |
|
|
41 |
|
// Some function to work with cTle stuff. |
42 |
|
bool compTLE(cTle* tle1, cTle *tle2); |
43 |
|
float getTleJulian(cTle *); |
44 |
|
string getTleDatetime(cTle*); |
45 |
|
|
46 |
/** |
/** |
47 |
* Constructor. |
* Constructor. |
48 |
* @param host hostname for the SQL connection. |
* @param host hostname for the SQL connection. |
54 |
* @param obt0 file obt0. |
* @param obt0 file obt0. |
55 |
* @param tsync file timesync. |
* @param tsync file timesync. |
56 |
* @param debug debug flag. |
* @param debug debug flag. |
57 |
|
* @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){ |
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){ |
60 |
// |
// |
61 |
// |
// |
62 |
SetConnection(host,user,password); |
SetConnection(host,user,password); |
70 |
SetTsync(tsync); |
SetTsync(tsync); |
71 |
SetObt0(obt0); |
SetObt0(obt0); |
72 |
// |
// |
73 |
|
SetTLEPath(tlefilename); |
74 |
|
// |
75 |
// |
// |
76 |
SetRootName(filerootname); |
INSERT_RAW =!filerawname.IsNull(); |
77 |
SetRawName(filerawname); |
if(INSERT_RAW)SetRawName(filerawname); |
78 |
// |
// |
79 |
this->OpenFile(); |
INSERT_ROOT = !filerootname.IsNull(); |
80 |
|
if( INSERT_ROOT ){ |
81 |
|
this->SetRootName(filerootname); |
82 |
|
this->SetOrbitNo(); |
83 |
|
file = TFile::Open(this->GetRootName().Data()); |
84 |
|
}; |
85 |
// |
// |
86 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
87 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
88 |
|
|
89 |
|
VALIDATE = false; |
90 |
|
|
91 |
// |
// |
92 |
}; |
}; |
93 |
|
|
96 |
*/ |
*/ |
97 |
void PamelaDBOperations::Close(){ |
void PamelaDBOperations::Close(){ |
98 |
if( conn && conn->IsConnected() ) conn->Close(); |
if( conn && conn->IsConnected() ) conn->Close(); |
99 |
|
delete clean_time; |
100 |
delete glrun; |
delete glrun; |
101 |
delete this; |
delete this; |
102 |
}; |
}; |
105 |
// SETTERS |
// SETTERS |
106 |
// |
// |
107 |
|
|
108 |
|
// |
109 |
|
// must be out of the constructor in order to FORCE the validation of the latest runs in case you run the validation together with the latest file |
110 |
|
// |
111 |
|
void PamelaDBOperations::CheckValidate(Long64_t olderthan){ |
112 |
|
clean_time = new TDatime(); |
113 |
|
if(olderthan >= 0){ |
114 |
|
VALIDATE = true; |
115 |
|
UInt_t timelim = 0; |
116 |
|
timelim = (UInt_t)clean_time->Convert() - olderthan; |
117 |
|
clean_time->Set(timelim,false); |
118 |
|
}; |
119 |
|
}; |
120 |
|
|
121 |
/** |
/** |
122 |
* Open the DB connection |
* Open the DB connection |
123 |
* @param host hostname for the SQL connection. |
* @param host hostname for the SQL connection. |
125 |
* @param password password for the SQL connection. |
* @param password password for the SQL connection. |
126 |
*/ |
*/ |
127 |
void PamelaDBOperations::SetConnection(TString host, TString user, TString password){ |
void PamelaDBOperations::SetConnection(TString host, TString user, TString password){ |
128 |
|
if ( IsDebug() ) printf(" Connecting using host = %s user = %s password = %s \n",host.Data(),user.Data(),password.Data()); |
129 |
conn = TSQLServer::Connect(host.Data(),user.Data(),password.Data()); |
conn = TSQLServer::Connect(host.Data(),user.Data(),password.Data()); |
130 |
}; |
}; |
131 |
|
|
194 |
}; |
}; |
195 |
|
|
196 |
/** |
/** |
197 |
|
* Store the downlink orbit number from filename. |
198 |
|
*/ |
199 |
|
void PamelaDBOperations::SetOrbitNo(){ |
200 |
|
dworbit = 0; |
201 |
|
TString name = this->GetRootFile(); |
202 |
|
Int_t nlength = name.Length(); |
203 |
|
if ( nlength < 5 ) return; |
204 |
|
TString dwo = 0; |
205 |
|
for (Int_t i = 0; i<5; i++){ |
206 |
|
dwo.Append(name[i],1); |
207 |
|
}; |
208 |
|
if ( dwo.IsDigit() ){ |
209 |
|
dworbit = (UInt_t)dwo.Atoi(); |
210 |
|
} else { |
211 |
|
dwo=""; |
212 |
|
for (Int_t i = 8; i<13; i++){ |
213 |
|
dwo.Append(name[i],1); |
214 |
|
}; |
215 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
216 |
|
}; |
217 |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
218 |
|
return; |
219 |
|
}; |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
/** |
224 |
* Store the NOBOOT flag. |
* Store the NOBOOT flag. |
225 |
* @param noboot true/false. |
* @param noboot true/false. |
226 |
*/ |
*/ |
229 |
}; |
}; |
230 |
|
|
231 |
/** |
/** |
232 |
|
* Store path to the TLE file. |
233 |
|
*/ |
234 |
|
void PamelaDBOperations::SetTLEPath(TString str){ |
235 |
|
tlefilename = str; |
236 |
|
}; |
237 |
|
|
238 |
|
/** |
239 |
* Store the olderthan variable |
* Store the olderthan variable |
240 |
* @param olderthan |
* @param olderthan |
241 |
*/ |
*/ |
242 |
void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
// void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
243 |
olderthan = oldthan; |
// olderthan = oldthan; |
244 |
}; |
// }; |
245 |
|
|
246 |
/** |
/** |
247 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
290 |
ULong64_t upperobt2 = 0; |
ULong64_t upperobt2 = 0; |
291 |
UInt_t zomp = 0; |
UInt_t zomp = 0; |
292 |
UInt_t jump = 50000; // was 5000 |
UInt_t jump = 50000; // was 5000 |
293 |
|
EventCounter *code=0; |
294 |
|
// |
295 |
|
UInt_t deltapkt = 5000; |
296 |
|
ULong64_t deltaobt = 50000; |
297 |
|
// |
298 |
|
// pcksList packetsNames; |
299 |
|
// pcksList::iterator Iter; |
300 |
|
// getPacketsNames(packetsNames); |
301 |
// |
// |
302 |
pktfirst = 0; |
pktfirst = 0; |
303 |
obtfirst = 0; |
obtfirst = 0; |
315 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
316 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
317 |
// |
// |
318 |
|
// code = eh->GetCounter(); |
319 |
|
// UInt_t en = 0; |
320 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
321 |
|
// en = code->Get(GetPacketType(*Iter)); |
322 |
|
// if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en); |
323 |
|
//}; |
324 |
|
// |
325 |
T->GetEntry(nevent-1); |
T->GetEntry(nevent-1); |
326 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
327 |
pktlast = ph->GetCounter(); |
pktlast = ph->GetCounter(); |
341 |
// |
// |
342 |
if ( nevent < 2 ) return(4); |
if ( nevent < 2 ) return(4); |
343 |
// |
// |
344 |
if ( PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst) ){ |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) ){ |
345 |
|
// |
346 |
// go back |
// go back |
347 |
zomp = nevent - 2; |
zomp = nevent - 2; |
348 |
// |
// |
391 |
// 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) |
392 |
// |
// |
393 |
PacketType *pctp=0; |
PacketType *pctp=0; |
|
EventCounter *code=0; |
|
|
T->GetEntry(upperentry); |
|
|
code = eh->GetCounter(); |
|
|
Int_t lasttrail = code->Get(pctp->RunTrailer); |
|
|
Int_t lasthead = code->Get(pctp->RunHeader); |
|
394 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
395 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
396 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
404 |
// |
// |
405 |
rhev = rh->GetEntries(); |
rhev = rh->GetEntries(); |
406 |
rtev = rt->GetEntries(); |
rtev = rt->GetEntries(); |
407 |
|
UInt_t sobtt = 0; |
408 |
|
UInt_t sobth = 0; |
409 |
|
UInt_t spktt = 0; |
410 |
|
UInt_t spkth = 0; |
411 |
UInt_t pktt = 0; |
UInt_t pktt = 0; |
412 |
ULong64_t obtt = 0; |
ULong64_t obtt = 0; |
413 |
UInt_t pkth = 0; |
UInt_t pkth = 0; |
414 |
ULong64_t obth = 0; |
ULong64_t obth = 0; |
415 |
// |
// |
416 |
|
T->GetEntry(upperentry); |
417 |
|
code = eh->GetCounter(); |
418 |
|
Int_t lasttrail = code->Get(pctp->RunTrailer); |
419 |
|
Int_t lasthead = code->Get(pctp->RunHeader); |
420 |
if ( lasttrail < rtev ){ |
if ( lasttrail < rtev ){ |
421 |
rt->GetEntry(lasttrail); |
rt->GetEntry(lasttrail); |
422 |
pht = eht->GetPscuHeader(); |
pht = eht->GetPscuHeader(); |
424 |
obtt = OBT(pht->GetOrbitalTime()); |
obtt = OBT(pht->GetOrbitalTime()); |
425 |
}; |
}; |
426 |
// |
// |
427 |
|
if ( lasthead < rhev ){ |
428 |
|
rh->GetEntry(lasthead); |
429 |
|
phh = ehh->GetPscuHeader(); |
430 |
|
pkth = PKT(phh->GetCounter()); |
431 |
|
obth = OBT(phh->GetOrbitalTime()); |
432 |
|
}; |
433 |
|
// |
434 |
|
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
435 |
|
if ( pkth > upperpkt && obth > upperobt ){ |
436 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt); |
437 |
|
upperpkt = pkth; |
438 |
|
upperobt = obth; |
439 |
|
rhev = lasthead+1; |
440 |
|
} else { |
441 |
|
rhev = lasthead; |
442 |
|
}; |
443 |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
444 |
|
// |
445 |
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
446 |
if ( pktt > upperpkt && obtt > upperobt ){ |
if ( pktt > upperpkt && obtt > upperobt ){ |
447 |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",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); |
452 |
rtev = lasttrail; |
rtev = lasttrail; |
453 |
}; |
}; |
454 |
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
455 |
|
// goto kikko; |
456 |
|
// |
457 |
|
// |
458 |
|
// Check if runtrailer/runheader are within lower limits |
459 |
|
// |
460 |
|
// |
461 |
|
pkth = 0; |
462 |
|
obth = 0; |
463 |
|
spkth = 0; |
464 |
|
sobth = 0; |
465 |
|
for (Int_t k=0; k<rhev; k++){ |
466 |
|
if ( k > 0 ){ |
467 |
|
spkth = pkth; |
468 |
|
sobth = obth; |
469 |
|
}; |
470 |
|
rh->GetEntry(k); |
471 |
|
phh = ehh->GetPscuHeader(); |
472 |
|
pkth = PKT(phh->GetCounter()); |
473 |
|
obth = OBT(phh->GetOrbitalTime()); |
474 |
|
// |
475 |
|
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); |
476 |
|
// |
477 |
|
if ( pkth < spkth && obth < sobth ){ |
478 |
|
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
479 |
|
// |
480 |
|
rhev = k-1; |
481 |
|
rh->GetEntry(rhev); |
482 |
|
pkth = spkth; |
483 |
|
obth = sobth; |
484 |
|
// |
485 |
|
UInt_t evbefh = 0; |
486 |
|
code = ehh->GetCounter(); |
487 |
|
evbefh = code->Get(pctp->Physics); |
488 |
|
if ( evbefh >= 0 ){ |
489 |
|
T->GetEntry(evbefh); |
490 |
|
ph = eh->GetPscuHeader(); |
491 |
|
t_pktlast = PKT(ph->GetCounter()); |
492 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
493 |
|
if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump |
494 |
|
upperpkt = pkth; |
495 |
|
upperobt = obth; |
496 |
|
upperentry = evbefh-1; |
497 |
|
} else { |
498 |
|
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
499 |
|
evbefh++; |
500 |
|
T->GetEntry(evbefh); |
501 |
|
ph = eh->GetPscuHeader(); |
502 |
|
t_pktlast = PKT(ph->GetCounter()); |
503 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
504 |
|
}; |
505 |
|
T->GetEntry(evbefh-1); |
506 |
|
ph = eh->GetPscuHeader(); |
507 |
|
upperpkt = PKT(ph->GetCounter()); |
508 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
509 |
|
upperentry = evbefh-1; |
510 |
|
}; |
511 |
|
}; |
512 |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
513 |
|
goto kikko0; |
514 |
|
}; |
515 |
|
}; |
516 |
|
kikko0: |
517 |
|
// |
518 |
|
// |
519 |
|
// |
520 |
|
pktt = 0; |
521 |
|
obtt = 0; |
522 |
|
spktt = 0; |
523 |
|
sobtt = 0; |
524 |
|
for (Int_t k=0; k<rtev; k++){ |
525 |
|
if ( k > 0 ){ |
526 |
|
spktt = pktt; |
527 |
|
sobtt = obtt; |
528 |
|
}; |
529 |
|
rt->GetEntry(k); |
530 |
|
pht = eht->GetPscuHeader(); |
531 |
|
pktt = PKT(pht->GetCounter()); |
532 |
|
obtt = OBT(pht->GetOrbitalTime()); |
533 |
|
// |
534 |
|
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
535 |
|
// |
536 |
|
if ( pktt < spktt && obtt < sobtt ){ |
537 |
|
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
538 |
|
// |
539 |
|
rtev = k-1; |
540 |
|
rt->GetEntry(rtev); |
541 |
|
pktt = spktt; |
542 |
|
obtt = sobtt; |
543 |
|
if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
544 |
|
// |
545 |
|
UInt_t evbeft = 0; |
546 |
|
code = eht->GetCounter(); |
547 |
|
evbeft = code->Get(pctp->Physics); |
548 |
|
if ( evbeft >= 0 ){ |
549 |
|
T->GetEntry(evbeft); |
550 |
|
ph = eh->GetPscuHeader(); |
551 |
|
t_pktlast = PKT(ph->GetCounter()); |
552 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
553 |
|
if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump |
554 |
|
upperpkt = pktt; |
555 |
|
upperobt = obtt; |
556 |
|
upperentry = evbeft-1; |
557 |
|
} else { |
558 |
|
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
559 |
|
evbeft++; |
560 |
|
T->GetEntry(evbeft); |
561 |
|
ph = eh->GetPscuHeader(); |
562 |
|
t_pktlast = PKT(ph->GetCounter()); |
563 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
564 |
|
}; |
565 |
|
T->GetEntry(evbeft-1); |
566 |
|
ph = eh->GetPscuHeader(); |
567 |
|
upperpkt = PKT(ph->GetCounter()); |
568 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
569 |
|
upperentry = evbeft-1; |
570 |
|
}; |
571 |
|
}; |
572 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
573 |
|
goto kikko; |
574 |
|
// break; |
575 |
|
// |
576 |
|
}; |
577 |
|
// |
578 |
|
}; |
579 |
|
// |
580 |
|
kikko: |
581 |
|
// |
582 |
|
T->GetEntry(upperentry); |
583 |
|
code = eh->GetCounter(); |
584 |
|
lasttrail = code->Get(pctp->RunTrailer); |
585 |
|
lasthead = code->Get(pctp->RunHeader); |
586 |
|
if ( lasttrail < rtev ){ |
587 |
|
rt->GetEntry(lasttrail); |
588 |
|
pht = eht->GetPscuHeader(); |
589 |
|
pktt = PKT(pht->GetCounter()); |
590 |
|
obtt = OBT(pht->GetOrbitalTime()); |
591 |
|
}; |
592 |
// |
// |
593 |
if ( lasthead < rhev ){ |
if ( lasthead < rhev ){ |
594 |
rh->GetEntry(lasthead); |
rh->GetEntry(lasthead); |
595 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
596 |
pkth = PKT(pht->GetCounter()); |
pkth = PKT(phh->GetCounter()); |
597 |
obth = OBT(pht->GetOrbitalTime()); |
obth = OBT(phh->GetOrbitalTime()); |
598 |
}; |
}; |
599 |
// |
// |
600 |
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
608 |
}; |
}; |
609 |
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); |
610 |
// |
// |
611 |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
612 |
|
if ( pktt > upperpkt && obtt > upperobt ){ |
613 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
614 |
|
upperpkt = pktt; |
615 |
|
upperobt = obtt; |
616 |
|
rtev = lasttrail+1; |
617 |
|
} else { |
618 |
|
rtev = lasttrail; |
619 |
|
}; |
620 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
621 |
|
// |
622 |
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); |
623 |
// |
// |
624 |
return(0); |
return(0); |
625 |
} |
} |
626 |
|
|
627 |
|
/** |
628 |
|
* |
629 |
|
* Trick to have unique RUN ID numbers even when runs are deleted and mysql deamon restarted. |
630 |
|
* Entries in the _RUNID_GEN table are never deleted. |
631 |
|
* |
632 |
|
**/ |
633 |
|
UInt_t PamelaDBOperations::AssignRunID(){ |
634 |
|
// |
635 |
|
TSQLResult *result = 0; |
636 |
|
TSQLRow *row = 0; |
637 |
|
UInt_t runid = 0; |
638 |
|
// |
639 |
|
stringstream oss; |
640 |
|
// |
641 |
|
oss.str(""); |
642 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL);"; |
643 |
|
result = conn->Query(oss.str().c_str()); |
644 |
|
if ( !result ) throw -10; |
645 |
|
oss.str(""); |
646 |
|
oss << "SELECT ID FROM _RUNID_GEN ORDER BY ID DESC LIMIT 1;"; |
647 |
|
result = conn->Query(oss.str().c_str()); |
648 |
|
if ( !result ) throw -10; |
649 |
|
// |
650 |
|
row = result->Next(); |
651 |
|
// |
652 |
|
if ( !row ) throw -28; |
653 |
|
// |
654 |
|
runid = (UInt_t)atoll(row->GetField(0)); |
655 |
|
// |
656 |
|
return(runid); |
657 |
|
}; |
658 |
|
|
659 |
// |
// |
660 |
// GETTERS |
// GETTERS |
661 |
// |
// |
731 |
// PRIVATE FUNCTIONS |
// PRIVATE FUNCTIONS |
732 |
// |
// |
733 |
|
|
734 |
/** |
// /** |
735 |
* Open the ROOT filename for reading |
// * Open the ROOT filename for reading |
736 |
*/ |
// */ |
737 |
void PamelaDBOperations::OpenFile(){ |
// void PamelaDBOperations::OpenFile(){ |
738 |
file = TFile::Open(this->GetRootName().Data()); |
// file = TFile::Open(this->GetRootName().Data()); |
739 |
|
// // |
740 |
|
|
741 |
|
void PamelaDBOperations::CheckFile(){ |
742 |
|
if ( !file ) throw -12; |
743 |
}; |
}; |
744 |
|
|
745 |
|
|
746 |
/** |
/** |
747 |
* Check if LEVEL0 file and DB connection have really be opened |
* Check if LEVEL0 file and DB connection have really be opened |
748 |
*/ |
*/ |
749 |
void PamelaDBOperations::CheckFile(){ |
void PamelaDBOperations::CheckConnection(){ |
|
// |
|
|
if ( !file ) throw -12; |
|
750 |
// |
// |
751 |
// check connection |
// check connection |
752 |
// |
// |
753 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
754 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
755 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
756 |
|
if ( !dworbit ) throw -27; |
757 |
}; |
}; |
758 |
|
|
759 |
/** |
/** |
933 |
if ( this->GetID_RAW() == 0 ) throw -11; |
if ( this->GetID_RAW() == 0 ) throw -11; |
934 |
// |
// |
935 |
oss.str(""); |
oss.str(""); |
936 |
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
937 |
<< id << " AND TO_ID_RAW >= " |
<< this->GetRawFile().Data() << "';"; |
|
<< id << ";"; |
|
938 |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
939 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
940 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
941 |
row = result->Next(); |
row = result->Next(); |
942 |
if ( !row ) throw -10; |
// |
943 |
|
if ( !row ){ |
944 |
|
oss.str(""); |
945 |
|
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
946 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
947 |
|
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
948 |
|
result = conn->Query(oss.str().c_str()); |
949 |
|
if ( !result ) throw -10; |
950 |
|
row = result->Next(); |
951 |
|
if ( !row ) throw -10; |
952 |
|
}; |
953 |
// |
// |
954 |
t0 = (UInt_t)TDatime(row->GetField(0)).Convert(); |
t0 = (UInt_t)TDatime(row->GetField(0)).Convert(); |
955 |
/* |
/* |
1023 |
// |
// |
1024 |
TYPE = 55;//224; |
TYPE = 55;//224; |
1025 |
// |
// |
1026 |
|
if ( IsDebug() ) printf("mcmd tsync %i tsync %u obt %u \n",i,TSYNC,OBT); |
1027 |
|
// |
1028 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
1029 |
existsts = true; |
existsts = true; |
1030 |
goto eout; |
goto eout; |
1047 |
// |
// |
1048 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
1049 |
// |
// |
1050 |
if ( rhev > 0 ){ |
Int_t nrhev = rh->GetEntries(); |
1051 |
rh->GetEntry(0); |
Int_t nrtev = rt->GetEntries(); |
1052 |
// |
if ( IsDebug() ) printf(" ou nevent %i rhev %i rtev %i \n",nevent,nrhev,nrtev); |
1053 |
TSYNC = runh->LAST_TIME_SYNC_INFO; |
// |
1054 |
OBT = runh->OBT_TIME_SYNC * 1000; |
if ( nrhev > 0 ){ |
1055 |
// |
for (Int_t i=0; i<nrhev; i++){ |
1056 |
TYPE = 20; |
// |
1057 |
// |
rh->GetEntry(i); |
1058 |
if ( TSYNC && OBT ){ |
// |
1059 |
existsts = true; |
TSYNC = runh->LAST_TIME_SYNC_INFO; |
1060 |
goto eout; |
OBT = runh->OBT_TIME_SYNC * 1000; |
1061 |
|
// |
1062 |
|
TYPE = 20; |
1063 |
|
// |
1064 |
|
if ( IsDebug() ) printf("runheader %i tsync %u obt %u \n",i,TSYNC,OBT); |
1065 |
|
// |
1066 |
|
if ( TSYNC && OBT ){ |
1067 |
|
existsts = true; |
1068 |
|
goto eout; |
1069 |
|
}; |
1070 |
}; |
}; |
1071 |
// |
// |
1072 |
}; |
}; |
1073 |
if ( rtev > 0 ){ |
if ( nrtev > 0 ){ |
1074 |
// |
// |
1075 |
if ( IsDebug() ) printf(" No runheader \n"); |
if ( IsDebug() ) printf(" No runheader \n"); |
1076 |
signal = 6; |
signal = 6; |
1077 |
// |
// |
1078 |
rt->GetEntry(0); |
for (Int_t i=0; i<nrtev; i++){ |
1079 |
// |
// |
1080 |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
rt->GetEntry(i); |
1081 |
OBT = runt->OBT_TYME_SYNC * 1000; |
// |
1082 |
// |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
1083 |
TYPE = 21; |
OBT = runt->OBT_TYME_SYNC * 1000; |
1084 |
// |
// |
1085 |
if ( TSYNC && OBT ){ |
TYPE = 21; |
1086 |
existsts = true; |
// |
1087 |
goto eout; |
if ( IsDebug() ) printf("runtrailer %i tsync %u obt %u \n",i,TSYNC,OBT); |
1088 |
|
// |
1089 |
|
if ( TSYNC && OBT ){ |
1090 |
|
existsts = true; |
1091 |
|
goto eout; |
1092 |
|
}; |
1093 |
}; |
}; |
1094 |
// |
// |
1095 |
} else { |
} else { |
1556 |
if ( glrun->GetNEVENTS() > (UInt_t)atoll(row->GetField(1)) ){ |
if ( glrun->GetNEVENTS() > (UInt_t)atoll(row->GetField(1)) ){ |
1557 |
// |
// |
1558 |
if ( IsDebug() ) printf(" The new run has more events than the old one \n"); |
if ( IsDebug() ) printf(" The new run has more events than the old one \n"); |
1559 |
oss.str(""); |
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
1560 |
oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
// oss.str(""); |
1561 |
if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
// oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
1562 |
conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
1563 |
|
// conn->Query(oss.str().c_str()); |
1564 |
if ( signal ) signal = false; |
if ( signal ) signal = false; |
1565 |
goto gonext; |
goto gonext; |
1566 |
// |
// |
1574 |
// |
// |
1575 |
if ( IsDebug() ) printf(" The new run has the same number of events and the runheader the old one miss the runheader \n"); |
if ( IsDebug() ) printf(" The new run has the same number of events and the runheader the old one miss the runheader \n"); |
1576 |
// |
// |
1577 |
oss.str(""); |
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
1578 |
oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
// oss.str(""); |
1579 |
if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
// oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
1580 |
conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
1581 |
|
// conn->Query(oss.str().c_str()); |
1582 |
// |
// |
1583 |
if ( signal ) signal = false; |
if ( signal ) signal = false; |
1584 |
goto gonext; |
goto gonext; |
1592 |
// |
// |
1593 |
if ( IsDebug() ) printf(" The new run has the same number of events, the runheader and the runtrailer the old one miss the runtrailer \n"); |
if ( IsDebug() ) printf(" The new run has the same number of events, the runheader and the runtrailer the old one miss the runtrailer \n"); |
1594 |
// |
// |
1595 |
oss.str(""); |
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
1596 |
oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
// oss.str(""); |
1597 |
if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
// oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
1598 |
conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
1599 |
|
// conn->Query(oss.str().c_str()); |
1600 |
if ( signal ) signal = false; |
if ( signal ) signal = false; |
1601 |
// |
// |
1602 |
}; |
}; |
1632 |
// |
// |
1633 |
this->FillClass(); |
this->FillClass(); |
1634 |
// |
// |
1635 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
1636 |
|
glrun->SetID(this->AssignRunID()); |
1637 |
|
glrun->SetID_RUN_FRAG(0); |
1638 |
|
glrun->Fill_GL_RUN(conn); |
1639 |
|
}; |
1640 |
} else { |
} else { |
1641 |
// |
// |
1642 |
if ( IsDebug() ) printf(" oh no! the distance between runheader and runtrailer seems wrong: check %llu pktt %llu \n",chkpkt,pktt); |
if ( IsDebug() ) printf(" oh no! the distance between runheader and runtrailer seems wrong: check %llu pktt %llu \n",chkpkt,pktt); |
1808 |
}; |
}; |
1809 |
if ( IsDebug() ) printf(" Check overlapping events done: %i %i %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); |
if ( IsDebug() ) printf(" Check overlapping events done: %i %i %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); |
1810 |
// |
// |
|
glrun1->SetID(0); |
|
1811 |
glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); |
glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); |
1812 |
glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); |
glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); |
1813 |
glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); |
glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); |
1835 |
// |
// |
1836 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
1837 |
// |
// |
1838 |
|
glrun->SetID(this->AssignRunID()); |
1839 |
|
glrun->SetID_RUN_FRAG(glrun1->GetID()); |
1840 |
glrun->Fill_GL_RUN(conn); |
glrun->Fill_GL_RUN(conn); |
1841 |
// |
// |
1842 |
// get id number |
// get id number |
1843 |
// |
// |
1844 |
oss.str(""); |
// oss.str(""); |
1845 |
oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND " |
// oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND " |
1846 |
<< " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND " |
// << " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND " |
1847 |
<< " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";"; |
// << " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";"; |
1848 |
// |
// // |
1849 |
if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); |
// if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); |
1850 |
// |
// // |
1851 |
result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
1852 |
if ( !result ) throw -4; |
// if ( !result ) throw -4; |
1853 |
row = result->Next(); |
// row = result->Next(); |
1854 |
// |
// // |
1855 |
UInt_t idrun0 = 0; |
// UInt_t idrun0 = 0; |
1856 |
if ( !row ){ |
// if ( !row ){ |
1857 |
throw -10; |
// throw -10; |
1858 |
} else { |
// } else { |
1859 |
idrun0 = (UInt_t)atoll(row->GetField(0)); |
// idrun0 = (UInt_t)atoll(row->GetField(0)); |
1860 |
}; |
// }; |
|
// |
|
|
glrun1->SetID_RUN_FRAG(idrun0); |
|
1861 |
// |
// |
1862 |
|
// glrun1->SetID_RUN_FRAG(idrun0); |
1863 |
|
glrun1->SetID_RUN_FRAG(glrun->GetID()); |
1864 |
glrun1->Fill_GL_RUN(conn); |
glrun1->Fill_GL_RUN(conn); |
1865 |
// |
// |
1866 |
oss.str(""); |
// oss.str(""); |
1867 |
oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;"; |
// oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;"; |
1868 |
// |
// // |
1869 |
if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str()); |
// if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str()); |
1870 |
// |
// // |
1871 |
result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
1872 |
if ( !result ) throw -4; |
// if ( !result ) throw -4; |
1873 |
row = result->Next(); |
// row = result->Next(); |
1874 |
// |
// // |
1875 |
UInt_t idrun1 = 0; |
// UInt_t idrun1 = 0; |
1876 |
if ( !row ){ |
// if ( !row ){ |
1877 |
throw -10; |
// throw -10; |
1878 |
} else { |
// } else { |
1879 |
idrun1 = (UInt_t)atoll(row->GetField(0)); |
// idrun1 = (UInt_t)atoll(row->GetField(0)); |
1880 |
}; |
// }; |
1881 |
// |
// // |
1882 |
oss.str(""); |
// oss.str(""); |
1883 |
oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;"; |
// oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;"; |
1884 |
// |
// // |
1885 |
result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
1886 |
if ( !result ) throw -4; |
// if ( !result ) throw -4; |
1887 |
// |
// |
1888 |
}; |
}; |
1889 |
// |
// |
1891 |
// |
// |
1892 |
// delete old entry in fragment table |
// delete old entry in fragment table |
1893 |
// |
// |
1894 |
oss.str(""); |
glrun->DeleteRun(conn,idfrag,"GL_RUN_FRAGMENTS"); |
1895 |
// |
// oss.str(""); |
1896 |
oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; |
// // |
1897 |
// |
// oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; |
1898 |
if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); |
// // |
1899 |
result = conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); |
1900 |
if ( !result ) throw -4; |
// result = conn->Query(oss.str().c_str()); |
1901 |
|
// if ( !result ) throw -4; |
1902 |
// |
// |
1903 |
return; |
return; |
1904 |
// |
// |
2034 |
glrun->SetRUNTRAILER_OBT(glrun1->GetRUNTRAILER_OBT()); |
glrun->SetRUNTRAILER_OBT(glrun1->GetRUNTRAILER_OBT()); |
2035 |
glrun->SetRUNTRAILER_PKT(glrun1->GetRUNTRAILER_PKT()); |
glrun->SetRUNTRAILER_PKT(glrun1->GetRUNTRAILER_PKT()); |
2036 |
// |
// |
|
glrun1->SetID(0); |
|
2037 |
glrun1->SetRUNHEADER_TIME(glrun->GetRUNHEADER_TIME()); |
glrun1->SetRUNHEADER_TIME(glrun->GetRUNHEADER_TIME()); |
2038 |
glrun1->SetRUNHEADER_OBT(glrun->GetRUNHEADER_OBT()); |
glrun1->SetRUNHEADER_OBT(glrun->GetRUNHEADER_OBT()); |
2039 |
glrun1->SetRUNHEADER_PKT(glrun->GetRUNHEADER_PKT()); |
glrun1->SetRUNHEADER_PKT(glrun->GetRUNHEADER_PKT()); |
2053 |
// |
// |
2054 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
2055 |
// |
// |
2056 |
|
glrun->SetID(this->AssignRunID()); |
2057 |
|
// |
2058 |
|
glrun->SetID_RUN_FRAG(glrun1->GetID()); |
2059 |
glrun->Fill_GL_RUN(conn); |
glrun->Fill_GL_RUN(conn); |
2060 |
// |
// |
2061 |
// get id number |
// get id number |
2062 |
// |
// |
2063 |
oss.str(""); |
// oss.str(""); |
2064 |
oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND " |
// oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND " |
2065 |
<< " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND " |
// << " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND " |
2066 |
<< " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";"; |
// << " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";"; |
2067 |
// |
// // |
2068 |
if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); |
// if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); |
2069 |
// |
// // |
2070 |
result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
2071 |
if ( !result ) throw -4; |
// if ( !result ) throw -4; |
2072 |
row = result->Next(); |
// row = result->Next(); |
2073 |
// |
// // |
2074 |
UInt_t idrun0 = 0; |
// UInt_t idrun0 = 0; |
2075 |
if ( !row ){ |
// if ( !row ){ |
2076 |
throw -10; |
// throw -10; |
2077 |
} else { |
// } else { |
2078 |
idrun0 = (UInt_t)atoll(row->GetField(0)); |
// idrun0 = (UInt_t)atoll(row->GetField(0)); |
2079 |
}; |
// }; |
2080 |
// |
// // |
2081 |
glrun1->SetID_RUN_FRAG(idrun0); |
// glrun1->SetID_RUN_FRAG(idrun0); |
2082 |
// |
// |
2083 |
|
glrun1->SetID_RUN_FRAG(glrun->GetID()); |
2084 |
glrun1->Fill_GL_RUN(conn); |
glrun1->Fill_GL_RUN(conn); |
2085 |
// |
// |
2086 |
oss.str(""); |
// oss.str(""); |
2087 |
oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;"; |
// oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;"; |
2088 |
// |
// // |
2089 |
if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str()); |
// if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str()); |
2090 |
// |
// // |
2091 |
result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
2092 |
if ( !result ) throw -4; |
// if ( !result ) throw -4; |
2093 |
row = result->Next(); |
// row = result->Next(); |
2094 |
// |
// // |
2095 |
UInt_t idrun1 = 0; |
// UInt_t idrun1 = 0; |
2096 |
if ( !row ){ |
// if ( !row ){ |
2097 |
throw -10; |
// throw -10; |
2098 |
} else { |
// } else { |
2099 |
idrun1 = (UInt_t)atoll(row->GetField(0)); |
// idrun1 = (UInt_t)atoll(row->GetField(0)); |
2100 |
}; |
// }; |
2101 |
// |
// // |
2102 |
oss.str(""); |
// oss.str(""); |
2103 |
oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;"; |
// oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;"; |
2104 |
// |
// // |
2105 |
result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
2106 |
if ( !result ) throw -4; |
// if ( !result ) throw -4; |
2107 |
// |
// |
2108 |
}; |
}; |
2109 |
// |
// |
2111 |
// |
// |
2112 |
// delete old entry in fragment table |
// delete old entry in fragment table |
2113 |
// |
// |
2114 |
oss.str(""); |
glrun->DeleteRun(conn,idfrag,"GL_RUN_FRAGMENTS"); |
2115 |
// |
// oss.str(""); |
2116 |
oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; |
// // |
2117 |
// |
// oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; |
2118 |
if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); |
// // |
2119 |
result = conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); |
2120 |
if ( !result ) throw -4; |
// result = conn->Query(oss.str().c_str()); |
2121 |
|
// if ( !result ) throw -4; |
2122 |
// |
// |
2123 |
// |
// |
2124 |
return; |
return; |
2188 |
if ( IsDebug() ) printf(" The run is new \n"); |
if ( IsDebug() ) printf(" The run is new \n"); |
2189 |
if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); |
if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); |
2190 |
// |
// |
2191 |
|
glrun->SetID(this->AssignRunID()); |
2192 |
|
glrun->SetID_RUN_FRAG(0); |
2193 |
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
2194 |
// |
// |
2195 |
} else { |
} else { |
2222 |
// |
// |
2223 |
this->FillClass(mishead,mistrail,firstev,lastev); |
this->FillClass(mishead,mistrail,firstev,lastev); |
2224 |
// |
// |
2225 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2226 |
|
glrun->SetID(this->AssignRunID()); |
2227 |
|
glrun->SetID_RUN_FRAG(0); |
2228 |
|
glrun->Fill_GL_RUN(conn); |
2229 |
|
}; |
2230 |
// |
// |
2231 |
}; |
}; |
2232 |
// |
// |
2393 |
// |
// |
2394 |
this->SetCommonGLRUN(firstTime,lastTime); |
this->SetCommonGLRUN(firstTime,lastTime); |
2395 |
// |
// |
2396 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2397 |
|
glrun->SetID(this->AssignRunID()); |
2398 |
|
glrun->SetID_RUN_FRAG(0); |
2399 |
|
glrun->Fill_GL_RUN(conn); |
2400 |
|
}; |
2401 |
// |
// |
2402 |
firstevno = lastentry + 1; |
firstevno = lastentry + 1; |
2403 |
// |
// |
2473 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
2474 |
// |
// |
2475 |
this->FillClass(); |
this->FillClass(); |
2476 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2477 |
|
glrun->SetID(this->AssignRunID()); |
2478 |
|
glrun->SetID_RUN_FRAG(0); |
2479 |
|
glrun->Fill_GL_RUN(conn); |
2480 |
|
}; |
2481 |
// |
// |
2482 |
} else { |
} else { |
2483 |
// |
// |
2505 |
if ( IsDebug() ) printf(" No packets but physics inside the run, I will consider it as good\n"); |
if ( IsDebug() ) printf(" No packets but physics inside the run, I will consider it as good\n"); |
2506 |
// |
// |
2507 |
this->FillClass(); |
this->FillClass(); |
2508 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2509 |
|
glrun->SetID(this->AssignRunID()); |
2510 |
|
glrun->SetID_RUN_FRAG(0); |
2511 |
|
glrun->Fill_GL_RUN(conn); |
2512 |
|
}; |
2513 |
// |
// |
2514 |
} else { |
} else { |
2515 |
// |
// |
2607 |
// |
// |
2608 |
this->SetCommonGLRUN(firstTime,lastTime); |
this->SetCommonGLRUN(firstTime,lastTime); |
2609 |
// |
// |
2610 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2611 |
|
glrun->SetID(this->AssignRunID()); |
2612 |
|
glrun->SetID_RUN_FRAG(0); |
2613 |
|
glrun->Fill_GL_RUN(conn); |
2614 |
|
}; |
2615 |
// |
// |
2616 |
if ( i == lastev && checkfirst < check ){ // if the last event gives a wrong check... |
if ( i == lastev && checkfirst < check ){ // if the last event gives a wrong check... |
2617 |
// |
// |
2646 |
// |
// |
2647 |
this->SetCommonGLRUN(firstTime,lastTime); |
this->SetCommonGLRUN(firstTime,lastTime); |
2648 |
// |
// |
2649 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2650 |
|
glrun->SetID(this->AssignRunID()); |
2651 |
|
glrun->SetID_RUN_FRAG(0); |
2652 |
|
glrun->Fill_GL_RUN(conn); |
2653 |
|
}; |
2654 |
}; |
}; |
2655 |
// |
// |
2656 |
firstevno = lastentry + 1; |
firstevno = lastentry + 1; |
3338 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
3339 |
// |
// |
3340 |
UInt_t moved = 0; |
UInt_t moved = 0; |
3341 |
UInt_t timelim = 0; |
// UInt_t timelim = 0; |
3342 |
TDatime *time = new TDatime(); |
// TDatime *time = new TDatime(); |
3343 |
// |
// |
3344 |
stringstream oss; |
stringstream oss; |
3345 |
oss.str(""); |
oss.str(""); |
3346 |
// |
// |
3347 |
// |
// |
|
// |
|
|
if ( olderthan < 0 ){ |
|
|
if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n"); |
|
|
return(1); |
|
|
}; |
|
|
// |
|
|
// timelim = now - olderthan |
|
|
// |
|
|
time->Set(); |
|
|
timelim = (UInt_t)time->Convert() - olderthan; |
|
|
time->Set(timelim,false); |
|
|
// |
|
3348 |
// check if there are entries older than "olderthan" seconds from now |
// check if there are entries older than "olderthan" seconds from now |
3349 |
// |
// |
3350 |
oss.str(""); |
oss.str(""); |
3351 |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3352 |
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
3353 |
// |
// |
3354 |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
3355 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
3356 |
// |
// |
3357 |
if ( result ){ |
if ( result ){ |
3358 |
// |
// |
3359 |
row = result->Next(); |
row = result->Next(); |
3360 |
// |
// |
3361 |
if ( row ){ |
while ( row ){ |
3362 |
// |
// |
3363 |
oss.str(""); |
oss.str(""); |
3364 |
oss << " ID= "<< row->GetField(0); |
oss << " ID= "<< row->GetField(0); |
3393 |
if ( IsDebug() ) printf(" The run is new \n"); |
if ( IsDebug() ) printf(" The run is new \n"); |
3394 |
if ( IsDebug() ) printf(" -> fill the DB \n"); |
if ( IsDebug() ) printf(" -> fill the DB \n"); |
3395 |
// |
// |
3396 |
glrun->SetID(0); |
// glrun->SetID(this->AssignRunID()); we use the old run number! |
3397 |
|
glrun->SetID_RUN_FRAG(glrun->GetID()); |
3398 |
glrun->Fill_GL_RUN(conn); |
glrun->Fill_GL_RUN(conn); |
3399 |
// |
// |
3400 |
oss.str(""); |
// oss.str(""); |
3401 |
oss << " SELECT ID FROM GL_RUN WHERE " |
// oss << " SELECT ID FROM GL_RUN WHERE " |
3402 |
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
// << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
3403 |
<< " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
// << " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
3404 |
<< " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
// << " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
3405 |
<< " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
// << " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
3406 |
<< " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
// << " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
3407 |
// |
// // |
3408 |
if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str()); |
// if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str()); |
3409 |
result2 = conn->Query(oss.str().c_str()); |
// result2 = conn->Query(oss.str().c_str()); |
3410 |
// |
// // |
3411 |
if ( !result2 ) throw -4; |
// if ( !result2 ) throw -4; |
3412 |
// |
// // |
3413 |
row2 = result2->Next(); |
// row2 = result2->Next(); |
3414 |
// |
// // |
3415 |
if ( !row2 ) throw -25; |
// if ( !row2 ) throw -25; |
3416 |
// |
// // |
3417 |
oss.str(""); |
// oss.str(""); |
3418 |
oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); |
// oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); |
3419 |
if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); |
// if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); |
3420 |
result2 = conn->Query(oss.str().c_str()); |
// result2 = conn->Query(oss.str().c_str()); |
3421 |
// |
// // |
3422 |
if ( !result2 ) throw -4; |
// if ( !result2 ) throw -4; |
3423 |
// |
// |
3424 |
moved++; |
moved++; |
3425 |
// |
// |
3429 |
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
3430 |
// |
// |
3431 |
// |
// |
3432 |
oss.str(""); |
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); |
3433 |
oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); |
// oss.str(""); |
3434 |
if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); |
// oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); |
3435 |
result2 = conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); |
3436 |
// |
// result2 = conn->Query(oss.str().c_str()); |
3437 |
if ( !result2 ) throw -4; |
// // |
3438 |
// |
// if ( !result2 ) throw -4; |
3439 |
|
// // |
3440 |
|
row = result->Next(); |
3441 |
}; |
}; |
3442 |
}; |
}; |
3443 |
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
3450 |
Int_t PamelaDBOperations::ValidateRuns(){ |
Int_t PamelaDBOperations::ValidateRuns(){ |
3451 |
// |
// |
3452 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
3453 |
// TSQLRow *row = 0; |
TSQLRow *row = 0; |
|
// |
|
|
UInt_t timelim = 0; |
|
|
TDatime *time = new TDatime(); |
|
3454 |
// |
// |
3455 |
stringstream oss; |
stringstream oss; |
3456 |
oss.str(""); |
oss.str(""); |
3457 |
// |
// |
3458 |
// |
// ======================================================= |
3459 |
// |
// validate runs by checking missing calibrations |
3460 |
if ( olderthan < 0 ){ |
// ======================================================= |
3461 |
if ( IsDebug() ) printf(" Do not validate runs \n"); |
UInt_t t_stop = 0; |
3462 |
return(1); |
UInt_t t_start = 0; |
3463 |
|
// -------------------------------------------------------------- |
3464 |
|
// 1) get the OBT of the last run inserted after clean-time limit |
3465 |
|
// -------------------------------------------------------------- |
3466 |
|
oss.str(""); |
3467 |
|
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
3468 |
|
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3469 |
|
if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
3470 |
|
result = conn->Query(oss.str().c_str()); |
3471 |
|
if ( !result ) throw -4; |
3472 |
|
if ( !result->GetRowCount() ) { |
3473 |
|
printf(" No runs to validate \n"); |
3474 |
|
return(1); |
3475 |
|
}else{ |
3476 |
|
row = result->Next(); |
3477 |
|
t_start = (UInt_t)atoll(row->GetField(4)); |
3478 |
|
}; |
3479 |
|
// -------------------------------------------------------------- |
3480 |
|
// 2) get the OBT of the last validated run |
3481 |
|
// -------------------------------------------------------------- |
3482 |
|
oss.str(""); |
3483 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
3484 |
|
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3485 |
|
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
3486 |
|
result = conn->Query(oss.str().c_str()); |
3487 |
|
if ( !result ) throw -4; |
3488 |
|
if ( result->GetRowCount() ){ |
3489 |
|
row = result->Next(); |
3490 |
|
t_stop = (UInt_t)atoll(row->GetField(4)); |
3491 |
}; |
}; |
3492 |
// |
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
3493 |
// timelim = now - olderthan |
// -------------------------------------------------------------- |
3494 |
// |
// now retrieves runs to be validated |
3495 |
time->Set(); |
// -------------------------------------------------------------- |
3496 |
timelim = (UInt_t)time->Convert() - olderthan; |
oss.str(""); |
3497 |
time->Set(timelim,false); |
oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; |
3498 |
// |
oss << " AND RUNHEADER_TIME >="<< t_stop; |
3499 |
// First of all validate runs with default calibration: |
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
3500 |
// |
// if ( IsDebug() ) |
3501 |
oss.str(""); |
if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
|
oss << " UPDATE GL_RUN SET VALIDATION=1 WHERE" |
|
|
<< " VALIDATION = 0 AND TRK_CALIB_USED=104 AND " |
|
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Validate runs with trk default calibration inserted before %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
|
3502 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
|
// |
|
3503 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
3504 |
|
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
3505 |
|
// printf("------------------------------------------------------------------------------- \n"); |
3506 |
|
|
3507 |
|
Int_t nrow = 0; |
3508 |
|
GL_RUN* this_run = new GL_RUN(); |
3509 |
|
GL_RUN* next_run = new GL_RUN(); |
3510 |
|
Int_t nseq_max = 1000; |
3511 |
|
// UInt_t* sequence = new UInt_t[100]; |
3512 |
|
vector<UInt_t> sequence(nseq_max); |
3513 |
|
Int_t nseq = 0; |
3514 |
|
Bool_t CHECK = false; |
3515 |
|
Bool_t this_ONLINE = false; |
3516 |
|
Bool_t next_ONLINE = false; |
3517 |
|
UInt_t t1=0,t2=0; |
3518 |
|
// --------------------------------------------------------------------------------- |
3519 |
|
// - loop over runs, back in time, |
3520 |
|
// - select sequences of runs close in time (less than 60 s apart), |
3521 |
|
// which could be preceeded by a calibration |
3522 |
|
// - check if there might be a missing calibration |
3523 |
|
// --------------------------------------------------------------------------------- |
3524 |
|
while(1){ |
3525 |
|
|
3526 |
|
row = result->Next(); |
3527 |
|
if( row == NULL ) break; |
3528 |
|
|
3529 |
|
//------------ |
3530 |
|
//get run info |
3531 |
|
//------------ |
3532 |
|
this_run->Set_GL_RUN(row); |
3533 |
|
|
3534 |
|
Bool_t this_BAD = false; |
3535 |
|
if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; |
3536 |
|
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
3537 |
|
else{ |
3538 |
|
// printf("Missing or corrupted header!! \n"); |
3539 |
|
this_ONLINE = false; |
3540 |
|
this_BAD = true; |
3541 |
|
}; |
3542 |
|
|
3543 |
|
//----------------------------------- |
3544 |
|
//compare with previous(next in time) |
3545 |
|
//----------------------------------- |
3546 |
|
CHECK = false; |
3547 |
|
UInt_t interval=0; |
3548 |
|
|
3549 |
|
if( nrow != 0){ |
3550 |
|
|
3551 |
|
|
3552 |
|
t1 = this_run->GetRUNTRAILER_TIME(); |
3553 |
|
t2 = next_run->GetRUNHEADER_TIME(); |
3554 |
|
interval = (t2-t1); |
3555 |
|
|
3556 |
|
if(this_ONLINE && next_ONLINE){ // this: ON-LINE + next: ON-LINE |
3557 |
|
|
3558 |
|
if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments |
3559 |
|
|
3560 |
|
if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration |
3561 |
|
|
3562 |
|
if( !CHECK && this_run->VALIDATION ){ |
3563 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
3564 |
|
nseq=0; |
3565 |
|
} |
3566 |
|
|
3567 |
|
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
3568 |
|
|
3569 |
|
CHECK = true; |
3570 |
|
|
3571 |
|
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
3572 |
|
|
3573 |
|
assignVALIDATION(next_run->ID,true); |
3574 |
|
nseq=0; |
3575 |
|
} |
3576 |
|
} |
3577 |
|
|
3578 |
|
//---------------------------- |
3579 |
|
//check run sequence for calib |
3580 |
|
//---------------------------- |
3581 |
|
if( CHECK ){ |
3582 |
|
// check if calibration exists |
3583 |
|
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
3584 |
|
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
3585 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
3586 |
|
nseq=0; |
3587 |
|
}; |
3588 |
|
//-------------- |
3589 |
|
//store run info |
3590 |
|
//-------------- |
3591 |
|
*next_run = *this_run; |
3592 |
|
next_ONLINE = this_ONLINE; |
3593 |
|
if( !this_BAD ){ |
3594 |
|
if(nseq < nseq_max){ |
3595 |
|
sequence[nseq] = this_run->ID; |
3596 |
|
nseq++; |
3597 |
|
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
3598 |
|
}; |
3599 |
|
|
3600 |
|
if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); |
3601 |
|
nrow++; |
3602 |
|
|
3603 |
|
}; |
3604 |
|
delete this_run; |
3605 |
|
delete next_run; |
3606 |
// |
// |
3607 |
return(0); |
return(0); |
3608 |
}; |
}; |
3609 |
|
/** |
3610 |
|
* Check if there might be a missing tracker calibration in a given time interval |
3611 |
|
* @param t1 From absolute time |
3612 |
|
* @param t2 To absolute time |
3613 |
|
* @return true if there might be a missing calibration |
3614 |
|
*/ |
3615 |
|
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
3616 |
|
|
3617 |
|
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
3618 |
|
|
3619 |
|
// get the closest VALIDATED calibration before the run start (t2) |
3620 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
3621 |
|
|
3622 |
|
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
3623 |
|
|
3624 |
|
//============================================================== |
3625 |
|
// Check is done first on the basis of time between calibration, |
3626 |
|
// which should be equal to the time between ascending-nodes. |
3627 |
|
//============================================================== |
3628 |
|
if ( t2 - trkcalib->FROM_TIME > 5700) { |
3629 |
|
if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); |
3630 |
|
//============================================================== |
3631 |
|
// there might be a missing calibration, due to: |
3632 |
|
// - MM full |
3633 |
|
// - corrupted packets |
3634 |
|
// - loss of data |
3635 |
|
// There is an exception in case a download was done during ascending node |
3636 |
|
//============================================================== |
3637 |
|
Bool_t DOWNLOAD = false; |
3638 |
|
// check if the calib was skipped becouse of download .... DA FARE!! |
3639 |
|
if(DOWNLOAD)return(false); |
3640 |
|
|
3641 |
|
return(true); //>>> missing |
3642 |
|
|
3643 |
|
}; |
3644 |
|
|
3645 |
|
//============================================================== |
3646 |
|
// If the last calibration is close to the run less than this time, |
3647 |
|
// it is enough to say that there are no missing calibrations |
3648 |
|
//============================================================== |
3649 |
|
// the long time interval bewteen runs might be due to download |
3650 |
|
if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
3651 |
|
return(false); |
3652 |
|
|
3653 |
|
}; |
3654 |
|
/** |
3655 |
|
* Assign VALIDATION value to a GL_RUN entry |
3656 |
|
* @param idrun Run ID |
3657 |
|
* @param validation true/false |
3658 |
|
*/ |
3659 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
3660 |
|
TSQLResult *result = 0; |
3661 |
|
stringstream oss; |
3662 |
|
oss.str(""); |
3663 |
|
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; |
3664 |
|
// |
3665 |
|
// if ( IsDebug() ) |
3666 |
|
// printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
3667 |
|
if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str()); |
3668 |
|
result = conn->Query(oss.str().c_str()); |
3669 |
|
if ( !result ) throw -4; |
3670 |
|
return(0); |
3671 |
|
} |
3672 |
|
|
3673 |
|
|
3674 |
|
|
3675 |
|
// Insert TLEs from file tlefilename in the table GL_TLE in the db |
3676 |
|
// opened by conn, sorting them by date from older to newer, if each |
3677 |
|
// TLE has not been alread inserted. |
3678 |
|
Int_t PamelaDBOperations::populateTLE()//(TSQLServer *conn, char *tleFile) |
3679 |
|
{ |
3680 |
|
fstream tlefile(tlefilename, ios::in); |
3681 |
|
|
3682 |
|
if ( !tlefile ) throw -7; |
3683 |
|
|
3684 |
|
vector<cTle*> ctles; |
3685 |
|
vector<cTle*>::iterator iter; |
3686 |
|
int present = 0; |
3687 |
|
|
3688 |
|
// Get three lines from tlefile, create a cTle object and put it |
3689 |
|
// into ctles |
3690 |
|
while(1) { |
3691 |
|
cTle *tlef; |
3692 |
|
string str1, str2, str3; |
3693 |
|
|
3694 |
|
getline(tlefile, str1); |
3695 |
|
if(tlefile.eof()) break; |
3696 |
|
|
3697 |
|
getline(tlefile, str2); |
3698 |
|
if(tlefile.eof()) break; |
3699 |
|
|
3700 |
|
getline(tlefile, str3); |
3701 |
|
if(tlefile.eof()) break; |
3702 |
|
|
3703 |
|
// We now have three good lines for a cTle. |
3704 |
|
tlef = new cTle(str1, str2, str3); |
3705 |
|
ctles.push_back(tlef); |
3706 |
|
} |
3707 |
|
|
3708 |
|
tlefile.close(); |
3709 |
|
|
3710 |
|
// Sort by date |
3711 |
|
sort(ctles.begin(), ctles.end(), compTLE); |
3712 |
|
|
3713 |
|
// Now we insert each TLE into the db |
3714 |
|
for(iter = ctles.begin(); iter != ctles.end(); iter++) { |
3715 |
|
cTle *tle = *iter; |
3716 |
|
|
3717 |
|
// Do nothing if it's already present in the db. Just increase |
3718 |
|
// the counter present. |
3719 |
|
if (! isTlePresent(tle)) |
3720 |
|
{ |
3721 |
|
int status = insertTle(tle); |
3722 |
|
|
3723 |
|
// Insert query failed. Return 1. |
3724 |
|
if(status == EXIT_FAILURE) { |
3725 |
|
|
3726 |
|
if( IsDebug() ) { |
3727 |
|
cerr << "Error: inserting TLE:" << endl |
3728 |
|
<< tle->getName() << endl |
3729 |
|
<< tle->getLine1() << endl |
3730 |
|
<< tle->getLine2() << endl; |
3731 |
|
} |
3732 |
|
|
3733 |
|
throw -4; |
3734 |
|
return 1; |
3735 |
|
} |
3736 |
|
|
3737 |
|
} |
3738 |
|
else |
3739 |
|
present++; |
3740 |
|
|
3741 |
|
} |
3742 |
|
|
3743 |
|
int inserted = ctles.size() - present; // Number of inserted TLE. |
3744 |
|
if ( IsDebug() ) |
3745 |
|
cout << "\nProcessed TLEs ranging from " << getTleDatetime(ctles[0]) << " to " << getTleDatetime(ctles[ctles.size()-1]) << "." << endl |
3746 |
|
<< inserted << " newly inserted TLEs out of " << ctles.size() << " processed." << endl; |
3747 |
|
|
3748 |
|
ctles.clear(); |
3749 |
|
|
3750 |
|
|
3751 |
|
// Return 2 if no new TLE has been inserted. 0 otherwise. |
3752 |
|
if(! inserted ) return 2; |
3753 |
|
return 0; |
3754 |
|
} |
3755 |
|
|
3756 |
|
|
3757 |
|
// Insert tle in the table GL_TLE using the connection conn. |
3758 |
|
int PamelaDBOperations::insertTle(cTle *tle) |
3759 |
|
{ |
3760 |
|
stringstream oss; |
3761 |
|
TSQLResult *result = 0; |
3762 |
|
|
3763 |
|
oss.str(""); |
3764 |
|
oss << " INSERT INTO GL_TLE (TLE1, TLE2, TLE3, FROM_TIME)" |
3765 |
|
<< " VALUES ( '" |
3766 |
|
<< tle->getName() << "', '" |
3767 |
|
<< tle->getLine1() << "', '" |
3768 |
|
<< tle->getLine2() << "', '" |
3769 |
|
<< getTleDatetime(tle) << "')"; |
3770 |
|
|
3771 |
|
// cout << oss.str().c_str() << endl; |
3772 |
|
result = conn->Query(oss.str().c_str()); |
3773 |
|
if (result == NULL) |
3774 |
|
return EXIT_FAILURE; |
3775 |
|
|
3776 |
|
return EXIT_SUCCESS; |
3777 |
|
} |
3778 |
|
|
3779 |
|
|
3780 |
|
// Return whether tle is already in the db connected by conn. |
3781 |
|
bool PamelaDBOperations::isTlePresent(cTle *tle) |
3782 |
|
{ |
3783 |
|
stringstream oss; |
3784 |
|
TSQLResult *result = 0; |
3785 |
|
|
3786 |
|
oss.str(""); |
3787 |
|
oss << "SELECT * FROM GL_TLE WHERE FROM_TIME = '" |
3788 |
|
<< getTleDatetime(tle) << "'"; |
3789 |
|
|
3790 |
|
result = conn->Query(oss.str().c_str()); |
3791 |
|
if (result == NULL) throw -4; |
3792 |
|
|
3793 |
|
if (result->GetRowCount()) |
3794 |
|
return true; |
3795 |
|
else |
3796 |
|
return false; |
3797 |
|
} |
3798 |
|
|
3799 |
|
|
3800 |
|
// Return whether the first TLE is dated early than the second |
3801 |
|
bool compTLE (cTle *tle1, cTle *tle2) |
3802 |
|
{ |
3803 |
|
return getTleJulian(tle1) < getTleJulian(tle2); |
3804 |
|
} |
3805 |
|
|
3806 |
|
|
3807 |
|
// Return the date of the tle using the format (year-2000)*1e3 + |
3808 |
|
// julian day. e.g. 6365 is the 31th Dec 2006. |
3809 |
|
// It does *not* return a cJulian date. |
3810 |
|
float getTleJulian(cTle *tle) { |
3811 |
|
return tle->getField(cTle::FLD_EPOCHYEAR)*1e3 + tle->getField(cTle::FLD_EPOCHDAY); |
3812 |
|
} |
3813 |
|
|
3814 |
|
|
3815 |
|
// Return a string like YYYY-MM-DD hh:mm:ss, usable for mysql datetime |
3816 |
|
// format. |
3817 |
|
string getTleDatetime(cTle *tle) |
3818 |
|
{ |
3819 |
|
int year, mon, day, hh, mm, ss; |
3820 |
|
double dom; // day of month (is double!) |
3821 |
|
stringstream date; // date in datetime format |
3822 |
|
|
3823 |
|
// create a cJulian from the date in tle |
3824 |
|
cJulian jdate = cJulian( 2000 + (int) tle->getField(cTle::FLD_EPOCHYEAR), tle->getField(cTle::FLD_EPOCHDAY)); |
3825 |
|
|
3826 |
|
// get year, month, day of month |
3827 |
|
jdate.getComponent(&year, &mon, &dom); |
3828 |
|
|
3829 |
|
// build a datetime YYYY-MM-DD hh:mm:ss |
3830 |
|
date.str(""); |
3831 |
|
day = (int) floor(dom); |
3832 |
|
hh = (int) floor( (dom - day) * 24); |
3833 |
|
mm = (int) floor( ((dom - day) * 24 - hh) * 60); |
3834 |
|
ss = (int) floor( ((((dom - day) * 24 - hh) * 60 - mm) * 60)); |
3835 |
|
// ms = (int) floor( (((((dom - day) * 24 - hh) * 60 - mm) * 60) - ss) * 1000); |
3836 |
|
|
3837 |
|
date << year << "-" << mon << "-" << day << " " << hh << ":" << mm << ":" << ss; |
3838 |
|
|
3839 |
|
return date.str(); |
3840 |
|
} |