/[PAMELA software]/chewbacca/PamOffLineSW/PacketUser.cpp
ViewVC logotype

Diff of /chewbacca/PamOffLineSW/PacketUser.cpp

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

revision 1.10 by mocchiut, Thu Dec 24 10:31:12 2009 UTC revision 1.14 by mocchiut, Fri Jan 15 14:02:29 2010 UTC
# Line 1  Line 1 
1  //============================================================================  //============================================================================
2  // $Id: PacketUser.cpp,v 1.9 2009/10/01 08:55:42 mocchiut Exp $  // $Id: PacketUser.cpp,v 1.13 2010/01/08 13:36:14 mocchiut Exp $
3  // Description :  // Description :
4  //============================================================================  //============================================================================
5  #include "PacketUser.h"  #include "PacketUser.h"
# Line 541  void PacketUser::FinishLastGroup() { Line 541  void PacketUser::FinishLastGroup() {
541  //Finish the old root file  //Finish the old root file
542  void PacketUser::FinishGroup(char * filename) {  void PacketUser::FinishGroup(char * filename) {
543    if (pRun) {    if (pRun) {
544      if ( !( !real_time_init && !real_time_last && numPKTSaved <= recoverlimit ) && candelete ) pRun->WriteFiles();      if ( !( !real_time_init && !real_time_last && numPKTSaved <= recoverlimit ) || !candelete  ) pRun->WriteFiles();
545      delete pRun;      delete pRun;
546      pRun = NULL;      pRun = NULL;
547      stringstream close;      stringstream close;
# Line 650  void PacketUser::FinishGroup(char * file Line 650  void PacketUser::FinishGroup(char * file
650          if (!single_connection) {          if (!single_connection) {
651            CloseDBConnection();            CloseDBConnection();
652          }          }
653          return;          //      return; // commented here...
654    
655        };        };
656      }      }
657    
658      if ( real_time_init || real_time_last) {      if ( real_time_init || real_time_last) {
659      //saves info in DB in table Table_ROOT        //saves info in DB in table Table_ROOT
660      if (boot_number == 0)        if (boot_number == 0)
661        boot_number = boot_number_prevvalue;          boot_number = boot_number_prevvalue;
   
     if (saveROOT_DB(  
                     Table_ROOT_Good,  
                     outDir, // here outDir is good, no expand EMI  
                     filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info,  
                     real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader,  
                     numPKTSaved, fni, time_is_estimated) == true) {  
       oss.str() = "";  
       oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Good << " id= " << my_id;  
       msg = oss.str();  
       mainLogUtil->logInfo(msg);  
662                
663        if (tryMerge) {        if (saveROOT_DB(
664          merge_ROOTfiles();                        Table_ROOT_Good,
665        }                        outDir, // here outDir is good, no expand EMI
666      } else {                        filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info,
667                          real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader,
668                          numPKTSaved, fni, time_is_estimated) == true) {
669            oss.str() = "";
670            oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Good << " id= " << my_id;
671            msg = oss.str();
672            mainLogUtil->logInfo(msg);
673            
674            if (tryMerge) {
675              merge_ROOTfiles();
676            }
677          } else {
678        oss.str() = "";        oss.str() = "";
679        oss << "Problem storing information in DB regarding file: " << filename;        oss << "Problem storing information in DB regarding file: " << filename;
680        msg = oss.str();        msg = oss.str();
681        mainLogUtil->logError(msg);        mainLogUtil->logError(msg);
682      }        }
683      };      };
684    
685      // if dbinfo is not empty than      // if dbinfo is not empty than
686      if ( obt_time_sync && last_time_sync_info && arsize > 0 ){      if ( arsize > 0 ){
         
687    
688   //    if(!m_dbinfos.empty()){        if ( !obt_time_sync || !last_time_sync_info ){
689  //       while(!m_dbinfos.empty()){          TString *nomino=new TString(rootfilename);
690  //      dbinfo *app = m_dbinfos.back();          nomino->Remove(15);
691  //      m_dbinfos.pop_back();          TString qu = Form("select OBT_TIME_SYNC,LAST_TIME_SYNC_INFO from ROOT_TABLE where FILE_NAME like '%s_%%' and (abs(PKT_NUMBER_INIT-%lu)<50000 or abs(PKT_OBT_INIT-%lu)<3000000) limit 1;",nomino->Data(),pkt_number_init,obt_init);
692        Int_t ez=0;          //
693        while ( ez < arsize ){          oss.str() = "";
694          Int_t eid = idtorecover->At(ez);          oss << "(EM) Trying to find obt_time_sync and last_time_sync_info from DB, query is: " << qu.Data();
695          if ( eid > -1 ){          msg = oss.str();
696            mainLogUtil->logInfo(msg);
697            //
698            TSQLResult *result = sqlServer->Query(qu.Data());
699            TSQLRow    *row = result->Next();
700            if ( row && result->GetRowCount() == 1 ){
701              obt_time_sync = (unsigned long int)atoll(row->GetField(0));
702              last_time_sync_info = (unsigned long int)atoll(row->GetField(1));
703              oss.str() = "";
704              oss << "(EM) found obt_time_sync and last_time_sync_info from DB! obt_time_sync =  " <<obt_time_sync <<" last_time_sync_info = " << last_time_sync_info;
705              msg = oss.str();
706              mainLogUtil->logInfo(msg);
707            };      
708            delete nomino;
709          };      
710    
711          if ( obt_time_sync && last_time_sync_info ){
712            //    if(!m_dbinfos.empty()){
713            //       while(!m_dbinfos.empty()){
714            //      dbinfo *app = m_dbinfos.back();
715            //      m_dbinfos.pop_back();
716            Int_t ez=0;
717            while ( ez < arsize ){
718              Int_t eid = idtorecover->At(ez);
719              if ( eid > -1 ){
720                        
721            TString qu = Form("select FOLDER_NAME,FILE_NAME,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,BOOT_NUMBER,TIME_OFFSET,BAD_PKT,BAD_PKT_READ,BAD_PKT_CALREAD,NUM_PKT_SAVED,INPUT_NAME,TIME_IS_ESTIMATED from ROOT_TABLE_BAD where ID_N=%i;",eid);              TString qu = Form("select FOLDER_NAME,FILE_NAME,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,BOOT_NUMBER,TIME_OFFSET,BAD_PKT,BAD_PKT_READ,BAD_PKT_CALREAD,NUM_PKT_SAVED,INPUT_NAME,TIME_IS_ESTIMATED from ROOT_TABLE_BAD where ID_N=%i;",eid);
722            TSQLResult *result = sqlServer->Query(qu.Data());              TSQLResult *result = sqlServer->Query(qu.Data());
723            TSQLRow    *row = result->Next();              TSQLRow    *row = result->Next();
724                                        
725            TString efolder_name="";              TString efolder_name="";
726            TString efile_name="";              TString efile_name="";
727            unsigned long int epkt_number_in=0ULL;              unsigned long int epkt_number_in=0ULL;
728            unsigned long int epkt_number_fin=0ULL;              unsigned long int epkt_number_fin=0ULL;
729            unsigned long int eobt_in=0ULL;              unsigned long int eobt_in=0ULL;
730            unsigned long int eobt_fin=0ULL;              unsigned long int eobt_fin=0ULL;
731            unsigned long int emboot_num=0ULL;              unsigned long int emboot_num=0ULL;
732            unsigned long int etime_offset=0ULL;              unsigned long int etime_offset=0ULL;
733            int ebad_pkt=0;              int ebad_pkt=0;
734            int ebad_pkt_read=0;              int ebad_pkt_read=0;
735            int ebad_pkt_CalRead=0;              int ebad_pkt_CalRead=0;
736            int enum_PKT_Saved=0;              int enum_PKT_Saved=0;
737            TString enome_input="";              TString enome_input="";
738            bool e_time_is_estimated=false;              bool e_time_is_estimated=false;
739    
740            if ( row ){              if ( row ){
741              efolder_name =                      (TString)row->GetField(0);                efolder_name =                      (TString)row->GetField(0);
742              efile_name =                        (TString)row->GetField(1);                efile_name =                        (TString)row->GetField(1);
743              epkt_number_in =    (unsigned long int)atoll(row->GetField(2));                epkt_number_in =    (unsigned long int)atoll(row->GetField(2));
744              epkt_number_fin =   (unsigned long int)atoll(row->GetField(3));                epkt_number_fin =   (unsigned long int)atoll(row->GetField(3));
745              eobt_in =           (unsigned long int)atoll(row->GetField(4));                eobt_in =           (unsigned long int)atoll(row->GetField(4));
746              eobt_fin =          (unsigned long int)atoll(row->GetField(5));                eobt_fin =          (unsigned long int)atoll(row->GetField(5));
747              emboot_num =        (unsigned long int)atoll(row->GetField(6));                emboot_num =        (unsigned long int)atoll(row->GetField(6));
748              etime_offset =      (unsigned long int)atoll(row->GetField(7));                etime_offset =      (unsigned long int)atoll(row->GetField(7));
749              ebad_pkt =                         (int)atoi(row->GetField(8));                ebad_pkt =                         (int)atoi(row->GetField(8));
750              ebad_pkt_read =                    (int)atoi(row->GetField(9));                ebad_pkt_read =                    (int)atoi(row->GetField(9));
751              ebad_pkt_CalRead =                (int)atoi(row->GetField(10));                ebad_pkt_CalRead =                (int)atoi(row->GetField(10));
752              enum_PKT_Saved =                  (int)atoi(row->GetField(11));                enum_PKT_Saved =                  (int)atoi(row->GetField(11));
753              enome_input =                      (TString)row->GetField(12);                enome_input =                      (TString)row->GetField(12);
754              e_time_is_estimated =            (bool)atoi(row->GetField(13));                e_time_is_estimated =            (bool)atoi(row->GetField(13));
755            };              };
756            delete result;              delete result;
757    
758            setReal_TimeRECOVERY(              setReal_TimeRECOVERY(
759                                 real_time_init,                                   real_time_init,
760                                 real_time_last,                                   real_time_last,
761                                 eobt_in,                                   eobt_in,
762                                 eobt_fin                                   eobt_fin
763                                 );                                   );
764            //              //
765                        
766            if (saveROOT_DB(              if (saveROOT_DB(
767                            Table_ROOT_Good,                              Table_ROOT_Good,
768                            efolder_name.Data(),                              efolder_name.Data(),
769                            efile_name.Data(),                              efile_name.Data(),
770                            epkt_number_in,                              epkt_number_in,
771                            epkt_number_fin, eobt_in, eobt_fin, obt_time_sync, last_time_sync_info,                              epkt_number_fin, eobt_in, eobt_fin, obt_time_sync, last_time_sync_info,
772                            real_time_init, real_time_last, emboot_num, etime_offset, ebad_pkt, ebad_pkt_read, ebad_pkt_CalRead,                              real_time_init, real_time_last, emboot_num, etime_offset, ebad_pkt, ebad_pkt_read, ebad_pkt_CalRead,
773                            enum_PKT_Saved, enome_input.Data(), e_time_is_estimated) == true) {                              enum_PKT_Saved, enome_input.Data(), e_time_is_estimated) == true) {
774              oss.str() = "";                oss.str() = "";
775              oss << "\nTAG(tassa): RECOVERED!!!! Saved information regarding file: " << efile_name << " in table " << Table_ROOT_Good << " id= " << my_id;                oss << "\nTAG(tassa): RECOVERED!!!! Saved information regarding file: " << efile_name << " in table " << Table_ROOT_Good << " id= " << my_id;
776              msg = oss.str();                msg = oss.str();
777              mainLogUtil->logInfo(msg);                mainLogUtil->logInfo(msg);
778              /*merging we use global variable. we haveto set with current value*/                /*merging we use global variable. we haveto set with current value*/
779                            
780              strcpy(outDir,efolder_name.Data() );                strcpy(outDir,efolder_name.Data() );
781              //      outDir=efolder_name.Data();                //            outDir=efolder_name.Data();
782              strcpy(filename,efile_name.Data() );                strcpy(filename,efile_name.Data() );
783              //      filename=efile_name.Data();                //            filename=efile_name.Data();
784              pkt_number_init=epkt_number_in;                pkt_number_init=epkt_number_in;
785              pkt_number_last=epkt_number_fin;                pkt_number_last=epkt_number_fin;
786              obt_init=eobt_in;                obt_init=eobt_in;
787              obt_last=eobt_fin;                obt_last=eobt_fin;
788              boot_number=emboot_num;                boot_number=emboot_num;
789              timeOffset=etime_offset;                timeOffset=etime_offset;
790              bad_pkt=ebad_pkt;                bad_pkt=ebad_pkt;
791              bad_pkt_EventReader=ebad_pkt_read;                bad_pkt_EventReader=ebad_pkt_read;
792              bad_pkt_CalibReader=ebad_pkt_CalRead;                bad_pkt_CalibReader=ebad_pkt_CalRead;
793              numPKTSaved=enum_PKT_Saved;                numPKTSaved=enum_PKT_Saved;
794              strcpy(fni,enome_input.Data() );                strcpy(fni,enome_input.Data() );
795              //      fni=enome_input.Data();                //            fni=enome_input.Data();
796              time_is_estimated=e_time_is_estimated;                time_is_estimated=e_time_is_estimated;
797                            
798              if (tryMerge) {                if (tryMerge) {
799                merge_ROOTfiles();                  merge_ROOTfiles();
800              }                }
801                            
802              TString qu2 = Form("update ROOT_TABLE_BAD set ON_DISK='MVD' where ID_N=%i;",eid);                TString qu2 = Form("update ROOT_TABLE_BAD set ON_DISK='MVD' where ID_N=%i;",eid);
803              sqlServer->Query(qu2.Data());                sqlServer->Query(qu2.Data());
804    
805                            
806            }              }
807            else {              else {
808              oss.str() = "";                oss.str() = "";
809              oss << "Problem storing information in DB regarding file: " << filename;                oss << "Problem storing information in DB regarding file: " << filename;
810              msg = oss.str();                msg = oss.str();
811              mainLogUtil->logError(msg);                mainLogUtil->logError(msg);
812            }              }
813                        
814                        
815          };            };
816          ez++;            ez++;
817        }          }
818        //          //
819        idtorecover->Reset();          idtorecover->Reset();
820        delete idtorecover;          delete idtorecover;
821        idtorecover = new TArrayI(100);          idtorecover = new TArrayI(100);
822        arsize =  0;          arsize =  0;
823        //        delete app;          //      delete app;
824      }        };
825        };
826            
827      CleanDisk();      CleanDisk();
828      if (!single_connection) {      if (!single_connection) {
# Line 1145  bool PacketUser::updateMergeROOT_DB(cons Line 1169  bool PacketUser::updateMergeROOT_DB(cons
1169    if (type_rel == AFTER) {    if (type_rel == AFTER) {
1170      mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file");      mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file");
1171      //marco_new:tolti tutti gli apici che qui non devono essere      //marco_new:tolti tutti gli apici che qui non devono essere
1172        
1173        int good = 1;
1174        if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0;
1175        
1176      oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL ="      oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL ="
1177          << obt_init << ", REAL_TIME_LAST =" << real_time_init << " WHERE ID_N =" << ID_record << ";";          << obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";";
1178    
1179    }    }
1180    else if (type_rel == BEFORE) {    else if (type_rel == BEFORE) {
1181      mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file");      mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file");
1182    
1183        int good = 1;
1184        if ( (pkt_number_last+1) >= pkt_number_fin && abs((int)((pkt_number_last+1)-pkt_number_fin))<10 ) good = 0;
1185        
1186      oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT ="      oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT ="
1187          << obt_last << ", REAL_TIME_INIT =" << real_time_last << " WHERE ID_N =" << ID_record << ";";          << obt_last << ", REAL_TIME_INIT =" << real_time_last << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";";
1188    }    }
1189    else if (type_rel == SMALLER) {    else if (type_rel == SMALLER) {
1190      //spezzettamentento      //spezzettamentento
1191      mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file");      mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file");
1192    
1193        int good = 1;
1194        if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0;
1195    
1196      oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL=" << (pkt_number_init - 1) << ", PKT_OBT_FINAL ="      oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL=" << (pkt_number_init - 1) << ", PKT_OBT_FINAL ="
1197          << obt_init << ", REAL_TIME_LAST =" << real_time_init << " WHERE ID_N =" << ID_record << ";";          << obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";";
1198    
1199      mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file");      mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file");
1200    
# Line 1222  TSQLResult* PacketUser::Select_merging(c Line 1257  TSQLResult* PacketUser::Select_merging(c
1257    else    else
1258      return 0;      return 0;
1259    
1260    query << " order by REAL_TIME_INIT ASC";//marco_new: inutile    query << " order by REAL_TIME_INIT ASC;";//marco_new: inutile
1261    //se volessi mettere un filtro sulla qualita'    //se volessi mettere un filtro sulla qualita'
1262    //    query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ;    //    query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ;
1263    string msg = query.str();    string msg = query.str();
# Line 1245  bool PacketUser::saveMergeROOT_DB(const Line 1280  bool PacketUser::saveMergeROOT_DB(const
1280      unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin,      unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin,
1281      unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) {      unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) {
1282    
1283      int good = 1;
1284      if ( pkt_number_in >= pkt_number_fin && abs((int)(pkt_number_fin-pkt_number_in))<10 ) good = 0;
1285    
1286    stringstream oss;    stringstream oss;
1287    oss.str("");    oss.str("");
1288    oss << "INSERT INTO " << table_name    oss << "INSERT INTO " << table_name
1289        << " (ID_N, ROOT_ID_N, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, REAL_TIME_INIT, REAL_TIME_LAST, BOOT_NUMBER, BAD_PKT_PERCENTAGE, INSERT_TIME, INSERTED_BY)"        << " (ID_N, ROOT_ID_N, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, REAL_TIME_INIT, REAL_TIME_LAST, BOOT_NUMBER, BAD_PKT_PERCENTAGE, INSERT_TIME, INSERTED_BY,GOOD)"
1290        << " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in        << " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in
1291        << "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage        << "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage
1292        << "'," << "NULL" << ",'" << tag_value << "'" << ");";        << "'," << "NULL" << ",'" << tag_value << "','" << good <<"');";
1293    
1294    string msg = oss.str();    string msg = oss.str();
1295    mainLogUtil->logAll(msg);    mainLogUtil->logAll(msg);

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.23