/[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.9 by mocchiut, Tue Sep 12 07:28:46 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 64  PamelaDBOperations::PamelaDBOperations(T Line 63  PamelaDBOperations::PamelaDBOperations(T
63    SetObt0(obt0);    SetObt0(obt0);
64    //    //
65    //    //
66    SetRootName(filerootname);    INSERT_RAW =!filerawname.IsNull();
67    SetRawName(filerawname);    if(INSERT_RAW)SetRawName(filerawname);
68    //    //
69    this->OpenFile();    INSERT_ROOT = !filerootname.IsNull();
70      if( INSERT_ROOT ){
71        file = TFile::Open(this->GetRootName().Data());
72        //    if ( !file ) INSERT_ROOT = false;
73      };
74      //  this->OpenFile();
75    //    //
76    this->SetID_RAW(0);    this->SetID_RAW(0);
77    this->SetID_ROOT(0);    this->SetID_ROOT(0);
78    
79      VALIDATE = false;
80      
81    //    //
82  };  };
83    
# Line 79  PamelaDBOperations::PamelaDBOperations(T Line 86  PamelaDBOperations::PamelaDBOperations(T
86   */   */
87  void PamelaDBOperations::Close(){  void PamelaDBOperations::Close(){
88    if( conn && conn->IsConnected() ) conn->Close();    if( conn && conn->IsConnected() ) conn->Close();
89      delete clean_time;
90    delete glrun;    delete glrun;
91    delete this;    delete this;
92  };  };
# Line 87  void PamelaDBOperations::Close(){ Line 95  void PamelaDBOperations::Close(){
95  // SETTERS  // SETTERS
96  //  //
97    
98    //
99    // must be out of the constructor in order to FORCE the validation of the latest runs in case you run the validation together with the latest file
100    //
101    void PamelaDBOperations::CheckValidate(Long64_t olderthan){
102      clean_time = new TDatime();
103      if(olderthan >= 0){
104        VALIDATE = true;
105        UInt_t timelim = 0;
106        timelim =  (UInt_t)clean_time->Convert() - olderthan;
107        clean_time->Set(timelim,false);
108      };
109    };
110    
111  /**  /**
112   * Open the DB connection   * Open the DB connection
113   * @param host         hostname for the SQL connection.   * @param host         hostname for the SQL connection.
# Line 170  void PamelaDBOperations::SetNOBOOT(Bool_ Line 191  void PamelaDBOperations::SetNOBOOT(Bool_
191  };  };
192    
193  /**  /**
194     * Store the olderthan variable
195     * @param olderthan
196     */
197    // void PamelaDBOperations::SetOlderThan(Long64_t oldthan){
198    //   olderthan = oldthan;
199    // };
200    
201    /**
202   * Retrieve the ID_RAW, if exists, returns NULL if does not exist.   * Retrieve the ID_RAW, if exists, returns NULL if does not exist.
203   */   */
204  Bool_t PamelaDBOperations::SetID_RAW(){  Bool_t PamelaDBOperations::SetID_RAW(){
# Line 181  Bool_t PamelaDBOperations::SetID_RAW(){ Line 210  Bool_t PamelaDBOperations::SetID_RAW(){
210        << " PATH = '" << this->GetRawPath().Data() << "' AND "        << " PATH = '" << this->GetRawPath().Data() << "' AND "
211        << " NAME = '" << this->GetRawFile().Data() << "' ";        << " NAME = '" << this->GetRawFile().Data() << "' ";
212    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
213    if (result == NULL) throw -4;    if ( result == NULL ) throw -4;
214    row = result->Next();    row = result->Next();
215    if (row == NULL) return false;    if ( !row ) return(false);
216    delete result;    delete result;
217    id = (UInt_t)atoll(row->GetField(0));    id = (UInt_t)atoll(row->GetField(0));
218    return(true);    return(true);
# Line 216  Int_t PamelaDBOperations::SetUpperLimits Line 245  Int_t PamelaDBOperations::SetUpperLimits
245    ULong64_t upperobt2 = 0;    ULong64_t upperobt2 = 0;
246    UInt_t zomp = 0;    UInt_t zomp = 0;
247    UInt_t jump = 50000; // was 5000    UInt_t jump = 50000; // was 5000
248      EventCounter *code=0;
249      //
250      //   pcksList packetsNames;
251      //   pcksList::iterator Iter;
252      //   getPacketsNames(packetsNames);
253    //    //
254    pktfirst = 0;    pktfirst = 0;
255    obtfirst = 0;    obtfirst = 0;
# Line 233  Int_t PamelaDBOperations::SetUpperLimits Line 267  Int_t PamelaDBOperations::SetUpperLimits
267    pktfirst = ph->GetCounter();    pktfirst = ph->GetCounter();
268    obtfirst = ph->GetOrbitalTime();      obtfirst = ph->GetOrbitalTime();  
269    //    //
270      //   code = eh->GetCounter();
271      //   UInt_t en = 0;
272      //   for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
273      //     en = code->Get(GetPacketType(*Iter));
274      //     if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en);
275      //};  
276      //
277    T->GetEntry(nevent-1);    T->GetEntry(nevent-1);
278    ph = eh->GetPscuHeader();    ph = eh->GetPscuHeader();
279    pktlast = ph->GetCounter();    pktlast = ph->GetCounter();
# Line 301  Int_t PamelaDBOperations::SetUpperLimits Line 342  Int_t PamelaDBOperations::SetUpperLimits
342    // 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)
343    //    //
344    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);  
345    TTree *rh=(TTree*)file->Get("RunHeader");    TTree *rh=(TTree*)file->Get("RunHeader");
346    if ( !rh || rh->IsZombie() ) throw -17;    if ( !rh || rh->IsZombie() ) throw -17;
347    TTree *rt=(TTree*)file->Get("RunTrailer");    TTree *rt=(TTree*)file->Get("RunTrailer");
# Line 319  Int_t PamelaDBOperations::SetUpperLimits Line 355  Int_t PamelaDBOperations::SetUpperLimits
355    //    //
356    rhev = rh->GetEntries();    rhev = rh->GetEntries();
357    rtev = rt->GetEntries();    rtev = rt->GetEntries();
358      UInt_t sobtt = 0;
359      UInt_t sobth = 0;
360      UInt_t spktt = 0;
361      UInt_t spkth = 0;
362    UInt_t pktt = 0;    UInt_t pktt = 0;
363    ULong64_t obtt = 0;    ULong64_t obtt = 0;
364    UInt_t pkth = 0;    UInt_t pkth = 0;
365    ULong64_t obth = 0;    ULong64_t obth = 0;
366    //    //
367      T->GetEntry(upperentry);
368      code = eh->GetCounter();
369      Int_t lasttrail = code->Get(pctp->RunTrailer);
370      Int_t lasthead = code->Get(pctp->RunHeader);
371    if ( lasttrail < rtev ){    if ( lasttrail < rtev ){
372      rt->GetEntry(lasttrail);      rt->GetEntry(lasttrail);
373      pht = eht->GetPscuHeader();      pht = eht->GetPscuHeader();
# Line 331  Int_t PamelaDBOperations::SetUpperLimits Line 375  Int_t PamelaDBOperations::SetUpperLimits
375      obtt = OBT(pht->GetOrbitalTime());      obtt = OBT(pht->GetOrbitalTime());
376    };    };
377    //    //
378      if ( lasthead < rhev ){
379        rh->GetEntry(lasthead);
380        phh = ehh->GetPscuHeader();
381        pkth = PKT(phh->GetCounter());
382        obth = OBT(phh->GetOrbitalTime());
383      };
384      //
385      if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
386      if ( pkth > upperpkt && obth > upperobt ){
387        if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt);
388        upperpkt = pkth;
389        upperobt = obth;
390        rhev = lasthead+1;
391      } else {
392        rhev = lasthead;
393      };
394      if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
395      //
396    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);
397    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
398      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 403  Int_t PamelaDBOperations::SetUpperLimits
403      rtev = lasttrail;      rtev = lasttrail;
404    };    };
405    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);
406      //  goto kikko;
407      //
408      //
409      // Check if runtrailer/runheader are within lower limits
410      //
411      //
412      pkth = 0;
413      obth = 0;
414      spkth = 0;
415      sobth = 0;
416      for (Int_t k=0; k<rhev; k++){
417        if ( k > 0 ){
418          spkth = pkth;
419          sobth = obth;
420        };
421        rh->GetEntry(k);
422        phh = ehh->GetPscuHeader();
423        pkth = PKT(phh->GetCounter());
424        obth = OBT(phh->GetOrbitalTime());
425        //
426    //    if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth);
427        //
428        if ( pkth < spkth && obth < sobth ){
429          if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i  \n",rhev);
430          //
431          rhev = k-1;
432          rh->GetEntry(rhev);
433          pkth = spkth;
434          obth = sobth;
435          //
436          UInt_t evbefh = 0;
437          code = ehh->GetCounter();
438          evbefh = code->Get(pctp->Physics);    
439          if ( evbefh >= 0 ){
440            T->GetEntry(evbefh);
441            ph = eh->GetPscuHeader();
442            t_pktlast = PKT(ph->GetCounter());
443            t_obtlast = OBT(ph->GetOrbitalTime());
444            if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump
445              upperpkt = pkth;
446              upperobt = obth;
447              upperentry = evbefh-1;
448            } else {
449              while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){
450                evbefh++;  
451                T->GetEntry(evbefh);
452                ph = eh->GetPscuHeader();
453                t_pktlast = PKT(ph->GetCounter());
454                t_obtlast = OBT(ph->GetOrbitalTime());
455              };
456              T->GetEntry(evbefh-1);
457              ph = eh->GetPscuHeader();
458              upperpkt = PKT(ph->GetCounter());
459              upperobt = OBT(ph->GetOrbitalTime());
460              upperentry = evbefh-1;
461            };    
462          };
463          if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
464          goto kikko0;
465        };
466      };
467     kikko0:
468      //
469      //
470      //
471      pktt = 0;
472      obtt = 0;
473      spktt = 0;
474      sobtt = 0;
475      for (Int_t k=0; k<rtev; k++){
476        if ( k > 0 ){
477          spktt = pktt;
478          sobtt = obtt;
479        };
480        rt->GetEntry(k);
481        pht = eht->GetPscuHeader();
482        pktt = PKT(pht->GetCounter());
483        obtt = OBT(pht->GetOrbitalTime());
484        //
485    //    if ( IsDebug() ) printf(" k %i rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt);
486        //
487        if ( pktt < spktt && obtt < sobtt ){
488          if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev);
489          //
490          rtev = k-1;
491          rt->GetEntry(rtev);
492          pktt = spktt;
493          obtt = sobtt;
494          if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
495          //
496          UInt_t evbeft = 0;
497          code = eht->GetCounter();
498          evbeft = code->Get(pctp->Physics);    
499          if ( evbeft >= 0 ){
500            T->GetEntry(evbeft);
501            ph = eh->GetPscuHeader();
502            t_pktlast = PKT(ph->GetCounter());
503            t_obtlast = OBT(ph->GetOrbitalTime());
504            if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump
505              upperpkt = pktt;
506              upperobt = obtt;
507              upperentry = evbeft-1;
508            } else {
509              while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){
510                evbeft++;  
511                T->GetEntry(evbeft);
512                ph = eh->GetPscuHeader();
513                t_pktlast = PKT(ph->GetCounter());
514                t_obtlast = OBT(ph->GetOrbitalTime());
515              };
516              T->GetEntry(evbeft-1);
517              ph = eh->GetPscuHeader();
518              upperpkt = PKT(ph->GetCounter());
519              upperobt = OBT(ph->GetOrbitalTime());
520              upperentry = evbeft-1;
521            };
522          };
523          if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
524          goto kikko;
525          //      break;
526          //
527        };
528        //  
529      };
530      //
531     kikko:
532      //
533      T->GetEntry(upperentry);
534      code = eh->GetCounter();
535      lasttrail = code->Get(pctp->RunTrailer);
536      lasthead = code->Get(pctp->RunHeader);
537      if ( lasttrail < rtev ){
538        rt->GetEntry(lasttrail);
539        pht = eht->GetPscuHeader();
540        pktt = PKT(pht->GetCounter());
541        obtt = OBT(pht->GetOrbitalTime());
542      };
543    //    //
544    if ( lasthead < rhev ){    if ( lasthead < rhev ){
545      rh->GetEntry(lasthead);      rh->GetEntry(lasthead);
546      phh = ehh->GetPscuHeader();      phh = ehh->GetPscuHeader();
547      pkth = PKT(pht->GetCounter());      pkth = PKT(phh->GetCounter());
548      obth = OBT(pht->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
549    };    };
550    //    //
551    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 559  Int_t PamelaDBOperations::SetUpperLimits
559    };    };
560    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);
561    //    //
562      if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
563      if ( pktt > upperpkt && obtt > upperobt ){
564        if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt);
565        upperpkt = pktt;
566        upperobt = obtt;
567        rtev = lasttrail+1;
568      } else {
569        rtev = lasttrail;
570      };
571      if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
572      //
573    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);
574    //    //
575    return(0);    return(0);
# Line 440  const PacketType* PamelaDBOperations::Ge Line 650  const PacketType* PamelaDBOperations::Ge
650  // PRIVATE FUNCTIONS  // PRIVATE FUNCTIONS
651  //  //
652    
653  /**  // /**
654   * Open the ROOT filename for reading  // * Open the ROOT filename for reading
655   */  // */
656  void PamelaDBOperations::OpenFile(){  // void PamelaDBOperations::OpenFile(){
657    file = TFile::Open(this->GetRootName().Data());  //   file = TFile::Open(this->GetRootName().Data());
658    //   //
659    
660    void PamelaDBOperations::CheckFile(){  
661      if ( !file ) throw -12;
662  };  };
663    
664    
665  /**  /**
666   * Check if LEVEL0 file and DB connection have really be opened   * Check if LEVEL0 file and DB connection have really be opened
667   */   */
668  void PamelaDBOperations::CheckFile(){    void PamelaDBOperations::CheckConnection(){  
   //  
   if ( !file ) throw -12;  
669    //    //
670    // check connection    // check connection
671    //    //
672    if( !conn ) throw -1;        if( !conn ) throw -1;
673    bool connect = conn->IsConnected();    bool connect = conn->IsConnected();
674    if( !connect ) throw -1;        if( !connect ) throw -1;
675  };  };
676    
677  /**  /**
# Line 550  void PamelaDBOperations::FillClass(Bool_ Line 762  void PamelaDBOperations::FillClass(Bool_
762      lastPkt = glrun->GetRUNTRAILER_PKT();      lastPkt = glrun->GetRUNTRAILER_PKT();
763    };    };
764    //    //
765    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
766    //    //
767    if ( mishead ) {    if ( mishead ) {
768      glrun->Set_GL_RUNH0();      glrun->Set_GL_RUNH0();
# Line 668  Int_t PamelaDBOperations::insertPamelaGL Line 880  Int_t PamelaDBOperations::insertPamelaGL
880    };    };
881    //    //
882    TTree *T = 0;    TTree *T = 0;
883      Int_t signal = 0;
884    //    //
885    UInt_t nevent = 0;    UInt_t nevent = 0;
886    UInt_t recEntries = 0;    UInt_t recEntries = 0;
# Line 721  Int_t PamelaDBOperations::insertPamelaGL Line 934  Int_t PamelaDBOperations::insertPamelaGL
934          //          //
935          if ( TSYNC && OBT ){          if ( TSYNC && OBT ){
936            existsts = true;            existsts = true;
937            goto out;            goto eout;
938          };          };
939          //          //
940        };        };
# Line 729  Int_t PamelaDBOperations::insertPamelaGL Line 942  Int_t PamelaDBOperations::insertPamelaGL
942    };    };
943    if ( !existsts ) { // try with runheader and runtrailer    if ( !existsts ) { // try with runheader and runtrailer
944      //      //
945        if ( IsDebug() ) printf(" No ts mcmd \n");
946        signal = 2;
947        //
948      TTree *rh=(TTree*)file->Get("RunHeader");      TTree *rh=(TTree*)file->Get("RunHeader");
949      if ( !rh || rh->IsZombie() ) throw -17;      if ( !rh || rh->IsZombie() ) throw -17;
950      TTree *rt=(TTree*)file->Get("RunTrailer");      TTree *rt=(TTree*)file->Get("RunTrailer");
# Line 738  Int_t PamelaDBOperations::insertPamelaGL Line 954  Int_t PamelaDBOperations::insertPamelaGL
954      //      //
955      rt->SetBranchAddress("RunTrailer", &runt);      rt->SetBranchAddress("RunTrailer", &runt);
956      //      //
     //    Int_t rhev = rh->GetEntries();  
     //    Int_t rtev = rt->GetEntries();  
     //  
957      if ( rhev > 0 ){      if ( rhev > 0 ){
958        rh->GetEntry(0);        rh->GetEntry(0);
959        //        //
# Line 751  Int_t PamelaDBOperations::insertPamelaGL Line 964  Int_t PamelaDBOperations::insertPamelaGL
964        //        //
965        if ( TSYNC && OBT ){        if ( TSYNC && OBT ){
966          existsts = true;          existsts = true;
967          goto out;          goto eout;
968        };        };
969        //        //
970      };      };
971      if ( rtev > 0 ){      if ( rtev > 0 ){
972          //
973          if ( IsDebug() ) printf(" No runheader \n");
974          signal = 6;
975          //
976        rt->GetEntry(0);        rt->GetEntry(0);
977        //        //
978        TSYNC = runt->LAST_TYME_SYNC_INFO;        TSYNC = runt->LAST_TYME_SYNC_INFO;
# Line 765  Int_t PamelaDBOperations::insertPamelaGL Line 982  Int_t PamelaDBOperations::insertPamelaGL
982        //        //
983        if ( TSYNC && OBT ){        if ( TSYNC && OBT ){
984          existsts = true;          existsts = true;
985          goto out;          goto eout;
986        };        };
987        //        //
988        } else {
989          if ( IsDebug() ) printf(" No runheader \n");
990      };      };
991    };    };
992    //    //
993    if ( !existsts ){ // try with inclination mcmd    if ( !existsts ){ // try with inclination mcmd
994        //
995        if ( IsDebug() ) printf(" No runtrailer \n");
996        signal = 14;
997        //
998      Double_t timesync = 0.;      Double_t timesync = 0.;
999      for (UInt_t i=0; i<nevent;i++){      for (UInt_t i=0; i<nevent;i++){
1000        //        //
# Line 800  Int_t PamelaDBOperations::insertPamelaGL Line 1023  Int_t PamelaDBOperations::insertPamelaGL
1023        TYPE = 666;        TYPE = 666;
1024        if ( TSYNC && OBT ){        if ( TSYNC && OBT ){
1025          existsts = true;          existsts = true;
1026          goto out;          goto eout;
1027        };        };
1028      };      };
1029    };    };
1030    //    //
1031    if ( !existsts && obt0 ){ // insert timesync by hand    if ( !existsts && obt0 ){ // insert timesync by hand
1032        //
1033        if ( IsDebug() ) printf(" No incl mcmd \n");
1034        signal = 30;
1035        //
1036      OBT = obt0;      OBT = obt0;
1037      TSYNC = tsync;      TSYNC = tsync;
1038      TYPE = 999;      TYPE = 999;
1039      existsts = true;      existsts = true;
1040      goto out;      goto eout;
1041    };    };
1042    //    //
1043   out:   eout:
1044    //    //
1045    if ( !existsts ) throw -3;    if ( !existsts ) throw -3;
1046    //    //
# Line 829  Int_t PamelaDBOperations::insertPamelaGL Line 1056  Int_t PamelaDBOperations::insertPamelaGL
1056    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;
1057    //    //
1058    delete result;    delete result;
1059    return(0);    return(signal);
1060  }  }
1061    
1062  /**  /**
# Line 907  Int_t PamelaDBOperations::assignBOOT_NUM Line 1134  Int_t PamelaDBOperations::assignBOOT_NUM
1134        << " NAME = '" << this->GetRawFile().Data() << "' ";        << " NAME = '" << this->GetRawFile().Data() << "' ";
1135    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
1136    //    //
1137    if ( !result ) return(8);    if ( !result ) throw -4;;
1138    row = result->Next();    row = result->Next();
1139    if ( !row ) return(16);    if ( !row ) return(16);
1140    if ( row->GetField(1) ){    if ( row->GetField(1) ){
1141      this->SetBOOTnumber((UInt_t)atoll(row->GetField(1)));      this->SetBOOTnumber((UInt_t)atoll(row->GetField(1)));
1142      return(1);      return(1);
1143    };    };
1144    if ( !row->GetField(0) ) return(8);    if ( !row->GetField(0) ) throw -26;
1145    //    //
1146    UInt_t idRaw = (UInt_t)atoll(row->GetField(0));    UInt_t idRaw = (UInt_t)atoll(row->GetField(0));
1147    //    //
# Line 924  Int_t PamelaDBOperations::assignBOOT_NUM Line 1151  Int_t PamelaDBOperations::assignBOOT_NUM
1151    trDumpEv = (TTree*)file->Get("VarDump");    trDumpEv = (TTree*)file->Get("VarDump");
1152    if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20;    if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20;
1153    //    //
   if (trDumpEv == NULL) return(2);  
   //      
1154    VarDumpEvent  *vde = 0;    VarDumpEvent  *vde = 0;
1155    VarDumpRecord *vdr = 0;    VarDumpRecord *vdr = 0;
1156    //    //
1157    trDumpEv->SetBranchAddress("VarDump", &vde);    trDumpEv->SetBranchAddress("VarDump", &vde);
1158    if (trDumpEv->GetEntries() > 0){    if ( trDumpEv->GetEntries() > 0 ){
1159      trDumpEv->GetEntry(0);      Bool_t found = false;
1160      vde->Records->GetEntries();      for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){
1161      if ( !vde->Records->GetEntries() ){        trDumpEv->GetEntry(i);
1162        if ( !this->GetBOOTnumber() ) return(4);        vde->Records->GetEntries();
1163      } else {        if ( vde->Records->GetEntries()>0 ){
1164            found = true;
1165            goto fill;
1166          };
1167        };
1168      fill:
1169        if ( found ){
1170          //
1171        vdr = (VarDumpRecord*)vde->Records->At(6);        vdr = (VarDumpRecord*)vde->Records->At(6);
1172          //
1173        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);
1174          //
1175        } else {
1176          if ( !this->GetBOOTnumber() ) return(4);
1177      };      };
1178    } else {    } else {
1179      if ( !this->GetBOOTnumber() ) return(2);      if ( !this->GetBOOTnumber() ) return(2);
# Line 1023  Int_t PamelaDBOperations::insertPamelaRU Line 1259  Int_t PamelaDBOperations::insertPamelaRU
1259          //          //
1260          if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt);          if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt);
1261          //          //
1262          if ( (ptt-1) < 0 ) throw -15;          if ( (ptt-1) < 0 ) throw -15; // should never arrive here!
1263          rt->GetEntry(ptt-1);          rt->GetEntry(ptt-1);
1264          cod = eht->GetCounter();          cod = eht->GetCounter();
1265          evbefh = cod->Get(pctp->Physics);          evbefh = cod->Get(pctp->Physics);
# Line 1129  Int_t PamelaDBOperations::insertPamelaRU Line 1365  Int_t PamelaDBOperations::insertPamelaRU
1365            if ( (UInt_t)evbeft < upperentry-1 ){            if ( (UInt_t)evbeft < upperentry-1 ){
1366              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");
1367              //              //
1368              if ( (ptt-1) < 0 ) throw -15;              if ( (ptt-1) < 0 ) throw -15; // should never arrive here!
1369              rt->GetEntry(ptt-1);              rt->GetEntry(ptt-1);
1370              cod = eht->GetCounter();              cod = eht->GetCounter();
1371              evbefh = cod->Get(pctp->Physics);              evbefh = cod->Get(pctp->Physics);
# Line 2106  void PamelaDBOperations::HandleSuspiciou Line 2342  void PamelaDBOperations::HandleSuspiciou
2342    if ( firstev == lastev+1 ) { // no events inside the run!    if ( firstev == lastev+1 ) { // no events inside the run!
2343      if ( IsDebug() ) printf(" Checking but no events in the run! \n");      if ( IsDebug() ) printf(" Checking but no events in the run! \n");
2344      //      //
     //    if ( IsDebug() ) printf(" -> fill the DB \n");  
     //  
2345      this->FillClass();      this->FillClass();
2346      if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn);          if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn);    
2347      //      //
# Line 2318  Int_t PamelaDBOperations::insertCALO_CAL Line 2552  Int_t PamelaDBOperations::insertCALO_CAL
2552    tr->SetBranchAddress("Header", &eh);    tr->SetBranchAddress("Header", &eh);
2553    nevents = tr->GetEntries();    nevents = tr->GetEntries();
2554    //    //
2555    if ( !nevents ) return(0);    if ( !nevents ) return(1);
2556    //    //
2557    for (UInt_t i=0; i < nevents; i++){    for (UInt_t i=0; i < nevents; i++){
2558      tr->GetEntry(i);      tr->GetEntry(i);
# Line 2635  Int_t PamelaDBOperations::insertTRK_CALI Line 2869  Int_t PamelaDBOperations::insertTRK_CALI
2869    tr2->SetBranchAddress("Header", &eh2);    tr2->SetBranchAddress("Header", &eh2);
2870    nevents2 = tr2->GetEntries();    nevents2 = tr2->GetEntries();
2871    //    //
2872    if ( !nevents1 && !nevents2 ) return(0);    if ( !nevents1 && !nevents2 ) return(1);
2873    //    //
2874    t2 = -1;    t2 = -1;
2875    Int_t pret2 = 0;    Int_t pret2 = 0;
# Line 2807  Int_t PamelaDBOperations::insertS4_CALIB Line 3041  Int_t PamelaDBOperations::insertS4_CALIB
3041    stringstream oss;    stringstream oss;
3042    oss.str("");    oss.str("");
3043    //    //
   CalibS4Event *calibS4    = new  CalibS4Event();  
3044    TTree *tr = 0;    TTree *tr = 0;
3045    EventHeader *eh = 0;    EventHeader *eh = 0;
3046    PscuHeader *ph = 0;    PscuHeader *ph = 0;
# Line 2821  Int_t PamelaDBOperations::insertS4_CALIB Line 3054  Int_t PamelaDBOperations::insertS4_CALIB
3054    tr = (TTree*)file->Get("CalibS4");    tr = (TTree*)file->Get("CalibS4");
3055    if ( !tr || tr->IsZombie() ) throw -24;    if ( !tr || tr->IsZombie() ) throw -24;
3056    //    //
   tr->SetBranchAddress("CalibS4", &calibS4);  
3057    tr->SetBranchAddress("Header", &eh);    tr->SetBranchAddress("Header", &eh);
3058    //    //
3059    nevents = tr->GetEntries();    nevents = tr->GetEntries();
3060    //    //
3061    if ( !nevents ) return(0);    if ( !nevents ) return(1);
3062    //    //
3063    for (UInt_t i = 0; i < nevents; i++){    for (UInt_t i = 0; i < nevents; i++){
3064      //      //
3065      tr->GetEntry(i);      tr->GetEntry(i);
     TArrayD params = S4_paramfit(calibS4);  
3066      //      //
3067      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
3068      obt = ph->GetOrbitalTime();        obt = ph->GetOrbitalTime();  
# Line 2921  Int_t PamelaDBOperations::insertS4_CALIB Line 3152  Int_t PamelaDBOperations::insertS4_CALIB
3152          };          };
3153          //          //
3154          oss.str("");          oss.str("");
3155          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) "
3156              << " VALUES (NULL,' "              << " VALUES (NULL,' "
3157              << idroot << "','"              << idroot << "','"
3158              << i << "','"              << i << "','"
3159              << fromtime << "','"              << fromtime << "','"
3160              << totime << "','"              << totime << "','"
             << dec << params.At(0) << "','"  
             << dec << params.At(1) << "','"        
3161              << obt << "','"              << obt << "','"
3162              << pkt << "','"              << pkt << "','"
3163              << this->GetBOOTnumber() << "','"              << this->GetBOOTnumber() << "');";
             << valid << "');";  
3164          //          //
3165          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());
3166          //          //
# Line 2953  Int_t PamelaDBOperations::insertS4_CALIB Line 3181  Int_t PamelaDBOperations::insertS4_CALIB
3181    return(0);    return(0);
3182  };  };
3183    
3184    /**
3185  /*   * Scan the fragment table and move old fragments to the GL_RUN table
  * Fit function Received from Valeria Malvezzi 06/02/2006  
3186   */   */
3187  Double_t fitf(Double_t *x, Double_t *par){    Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){
3188    Double_t fitval =(par[0]*x[0])+par[1];    //
3189    return fitval;    TSQLResult *result = 0;
3190  }    TSQLRow    *row    = 0;
3191      TSQLResult *result2 = 0;
3192      TSQLRow    *row2   = 0;
3193      //
3194      UInt_t moved = 0;
3195    //  UInt_t timelim = 0;
3196    //  TDatime *time = new TDatime();
3197      //
3198      stringstream oss;
3199      oss.str("");
3200      //
3201      //
3202      // check if there are entries older than "olderthan" seconds from now
3203      //
3204      oss.str("");
3205      oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3206          << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";
3207      //
3208      if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str());
3209      result = conn->Query(oss.str().c_str());
3210      //
3211      if ( result ){
3212        //
3213        row = result->Next();
3214        //
3215        if ( row ){
3216          //
3217          oss.str("");
3218          oss << " ID= "<< row->GetField(0);
3219          //
3220          glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
3221          //
3222          oss.str("");
3223          oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE "
3224              << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND ("
3225              << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
3226              << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
3227              << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR "
3228              << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND ("
3229              << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR "
3230              << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR "
3231              << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "
3232              << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND ("
3233              << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "
3234              << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("
3235              << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "
3236              << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));";
3237          //
3238          if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str());
3239          result2 = conn->Query(oss.str().c_str());
3240          //
3241          if ( !result2 ) throw -4;
3242          //
3243          row2 = result2->Next();
3244          //
3245          if ( !row2 ){
3246            //
3247            if ( IsDebug() ) printf(" The run is new \n");
3248            if ( IsDebug() ) printf(" -> fill the DB \n");      
3249            //
3250            glrun->SetID(0);
3251            glrun->Fill_GL_RUN(conn);  
3252            //
3253            oss.str("");
3254            oss << " SELECT ID FROM GL_RUN WHERE "
3255                << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND "
3256                << " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND "
3257                << " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND "
3258                << " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND "
3259                << " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; ";
3260            //
3261            if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str());
3262            result2 = conn->Query(oss.str().c_str());
3263            //
3264            if ( !result2 ) throw -4;
3265            //
3266            row2 = result2->Next();
3267            //
3268            if ( !row2 ) throw -25;
3269            //
3270            oss.str("");
3271            oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0);
3272            if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str());
3273            result2 = conn->Query(oss.str().c_str());
3274            //
3275            if ( !result2 ) throw -4;
3276            //
3277            moved++;
3278            //
3279          } else {
3280            if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n");
3281          };
3282          if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0));      
3283          //
3284          //
3285          oss.str("");
3286          oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0);
3287          if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str());
3288          result2 = conn->Query(oss.str().c_str());
3289          //
3290          if ( !result2 ) throw -4;
3291          //
3292        };
3293      };
3294      if ( IsDebug() ) printf(" Moved %u runs\n",moved);
3295      return(0);
3296    };
3297    
3298  /*  /**
3299   * 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..
3300   */   */
3301  TArrayD PamelaDBOperations::S4_paramfit(pamela::CalibS4Event *S4CalibEvent){        Int_t PamelaDBOperations::ValidateRuns(){
3302      //
3303    //----------- variable initialization -------------------------------------------------    TSQLResult *result = 0;
3304      TSQLRow    *row    = 0;
3305    Double_t mip[3]={1, 30, 300};    //
3306    Double_t adc[3] = {0.,0.,0.};    stringstream oss;
3307      oss.str("");
3308      //
3309      // =======================================================
3310      // validate runs by checking missing calibrations
3311      // =======================================================
3312      UInt_t t_stop  = 0;
3313      UInt_t t_start = 0;
3314      // --------------------------------------------------------------
3315      // 1) get the OBT of the last run inserted after clean-time limit
3316      // --------------------------------------------------------------
3317      oss.str("");
3318      oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()
3319              << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3320      if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3321      result = conn->Query(oss.str().c_str());
3322      if ( !result ) throw -4;
3323      if ( !result->GetRowCount() ) {
3324              printf(" No runs to validate \n");
3325              return(1);
3326      }else{
3327            row = result->Next();
3328            t_start = (UInt_t)atoll(row->GetField(4));
3329      };  
3330      // --------------------------------------------------------------
3331      // 2) get the OBT of the last validated run
3332      // --------------------------------------------------------------
3333      oss.str("");
3334      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3335          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3336      if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
3337      result = conn->Query(oss.str().c_str());
3338      if ( !result ) throw -4;
3339      if ( result->GetRowCount() ){
3340              row = result->Next();
3341              t_stop = (UInt_t)atoll(row->GetField(4));
3342      };
3343      if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);
3344      // --------------------------------------------------------------
3345      // now retrieves runs to be validated
3346      // --------------------------------------------------------------
3347      oss.str("");
3348      oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;
3349      oss << " AND RUNHEADER_TIME >="<< t_stop;
3350      oss << " ORDER BY RUNHEADER_TIME DESC;";
3351    //  if ( IsDebug() )
3352      if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());
3353      result = conn->Query(oss.str().c_str());
3354      if ( !result ) throw -4;
3355      if ( !result->GetRowCount() ) printf(" No runs to validate \n");
3356    //  printf("------------------------------------------------------------------------------- \n");
3357        
3358    TArrayD parametri(2);    Int_t nrow = 0;
3359      GL_RUN* this_run = new GL_RUN();
3360    valid = 1;    GL_RUN* next_run = new GL_RUN();
3361      Int_t   nseq_max = 1000;
3362    //------------ Fit calibrations and find parameters to calibrate data ------------------  //  UInt_t* sequence = new UInt_t[100];
3363    pamela::S4::S4Event  *s4Record;    vector<UInt_t> sequence(nseq_max);
3364      Int_t   nseq = 0;
3365      Bool_t CHECK = false;
3366      Bool_t this_ONLINE = false;
3367      Bool_t next_ONLINE = false;
3368      UInt_t t1=0,t2=0;
3369      // ---------------------------------------------------------------------------------
3370      // - loop over runs, back in time,
3371      // - select sequences of runs close in time (less than 60 s apart),
3372      //   which could be preceeded by a calibration
3373      // - check if there might be a missing calibration
3374      // ---------------------------------------------------------------------------------
3375      while(1){
3376              
3377              row = result->Next();
3378              if( row == NULL ) break;
3379              
3380              //------------
3381              //get run info
3382              //------------
3383              this_run->Set_GL_RUN(row);
3384                      
3385              Bool_t this_BAD = false;
3386              if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true;
3387              else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;
3388              else{
3389    //                printf("Missing or corrupted header!! \n");
3390                      this_ONLINE = false;
3391                      this_BAD = true;
3392              };
3393    
3394    for (Int_t j = 0; j < 4; j++){            //-----------------------------------
3395      for (Int_t i = 0; i < 128; i++){            //compare with previous(next in time)
3396        s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i));            //-----------------------------------
3397        switch (j) {            CHECK = false;
3398        case 0 :{            UInt_t interval=0;
3399          adc[0]=adc[0]+((s4Record->S4_DATA)-32);            
3400          break;            if( nrow != 0){
3401        };          
3402        case 1 :{                    
3403          adc[1]=adc[1]+((s4Record->S4_DATA)-32);                    t1 = this_run->GetRUNTRAILER_TIME();
3404          break;                    t2 = next_run->GetRUNHEADER_TIME();
3405        };                    interval = (t2-t1);
3406        case 3 :{                    
3407          adc[2]=adc[2]+((s4Record->S4_DATA)-32);                    if(this_ONLINE && next_ONLINE){                               // this: ON-LINE + next: ON-LINE
3408          break;                            
3409        };                            if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments
3410        };                            
3411      };                            if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration
3412                              
3413                              if( !CHECK && this_run->VALIDATION ){
3414                                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
3415                                      nseq=0;
3416                              }
3417                      
3418                      }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE
3419                              
3420                              CHECK = true;
3421    
3422                      }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT
3423                              
3424                              assignVALIDATION(next_run->ID,true);
3425                              nseq=0;
3426                      }
3427              }
3428    
3429              //----------------------------
3430              //check run sequence for calib
3431              //----------------------------
3432              if( CHECK ){
3433                      // check if calibration exists
3434                      if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
3435                      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
3436                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);
3437                      nseq=0;
3438              };
3439              //--------------
3440              //store run info
3441              //--------------
3442              *next_run   = *this_run;
3443              next_ONLINE = this_ONLINE;
3444              if( !this_BAD ){
3445                      if(nseq < nseq_max){
3446                              sequence[nseq] = this_run->ID;
3447                              nseq++;
3448                      }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);
3449              };
3450              
3451              if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID);
3452              nrow++;
3453              
3454    };    };
3455        delete this_run;
3456    adc[0]=adc[0]/128;    delete next_run;
3457    adc[1]=adc[1]/128;    //
3458    adc[2]=adc[2]/128;    return(0);
3459      };
3460    TGraph *fitpar = new TGraph (3, adc, mip);  /**
3461    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
3462       * @param t1 From absolute time
3463    func->SetParameters(0.3,1.);        //inizializzazione dei parametri a 1   * @param t2 To absolute time
3464    func->SetParNames("m","q");      //definisce il nome dei parametri   * @return true if there might be a missing calibration
3465    fitpar->Fit(func,"qr");          //fitta fitpar con la funzione func nel range definito nella funzione   */
3466    //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){
3467                
3468    parametri[0] = func -> GetParameter(0);          GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
3469    parametri[1] = func -> GetParameter(1);          
3470            // get the closest VALIDATED calibration before the run start (t2)
3471            if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);      //>>> missing
3472            
3473            if ( trkcalib->TO_TIME  < t2 ) return(true);                                    //>>> missing
3474            
3475            //==============================================================
3476            // Check is done first on the basis of time between calibration,
3477            // which should be equal to the time between ascending-nodes.
3478            //==============================================================
3479            if ( t2 - trkcalib->FROM_TIME > 5700) {
3480                    if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME);
3481            //==============================================================
3482            // there might be a missing calibration, due to:
3483            // - MM full
3484            // - corrupted packets
3485            // - loss of data
3486            // There is an exception in case a download was done during ascending node
3487            //==============================================================
3488                    Bool_t DOWNLOAD = false;
3489                    // check if the calib was skipped becouse of download .... DA FARE!!
3490                    if(DOWNLOAD)return(false);
3491                    
3492                    return(true);                                   //>>> missing
3493                    
3494            };
3495            
3496            //==============================================================
3497            // If the last calibration is close to the run less than this time,
3498            // it is enough to say that there are no missing calibrations
3499            //==============================================================
3500            // the long time interval bewteen runs might be due to download
3501            if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);
3502            return(false);
3503            
3504    };
3505    /**
3506     * Assign VALIDATION value to a GL_RUN entry
3507     * @param idrun Run ID
3508     * @param validation true/false
3509     */
3510    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
3511            TSQLResult *result = 0;
3512            stringstream oss;
3513            oss.str("");
3514            oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";";
3515            //
3516    //      if ( IsDebug() )
3517    //      printf(" Set VALIDATION = %i for run %i \n",validation,idrun);
3518            if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str());
3519            result = conn->Query(oss.str().c_str());
3520            if ( !result ) throw -4;
3521            return(0);
3522    }
3523    
3524    
   if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.8 || parametri[1] > 1. ) valid = 0;  
3525    
   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.9

  ViewVC Help
Powered by ViewVC 1.1.23