14 |
#include <TSQLRow.h> |
#include <TSQLRow.h> |
15 |
#include <TTree.h> |
#include <TTree.h> |
16 |
#include <TGraph.h> |
#include <TGraph.h> |
17 |
#include <TDatime.h> |
#include <TTimeStamp.h> |
18 |
#include <TF1.h> |
#include <TF1.h> |
19 |
// |
// |
20 |
#include <EventHeader.h> |
#include <EventHeader.h> |
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, UInt_t dwinput){ |
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 |
// |
// |
|
SetRootName(filerootname); |
|
|
SetRawName(filerawname); |
|
75 |
// |
// |
76 |
this->OpenFile(); |
INSERT_RAW =!filerawname.IsNull(); |
77 |
|
if(INSERT_RAW)SetRawName(filerawname); |
78 |
|
// |
79 |
|
INSERT_ROOT = !filerootname.IsNull(); |
80 |
|
if( INSERT_ROOT ){ |
81 |
|
this->SetRootName(filerootname); |
82 |
|
this->SetOrbitNo(dwinput); |
83 |
|
file = TFile::Open(this->GetRootName().Data()); |
84 |
|
} else { |
85 |
|
this->SetRootName(""); |
86 |
|
}; |
87 |
// |
// |
88 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
89 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
90 |
|
|
91 |
|
VALIDATE = false; |
92 |
|
|
93 |
// |
// |
94 |
}; |
}; |
95 |
|
|
98 |
*/ |
*/ |
99 |
void PamelaDBOperations::Close(){ |
void PamelaDBOperations::Close(){ |
100 |
if( conn && conn->IsConnected() ) conn->Close(); |
if( conn && conn->IsConnected() ) conn->Close(); |
101 |
|
delete clean_time; |
102 |
delete glrun; |
delete glrun; |
103 |
delete this; |
delete this; |
104 |
}; |
}; |
107 |
// SETTERS |
// SETTERS |
108 |
// |
// |
109 |
|
|
110 |
|
// |
111 |
|
// 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 |
112 |
|
// |
113 |
|
void PamelaDBOperations::CheckValidate(Long64_t olderthan){ |
114 |
|
clean_time = new TDatime(); |
115 |
|
// |
116 |
|
if(olderthan >= 0){ |
117 |
|
VALIDATE = true; |
118 |
|
UInt_t timelim = 0; |
119 |
|
timelim = (UInt_t)clean_time->Convert(true) - olderthan; |
120 |
|
clean_time->Set(timelim,false); |
121 |
|
}; |
122 |
|
}; |
123 |
|
|
124 |
/** |
/** |
125 |
* Open the DB connection |
* Open the DB connection |
126 |
* @param host hostname for the SQL connection. |
* @param host hostname for the SQL connection. |
128 |
* @param password password for the SQL connection. |
* @param password password for the SQL connection. |
129 |
*/ |
*/ |
130 |
void PamelaDBOperations::SetConnection(TString host, TString user, TString password){ |
void PamelaDBOperations::SetConnection(TString host, TString user, TString password){ |
131 |
|
if ( IsDebug() ) printf(" Connecting using host = %s user = %s password = %s \n",host.Data(),user.Data(),password.Data()); |
132 |
conn = TSQLServer::Connect(host.Data(),user.Data(),password.Data()); |
conn = TSQLServer::Connect(host.Data(),user.Data(),password.Data()); |
133 |
}; |
}; |
134 |
|
|
157 |
}; |
}; |
158 |
|
|
159 |
/** |
/** |
160 |
|
* Set the autoboot flag |
161 |
|
* |
162 |
|
*/ |
163 |
|
void PamelaDBOperations::SetAutoBoot(Bool_t dbg){ |
164 |
|
AUTOBOOT = dbg; |
165 |
|
}; |
166 |
|
|
167 |
|
/** |
168 |
|
* Set the nofrag flag |
169 |
|
* |
170 |
|
*/ |
171 |
|
void PamelaDBOperations::SetNoFrag(Bool_t nf){ |
172 |
|
NOFRAG = nf; |
173 |
|
}; |
174 |
|
|
175 |
|
/** |
176 |
* Store the BOOT number of the RAW file. |
* Store the BOOT number of the RAW file. |
177 |
* @param boot BOOT number of the RAW file |
* @param boot BOOT number of the RAW file |
178 |
*/ |
*/ |
213 |
}; |
}; |
214 |
|
|
215 |
/** |
/** |
216 |
|
* Store the downlink orbit number from filename. |
217 |
|
*/ |
218 |
|
void PamelaDBOperations::SetOrbitNo(UInt_t dwinput){ |
219 |
|
dworbit = 0; |
220 |
|
// |
221 |
|
if ( dwinput ){ |
222 |
|
dworbit = dwinput; |
223 |
|
if ( IsDebug() ) printf(" Downlink orbit given by hand: %i \n",dworbit); |
224 |
|
return; |
225 |
|
}; |
226 |
|
// |
227 |
|
TString name = this->GetRootFile(); |
228 |
|
Int_t nlength = name.Length(); |
229 |
|
if ( nlength < 5 ) return; |
230 |
|
TString dwo = 0; |
231 |
|
for (Int_t i = 0; i<5; i++){ |
232 |
|
dwo.Append(name[i],1); |
233 |
|
}; |
234 |
|
if ( dwo.IsDigit() ){ |
235 |
|
dworbit = (UInt_t)dwo.Atoi(); |
236 |
|
} else { |
237 |
|
dwo=""; |
238 |
|
for (Int_t i = 8; i<13; i++){ |
239 |
|
dwo.Append(name[i],1); |
240 |
|
}; |
241 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
242 |
|
}; |
243 |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
244 |
|
return; |
245 |
|
}; |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
/** |
250 |
* Store the NOBOOT flag. |
* Store the NOBOOT flag. |
251 |
* @param noboot true/false. |
* @param noboot true/false. |
252 |
*/ |
*/ |
255 |
}; |
}; |
256 |
|
|
257 |
/** |
/** |
258 |
|
* Store path to the TLE file. |
259 |
|
*/ |
260 |
|
void PamelaDBOperations::SetTLEPath(TString str){ |
261 |
|
tlefilename = str; |
262 |
|
}; |
263 |
|
|
264 |
|
/** |
265 |
* Store the olderthan variable |
* Store the olderthan variable |
266 |
* @param olderthan |
* @param olderthan |
267 |
*/ |
*/ |
268 |
void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
// void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
269 |
olderthan = oldthan; |
// olderthan = oldthan; |
270 |
}; |
// }; |
271 |
|
|
272 |
/** |
/** |
273 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
280 |
oss << "SELECT ID FROM GL_RAW WHERE " |
oss << "SELECT ID FROM GL_RAW WHERE " |
281 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
282 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
283 |
|
|
284 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
285 |
if ( result == NULL ) throw -4; |
if ( result == NULL ) throw -4; |
286 |
row = result->Next(); |
row = result->Next(); |
311 |
UInt_t nevent = 0; |
UInt_t nevent = 0; |
312 |
UInt_t pktlast = 0; |
UInt_t pktlast = 0; |
313 |
UInt_t obtlast = 0; |
UInt_t obtlast = 0; |
314 |
UInt_t t_pktlast = 0; |
Long64_t t_pktlast = 0LL; |
315 |
UInt_t t_obtlast = 0; |
// UInt_t t_obtlast = 0; |
316 |
UInt_t upperpkt2 = 0; |
Long64_t t_obtlast = 0LL; |
317 |
ULong64_t upperobt2 = 0; |
Long64_t upperpkt2 = 0LL; |
318 |
|
Long64_t upperobt2 = 0LL; |
319 |
UInt_t zomp = 0; |
UInt_t zomp = 0; |
320 |
UInt_t jump = 50000; // was 5000 |
UInt_t jump = 50000; // was 5000 |
321 |
EventCounter *code=0; |
EventCounter *code=0; |
322 |
// |
// |
323 |
|
Long64_t deltapkt = 5000LL; |
324 |
|
Long64_t deltaobt = 50000LL; |
325 |
|
// |
326 |
// pcksList packetsNames; |
// pcksList packetsNames; |
327 |
// pcksList::iterator Iter; |
// pcksList::iterator Iter; |
328 |
// getPacketsNames(packetsNames); |
// getPacketsNames(packetsNames); |
359 |
upperobt = OBT(obtlast); |
upperobt = OBT(obtlast); |
360 |
upperentry = nevent-1; |
upperentry = nevent-1; |
361 |
// |
// |
362 |
if ( IsDebug() ) printf(" First entries are: OBT %llu pkt_num %i \n",obtfirst,pktfirst); |
if ( IsDebug() ) printf(" First entries are: OBT %i pkt_num %i \n",obtfirst,pktfirst); |
363 |
// |
// |
364 |
if ( IsDebug() ) printf(" Last entries are: OBT %llu pkt_num %i entry %i\n",upperobt,upperpkt,upperentry); |
if ( IsDebug() ) printf(" Last entries are: OBT %lld pkt_num %lld entry %i\n",upperobt,upperpkt,upperentry); |
365 |
// |
// |
366 |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) || (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) ) return(1); |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) || (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) ) return(1); |
367 |
// |
// |
368 |
if ( !nevent ) return(2); |
if ( !nevent ) return(2); |
369 |
// |
// |
370 |
if ( nevent < 2 ) return(4); |
if ( nevent < 2 ) return(4); |
371 |
|
if ( nevent < jump ) jump = 1; |
372 |
|
// if ( nevent < jump ) jump = int(nevent/10); |
373 |
|
// if ( !jump ) jump = 1; |
374 |
// |
// |
375 |
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) && nevent > deltapkt ){ |
376 |
|
// |
377 |
|
if ( IsDebug() ) printf(" starting jump %i \n",jump); |
378 |
// go back |
// go back |
379 |
zomp = nevent - 2; |
zomp = nevent - 2; |
380 |
// |
// |
396 |
upperpkt2 = PKT(ph->GetCounter()); |
upperpkt2 = PKT(ph->GetCounter()); |
397 |
upperobt2 = OBT(ph->GetOrbitalTime()); |
upperobt2 = OBT(ph->GetOrbitalTime()); |
398 |
// |
// |
399 |
if ( (t_pktlast < upperpkt && t_obtlast > upperobt) || (t_pktlast < upperpkt2 && t_obtlast > upperobt2) ) throw -13; |
if ( (t_pktlast < upperpkt && t_obtlast > upperobt) || (t_pktlast < upperpkt2 && t_obtlast > upperobt2) ){ |
400 |
|
if ( IsDebug() ) printf(" .-. upperpkt2 %lld upperobt2 %lld \n",upperpkt2,upperobt2); |
401 |
|
if ( IsDebug() ) printf(" .-. upperpkt %lld t_pktlast %lld upperobt %lld t_obtlast %lld \n",upperpkt,t_pktlast,upperobt,t_obtlast); |
402 |
|
if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %lld pktlast %u upperobt %lld obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); |
403 |
|
throw -13; |
404 |
|
}; |
405 |
// |
// |
406 |
if ( t_pktlast < upperpkt && t_obtlast < upperobt && t_pktlast < upperpkt2 && t_obtlast < upperobt2 ){ |
if ( t_pktlast < upperpkt && t_obtlast < upperobt && t_pktlast < upperpkt2 && t_obtlast < upperobt2 ){ |
407 |
zomp = i + jump + 1; |
zomp = i + jump + 1; |
408 |
if ( zomp > nevent-2 ) zomp = nevent - 2; |
if ( zomp > nevent-2 ) zomp = nevent - 2; |
409 |
if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %i pktlast %i upperobt %llu obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); |
if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %lld pktlast %i upperobt %lld obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); |
410 |
break; |
break; |
411 |
}; |
}; |
412 |
// |
// |
428 |
// 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) |
429 |
// |
// |
430 |
PacketType *pctp=0; |
PacketType *pctp=0; |
|
T->GetEntry(upperentry); |
|
|
code = eh->GetCounter(); |
|
|
Int_t lasttrail = code->Get(pctp->RunTrailer); |
|
|
Int_t lasthead = code->Get(pctp->RunHeader); |
|
431 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
432 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
433 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
441 |
// |
// |
442 |
rhev = rh->GetEntries(); |
rhev = rh->GetEntries(); |
443 |
rtev = rt->GetEntries(); |
rtev = rt->GetEntries(); |
444 |
UInt_t sobtt = 0; |
Long64_t sobtt = 0LL; |
445 |
UInt_t sobth = 0; |
Long64_t sobth = 0LL; |
446 |
UInt_t spktt = 0; |
Long64_t spktt = 0LL; |
447 |
UInt_t spkth = 0; |
Long64_t spkth = 0LL; |
448 |
UInt_t pktt = 0; |
Long64_t pktt = 0LL; |
449 |
ULong64_t obtt = 0; |
Long64_t obtt = 0LL; |
450 |
UInt_t pkth = 0; |
Long64_t pkth = 0LL; |
451 |
ULong64_t obth = 0; |
Long64_t obth = 0LL; |
452 |
// |
// |
453 |
|
if ( rhev || rtev ){ |
454 |
|
|
455 |
|
|
456 |
|
T->GetEntry(upperentry); |
457 |
|
code = eh->GetCounter(); |
458 |
|
Int_t lasttrail = code->Get(pctp->RunTrailer); |
459 |
|
Int_t lasthead = code->Get(pctp->RunHeader); |
460 |
if ( lasttrail < rtev ){ |
if ( lasttrail < rtev ){ |
461 |
rt->GetEntry(lasttrail); |
rt->GetEntry(lasttrail); |
462 |
pht = eht->GetPscuHeader(); |
pht = eht->GetPscuHeader(); |
467 |
if ( lasthead < rhev ){ |
if ( lasthead < rhev ){ |
468 |
rh->GetEntry(lasthead); |
rh->GetEntry(lasthead); |
469 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
470 |
pkth = PKT(pht->GetCounter()); |
pkth = PKT(phh->GetCounter()); |
471 |
obth = OBT(pht->GetOrbitalTime()); |
obth = OBT(phh->GetOrbitalTime()); |
472 |
}; |
}; |
473 |
// |
// |
474 |
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 %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
475 |
if ( pkth > upperpkt && obth > upperobt ){ |
if ( pkth > upperpkt && obth > upperobt ){ |
476 |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); |
477 |
upperpkt = pkth; |
upperpkt = pkth; |
478 |
upperobt = obth; |
upperobt = obth; |
479 |
rhev = lasthead+1; |
rhev = lasthead+1; |
480 |
} else { |
} else { |
481 |
rhev = lasthead; |
rhev = lasthead; |
482 |
}; |
}; |
483 |
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 %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
484 |
// |
// |
485 |
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 %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
486 |
if ( pktt > upperpkt && obtt > upperobt ){ |
if ( pktt > upperpkt && obtt > upperobt ){ |
487 |
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 %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); |
488 |
upperpkt = pktt; |
upperpkt = pktt; |
489 |
upperobt = obtt; |
upperobt = obtt; |
490 |
rtev = lasttrail+1; |
rtev = lasttrail+1; |
491 |
} else { |
} else { |
492 |
rtev = lasttrail; |
rtev = lasttrail; |
493 |
}; |
}; |
494 |
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 %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
495 |
// goto kikko; |
// goto kikko; |
496 |
// |
// |
497 |
// |
// |
498 |
// Check if runtrailer/runheader are within lower limits |
// Check if runtrailer/runheader are within lower limits |
499 |
// |
// |
500 |
// |
// |
501 |
pkth = 0; |
pkth = 0LL; |
502 |
obth = 0; |
obth = 0LL; |
503 |
spkth = 0; |
spkth = 0LL; |
504 |
sobth = 0; |
sobth = 0LL; |
505 |
for (Int_t k=0; k<rhev; k++){ |
for (Int_t k=0; k<rhev; k++){ |
506 |
if ( k > 0 ){ |
if ( k > 0 ){ |
507 |
spkth = pkth; |
spkth = pkth; |
512 |
pkth = PKT(phh->GetCounter()); |
pkth = PKT(phh->GetCounter()); |
513 |
obth = OBT(phh->GetOrbitalTime()); |
obth = OBT(phh->GetOrbitalTime()); |
514 |
// |
// |
515 |
|
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); |
516 |
|
// |
517 |
if ( pkth < spkth && obth < sobth ){ |
if ( pkth < spkth && obth < sobth ){ |
|
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
|
518 |
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
519 |
// |
// |
520 |
rhev--; |
rhev = k-1; |
521 |
rh->GetEntry(rhev); |
rh->GetEntry(rhev); |
522 |
pkth = spkth; |
pkth = spkth; |
523 |
obth = sobth; |
obth = sobth; |
|
if ( IsDebug() ) printf(" lasthead %i pt %i p1 %i ot %u o1 %u \n",rhev,pkth,spkth,obth,sobth); |
|
524 |
// |
// |
525 |
UInt_t evbefh = 0; |
UInt_t evbefh = 0; |
526 |
code = ehh->GetCounter(); |
code = ehh->GetCounter(); |
530 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
531 |
t_pktlast = PKT(ph->GetCounter()); |
t_pktlast = PKT(ph->GetCounter()); |
532 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
t_obtlast = OBT(ph->GetOrbitalTime()); |
533 |
if ( t_pktlast < spkth && t_obtlast < sobth ){ // jump |
if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump |
534 |
upperpkt = pkth; |
upperpkt = pkth; |
535 |
upperobt = obth; |
upperobt = obth; |
536 |
upperentry = evbefh-1; |
upperentry = evbefh-1; |
549 |
upperentry = evbefh-1; |
upperentry = evbefh-1; |
550 |
}; |
}; |
551 |
}; |
}; |
552 |
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 %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
553 |
|
goto kikko0; |
554 |
}; |
}; |
555 |
}; |
}; |
556 |
|
kikko0: |
557 |
// |
// |
558 |
// |
// |
559 |
// |
// |
560 |
pktt = 0; |
pktt = 0LL; |
561 |
obtt = 0; |
obtt = 0LL; |
562 |
spktt = 0; |
spktt = 0LL; |
563 |
sobtt = 0; |
sobtt = 0LL; |
564 |
for (Int_t k=0; k<rtev; k++){ |
for (Int_t k=0; k<rtev; k++){ |
565 |
if ( k > 0 ){ |
if ( k > 0 ){ |
566 |
spktt = pktt; |
spktt = pktt; |
571 |
pktt = PKT(pht->GetCounter()); |
pktt = PKT(pht->GetCounter()); |
572 |
obtt = OBT(pht->GetOrbitalTime()); |
obtt = OBT(pht->GetOrbitalTime()); |
573 |
// |
// |
574 |
|
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
575 |
|
// |
576 |
if ( pktt < spktt && obtt < sobtt ){ |
if ( pktt < spktt && obtt < sobtt ){ |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
577 |
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
578 |
// |
// |
579 |
rtev--; |
rtev = k-1; |
580 |
rt->GetEntry(rtev); |
rt->GetEntry(rtev); |
581 |
pktt = spktt; |
pktt = spktt; |
582 |
obtt = sobtt; |
obtt = sobtt; |
583 |
if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" lasttrail %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
584 |
// |
// |
585 |
UInt_t evbeft = 0; |
UInt_t evbeft = 0; |
586 |
code = eht->GetCounter(); |
code = eht->GetCounter(); |
590 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
591 |
t_pktlast = PKT(ph->GetCounter()); |
t_pktlast = PKT(ph->GetCounter()); |
592 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
t_obtlast = OBT(ph->GetOrbitalTime()); |
593 |
if ( t_pktlast < spktt && t_obtlast < sobtt ){ // jump |
if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump |
594 |
upperpkt = pktt; |
upperpkt = pktt; |
595 |
upperobt = obtt; |
upperobt = obtt; |
596 |
upperentry = evbeft-1; |
upperentry = evbeft-1; |
609 |
upperentry = evbeft-1; |
upperentry = evbeft-1; |
610 |
}; |
}; |
611 |
}; |
}; |
612 |
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 %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
613 |
break; |
goto kikko; |
614 |
|
// break; |
615 |
// |
// |
616 |
}; |
}; |
617 |
// |
// |
618 |
}; |
}; |
619 |
// |
// |
620 |
// kikko: |
kikko: |
621 |
|
// |
622 |
|
T->GetEntry(upperentry); |
623 |
|
code = eh->GetCounter(); |
624 |
|
lasttrail = code->Get(pctp->RunTrailer); |
625 |
|
lasthead = code->Get(pctp->RunHeader); |
626 |
|
if ( lasttrail < rtev ){ |
627 |
|
rt->GetEntry(lasttrail); |
628 |
|
pht = eht->GetPscuHeader(); |
629 |
|
pktt = PKT(pht->GetCounter()); |
630 |
|
obtt = OBT(pht->GetOrbitalTime()); |
631 |
|
}; |
632 |
|
// |
633 |
|
if ( lasthead < rhev ){ |
634 |
|
rh->GetEntry(lasthead); |
635 |
|
phh = ehh->GetPscuHeader(); |
636 |
|
pkth = PKT(phh->GetCounter()); |
637 |
|
obth = OBT(phh->GetOrbitalTime()); |
638 |
|
}; |
639 |
|
// |
640 |
|
if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
641 |
|
if ( pkth > upperpkt && obth > upperobt ){ |
642 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); |
643 |
|
upperpkt = pkth; |
644 |
|
upperobt = obth; |
645 |
|
rhev = lasthead+1; |
646 |
|
} else { |
647 |
|
rhev = lasthead; |
648 |
|
}; |
649 |
|
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
650 |
|
// |
651 |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
652 |
|
if ( pktt > upperpkt && obtt > upperobt ){ |
653 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); |
654 |
|
upperpkt = pktt; |
655 |
|
upperobt = obtt; |
656 |
|
rtev = lasttrail+1; |
657 |
|
} else { |
658 |
|
rtev = lasttrail; |
659 |
|
}; |
660 |
|
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
661 |
|
// |
662 |
|
|
663 |
|
|
664 |
|
}; |
665 |
// |
// |
666 |
if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry); |
if ( IsDebug() ) printf(" Upper limits are: OBT %lld pkt_num %lld upper entry %i \n",upperobt,upperpkt,upperentry); |
667 |
// |
// |
668 |
return(0); |
return(0); |
669 |
} |
} |
670 |
|
|
671 |
|
/** |
672 |
|
* |
673 |
|
* Trick to have unique RUN ID numbers even when runs are deleted and mysql deamon restarted. |
674 |
|
* Entries in the _RUNID_GEN table are never deleted. |
675 |
|
* |
676 |
|
**/ |
677 |
|
UInt_t PamelaDBOperations::AssignRunID(){ |
678 |
|
// |
679 |
|
TSQLResult *result = 0; |
680 |
|
TSQLRow *row = 0; |
681 |
|
UInt_t runid = 0; |
682 |
|
// |
683 |
|
stringstream oss; |
684 |
|
// |
685 |
|
oss.str(""); |
686 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL);"; |
687 |
|
result = conn->Query(oss.str().c_str()); |
688 |
|
if ( !result ) throw -10; |
689 |
|
oss.str(""); |
690 |
|
oss << "SELECT ID FROM _RUNID_GEN ORDER BY ID DESC LIMIT 1;"; |
691 |
|
result = conn->Query(oss.str().c_str()); |
692 |
|
if ( !result ) throw -10; |
693 |
|
// |
694 |
|
row = result->Next(); |
695 |
|
// |
696 |
|
if ( !row ) throw -28; |
697 |
|
// |
698 |
|
runid = (UInt_t)atoll(row->GetField(0)); |
699 |
|
// |
700 |
|
return(runid); |
701 |
|
}; |
702 |
|
|
703 |
// |
// |
704 |
// GETTERS |
// GETTERS |
705 |
// |
// |
775 |
// PRIVATE FUNCTIONS |
// PRIVATE FUNCTIONS |
776 |
// |
// |
777 |
|
|
778 |
/** |
// /** |
779 |
* Open the ROOT filename for reading |
// * Open the ROOT filename for reading |
780 |
*/ |
// */ |
781 |
void PamelaDBOperations::OpenFile(){ |
// void PamelaDBOperations::OpenFile(){ |
782 |
file = TFile::Open(this->GetRootName().Data()); |
// file = TFile::Open(this->GetRootName().Data()); |
783 |
|
// // |
784 |
|
|
785 |
|
void PamelaDBOperations::CheckFile(){ |
786 |
|
if ( !file ) throw -12; |
787 |
}; |
}; |
788 |
|
|
789 |
|
|
790 |
/** |
/** |
791 |
* Check if LEVEL0 file and DB connection have really be opened |
* Check if LEVEL0 file and DB connection have really be opened |
792 |
*/ |
*/ |
793 |
void PamelaDBOperations::CheckFile(){ |
void PamelaDBOperations::CheckConnection(){ |
|
// |
|
|
if ( !file ) throw -12; |
|
794 |
// |
// |
795 |
// check connection |
// check connection |
796 |
// |
// |
797 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
798 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
799 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
800 |
|
// |
801 |
|
if ( IsDebug() ) printf("\n DB INFORMATIONS:\n SQL: %s Version: %s Host %s Port %i \n\n",conn->GetDBMS(),conn->ServerInfo(),conn->GetHost(),conn->GetPort()); |
802 |
|
// |
803 |
|
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
804 |
|
// |
805 |
|
// set DB timezone to UTC |
806 |
|
// |
807 |
|
stringstream oss; |
808 |
|
// |
809 |
|
oss.str(""); |
810 |
|
oss << "SET time_zone='+0:00';"; |
811 |
|
TSQLResult *result = 0; |
812 |
|
result = conn->Query(oss.str().c_str()); |
813 |
|
if ( !result ) throw -10; |
814 |
|
oss.str(""); |
815 |
|
oss << "SET wait_timeout=173000;"; |
816 |
|
conn->Query(oss.str().c_str()); |
817 |
|
// |
818 |
}; |
}; |
819 |
|
|
820 |
/** |
/** |
821 |
* Return the correct packet number if we went back to zero |
* Return the correct packet number if we went back to zero |
822 |
*/ |
*/ |
823 |
UInt_t PamelaDBOperations::PKT(UInt_t pkt_num){ |
Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){ |
824 |
// |
// |
825 |
// if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (pktfirst - (UInt_t)(16777212/2)) is %u \n",pkt_num,pktfirst,(pktfirst - (UInt_t)(16777212/2))); |
if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (UInt_t)(16777214/2)) is %u \n",pkt_num,pktfirst,(UInt_t)(16777214/2)); |
826 |
// |
// |
827 |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ |
828 |
|
if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL); |
829 |
|
return((Long64_t)pkt_num+16777215LL); |
830 |
|
}; |
831 |
// |
// |
832 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
833 |
if ( (pkt_num-16777215) < 0 ){ |
if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL); |
834 |
return((16777215-pkt_num)); |
return((Long64_t)pkt_num-16777215LL); |
|
} else { |
|
|
return((pkt_num-16777215)); |
|
|
}; |
|
835 |
}; |
}; |
836 |
// |
// |
837 |
return(pkt_num); |
if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)pkt_num); |
838 |
|
return((Long64_t)pkt_num); |
839 |
// |
// |
840 |
}; |
}; |
841 |
|
|
842 |
/** |
/** |
843 |
* Return the correct On Board Time if we went back to zero |
* Return the correct On Board Time if we went back to zero |
844 |
*/ |
*/ |
845 |
ULong64_t PamelaDBOperations::OBT(UInt_t obt){ |
Long64_t PamelaDBOperations::OBT(UInt_t obt){ |
846 |
// |
// |
847 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max())); |
848 |
// |
// |
849 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
850 |
if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
|
return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
|
|
} else { |
|
|
return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
|
|
}; |
|
851 |
}; |
}; |
852 |
// |
// |
853 |
return((ULong64_t)obt); |
return((Long64_t)obt); |
854 |
}; |
}; |
855 |
|
|
856 |
/** |
/** |
991 |
if ( this->GetID_RAW() == 0 ) throw -11; |
if ( this->GetID_RAW() == 0 ) throw -11; |
992 |
// |
// |
993 |
oss.str(""); |
oss.str(""); |
994 |
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
995 |
<< id << " AND TO_ID_RAW >= " |
<< this->GetRawFile().Data() << "';"; |
|
<< id << ";"; |
|
996 |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
997 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
998 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
999 |
row = result->Next(); |
row = result->Next(); |
|
if ( !row ) throw -10; |
|
1000 |
// |
// |
1001 |
t0 = (UInt_t)TDatime(row->GetField(0)).Convert(); |
if ( !row ){ |
1002 |
|
oss.str(""); |
1003 |
|
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1004 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1005 |
|
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1006 |
|
result = conn->Query(oss.str().c_str()); |
1007 |
|
if ( !result ) throw -10; |
1008 |
|
row = result->Next(); |
1009 |
|
if ( !row ) throw -10; |
1010 |
|
}; |
1011 |
|
// |
1012 |
|
TTimeStamp tu = TTimeStamp((UInt_t)atoi(row->GetField(0)),(UInt_t)atoi(row->GetField(1)),(UInt_t)atoi(row->GetField(2)),(UInt_t)atoi(row->GetField(3)),(UInt_t)atoi(row->GetField(4)),(UInt_t)atoi(row->GetField(5)),0,true,0); |
1013 |
|
t0 = (UInt_t)tu.GetSec(); |
1014 |
|
if ( IsDebug() ) printf(" t0 is %u ti is %s %s %s %s %s %s\n",t0,row->GetField(0),row->GetField(1),row->GetField(2),row->GetField(3),row->GetField(4),row->GetField(5)); |
1015 |
|
// |
1016 |
/* |
/* |
1017 |
* Verify that the TIMESYNC have been not already processed |
* Verify that the TIMESYNC have been not already processed |
1018 |
*/ |
*/ |
1027 |
if (result == NULL) throw -10; |
if (result == NULL) throw -10; |
1028 |
row = result->Next(); |
row = result->Next(); |
1029 |
if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){ |
if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){ |
1030 |
|
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
1031 |
toffset = (UInt_t)atoll(row->GetField(2)) - (UInt_t)(this->OBT((UInt_t)atoll(row->GetField(1)))/1000) + t0; |
toffset = (UInt_t)atoll(row->GetField(2)) - (UInt_t)(this->OBT((UInt_t)atoll(row->GetField(1)))/1000) + t0; |
1032 |
|
// |
1033 |
|
tsync = (UInt_t)atoll(row->GetField(2)); |
1034 |
|
obt0 = (UInt_t)atoll(row->GetField(1)); |
1035 |
|
// |
1036 |
return(1); |
return(1); |
1037 |
}; |
}; |
1038 |
// |
// |
1089 |
// |
// |
1090 |
TYPE = 55;//224; |
TYPE = 55;//224; |
1091 |
// |
// |
1092 |
|
if ( IsDebug() ) printf("mcmd tsync %i tsync %u obt %u \n",i,TSYNC,OBT); |
1093 |
|
// |
1094 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
1095 |
existsts = true; |
existsts = true; |
1096 |
goto eout; |
goto eout; |
1113 |
// |
// |
1114 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
1115 |
// |
// |
1116 |
if ( rhev > 0 ){ |
Int_t nrhev = rh->GetEntries(); |
1117 |
rh->GetEntry(0); |
Int_t nrtev = rt->GetEntries(); |
1118 |
// |
if ( IsDebug() ) printf(" ou nevent %i rhev %i rtev %i \n",nevent,nrhev,nrtev); |
1119 |
TSYNC = runh->LAST_TIME_SYNC_INFO; |
// |
1120 |
OBT = runh->OBT_TIME_SYNC * 1000; |
if ( nrhev > 0 ){ |
1121 |
// |
for (Int_t i=0; i<nrhev; i++){ |
1122 |
TYPE = 20; |
// |
1123 |
// |
rh->GetEntry(i); |
1124 |
if ( TSYNC && OBT ){ |
// |
1125 |
existsts = true; |
TSYNC = runh->LAST_TIME_SYNC_INFO; |
1126 |
goto eout; |
OBT = runh->OBT_TIME_SYNC * 1000; |
1127 |
|
// |
1128 |
|
TYPE = 20; |
1129 |
|
// |
1130 |
|
if ( IsDebug() ) printf("runheader %i tsync %u obt %u \n",i,TSYNC,OBT); |
1131 |
|
// |
1132 |
|
if ( TSYNC && OBT ){ |
1133 |
|
existsts = true; |
1134 |
|
goto eout; |
1135 |
|
}; |
1136 |
}; |
}; |
1137 |
// |
// |
1138 |
}; |
}; |
1139 |
if ( rtev > 0 ){ |
if ( nrtev > 0 ){ |
1140 |
// |
// |
1141 |
if ( IsDebug() ) printf(" No runheader \n"); |
if ( IsDebug() ) printf(" No runheader \n"); |
1142 |
signal = 6; |
signal = 6; |
1143 |
// |
// |
1144 |
rt->GetEntry(0); |
for (Int_t i=0; i<nrtev; i++){ |
1145 |
// |
// |
1146 |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
rt->GetEntry(i); |
1147 |
OBT = runt->OBT_TYME_SYNC * 1000; |
// |
1148 |
// |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
1149 |
TYPE = 21; |
OBT = runt->OBT_TYME_SYNC * 1000; |
1150 |
// |
// |
1151 |
if ( TSYNC && OBT ){ |
TYPE = 21; |
1152 |
existsts = true; |
// |
1153 |
goto eout; |
if ( IsDebug() ) printf("runtrailer %i tsync %u obt %u \n",i,TSYNC,OBT); |
1154 |
|
// |
1155 |
|
if ( TSYNC && OBT ){ |
1156 |
|
existsts = true; |
1157 |
|
goto eout; |
1158 |
|
}; |
1159 |
}; |
}; |
1160 |
// |
// |
1161 |
} else { |
} else { |
1226 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
1227 |
if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str()); |
1228 |
// |
// |
1229 |
|
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
1230 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
1231 |
// |
// |
1232 |
|
tsync = TSYNC; |
1233 |
|
obt0 = OBT; |
1234 |
|
// |
1235 |
delete result; |
delete result; |
1236 |
return(signal); |
return(signal); |
1237 |
} |
} |
1331 |
VarDumpEvent *vde = 0; |
VarDumpEvent *vde = 0; |
1332 |
VarDumpRecord *vdr = 0; |
VarDumpRecord *vdr = 0; |
1333 |
// |
// |
1334 |
|
Bool_t found = false; |
1335 |
trDumpEv->SetBranchAddress("VarDump", &vde); |
trDumpEv->SetBranchAddress("VarDump", &vde); |
1336 |
if ( trDumpEv->GetEntries() > 0 ){ |
if ( trDumpEv->GetEntries() > 0 ){ |
1337 |
Bool_t found = false; |
found = false; |
1338 |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
1339 |
trDumpEv->GetEntry(i); |
trDumpEv->GetEntry(i); |
1340 |
vde->Records->GetEntries(); |
// vde->Records->GetEntries(); |
1341 |
if ( vde->Records->GetEntries()>0 ){ |
if ( vde->Records->GetEntries()>5 ){ |
1342 |
found = true; |
found = true; |
1343 |
goto fill; |
goto fill; |
1344 |
}; |
}; |
1351 |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
1352 |
// |
// |
1353 |
} else { |
} else { |
1354 |
if ( !this->GetBOOTnumber() ) return(4); |
if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(4); |
1355 |
|
}; |
1356 |
|
} else { |
1357 |
|
if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(2); |
1358 |
|
}; |
1359 |
|
// |
1360 |
|
UInt_t bn = 0; |
1361 |
|
Bool_t afound = false; |
1362 |
|
if ( !found && this->AutoBoot()){ |
1363 |
|
afound = true; |
1364 |
|
// |
1365 |
|
// Search for other files with similar timesync |
1366 |
|
// |
1367 |
|
if ( IsDebug() ) printf(" tsync %u obt0 %u \n",tsync,obt0); |
1368 |
|
UInt_t upperts = tsync-(obt0/1000)+5; |
1369 |
|
UInt_t lowerts = tsync-(obt0/1000)-5; |
1370 |
|
oss.str(""); |
1371 |
|
oss << "select GL_RAW.BOOT_NUMBER from GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW where TIMESYNC-(OBT0/1000)<" |
1372 |
|
<< upperts |
1373 |
|
<< " AND TIMESYNC-(OBT0/1000)>" |
1374 |
|
<< lowerts |
1375 |
|
<< " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;"; |
1376 |
|
result = conn->Query(oss.str().c_str()); |
1377 |
|
if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to find boot number:\n %s \n",oss.str().c_str()); |
1378 |
|
// |
1379 |
|
if ( !result ) throw -4;; |
1380 |
|
found = true; |
1381 |
|
if ( result->GetRowCount()<3 ){ |
1382 |
|
if ( IsDebug() ) printf(" AGH! no results!\n"); |
1383 |
|
found = false; |
1384 |
|
} else { |
1385 |
|
row = result->Next(); |
1386 |
|
bn = (UInt_t)atoll(row->GetField(0)); |
1387 |
|
for ( Int_t r=1; r<result->GetRowCount() ;r++){ |
1388 |
|
if ( !row ) throw -4; |
1389 |
|
if ( IsDebug() ) printf(" BOOT number is %s \n",row->GetField(0)); |
1390 |
|
if ( bn != (UInt_t)atoll(row->GetField(0)) ){ |
1391 |
|
if ( IsDebug() ) printf(" AGH! bn = %u here instead %u \n",bn,(UInt_t)atoll(row->GetField(0))); |
1392 |
|
found = false; |
1393 |
|
}; |
1394 |
|
row = result->Next(); |
1395 |
|
}; |
1396 |
}; |
}; |
1397 |
|
}; |
1398 |
|
// |
1399 |
|
Int_t sgn = 0; |
1400 |
|
// |
1401 |
|
if ( !found && !BOOTNO ){ |
1402 |
|
throw -29; |
1403 |
} else { |
} else { |
1404 |
if ( !this->GetBOOTnumber() ) return(2); |
if ( afound ){ |
1405 |
|
this->SetBOOTnumber(bn); |
1406 |
|
sgn = 8; |
1407 |
|
}; |
1408 |
}; |
}; |
1409 |
// |
// |
1410 |
oss.str(""); |
oss.str(""); |
1414 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
1415 |
// |
// |
1416 |
delete result; |
delete result; |
1417 |
return(0); |
return(sgn); |
1418 |
}; |
}; |
1419 |
|
|
1420 |
/** |
/** |
1677 |
if ( glrun->GetNEVENTS() > (UInt_t)atoll(row->GetField(1)) ){ |
if ( glrun->GetNEVENTS() > (UInt_t)atoll(row->GetField(1)) ){ |
1678 |
// |
// |
1679 |
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"); |
1680 |
oss.str(""); |
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
1681 |
oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
// oss.str(""); |
1682 |
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) <<";"; |
1683 |
conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
1684 |
|
// conn->Query(oss.str().c_str()); |
1685 |
if ( signal ) signal = false; |
if ( signal ) signal = false; |
1686 |
goto gonext; |
goto gonext; |
1687 |
// |
// |
1695 |
// |
// |
1696 |
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"); |
1697 |
// |
// |
1698 |
oss.str(""); |
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
1699 |
oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
// oss.str(""); |
1700 |
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) <<";"; |
1701 |
conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
1702 |
|
// conn->Query(oss.str().c_str()); |
1703 |
// |
// |
1704 |
if ( signal ) signal = false; |
if ( signal ) signal = false; |
1705 |
goto gonext; |
goto gonext; |
1713 |
// |
// |
1714 |
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"); |
1715 |
// |
// |
1716 |
oss.str(""); |
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
1717 |
oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; |
// oss.str(""); |
1718 |
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) <<";"; |
1719 |
conn->Query(oss.str().c_str()); |
// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); |
1720 |
|
// conn->Query(oss.str().c_str()); |
1721 |
if ( signal ) signal = false; |
if ( signal ) signal = false; |
1722 |
// |
// |
1723 |
}; |
}; |
1732 |
delete result; |
delete result; |
1733 |
// |
// |
1734 |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
1735 |
|
if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n"); |
1736 |
return(signal); |
return(signal); |
1737 |
}; |
}; |
1738 |
|
|
1754 |
// |
// |
1755 |
this->FillClass(); |
this->FillClass(); |
1756 |
// |
// |
1757 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
1758 |
|
glrun->SetID(this->AssignRunID()); |
1759 |
|
glrun->SetID_RUN_FRAG(0); |
1760 |
|
glrun->Fill_GL_RUN(conn); |
1761 |
|
}; |
1762 |
} else { |
} else { |
1763 |
// |
// |
1764 |
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); |
1781 |
UInt_t rhfirstev = firstev; |
UInt_t rhfirstev = firstev; |
1782 |
UInt_t rtlastev = lastev; |
UInt_t rtlastev = lastev; |
1783 |
Bool_t found = false; |
Bool_t found = false; |
1784 |
|
Bool_t foundinrun = false; |
1785 |
// |
// |
1786 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1787 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1808 |
// |
// |
1809 |
if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); |
if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); |
1810 |
// |
// |
1811 |
|
// First of all insert the run in the fragment table... |
1812 |
|
// |
1813 |
|
oss.str(""); |
1814 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE " |
1815 |
|
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" |
1816 |
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
1817 |
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
1818 |
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
1819 |
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
1820 |
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
1821 |
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
1822 |
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
1823 |
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
1824 |
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
1825 |
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
1826 |
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
1827 |
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
1828 |
|
// |
1829 |
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
1830 |
|
result = conn->Query(oss.str().c_str()); |
1831 |
|
// |
1832 |
|
if ( !result ) throw -4; |
1833 |
|
// |
1834 |
|
row = result->Next(); |
1835 |
|
// |
1836 |
|
if ( !row ){ |
1837 |
|
// |
1838 |
|
// no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!) |
1839 |
|
// |
1840 |
|
if ( IsDebug() ) printf(" The run is new \n"); |
1841 |
|
if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); |
1842 |
|
// |
1843 |
|
glrun->SetID(this->AssignRunID()); |
1844 |
|
glrun->SetID_RUN_FRAG(0); |
1845 |
|
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
1846 |
|
// |
1847 |
|
} else { |
1848 |
|
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
1849 |
|
return; |
1850 |
|
}; |
1851 |
|
// |
1852 |
|
// |
1853 |
// can we find the other piece of the run in the GL_RUN_FRAGMENTS table? |
// can we find the other piece of the run in the GL_RUN_FRAGMENTS table? |
1854 |
// |
// |
1855 |
if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is |
if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is |
1858 |
oss.str(""); |
oss.str(""); |
1859 |
oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE " |
oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE " |
1860 |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
1861 |
<< " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() |
<< " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
1862 |
|
<< " ID != " << glrun->ID |
1863 |
<< " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! |
<< " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! |
1864 |
// |
// |
1865 |
if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str()); |
1869 |
// |
// |
1870 |
row = result->Next(); |
row = result->Next(); |
1871 |
// |
// |
1872 |
|
if ( !row && NoFrag() ){ |
1873 |
|
// |
1874 |
|
oss.str(""); |
1875 |
|
oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN WHERE " |
1876 |
|
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
1877 |
|
<< " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
1878 |
|
<< " ID != " << glrun->ID |
1879 |
|
<< " AND ID=ID_RUN_FRAG ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! |
1880 |
|
// |
1881 |
|
if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); |
1882 |
|
result = conn->Query(oss.str().c_str()); |
1883 |
|
// |
1884 |
|
if ( !result ) throw -4; |
1885 |
|
// |
1886 |
|
foundinrun = true; |
1887 |
|
// |
1888 |
|
row = result->Next(); |
1889 |
|
// |
1890 |
|
}; |
1891 |
|
// |
1892 |
if ( !row ){ |
if ( !row ){ |
1893 |
if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); |
if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); |
1894 |
found = false; |
found = false; |
1963 |
// |
// |
1964 |
if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); |
if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); |
1965 |
// |
// |
1966 |
|
if ( foundinrun ){ |
1967 |
|
glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); |
1968 |
|
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
1969 |
|
}; |
1970 |
|
// |
1971 |
GL_RUN *glrun1 = new GL_RUN(); |
GL_RUN *glrun1 = new GL_RUN(); |
1972 |
// |
// |
1973 |
UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); |
// UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); |
1974 |
// |
// |
1975 |
oss.str(""); |
oss.str(""); |
1976 |
oss << " ID="<<row->GetField(0)<<";"; |
oss << " ID="<<row->GetField(0)<<";"; |
1999 |
}; |
}; |
2000 |
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); |
2001 |
// |
// |
|
glrun1->SetID(0); |
|
2002 |
glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); |
glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); |
2003 |
glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); |
glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); |
2004 |
glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); |
glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); |
2007 |
// |
// |
2008 |
glrun->SetEV_FROM(firstev); |
glrun->SetEV_FROM(firstev); |
2009 |
glrun->SetNEVENTS(lastev-firstev+1); |
glrun->SetNEVENTS(lastev-firstev+1); |
2010 |
|
// |
2011 |
glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); |
glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); |
2012 |
glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT()); |
glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT()); |
2013 |
glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT()); |
glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT()); |
2027 |
// |
// |
2028 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
2029 |
// |
// |
2030 |
|
// glrun->SetID(this->AssignRunID()); |
2031 |
|
glrun->SetID_RUN_FRAG(glrun1->GetID()); |
2032 |
glrun->Fill_GL_RUN(conn); |
glrun->Fill_GL_RUN(conn); |
2033 |
// |
// |
2034 |
// get id number |
// set id number |
|
// |
|
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND " |
|
|
<< " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND " |
|
|
<< " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); |
|
|
// |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
if ( !result ) throw -4; |
|
|
row = result->Next(); |
|
|
// |
|
|
UInt_t idrun0 = 0; |
|
|
if ( !row ){ |
|
|
throw -10; |
|
|
} else { |
|
|
idrun0 = (UInt_t)atoll(row->GetField(0)); |
|
|
}; |
|
|
// |
|
|
glrun1->SetID_RUN_FRAG(idrun0); |
|
2035 |
// |
// |
2036 |
|
glrun1->SetID_RUN_FRAG(glrun->GetID()); |
2037 |
glrun1->Fill_GL_RUN(conn); |
glrun1->Fill_GL_RUN(conn); |
2038 |
// |
// |
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str()); |
|
|
// |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
if ( !result ) throw -4; |
|
|
row = result->Next(); |
|
|
// |
|
|
UInt_t idrun1 = 0; |
|
|
if ( !row ){ |
|
|
throw -10; |
|
|
} else { |
|
|
idrun1 = (UInt_t)atoll(row->GetField(0)); |
|
|
}; |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;"; |
|
|
// |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
if ( !result ) throw -4; |
|
|
// |
|
2039 |
}; |
}; |
|
// |
|
|
delete glrun1; |
|
|
// |
|
2040 |
// delete old entry in fragment table |
// delete old entry in fragment table |
2041 |
// |
// |
2042 |
oss.str(""); |
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
2043 |
|
glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
2044 |
// |
// |
2045 |
oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; |
delete glrun1; |
2046 |
// |
// |
|
if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
if ( !result ) throw -4; |
|
2047 |
// |
// |
2048 |
return; |
return; |
2049 |
// |
// |
2052 |
}; |
}; |
2053 |
// |
// |
2054 |
if ( mistrail && rtlastev == lastev ) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is |
if ( mistrail && rtlastev == lastev ) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is |
2055 |
// missing it no way we can found a piece in the frag table |
// missing it no way we can found a piece in the frag table |
2056 |
// |
// |
2057 |
oss.str(""); |
oss.str(""); |
2058 |
oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE " |
oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE " |
2059 |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
2060 |
<< " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() |
<< " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND " |
2061 |
|
<< " ID != " << glrun->ID |
2062 |
<< " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; |
<< " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; |
2063 |
// |
// |
2064 |
if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str()); |
2068 |
// |
// |
2069 |
row = result->Next(); |
row = result->Next(); |
2070 |
// |
// |
2071 |
|
if ( !row && NoFrag() ){ |
2072 |
|
// |
2073 |
|
oss.str(""); |
2074 |
|
oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN WHERE " |
2075 |
|
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
2076 |
|
<< " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND " |
2077 |
|
<< " ID != " << glrun->ID |
2078 |
|
<< " AND ID=ID_RUN_FRAG ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; |
2079 |
|
// |
2080 |
|
if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); |
2081 |
|
result = conn->Query(oss.str().c_str()); |
2082 |
|
// |
2083 |
|
if ( !result ) throw -4; |
2084 |
|
// |
2085 |
|
foundinrun = true; |
2086 |
|
row = result->Next(); |
2087 |
|
// |
2088 |
|
}; |
2089 |
|
// |
2090 |
if ( !row ){ |
if ( !row ){ |
2091 |
if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); |
if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); |
2092 |
found = false; |
found = false; |
2160 |
// |
// |
2161 |
if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); |
if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); |
2162 |
// |
// |
2163 |
|
if ( foundinrun ){ |
2164 |
|
glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); |
2165 |
|
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
2166 |
|
}; |
2167 |
|
// |
2168 |
GL_RUN *glrun1 = new GL_RUN(); |
GL_RUN *glrun1 = new GL_RUN(); |
2169 |
// |
// |
2170 |
UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); |
// UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); |
2171 |
// |
// |
2172 |
oss.str(""); |
oss.str(""); |
2173 |
oss << " ID="<<row->GetField(0)<<";"; |
oss << " ID="<<row->GetField(0)<<";"; |
2204 |
glrun->SetRUNTRAILER_OBT(glrun1->GetRUNTRAILER_OBT()); |
glrun->SetRUNTRAILER_OBT(glrun1->GetRUNTRAILER_OBT()); |
2205 |
glrun->SetRUNTRAILER_PKT(glrun1->GetRUNTRAILER_PKT()); |
glrun->SetRUNTRAILER_PKT(glrun1->GetRUNTRAILER_PKT()); |
2206 |
// |
// |
|
glrun1->SetID(0); |
|
2207 |
glrun1->SetRUNHEADER_TIME(glrun->GetRUNHEADER_TIME()); |
glrun1->SetRUNHEADER_TIME(glrun->GetRUNHEADER_TIME()); |
2208 |
glrun1->SetRUNHEADER_OBT(glrun->GetRUNHEADER_OBT()); |
glrun1->SetRUNHEADER_OBT(glrun->GetRUNHEADER_OBT()); |
2209 |
glrun1->SetRUNHEADER_PKT(glrun->GetRUNHEADER_PKT()); |
glrun1->SetRUNHEADER_PKT(glrun->GetRUNHEADER_PKT()); |
2223 |
// |
// |
2224 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
2225 |
// |
// |
2226 |
glrun->Fill_GL_RUN(conn); |
// glrun->SetID(this->AssignRunID()); |
|
// |
|
|
// get id number |
|
2227 |
// |
// |
2228 |
oss.str(""); |
glrun->SetID_RUN_FRAG(glrun1->GetID()); |
2229 |
oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND " |
glrun->Fill_GL_RUN(conn); |
|
<< " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND " |
|
|
<< " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); |
|
|
// |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
if ( !result ) throw -4; |
|
|
row = result->Next(); |
|
|
// |
|
|
UInt_t idrun0 = 0; |
|
|
if ( !row ){ |
|
|
throw -10; |
|
|
} else { |
|
|
idrun0 = (UInt_t)atoll(row->GetField(0)); |
|
|
}; |
|
2230 |
// |
// |
2231 |
glrun1->SetID_RUN_FRAG(idrun0); |
// set id number |
2232 |
// |
// |
2233 |
|
glrun1->SetID_RUN_FRAG(glrun->GetID()); |
2234 |
glrun1->Fill_GL_RUN(conn); |
glrun1->Fill_GL_RUN(conn); |
2235 |
// |
// |
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str()); |
|
|
// |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
if ( !result ) throw -4; |
|
|
row = result->Next(); |
|
|
// |
|
|
UInt_t idrun1 = 0; |
|
|
if ( !row ){ |
|
|
throw -10; |
|
|
} else { |
|
|
idrun1 = (UInt_t)atoll(row->GetField(0)); |
|
|
}; |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;"; |
|
|
// |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
if ( !result ) throw -4; |
|
|
// |
|
2236 |
}; |
}; |
2237 |
// |
// |
2238 |
delete glrun1; |
// delete old entries in fragment table |
|
// |
|
|
// delete old entry in fragment table |
|
|
// |
|
|
oss.str(""); |
|
|
// |
|
|
oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; |
|
2239 |
// |
// |
2240 |
if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); |
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
2241 |
result = conn->Query(oss.str().c_str()); |
glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
|
if ( !result ) throw -4; |
|
2242 |
// |
// |
2243 |
|
delete glrun1; |
2244 |
// |
// |
2245 |
return; |
return; |
2246 |
// |
// |
2277 |
// |
// |
2278 |
row = result->Next(); |
row = result->Next(); |
2279 |
// |
// |
2280 |
if ( !row ){ |
if ( row ){ |
|
// |
|
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE " |
|
|
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" |
|
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
|
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
|
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
|
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
|
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
|
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
|
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
|
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
|
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
|
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
|
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
|
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -4; |
|
|
// |
|
|
row = result->Next(); |
|
|
// |
|
|
if ( !row ){ |
|
|
// |
|
|
// no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!) |
|
|
// |
|
|
if ( IsDebug() ) printf(" The run is new \n"); |
|
|
if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); |
|
|
// |
|
|
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
|
|
// |
|
|
} else { |
|
|
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
|
|
}; |
|
|
} else { |
|
2281 |
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
2282 |
|
} else { |
2283 |
|
if ( NoFrag() ){ |
2284 |
|
glrun->SetID_RUN_FRAG(glrun->GetID()); |
2285 |
|
glrun->Fill_GL_RUN(conn); |
2286 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
2287 |
|
}; |
2288 |
}; |
}; |
2289 |
}; |
}; |
2290 |
// |
// |
2310 |
// |
// |
2311 |
this->FillClass(mishead,mistrail,firstev,lastev); |
this->FillClass(mishead,mistrail,firstev,lastev); |
2312 |
// |
// |
2313 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2314 |
|
glrun->SetID(this->AssignRunID()); |
2315 |
|
glrun->SetID_RUN_FRAG(0); |
2316 |
|
glrun->Fill_GL_RUN(conn); |
2317 |
|
}; |
2318 |
// |
// |
2319 |
}; |
}; |
2320 |
// |
// |
2481 |
// |
// |
2482 |
this->SetCommonGLRUN(firstTime,lastTime); |
this->SetCommonGLRUN(firstTime,lastTime); |
2483 |
// |
// |
2484 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2485 |
|
glrun->SetID(this->AssignRunID()); |
2486 |
|
glrun->SetID_RUN_FRAG(0); |
2487 |
|
glrun->Fill_GL_RUN(conn); |
2488 |
|
}; |
2489 |
// |
// |
2490 |
firstevno = lastentry + 1; |
firstevno = lastentry + 1; |
2491 |
// |
// |
2561 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
2562 |
// |
// |
2563 |
this->FillClass(); |
this->FillClass(); |
2564 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2565 |
|
glrun->SetID(this->AssignRunID()); |
2566 |
|
glrun->SetID_RUN_FRAG(0); |
2567 |
|
glrun->Fill_GL_RUN(conn); |
2568 |
|
}; |
2569 |
// |
// |
2570 |
} else { |
} else { |
2571 |
// |
// |
2593 |
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"); |
2594 |
// |
// |
2595 |
this->FillClass(); |
this->FillClass(); |
2596 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2597 |
|
glrun->SetID(this->AssignRunID()); |
2598 |
|
glrun->SetID_RUN_FRAG(0); |
2599 |
|
glrun->Fill_GL_RUN(conn); |
2600 |
|
}; |
2601 |
// |
// |
2602 |
} else { |
} else { |
2603 |
// |
// |
2695 |
// |
// |
2696 |
this->SetCommonGLRUN(firstTime,lastTime); |
this->SetCommonGLRUN(firstTime,lastTime); |
2697 |
// |
// |
2698 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2699 |
|
glrun->SetID(this->AssignRunID()); |
2700 |
|
glrun->SetID_RUN_FRAG(0); |
2701 |
|
glrun->Fill_GL_RUN(conn); |
2702 |
|
}; |
2703 |
// |
// |
2704 |
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... |
2705 |
// |
// |
2734 |
// |
// |
2735 |
this->SetCommonGLRUN(firstTime,lastTime); |
this->SetCommonGLRUN(firstTime,lastTime); |
2736 |
// |
// |
2737 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ){ |
2738 |
|
glrun->SetID(this->AssignRunID()); |
2739 |
|
glrun->SetID_RUN_FRAG(0); |
2740 |
|
glrun->Fill_GL_RUN(conn); |
2741 |
|
}; |
2742 |
}; |
}; |
2743 |
// |
// |
2744 |
firstevno = lastentry + 1; |
firstevno = lastentry + 1; |
2845 |
// no calibrations in the db contain our calibration |
// no calibrations in the db contain our calibration |
2846 |
// |
// |
2847 |
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB for section %i \n",section); |
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB for section %i \n",section); |
2848 |
if ( fromtime < 1150863400 ){ |
if ( fromtime < 1150871000 ){ //1150866904 |
2849 |
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime); |
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime); |
2850 |
fromtime = 0;// the first flight calibration was taken at about 1156429100 s, this line allow to analyze first runs in raw mode |
fromtime = 0;// the first flight calibration was taken at about 1156429100 s, this line allow to analyze first runs in raw mode |
2851 |
}; |
}; |
2990 |
// no calibrations in the db contain our calibration |
// no calibrations in the db contain our calibration |
2991 |
// |
// |
2992 |
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); |
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); |
2993 |
if ( fromtime < 1150863400 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode |
if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode |
2994 |
// |
// |
2995 |
oss.str(""); |
oss.str(""); |
2996 |
oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " |
oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " |
3119 |
pkt1 = ph1->GetCounter(); |
pkt1 = ph1->GetCounter(); |
3120 |
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
3121 |
// |
// |
3122 |
valid = 1; |
// valid = 1; |
3123 |
// |
// // |
3124 |
if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
// if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
3125 |
// |
// |
3126 |
// |
// |
3127 |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
3128 |
// |
// |
3129 |
if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); |
if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); |
3130 |
|
// |
3131 |
|
valid = ValidateTrkCalib( caltrk1, eh1 ); |
3132 |
|
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
3133 |
// |
// |
3134 |
// Do we have the second calibration packet? |
// Do we have the second calibration packet? |
3135 |
// |
// |
3146 |
obt2 = ph2->GetOrbitalTime(); |
obt2 = ph2->GetOrbitalTime(); |
3147 |
pkt2 = ph2->GetCounter(); |
pkt2 = ph2->GetCounter(); |
3148 |
// |
// |
3149 |
if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
3150 |
// |
// |
3151 |
} else { |
} else { |
3152 |
// |
// |
3177 |
// |
// |
3178 |
if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2); |
if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2); |
3179 |
// |
// |
3180 |
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
3181 |
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
3182 |
|
valid = valid & valid2; |
3183 |
|
// |
3184 |
// Handle good calib |
// Handle good calib |
3185 |
// |
// |
3186 |
this->HandleTRK_CALIB(true,true); |
this->HandleTRK_CALIB(true,true); |
3353 |
// no calibrations in the db contain our calibration |
// no calibrations in the db contain our calibration |
3354 |
// |
// |
3355 |
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB \n"); |
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB \n"); |
3356 |
if ( fromtime < 1150863400 ){ |
if ( fromtime < 1150871000 ){ |
3357 |
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime); |
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime); |
3358 |
fromtime = 0;// the first flight calibration was taken at about 1156429100 s, this line allow to analyze first runs in raw mode |
fromtime = 0;// the first flight calibration was taken at about 1156429100 s, this line allow to analyze first runs in raw mode |
3359 |
}; |
}; |
3426 |
* Scan the fragment table and move old fragments to the GL_RUN table |
* Scan the fragment table and move old fragments to the GL_RUN table |
3427 |
*/ |
*/ |
3428 |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
3429 |
|
return(this->CleanGL_RUN_FRAGMENTS("")); |
3430 |
|
}; |
3431 |
|
|
3432 |
|
/** |
3433 |
|
* Scan the fragment table and move old fragments to the GL_RUN table |
3434 |
|
*/ |
3435 |
|
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(TString fcleanfile){ |
3436 |
// |
// |
3437 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
3438 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
3440 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
3441 |
// |
// |
3442 |
UInt_t moved = 0; |
UInt_t moved = 0; |
|
UInt_t timelim = 0; |
|
|
TDatime *time = new TDatime(); |
|
3443 |
// |
// |
3444 |
stringstream oss; |
stringstream oss; |
3445 |
oss.str(""); |
oss.str(""); |
3446 |
// |
// |
3447 |
// |
if ( !strcmp(fcleanfile.Data(),"") ){ |
3448 |
// |
// |
3449 |
if ( olderthan < 0 ){ |
// check if there are entries older than "olderthan" seconds from now |
3450 |
if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n"); |
// |
3451 |
return(1); |
oss.str(""); |
3452 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3453 |
|
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
3454 |
|
// |
3455 |
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
3456 |
|
result = conn->Query(oss.str().c_str()); |
3457 |
|
// |
3458 |
|
} else { |
3459 |
|
oss.str(""); |
3460 |
|
oss << " SELECT ID FROM GL_ROOT WHERE NAME='" << fcleanfile.Data() << "';"; |
3461 |
|
if ( IsDebug() ) printf(" Getting ID_ROOT_L0 query %s \n",oss.str().c_str()); |
3462 |
|
result = conn->Query(oss.str().c_str()); |
3463 |
|
// |
3464 |
|
if ( result ){ |
3465 |
|
// |
3466 |
|
row = result->Next(); |
3467 |
|
// |
3468 |
|
if ( row ){ |
3469 |
|
oss.str(""); |
3470 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3471 |
|
<< " ID_ROOT_L0=" << row->GetField(0) << ";"; |
3472 |
|
// |
3473 |
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS for ROOT file query is \n %s \n",oss.str().c_str()); |
3474 |
|
result = conn->Query(oss.str().c_str()); |
3475 |
|
// |
3476 |
|
}; |
3477 |
|
} else { |
3478 |
|
return(2); |
3479 |
|
}; |
3480 |
}; |
}; |
3481 |
// |
// |
|
// timelim = now - olderthan |
|
|
// |
|
|
time->Set(); |
|
|
timelim = (UInt_t)time->Convert() - olderthan; |
|
|
time->Set(timelim,false); |
|
|
// |
|
|
// check if there are entries older than "olderthan" seconds from now |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
|
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
3482 |
if ( result ){ |
if ( result ){ |
3483 |
// |
// |
3484 |
row = result->Next(); |
row = result->Next(); |
3485 |
// |
// |
3486 |
if ( row ){ |
while ( row ){ |
3487 |
// |
// |
3488 |
oss.str(""); |
oss.str(""); |
3489 |
oss << " ID= "<< row->GetField(0); |
oss << " ID= "<< row->GetField(0); |
3518 |
if ( IsDebug() ) printf(" The run is new \n"); |
if ( IsDebug() ) printf(" The run is new \n"); |
3519 |
if ( IsDebug() ) printf(" -> fill the DB \n"); |
if ( IsDebug() ) printf(" -> fill the DB \n"); |
3520 |
// |
// |
3521 |
glrun->SetID(0); |
// glrun->SetID(this->AssignRunID()); we use the old run number! |
3522 |
|
glrun->SetID_RUN_FRAG(glrun->GetID()); |
3523 |
glrun->Fill_GL_RUN(conn); |
glrun->Fill_GL_RUN(conn); |
3524 |
// |
// |
3525 |
oss.str(""); |
// oss.str(""); |
3526 |
oss << " SELECT ID FROM GL_RUN WHERE " |
// oss << " SELECT ID FROM GL_RUN WHERE " |
3527 |
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
// << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
3528 |
<< " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
// << " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
3529 |
<< " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
// << " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
3530 |
<< " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
// << " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
3531 |
<< " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
// << " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
3532 |
// |
// // |
3533 |
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()); |
3534 |
result2 = conn->Query(oss.str().c_str()); |
// result2 = conn->Query(oss.str().c_str()); |
3535 |
// |
// // |
3536 |
if ( !result2 ) throw -4; |
// if ( !result2 ) throw -4; |
3537 |
// |
// // |
3538 |
row2 = result2->Next(); |
// row2 = result2->Next(); |
3539 |
// |
// // |
3540 |
if ( !row2 ) throw -25; |
// if ( !row2 ) throw -25; |
3541 |
// |
// // |
3542 |
oss.str(""); |
// oss.str(""); |
3543 |
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); |
3544 |
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()); |
3545 |
result2 = conn->Query(oss.str().c_str()); |
// result2 = conn->Query(oss.str().c_str()); |
3546 |
// |
// // |
3547 |
if ( !result2 ) throw -4; |
// if ( !result2 ) throw -4; |
3548 |
// |
// |
3549 |
moved++; |
moved++; |
3550 |
// |
// |
3554 |
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)); |
3555 |
// |
// |
3556 |
// |
// |
3557 |
oss.str(""); |
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); |
3558 |
oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); |
// oss.str(""); |
3559 |
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); |
3560 |
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()); |
3561 |
// |
// result2 = conn->Query(oss.str().c_str()); |
3562 |
if ( !result2 ) throw -4; |
// // |
3563 |
// |
// if ( !result2 ) throw -4; |
3564 |
|
// // |
3565 |
|
row = result->Next(); |
3566 |
}; |
}; |
3567 |
}; |
}; |
3568 |
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
3573 |
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
3574 |
*/ |
*/ |
3575 |
Int_t PamelaDBOperations::ValidateRuns(){ |
Int_t PamelaDBOperations::ValidateRuns(){ |
3576 |
|
return(this->ValidateRuns("")); |
3577 |
|
}; |
3578 |
|
|
3579 |
|
/** |
3580 |
|
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
3581 |
|
*/ |
3582 |
|
Int_t PamelaDBOperations::ValidateRuns(TString valfile){ |
3583 |
// |
// |
3584 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
3585 |
// TSQLRow *row = 0; |
TSQLRow *row = 0; |
3586 |
// |
// |
3587 |
UInt_t timelim = 0; |
UInt_t calibtime = 50; |
|
TDatime *time = new TDatime(); |
|
3588 |
// |
// |
3589 |
stringstream oss; |
stringstream oss; |
3590 |
oss.str(""); |
oss.str(""); |
3591 |
// |
// |
3592 |
|
// ======================================================= |
3593 |
|
// validate runs by checking missing calibrations |
3594 |
|
// ======================================================= |
3595 |
|
UInt_t t_stop = 0; |
3596 |
|
UInt_t t_start = 0; |
3597 |
|
if ( !strcmp(valfile.Data(),"") ) { |
3598 |
|
// -------------------------------------------------------------- |
3599 |
|
// 1) get the OBT of the last run inserted after clean-time limit |
3600 |
|
// -------------------------------------------------------------- |
3601 |
|
oss.str(""); |
3602 |
|
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
3603 |
|
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3604 |
|
if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
3605 |
|
result = conn->Query(oss.str().c_str()); |
3606 |
|
if ( !result ) throw -4; |
3607 |
|
if ( !result->GetRowCount() ) { |
3608 |
|
printf(" No runs to validate \n"); |
3609 |
|
return(1); |
3610 |
|
}else{ |
3611 |
|
row = result->Next(); |
3612 |
|
t_start = (UInt_t)atoll(row->GetField(4)); |
3613 |
|
}; |
3614 |
|
// -------------------------------------------------------------- |
3615 |
|
// 2) get the OBT of the last validated run |
3616 |
|
// -------------------------------------------------------------- |
3617 |
|
oss.str(""); |
3618 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
3619 |
|
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3620 |
|
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
3621 |
|
result = conn->Query(oss.str().c_str()); |
3622 |
|
if ( !result ) throw -4; |
3623 |
|
if ( result->GetRowCount() ){ |
3624 |
|
row = result->Next(); |
3625 |
|
t_stop = (UInt_t)atoll(row->GetField(4)); |
3626 |
|
}; |
3627 |
|
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
3628 |
|
// -------------------------------------------------------------- |
3629 |
|
// now retrieves runs to be validated |
3630 |
|
// -------------------------------------------------------------- |
3631 |
|
oss.str(""); |
3632 |
|
oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; |
3633 |
|
oss << " AND RUNHEADER_TIME >="<< t_stop; |
3634 |
|
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
3635 |
|
if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
3636 |
|
result = conn->Query(oss.str().c_str()); |
3637 |
|
} else { |
3638 |
|
// |
3639 |
|
stringstream myquery; |
3640 |
|
UInt_t myid = 0; |
3641 |
|
myquery.str(""); |
3642 |
|
myquery << " SELECT ID FROM GL_ROOT where NAME='"<<valfile.Data() <<"';"; |
3643 |
|
// |
3644 |
|
result = conn->Query(myquery.str().c_str()); |
3645 |
|
// |
3646 |
|
row = result->Next(); |
3647 |
|
if( !row ){ |
3648 |
|
if ( strcmp(valfile.Data(),GetRootName().Data()) ){ |
3649 |
|
if ( IsDebug() ) printf(" No file to be validated even if option \"-validate file\" was used!!\n"); |
3650 |
|
return(2); |
3651 |
|
}; |
3652 |
|
if ( IsDebug() ) printf(" No file to be validated (force mode)! \n"); |
3653 |
|
return(0); |
3654 |
|
}; |
3655 |
|
myid=(UInt_t)atoll(row->GetField(0)); |
3656 |
|
// |
3657 |
|
myquery.str(""); |
3658 |
|
myquery << " SELECT MAX(RUNTRAILER_TIME),MIN(RUNHEADER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< myid <<";"; |
3659 |
|
// |
3660 |
|
result = conn->Query(myquery.str().c_str()); |
3661 |
|
// |
3662 |
|
row = result->Next(); |
3663 |
|
if( !row->GetField(0) || !row->GetField(1)){ |
3664 |
|
// |
3665 |
|
if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n"); |
3666 |
|
// |
3667 |
|
return(0); |
3668 |
|
// |
3669 |
|
} else { |
3670 |
|
// |
3671 |
|
UInt_t runhtime = (UInt_t)atoll(row->GetField(0)); |
3672 |
|
UInt_t runttime = (UInt_t)atoll(row->GetField(1)); |
3673 |
|
UInt_t caltime = 0; |
3674 |
|
// |
3675 |
|
myquery.str(""); |
3676 |
|
myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <<runhtime; |
3677 |
|
myquery << " order by FROM_TIME asc limit 1;"; |
3678 |
|
// |
3679 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
3680 |
|
// |
3681 |
|
// |
3682 |
|
result = conn->Query(myquery.str().c_str()); |
3683 |
|
// |
3684 |
|
row = result->Next(); |
3685 |
|
if( !row ){ |
3686 |
|
caltime = runhtime; |
3687 |
|
} else { |
3688 |
|
caltime = (UInt_t)atoll(row->GetField(0)); |
3689 |
|
}; |
3690 |
|
// |
3691 |
|
myquery.str(""); |
3692 |
|
myquery << " SELECT * from GL_RUN where RUNHEADER_TIME>="<< runttime <<" AND RUNHEADER_TIME<=" ; |
3693 |
|
myquery << caltime << " order by RUNHEADER_TIME DESC"; |
3694 |
|
// |
3695 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
3696 |
|
// |
3697 |
|
result = conn->Query(myquery.str().c_str()); |
3698 |
|
// |
3699 |
|
}; |
3700 |
|
}; |
3701 |
// |
// |
3702 |
|
if ( !result ) throw -4; |
3703 |
|
if ( !result->GetRowCount() && IsDebug() ) printf(" No runs to validate \n"); |
3704 |
// |
// |
3705 |
if ( olderthan < 0 ){ |
Int_t nrow = 0; |
3706 |
if ( IsDebug() ) printf(" Do not validate runs \n"); |
GL_RUN* this_run = new GL_RUN(); |
3707 |
return(1); |
GL_RUN* next_run = new GL_RUN(); |
3708 |
|
Int_t nseq_max = 1000; |
3709 |
|
// UInt_t* sequence = new UInt_t[100]; |
3710 |
|
vector<UInt_t> sequence(nseq_max); |
3711 |
|
Int_t nseq = 0; |
3712 |
|
Bool_t CHECK = false; |
3713 |
|
Bool_t this_ONLINE = false; |
3714 |
|
Bool_t next_ONLINE = false; |
3715 |
|
UInt_t t1=0,t2=0; |
3716 |
|
// --------------------------------------------------------------------------------- |
3717 |
|
// - loop over runs, back in time, |
3718 |
|
// - select sequences of runs close in time (less than calibtime s apart), |
3719 |
|
// which could be preceeded by a calibration |
3720 |
|
// - check if there might be a missing calibration |
3721 |
|
// --------------------------------------------------------------------------------- |
3722 |
|
while(1){ |
3723 |
|
|
3724 |
|
row = result->Next(); |
3725 |
|
if( row == NULL ) break; |
3726 |
|
|
3727 |
|
//------------ |
3728 |
|
//get run info |
3729 |
|
//------------ |
3730 |
|
this_run->Set_GL_RUN(row); |
3731 |
|
|
3732 |
|
Bool_t this_BAD = false; |
3733 |
|
if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; |
3734 |
|
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
3735 |
|
else{ |
3736 |
|
// printf("Missing or corrupted header!! \n"); |
3737 |
|
this_ONLINE = false; |
3738 |
|
this_BAD = true; |
3739 |
|
}; |
3740 |
|
|
3741 |
|
//----------------------------------- |
3742 |
|
//compare with previous(next in time) |
3743 |
|
//----------------------------------- |
3744 |
|
CHECK = false; |
3745 |
|
UInt_t interval=0; |
3746 |
|
|
3747 |
|
if( nrow != 0){ |
3748 |
|
|
3749 |
|
|
3750 |
|
t1 = this_run->GetRUNTRAILER_TIME(); |
3751 |
|
t2 = next_run->GetRUNHEADER_TIME(); |
3752 |
|
interval = (t2-t1); |
3753 |
|
|
3754 |
|
if(this_ONLINE && next_ONLINE){ // this: ON-LINE + next: ON-LINE |
3755 |
|
|
3756 |
|
if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments |
3757 |
|
|
3758 |
|
if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration |
3759 |
|
|
3760 |
|
if( !CHECK && this_run->VALIDATION ){ |
3761 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
3762 |
|
nseq=0; |
3763 |
|
} |
3764 |
|
|
3765 |
|
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
3766 |
|
|
3767 |
|
CHECK = true; |
3768 |
|
|
3769 |
|
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
3770 |
|
|
3771 |
|
assignVALIDATION(next_run->ID,true); |
3772 |
|
nseq=0; |
3773 |
|
} |
3774 |
|
} |
3775 |
|
|
3776 |
|
//---------------------------- |
3777 |
|
//check run sequence for calib |
3778 |
|
//---------------------------- |
3779 |
|
if( CHECK ){ |
3780 |
|
// check if calibration exists |
3781 |
|
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
3782 |
|
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
3783 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
3784 |
|
nseq=0; |
3785 |
|
}; |
3786 |
|
//-------------- |
3787 |
|
//store run info |
3788 |
|
//-------------- |
3789 |
|
*next_run = *this_run; |
3790 |
|
next_ONLINE = this_ONLINE; |
3791 |
|
if( !this_BAD ){ |
3792 |
|
if(nseq < nseq_max){ |
3793 |
|
sequence[nseq] = this_run->ID; |
3794 |
|
nseq++; |
3795 |
|
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
3796 |
|
}; |
3797 |
|
|
3798 |
|
if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); |
3799 |
|
nrow++; |
3800 |
|
|
3801 |
}; |
}; |
3802 |
|
delete this_run; |
3803 |
|
delete next_run; |
3804 |
// |
// |
3805 |
// timelim = now - olderthan |
return(0); |
3806 |
|
}; |
3807 |
|
/** |
3808 |
|
* Check if there might be a missing tracker calibration in a given time interval |
3809 |
|
* @param t1 From absolute time |
3810 |
|
* @param t2 To absolute time |
3811 |
|
* @return true if there might be a missing calibration |
3812 |
|
*/ |
3813 |
|
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
3814 |
|
|
3815 |
|
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
3816 |
|
|
3817 |
|
// get the closest VALIDATED calibration before the run start (t2) |
3818 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
3819 |
|
|
3820 |
|
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
3821 |
|
|
3822 |
|
//============================================================== |
3823 |
|
// Check is done first on the basis of time between calibration, |
3824 |
|
// which should be equal to the time between ascending-nodes. |
3825 |
|
//============================================================== |
3826 |
|
if ( t2 - trkcalib->FROM_TIME > 5700) { |
3827 |
|
if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); |
3828 |
|
//============================================================== |
3829 |
|
// there might be a missing calibration, due to: |
3830 |
|
// - MM full |
3831 |
|
// - corrupted packets |
3832 |
|
// - loss of data |
3833 |
|
// There is an exception in case a download was done during ascending node |
3834 |
|
//============================================================== |
3835 |
|
Bool_t DOWNLOAD = false; |
3836 |
|
// check if the calib was skipped becouse of download .... DA FARE!! |
3837 |
|
if(DOWNLOAD)return(false); |
3838 |
|
|
3839 |
|
return(true); //>>> missing |
3840 |
|
|
3841 |
|
}; |
3842 |
|
|
3843 |
|
//============================================================== |
3844 |
|
// If the last calibration is close to the run less than this time, |
3845 |
|
// it is enough to say that there are no missing calibrations |
3846 |
|
//============================================================== |
3847 |
|
// the long time interval bewteen runs might be due to download |
3848 |
|
if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
3849 |
|
return(false); |
3850 |
|
|
3851 |
|
}; |
3852 |
|
/** |
3853 |
|
* Assign VALIDATION value to a GL_RUN entry |
3854 |
|
* @param idrun Run ID |
3855 |
|
* @param validation true/false |
3856 |
|
*/ |
3857 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
3858 |
|
TSQLResult *result = 0; |
3859 |
|
stringstream oss; |
3860 |
|
oss.str(""); |
3861 |
|
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; |
3862 |
|
// |
3863 |
|
// if ( IsDebug() ) |
3864 |
|
// printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
3865 |
|
if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str()); |
3866 |
|
result = conn->Query(oss.str().c_str()); |
3867 |
|
if ( !result ) throw -4; |
3868 |
|
return(0); |
3869 |
|
} |
3870 |
|
|
3871 |
|
|
3872 |
|
|
3873 |
|
// Insert TLEs from file tlefilename in the table GL_TLE in the db |
3874 |
|
// opened by conn, sorting them by date from older to newer, if each |
3875 |
|
// TLE has not been alread inserted. |
3876 |
|
Int_t PamelaDBOperations::populateTLE()//(TSQLServer *conn, char *tleFile) |
3877 |
|
{ |
3878 |
|
fstream tlefile(tlefilename, ios::in); |
3879 |
|
|
3880 |
|
if ( !tlefile ) throw -7; |
3881 |
|
|
3882 |
|
vector<cTle*> ctles; |
3883 |
|
vector<cTle*>::iterator iter; |
3884 |
|
int present = 0; |
3885 |
|
|
3886 |
|
// Get three lines from tlefile, create a cTle object and put it |
3887 |
|
// into ctles |
3888 |
|
while(1) { |
3889 |
|
cTle *tlef; |
3890 |
|
string str1, str2, str3; |
3891 |
|
|
3892 |
|
getline(tlefile, str1); |
3893 |
|
if(tlefile.eof()) break; |
3894 |
|
|
3895 |
|
getline(tlefile, str2); |
3896 |
|
if(tlefile.eof()) break; |
3897 |
|
|
3898 |
|
getline(tlefile, str3); |
3899 |
|
if(tlefile.eof()) break; |
3900 |
|
|
3901 |
|
// We now have three good lines for a cTle. |
3902 |
|
tlef = new cTle(str1, str2, str3); |
3903 |
|
ctles.push_back(tlef); |
3904 |
|
} |
3905 |
|
|
3906 |
|
tlefile.close(); |
3907 |
|
|
3908 |
|
// Sort by date |
3909 |
|
sort(ctles.begin(), ctles.end(), compTLE); |
3910 |
|
|
3911 |
|
// Now we insert each TLE into the db |
3912 |
|
for(iter = ctles.begin(); iter != ctles.end(); iter++) { |
3913 |
|
cTle *tle = *iter; |
3914 |
|
|
3915 |
|
// Do nothing if it's already present in the db. Just increase |
3916 |
|
// the counter present. |
3917 |
|
if (! isTlePresent(tle)) |
3918 |
|
{ |
3919 |
|
int status = insertTle(tle); |
3920 |
|
|
3921 |
|
// Insert query failed. Return 1. |
3922 |
|
if(status == EXIT_FAILURE) { |
3923 |
|
|
3924 |
|
if( IsDebug() ) { |
3925 |
|
cerr << "Error: inserting TLE:" << endl |
3926 |
|
<< tle->getName() << endl |
3927 |
|
<< tle->getLine1() << endl |
3928 |
|
<< tle->getLine2() << endl; |
3929 |
|
} |
3930 |
|
|
3931 |
|
throw -4; |
3932 |
|
return 1; |
3933 |
|
} |
3934 |
|
|
3935 |
|
} |
3936 |
|
else |
3937 |
|
present++; |
3938 |
|
|
3939 |
|
} |
3940 |
|
|
3941 |
|
int inserted = ctles.size() - present; // Number of inserted TLE. |
3942 |
|
if ( IsDebug() ) |
3943 |
|
cout << "\nProcessed TLEs ranging from " << getTleDatetime(ctles[0]) << " to " << getTleDatetime(ctles[ctles.size()-1]) << "." << endl |
3944 |
|
<< inserted << " newly inserted TLEs out of " << ctles.size() << " processed." << endl; |
3945 |
|
|
3946 |
|
ctles.clear(); |
3947 |
|
|
3948 |
|
|
3949 |
|
// Return 2 if no new TLE has been inserted. 0 otherwise. |
3950 |
|
if(! inserted ) return 2; |
3951 |
|
return 0; |
3952 |
|
} |
3953 |
|
|
3954 |
|
|
3955 |
|
// Insert tle in the table GL_TLE using the connection conn. |
3956 |
|
Int_t PamelaDBOperations::insertTle(cTle *tle) |
3957 |
|
{ |
3958 |
|
stringstream oss; |
3959 |
|
TSQLResult *result = 0; |
3960 |
|
|
3961 |
|
oss.str(""); |
3962 |
|
oss << " INSERT INTO GL_TLE (TLE1, TLE2, TLE3, FROM_TIME)" |
3963 |
|
<< " VALUES ( '" |
3964 |
|
<< tle->getName() << "', '" |
3965 |
|
<< tle->getLine1() << "', '" |
3966 |
|
<< tle->getLine2() << "', '" |
3967 |
|
<< getTleDatetime(tle) << "')"; |
3968 |
|
|
3969 |
|
// cout << oss.str().c_str() << endl; |
3970 |
|
result = conn->Query(oss.str().c_str()); |
3971 |
|
if (result == NULL) |
3972 |
|
return EXIT_FAILURE; |
3973 |
|
|
3974 |
|
return EXIT_SUCCESS; |
3975 |
|
} |
3976 |
|
|
3977 |
|
|
3978 |
|
// Return whether tle is already in the db connected by conn. |
3979 |
|
bool PamelaDBOperations::isTlePresent(cTle *tle) |
3980 |
|
{ |
3981 |
|
stringstream oss; |
3982 |
|
TSQLResult *result = 0; |
3983 |
|
|
3984 |
|
oss.str(""); |
3985 |
|
oss << "SELECT * FROM GL_TLE WHERE FROM_TIME = '" |
3986 |
|
<< getTleDatetime(tle) << "'"; |
3987 |
|
|
3988 |
|
result = conn->Query(oss.str().c_str()); |
3989 |
|
if (result == NULL) throw -4; |
3990 |
|
|
3991 |
|
if (result->GetRowCount()) |
3992 |
|
return true; |
3993 |
|
else |
3994 |
|
return false; |
3995 |
|
} |
3996 |
|
|
3997 |
|
|
3998 |
|
// Return whether the first TLE is dated early than the second |
3999 |
|
bool compTLE (cTle *tle1, cTle *tle2) |
4000 |
|
{ |
4001 |
|
return getTleJulian(tle1) < getTleJulian(tle2); |
4002 |
|
} |
4003 |
|
|
4004 |
|
|
4005 |
|
// Return the date of the tle using the format (year-2000)*1e3 + |
4006 |
|
// julian day. e.g. 6365 is the 31th Dec 2006. |
4007 |
|
// It does *not* return a cJulian date. |
4008 |
|
float getTleJulian(cTle *tle) { |
4009 |
|
return tle->getField(cTle::FLD_EPOCHYEAR)*1e3 + tle->getField(cTle::FLD_EPOCHDAY); |
4010 |
|
} |
4011 |
|
|
4012 |
|
|
4013 |
|
// Return a string like YYYY-MM-DD hh:mm:ss, usable for mysql datetime |
4014 |
|
// format. |
4015 |
|
string getTleDatetime(cTle *tle) |
4016 |
|
{ |
4017 |
|
int year, mon, day, hh, mm, ss; |
4018 |
|
double dom; // day of month (is double!) |
4019 |
|
stringstream date; // date in datetime format |
4020 |
|
|
4021 |
|
// create a cJulian from the date in tle |
4022 |
|
cJulian jdate = cJulian( 2000 + (int) tle->getField(cTle::FLD_EPOCHYEAR), tle->getField(cTle::FLD_EPOCHDAY)); |
4023 |
|
|
4024 |
|
// get year, month, day of month |
4025 |
|
jdate.getComponent(&year, &mon, &dom); |
4026 |
|
|
4027 |
|
// build a datetime YYYY-MM-DD hh:mm:ss |
4028 |
|
date.str(""); |
4029 |
|
day = (int) floor(dom); |
4030 |
|
hh = (int) floor( (dom - day) * 24); |
4031 |
|
mm = (int) floor( ((dom - day) * 24 - hh) * 60); |
4032 |
|
ss = (int) floor( ((((dom - day) * 24 - hh) * 60 - mm) * 60)); |
4033 |
|
// ms = (int) floor( (((((dom - day) * 24 - hh) * 60 - mm) * 60) - ss) * 1000); |
4034 |
|
|
4035 |
|
date << year << "-" << mon << "-" << day << " " << hh << ":" << mm << ":" << ss; |
4036 |
|
|
4037 |
|
return date.str(); |
4038 |
|
} |
4039 |
|
|
4040 |
|
/** |
4041 |
|
* Remove a file from the DB, delete on cascade all entries related to that file |
4042 |
|
* rearrange GL_RUN and GL_XXX_CALIB tables, turn off validation till the following |
4043 |
|
* calibration |
4044 |
|
**/ |
4045 |
|
Int_t PamelaDBOperations::removeFile(TString remfile){ |
4046 |
// |
// |
4047 |
time->Set(); |
// Determine ID_ROOT_L0 and ID_RAW |
|
timelim = (UInt_t)time->Convert() - olderthan; |
|
|
time->Set(timelim,false); |
|
4048 |
// |
// |
4049 |
// First of all validate runs with default calibration: |
TSQLResult *pResult; |
4050 |
|
TSQLRow *Row; |
4051 |
|
stringstream myquery; |
4052 |
|
// |
4053 |
|
myquery.str(""); |
4054 |
|
myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<<remfile.Data() <<"';"; |
4055 |
// |
// |
4056 |
oss.str(""); |
pResult = conn->Query(myquery.str().c_str()); |
|
oss << " UPDATE GL_RUN SET VALIDATION=1 WHERE" |
|
|
<< " VALIDATION = 0 AND TRK_CALIB_USED=104 AND " |
|
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
|
4057 |
// |
// |
4058 |
if ( IsDebug() ) printf(" Validate runs with trk default calibration inserted before %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
Row = pResult->Next(); |
4059 |
result = conn->Query(oss.str().c_str()); |
if( !Row ){ |
4060 |
|
if ( strcmp(remfile.Data(),GetRootName().Data()) ){ |
4061 |
|
if ( IsDebug() ) printf(" No file to be removed even if option \"-remove file\" was used!!\n"); |
4062 |
|
return(1); |
4063 |
|
}; |
4064 |
|
if ( IsDebug() ) printf(" No file to be removed (force mode)! \n"); |
4065 |
|
return(0); |
4066 |
|
}; |
4067 |
// |
// |
4068 |
if ( !result ) throw -4; |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
4069 |
|
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
4070 |
|
// |
4071 |
|
this->ValidationOFF(); |
4072 |
|
// |
4073 |
|
this->RemoveCALIBS(); |
4074 |
|
// |
4075 |
|
this->RemoveRUNS(); |
4076 |
|
// |
4077 |
|
this->RemoveFILES(); |
4078 |
|
// |
4079 |
|
this->SetID_ROOT(0); |
4080 |
|
this->SetID_RAW(0); |
4081 |
// |
// |
4082 |
return(0); |
return(0); |
4083 |
}; |
}; |
4084 |
|
|
4085 |
|
/** |
4086 |
|
* |
4087 |
|
* Set validation bit to zero for runs following the removing file till |
4088 |
|
* 1) a run with TRK_CALIB_USED=140 |
4089 |
|
* 2) a run with VALIDATION = 0 |
4090 |
|
* 3) the next calibration |
4091 |
|
* |
4092 |
|
**/ |
4093 |
|
void PamelaDBOperations::ValidationOFF(){ |
4094 |
|
TSQLResult *pResult; |
4095 |
|
TSQLRow *Row; |
4096 |
|
stringstream myquery; |
4097 |
|
Int_t unv = 0; |
4098 |
|
//select ID from GL_RUN where RUNHEADER_TIME>=1152671382 AND (VALIDATION=0 OR TRK_CALIB_USED=104) order by RUNHEADER_TIME asc limit 1; |
4099 |
|
myquery.str(""); |
4100 |
|
myquery << " SELECT MAX(RUNTRAILER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; |
4101 |
|
// |
4102 |
|
pResult = conn->Query(myquery.str().c_str()); |
4103 |
|
// |
4104 |
|
Row = pResult->Next(); |
4105 |
|
if( !Row->GetField(0) ){ |
4106 |
|
// |
4107 |
|
if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n"); |
4108 |
|
// |
4109 |
|
} else { |
4110 |
|
// |
4111 |
|
UInt_t runhtime = (UInt_t)atoll(Row->GetField(0)); |
4112 |
|
UInt_t caltime = 0; |
4113 |
|
// |
4114 |
|
myquery.str(""); |
4115 |
|
myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <<runhtime; |
4116 |
|
myquery << " order by FROM_TIME asc limit 1;"; |
4117 |
|
// |
4118 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4119 |
|
// |
4120 |
|
// |
4121 |
|
delete pResult; |
4122 |
|
pResult = conn->Query(myquery.str().c_str()); |
4123 |
|
// |
4124 |
|
Row = pResult->Next(); |
4125 |
|
if( !Row ){ |
4126 |
|
caltime = runhtime; |
4127 |
|
} else { |
4128 |
|
caltime = (UInt_t)atoll(Row->GetField(0)); |
4129 |
|
}; |
4130 |
|
// |
4131 |
|
myquery.str(""); |
4132 |
|
myquery << " SELECT ID,RUNHEADER_TIME from GL_RUN where RUNHEADER_TIME>="<< runhtime <<" AND (VALIDATION=0 OR TRK_CALIB_USED=104 OR RUNHEADER_TIME>" ; |
4133 |
|
myquery << caltime << ") order by RUNHEADER_TIME asc LIMIT 1"; |
4134 |
|
// |
4135 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4136 |
|
// |
4137 |
|
pResult = conn->Query(myquery.str().c_str()); |
4138 |
|
// |
4139 |
|
Row = pResult->Next(); |
4140 |
|
if( !Row ){ |
4141 |
|
// |
4142 |
|
if ( IsDebug() ) printf(" NO RUN NEED TO BE UNVALIDATED \n"); |
4143 |
|
// |
4144 |
|
} else { |
4145 |
|
myquery.str(""); |
4146 |
|
myquery << " SELECT ID from GL_RUN where RUNHEADER_TIME<"<< Row->GetField(1) <<" AND "; |
4147 |
|
myquery << " RUNHEADER_TIME>=" <<runhtime; |
4148 |
|
myquery << " order by RUNHEADER_TIME asc;"; |
4149 |
|
// |
4150 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4151 |
|
// |
4152 |
|
pResult = conn->Query(myquery.str().c_str()); |
4153 |
|
// |
4154 |
|
Row = pResult->Next(); |
4155 |
|
while ( Row ){ |
4156 |
|
// |
4157 |
|
unv++; |
4158 |
|
this->assignVALIDATION((UInt_t)atoll(Row->GetField(0)), false); |
4159 |
|
Row = pResult->Next(); |
4160 |
|
// |
4161 |
|
}; |
4162 |
|
}; |
4163 |
|
}; |
4164 |
|
if ( IsDebug() ) printf(" %i runs have been unvalidated \n",unv); |
4165 |
|
}; |
4166 |
|
|
4167 |
|
/** |
4168 |
|
* |
4169 |
|
* Rearrange GL_RUN table and remove runs |
4170 |
|
* |
4171 |
|
**/ |
4172 |
|
void PamelaDBOperations::RemoveRUNS(){ |
4173 |
|
TSQLResult *pResult; |
4174 |
|
TSQLRow *Row; |
4175 |
|
stringstream myquery; |
4176 |
|
UInt_t drun = 0; |
4177 |
|
GL_RUN *delrun = new GL_RUN(); |
4178 |
|
// |
4179 |
|
myquery.str(""); |
4180 |
|
myquery << " SELECT ID FROM GL_RUN where ID_RUN_FRAG=0 and ID_ROOT_L0=" <<this->GetID_ROOT() <<";"; |
4181 |
|
// |
4182 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4183 |
|
// |
4184 |
|
pResult = conn->Query(myquery.str().c_str()); |
4185 |
|
// |
4186 |
|
Row = pResult->Next(); |
4187 |
|
// |
4188 |
|
// |
4189 |
|
if ( !Row ){ |
4190 |
|
if ( IsDebug() ) printf(" No run with ID_RUN_FRAG=0 belonged to this file \n"); |
4191 |
|
} else { |
4192 |
|
if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n"); |
4193 |
|
while ( Row ){ |
4194 |
|
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); |
4195 |
|
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
4196 |
|
drun++; |
4197 |
|
Row = pResult->Next(); |
4198 |
|
}; |
4199 |
|
}; |
4200 |
|
// |
4201 |
|
// |
4202 |
|
myquery.str(""); |
4203 |
|
myquery << " SELECT ID,ID_RUN_FRAG FROM GL_RUN where ID_RUN_FRAG!=0 and ID_ROOT_L0=" <<this->GetID_ROOT() <<";"; |
4204 |
|
// |
4205 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4206 |
|
// |
4207 |
|
pResult = conn->Query(myquery.str().c_str()); |
4208 |
|
// |
4209 |
|
Row = pResult->Next(); |
4210 |
|
// |
4211 |
|
if ( !Row ){ |
4212 |
|
if ( IsDebug() ) printf(" No run with ID_RUN_FRAG!=0 belonged to this file \n"); |
4213 |
|
} else { |
4214 |
|
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n"); |
4215 |
|
while ( Row ){ |
4216 |
|
if ( IsDebug() ) printf(" restore run %i \n",(UInt_t)atoll(Row->GetField(1))); |
4217 |
|
delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS"); |
4218 |
|
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(1))); |
4219 |
|
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN"); |
4220 |
|
if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){ |
4221 |
|
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
4222 |
|
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); |
4223 |
|
}; |
4224 |
|
drun++; |
4225 |
|
Row = pResult->Next(); |
4226 |
|
}; |
4227 |
|
}; |
4228 |
|
// |
4229 |
|
if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN table \n",drun); |
4230 |
|
// |
4231 |
|
// |
4232 |
|
// |
4233 |
|
drun = 0; |
4234 |
|
// |
4235 |
|
myquery.str(""); |
4236 |
|
myquery << " SELECT ID_TRASH FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID_ROOT_L0=" <<this->GetID_ROOT() <<";"; |
4237 |
|
// |
4238 |
|
pResult = conn->Query(myquery.str().c_str()); |
4239 |
|
// |
4240 |
|
Row = pResult->Next(); |
4241 |
|
// |
4242 |
|
if ( !Row ){ |
4243 |
|
if ( IsDebug() ) printf(" No run from GL_RUN_FRAGMENTS table in the trash table for this file \n"); |
4244 |
|
} else { |
4245 |
|
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n"); |
4246 |
|
while ( Row ){ |
4247 |
|
if ( IsDebug() ) printf(" del run idtrash %i \n",(UInt_t)atoll(Row->GetField(0))); |
4248 |
|
myquery.str(""); |
4249 |
|
myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";"; |
4250 |
|
conn->Query(myquery.str().c_str()); |
4251 |
|
drun++; |
4252 |
|
Row = pResult->Next(); |
4253 |
|
}; |
4254 |
|
}; |
4255 |
|
// |
4256 |
|
if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_TRASH table \n",drun); |
4257 |
|
// |
4258 |
|
// |
4259 |
|
// |
4260 |
|
drun = 0; |
4261 |
|
// |
4262 |
|
myquery.str(""); |
4263 |
|
myquery << " SELECT ID FROM GL_RUN_FRAGMENTS where ID_ROOT_L0=" <<this->GetID_ROOT() <<";"; |
4264 |
|
// |
4265 |
|
pResult = conn->Query(myquery.str().c_str()); |
4266 |
|
// |
4267 |
|
Row = pResult->Next(); |
4268 |
|
// |
4269 |
|
if ( !Row ){ |
4270 |
|
if ( IsDebug() ) printf(" No run in the GL_RUN_FRAGMENTS table for this file \n"); |
4271 |
|
} else { |
4272 |
|
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n"); |
4273 |
|
while ( Row ){ |
4274 |
|
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
4275 |
|
myquery.str(""); |
4276 |
|
myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";"; |
4277 |
|
conn->Query(myquery.str().c_str()); |
4278 |
|
drun++; |
4279 |
|
Row = pResult->Next(); |
4280 |
|
}; |
4281 |
|
}; |
4282 |
|
// |
4283 |
|
if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_FRAGMENTS table \n",drun); |
4284 |
|
// |
4285 |
|
// |
4286 |
|
// |
4287 |
|
delete delrun; |
4288 |
|
// |
4289 |
|
}; |
4290 |
|
|
4291 |
|
|
4292 |
|
/** |
4293 |
|
* |
4294 |
|
* Rearrange calibration tables |
4295 |
|
* |
4296 |
|
**/ |
4297 |
|
void PamelaDBOperations::RemoveFILES(){ |
4298 |
|
stringstream myquery; |
4299 |
|
// |
4300 |
|
myquery.str(""); |
4301 |
|
myquery << " DELETE FROM GL_RAW WHERE ID=" <<this->GetID_RAW() <<";"; |
4302 |
|
// |
4303 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4304 |
|
// |
4305 |
|
conn->Query(myquery.str().c_str()); |
4306 |
|
// |
4307 |
|
}; |
4308 |
|
|
4309 |
|
/** |
4310 |
|
* |
4311 |
|
* Rearrange calibration tables |
4312 |
|
* |
4313 |
|
**/ |
4314 |
|
void PamelaDBOperations::RemoveCALIBS(){ |
4315 |
|
TSQLResult *pResult; |
4316 |
|
TSQLRow *Row; |
4317 |
|
stringstream myquery; |
4318 |
|
// |
4319 |
|
// |
4320 |
|
// Calorimeter |
4321 |
|
// |
4322 |
|
for (Int_t section = 0; section < 4; section++){ |
4323 |
|
myquery.str(""); |
4324 |
|
myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_CALO_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<" AND "; |
4325 |
|
myquery << " SECTION=" << section << ";"; |
4326 |
|
// |
4327 |
|
pResult = conn->Query(myquery.str().c_str()); |
4328 |
|
// |
4329 |
|
Row = pResult->Next(); |
4330 |
|
if( !Row->GetField(0) || !Row->GetField(1) ){ |
4331 |
|
// |
4332 |
|
if ( IsDebug() ) printf(" NO CALO CALIBRATION SECTION %i ASSOCIATED TO THIS FILE! \n",section); |
4333 |
|
// |
4334 |
|
} else { |
4335 |
|
// |
4336 |
|
myquery.str(""); |
4337 |
|
myquery << " UPDATE GL_CALO_CALIB SET TO_TIME=" << Row->GetField(1); |
4338 |
|
myquery << " WHERE TO_TIME="<< Row->GetField(0) << " AND "; |
4339 |
|
myquery << " SECTION=" << section << ";"; |
4340 |
|
// |
4341 |
|
pResult = conn->Query(myquery.str().c_str()); |
4342 |
|
// |
4343 |
|
if( !pResult ){ |
4344 |
|
// |
4345 |
|
if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n"); |
4346 |
|
// |
4347 |
|
throw -4; |
4348 |
|
// |
4349 |
|
}; |
4350 |
|
// |
4351 |
|
}; |
4352 |
|
}; |
4353 |
|
myquery.str(""); |
4354 |
|
myquery << " DELETE FROM GL_CALO_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
4355 |
|
// |
4356 |
|
pResult = conn->Query(myquery.str().c_str()); |
4357 |
|
// |
4358 |
|
if( !pResult ){ |
4359 |
|
// |
4360 |
|
if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n"); |
4361 |
|
// |
4362 |
|
throw -4; |
4363 |
|
// |
4364 |
|
}; |
4365 |
|
// |
4366 |
|
// Tracker |
4367 |
|
// |
4368 |
|
myquery.str(""); |
4369 |
|
myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_TRK_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; |
4370 |
|
// |
4371 |
|
pResult = conn->Query(myquery.str().c_str()); |
4372 |
|
// |
4373 |
|
Row = pResult->Next(); |
4374 |
|
if( !Row->GetField(0) || !Row->GetField(1) ){ |
4375 |
|
// |
4376 |
|
if ( IsDebug() ) printf(" NO TRK CALIBRATION ASSOCIATED TO THIS FILE! \n"); |
4377 |
|
// |
4378 |
|
} else { |
4379 |
|
// |
4380 |
|
myquery.str(""); |
4381 |
|
myquery << " UPDATE GL_TRK_CALIB SET TO_TIME=" << Row->GetField(1); |
4382 |
|
myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";"; |
4383 |
|
// |
4384 |
|
pResult = conn->Query(myquery.str().c_str()); |
4385 |
|
// |
4386 |
|
if( !pResult ){ |
4387 |
|
// |
4388 |
|
if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n"); |
4389 |
|
// |
4390 |
|
throw -4; |
4391 |
|
// |
4392 |
|
}; |
4393 |
|
// |
4394 |
|
myquery.str(""); |
4395 |
|
myquery << " DELETE FROM GL_TRK_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
4396 |
|
// |
4397 |
|
pResult = conn->Query(myquery.str().c_str()); |
4398 |
|
// |
4399 |
|
if( !pResult ){ |
4400 |
|
// |
4401 |
|
if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n"); |
4402 |
|
// |
4403 |
|
throw -4; |
4404 |
|
// |
4405 |
|
}; |
4406 |
|
}; |
4407 |
|
// |
4408 |
|
// |
4409 |
|
// S4 |
4410 |
|
// |
4411 |
|
myquery.str(""); |
4412 |
|
myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_S4_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; |
4413 |
|
// |
4414 |
|
pResult = conn->Query(myquery.str().c_str()); |
4415 |
|
// |
4416 |
|
Row = pResult->Next(); |
4417 |
|
if( !Row->GetField(0) || !Row->GetField(1) ){ |
4418 |
|
// |
4419 |
|
if ( IsDebug() ) printf(" NO S4 CALIBRATION ASSOCIATED TO THIS FILE! \n"); |
4420 |
|
// |
4421 |
|
} else { |
4422 |
|
// |
4423 |
|
myquery.str(""); |
4424 |
|
myquery << " UPDATE GL_S4_CALIB SET TO_TIME=" << Row->GetField(1); |
4425 |
|
myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";"; |
4426 |
|
// |
4427 |
|
pResult = conn->Query(myquery.str().c_str()); |
4428 |
|
// |
4429 |
|
if( !pResult ){ |
4430 |
|
// |
4431 |
|
if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n"); |
4432 |
|
// |
4433 |
|
throw -4; |
4434 |
|
// |
4435 |
|
}; |
4436 |
|
// |
4437 |
|
myquery.str(""); |
4438 |
|
myquery << " DELETE FROM GL_S4_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
4439 |
|
// |
4440 |
|
pResult = conn->Query(myquery.str().c_str()); |
4441 |
|
// |
4442 |
|
if( !pResult ){ |
4443 |
|
// |
4444 |
|
if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n"); |
4445 |
|
// |
4446 |
|
throw -4; |
4447 |
|
// |
4448 |
|
}; |
4449 |
|
// |
4450 |
|
}; |
4451 |
|
}; |
4452 |
|
|
4453 |
|
/** |
4454 |
|
* |
4455 |
|
* Rearrange calibration tables |
4456 |
|
* |
4457 |
|
**/ |
4458 |
|
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
4459 |
|
|
4460 |
|
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
4461 |
|
UInt_t timeaftercalib=120000; //2000; |
4462 |
|
// ---------- |
4463 |
|
// Check CRCs |
4464 |
|
// ---------- |
4465 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
4466 |
|
if( caltrk->crc_hcal[ipkt] )return 0; // :-( |
4467 |
|
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( |
4468 |
|
} |
4469 |
|
// ----------------------- |
4470 |
|
// Check missing packets: |
4471 |
|
// ----------------------- |
4472 |
|
// Readout order: |
4473 |
|
// ------------------ |
4474 |
|
// DSP packet board |
4475 |
|
// ------------------ |
4476 |
|
// 12 0 1 |
4477 |
|
// 10 1 1 |
4478 |
|
// 8 2 1 |
4479 |
|
// 4 3 1 |
4480 |
|
// 6 4 1 |
4481 |
|
// 2 5 1 |
4482 |
|
// ------------------ |
4483 |
|
// 11 0 2 |
4484 |
|
// 9 1 2 |
4485 |
|
// 7 2 2 |
4486 |
|
// 3 3 2 |
4487 |
|
// 5 4 2 |
4488 |
|
// 1 5 2 |
4489 |
|
// ------------------ |
4490 |
|
// ------------------------------------------------- |
4491 |
|
// Check if it is first or second calibration packet |
4492 |
|
// ------------------------------------------------- |
4493 |
|
UInt_t build=0; |
4494 |
|
TString classname = caltrk->GetName(); |
4495 |
|
UInt_t base=0; |
4496 |
|
UInt_t mask=0; |
4497 |
|
if(classname.Contains("CalibTrk1Event")){ |
4498 |
|
base=12; |
4499 |
|
mask=0x03F000; |
4500 |
|
} |
4501 |
|
if(classname.Contains("CalibTrk2Event")){ |
4502 |
|
base=18; |
4503 |
|
mask=0xFC0000; |
4504 |
|
} |
4505 |
|
// ------------------------------------------------- |
4506 |
|
// Count number of packets and set build variable |
4507 |
|
// ------------------------------------------------- |
4508 |
|
Int_t npkts=0; |
4509 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
4510 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
4511 |
|
npkts++; |
4512 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
4513 |
|
} |
4514 |
|
} |
4515 |
|
// if( npkts==6 )return 1; // :-) |
4516 |
|
|
4517 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
4518 |
|
|
4519 |
|
// ----------------------------------------------- |
4520 |
|
// If missing packets: check the acq configuration |
4521 |
|
// (some DSPs might be excluded from acquisition) |
4522 |
|
// ----------------------------------------------- |
4523 |
|
|
4524 |
|
// ----------------------------------------------- |
4525 |
|
// retrieve the first run header after calib |
4526 |
|
// ----------------------------------------------- |
4527 |
|
PacketType *pctp; |
4528 |
|
EventCounter *cod; |
4529 |
|
cod = eh->GetCounter(); |
4530 |
|
Int_t irun = cod->Get(pctp->RunHeader); |
4531 |
|
TTree *rh=(TTree*)file->Get("RunHeader"); |
4532 |
|
if ( !rh || rh->IsZombie() ) throw -17; |
4533 |
|
if( rh->GetEntries() == irun ){ |
4534 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
4535 |
|
return 0; // :-( |
4536 |
|
} |
4537 |
|
|
4538 |
|
RunHeaderEvent *run = 0; |
4539 |
|
EventHeader *hrun = 0; |
4540 |
|
rh->SetBranchAddress("RunHeader", &run); |
4541 |
|
rh->SetBranchAddress("Header", &hrun); |
4542 |
|
rh->GetEntry(irun); |
4543 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
4544 |
|
|
4545 |
|
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
4546 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
4547 |
|
return 0; // :-( |
4548 |
|
} |
4549 |
|
|
4550 |
|
if( !run->RM_ACQ_AFTER_CALIB ){ |
4551 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
4552 |
|
return 0; // :-( |
4553 |
|
} |
4554 |
|
|
4555 |
|
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
4556 |
|
if( dtime > timeaftercalib ){ |
4557 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
4558 |
|
return 0; // :-( |
4559 |
|
} |
4560 |
|
|
4561 |
|
|
4562 |
|
|
4563 |
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
4564 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
4565 |
|
return 0; // :-( |
4566 |
|
} |
4567 |
|
return 1; // :-) |
4568 |
|
|
4569 |
|
} |
4570 |
|
|
4571 |
|
/** |
4572 |
|
* |
4573 |
|
* Check the DB (only for overlapping runs at the moment) |
4574 |
|
* |
4575 |
|
**/ |
4576 |
|
UInt_t PamelaDBOperations::Check(){ |
4577 |
|
// |
4578 |
|
UInt_t test = 0; |
4579 |
|
// |
4580 |
|
UInt_t thisrht = 0; |
4581 |
|
UInt_t thisrtt = 0; |
4582 |
|
UInt_t thisid = 0; |
4583 |
|
UInt_t prevrht = 0; |
4584 |
|
UInt_t prevrtt = 0; |
4585 |
|
UInt_t previd = 0; |
4586 |
|
// |
4587 |
|
UInt_t prevl0id = 0; |
4588 |
|
UInt_t thisl0id = 0; |
4589 |
|
// |
4590 |
|
stringstream oss; |
4591 |
|
TSQLResult *result = 0; |
4592 |
|
TSQLRow *row = 0; |
4593 |
|
TSQLResult *result2 = 0; |
4594 |
|
TSQLRow *row2 = 0; |
4595 |
|
oss.str(""); |
4596 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;"; |
4597 |
|
// oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; |
4598 |
|
result = conn->Query(oss.str().c_str()); |
4599 |
|
// |
4600 |
|
if ( !result ) throw -4;; |
4601 |
|
// |
4602 |
|
row = result->Next(); |
4603 |
|
// |
4604 |
|
while ( row ){ |
4605 |
|
thisid = (UInt_t)atoll(row->GetField(0)); |
4606 |
|
thisl0id = (UInt_t)atoll(row->GetField(1)); |
4607 |
|
thisrht = (UInt_t)atoll(row->GetField(2)); |
4608 |
|
thisrtt = (UInt_t)atoll(row->GetField(3)); |
4609 |
|
// |
4610 |
|
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
4611 |
|
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
4612 |
|
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
4613 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4614 |
|
printf(" CHECK n.1 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid); |
4615 |
|
TString prevf = ""; |
4616 |
|
TString thisf = ""; |
4617 |
|
oss.str(""); |
4618 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4619 |
|
result2 = conn->Query(oss.str().c_str()); |
4620 |
|
if ( !result2 ) throw -4;; |
4621 |
|
row2 = result2->Next(); |
4622 |
|
prevf = (TString)row2->GetField(0); |
4623 |
|
oss.str(""); |
4624 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4625 |
|
result2 = conn->Query(oss.str().c_str()); |
4626 |
|
if ( !result2 ) throw -4;; |
4627 |
|
row2 = result2->Next(); |
4628 |
|
thisf = (TString)row2->GetField(0); |
4629 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4630 |
|
test = 1; |
4631 |
|
}; |
4632 |
|
// |
4633 |
|
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
4634 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4635 |
|
printf(" CHECK n.2 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid); |
4636 |
|
TString prevf = ""; |
4637 |
|
TString thisf = ""; |
4638 |
|
oss.str(""); |
4639 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4640 |
|
result2 = conn->Query(oss.str().c_str()); |
4641 |
|
if ( !result2 ) throw -4;; |
4642 |
|
row2 = result2->Next(); |
4643 |
|
prevf = (TString)row2->GetField(0); |
4644 |
|
oss.str(""); |
4645 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4646 |
|
result2 = conn->Query(oss.str().c_str()); |
4647 |
|
if ( !result2 ) throw -4;; |
4648 |
|
row2 = result2->Next(); |
4649 |
|
thisf = (TString)row2->GetField(0); |
4650 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4651 |
|
test = 1; |
4652 |
|
}; |
4653 |
|
// |
4654 |
|
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
4655 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4656 |
|
printf(" CHECK n.3 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid); |
4657 |
|
TString prevf = ""; |
4658 |
|
TString thisf = ""; |
4659 |
|
oss.str(""); |
4660 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4661 |
|
result2 = conn->Query(oss.str().c_str()); |
4662 |
|
if ( !result2 ) throw -4;; |
4663 |
|
row2 = result2->Next(); |
4664 |
|
prevf = (TString)row2->GetField(0); |
4665 |
|
oss.str(""); |
4666 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4667 |
|
result2 = conn->Query(oss.str().c_str()); |
4668 |
|
if ( !result2 ) throw -4;; |
4669 |
|
row2 = result2->Next(); |
4670 |
|
thisf = (TString)row2->GetField(0); |
4671 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4672 |
|
test = 1; |
4673 |
|
}; |
4674 |
|
|
4675 |
|
// |
4676 |
|
prevrht = thisrht; |
4677 |
|
prevrtt = thisrtt; |
4678 |
|
previd = thisid; |
4679 |
|
prevl0id = thisl0id; |
4680 |
|
row = result->Next(); |
4681 |
|
}; |
4682 |
|
// |
4683 |
|
return(test); |
4684 |
|
// |
4685 |
|
}; |