/[PAMELA software]/YodaProfiler/src/PamelaDBOperations.cpp
ViewVC logotype

Diff of /YodaProfiler/src/PamelaDBOperations.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by mocchiut, Wed Aug 30 11:18:13 2006 UTC revision 1.6 by mocchiut, Fri Sep 8 16:06:02 2006 UTC
# Line 8  Line 8 
8  #include <list>  #include <list>
9  #include <errno.h>  #include <errno.h>
10  //  //
11    #include <TFile.h>
12    #include <TSystem.h>
13  #include <TSQLResult.h>  #include <TSQLResult.h>
 #include <TRFIOFile.h>  
14  #include <TSQLRow.h>  #include <TSQLRow.h>
15  #include <TTree.h>  #include <TTree.h>
16  #include <TGraph.h>  #include <TGraph.h>
# Line 29  Line 30 
30  #include <varDump/VarDumpEvent.h>  #include <varDump/VarDumpEvent.h>
31  #include <varDump/VarDumpRecord.h>  #include <varDump/VarDumpRecord.h>
32  #include <physics/S4/S4Event.h>  #include <physics/S4/S4Event.h>
   
33  //  //
34  #include <PamelaDBOperations.h>  #include <PamelaDBOperations.h>
35  //  //
36  using namespace std;  using namespace std;
37  using namespace pamela;  using namespace pamela;
 //using namespace yngn::util;  
