| 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> |
| 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 |
*/ |
*/ |
| 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 |
|
|
| 498 |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){ |
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); |
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 |
// |
// |
| 638 |
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,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 |
// |
// |
| 640 |
if ( pkth < spkth && obth < sobth ){ |
if ( pkth < spkth && obth < sobth ){ |
| 641 |
|
if ( PEDANTIC ) throw -66; |
| 642 |
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
| 643 |
// |
// |
| 644 |
rhev = k-1; |
rhev = k-1; |
| 698 |
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
| 699 |
// |
// |
| 700 |
if ( pktt < spktt && obtt < sobtt ){ |
if ( pktt < spktt && obtt < sobtt ){ |
| 701 |
|
if ( PEDANTIC ) throw -66; |
| 702 |
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
| 703 |
// |
// |
| 704 |
rtev = k-1; |
rtev = k-1; |
| 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 |
// |
// |
| 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 |
// |
// |
| 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 |
// |
// |
| 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: %u %u %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 |
// |
// |
| 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: %u %u %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 |
// |
// |
| 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()); |
| 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 |
// |
// |
| 3119 |
} else { |
} else { |
| 3120 |
// |
// |
| 3121 |
if ( IsDebug() ) printf(" Repeated calo calibration for section %i at time %u obt %u pkt %u \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 |
// |
// |
| 3825 |
} else { |
} else { |
| 3826 |
// |
// |
| 3827 |
if ( IsDebug() ) printf(" Repetead trk calibration1 at time %u obt %u pkt %u \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 |
// |
// |
| 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 |
// |
// |
| 4008 |
} else { |
} else { |
| 4009 |
// |
// |
| 4010 |
if ( IsDebug() ) printf(" Repeated S4 calibration at time %u obt %u pkt %u \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 |
// |
// |
| 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 |
// |
// |