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

Diff of /YodaProfiler/src/GLTables.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.8 by mocchiut, Fri Sep 8 08:48:04 2006 UTC
# Line 403  Int_t GL_RUN::Fill_GL_RUN(TSQLServer *db Line 403  Int_t GL_RUN::Fill_GL_RUN(TSQLServer *db
403    myquery << (UInt_t)BOOT_NUMBER << "','";    myquery << (UInt_t)BOOT_NUMBER << "','";
404    myquery << (UInt_t)VALIDATION << "');";    myquery << (UInt_t)VALIDATION << "');";
405    //    //
406    //printf("myquery is %s \n",myquery.str().c_str());    //  printf("myquery is %s \n",myquery.str().c_str());
407    //    //
408    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
409    //    //
# Line 537  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T Line 537  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T
537    myquery << ",VALIDATION";    myquery << ",VALIDATION";
538    myquery << " from GL_RUN where ID=" << run << ";";    myquery << " from GL_RUN where ID=" << run << ";";
539    //    //
540      //  printf(" myquery is %s \n",myquery.str().c_str());
541    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
542    if(!pResult->GetRowCount())return(-50);    //
543      //  printf(" getrowcount %i \n",pResult->GetRowCount());
544      //
545      if( !pResult->GetRowCount() ) return(-50);
546      //
547    for( r=0; r < 1000; r++){    for( r=0; r < 1000; r++){
548        Row = pResult->Next();              Row = pResult->Next();      
549        if( Row == NULL ) break;        if( Row == NULL ) break;
# Line 575  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T Line 580  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T
580            if (t==29) VALIDATION        = (UInt_t)atoll(Row->GetField(t));            if (t==29) VALIDATION        = (UInt_t)atoll(Row->GetField(t));
581        };        };
582    };    };
583    delete pResult;    //  delete pResult;
584      return(0);
   return 0;  
   