38    
39  /**  /**
40   * Constructor.   * Constructor.
# Line 170  void PamelaDBOperations::SetNOBOOT(Bool_ Line 169  void PamelaDBOperations::SetNOBOOT(Bool_
169  };  };
170    
171  /**  /**
172     * Store the olderthan variable
173     * @param olderthan
174     */
175    void PamelaDBOperations::SetOlderThan(Long64_t oldthan){
176      olderthan = oldthan;
177    };
178    
179    /**
180   * Retrieve the ID_RAW, if exists, returns NULL if does not exist.   * Retrieve the ID_RAW, if exists, returns NULL if does not exist.
181   */   */
182  Bool_t PamelaDBOperations::SetID_RAW(){  Bool_t PamelaDBOperations::SetID_RAW(){
# Line 181  Bool_t PamelaDBOperations::SetID_RAW(){ Line 188  Bool_t PamelaDBOperations::SetID_RAW(){
188        << " PATH = '" << this->GetRawPath().Data() << "' AND "        << " PATH = '" << this->GetRawPath().Data() << "' AND "
189        << " NAME = '" << this->GetRawFile().Data() << "' ";        << " NAME = '" << this->GetRawFile().Data() << "' ";
190    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
191    if (result == NULL) throw -4;    if ( result == NULL ) throw -4;
192    row = result->Next();    row = result->Next();
193    if (row == NULL) return false;    if ( !row ) return(false);
194    delete result;    delete result;
195    id = (UInt_t)atoll(row->GetField(0));    id = (UInt_t)atoll(row->GetField(0));
196    return(true);    return(true);
# Line 216  Int_t PamelaDBOperations::SetUpperLimits Line 223  Int_t PamelaDBOperations::SetUpperLimits
223    ULong64_t upperobt2 = 0;    ULong64_t upperobt2 = 0;
224    UInt_t zomp = 0;    UInt_t zomp = 0;
225    UInt_t jump = 50000; // was 5000    UInt_t jump = 50000; // was 5000
226      EventCounter *code=0;
227      //
228      //   pcksList packetsNames;
229      //   pcksList::iterator Iter;
230      //   getPacketsNames(packetsNames);
231    //    //
232    pktfirst = 0;    pktfirst = 0;
233    obtfirst = 0;    obtfirst = 0;
# Line 233  Int_t PamelaDBOperations::SetUpperLimits Line 245  Int_t PamelaDBOperations::SetUpperLimits
245    pktfirst = ph->GetCounter();    pktfirst = ph->GetCounter();
246    obtfirst = ph->GetOrbitalTime();      obtfirst = ph->GetOrbitalTime();  
247    //    //
248      //   code = eh->GetCounter();
249      //   UInt_t en = 0;
250      //   for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
251      //     en = code->Get(GetPacketType(*Iter));
252      //     if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en);
253      //};  
254      //
255    T->GetEntry(nevent-1);    T->GetEntry(nevent-1);
256    ph = eh->GetPscuHeader();    ph = eh->GetPscuHeader();
257    pktlast = ph->GetCounter();    pktlast = ph->GetCounter();
# Line 301  Int_t PamelaDBOperations::SetUpperLimits Line 320  Int_t PamelaDBOperations::SetUpperLimits
320    // check if last runtrailer is within limits, if not extend limits (one should check for all packets but we need only runtrailer)    // check if last runtrailer is within limits, if not extend limits (one should check for all packets but we need only runtrailer)
321    //    //
322    PacketType *pctp=0;    PacketType *pctp=0;
   EventCounter *code=0;  
   T->GetEntry(upperentry);  
   code = eh->GetCounter();  
   Int_t lasttrail = code->Get(pctp->RunTrailer);  
   Int_t lasthead = code->Get(pctp->RunHeader);  
323    TTree *rh=(TTree*)file->Get("RunHeader");    TTree *rh=(TTree*)file->Get("RunHeader");
324    if ( !rh || rh->IsZombie() ) throw -17;    if ( !rh || rh->IsZombie() ) throw -17;
325    TTree *rt=(TTree*)file->Get("RunTrailer");    TTree *rt=(TTree*)file->Get("RunTrailer");
# Line 319  Int_t PamelaDBOperations::SetUpperLimits Line 333  Int_t PamelaDBOperations::SetUpperLimits
333    //    //
334    rhev = rh->GetEntries();    rhev = rh->GetEntries();
335    rtev = rt->GetEntries();    rtev = rt->GetEntries();
336      UInt_t sobtt = 0;
337      UInt_t sobth = 0;
338      UInt_t spktt = 0;
339      UInt_t spkth = 0;
340    UInt_t pktt = 0;    UInt_t pktt = 0;
341    ULong64_t obtt = 0;    ULong64_t obtt = 0;
342    UInt_t pkth = 0;    UInt_t pkth = 0;
343    ULong64_t obth = 0;    ULong64_t obth = 0;
344    //    //
345      T->GetEntry(upperentry);
346      code = eh->GetCounter();
347      Int_t lasttrail = code->Get(pctp->RunTrailer);
348      Int_t lasthead = code->Get(pctp->RunHeader);
349    if ( lasttrail < rtev ){    if ( lasttrail < rtev ){
350      rt->GetEntry(lasttrail);      rt->GetEntry(lasttrail);
351      pht = eht->GetPscuHeader();      pht = eht->GetPscuHeader();
# Line 331  Int_t PamelaDBOperations::SetUpperLimits Line 353  Int_t PamelaDBOperations::SetUpperLimits
353      obtt = OBT(pht->GetOrbitalTime());      obtt = OBT(pht->GetOrbitalTime());
354    };    };
355    //    //
356      if ( lasthead < rhev ){
357        rh->GetEntry(lasthead);
358        phh = ehh->GetPscuHeader();
359        pkth = PKT(phh->GetCounter());
360        obth = OBT(phh->GetOrbitalTime());
361      };
362      //
363      if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
364      if ( pkth > upperpkt && obth > upperobt ){
365        if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt);
366        upperpkt = pkth;
367        upperobt = obth;
368        rhev = lasthead+1;
369      } else {
370        rhev = lasthead;
371      };
372      if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
373      //
374    if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);    if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
375    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
376      if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt);      if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt);
# Line 341  Int_t PamelaDBOperations::SetUpperLimits Line 381  Int_t PamelaDBOperations::SetUpperLimits
381      rtev = lasttrail;      rtev = lasttrail;
382    };    };
383    if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);    if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
384      //  goto kikko;
385      //
386      //
387      // Check if runtrailer/runheader are within lower limits
388      //
389      //
390      pkth = 0;
391      obth = 0;
392      spkth = 0;
393      sobth = 0;
394      for (Int_t k=0; k<rhev; k++){
395        if ( k > 0 ){
396          spkth = pkth;
397          sobth = obth;
398        };
399        rh->GetEntry(k);
400        phh = ehh->GetPscuHeader();
401        pkth = PKT(phh->GetCounter());
402        obth = OBT(phh->GetOrbitalTime());
403        //
404        if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth);
405        //
406        if ( pkth < spkth && obth < sobth ){
407          if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i  \n",rhev);
408          //
409          rhev = k-1;
410          rh->GetEntry(rhev);
411          pkth = spkth;
412          obth = sobth;
413          //
414          UInt_t evbefh = 0;
415          code = ehh->GetCounter();
416          evbefh = code->Get(pctp->Physics);    
417          if ( evbefh >= 0 ){
418            T->GetEntry(evbefh);
419            ph = eh->GetPscuHeader();
420            t_pktlast = PKT(ph->GetCounter());
421            t_obtlast = OBT(ph->GetOrbitalTime());
422            if ( t_pktlast < spkth && t_obtlast < sobth ){ // jump
423              upperpkt = pkth;
424              upperobt = obth;
425              upperentry = evbefh-1;
426            } else {
427              while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){
428                evbefh++;  
429                T->GetEntry(evbefh);
430                ph = eh->GetPscuHeader();
431                t_pktlast = PKT(ph->GetCounter());
432                t_obtlast = OBT(ph->GetOrbitalTime());
433              };
434              T->GetEntry(evbefh-1);
435              ph = eh->GetPscuHeader();
436              upperpkt = PKT(ph->GetCounter());
437              upperobt = OBT(ph->GetOrbitalTime());
438              upperentry = evbefh-1;
439            };    
440          };
441          if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
442          goto kikko0;
443        };
444      };
445     kikko0:
446      //
447      //
448      //
449      pktt = 0;
450      obtt = 0;
451      spktt = 0;
452      sobtt = 0;
453      for (Int_t k=0; k<rtev; k++){
454        if ( k > 0 ){
455          spktt = pktt;
456          sobtt = obtt;
457        };
458        rt->GetEntry(k);
459        pht = eht->GetPscuHeader();
460        pktt = PKT(pht->GetCounter());
461        obtt = OBT(pht->GetOrbitalTime());
462        //
463        if ( IsDebug() ) printf(" k %i rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt);
464        //
465        if ( pktt < spktt && obtt < sobtt ){
466          if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev);
467          //
468          rtev = k-1;
469          rt->GetEntry(rtev);
470          pktt = spktt;
471          obtt = sobtt;
472          if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
473          //
474          UInt_t evbeft = 0;
475          code = eht->GetCounter();
476          evbeft = code->Get(pctp->Physics);    
477          if ( evbeft >= 0 ){
478            T->GetEntry(evbeft);
479            ph = eh->GetPscuHeader();
480            t_pktlast = PKT(ph->GetCounter());
481            t_obtlast = OBT(ph->GetOrbitalTime());
482            if ( t_pktlast < spktt && t_obtlast < sobtt ){ // jump
483              upperpkt = pktt;
484              upperobt = obtt;
485              upperentry = evbeft-1;
486            } else {
487              while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){
488                evbeft++;  
489                T->GetEntry(evbeft);
490                ph = eh->GetPscuHeader();
491                t_pktlast = PKT(ph->GetCounter());
492                t_obtlast = OBT(ph->GetOrbitalTime());
493              };
494              T->GetEntry(evbeft-1);
495              ph = eh->GetPscuHeader();
496              upperpkt = PKT(ph->GetCounter());
497              upperobt = OBT(ph->GetOrbitalTime());
498              upperentry = evbeft-1;
499            };
500          };
501          if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
502          goto kikko;
503          //      break;
504          //
505        };
506        //  
507      };
508      //
509     kikko:
510      //
511      T->GetEntry(upperentry);
512      code = eh->GetCounter();
513      lasttrail = code->Get(pctp->RunTrailer);
514      lasthead = code->Get(pctp->RunHeader);
515      if ( lasttrail < rtev ){
516        rt->GetEntry(lasttrail);
517        pht = eht->GetPscuHeader();
518        pktt = PKT(pht->GetCounter());
519        obtt = OBT(pht->GetOrbitalTime());
520      };
521    //    //
522    if ( lasthead < rhev ){    if ( lasthead < rhev ){
523      rh->GetEntry(lasthead);      rh->GetEntry(lasthead);
524      phh = ehh->GetPscuHeader();      phh = ehh->GetPscuHeader();
525      pkth = PKT(pht->GetCounter());      pkth = PKT(phh->GetCounter());
526      obth = OBT(pht->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
527    };    };
528    //    //
529    if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);    if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
# Line 360  Int_t PamelaDBOperations::SetUpperLimits Line 537  Int_t PamelaDBOperations::SetUpperLimits
537    };    };
538    if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);    if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
539    //    //
540      if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
541      if ( pktt > upperpkt && obtt > upperobt ){
542        if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt);
543        upperpkt = pktt;
544        upperobt = obtt;
545        rtev = lasttrail+1;
546      } else {
547        rtev = lasttrail;
548      };
549      if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
550      //
551    if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry);    if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry);
552    //    //
553    return(0);    return(0);
# Line 550  void PamelaDBOperations::FillClass(Bool_ Line 738  void PamelaDBOperations::FillClass(Bool_
738      lastPkt = glrun->GetRUNTRAILER_PKT();      lastPkt = glrun->GetRUNTRAILER_PKT();
739    };    };
740    //    //
741    if ( mishead && mistrail && lastev+1 == firstev ) throw -14; // run with no events, no runtrailer, no runheader... unsupported    if ( mishead && mistrail && lastev+1 == firstev ) throw -14; // run with no events, no runtrailer, no runheader... unsupported should never arrive here
742    //    //
743    if ( mishead ) {    if ( mishead ) {
744      glrun->Set_GL_RUNH0();      glrun->Set_GL_RUNH0();
# Line 668  Int_t PamelaDBOperations::insertPamelaGL Line 856  Int_t PamelaDBOperations::insertPamelaGL
856    };    };
857    //    //
858    TTree *T = 0;    TTree *T = 0;
859      Int_t signal = 0;
860    //    //
861    UInt_t nevent = 0;    UInt_t nevent = 0;
862    UInt_t recEntries = 0;    UInt_t recEntries = 0;
# Line 721  Int_t PamelaDBOperations::insertPamelaGL Line 910  Int_t PamelaDBOperations::insertPamelaGL
910          //          //
911          if ( TSYNC && OBT ){          if ( TSYNC && OBT ){
912            existsts = true;            existsts = true;
913            goto out;            goto eout;
914          };          };
915          //          //
916        };        };
# Line 729  Int_t PamelaDBOperations::insertPamelaGL Line 918  Int_t PamelaDBOperations::insertPamelaGL
918    };    };
919    if ( !existsts ) { // try with runheader and runtrailer    if ( !existsts ) { // try with runheader and runtrailer
920      //      //
921        if ( IsDebug() ) printf(" No ts mcmd \n");
922        signal = 2;
923        //
924      TTree *rh=(TTree*)file->Get("RunHeader");      TTree *rh=(TTree*)file->Get("RunHeader");
925      if ( !rh || rh->IsZombie() ) throw -17;      if ( !rh || rh->IsZombie() ) throw -17;
926      TTree *rt=(TTree*)file->Get("RunTrailer");      TTree *rt=(TTree*)file->Get("RunTrailer");
# Line 738  Int_t PamelaDBOperations::insertPamelaGL Line 930  Int_t PamelaDBOperations::insertPamelaGL
930      //      //
931      rt->SetBranchAddress("RunTrailer", &runt);      rt->SetBranchAddress("RunTrailer", &runt);
932      //      //
     //    Int_t rhev = rh->GetEntries();  
     //    Int_t rtev = rt->GetEntries();  
     //  
933      if ( rhev > 0 ){      if ( rhev > 0 ){
934        rh->GetEntry(0);        rh->GetEntry(0);
935        //        //
# Line 751  Int_t PamelaDBOperations::insertPamelaGL Line 940  Int_t PamelaDBOperations::insertPamelaGL
940        //        //
941        if ( TSYNC && OBT ){        if ( TSYNC && OBT ){
942          existsts = true;          existsts = true;
943          goto out;          goto eout;
944        };        };
945        //        //
946      };      };
947      if ( rtev > 0 ){      if ( rtev > 0 ){
948          //
949          if ( IsDebug() ) printf(" No runheader \n");
950          signal = 6;
951          //
952        rt->GetEntry(0);        rt->GetEntry(0);
953        //        //
954        TSYNC = runt->LAST_TYME_SYNC_INFO;        TSYNC = runt->LAST_TYME_SYNC_INFO;
# Line 765  Int_t PamelaDBOperations::insertPamelaGL Line 958  Int_t PamelaDBOperations::insertPamelaGL
958        //        //
959        if ( TSYNC && OBT ){        if ( TSYNC && OBT ){
960          existsts = true;          existsts = true;
961          goto out;          goto eout;
962        };        };
963        //        //
964        } else {
965          if ( IsDebug() ) printf(" No runheader \n");
966      };      };
967    };    };
968    //    //
969    if ( !existsts ){ // try with inclination mcmd    if ( !existsts ){ // try with inclination mcmd
970        //
971        if ( IsDebug() ) printf(" No runtrailer \n");
972        signal = 14;
973        //
974      Double_t timesync = 0.;      Double_t timesync = 0.;
975      for (UInt_t i=0; i<nevent;i++){      for (UInt_t i=0; i<nevent;i++){
976        //        //
# Line 800  Int_t PamelaDBOperations::insertPamelaGL Line 999  Int_t PamelaDBOperations::insertPamelaGL
999        TYPE = 666;        TYPE = 666;
1000        if ( TSYNC && OBT ){        if ( TSYNC && OBT ){
1001          existsts = true;          existsts = true;
1002          goto out;          goto eout;
1003        };        };
1004      };      };
1005    };    };
1006    //    //
1007    if ( !existsts && obt0 ){ // insert timesync by hand    if ( !existsts && obt0 ){ // insert timesync by hand
1008        //
1009        if ( IsDebug() ) printf(" No incl mcmd \n");
1010        signal = 30;
1011        //
1012      OBT = obt0;      OBT = obt0;
1013      TSYNC = tsync;      TSYNC = tsync;
1014      TYPE = 999;      TYPE = 999;
1015      existsts = true;      existsts = true;
1016      goto out;      goto eout;
1017    };    };
1018    //    //
1019   out:   eout:
1020    //    //
1021    if ( !existsts ) throw -3;    if ( !existsts ) throw -3;
1022    //    //
# Line 829  Int_t PamelaDBOperations::insertPamelaGL Line 1032  Int_t PamelaDBOperations::insertPamelaGL
1032    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;
1033    //    //
1034    delete result;    delete result;
1035    return(0);    return(signal);
1036  }  }
1037    
1038  /**  /**
# Line 907  Int_t PamelaDBOperations::assignBOOT_NUM Line 1110  Int_t PamelaDBOperations::assignBOOT_NUM
1110        << " NAME = '" << this->GetRawFile().Data() << "' ";        << " NAME = '" << this->GetRawFile().Data() << "' ";
1111    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
1112    //    //
1113    if ( !result ) return(8);    if ( !result ) throw -4;;
1114    row = result->Next();    row = result->Next();
1115    if ( !row ) return(16);    if ( !row ) return(16);
1116    if ( row->GetField(1) ){    if ( row->GetField(1) ){
1117      this->SetBOOTnumber((UInt_t)atoll(row->GetField(1)));      this->SetBOOTnumber((UInt_t)atoll(row->GetField(1)));
1118      return(1);      return(1);
1119    };    };
1120    if ( !row->GetField(0) ) return(8);    if ( !row->GetField(0) ) throw -26;
1121    //    //
1122    UInt_t idRaw = (UInt_t)atoll(row->GetField(0));    UInt_t idRaw = (UInt_t)atoll(row->GetField(0));
1123    //    //
# Line 924  Int_t PamelaDBOperations::assignBOOT_NUM Line 1127  Int_t PamelaDBOperations::assignBOOT_NUM
1127    trDumpEv = (TTree*)file->Get("VarDump");    trDumpEv = (TTree*)file->Get("VarDump");
1128    if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20;    if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20;
1129    //    //
   if (trDumpEv == NULL) return(2);  
   //      
1130    VarDumpEvent  *vde = 0;    VarDumpEvent  *vde = 0;
1131    VarDumpRecord *vdr = 0;    VarDumpRecord *vdr = 0;
1132    //    //
1133    trDumpEv->SetBranchAddress("VarDump", &vde);    trDumpEv->SetBranchAddress("VarDump", &vde);
1134    if (trDumpEv->GetEntries() > 0){    if ( trDumpEv->GetEntries() > 0 ){
1135      trDumpEv->GetEntry(0);      Bool_t found = false;
1136      vde->Records->GetEntries();      for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){
1137      if ( !vde->Records->GetEntries() ){        trDumpEv->GetEntry(i);
1138        if ( !this->GetBOOTnumber() ) return(4);        vde->Records->GetEntries();
1139      } else {        if ( vde->Records->GetEntries()>0 ){
1140            found = true;
1141            goto fill;
1142          };
1143        };
1144      fill:
1145        if ( found ){
1146          //
1147        vdr = (VarDumpRecord*)vde->Records->At(6);        vdr = (VarDumpRecord*)vde->Records->At(6);
1148          //
1149        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);
1150          //
1151        } else {
1152          if ( !this->GetBOOTnumber() ) return(4);
1153      };      };
1154    } else {    } else {
1155      if ( !this->GetBOOTnumber() ) return(2);      if ( !this->GetBOOTnumber() ) return(2);
# Line 1023  Int_t PamelaDBOperations::insertPamelaRU Line 1235  Int_t PamelaDBOperations::insertPamelaRU
1235          //          //
1236          if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt);          if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt);
1237          //          //
1238          if ( (ptt-1) < 0 ) throw -15;          if ( (ptt-1) < 0 ) throw -15; // should never arrive here!
1239          rt->GetEntry(ptt-1);          rt->GetEntry(ptt-1);
1240          cod = eht->GetCounter();          cod = eht->GetCounter();
1241          evbefh = cod->Get(pctp->Physics);          evbefh = cod->Get(pctp->Physics);
# Line 1129  Int_t PamelaDBOperations::insertPamelaRU Line 1341  Int_t PamelaDBOperations::insertPamelaRU
1341            if ( (UInt_t)evbeft < upperentry-1 ){            if ( (UInt_t)evbeft < upperentry-1 ){
1342              if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER!\n");              if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER!\n");
1343              //              //
1344              if ( (ptt-1) < 0 ) throw -15;              if ( (ptt-1) < 0 ) throw -15; // should never arrive here!
1345              rt->GetEntry(ptt-1);              rt->GetEntry(ptt-1);
1346              cod = eht->GetCounter();              cod = eht->GetCounter();
1347              evbefh = cod->Get(pctp->Physics);              evbefh = cod->Get(pctp->Physics);
# Line 2106  void PamelaDBOperations::HandleSuspiciou Line 2318  void PamelaDBOperations::HandleSuspiciou
2318    if ( firstev == lastev+1 ) { // no events inside the run!    if ( firstev == lastev+1 ) { // no events inside the run!
2319      if ( IsDebug() ) printf(" Checking but no events in the run! \n");      if ( IsDebug() ) printf(" Checking but no events in the run! \n");
2320      //      //
     //    if ( IsDebug() ) printf(" -> fill the DB \n");  
     //  
2321      this->FillClass();      this->FillClass();
2322      if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn);          if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn);    
2323      //      //
# Line 2318  Int_t PamelaDBOperations::insertCALO_CAL Line 2528  Int_t PamelaDBOperations::insertCALO_CAL
2528    tr->SetBranchAddress("Header", &eh);    tr->SetBranchAddress("Header", &eh);
2529    nevents = tr->GetEntries();    nevents = tr->GetEntries();
2530    //    //
2531    if ( !nevents ) return(0);    if ( !nevents ) return(1);
2532    //    //
2533    for (UInt_t i=0; i < nevents; i++){    for (UInt_t i=0; i < nevents; i++){
2534      tr->GetEntry(i);      tr->GetEntry(i);
# Line 2635  Int_t PamelaDBOperations::insertTRK_CALI Line 2845  Int_t PamelaDBOperations::insertTRK_CALI
2845    tr2->SetBranchAddress("Header", &eh2);    tr2->SetBranchAddress("Header", &eh2);
2846    nevents2 = tr2->GetEntries();    nevents2 = tr2->GetEntries();
2847    //    //
2848    if ( !nevents1 && !nevents2 ) return(0);    if ( !nevents1 && !nevents2 ) return(1);
2849    //    //
2850    t2 = -1;    t2 = -1;
2851    Int_t pret2 = 0;    Int_t pret2 = 0;
# Line 2807  Int_t PamelaDBOperations::insertS4_CALIB Line 3017  Int_t PamelaDBOperations::insertS4_CALIB
3017    stringstream oss;    stringstream oss;
3018    oss.str("");    oss.str("");
3019    //    //
   CalibS4Event *calibS4    = new  CalibS4Event();  
3020    TTree *tr = 0;    TTree *tr = 0;
3021    EventHeader *eh = 0;    EventHeader *eh = 0;
3022    PscuHeader *ph = 0;    PscuHeader *ph = 0;
# Line 2821  Int_t PamelaDBOperations::insertS4_CALIB Line 3030  Int_t PamelaDBOperations::insertS4_CALIB
3030    tr = (TTree*)file->Get("CalibS4");    tr = (TTree*)file->Get("CalibS4");
3031    if ( !tr || tr->IsZombie() ) throw -24;    if ( !tr || tr->IsZombie() ) throw -24;
3032    //    //
   tr->SetBranchAddress("CalibS4", &calibS4);  
3033    tr->SetBranchAddress("Header", &eh);    tr->SetBranchAddress("Header", &eh);
3034    //    //
3035    nevents = tr->GetEntries();    nevents = tr->GetEntries();
3036    //    //
3037    if ( !nevents ) return(0);    if ( !nevents ) return(1);
3038    //    //
3039    for (UInt_t i = 0; i < nevents; i++){    for (UInt_t i = 0; i < nevents; i++){
3040      //      //
3041      tr->GetEntry(i);      tr->GetEntry(i);
     TArrayD params = S4_paramfit(calibS4);  
3042      //      //
3043      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
3044      obt = ph->GetOrbitalTime();        obt = ph->GetOrbitalTime();  
# Line 2921  Int_t PamelaDBOperations::insertS4_CALIB Line 3128  Int_t PamelaDBOperations::insertS4_CALIB
3128          };          };
3129          //          //
3130          oss.str("");          oss.str("");
3131          oss << " INSERT INTO GL_S4_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,PARAM_FIT0,PARAM_FIT1,OBT,PKT,BOOT_NUMBER,VALIDATION) "          oss << " INSERT INTO GL_S4_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,OBT,PKT,BOOT_NUMBER) "
3132              << " VALUES (NULL,' "              << " VALUES (NULL,' "
3133              << idroot << "','"              << idroot << "','"
3134              << i << "','"              << i << "','"
3135              << fromtime << "','"              << fromtime << "','"
3136              << totime << "','"              << totime << "','"
             << dec << params.At(0) << "','"  
             << dec << params.At(1) << "','"        
3137              << obt << "','"              << obt << "','"
3138              << pkt << "','"              << pkt << "','"
3139              << this->GetBOOTnumber() << "','"              << this->GetBOOTnumber() << "');";
             << valid << "');";  
3140          //          //
3141          if ( IsDebug() ) printf(" Insert the new calibration: query is \n %s \n",oss.str().c_str());          if ( IsDebug() ) printf(" Insert the new calibration: query is \n %s \n",oss.str().c_str());
3142          //          //
# Line 2953  Int_t PamelaDBOperations::insertS4_CALIB Line 3157  Int_t PamelaDBOperations::insertS4_CALIB
3157    return(0);    return(0);
3158  };  };
3159    
3160    /**
3161  /*   * Scan the fragment table and move old fragments to the GL_RUN table
  * Fit function Received from Valeria Malvezzi 06/02/2006  
3162   */   */
3163  Double_t fitf(Double_t *x, Double_t *par){    Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){
3164    Double_t fitval =(par[0]*x[0])+par[1];    //
3165    return fitval;    TSQLResult *result = 0;
3166  }    TSQLRow    *row    = 0;
3167      TSQLResult *result2 = 0;
3168      TSQLRow    *row2   = 0;
3169      //
3170      UInt_t moved = 0;
3171      UInt_t timelim = 0;
3172      TDatime *time = new TDatime();
3173      //
3174      stringstream oss;
3175      oss.str("");
3176      //
3177      //
3178      //
3179      if ( olderthan < 0 ){
3180        if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n");
3181        return(1);
3182      };
3183      //
3184      // timelim = now - olderthan
3185      //
3186      time->Set();
3187      timelim =  (UInt_t)time->Convert() - olderthan;
3188      time->Set(timelim,false);
3189      //
3190      // check if there are entries older than "olderthan" seconds from now
3191      //
3192      oss.str("");
3193      oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3194          << " INSERT_TIME <= '" << time->AsSQLString() << "';";
3195      //
3196      if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str());
3197      result = conn->Query(oss.str().c_str());
3198      //
3199      if ( result ){
3200        //
3201        row = result->Next();
3202        //
3203        if ( row ){
3204          //
3205          oss.str("");
3206          oss << " ID= "<< row->GetField(0);
3207          //
3208          glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
3209          //
3210          oss.str("");
3211          oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE "
3212              << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND ("
3213              << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
3214              << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
3215              << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR "
3216              << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND ("
3217              << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR "
3218              << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR "
3219              << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "
3220              << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND ("
3221              << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "
3222              << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("
3223              << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "
3224              << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));";
3225          //
3226          if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str());
3227          result2 = conn->Query(oss.str().c_str());
3228          //
3229          if ( !result2 ) throw -4;
3230          //
3231          row2 = result2->Next();
3232          //
3233          if ( !row2 ){
3234            //
3235            if ( IsDebug() ) printf(" The run is new \n");
3236            if ( IsDebug() ) printf(" -> fill the DB \n");      
3237            //
3238            glrun->SetID(0);
3239            glrun->Fill_GL_RUN(conn);  
3240            //
3241            oss.str("");
3242            oss << " SELECT ID FROM GL_RUN WHERE "
3243                << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND "
3244                << " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND "
3245                << " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND "
3246                << " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND "
3247                << " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; ";
3248            //
3249            if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str());
3250            result2 = conn->Query(oss.str().c_str());
3251            //
3252            if ( !result2 ) throw -4;
3253            //
3254            row2 = result2->Next();
3255            //
3256            if ( !row2 ) throw -25;
3257            //
3258            oss.str("");
3259            oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0);
3260            if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str());
3261            result2 = conn->Query(oss.str().c_str());
3262            //
3263            if ( !result2 ) throw -4;
3264            //
3265            moved++;
3266            //
3267          } else {
3268            if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n");
3269          };
3270          if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0));      
3271          //
3272          //
3273          oss.str("");
3274          oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0);
3275          if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str());
3276          result2 = conn->Query(oss.str().c_str());
3277          //
3278          if ( !result2 ) throw -4;
3279          //
3280        };
3281      };
3282      if ( IsDebug() ) printf(" Moved %u runs\n",moved);
3283      return(0);
3284    };
3285    
3286  /*  /**
3287   * Fit the S4 calibration with a straight line - Received from Valeria Malvezzi 06/02/2006   * Check if runs are good, i.e. if the tracker calibration is correctly associated..
3288   */   */
3289  TArrayD PamelaDBOperations::S4_paramfit(pamela::CalibS4Event *S4CalibEvent){        Int_t PamelaDBOperations::ValidateRuns(){
3290      //
3291    //----------- variable initialization -------------------------------------------------    TSQLResult *result = 0;
3292      TSQLRow    *row    = 0;
3293    Double_t mip[3]={1, 30, 300};    //
3294    Double_t adc[3] = {0.,0.,0.};    UInt_t timelim = 0;
3295      TDatime *time = new TDatime();
3296      //
3297      stringstream oss;
3298      oss.str("");
3299      //
3300      //
3301      //
3302      if ( olderthan < 0 ){
3303        if ( IsDebug() ) printf(" Do not validate runs \n");
3304        return(1);
3305      };
3306      //
3307      // timelim = now - olderthan
3308      //
3309      time->Set();
3310      timelim =  (UInt_t)time->Convert() - olderthan;
3311      time->Set(timelim,false);
3312    
3313      printf("Validate runs older than %s \n",time->AsSQLString());
3314    
3315      // =======================================================
3316      // validate runs by checking missing calibrations
3317      // =======================================================
3318      UInt_t t_stop  = 0;
3319      UInt_t t_start = 0;
3320      // --------------------------------------------------------------
3321      // 1) get the OBT of the last run inserted after clean-time limit
3322      // --------------------------------------------------------------
3323      oss.str("");
3324      oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << time->AsSQLString()
3325          << "' ORDER BY INSERT_TIME DESC LIMIT 1;";
3326      printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3327      result = conn->Query(oss.str().c_str());
3328      if ( !result ) throw -4;
3329      if ( !result->GetRowCount() ) {
3330              printf(" No runs to validate \n");
3331              return(1);
3332      }else{
3333            row = result->Next();
3334            t_start = (UInt_t)atoll(row->GetField(4));
3335            printf("t_start %i\n",t_start);
3336      };  
3337      // --------------------------------------------------------------
3338      // 2) get the OBT of the last validated run
3339      // --------------------------------------------------------------
3340      oss.str("");
3341      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3342          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3343      printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
3344      result = conn->Query(oss.str().c_str());
3345      if ( !result ) throw -4;
3346      if ( result->GetRowCount() ){
3347              row = result->Next();
3348              t_stop = (UInt_t)atoll(row->GetField(4));
3349      };
3350      printf("t_stop %i\n",t_stop);
3351      // --------------------------------------------------------------
3352      // now retrieves runs to be validated
3353      // --------------------------------------------------------------
3354      oss.str("");
3355      oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;
3356      oss << " AND RUNHEADER_TIME >="<< t_stop;
3357      oss << " ORDER BY RUNHEADER_TIME DESC;";
3358    //  if ( IsDebug() )
3359      printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());
3360      result = conn->Query(oss.str().c_str());
3361      if ( !result ) throw -4;
3362      if ( !result->GetRowCount() ) printf(" No runs to validate \n");
3363      printf("------------------------------------------------------------------------------- \n");
3364        
3365    TArrayD parametri(2);    Int_t nrow = 0;
3366      GL_RUN* this_run = new GL_RUN();
3367    valid = 1;    GL_RUN* next_run = new GL_RUN();
3368      Int_t   nseq_max = 100;
3369    //------------ Fit calibrations and find parameters to calibrate data ------------------  //  UInt_t* sequence = new UInt_t[100];
3370    pamela::S4::S4Event  *s4Record;    vector<UInt_t> sequence(nseq_max);
3371      Int_t   nseq = 0;
3372      Bool_t CHECK = false;
3373      Bool_t this_ONLINE = false;
3374      Bool_t next_ONLINE = false;
3375      UInt_t t1=0,t2=0;
3376      // ---------------------------------------------------------------------------------
3377      // - loop over runs, back in time,
3378      // - select sequences of runs close in time (less than 60 s apart),
3379      //   which could be preceeded by a calibration
3380      // - check if there might be a missing calibration
3381      // ---------------------------------------------------------------------------------
3382      while(1){
3383              
3384              row = result->Next();
3385              if( row == NULL ) break;
3386              
3387              //------------
3388              //get run info
3389              //------------
3390              this_run->Set_GL_RUN(row);
3391              
3392              printf(" RUN ID %i --- TRK_CALIB_USED %i --- RM_ACQ_AFTER_CALIB %i --- TIME %i %i \n",this_run->ID,this_run->TRK_CALIB_USED,this_run->RM_ACQ_AFTER_CALIB,this_run->RUNHEADER_TIME, this_run->RUNTRAILER_TIME);
3393              
3394              Bool_t this_BAD = false;
3395              if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true;
3396              else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;
3397              else{
3398                      printf("Missing or corrupted header!! \n");
3399                      this_ONLINE = false;
3400                      this_BAD = true;
3401              };
3402    
3403    for (Int_t j = 0; j < 4; j++){            //-----------------------------------
3404      for (Int_t i = 0; i < 128; i++){            //compare with previous(next in time)
3405        s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i));            //-----------------------------------
3406        switch (j) {            CHECK = false;
3407        case 0 :{            UInt_t interval=0;
3408          adc[0]=adc[0]+((s4Record->S4_DATA)-32);            
3409          break;            if( nrow != 0){
3410        };          
3411        case 1 :{                    
3412          adc[1]=adc[1]+((s4Record->S4_DATA)-32);                    t1 = this_run->GetRUNTRAILER_TIME();
3413          break;                    t2 = next_run->GetRUNHEADER_TIME();
3414        };                    interval = (t2-t1);
3415        case 3 :{                    
3416          adc[2]=adc[2]+((s4Record->S4_DATA)-32);                    if(this_ONLINE && next_ONLINE){                               // this: ON-LINE + next: ON-LINE
3417          break;                            
3418        };                            if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments
3419        };                            
3420      };                            if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration
3421                              
3422    /*                        if( CHECK && !next_run->GetRM_ACQ_AFTER_CALIB() )
3423                                      printf(" ValidateRuns ***WARNING*** : DT = %i but RM_ACQ_AFTER_CALIB = %i \n",(t2-t1),next_run->GetRM_ACQ_AFTER_CALIB());*/
3424                                                      
3425                              
3426                              if( !CHECK && this_run->VALIDATION ){
3427                                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
3428                                      nseq=0;
3429                              }
3430                      
3431                      }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE
3432                              
3433                              CHECK = true;
3434    //                        if( interval < 60 ) printf(" ValidateRuns ***WARNING*** : kkkkkk DT = %i \n",interval);
3435    
3436                      }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT
3437                              
3438                              assignVALIDATION(next_run->ID,true);
3439                              nseq=0;
3440                      }
3441              }
3442    
3443              //----------------------------
3444              //check run sequence for calib
3445              //----------------------------
3446              if( CHECK ){
3447                      // check if calibration exists
3448                      printf("DT %i ===> CHECK Missing calibration\n",interval);
3449                      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
3450                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);
3451                      nseq=0;
3452              } else printf("DT %i\n",interval);
3453              //--------------
3454              //store run info
3455              //--------------
3456              *next_run   = *this_run;
3457              next_ONLINE = this_ONLINE;
3458              if( !this_BAD ){
3459                      if(nseq < nseq_max){
3460                              sequence[nseq] = this_run->ID;
3461                              nseq++;
3462                      }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);
3463              };
3464              
3465              nrow++;
3466              
3467    };    };
3468        delete this_run;
3469    adc[0]=adc[0]/128;    delete next_run;
3470    adc[1]=adc[1]/128;    //
3471    adc[2]=adc[2]/128;    return(0);
3472      };
3473    TGraph *fitpar = new TGraph (3, adc, mip);  /**
3474    TF1 *func = new TF1("fitf", fitf, -0., 1000., 2); // definizione della funzione, 2 = num. parametri   * Check if there might be a missing tracker calibration in a given time interval
3475       * @param t1 From absolute time
3476    func->SetParameters(0.3,1.);        //inizializzazione dei parametri a 1   * @param t2 To absolute time
3477    func->SetParNames("m","q");      //definisce il nome dei parametri   * @return true if there might be a missing calibration
3478    fitpar->Fit(func,"qr");          //fitta fitpar con la funzione func nel range definito nella funzione   */
3479    //fitpar->Fit(func,"r");          //fitta fitpar con la funzione func nel range definito nella funzione  Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
3480                
3481    parametri[0] = func -> GetParameter(0);          GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
3482    parametri[1] = func -> GetParameter(1);          
3483            // get the closest VALIDATED calibration before the run start (t2)
3484            if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);      //>>> missing
3485            
3486            if ( trkcalib->TO_TIME  < t2 ) return(true);                                    //>>> missing
3487            
3488            //==============================================================
3489            // Check is done first on the basis of time between calibration,
3490            // which should be equal to the time between ascending-nodes.
3491            //==============================================================
3492            if ( t2 - trkcalib->FROM_TIME > 5700) {
3493                    printf("Long time to previous calib %i :-( \n",t2 - trkcalib->FROM_TIME);
3494            //==============================================================
3495            // there might be a missing calibration, due to:
3496            // - MM full
3497            // - corrupted packets
3498            // - loss of data
3499            // There is an exception in case a download was done during ascending node
3500            //==============================================================
3501                    Bool_t DOWNLOAD = false;
3502                    // check if the calib was skipped becouse of download .... DA FARE!!
3503                    if(DOWNLOAD)return(false);
3504                    
3505                    return(true);                                   //>>> missing
3506                    
3507            };
3508            
3509            //==============================================================
3510            // If the last calibration is close to the run less than this time,
3511            // it is enough to say that there are no missing calibrations
3512            //==============================================================
3513            // the long time interval bewteen runs might be due to download
3514            printf("Short time to previous calib %i :-) \n",t2 - trkcalib->FROM_TIME);
3515            return(false);
3516            
3517    };
3518    /**
3519     * Assign VALIDATION value to a GL_RUN entry
3520     * @param idrun Run ID
3521     * @param validation true/false
3522     */
3523    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
3524            TSQLResult *result = 0;
3525            stringstream oss;
3526            oss.str("");
3527            oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << "';";
3528            //
3529    //      if ( IsDebug() )
3530            printf(" Set VALIDATION = %i for run %i \n",validation,idrun);
3531    //      printf(" Set VALIDATION = %i for run %i : query is \n %s \n",validation,idrun,oss.str().c_str());
3532    //      result = conn->Query(oss.str().c_str());
3533    //      if ( !result ) throw -4;
3534            return(0);
3535    }
3536    
3537    
   if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.8 || parametri[1] > 1. ) valid = 0;  
3538    
   if ( IsDebug() ) printf(" par1 = %g par2 = %g\n",parametri[0],parametri[1]);  
   
   return parametri;  
 };  

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.23