24 |
#include <RunHeaderEvent.h> |
#include <RunHeaderEvent.h> |
25 |
#include <RunTrailerEvent.h> |
#include <RunTrailerEvent.h> |
26 |
#include <CalibCalPedEvent.h> |
#include <CalibCalPedEvent.h> |
27 |
|
#include <CalibCalPulse1Event.h> |
28 |
|
#include <CalibCalPulse2Event.h> |
29 |
#include <CalibS4Event.h> |
#include <CalibS4Event.h> |
30 |
#include <CalibTrk1Event.h> |
#include <CalibTrk1Event.h> |
31 |
#include <CalibTrk2Event.h> |
#include <CalibTrk2Event.h> |
58 |
* @param debug debug flag. |
* @param debug debug flag. |
59 |
* @param tlefilename ascii file with TLE 3 line elements. |
* @param tlefilename ascii file with TLE 3 line elements. |
60 |
*/ |
*/ |
61 |
PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename){ |
PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput, Bool_t staticp, Bool_t gpamela){ |
62 |
// |
// |
63 |
|
STATIC=false; |
64 |
|
if ( staticp ) STATIC=true; |
65 |
// |
// |
66 |
SetConnection(host,user,password); |
SetConnection(host,user,password); |
67 |
// |
// |
70 |
glrun = new GL_RUN(); |
glrun = new GL_RUN(); |
71 |
// |
// |
72 |
if ( !boot ) SetNOBOOT(false); |
if ( !boot ) SetNOBOOT(false); |
73 |
SetBOOTnumber(boot); |
SetTsync(tsync,gpamela); |
74 |
SetTsync(tsync); |
SetBOOTnumber(boot,gpamela); |
75 |
SetObt0(obt0); |
SetObt0(obt0); |
76 |
// |
// |
77 |
SetTLEPath(tlefilename); |
SetTLEPath(tlefilename); |
83 |
INSERT_ROOT = !filerootname.IsNull(); |
INSERT_ROOT = !filerootname.IsNull(); |
84 |
if( INSERT_ROOT ){ |
if( INSERT_ROOT ){ |
85 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
86 |
this->SetOrbitNo(); |
this->SetOrbitNo(dwinput); |
87 |
file = TFile::Open(this->GetRootName().Data()); |
file = TFile::Open(this->GetRootName().Data()); |
88 |
} else { |
} else { |
89 |
this->SetRootName(""); |
this->SetRootName(""); |
169 |
}; |
}; |
170 |
|
|
171 |
/** |
/** |
172 |
|
* Set the pedantic flag |
173 |
|
* |
174 |
|
*/ |
175 |
|
void PamelaDBOperations::SetPedantic(Bool_t dbg){ |
176 |
|
PEDANTIC = dbg; |
177 |
|
}; |
178 |
|
|
179 |
|
/** |
180 |
* Set the nofrag flag |
* Set the nofrag flag |
181 |
* |
* |
182 |
*/ |
*/ |
189 |
* @param boot BOOT number of the RAW file |
* @param boot BOOT number of the RAW file |
190 |
*/ |
*/ |
191 |
void PamelaDBOperations::SetBOOTnumber(UInt_t boot){ |
void PamelaDBOperations::SetBOOTnumber(UInt_t boot){ |
192 |
|
this->SetBOOTnumber(boot,false); |
193 |
|
}; |
194 |
|
|
195 |
|
/** |
196 |
|
* Store the BOOT number of the RAW file. |
197 |
|
* @param boot BOOT number of the RAW file |
198 |
|
*/ |
199 |
|
void PamelaDBOperations::SetBOOTnumber(UInt_t boot, Bool_t gpamela){ |
200 |
BOOTNO=boot; |
BOOTNO=boot; |
201 |
|
if ( gpamela ){ |
202 |
|
stringstream oss; |
203 |
|
TSQLResult *result = 0; |
204 |
|
TSQLRow *row = 0; |
205 |
|
if ( !boot ){ |
206 |
|
// |
207 |
|
BOOTNO = 1; |
208 |
|
// |
209 |
|
// look in the DB for the last timesync and the last run |
210 |
|
// |
211 |
|
oss.str(""); |
212 |
|
oss << "SELECT BOOT_NUMBER FROM GL_RUN order by RUNHEADER_TIME desc limit 1;"; |
213 |
|
result = conn->Query(oss.str().c_str()); |
214 |
|
if ( result ){ |
215 |
|
row = result->Next(); |
216 |
|
if ( row ){ |
217 |
|
BOOTNO = (UInt_t)atoll(row->GetField(0)) + 1; |
218 |
|
}; |
219 |
|
}; |
220 |
|
}; |
221 |
|
}; |
222 |
}; |
}; |
223 |
|
|
224 |
/** |
/** |
226 |
* @param boot time sync |
* @param boot time sync |
227 |
*/ |
*/ |
228 |
void PamelaDBOperations::SetTsync(UInt_t ts){ |
void PamelaDBOperations::SetTsync(UInt_t ts){ |
229 |
|
this->SetTsync(ts,false); |
230 |
|
}; |
231 |
|
|
232 |
|
/** |
233 |
|
* Store the time sync of the RAW file. |
234 |
|
* @param boot time sync |
235 |
|
*/ |
236 |
|
void PamelaDBOperations::SetTsync(UInt_t ts, Bool_t gpamela){ |
237 |
|
// |
238 |
|
// if not gpamela or given tsync file set ts |
239 |
|
// |
240 |
tsync=ts; |
tsync=ts; |
241 |
|
if ( gpamela ){ |
242 |
|
stringstream oss; |
243 |
|
TSQLResult *result = 0; |
244 |
|
TSQLRow *row = 0; |
245 |
|
TSQLResult *result2 = 0; |
246 |
|
TSQLRow *row2 = 0; |
247 |
|
if ( !ts ){ |
248 |
|
// |
249 |
|
tsync = 1; |
250 |
|
// |
251 |
|
// look in the DB for the last timesync and the last run |
252 |
|
// |
253 |
|
oss.str(""); |
254 |
|
oss << "SELECT TIMESYNC FROM GL_TIMESYNC order by TIMESYNC desc limit 1;"; |
255 |
|
result = conn->Query(oss.str().c_str()); |
256 |
|
if ( result ){ |
257 |
|
row = result->Next(); |
258 |
|
if ( row ){ |
259 |
|
tsync = (UInt_t)atoll(row->GetField(0)) + 1; |
260 |
|
oss.str(""); |
261 |
|
oss << "SELECT (RUNTRAILER_TIME-RUNHEADER_TIME) FROM GL_RUN order by RUNHEADER_TIME desc limit 1;"; |
262 |
|
result2 = conn->Query(oss.str().c_str()); |
263 |
|
if ( result2 ){ |
264 |
|
row2 = result2->Next(); |
265 |
|
if ( row2 ){ |
266 |
|
tsync += (UInt_t)atoll(row2->GetField(0)); |
267 |
|
}; |
268 |
|
} |
269 |
|
}; |
270 |
|
}; |
271 |
|
}; |
272 |
|
}; |
273 |
}; |
}; |
274 |
|
|
275 |
/** |
/** |
299 |
/** |
/** |
300 |
* Store the downlink orbit number from filename. |
* Store the downlink orbit number from filename. |
301 |
*/ |
*/ |
302 |
void PamelaDBOperations::SetOrbitNo(){ |
void PamelaDBOperations::SetOrbitNo(UInt_t dwinput){ |
303 |
dworbit = 0; |
dworbit = 0; |
304 |
|
// |
305 |
|
if ( dwinput ){ |
306 |
|
dworbit = dwinput; |
307 |
|
if ( IsDebug() ) printf(" Downlink orbit given by hand: %i \n",dworbit); |
308 |
|
return; |
309 |
|
}; |
310 |
|
// |
311 |
TString name = this->GetRootFile(); |
TString name = this->GetRootFile(); |
312 |
Int_t nlength = name.Length(); |
Int_t nlength = name.Length(); |
313 |
if ( nlength < 5 ) return; |
if ( nlength < 5 ) return; |
345 |
tlefilename = str; |
tlefilename = str; |
346 |
}; |
}; |
347 |
|
|
348 |
|
TString PamelaDBOperations::GetRawPath(){ |
349 |
|
if ( STATIC ){ |
350 |
|
return((TString)gSystem->DirName(filerawname.Data())+'/'); |
351 |
|
} else { |
352 |
|
return((TString)gSystem->ExpandPathName("$PAM_RAW")+'/'); |
353 |
|
}; |
354 |
|
}; |
355 |
|
|
356 |
|
TString PamelaDBOperations::GetRootPath(){ |
357 |
|
if ( STATIC ){ |
358 |
|
return((TString)gSystem->DirName(filerootname.Data())+'/'); |
359 |
|
} else { |
360 |
|
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
361 |
|
}; |
362 |
|
}; |
363 |
|
|
364 |
/** |
/** |
365 |
* Store the olderthan variable |
* Store the olderthan variable |
366 |
* @param olderthan |
* @param olderthan |
377 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
378 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
379 |
oss.str(""); |
oss.str(""); |
380 |
oss << "SELECT ID FROM GL_RAW WHERE " |
if ( STATIC ){ |
381 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
oss << "SELECT ID FROM GL_RAW WHERE " |
382 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
383 |
|
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
384 |
|
} else { |
385 |
|
oss << "SELECT ID FROM GL_RAW WHERE " |
386 |
|
<< " PATH = '$PAM_RAW' AND " |
387 |
|
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
388 |
|
} |
389 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
390 |
if ( result == NULL ) throw -4; |
if ( result == NULL ) throw -4; |
391 |
row = result->Next(); |
row = result->Next(); |
392 |
if ( !row ) return(false); |
if ( !row ) return(false); |
|
delete result; |
|
393 |
id = (UInt_t)atoll(row->GetField(0)); |
id = (UInt_t)atoll(row->GetField(0)); |
394 |
|
delete result; |
395 |
return(true); |
return(true); |
396 |
} |
} |
397 |
|
|
428 |
Long64_t deltapkt = 5000LL; |
Long64_t deltapkt = 5000LL; |
429 |
Long64_t deltaobt = 50000LL; |
Long64_t deltaobt = 50000LL; |
430 |
// |
// |
431 |
// pcksList packetsNames; |
pcksList packetsNames; |
432 |
// pcksList::iterator Iter; |
pcksList::iterator Iter; |
433 |
// getPacketsNames(packetsNames); |
getPacketsNames(packetsNames); |
434 |
// |
// |
435 |
pktfirst = 0; |
pktfirst = 0; |
436 |
obtfirst = 0; |
obtfirst = 0; |
437 |
|
ppktfirst = 0; |
438 |
|
pobtfirst = 0; |
439 |
// |
// |
440 |
TTree *T = 0; |
TTree *T = 0; |
441 |
T = (TTree*)file->Get("Physics"); |
T = (TTree*)file->Get("Physics"); |
449 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
450 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
451 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
452 |
|
ppktfirst = pktfirst; |
453 |
|
pobtfirst = obtfirst; |
454 |
// |
// |
455 |
// code = eh->GetCounter(); |
code = eh->GetCounter(); |
456 |
// UInt_t en = 0; |
UInt_t en = 0; |
457 |
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
458 |
// en = code->Get(GetPacketType(*Iter)); |
en = code->Get(GetPacketType(*Iter)); |
459 |
// if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en); |
if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
460 |
//}; |
if ( IsDebug() ) printf(" We have a calibration before the first physic packet: packet type is %s, entries: %i \n",*Iter,en); |
461 |
|
// |
462 |
|
TTree *TC = 0; |
463 |
|
TC = (TTree*)file->Get("CalibCalPed"); |
464 |
|
if ( !TC || TC->IsZombie() ) throw -16; |
465 |
|
EventHeader *ehc = 0; |
466 |
|
PscuHeader *phc = 0; |
467 |
|
TC->SetBranchAddress("Header", &ehc); |
468 |
|
TC->GetEntry(0); |
469 |
|
phc = ehc->GetPscuHeader(); |
470 |
|
pktfirst = phc->GetCounter(); |
471 |
|
obtfirst = phc->GetOrbitalTime(); |
472 |
|
// |
473 |
|
}; |
474 |
|
}; |
475 |
// |
// |
476 |
T->GetEntry(nevent-1); |
T->GetEntry(nevent-1); |
477 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
482 |
upperobt = OBT(obtlast); |
upperobt = OBT(obtlast); |
483 |
upperentry = nevent-1; |
upperentry = nevent-1; |
484 |
// |
// |
485 |
if ( IsDebug() ) printf(" First entries are: OBT %i pkt_num %i \n",obtfirst,pktfirst); |
if ( IsDebug() ) printf(" First entries are: OBT %u pkt_num %u \n",obtfirst,pktfirst); |
486 |
// |
// |
487 |
if ( IsDebug() ) printf(" Last entries are: OBT %lld pkt_num %lld entry %i\n",upperobt,upperpkt,upperentry); |
if ( IsDebug() ) printf(" Last entries are: OBT %lld pkt_num %lld entry %i\n",upperobt,upperpkt,upperentry); |
488 |
// |
// |
489 |
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(32); |
490 |
// |
// |
491 |
if ( !nevent ) return(2); |
if ( !nevent ) return(64); |
492 |
// |
// |
493 |
if ( nevent < 2 ) return(4); |
if ( nevent < 2 ) return(128); |
494 |
|
if ( nevent < jump ) jump = 1; |
495 |
|
// if ( nevent < jump ) jump = int(nevent/10); |
496 |
|
// if ( !jump ) jump = 1; |
497 |
// |
// |
498 |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) ){ |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){ |
499 |
// |
// |
500 |
|
if ( IsDebug() ) printf(" starting jump %i \n",jump); |
501 |
|
if ( PEDANTIC ) throw -66; |
502 |
// go back |
// go back |
503 |
zomp = nevent - 2; |
zomp = nevent - 2; |
504 |
// |
// |
530 |
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 ){ |
531 |
zomp = i + jump + 1; |
zomp = i + jump + 1; |
532 |
if ( zomp > nevent-2 ) zomp = nevent - 2; |
if ( zomp > nevent-2 ) zomp = nevent - 2; |
533 |
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); |
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); |
534 |
break; |
break; |
535 |
}; |
}; |
536 |
// |
// |
574 |
Long64_t pkth = 0LL; |
Long64_t pkth = 0LL; |
575 |
Long64_t obth = 0LL; |
Long64_t obth = 0LL; |
576 |
// |
// |
577 |
T->GetEntry(upperentry); |
if ( rhev || rtev ){ |
578 |
code = eh->GetCounter(); |
|
579 |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
T->GetEntry(upperentry); |
580 |
Int_t lasthead = code->Get(pctp->RunHeader); |
code = eh->GetCounter(); |
581 |
if ( lasttrail < rtev ){ |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
582 |
rt->GetEntry(lasttrail); |
Int_t lasthead = code->Get(pctp->RunHeader); |
583 |
pht = eht->GetPscuHeader(); |
if ( lasttrail < rtev ){ |
584 |
pktt = PKT(pht->GetCounter()); |
rt->GetEntry(lasttrail); |
585 |
obtt = OBT(pht->GetOrbitalTime()); |
pht = eht->GetPscuHeader(); |
586 |
}; |
pktt = PKT(pht->GetCounter()); |
587 |
// |
obtt = OBT(pht->GetOrbitalTime()); |
588 |
if ( lasthead < rhev ){ |
}; |
589 |
rh->GetEntry(lasthead); |
// |
590 |
phh = ehh->GetPscuHeader(); |
if ( lasthead < rhev ){ |
591 |
pkth = PKT(phh->GetCounter()); |
rh->GetEntry(lasthead); |
592 |
obth = OBT(phh->GetOrbitalTime()); |
phh = ehh->GetPscuHeader(); |
593 |
}; |
pkth = PKT(phh->GetCounter()); |
594 |
// |
obth = OBT(phh->GetOrbitalTime()); |
595 |
if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
}; |
596 |
if ( pkth > upperpkt && obth > upperobt ){ |
// |
597 |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
598 |
upperpkt = pkth; |
if ( pkth > upperpkt && obth > upperobt ){ |
599 |
upperobt = obth; |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); |
600 |
rhev = lasthead+1; |
upperpkt = pkth; |
601 |
} else { |
upperobt = obth; |
602 |
rhev = lasthead; |
rhev = lasthead+1; |
603 |
}; |
} else { |
604 |
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
rhev = lasthead; |
605 |
// |
}; |
606 |
if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
607 |
if ( pktt > upperpkt && obtt > upperobt ){ |
// |
608 |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
609 |
upperpkt = pktt; |
if ( pktt > upperpkt && obtt > upperobt ){ |
610 |
upperobt = obtt; |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); |
611 |
rtev = lasttrail+1; |
upperpkt = pktt; |
612 |
} else { |
upperobt = obtt; |
613 |
rtev = lasttrail; |
rtev = lasttrail+1; |
614 |
}; |
} else { |
615 |
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
rtev = lasttrail; |
616 |
// goto kikko; |
}; |
617 |
// |
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
618 |
// |
// goto kikko; |
619 |
// Check if runtrailer/runheader are within lower limits |
// |
620 |
// |
// |
621 |
// |
// Check if runtrailer/runheader are within lower limits |
622 |
pkth = 0LL; |
// |
623 |
obth = 0LL; |
// |
624 |
spkth = 0LL; |
pkth = 0LL; |
625 |
sobth = 0LL; |
obth = 0LL; |
626 |
for (Int_t k=0; k<rhev; k++){ |
spkth = 0LL; |
627 |
if ( k > 0 ){ |
sobth = 0LL; |
628 |
spkth = pkth; |
for (Int_t k=0; k<rhev; k++){ |
629 |
sobth = obth; |
if ( k > 0 ){ |
630 |
}; |
spkth = pkth; |
631 |
rh->GetEntry(k); |
sobth = obth; |
632 |
phh = ehh->GetPscuHeader(); |
}; |
633 |
pkth = PKT(phh->GetCounter()); |
rh->GetEntry(k); |
634 |
obth = OBT(phh->GetOrbitalTime()); |
phh = ehh->GetPscuHeader(); |
635 |
// |
pkth = PKT(phh->GetCounter()); |
636 |
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); |
obth = OBT(phh->GetOrbitalTime()); |
637 |
// |
// |
638 |
if ( pkth < spkth && obth < sobth ){ |
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); |
639 |
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
// |
640 |
// |
if ( pkth < spkth && obth < sobth ){ |
641 |
rhev = k-1; |
if ( PEDANTIC ) throw -66; |
642 |
rh->GetEntry(rhev); |
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
643 |
pkth = spkth; |
// |
644 |
obth = sobth; |
rhev = k-1; |
645 |
// |
rh->GetEntry(rhev); |
646 |
UInt_t evbefh = 0; |
pkth = spkth; |
647 |
code = ehh->GetCounter(); |
obth = sobth; |
648 |
evbefh = code->Get(pctp->Physics); |
// |
649 |
if ( evbefh >= 0 ){ |
UInt_t evbefh = 0; |
650 |
T->GetEntry(evbefh); |
code = ehh->GetCounter(); |
651 |
ph = eh->GetPscuHeader(); |
evbefh = code->Get(pctp->Physics); |
652 |
t_pktlast = PKT(ph->GetCounter()); |
if ( evbefh >= 0 ){ |
653 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
T->GetEntry(evbefh); |
|
if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump |
|
|
upperpkt = pkth; |
|
|
upperobt = obth; |
|
|
upperentry = evbefh-1; |
|
|
} else { |
|
|
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
|
|
evbefh++; |
|
|
T->GetEntry(evbefh); |
|
|
ph = eh->GetPscuHeader(); |
|
|
t_pktlast = PKT(ph->GetCounter()); |
|
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
|
|
}; |
|
|
T->GetEntry(evbefh-1); |
|
654 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
655 |
upperpkt = PKT(ph->GetCounter()); |
t_pktlast = PKT(ph->GetCounter()); |
656 |
upperobt = OBT(ph->GetOrbitalTime()); |
t_obtlast = OBT(ph->GetOrbitalTime()); |
657 |
upperentry = evbefh-1; |
if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump |
658 |
}; |
upperpkt = pkth; |
659 |
|
upperobt = obth; |
660 |
|
upperentry = evbefh-1; |
661 |
|
} else { |
662 |
|
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
663 |
|
evbefh++; |
664 |
|
T->GetEntry(evbefh); |
665 |
|
ph = eh->GetPscuHeader(); |
666 |
|
t_pktlast = PKT(ph->GetCounter()); |
667 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
668 |
|
}; |
669 |
|
T->GetEntry(evbefh-1); |
670 |
|
ph = eh->GetPscuHeader(); |
671 |
|
upperpkt = PKT(ph->GetCounter()); |
672 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
673 |
|
upperentry = evbefh-1; |
674 |
|
}; |
675 |
|
}; |
676 |
|
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
677 |
|
goto kikko0; |
678 |
}; |
}; |
|
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
|
|
goto kikko0; |
|
|
}; |
|
|
}; |
|
|
kikko0: |
|
|
// |
|
|
// |
|
|
// |
|
|
pktt = 0LL; |
|
|
obtt = 0LL; |
|
|
spktt = 0LL; |
|
|
sobtt = 0LL; |
|
|
for (Int_t k=0; k<rtev; k++){ |
|
|
if ( k > 0 ){ |
|
|
spktt = pktt; |
|
|
sobtt = obtt; |
|
679 |
}; |
}; |
680 |
rt->GetEntry(k); |
kikko0: |
|
pht = eht->GetPscuHeader(); |
|
|
pktt = PKT(pht->GetCounter()); |
|
|
obtt = OBT(pht->GetOrbitalTime()); |
|
681 |
// |
// |
|
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
|
682 |
// |
// |
683 |
if ( pktt < spktt && obtt < sobtt ){ |
// |
684 |
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
pktt = 0LL; |
685 |
|
obtt = 0LL; |
686 |
|
spktt = 0LL; |
687 |
|
sobtt = 0LL; |
688 |
|
for (Int_t k=0; k<rtev; k++){ |
689 |
|
if ( k > 0 ){ |
690 |
|
spktt = pktt; |
691 |
|
sobtt = obtt; |
692 |
|
}; |
693 |
|
rt->GetEntry(k); |
694 |
|
pht = eht->GetPscuHeader(); |
695 |
|
pktt = PKT(pht->GetCounter()); |
696 |
|
obtt = OBT(pht->GetOrbitalTime()); |
697 |
// |
// |
698 |
rtev = k-1; |
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
|
rt->GetEntry(rtev); |
|
|
pktt = spktt; |
|
|
obtt = sobtt; |
|
|
if ( IsDebug() ) printf(" lasttrail %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
699 |
// |
// |
700 |
UInt_t evbeft = 0; |
if ( pktt < spktt && obtt < sobtt ){ |
701 |
code = eht->GetCounter(); |
if ( PEDANTIC ) throw -66; |
702 |
evbeft = code->Get(pctp->Physics); |
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
703 |
if ( evbeft >= 0 ){ |
// |
704 |
T->GetEntry(evbeft); |
rtev = k-1; |
705 |
ph = eh->GetPscuHeader(); |
rt->GetEntry(rtev); |
706 |
t_pktlast = PKT(ph->GetCounter()); |
pktt = spktt; |
707 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
obtt = sobtt; |
708 |
if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump |
if ( IsDebug() ) printf(" lasttrail %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
709 |
upperpkt = pktt; |
// |
710 |
upperobt = obtt; |
UInt_t evbeft = 0; |
711 |
upperentry = evbeft-1; |
code = eht->GetCounter(); |
712 |
} else { |
evbeft = code->Get(pctp->Physics); |
713 |
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
if ( evbeft >= 0 ){ |
714 |
evbeft++; |
T->GetEntry(evbeft); |
715 |
T->GetEntry(evbeft); |
ph = eh->GetPscuHeader(); |
716 |
|
t_pktlast = PKT(ph->GetCounter()); |
717 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
718 |
|
if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump |
719 |
|
upperpkt = pktt; |
720 |
|
upperobt = obtt; |
721 |
|
upperentry = evbeft-1; |
722 |
|
} else { |
723 |
|
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
724 |
|
evbeft++; |
725 |
|
T->GetEntry(evbeft); |
726 |
|
ph = eh->GetPscuHeader(); |
727 |
|
t_pktlast = PKT(ph->GetCounter()); |
728 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
729 |
|
}; |
730 |
|
T->GetEntry(evbeft-1); |
731 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
732 |
t_pktlast = PKT(ph->GetCounter()); |
upperpkt = PKT(ph->GetCounter()); |
733 |
t_obtlast = OBT(ph->GetOrbitalTime()); |
upperobt = OBT(ph->GetOrbitalTime()); |
734 |
|
upperentry = evbeft-1; |
735 |
}; |
}; |
|
T->GetEntry(evbeft-1); |
|
|
ph = eh->GetPscuHeader(); |
|
|
upperpkt = PKT(ph->GetCounter()); |
|
|
upperobt = OBT(ph->GetOrbitalTime()); |
|
|
upperentry = evbeft-1; |
|
736 |
}; |
}; |
737 |
|
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
738 |
|
goto kikko; |
739 |
|
// break; |
740 |
|
// |
741 |
}; |
}; |
742 |
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
// |
|
goto kikko; |
|
|
// break; |
|
|
// |
|
743 |
}; |
}; |
744 |
// |
// |
745 |
}; |
kikko: |
746 |
// |
// |
747 |
kikko: |
T->GetEntry(upperentry); |
748 |
// |
code = eh->GetCounter(); |
749 |
T->GetEntry(upperentry); |
lasttrail = code->Get(pctp->RunTrailer); |
750 |
code = eh->GetCounter(); |
lasthead = code->Get(pctp->RunHeader); |
751 |
lasttrail = code->Get(pctp->RunTrailer); |
if ( lasttrail < rtev ){ |
752 |
lasthead = code->Get(pctp->RunHeader); |
rt->GetEntry(lasttrail); |
753 |
if ( lasttrail < rtev ){ |
pht = eht->GetPscuHeader(); |
754 |
rt->GetEntry(lasttrail); |
pktt = PKT(pht->GetCounter()); |
755 |
pht = eht->GetPscuHeader(); |
obtt = OBT(pht->GetOrbitalTime()); |
756 |
pktt = PKT(pht->GetCounter()); |
}; |
757 |
obtt = OBT(pht->GetOrbitalTime()); |
// |
758 |
}; |
if ( lasthead < rhev ){ |
759 |
// |
rh->GetEntry(lasthead); |
760 |
if ( lasthead < rhev ){ |
phh = ehh->GetPscuHeader(); |
761 |
rh->GetEntry(lasthead); |
pkth = PKT(phh->GetCounter()); |
762 |
phh = ehh->GetPscuHeader(); |
obth = OBT(phh->GetOrbitalTime()); |
763 |
pkth = PKT(phh->GetCounter()); |
}; |
764 |
obth = OBT(phh->GetOrbitalTime()); |
// |
765 |
}; |
if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
766 |
// |
if ( pkth > upperpkt && obth > upperobt ){ |
767 |
if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); |
768 |
if ( pkth > upperpkt && obth > upperobt ){ |
upperpkt = pkth; |
769 |
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); |
upperobt = obth; |
770 |
upperpkt = pkth; |
rhev = lasthead+1; |
771 |
upperobt = obth; |
} else { |
772 |
rhev = lasthead+1; |
rhev = lasthead; |
773 |
} else { |
}; |
774 |
rhev = lasthead; |
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
775 |
}; |
// |
776 |
if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
777 |
// |
if ( pktt > upperpkt && obtt > upperobt ){ |
778 |
if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); |
779 |
if ( pktt > upperpkt && obtt > upperobt ){ |
upperpkt = pktt; |
780 |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); |
upperobt = obtt; |
781 |
upperpkt = pktt; |
rtev = lasttrail+1; |
782 |
upperobt = obtt; |
} else { |
783 |
rtev = lasttrail+1; |
rtev = lasttrail; |
784 |
} else { |
}; |
785 |
rtev = lasttrail; |
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
786 |
|
// |
787 |
}; |
}; |
|
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
788 |
// |
// |
789 |
if ( IsDebug() ) printf(" Upper limits are: OBT %lld pkt_num %lld 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); |
790 |
// |
// |
920 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
921 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
922 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
923 |
|
// |
924 |
|
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()); |
925 |
|
// |
926 |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
927 |
// |
// |
928 |
// set DB timezone to UTC |
// set DB timezone to UTC |
934 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
935 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
936 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
937 |
|
oss.str(""); |
938 |
|
oss << "SET wait_timeout=173000;"; |
939 |
|
conn->Query(oss.str().c_str()); |
940 |
// |
// |
941 |
}; |
}; |
942 |
|
|
945 |
*/ |
*/ |
946 |
Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){ |
Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){ |
947 |
// |
// |
948 |
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)); |
if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (UInt_t)(16777214/2)) is %u \n",pkt_num,ppktfirst,(UInt_t)(16777214/2)); |
949 |
// |
// |
950 |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ |
if ( pkt_num < (ppktfirst/2) && ppktfirst > (16777214/2) ){ |
951 |
if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL); |
if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL); |
952 |
return((Long64_t)pkt_num+16777215LL); |
return((Long64_t)pkt_num+16777215LL); |
953 |
}; |
}; |
954 |
// |
// |
955 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( pkt_num > ((Long64_t)ppktfirst*2) && pkt_num > (16777214/2) ){ |
956 |
if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL); |
if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL); |
957 |
return((Long64_t)pkt_num-16777215LL); |
return((Long64_t)pkt_num-16777215LL); |
958 |
}; |
}; |
967 |
*/ |
*/ |
968 |
Long64_t PamelaDBOperations::OBT(UInt_t obt){ |
Long64_t PamelaDBOperations::OBT(UInt_t obt){ |
969 |
// |
// |
970 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max())); |
if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits<UInt_t>::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits<UInt_t>::max()/2)); |
971 |
|
// |
972 |
|
if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
973 |
|
if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
974 |
|
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
975 |
|
}; |
976 |
// |
// |
977 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt > ((Long64_t)pobtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
978 |
|
if ( IsDebug() ) printf(" pobtfirst*2 %lld \n",((Long64_t)pobtfirst*2)); |
979 |
|
if ( IsDebug() ) printf(" rise down pktnum %lld \n", (Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
980 |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
981 |
}; |
}; |
982 |
// |
// |
983 |
|
if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)obt); |
984 |
return((Long64_t)obt); |
return((Long64_t)obt); |
985 |
}; |
}; |
986 |
|
|
1096 |
if ( idr ) return(1); |
if ( idr ) return(1); |
1097 |
// |
// |
1098 |
oss.str(""); |
oss.str(""); |
1099 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
if ( STATIC ){ |
1100 |
<< this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
1101 |
|
<< this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; |
1102 |
|
} else { |
1103 |
|
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')"; |
1104 |
|
}; |
1105 |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1106 |
// |
// |
1107 |
idr = this->SetID_RAW(); |
idr = this->SetID_RAW(); |
1120 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1121 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1122 |
UInt_t t0 = 0; |
UInt_t t0 = 0; |
1123 |
|
Int_t signal = 0; |
1124 |
|
UInt_t idresof = 0; |
1125 |
|
// |
1126 |
|
signal = this->SetUpperLimits(); |
1127 |
// |
// |
1128 |
stringstream oss; |
stringstream oss; |
1129 |
// |
// |
1130 |
if ( this->GetID_RAW() == 0 ) throw -11; |
if ( this->GetID_RAW() == 0 ) throw -11; |
1131 |
// |
// |
1132 |
oss.str(""); |
oss.str(""); |
1133 |
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='" |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
1134 |
<< this->GetRawFile().Data() << "';"; |
<< this->GetRawFile().Data() << "';"; |
1135 |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1136 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1139 |
// |
// |
1140 |
if ( !row ){ |
if ( !row ){ |
1141 |
oss.str(""); |
oss.str(""); |
1142 |
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< " |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1143 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1144 |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1145 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1148 |
if ( !row ) throw -10; |
if ( !row ) throw -10; |
1149 |
}; |
}; |
1150 |
// |
// |
1151 |
|
idresof = (UInt_t)atoll(row->GetField(6)); |
1152 |
|
// |
1153 |
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); |
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); |
1154 |
t0 = (UInt_t)tu.GetSec(); |
t0 = (UInt_t)tu.GetSec(); |
1155 |
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)); |
if ( IsDebug() ) printf(" t0 is %u ti is %s %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),row->GetField(6)); |
1156 |
// |
// |
1157 |
/* |
/* |
1158 |
* Verify that the TIMESYNC have been not already processed |
* Verify that the TIMESYNC have been not already processed |
1174 |
tsync = (UInt_t)atoll(row->GetField(2)); |
tsync = (UInt_t)atoll(row->GetField(2)); |
1175 |
obt0 = (UInt_t)atoll(row->GetField(1)); |
obt0 = (UInt_t)atoll(row->GetField(1)); |
1176 |
// |
// |
1177 |
|
if ( PEDANTIC ) throw -67; |
1178 |
return(1); |
return(1); |
1179 |
}; |
}; |
1180 |
// |
// |
1181 |
TTree *T = 0; |
TTree *T = 0; |
|
Int_t signal = 0; |
|
1182 |
// |
// |
1183 |
UInt_t nevent = 0; |
UInt_t nevent = 0; |
1184 |
UInt_t recEntries = 0; |
UInt_t recEntries = 0; |
1344 |
// |
// |
1345 |
if ( !existsts && obt0 ){ // insert timesync by hand |
if ( !existsts && obt0 ){ // insert timesync by hand |
1346 |
// |
// |
1347 |
|
if ( PEDANTIC ) throw -68; |
1348 |
if ( IsDebug() ) printf(" No incl mcmd \n"); |
if ( IsDebug() ) printf(" No incl mcmd \n"); |
1349 |
signal = 30; |
signal = 30; |
1350 |
// |
// |
1360 |
if ( !existsts ) throw -3; |
if ( !existsts ) throw -3; |
1361 |
// |
// |
1362 |
oss.str(""); |
oss.str(""); |
1363 |
oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC) VALUES ('" |
oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC,ID_RESURS_OFFSET) VALUES ('" |
1364 |
<< this->GetID_RAW() << "','"//224'" |
<< this->GetID_RAW() << "','"//224'" |
1365 |
<< dec << (UInt_t)TYPE << "','" |
<< dec << (UInt_t)TYPE << "','" |
1366 |
<< dec << (UInt_t)OBT << "','" |
<< dec << (UInt_t)OBT << "','" |
1367 |
<< dec << (UInt_t)TSYNC << "');"; |
<< dec << (UInt_t)TSYNC << "','" |
1368 |
|
<< dec << (UInt_t)idresof << "');"; |
1369 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
1370 |
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()); |
1371 |
|
if ( conn->GetErrorCode() ){ |
1372 |
|
printf(" OK, you got an error because the database structure you are using is not up to date\n Using backward compability code, hence you can continue safetly \n"); |
1373 |
|
oss.str(""); |
1374 |
|
oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC) VALUES ('" |
1375 |
|
<< this->GetID_RAW() << "','"//224'" |
1376 |
|
<< dec << (UInt_t)TYPE << "','" |
1377 |
|
<< dec << (UInt_t)OBT << "','" |
1378 |
|
<< dec << (UInt_t)TSYNC << "');"; |
1379 |
|
conn->Query(oss.str().c_str()); |
1380 |
|
if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str()); |
1381 |
|
}; |
1382 |
// |
// |
1383 |
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
1384 |
|
// |
1385 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
1386 |
// |
// |
1387 |
tsync = TSYNC; |
tsync = TSYNC; |
1402 |
UInt_t idtimesync = 0; |
UInt_t idtimesync = 0; |
1403 |
// |
// |
1404 |
oss.str(""); |
oss.str(""); |
1405 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
if ( STATIC ){ |
1406 |
<< " LEFT JOIN GL_ROOT " |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1407 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
<< " LEFT JOIN GL_ROOT " |
1408 |
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1409 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
1410 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1411 |
|
} else { |
1412 |
|
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1413 |
|
<< " LEFT JOIN GL_ROOT " |
1414 |
|
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1415 |
|
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
1416 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1417 |
|
}; |
1418 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1419 |
// |
// |
1420 |
if ( !result ) throw -12; |
if ( !result ) throw -12; |
1441 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
1442 |
// |
// |
1443 |
oss.str(""); |
oss.str(""); |
1444 |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
if ( STATIC ){ |
1445 |
<< this->GetID_RAW() << "', '" << idtimesync << "', '" << this->GetRootPath().Data() << "', '" << this->GetRootFile().Data() << "')"; |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
1446 |
|
<< this->GetID_RAW() << "', '" << idtimesync << "', '" << this->GetRootPath().Data() << "', '" << this->GetRootFile().Data() << "')"; |
1447 |
|
} else { |
1448 |
|
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
1449 |
|
<< this->GetID_RAW() << "', '" << idtimesync << "', '$PAM_L0', '" << this->GetRootFile().Data() << "')"; |
1450 |
|
}; |
1451 |
// |
// |
1452 |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
1453 |
// |
// |
1474 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1475 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1476 |
oss.str(""); |
oss.str(""); |
1477 |
oss << "SELECT ID, BOOT_NUMBER FROM GL_RAW WHERE " |
if ( STATIC ){ |
1478 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
oss << "SELECT ID, BOOT_NUMBER FROM GL_RAW WHERE " |
1479 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
1480 |
|
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
1481 |
|
} else { |
1482 |
|
oss << "SELECT ID, BOOT_NUMBER FROM GL_RAW WHERE " |
1483 |
|
<< " PATH = '$PAM_RAW' AND " |
1484 |
|
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
1485 |
|
}; |
1486 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1487 |
// |
// |
1488 |
if ( !result ) throw -4;; |
if ( !result ) throw -4;; |
1572 |
// |
// |
1573 |
Int_t sgn = 0; |
Int_t sgn = 0; |
1574 |
// |
// |
1575 |
if ( !found ){ |
if ( !found && !BOOTNO ){ |
1576 |
throw -29; |
throw -29; |
1577 |
} else { |
} else { |
1578 |
if ( afound ){ |
if ( afound ){ |
1601 |
stringstream oss; |
stringstream oss; |
1602 |
oss.str(""); |
oss.str(""); |
1603 |
// |
// |
1604 |
signal = this->SetUpperLimits(); |
// signal = this->SetUpperLimits(); |
1605 |
// |
// |
1606 |
// loop on runheader and runtrailer events |
// loop on runheader and runtrailer events |
1607 |
// |
// |
1619 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
1620 |
rt->SetBranchAddress("Header", &eht); |
rt->SetBranchAddress("Header", &eht); |
1621 |
// |
// |
1622 |
|
TTree *T = (TTree*)file->Get("Physics"); |
1623 |
|
if ( !T || T->IsZombie() ) throw -16; |
1624 |
|
EventHeader *eh = 0; |
1625 |
|
T->SetBranchAddress("Header", &eh); |
1626 |
|
// |
1627 |
|
if ( !(rh->GetEntries()) && !(rt->GetEntries()) && !(T->GetEntries()) ) return(16); |
1628 |
|
// |
1629 |
UInt_t obtt = 0; |
UInt_t obtt = 0; |
1630 |
UInt_t obth = 0; |
UInt_t obth = 0; |
1631 |
UInt_t pktt = 0; |
UInt_t pktt = 0; |
1659 |
// |
// |
1660 |
if ( !ptt && !(ptht+1) ){ |
if ( !ptt && !(ptht+1) ){ |
1661 |
// |
// |
1662 |
if ( IsDebug() ) printf(" Piece of run at the beginning of the file %i %i %i \n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Piece of run at the beginning of the file %u %u %u \n",ptht,pth,ptt); |
1663 |
// |
// |
1664 |
this->HandleRunFragments(true,false,0,(evbeft-1)); |
this->HandleRunFragments(true,false,0,(evbeft-1)); |
1665 |
// |
// |
1666 |
// |
// |
1667 |
} else if ( pth == ptht ){ |
} else if ( pth == ptht ){ |
1668 |
// |
// |
1669 |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Missing header %u %u %u\n",ptht,pth,ptt); |
1670 |
// |
// |
1671 |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1672 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1675 |
rt->GetEntry(ptt); |
rt->GetEntry(ptt); |
1676 |
pht = eht->GetPscuHeader(); |
pht = eht->GetPscuHeader(); |
1677 |
// |
// |
1678 |
if ( IsDebug() ) printf(" Try to find the beginning of a run which has only the runtrailer %i %i %i \n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Try to find the beginning of a run which has only the runtrailer %u %u %u \n",ptht,pth,ptt); |
1679 |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %i %i %i \n",pkth,obth,obtt); |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %u %u %u \n",pkth,obth,obtt); |
1680 |
// |
// |
1681 |
this->HandleMissingHoT(true,false,evbefh,evbeft-1); |
this->HandleMissingHoT(true,false,evbefh,evbeft-1); |
1682 |
// |
// |
1683 |
} else { |
} else { |
1684 |
// |
// |
1685 |
if ( IsDebug() ) printf(" Could be a good run, we have a runheader followed by a runtrailer %i %i %i\n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Could be a good run, we have a runheader followed by a runtrailer %u %u %u\n",ptht,pth,ptt); |
1686 |
// |
// |
1687 |
rh->GetEntry(ptht); |
rh->GetEntry(ptht); |
1688 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
1690 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
1691 |
cod = ehh->GetCounter(); |
cod = ehh->GetCounter(); |
1692 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
1693 |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %i %i %i \n",pkth,obth,obtt); |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %u %u %u \n",pkth,obth,obtt); |
1694 |
// |
// |
1695 |
// handle this run |
// handle this run |
1696 |
// |
// |
1700 |
// |
// |
1701 |
if ( PKT(pkth)>PKT(pktfirst) && OBT(obth)>OBT(obtfirst) && !ptt ){ |
if ( PKT(pkth)>PKT(pktfirst) && OBT(obth)>OBT(obtfirst) && !ptt ){ |
1702 |
// |
// |
1703 |
if ( IsDebug() ) printf(" Piece of run at the beginning of the file WITH NO RUNTRAILER \n"); |
if ( IsDebug() ) printf(" Piece of run at the beginning of the file WITH NO RUNTRAILER evbefh = %u \n",evbefh); |
|
// |
|
|
this->HandleRunFragments(true,true,0,(evbefh-1)); |
|
1704 |
// |
// |
1705 |
|
if ( evbefh == 0 ) { |
1706 |
|
// |
1707 |
|
signal = 8; |
1708 |
|
if ( IsDebug() ) printf(" Not supported yet: run with no events, no runtrailer, no runheader \n"); |
1709 |
|
// |
1710 |
|
} else { |
1711 |
|
// |
1712 |
|
this->HandleRunFragments(true,true,0,(evbefh-1)); |
1713 |
|
// |
1714 |
|
}; |
1715 |
}; |
}; |
1716 |
// |
// |
1717 |
// |
// |
1718 |
if ( (ptht - pth) > 1 ){ |
if ( (ptht - pth) > 1 ){ |
1719 |
// |
// |
1720 |
if ( IsDebug() ) printf(" Missing runtrailers! \n"); |
if ( IsDebug() ) printf(" Missing runtrailers! \n"); |
1721 |
if ( IsDebug() ) printf(" Attention there is a jump in the runheader counter %i %i %i \n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Attention there is a jump in the runheader counter %u %u %u \n",ptht,pth,ptt); |
1722 |
// is not the consecutive header |
// is not the consecutive header |
1723 |
while ( pth != ptht ){ |
while ( pth != ptht ){ |
1724 |
// |
// |
1739 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
1740 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
1741 |
// |
// |
1742 |
if ( IsDebug() ) printf(" Try to find the end of a run which has only the runheader %i %i %i \n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Try to find the end of a run which has only the runheader %u %u %u \n",ptht,pth,ptt); |
1743 |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %i %i %i \n",pkth,obth,obtt); |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %u %u %u \n",pkth,obth,obtt); |
1744 |
// |
// |
1745 |
this->HandleMissingHoT(false,true,evbefh,evbeft-1); |
this->HandleMissingHoT(false,true,evbefh,evbeft-1); |
1746 |
// |
// |
1749 |
} else if ( !(ptht - pth) ){ |
} else if ( !(ptht - pth) ){ |
1750 |
// |
// |
1751 |
if ( IsDebug() ) printf(" Missing runheader! \n"); |
if ( IsDebug() ) printf(" Missing runheader! \n"); |
1752 |
if ( IsDebug() ) printf(" Attention! the runheader counter did not changed %i %i %i \n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Attention! the runheader counter did not changed %u %u %u \n",ptht,pth,ptt); |
1753 |
if ( IsDebug() ) printf(" The run should have already been handled by HandleRun() \n"); |
if ( IsDebug() ) printf(" The run should have already been handled by HandleRun() \n"); |
1754 |
// |
// |
1755 |
} else { |
} else { |
1770 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
1771 |
cod = ehh->GetCounter(); |
cod = ehh->GetCounter(); |
1772 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
1773 |
if ( IsDebug() ) printf(" Piece of run at the end of file %i %i %i \n",pkth,obth,obtt); |
if ( IsDebug() ) printf(" Piece of run at the end of file %u %u %u \n",pkth,obth,obtt); |
1774 |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''' %i %i %i \n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''' %u %u %u \n",ptht,pth,ptt); |
1775 |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''' %i \n",rhev); |
if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''' %u \n",rhev); |
1776 |
// |
// |
1777 |
this->HandleRunFragments(false,true,evbefh,upperentry); |
this->HandleRunFragments(false,true,evbefh,upperentry); |
1778 |
} else { |
} else { |
1820 |
// ( runhead_time <= _our_runhead_time && runtrail_time >= _our_runtrail_time) && |
// ( runhead_time <= _our_runhead_time && runtrail_time >= _our_runtrail_time) && |
1821 |
// ( runhead_obt <= _our_runheadobt || runhead_pkt <= _our_runheadpkt ) && |
// ( runhead_obt <= _our_runheadobt || runhead_pkt <= _our_runheadpkt ) && |
1822 |
// ( runtrail_obt <= _our_runtrailobt || runtrail_pkt <= _our_runtrailpkt ) ) |
// ( runtrail_obt <= _our_runtrailobt || runtrail_pkt <= _our_runtrailpkt ) ) |
1823 |
|
// || |
1824 |
|
// ( runhead_time = _our_runhead_time && runtrail_time = _our_runtrail_time && nevents > 100 ) |
1825 |
|
// ) |
1826 |
|
// || |
1827 |
|
// ( runhead_time = _our_runhead_time && runtrail_time > _our_runtrail_time && nevents > 100 ) |
1828 |
|
// ) |
1829 |
|
// || |
1830 |
|
// ( runhead_time < _our_runhead_time && runtrail_time = _our_runtrail_time && nevents > 100 ) |
1831 |
// ) |
// ) |
1832 |
// |
// |
1833 |
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " |
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " |
1843 |
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
1844 |
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
1845 |
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
1846 |
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") OR " |
1847 |
|
<< " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // these two lines in a certain way disable the patch below... |
1848 |
|
<< " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR" // |
1849 |
|
<< " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // |
1850 |
|
<< " RUNTRAILER_TIME>" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR" // |
1851 |
|
<< " (RUNHEADER_TIME<" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // |
1852 |
|
<< " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100)" // |
1853 |
|
<< " ));"; |
1854 |
// |
// |
1855 |
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
1856 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1872 |
// |
// |
1873 |
// the run has already been inserted |
// the run has already been inserted |
1874 |
// |
// |
1875 |
// return(true); //<<<<<<<<<<<<<<<<<<<<<<<< patch follows, uncomment here |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
1876 |
|
return(true); //<<<<<<<<<<<<<<<<<<<<<<<< patch follows, uncomment here |
1877 |
// |
// |
1878 |
// PATCH! |
// PATCH! |
1879 |
// we keep the processing run if (in order of growing importance) 1) we have the runtrailer while the old run doesn't have it 2) we have the runheader |
// we keep the processing run if (in order of growing importance) 1) we have the runtrailer while the old run doesn't have it 2) we have the runheader |
2051 |
// |
// |
2052 |
} else { |
} else { |
2053 |
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
2054 |
|
if ( PEDANTIC ) throw -69; |
2055 |
return; |
return; |
2056 |
}; |
}; |
2057 |
// |
// |
2189 |
ULong64_t aobt = OBT(glrun1->GetRUNTRAILER_OBT()); |
ULong64_t aobt = OBT(glrun1->GetRUNTRAILER_OBT()); |
2190 |
UInt_t bpkt = PKT(glrun->GetRUNHEADER_PKT()); |
UInt_t bpkt = PKT(glrun->GetRUNHEADER_PKT()); |
2191 |
ULong64_t bobt = OBT(glrun->GetRUNHEADER_OBT()); |
ULong64_t bobt = OBT(glrun->GetRUNHEADER_OBT()); |
2192 |
if ( IsDebug() ) printf(" Check overlapping events: %i %i %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); |
if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); |
2193 |
TTree *T= 0; |
TTree *T= 0; |
2194 |
T = (TTree*)file->Get("Physics"); |
T = (TTree*)file->Get("Physics"); |
2195 |
if ( !T || T->IsZombie() ) throw -16; |
if ( !T || T->IsZombie() ) throw -16; |
2202 |
bpkt = PKT(ph->GetCounter()); |
bpkt = PKT(ph->GetCounter()); |
2203 |
bobt = OBT(ph->GetOrbitalTime()); |
bobt = OBT(ph->GetOrbitalTime()); |
2204 |
firstev++; |
firstev++; |
2205 |
|
if ( PEDANTIC ) throw -71; |
2206 |
}; |
}; |
2207 |
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: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); |
2208 |
// |
// |
2209 |
glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); |
glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); |
2210 |
glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); |
glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); |
2387 |
ULong64_t aobt = OBT(glrun->GetRUNTRAILER_OBT()); |
ULong64_t aobt = OBT(glrun->GetRUNTRAILER_OBT()); |
2388 |
UInt_t bpkt = PKT(glrun1->GetRUNHEADER_PKT()); |
UInt_t bpkt = PKT(glrun1->GetRUNHEADER_PKT()); |
2389 |
ULong64_t bobt = OBT(glrun1->GetRUNHEADER_OBT()); |
ULong64_t bobt = OBT(glrun1->GetRUNHEADER_OBT()); |
2390 |
if ( IsDebug() ) printf(" Check overlapping events: %i %i %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); |
if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); |
2391 |
TTree *T= 0; |
TTree *T= 0; |
2392 |
T = (TTree*)file->Get("Physics"); |
T = (TTree*)file->Get("Physics"); |
2393 |
if ( !T || T->IsZombie() ) throw -16; |
if ( !T || T->IsZombie() ) throw -16; |
2400 |
apkt = PKT(ph->GetCounter()); |
apkt = PKT(ph->GetCounter()); |
2401 |
aobt = OBT(ph->GetOrbitalTime()); |
aobt = OBT(ph->GetOrbitalTime()); |
2402 |
lastev--; |
lastev--; |
2403 |
|
if ( PEDANTIC ) throw -72; |
2404 |
}; |
}; |
2405 |
if ( IsDebug() ) printf(" Check overlapping events done: %i %i %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); |
if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); |
2406 |
// |
// |
2407 |
glrun->SetEV_TO(lastev); |
glrun->SetEV_TO(lastev); |
2408 |
glrun->SetNEVENTS(lastev-firstev+1); |
glrun->SetNEVENTS(lastev-firstev+1); |
2487 |
// |
// |
2488 |
if ( row ){ |
if ( row ){ |
2489 |
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"); |
2490 |
|
if ( PEDANTIC ) throw -70; |
2491 |
} else { |
} else { |
2492 |
if ( NoFrag() ){ |
if ( NoFrag() ){ |
2493 |
glrun->SetID_RUN_FRAG(glrun->GetID()); |
glrun->SetID_RUN_FRAG(glrun->GetID()); |
3010 |
fromtime = this->GetAbsTime(ph->GetOrbitalTime()); |
fromtime = this->GetAbsTime(ph->GetOrbitalTime()); |
3011 |
if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){ |
if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){ |
3012 |
// |
// |
3013 |
if ( IsDebug() ) printf(" Calo calibration for section %i at time %i obt %i pkt %i \n",section,fromtime,obt,pkt); |
if ( IsDebug() ) printf(" Calo calibration for section %i at time %u obt %u pkt %u \n",section,fromtime,obt,pkt); |
3014 |
// |
// |
3015 |
// check if the calibration has already been inserted |
// check if the calibration has already been inserted |
3016 |
// |
// |
3031 |
if ( row ){ |
if ( row ){ |
3032 |
// |
// |
3033 |
if ( IsDebug() ) printf(" Calo calibration already inserted in the DB\n"); |
if ( IsDebug() ) printf(" Calo calibration already inserted in the DB\n"); |
3034 |
|
if ( PEDANTIC ) throw -73; |
3035 |
// |
// |
3036 |
} else { |
} else { |
3037 |
// |
// |
3056 |
// |
// |
3057 |
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); |
3058 |
if ( fromtime < 1150871000 ){ //1150866904 |
if ( fromtime < 1150871000 ){ //1150866904 |
3059 |
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime); |
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %u \n",fromtime); |
3060 |
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 |
3061 |
}; |
}; |
3062 |
// |
// |
3118 |
// |
// |
3119 |
} else { |
} else { |
3120 |
// |
// |
3121 |
if ( IsDebug() ) printf(" Repetead calo calibration for section %i at time %i obt %i pkt %i \n",section,fromtime,obt,pkt); |
if ( IsDebug() ) printf(" Repeated calo calibration for section %i at time %u obt %u pkt %u \n",section,fromtime,obt,pkt); |
3122 |
|
if ( PEDANTIC ) throw -74; |
3123 |
// |
// |
3124 |
}; |
}; |
3125 |
// |
// |
3130 |
return(0); |
return(0); |
3131 |
}; |
}; |
3132 |
|
|
3133 |
|
|
3134 |
|
/** |
3135 |
|
* Scan calorimeter calibrations packets, fill the GL_CALO_CALIB table |
3136 |
|
*/ |
3137 |
|
Int_t PamelaDBOperations::insertCALOPULSE_CALIB(){ |
3138 |
|
// |
3139 |
|
TSQLResult *result = 0; |
3140 |
|
TSQLRow *row = 0; |
3141 |
|
// |
3142 |
|
stringstream oss; |
3143 |
|
oss.str(""); |
3144 |
|
// |
3145 |
|
oss << " DESCRIBE GL_CALOPULSE_CALIB;"; |
3146 |
|
if ( IsDebug() ) printf(" Check if the GL_CALOPULSE_CALIB table exists: query is \n %s \n",oss.str().c_str()); |
3147 |
|
result = conn->Query(oss.str().c_str()); |
3148 |
|
// |
3149 |
|
if ( conn->GetErrorCode() ){ |
3150 |
|
if ( IsDebug() ) printf(" The GL_CALOPULSE_CALIB table does not exists! \n"); |
3151 |
|
throw -30; |
3152 |
|
}; |
3153 |
|
// |
3154 |
|
// CaloPulse1 |
3155 |
|
// |
3156 |
|
CalibCalPulse1Event *cp1 = 0; |
3157 |
|
TTree *tr = 0; |
3158 |
|
EventHeader *eh = 0; |
3159 |
|
PscuHeader *ph = 0; |
3160 |
|
// |
3161 |
|
UInt_t nevents = 0; |
3162 |
|
UInt_t fromtime = 0; |
3163 |
|
UInt_t totime = 0; |
3164 |
|
UInt_t obt = 0; |
3165 |
|
UInt_t pkt = 0; |
3166 |
|
// |
3167 |
|
tr = (TTree*)file->Get("CalibCalPulse1"); |
3168 |
|
if ( !tr || tr->IsZombie() ) throw -31; |
3169 |
|
// |
3170 |
|
tr->SetBranchAddress("CalibCalPulse1", &cp1); |
3171 |
|
tr->SetBranchAddress("Header", &eh); |
3172 |
|
nevents = tr->GetEntries(); |
3173 |
|
// |
3174 |
|
if ( nevents > 0 ){ |
3175 |
|
// |
3176 |
|
for (UInt_t i=0; i < nevents; i++){ |
3177 |
|
tr->GetEntry(i); |
3178 |
|
for (UInt_t section = 0; section < 4; section++){ |
3179 |
|
// |
3180 |
|
if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){ |
3181 |
|
valid = 1; |
3182 |
|
if ( cp1->pperror[section] ) valid = 0; |
3183 |
|
ph = eh->GetPscuHeader(); |
3184 |
|
obt = ph->GetOrbitalTime(); |
3185 |
|
pkt = ph->GetCounter(); |
3186 |
|
fromtime = this->GetAbsTime(ph->GetOrbitalTime()); |
3187 |
|
if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){ |
3188 |
|
// |
3189 |
|
if ( IsDebug() ) printf(" Calo pulse1 calibration for section %i at time %u obt %u pkt %u \n",section,fromtime,obt,pkt); |
3190 |
|
// |
3191 |
|
// check if the calibration has already been inserted |
3192 |
|
// |
3193 |
|
oss.str(""); |
3194 |
|
oss << " SELECT ID FROM GL_CALOPULSE_CALIB WHERE " |
3195 |
|
<< " SECTION = "<< section << " AND " |
3196 |
|
<< " PULSE_AMPLITUDE = 0 AND " |
3197 |
|
<< " BOOT_NUMBER = "<< this->GetBOOTnumber() << " AND " |
3198 |
|
<< " OBT = "<< obt << " AND " |
3199 |
|
<< " PKT = "<< pkt << ";"; |
3200 |
|
// |
3201 |
|
if ( IsDebug() ) printf(" Check if the calo pulse1 calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
3202 |
|
result = conn->Query(oss.str().c_str()); |
3203 |
|
// |
3204 |
|
if ( !result ) throw -4; |
3205 |
|
// |
3206 |
|
row = result->Next(); |
3207 |
|
// |
3208 |
|
if ( row ){ |
3209 |
|
// |
3210 |
|
if ( IsDebug() ) printf(" Calo pulse1 calibration already inserted in the DB\n"); |
3211 |
|
if ( PEDANTIC ) throw -75; |
3212 |
|
// |
3213 |
|
} else { |
3214 |
|
// |
3215 |
|
// we have to insert a new calibration, check where to place it |
3216 |
|
// |
3217 |
|
oss.str(""); |
3218 |
|
oss << " SELECT ID,TO_TIME FROM GL_CALOPULSE_CALIB WHERE " |
3219 |
|
<< " SECTION = "<< section << " AND " |
3220 |
|
<< " PULSE_AMPLITUDE = 0 AND " |
3221 |
|
<< " SECTION = "<< section << " AND " |
3222 |
|
<< " FROM_TIME < "<< fromtime << " AND " |
3223 |
|
<< " TO_TIME > "<< fromtime << ";"; |
3224 |
|
// |
3225 |
|
if ( IsDebug() ) printf(" Check where to place the pulse1 calo calibration: query is \n %s \n",oss.str().c_str()); |
3226 |
|
result = conn->Query(oss.str().c_str()); |
3227 |
|
// |
3228 |
|
if ( !result ) throw -4; |
3229 |
|
// |
3230 |
|
row = result->Next(); |
3231 |
|
// |
3232 |
|
if ( !row ){ |
3233 |
|
// |
3234 |
|
// no calibrations in the db contain our calibration |
3235 |
|
// |
3236 |
|
if ( IsDebug() ) printf(" Pulse1 calibration with fromtime lower than others to be inserted in the DB for section %i \n",section); |
3237 |
|
if ( fromtime < 1150871000 ){ //1150866904 |
3238 |
|
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %u \n",fromtime); |
3239 |
|
fromtime = 0;// the first flight calibration was taken at about 1156429100 s, this line allow to analyze first runs in raw mode |
3240 |
|
}; |
3241 |
|
// |
3242 |
|
oss.str(""); |
3243 |
|
oss << " SELECT FROM_TIME FROM GL_CALOPULSE_CALIB WHERE " |
3244 |
|
<< " PULSE_AMPLITUDE = 0 AND " |
3245 |
|
<< " SECTION = "<< section << " AND " |
3246 |
|
<< " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
3247 |
|
// |
3248 |
|
if ( IsDebug() ) printf(" Check the upper limit for pulse1 calibration: query is \n %s \n",oss.str().c_str()); |
3249 |
|
result = conn->Query(oss.str().c_str()); |
3250 |
|
// |
3251 |
|
if ( !result ) throw -4; |
3252 |
|
// |
3253 |
|
row = result->Next(); |
3254 |
|
if ( !row ){ |
3255 |
|
totime = numeric_limits<UInt_t>::max(); |
3256 |
|
} else { |
3257 |
|
totime = (UInt_t)atoll(row->GetField(0)); |
3258 |
|
}; |
3259 |
|
// |
3260 |
|
} else { |
3261 |
|
// |
3262 |
|
// determine upper and lower limits and make space for the new calibration |
3263 |
|
// |
3264 |
|
totime = (UInt_t)atoll(row->GetField(1)); |
3265 |
|
// |
3266 |
|
oss.str(""); |
3267 |
|
oss << " UPDATE GL_CALOPULSE_CALIB SET " |
3268 |
|
<< " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ |
3269 |
|
<< " ID = "<< row->GetField(0) << ";"; |
3270 |
|
// |
3271 |
|
if ( IsDebug() ) printf(" Make space for the new pulse1 calibration: query is \n %s \n",oss.str().c_str()); |
3272 |
|
result = conn->Query(oss.str().c_str()); |
3273 |
|
// |
3274 |
|
if ( !result ) throw -4; |
3275 |
|
// |
3276 |
|
}; |
3277 |
|
// |
3278 |
|
oss.str(""); |
3279 |
|
oss << " INSERT INTO GL_CALOPULSE_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,SECTION,PULSED_STRIP,PULSE_AMPLITUDE,OBT,PKT,BOOT_NUMBER,VALIDATION) " |
3280 |
|
<< " VALUES (NULL,' " |
3281 |
|
<< idroot << "','" |
3282 |
|
<< i << "','" |
3283 |
|
<< fromtime << "','" |
3284 |
|
<< totime << "','" |
3285 |
|
<< section << "',NULL,'0','" |
3286 |
|
<< obt << "','" |
3287 |
|
<< pkt << "','" |
3288 |
|
<< this->GetBOOTnumber() << "','" |
3289 |
|
<< valid << "');"; |
3290 |
|
// |
3291 |
|
if ( IsDebug() ) printf(" Insert the new pulse1 calibration: query is \n %s \n",oss.str().c_str()); |
3292 |
|
// |
3293 |
|
result = conn->Query(oss.str().c_str()); |
3294 |
|
// |
3295 |
|
if ( !result ) throw -4; |
3296 |
|
// |
3297 |
|
}; |
3298 |
|
// |
3299 |
|
} else { |
3300 |
|
// |
3301 |
|
if ( IsDebug() ) printf(" Repeated pulse1 calo calibration for section %i at time %u obt %u pkt %u \n",section,fromtime,obt,pkt); |
3302 |
|
if ( PEDANTIC ) throw -76; |
3303 |
|
// |
3304 |
|
}; |
3305 |
|
// |
3306 |
|
}; |
3307 |
|
}; |
3308 |
|
}; |
3309 |
|
}; |
3310 |
|
// |
3311 |
|
// CaloPulse2 |
3312 |
|
// |
3313 |
|
tr->Reset(); |
3314 |
|
CalibCalPulse2Event *cp2 = 0; |
3315 |
|
tr = 0; |
3316 |
|
// |
3317 |
|
nevents = 0; |
3318 |
|
fromtime = 0; |
3319 |
|
totime = 0; |
3320 |
|
obt = 0; |
3321 |
|
pkt = 0; |
3322 |
|
// |
3323 |
|
tr = (TTree*)file->Get("CalibCalPulse2"); |
3324 |
|
if ( !tr || tr->IsZombie() ) throw -32; |
3325 |
|
// |
3326 |
|
tr->SetBranchAddress("CalibCalPulse2", &cp2); |
3327 |
|
tr->SetBranchAddress("Header", &eh); |
3328 |
|
nevents = tr->GetEntries(); |
3329 |
|
// |
3330 |
|
if ( nevents > 0 ){ |
3331 |
|
// |
3332 |
|
for (UInt_t i=0; i < nevents; i++){ |
3333 |
|
tr->GetEntry(i); |
3334 |
|
for (UInt_t section = 0; section < 4; section++){ |
3335 |
|
// |
3336 |
|
if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){ |
3337 |
|
valid = 1; |
3338 |
|
if ( cp2->pperror[section] ) valid = 0; |
3339 |
|
ph = eh->GetPscuHeader(); |
3340 |
|
obt = ph->GetOrbitalTime(); |
3341 |
|
pkt = ph->GetCounter(); |
3342 |
|
fromtime = this->GetAbsTime(ph->GetOrbitalTime()); |
3343 |
|
if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){ |
3344 |
|
// |
3345 |
|
if ( IsDebug() ) printf(" Calo pulse2 calibration for section %i at time %u obt %u pkt %u \n",section,fromtime,obt,pkt); |
3346 |
|
// |
3347 |
|
// check if the calibration has already been inserted |
3348 |
|
// |
3349 |
|
oss.str(""); |
3350 |
|
oss << " SELECT ID FROM GL_CALOPULSE_CALIB WHERE " |
3351 |
|
<< " SECTION = "<< section << " AND " |
3352 |
|
<< " PULSE_AMPLITUDE != 0 AND " |
3353 |
|
<< " BOOT_NUMBER = "<< this->GetBOOTnumber() << " AND " |
3354 |
|
<< " OBT = "<< obt << " AND " |
3355 |
|
<< " PKT = "<< pkt << ";"; |
3356 |
|
// |
3357 |
|
if ( IsDebug() ) printf(" Check if the calo pulse2 calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
3358 |
|
result = conn->Query(oss.str().c_str()); |
3359 |
|
// |
3360 |
|
if ( !result ) throw -4; |
3361 |
|
// |
3362 |
|
row = result->Next(); |
3363 |
|
// |
3364 |
|
if ( row ){ |
3365 |
|
// |
3366 |
|
if ( IsDebug() ) printf(" Calo pulse2 calibration already inserted in the DB\n"); |
3367 |
|
if ( PEDANTIC ) throw -77; |
3368 |
|
// |
3369 |
|
} else { |
3370 |
|
// |
3371 |
|
// we have to insert a new calibration |
3372 |
|
// |
3373 |
|
// |
3374 |
|
// Determine the amplitude of the pulse |
3375 |
|
// |
3376 |
|
UInt_t pampli = 1; |
3377 |
|
UInt_t pstrip = 0; |
3378 |
|
UInt_t se = 0; |
3379 |
|
if ( section == 1 ) se = 2; |
3380 |
|
if ( section == 2 ) se = 3; |
3381 |
|
if ( section == 3 ) se = 1; |
3382 |
|
for (Int_t ii=0;ii<16;ii++){ |
3383 |
|
if ( cp2->calpuls[se][0][ii] > 10000. ){ |
3384 |
|
pampli = 2; |
3385 |
|
pstrip = ii; |
3386 |
|
}; |
3387 |
|
}; |
3388 |
|
if ( pampli == 1 ){ |
3389 |
|
Bool_t found = false; |
3390 |
|
Float_t delta=0.; |
3391 |
|
UInt_t cstr = 0; |
3392 |
|
while ( !found && cstr < 16 ){ |
3393 |
|
for (Int_t ii=0;ii<16;ii++){ |
3394 |
|
delta = cp2->calpuls[se][0][ii] - cp2->calpuls[se][0][cstr]; |
3395 |
|
if ( IsDebug() ) printf(" cstr is %u ii is %i delta is %f \n",cstr,ii,delta); |
3396 |
|
if ( delta > 500. ){ |
3397 |
|
pampli = 1; |
3398 |
|
pstrip = ii; |
3399 |
|
found = true; |
3400 |
|
if ( IsDebug() ) printf(" FOUND cstr is %u ii is %i delta is %f \n",cstr,ii,delta); |
3401 |
|
}; |
3402 |
|
}; |
3403 |
|
cstr++; |
3404 |
|
}; |
3405 |
|
if ( !found ) pstrip = 100; |
3406 |
|
}; |
3407 |
|
if ( IsDebug() ) printf(" The amplitude of the pulser is %u (where 1 = low pulse, 2 = high pulse), pulsed strip is %u \n",pampli,pstrip); |
3408 |
|
// |
3409 |
|
// we have to insert a new calibration, check where to place it |
3410 |
|
// |
3411 |
|
oss.str(""); |
3412 |
|
oss << " SELECT ID,TO_TIME FROM GL_CALOPULSE_CALIB WHERE " |
3413 |
|
<< " SECTION = "<< section << " AND " |
3414 |
|
<< " PULSE_AMPLITUDE = " << pampli << " AND " |
3415 |
|
<< " SECTION = "<< section << " AND " |
3416 |
|
<< " FROM_TIME < "<< fromtime << " AND " |
3417 |
|
<< " TO_TIME > "<< fromtime << ";"; |
3418 |
|
// |
3419 |
|
if ( IsDebug() ) printf(" Check where to place the pulse2 calo calibration: query is \n %s \n",oss.str().c_str()); |
3420 |
|
result = conn->Query(oss.str().c_str()); |
3421 |
|
// |
3422 |
|
if ( !result ) throw -4; |
3423 |
|
// |
3424 |
|
row = result->Next(); |
3425 |
|
// |
3426 |
|
if ( !row ){ |
3427 |
|
// |
3428 |
|
// no calibrations in the db contain our calibration |
3429 |
|
// |
3430 |
|
if ( IsDebug() ) printf(" Pulse2 calibration with fromtime lower than others to be inserted in the DB for section %i \n",section); |
3431 |
|
if ( fromtime < 1150871000 ){ //1150866904 |
3432 |
|
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %u \n",fromtime); |
3433 |
|
fromtime = 0;// the first flight calibration was taken at about 1156429100 s, this line allow to analyze first runs in raw mode |
3434 |
|
}; |
3435 |
|
// |
3436 |
|
oss.str(""); |
3437 |
|
oss << " SELECT FROM_TIME FROM GL_CALOPULSE_CALIB WHERE " |
3438 |
|
<< " PULSE_AMPLITUDE = " << pampli << " AND " |
3439 |
|
<< " SECTION = "<< section << " AND " |
3440 |
|
<< " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
3441 |
|
// |
3442 |
|
if ( IsDebug() ) printf(" Check the upper limit for pulse2 calibration: query is \n %s \n",oss.str().c_str()); |
3443 |
|
result = conn->Query(oss.str().c_str()); |
3444 |
|
// |
3445 |
|
if ( !result ) throw -4; |
3446 |
|
// |
3447 |
|
row = result->Next(); |
3448 |
|
if ( !row ){ |
3449 |
|
totime = numeric_limits<UInt_t>::max(); |
3450 |
|
} else { |
3451 |
|
totime = (UInt_t)atoll(row->GetField(0)); |
3452 |
|
}; |
3453 |
|
// |
3454 |
|
} else { |
3455 |
|
// |
3456 |
|
// determine upper and lower limits and make space for the new calibration |
3457 |
|
// |
3458 |
|
totime = (UInt_t)atoll(row->GetField(1)); |
3459 |
|
// |
3460 |
|
oss.str(""); |
3461 |
|
oss << " UPDATE GL_CALOPULSE_CALIB SET " |
3462 |
|
<< " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ |
3463 |
|
<< " ID = "<< row->GetField(0) << ";"; |
3464 |
|
// |
3465 |
|
if ( IsDebug() ) printf(" Make space for the new pulse2 calibration: query is \n %s \n",oss.str().c_str()); |
3466 |
|
result = conn->Query(oss.str().c_str()); |
3467 |
|
// |
3468 |
|
if ( !result ) throw -4; |
3469 |
|
// |
3470 |
|
}; |
3471 |
|
// |
3472 |
|
// Fill the DB |
3473 |
|
// |
3474 |
|
oss.str(""); |
3475 |
|
// oss << " INSERT INTO GL_CALOPULSE_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,SECTION,OBT,PKT,BOOT_NUMBER,VALIDATION) " |
3476 |
|
oss << " INSERT INTO GL_CALOPULSE_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,SECTION,PULSED_STRIP,PULSE_AMPLITUDE,OBT,PKT,BOOT_NUMBER,VALIDATION) " |
3477 |
|
<< " VALUES (NULL,' " |
3478 |
|
<< idroot << "','" |
3479 |
|
<< i << "','" |
3480 |
|
<< fromtime << "','" |
3481 |
|
<< totime << "','" |
3482 |
|
<< section << "','" |
3483 |
|
<< pstrip << "','" |
3484 |
|
<< pampli << "','" |
3485 |
|
<< obt << "','" |
3486 |
|
<< pkt << "','" |
3487 |
|
<< this->GetBOOTnumber() << "','" |
3488 |
|
<< valid << "');"; |
3489 |
|
// |
3490 |
|
if ( IsDebug() ) printf(" Insert the new pulse2 calibration: query is \n %s \n",oss.str().c_str()); |
3491 |
|
// |
3492 |
|
result = conn->Query(oss.str().c_str()); |
3493 |
|
// |
3494 |
|
if ( !result ) throw -4; |
3495 |
|
// |
3496 |
|
}; |
3497 |
|
// |
3498 |
|
} else { |
3499 |
|
// |
3500 |
|
if ( IsDebug() ) printf(" Repeated pulse2 calo calibration for section %i at time %u obt %u pkt %u \n",section,fromtime,obt,pkt); |
3501 |
|
if ( PEDANTIC ) throw -78; |
3502 |
|
// |
3503 |
|
}; |
3504 |
|
// |
3505 |
|
}; |
3506 |
|
}; |
3507 |
|
}; |
3508 |
|
}; |
3509 |
|
// |
3510 |
|
return(0); |
3511 |
|
}; |
3512 |
|
|
3513 |
/** |
/** |
3514 |
* Fill the GL_TRK_CALIB table |
* Fill the GL_TRK_CALIB table |
3515 |
*/ |
*/ |
3559 |
if ( row ){ |
if ( row ){ |
3560 |
// |
// |
3561 |
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
3562 |
|
if ( PEDANTIC ) throw -80; |
3563 |
// |
// |
3564 |
} else { |
} else { |
3565 |
// |
// |
3718 |
// |
// |
3719 |
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) ){ |
3720 |
// |
// |
3721 |
if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u \n",fromtime,obt1,pkt1); |
3722 |
// |
// |
3723 |
valid = ValidateTrkCalib( caltrk1, eh1 ); |
valid = ValidateTrkCalib( caltrk1, eh1 ); |
3724 |
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
3761 |
// |
// |
3762 |
}; |
}; |
3763 |
// |
// |
3764 |
if ( IsDebug() ) printf(" Found trk calibration2 at obt %i pkt %i t2 is %i \n",obt2,pkt2,t2); |
if ( IsDebug() ) printf(" Found trk calibration2 at obt %u pkt %u t2 is %u \n",obt2,pkt2,t2); |
3765 |
// |
// |
3766 |
// The calibration is good |
// The calibration is good |
3767 |
// |
// |
3768 |
if ( this->PKT(pkt2) == this->PKT(pkt1)+1 ){ |
if ( this->PKT(pkt2) == this->PKT(pkt1)+1 ){ |
3769 |
// |
// |
3770 |
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 %u pkt %u t2 is %u is good \n",obt2,pkt2,t2); |
3771 |
// |
// |
3772 |
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
3773 |
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
3781 |
// |
// |
3782 |
if ( t2 != pret2+1 ){ |
if ( t2 != pret2+1 ){ |
3783 |
// |
// |
3784 |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %i pkt %i t2 is %i pret2 is %i \n",obt2,pkt2,t2,pret2); |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u pret2 is %u \n",obt2,pkt2,t2,pret2); |
3785 |
// |
// |
3786 |
while ( t2 > pret2+1 ){ |
while ( t2 > pret2+1 ){ |
3787 |
// |
// |
3810 |
// |
// |
3811 |
// Check for missing calibtrk2 |
// Check for missing calibtrk2 |
3812 |
// |
// |
3813 |
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %i pkt %i t2 is %i\n",obt2,pkt2,t2); |
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
3814 |
t2 = pret2; |
t2 = pret2; |
3815 |
// |
// |
3816 |
// handle missing calib2 |
// handle missing calib2 |
3824 |
// |
// |
3825 |
} else { |
} else { |
3826 |
// |
// |
3827 |
if ( IsDebug() ) printf(" Repetead trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); |
if ( IsDebug() ) printf(" Repetead trk calibration1 at time %u obt %u pkt %u \n",fromtime,obt1,pkt1); |
3828 |
|
if ( PEDANTIC ) throw -79; |
3829 |
// |
// |
3830 |
}; |
}; |
3831 |
// |
// |
3850 |
valid = 0; |
valid = 0; |
3851 |
if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
3852 |
// |
// |
3853 |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %i pkt %i t2 is %i\n",obt2,pkt2,t2); |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
3854 |
// |
// |
3855 |
this->HandleTRK_CALIB(false,true); |
this->HandleTRK_CALIB(false,true); |
3856 |
// |
// |
3904 |
fromtime = this->GetAbsTime(ph->GetOrbitalTime()); |
fromtime = this->GetAbsTime(ph->GetOrbitalTime()); |
3905 |
if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){ |
if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){ |
3906 |
// |
// |
3907 |
if ( IsDebug() ) printf(" S4 calibration at time %i obt %i pkt %i \n",fromtime,obt,pkt); |
if ( IsDebug() ) printf(" S4 calibration at time %u obt %u pkt %u \n",fromtime,obt,pkt); |
3908 |
// |
// |
3909 |
// check if the calibration has already been inserted |
// check if the calibration has already been inserted |
3910 |
// |
// |
3924 |
if ( row ){ |
if ( row ){ |
3925 |
// |
// |
3926 |
if ( IsDebug() ) printf(" S4 calibration already inserted in the DB\n"); |
if ( IsDebug() ) printf(" S4 calibration already inserted in the DB\n"); |
3927 |
|
if ( PEDANTIC ) throw -81; |
3928 |
// |
// |
3929 |
} else { |
} else { |
3930 |
// |
// |
3948 |
// |
// |
3949 |
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"); |
3950 |
if ( fromtime < 1150871000 ){ |
if ( fromtime < 1150871000 ){ |
3951 |
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime); |
if ( IsDebug() ) printf(" First PAMELA flight calibration at time %u \n",fromtime); |
3952 |
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 |
3953 |
}; |
}; |
3954 |
// |
// |
4007 |
// |
// |
4008 |
} else { |
} else { |
4009 |
// |
// |
4010 |
if ( IsDebug() ) printf(" Repetead S4 calibration at time %i obt %i pkt %i \n",fromtime,obt,pkt); |
if ( IsDebug() ) printf(" Repeated S4 calibration at time %u obt %u pkt %u \n",fromtime,obt,pkt); |
4011 |
|
if ( PEDANTIC ) throw -82; |
4012 |
// |
// |
4013 |
}; |
}; |
4014 |
// |
// |
4145 |
// |
// |
4146 |
} else { |
} else { |
4147 |
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
4148 |
|
if ( PEDANTIC ) throw -83; |
4149 |
}; |
}; |
4150 |
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)); |
4151 |
// |
// |
4220 |
row = result->Next(); |
row = result->Next(); |
4221 |
t_stop = (UInt_t)atoll(row->GetField(4)); |
t_stop = (UInt_t)atoll(row->GetField(4)); |
4222 |
}; |
}; |
4223 |
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
if ( IsDebug() ) printf("Validation interval: from time %u - to time %u \n\n",t_stop,t_start); |
4224 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
4225 |
// now retrieves runs to be validated |
// now retrieves runs to be validated |
4226 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
4391 |
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
4392 |
}; |
}; |
4393 |
|
|
4394 |
if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); |
if ( IsDebug() ) printf("%i Run %u \n",nrow,this_run->ID); |
4395 |
nrow++; |
nrow++; |
4396 |
|
|
4397 |
}; |
}; |
4420 |
// which should be equal to the time between ascending-nodes. |
// which should be equal to the time between ascending-nodes. |
4421 |
//============================================================== |
//============================================================== |
4422 |
if ( t2 - trkcalib->FROM_TIME > 5700) { |
if ( t2 - trkcalib->FROM_TIME > 5700) { |
4423 |
if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); |
if ( IsDebug() )printf("Long time between calib and run start %u :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); |
4424 |
//============================================================== |
//============================================================== |
4425 |
// there might be a missing calibration, due to: |
// there might be a missing calibration, due to: |
4426 |
// - MM full |
// - MM full |
4441 |
// it is enough to say that there are no missing calibrations |
// it is enough to say that there are no missing calibrations |
4442 |
//============================================================== |
//============================================================== |
4443 |
// the long time interval bewteen runs might be due to download |
// the long time interval bewteen runs might be due to download |
4444 |
if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
4445 |
return(false); |
return(false); |
4446 |
|
|
4447 |
}; |
}; |
4757 |
}; |
}; |
4758 |
}; |
}; |
4759 |
}; |
}; |
4760 |
if ( IsDebug() ) printf(" %i runs have been unvalidated \n",unv); |
if ( IsDebug() ) printf(" %u runs have been unvalidated \n",unv); |
4761 |
}; |
}; |
4762 |
|
|
4763 |
/** |
/** |
4788 |
if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n"); |
if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n"); |
4789 |
while ( Row ){ |
while ( Row ){ |
4790 |
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); |
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); |
4791 |
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
if ( IsDebug() ) printf(" del run %u \n",(UInt_t)atoll(Row->GetField(0))); |
4792 |
drun++; |
drun++; |
4793 |
Row = pResult->Next(); |
Row = pResult->Next(); |
4794 |
}; |
}; |
4809 |
} else { |
} else { |
4810 |
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n"); |
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n"); |
4811 |
while ( Row ){ |
while ( Row ){ |
4812 |
if ( IsDebug() ) printf(" restore run %i \n",(UInt_t)atoll(Row->GetField(1))); |
if ( IsDebug() ) printf(" restore run %u \n",(UInt_t)atoll(Row->GetField(1))); |
4813 |
delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS"); |
delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS"); |
4814 |
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(1))); |
if ( IsDebug() ) printf(" del run %u \n",(UInt_t)atoll(Row->GetField(1))); |
4815 |
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN"); |
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN"); |
4816 |
if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){ |
if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){ |
4817 |
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
if ( IsDebug() ) printf(" del run %u \n",(UInt_t)atoll(Row->GetField(0))); |
4818 |
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); |
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); |
4819 |
}; |
}; |
4820 |
drun++; |
drun++; |
4840 |
} else { |
} else { |
4841 |
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n"); |
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n"); |
4842 |
while ( Row ){ |
while ( Row ){ |
4843 |
if ( IsDebug() ) printf(" del run idtrash %i \n",(UInt_t)atoll(Row->GetField(0))); |
if ( IsDebug() ) printf(" del run idtrash %u \n",(UInt_t)atoll(Row->GetField(0))); |
4844 |
myquery.str(""); |
myquery.str(""); |
4845 |
myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";"; |
myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";"; |
4846 |
conn->Query(myquery.str().c_str()); |
conn->Query(myquery.str().c_str()); |
4849 |
}; |
}; |
4850 |
}; |
}; |
4851 |
// |
// |
4852 |
if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_TRASH table \n",drun); |
if ( IsDebug() ) printf(" Deleted %u run(s) from GL_RUN_TRASH table \n",drun); |
4853 |
// |
// |
4854 |
// |
// |
4855 |
// |
// |
4867 |
} else { |
} else { |
4868 |
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n"); |
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n"); |
4869 |
while ( Row ){ |
while ( Row ){ |
4870 |
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
if ( IsDebug() ) printf(" del run %u \n",(UInt_t)atoll(Row->GetField(0))); |
4871 |
myquery.str(""); |
myquery.str(""); |
4872 |
myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";"; |
myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";"; |
4873 |
conn->Query(myquery.str().c_str()); |
conn->Query(myquery.str().c_str()); |
4876 |
}; |
}; |
4877 |
}; |
}; |
4878 |
// |
// |
4879 |
if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_FRAGMENTS table \n",drun); |
if ( IsDebug() ) printf(" Deleted %u run(s) from GL_RUN_FRAGMENTS table \n",drun); |
4880 |
// |
// |
4881 |
// |
// |
4882 |
// |
// |
4946 |
// |
// |
4947 |
}; |
}; |
4948 |
}; |
}; |
4949 |
|
Bool_t OLDDB = false; |
4950 |
|
for (Int_t section = 0; section < 4; section++){ |
4951 |
|
myquery.str(""); |
4952 |
|
myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_CALOPULSE_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<" AND "; |
4953 |
|
myquery << " SECTION=" << section << ";"; |
4954 |
|
// |
4955 |
|
pResult = conn->Query(myquery.str().c_str()); |
4956 |
|
// |
4957 |
|
if ( conn->GetErrorCode() ){ |
4958 |
|
printf(" Section %i : warning, old databse structure no GL_CALOPULSE_CALIB table!\n",section); |
4959 |
|
OLDDB=true; |
4960 |
|
} else { |
4961 |
|
Row = pResult->Next(); |
4962 |
|
if( !Row->GetField(0) || !Row->GetField(1) ){ |
4963 |
|
// |
4964 |
|
if ( IsDebug() ) printf(" NO PULSE CALO CALIBRATION SECTION %i ASSOCIATED TO THIS FILE! \n",section); |
4965 |
|
// |
4966 |
|
} else { |
4967 |
|
// |
4968 |
|
myquery.str(""); |
4969 |
|
myquery << " UPDATE GL_CALOPULSE_CALIB SET TO_TIME=" << Row->GetField(1); |
4970 |
|
myquery << " WHERE TO_TIME="<< Row->GetField(0) << " AND "; |
4971 |
|
myquery << " SECTION=" << section << ";"; |
4972 |
|
// |
4973 |
|
pResult = conn->Query(myquery.str().c_str()); |
4974 |
|
// |
4975 |
|
if( !pResult ){ |
4976 |
|
// |
4977 |
|
if ( IsDebug() ) printf(" ERROR DELETING CALO PULSE CALIBRATIONS \n"); |
4978 |
|
// |
4979 |
|
throw -4; |
4980 |
|
// |
4981 |
|
}; |
4982 |
|
// |
4983 |
|
}; |
4984 |
|
}; |
4985 |
|
}; |
4986 |
myquery.str(""); |
myquery.str(""); |
4987 |
myquery << " DELETE FROM GL_CALO_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
myquery << " DELETE FROM GL_CALO_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT() << ";"; |
4988 |
// |
// |
4989 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
4990 |
// |
// |
4996 |
// |
// |
4997 |
}; |
}; |
4998 |
// |
// |
4999 |
|
myquery.str(""); |
5000 |
|
myquery << " DELETE FROM GL_CALOPULSE_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT() << ";"; |
5001 |
|
// |
5002 |
|
pResult = conn->Query(myquery.str().c_str()); |
5003 |
|
if ( IsDebug() ) printf(" Delete from GL_CALOPULSE_CALIB query is %s \n",myquery.str().c_str()); |
5004 |
|
if ( !OLDDB ){ |
5005 |
|
// |
5006 |
|
if( !pResult ){ |
5007 |
|
// |
5008 |
|
if ( IsDebug() ) printf(" ERROR DELETING PULSE CALO CALIBRATIONS \n"); |
5009 |
|
// |
5010 |
|
throw -4; |
5011 |
|
// |
5012 |
|
}; |
5013 |
|
}; |
5014 |
|
// |
5015 |
// Tracker |
// Tracker |
5016 |
// |
// |
5017 |
myquery.str(""); |
myquery.str(""); |
5041 |
}; |
}; |
5042 |
// |
// |
5043 |
myquery.str(""); |
myquery.str(""); |
5044 |
myquery << " DELETE FROM GL_TRK_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
myquery << " DELETE FROM GL_TRK_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT() << ";"; |
5045 |
// |
// |
5046 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
5047 |
// |
// |
5084 |
}; |
}; |
5085 |
// |
// |
5086 |
myquery.str(""); |
myquery.str(""); |
5087 |
myquery << " DELETE FROM GL_S4_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
myquery << " DELETE FROM GL_S4_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT() << ";"; |
5088 |
// |
// |
5089 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
5090 |
// |
// |
5223 |
* |
* |
5224 |
**/ |
**/ |
5225 |
UInt_t PamelaDBOperations::Check(){ |
UInt_t PamelaDBOperations::Check(){ |
5226 |
|
return(this->Check(0,0)); |
5227 |
|
} |
5228 |
|
|
5229 |
|
UInt_t PamelaDBOperations::Check(UInt_t from, UInt_t to){ |
5230 |
|
// |
5231 |
|
if ( IsDebug() ) printf(" from %u to %u \n",from,to); |
5232 |
// |
// |
5233 |
UInt_t test = 0; |
UInt_t test = 0; |
5234 |
// |
// |
5247 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
5248 |
TSQLResult *result2 = 0; |
TSQLResult *result2 = 0; |
5249 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
5250 |
|
TSQLResult *result3 = 0; |
5251 |
|
TSQLRow *row3 = 0; |
5252 |
oss.str(""); |
oss.str(""); |
5253 |
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;"; |
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS FROM GL_RUN order by RUNHEADER_TIME asc;"; |
5254 |
// oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; |
// oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; |
5255 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
5256 |
// |
// |
5257 |
if ( !result ) throw -4;; |
if ( !result ) throw -4;; |
5258 |
// |
// |
5259 |
row = result->Next(); |
row = result->Next(); |
5260 |
|
UInt_t nid = 0; |
5261 |
// |
// |
5262 |
while ( row ){ |
while ( row ){ |
5263 |
|
nid++; |
5264 |
|
if ( !(nid%1000) && nid ) printf(" %iK run scanned \n",nid/1000); |
5265 |
thisid = (UInt_t)atoll(row->GetField(0)); |
thisid = (UInt_t)atoll(row->GetField(0)); |
5266 |
thisl0id = (UInt_t)atoll(row->GetField(1)); |
thisl0id = (UInt_t)atoll(row->GetField(1)); |
5267 |
thisrht = (UInt_t)atoll(row->GetField(2)); |
thisrht = (UInt_t)atoll(row->GetField(2)); |
5268 |
thisrtt = (UInt_t)atoll(row->GetField(3)); |
thisrtt = (UInt_t)atoll(row->GetField(3)); |
5269 |
// |
// |
5270 |
|
if ( from > 0 && nid <= from ) goto ss; |
5271 |
|
if ( to > 0 && nid >= to ) goto ss; |
5272 |
|
// |
5273 |
|
if ( (UInt_t)atoll(row->GetField(4)) > 1 ){ |
5274 |
|
// |
5275 |
|
// |
5276 |
|
// |
5277 |
|
oss.str(""); |
5278 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
5279 |
|
<< thisid << " AND ( RUNHEADER_TIME=" |
5280 |
|
<< thisrht << " OR RUNTRAILER_TIME=" |
5281 |
|
<< thisrtt << " ) AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
5282 |
|
result3 = conn->Query(oss.str().c_str()); |
5283 |
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
5284 |
|
if ( result3 ){ |
5285 |
|
// |
5286 |
|
oss.str(""); |
5287 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
5288 |
|
<< thisid << " AND RUNHEADER_TIME=" |
5289 |
|
<< thisrht << " AND RUNTRAILER_TIME!=" |
5290 |
|
<< thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
5291 |
|
result3 = conn->Query(oss.str().c_str()); |
5292 |
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
5293 |
|
if ( result3 ){ |
5294 |
|
row3 = result3->Next(); |
5295 |
|
// |
5296 |
|
while ( row3 ){ |
5297 |
|
// |
5298 |
|
// 2 runs with same runheader |
5299 |
|
// |
5300 |
|
printf(" CHECK n.4 RUNs %u and %u HAVE SAME RUNHEADER \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
5301 |
|
row3 = result3->Next(); |
5302 |
|
}; |
5303 |
|
// delete result3; |
5304 |
|
|
5305 |
|
}; |
5306 |
|
// |
5307 |
|
oss.str(""); |
5308 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
5309 |
|
<< thisid << " AND RUNHEADER_TIME!=" |
5310 |
|
<< thisrht << " AND RUNTRAILER_TIME=" |
5311 |
|
<< thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
5312 |
|
result3 = conn->Query(oss.str().c_str()); |
5313 |
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
5314 |
|
if ( result3 ){ |
5315 |
|
row3 = result3->Next(); |
5316 |
|
// |
5317 |
|
while ( row3 ){ |
5318 |
|
// |
5319 |
|
// 2 runs with same runtrailer |
5320 |
|
// |
5321 |
|
printf(" CHECK n.5 RUNs %u and %u HAVE SAME RUNTRAILER \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
5322 |
|
row3 = result3->Next(); |
5323 |
|
}; |
5324 |
|
// delete result3; |
5325 |
|
}; |
5326 |
|
// |
5327 |
|
oss.str(""); |
5328 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
5329 |
|
<< thisid << " AND RUNHEADER_TIME=" |
5330 |
|
<< thisrht << " AND RUNTRAILER_TIME=" |
5331 |
|
<< thisrtt << " AND ID_RUN_FRAG!=" |
5332 |
|
<< thisid << " order by RUNHEADER_TIME asc;"; |
5333 |
|
result3 = conn->Query(oss.str().c_str()); |
5334 |
|
if ( result3 ){ |
5335 |
|
row3 = result3->Next(); |
5336 |
|
// |
5337 |
|
while ( row3 ){ |
5338 |
|
// |
5339 |
|
// duplicated run |
5340 |
|
// |
5341 |
|
printf(" CHECK n.7 RUNs %u and %u HAVE SAME RUNTRAILER AND RUNHEADER (ARE THE SAME?) \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
5342 |
|
row3 = result3->Next(); |
5343 |
|
}; |
5344 |
|
// delete result3; |
5345 |
|
|
5346 |
|
}; |
5347 |
|
}; |
5348 |
|
// |
5349 |
|
oss.str(""); |
5350 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
5351 |
|
<< thisid << " AND RUNHEADER_TIME>" |
5352 |
|
<< thisrht << " AND RUNTRAILER_TIME<" |
5353 |
|
<< thisrtt << " order by RUNHEADER_TIME asc;"; |
5354 |
|
result3 = conn->Query(oss.str().c_str()); |
5355 |
|
if ( result3 ){ |
5356 |
|
row3 = result3->Next(); |
5357 |
|
// |
5358 |
|
while ( row3 ){ |
5359 |
|
// |
5360 |
|
// run contained in the checked one |
5361 |
|
// |
5362 |
|
printf(" CHECK n.6 RUN %u CONTAINS RUN %u \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
5363 |
|
row3 = result3->Next(); |
5364 |
|
}; |
5365 |
|
// delete result3; |
5366 |
|
}; |
5367 |
|
// |
5368 |
|
}; |
5369 |
|
// |
5370 |
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
5371 |
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
5372 |
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
5388 |
thisf = (TString)row2->GetField(0); |
thisf = (TString)row2->GetField(0); |
5389 |
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
5390 |
test = 1; |
test = 1; |
5391 |
|
// delete result2; |
5392 |
}; |
}; |
5393 |
// |
// |
5394 |
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
5399 |
oss.str(""); |
oss.str(""); |
5400 |
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
5401 |
result2 = conn->Query(oss.str().c_str()); |
result2 = conn->Query(oss.str().c_str()); |
5402 |
if ( !result2 ) throw -4;; |
if ( !result2 ) throw -4; |
5403 |
row2 = result2->Next(); |
row2 = result2->Next(); |
5404 |
prevf = (TString)row2->GetField(0); |
prevf = (TString)row2->GetField(0); |
5405 |
oss.str(""); |
oss.str(""); |
5410 |
thisf = (TString)row2->GetField(0); |
thisf = (TString)row2->GetField(0); |
5411 |
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
5412 |
test = 1; |
test = 1; |
5413 |
|
// delete result2; |
5414 |
}; |
}; |
5415 |
// |
// |
5416 |
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
5432 |
thisf = (TString)row2->GetField(0); |
thisf = (TString)row2->GetField(0); |
5433 |
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
5434 |
test = 1; |
test = 1; |
5435 |
|
// delete result2; |
5436 |
}; |
}; |
5437 |
|
ss: |
5438 |
// |
// |
5439 |
prevrht = thisrht; |
prevrht = thisrht; |
5440 |
prevrtt = thisrtt; |
prevrtt = thisrtt; |
5441 |
previd = thisid; |
previd = thisid; |
5442 |
prevl0id = thisl0id; |
prevl0id = thisl0id; |
5443 |
row = result->Next(); |
row = result->Next(); |
5444 |
|
// if ( result2 ) delete result2; |
5445 |
|
// if ( result3 ) delete result3; |
5446 |
}; |
}; |
5447 |
// |
// |
5448 |
return(test); |
return(test); |