585  };  };
586    
587  /**  /**
# Line 589  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T Line 592  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T
592   *   *
593   */   */
594  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){
   //    Bool_t debug = 1;  
595    // MySQL variables    // MySQL variables
596    TSQLResult *pResult;    TSQLResult *pResult;
597    TSQLRow *Row;    TSQLRow *Row;
# Line 597  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TSt Line 599  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TSt
599    int r;    int r;
600    stringstream myquery;    stringstream myquery;
601    // ----------------    // ----------------
   // NB! unsigned long long integers: when set to a number use ULL to store the correct number  
602    myquery.str("");    myquery.str("");
603    myquery << " select ";    myquery << " select ";
   //    myquery << " * ";  
604    myquery << "ID";    myquery << "ID";
605      myquery << ",ID_RUN_FRAG";
606    myquery << ",ID_ROOT_L0";    myquery << ",ID_ROOT_L0";
607      myquery << ",ID_ROOT_L2";
608    myquery << ",RUNHEADER_TIME";    myquery << ",RUNHEADER_TIME";
609    myquery << ",RUNTRAILER_TIME";    myquery << ",RUNTRAILER_TIME";
610    myquery << ",RUNHEADER_OBT";    myquery << ",RUNHEADER_OBT";
# Line 628  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TSt Line 630  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TSt
630    myquery << ",TRK_CALIB_USED";    myquery << ",TRK_CALIB_USED";
631    myquery << ",CAL_DSP_MASK";    myquery << ",CAL_DSP_MASK";
632    myquery << ",BOOT_NUMBER";    myquery << ",BOOT_NUMBER";
633      myquery << ",VALIDATION";
634    myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";";    myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";";
635    //    //
636      //  printf(" query is %s \n",myquery.str().c_str());
637      //
638    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
639    if(!pResult->GetRowCount())return(-50);    if(!pResult->GetRowCount())return(-50);
640    for( r=0; r < 1000; r++){    for( r=0; r < 1000; r++){
641        Row = pResult->Next();            Row = pResult->Next();      
642        if( Row == NULL ) break;      if( Row == NULL ) break;
643        for( t = 0; t < pResult->GetFieldCount(); t++){      for( t = 0; t < pResult->GetFieldCount(); t++){
644            if (t== 0) ID               = (UInt_t)atoll(Row->GetField(t));        if (t== 0) ID                = (UInt_t)atoll(Row->GetField(t));
645            if (t== 1) ID_ROOT_L0          = (UInt_t)atoll(Row->GetField(t));        if (t== 1) ID_RUN_FRAG       = (UInt_t)atoll(Row->GetField(t));
646            if (t== 2) RUNHEADER_TIME   = (UInt_t)atoll(Row->GetField(t));        if (t== 2) ID_ROOT_L0        = (UInt_t)atoll(Row->GetField(t));
647            if (t== 3) RUNTRAILER_TIME  = (UInt_t)atoll(Row->GetField(t));        if (t== 3) ID_ROOT_L2        = (UInt_t)atoll(Row->GetField(t));
648            if (t== 4) RUNHEADER_OBT   = (UInt_t)atoll(Row->GetField(t));        if (t== 4) RUNHEADER_TIME    = (UInt_t)atoll(Row->GetField(t));
649            if (t== 5) RUNTRAILER_OBT  = (UInt_t)atoll(Row->GetField(t));        if (t== 5) RUNTRAILER_TIME   = (UInt_t)atoll(Row->GetField(t));
650            if (t== 6) RUNHEADER_PKT   = (UInt_t)atoll(Row->GetField(t));        if (t== 6) RUNHEADER_OBT     = (UInt_t)atoll(Row->GetField(t));
651            if (t== 7) RUNTRAILER_PKT  = (UInt_t)atoll(Row->GetField(t));        if (t== 7) RUNTRAILER_OBT    = (UInt_t)atoll(Row->GetField(t));
652            if (t== 8) EV_FROM = (UInt_t)atoll(Row->GetField(t));        if (t== 8) RUNHEADER_PKT     = (UInt_t)atoll(Row->GetField(t));
653            if (t== 9) EV_TO = (UInt_t)atoll(Row->GetField(t));        if (t== 9) RUNTRAILER_PKT    = (UInt_t)atoll(Row->GetField(t));
654            if (t==10) NEVENTS = (UInt_t)atoll(Row->GetField(t));        if (t==10) EV_FROM           = (UInt_t)atoll(Row->GetField(t));
655            if (t==11) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));        if (t==11) EV_TO             = (UInt_t)atoll(Row->GetField(t));
656            if (t==12) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));        if (t==12) NEVENTS           = (UInt_t)atoll(Row->GetField(t));
657            if (t==13) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));        if (t==13) LAST_TIMESYNC     = (UInt_t)atoll(Row->GetField(t));
658            if (t==14) FAV_WRK_SCHEDULE  = (UInt_t)atoll(Row->GetField(t));        if (t==14) OBT_TIMESYNC      = (UInt_t)atoll(Row->GetField(t));
659            if (t==15) EFF_WRK_SCHEDULE  = (UInt_t)atoll(Row->GetField(t));        if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
660            if (t==16) PRH_VAR_TRG_MODE_A      = (UInt_t)atoll(Row->GetField(t));        if (t==16) FAV_WRK_SCHEDULE  = (UInt_t)atoll(Row->GetField(t));
661            if (t==17) PRH_VAR_TRG_MODE_B      = (UInt_t)atoll(Row->GetField(t));        if (t==17) EFF_WRK_SCHEDULE  = (UInt_t)atoll(Row->GetField(t));
662            if (t==18) ACQ_BUILD_INFO   = (UInt_t)atoll(Row->GetField(t));        if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
663            if (t==19) ACQ_VAR_INFO     = (UInt_t)atoll(Row->GetField(t));        if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
664            if (t==20) RM_ACQ_AFTER_CALIB   = (UInt_t)atoll(Row->GetField(t));        if (t==20) ACQ_BUILD_INFO    = (UInt_t)atoll(Row->GetField(t));
665            if (t==21) RM_ACQ_SETTING_MODE     = (UInt_t)atoll(Row->GetField(t));        if (t==21) ACQ_VAR_INFO      = (UInt_t)atoll(Row->GetField(t));
666            if (t==22) PKT_COUNTER   = (UInt_t)atoll(Row->GetField(t));        if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
667            if (t==23) PKT_READY_COUNTER    = (UInt_t)atoll(Row->GetField(t));        if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
668            if (t==24) TRK_CALIB_USED   = (UInt_t)atoll(Row->GetField(t));        if (t==24) PKT_COUNTER       = (UInt_t)atoll(Row->GetField(t));
669            if (t==25) CAL_DSP_MASK   = (UInt_t)atoll(Row->GetField(t));        if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
670            if (t==26) BOOT_NUMBER   = (UInt_t)atoll(Row->GetField(t));        if (t==26) TRK_CALIB_USED    = (UInt_t)atoll(Row->GetField(t));
671        };        if (t==27) CAL_DSP_MASK      = (UInt_t)atoll(Row->GetField(t));
672          if (t==28) BOOT_NUMBER       = (UInt_t)atoll(Row->GetField(t));
673          if (t==29) VALIDATION        = (UInt_t)atoll(Row->GetField(t));
674        };
675    };    };
676    delete pResult;    //  delete pResult;
677      return(0);
   return 0;  
   
678  };// ****************************************************  };// ****************************************************
679    
680  /**  /**
681   * Function to query the GL_ROOT table of the DB.   * Function to query the GL_ROOT table of the DB.
682   *   *
# Line 734  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U Line 741  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U
741        Row = pResult->Next();            Row = pResult->Next();    
742        if( Row == NULL ) break;        if( Row == NULL ) break;
743        for( t = 0; t < pResult->GetFieldCount(); t++){        for( t = 0; t < pResult->GetFieldCount(); t++){
744              stringstream row;
745              row.str("");
746              row << "0" << Row->GetField(t); // add leading 0 since we have two fields that could be "null" and we want to avoid crashes due to atoll
747            if (t==0) ID               = (UInt_t)atoll(Row->GetField(t));            if (t==0) ID               = (UInt_t)atoll(Row->GetField(t));
748            if (t==1) ID_ROOT_L0  = (UInt_t)atoll(Row->GetField(t));            if (t==1) ID_ROOT_L0  = (UInt_t)atoll(Row->GetField(t));
749            if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(Row->GetField(t));            if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str());
750            if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(Row->GetField(t));            if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str());
751            if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));            if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
752            if (t==5) TO_TIME   = (UInt_t)atoll(Row->GetField(t));                          if (t==5) TO_TIME   = (UInt_t)atoll(Row->GetField(t));              
753            //            //
# Line 749  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U Line 759  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U
759    };    };
760    delete pResult;        delete pResult;    
761    //    //
762    if(TO_TIME < time)return(51);    if ( TO_TIME < time ) return(51);
763      //
764    if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING!    if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING!
765    //    //
766    return 0;    return 0;
# Line 762  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U Line 773  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U
773   * \param  run starting time   * \param  run starting time
774   * \return struct of type GL_CALO_CALIB_data, which stores the query result   * \return struct of type GL_CALO_CALIB_data, which stores the query result
775   */   */
776  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t section, TSQLServer *dbc){  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime,  UInt_t section, TSQLServer *dbc){
777    // MySQL variables    // MySQL variables
778    TSQLResult *pResult;    TSQLResult *pResult;
779    TSQLRow *Row;    TSQLRow *Row;
780    int t;    int t;
781    stringstream myquery;    stringstream myquery;
782      uptime = 0;
783    //    //
784    // select the correct calibration    // select the correct calibration
785    //    //
# Line 775  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 787  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
787    myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;    myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
788    myquery << " and FROM_TIME <= " << time;    myquery << " and FROM_TIME <= " << time;
789    myquery << " and TO_TIME > " << time;    myquery << " and TO_TIME > " << time;
790    myquery << " and VALIDATION=1;";    myquery << " ;";
791      //myquery << " and VALIDATION=1;";
792    //    //
793    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
794      //  printf(" mysquery is %s\n",myquery.str().c_str());
795      //
796      if( !pResult->GetRowCount() ) return(-54);
797      Row = pResult->Next();
798      if( Row == NULL ) return (-54);
799      //
800      uptime = (UInt_t)atoll(Row->GetField(2));
801    //    //
802    // if it is corrupted validation is 0 and we have no results from the query...    // if it is corrupted validation is 0 and we have no results from the query...
803    //    //
804    if( !pResult->GetRowCount() ){    if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0
     //    pResult->Delete();  
805      //      //
806      // in this case take relax the conditions and take the valid calibration that preceed the correct one      // in this case take relax the conditions and take the valid calibration that preceed the correct one
807      //      //
# Line 791  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 810  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
810      myquery << " and FROM_TIME <= " << time;      myquery << " and FROM_TIME <= " << time;
811      myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";      myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
812      pResult = dbc->Query(myquery.str().c_str());      pResult = dbc->Query(myquery.str().c_str());
813        //    printf(" mysquery is %s\n",myquery.str().c_str());
814      //      //
815      // if no results yet quit with error      // if no results yet quit with error
816      //      //
817      if( !pResult->GetRowCount() ) return (-54);      if( !pResult->GetRowCount() ) return (-54);
818        //
819        Row = pResult->Next();
820        //
821    };    };
822    //    //
823    // store infos and exit    // store infos and exit
824    //    //
   Row = pResult->Next();  
825    if( Row == NULL ) return (-54);    if( Row == NULL ) return (-54);
826    for( t = 0; t < pResult->GetFieldCount(); t++){    for( t = 0; t < pResult->GetFieldCount(); t++){
827      if (t==0) ID_ROOT_L0  = (UInt_t)atoll(Row->GetField(t));      if (t==0) ID_ROOT_L0  = (UInt_t)atoll(Row->GetField(t));
# Line 827  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn Line 849  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn
849    // ----------------    // ----------------
850    myquery.str("");    myquery.str("");
851    myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;    myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;
852    myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;";          myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
853    //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
854    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
855    if(!pResult->GetRowCount())return (-55);//throw -55;    if(!pResult->GetRowCount())return (-55);//throw -55;
# Line 992  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1014  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1014        toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0;        toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0;
1015      };      };
1016    };    };
1017      //
1018      file->Close();
1019    delete pResult;          delete pResult;      
1020  };  };
1021    
# Line 1038  UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num Line 1062  UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num
1062    return(pkt_num);    return(pkt_num);
1063    //    //
1064  };  };
1065    
1066    /*
1067     *
1068     * Convert the time in the DB from UInt_t to a string
1069     *
1070     * @param dbt time in the DB
1071     * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK
1072     *
1073     */
1074    TString GL_TIMESYNC::ConvertTime(TString tzone, UInt_t dbt){
1075      //
1076      TDatime *time = new TDatime();
1077      TString rtime;
1078      //
1079      time->Set(dbt,false); // MSK = Moscow Winter Time
1080      //
1081      if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){
1082        //
1083        UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3 hs
1084        time->Set(timeUTC,false);
1085        //
1086      };
1087      //
1088      if ( !strcmp(tzone.Data(),"CET") ){
1089        //
1090        UInt_t timeCET = time->Convert() - 60*60*2; // CET (Central European Time) = Moscow Winter Time - 2 hs
1091        time->Set(timeCET,false);
1092        //
1093      };
1094      //
1095      if ( !strcmp(tzone.Data(),"CEST") ){
1096        //
1097        UInt_t timeCEST = time->Convert() - 60*60*1; // CEST (Central European Summer Time) = Moscow Winter Time - 1 h
1098        time->Set(timeCEST,false);
1099        //
1100      };
1101      //
1102      if ( !strcmp(tzone.Data(),"MSD") ){
1103        //
1104        UInt_t timeMSD = time->Convert() + 60*60*1; // MSD (Moscow Summer Time) = Moscow Winter Time + 1 h
1105        time->Set(timeMSD,false);
1106        //
1107      };
1108      //
1109      rtime = time->AsSQLString();
1110      //
1111      return(rtime);
1112    }
1113    
1114    /*
1115     *
1116     * Convert the time in the DB from UInt_t to a string
1117     *
1118     * @param dbt time in the DB
1119     * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK
1120     *
1121     */
1122    TString GL_TIMESYNC::UnConvertTime(TString tzone, UInt_t dbt){
1123      //
1124      TDatime *time = new TDatime();
1125      TString rtime;
1126      //
1127      time->Set(dbt,false); // MSK = Moscow Winter Time
1128      //
1129      if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){
1130        //
1131        UInt_t timeUTC = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) +3 hs = Moscow Winter Time
1132        time->Set(timeUTC,false);
1133        //
1134      };
1135      //
1136      if ( !strcmp(tzone.Data(),"CET") ){
1137        //
1138        UInt_t timeCET = time->Convert() + 60*60*2; // CET (Central European Time) + 2 hs = Moscow Winter Time  
1139        time->Set(timeCET,false);
1140        //
1141      };
1142      //
1143      if ( !strcmp(tzone.Data(),"CEST") ){
1144        //
1145        UInt_t timeCEST = time->Convert() + 60*60*1; // CEST (Central European Summer Time) + 1 h = Moscow Winter Time
1146        time->Set(timeCEST,false);
1147        //
1148      };
1149      //
1150      if ( !strcmp(tzone.Data(),"MSD") ){
1151        //
1152        UInt_t timeMSD = time->Convert() - 60*60*1; // MSD (Moscow Summer Time) - 1 h = Moscow Winter Time
1153        time->Set(timeMSD,false);
1154        //
1155      };
1156      //
1157      rtime = time->AsSQLString();
1158      //
1159      return(rtime);
1160    }

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

  ViewVC Help
Powered by ViewVC 1.1.23