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

Diff of /chewbacca/PamOffLineSW/PamOffLineSW_Main.cpp

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

revision 1.1 by mocchiut, Tue Sep 23 07:20:14 2008 UTC revision 1.7 by pam-fi, Wed Aug 5 18:48:43 2009 UTC
# Line 1  Line 1 
1  //============================================================================  //============================================================================
2  // $Id: PamOffLineSW_Main.cpp,v 1.51 2008-09-05 14:33:48 messineo Exp $  // $Id: PamOffLineSW_Main.cpp,v 1.6 2009-02-01 16:38:26 mocchiut Exp $
3  // Description : Pamela Off-Line Software  // Description : Pamela Off-Line Software
4  //============================================================================  //============================================================================
5    
# Line 42  short int CRC_Cadre_Check(char dataVRL[] Line 42  short int CRC_Cadre_Check(char dataVRL[]
42    
43  //global variables  //global variables
44  bool simulated_data = false;  bool simulated_data = false;
45  bool do_vrl_check = false;  //bool do_vrl_check = false; //EMI
46    bool do_vrl_check = true; //EMI
47    
48  char*  db_host = "";  const char*  db_host = "";
49  int        db_port = 0;  int        db_port = 0;
50  char*  db_name = "";  const char*  db_name = "";
51  char conn[100]="";  char conn[100]="";
 //char* connection = NULL;        
 //char*  db_user = "yoda_user";  
 //char*  db_pwd  = "yoda_pwd";  
52    
53  LogUtil::logLevel loglevel=LogUtil::LOGERROR;  LogUtil::logLevel loglevel=LogUtil::LOGERROR;
54  char* logfilename = "pamofflinesw.log";  const char* logfilename = "chewbacca.log";
55  //current route  //current route
56  int route = 999;  int route = 999;
57  //previous route  //previous route
# Line 65  long int iNumGoodCadres=0; //total numbe Line 63  long int iNumGoodCadres=0; //total numbe
63  // global variables used in all the project  // global variables used in all the project
64  namespace PamOffLineSW  namespace PamOffLineSW
65  {        {      
66          char*  db_user = "";          const char*  db_user = "";
67          char*  db_pwd  = "";          const char*  db_pwd  = "";
68          char* connection = NULL;                  char* connection = NULL;        
69          //marco_new_01          //marco_new_01
70          bool single_connection=false;            bool single_connection=false;  
# Line 77  namespace PamOffLineSW Line 75  namespace PamOffLineSW
75          char* fni; //path completo          char* fni; //path completo
76          short compression = 3;          short compression = 3;
77  //      char *outDir = ".";  //      char *outDir = ".";
78          char *outDir = "";          const char *outDir = "";
79    
80          char * nome_output="yoda";    //    char * nome_output="chewbacca"; //EMI
81      bool multiFile = 0;          const char * nome_output="L0PAM";//EMI
82          unsigned long int step_pkt_number=0;          bool multiFile = 0;    
83          unsigned long int step_pkt_obt=0;    //    unsigned long int step_pkt_number=0; // EMI
84            unsigned long int step_pkt_number=3000;
85      //    unsigned long int step_pkt_obt=0; // EMI
86            unsigned long int step_pkt_obt=7200000; // EMI
87          LogUtil* mainLogUtil = NULL;          LogUtil* mainLogUtil = NULL;
88          TSQLServer* sqlServer = NULL;          TSQLServer* sqlServer = NULL;
89          unsigned long int max_pkt_number =   16777215;//biggest value before reset          unsigned long int max_pkt_number =   16777215;//biggest value before reset
90          unsigned long int max_pkt_obt    = 4294967295u;//biggest value before reset          unsigned long int max_pkt_obt    = 4294967295u;//biggest value before reset
91    
92          bool is_new_route = false;          //    bool is_new_route = false;      // EMI
93            bool is_new_route = true;       // EMI ??????????? VA BENE? SECONDO ME SI`
94          unsigned int download = 0;          unsigned int download = 0;
95          unsigned int orbit_number=0;          unsigned int orbit_number=0;
96          unsigned int mmm_number = 0;//session_number          unsigned int mmm_number = 0;//session_number
97          unsigned long int time_Offset=0;          unsigned long int time_Offset=0;
98          bool tryMerge = false;    //    bool tryMerge = false;
99            bool tryMerge = true;
100                                    
101          bool do_cont_check=true;//if do_cont_check is false do not use a DB ...          bool do_cont_check=true;//if do_cont_check is false do not use a DB ...
102    
103          //TODO: now it is unused          //TODO: now it is unused
104          unsigned long int delta_Time=0;//in seconds          unsigned long int delta_Time=0;//in seconds
105    #define TAGVALUELEN 4
106      char tag_value[TAGVALUELEN];
107  }  }
108    
109  // main:  // main:
# Line 161  void readOptions(int argc, char *argv[]) Line 166  void readOptions(int argc, char *argv[])
166          cout << "\t  (-help | --help | -h) print this help and exit \n";          cout << "\t  (-help | --help | -h) print this help and exit \n";
167          cout << "\t -simu       if the input file contains simulated data instead of real data\n";          cout << "\t -simu       if the input file contains simulated data instead of real data\n";
168          cout << "\t -vrl    if you want to perform the vrl check\n";          cout << "\t -vrl    if you want to perform the vrl check\n";
169          cout << "\t -filelog     set the log filename. [default: pamofflinesw.log]\n";          cout << "\t -no-vrl    if you DO NOT want to perform the vrl check\n";
170            cout << "\t -gpamela    gpamela data as input\n";
171            cout << "\t -filelog     set the log filename. [default: chewbacca.log]\n";
172          cout << "\t -loglevel     set the log level. Values: [0,3] (error,warning,info,all) [default:0]\n";          cout << "\t -loglevel     set the log level. Values: [0,3] (error,warning,info,all) [default:0]\n";
173          cout << "\t -c      set the compression level for the generated ROOT file(s). Values: [0,9] [default = 3]\n";          cout << "\t -c      set the compression level for the generated ROOT file(s). Values: [0,9] [default = 3]\n";
174          cout << "\t -root_name      set the root-name for the generated ROOT file(s). [default = yoda]\n";          cout << "\t -root_name      set the root-name for the generated ROOT file(s). [default = chewbacca]\n";
175          cout << "\t -outDir      set the output directory for the generated root file(s). [default = .]\n";          cout << "\t -outDir      set the output directory for the generated root file(s). [default = .]\n";
176          cout << "\t -delta_counter     set the allowed difference in the Packet Counter between two continuos packets. If 0 all packets are considered continuos.  [default = 0]\n";          cout << "\t -delta_counter     set the allowed difference in the Packet Counter between two continuos packets. If 0 all packets are considered continuos.  [default = 0]\n";
177          cout << "\t -delta_obt     set the allowed difference (ms) in the Packet Orbital Time between two continuos packets. If 0 all packets are considered continuos.  [default = 0]\n";          cout << "\t -delta_obt     set the allowed difference (ms) in the Packet Orbital Time between two continuos packets. If 0 all packets are considered continuos.  [default = 0]\n";
178          cout << "\t -db_host   set the host-name of the DataBase.  [default = localhost]\n";          cout << "\t -db_host   set the host-name of the DataBase.  [default = localhost]\n";
179          cout << "\t -db_port  set the port of the DataBase.  [default = 3306]\n";          cout << "\t -db_port  set the port of the DataBase.  [default = 3306]\n";
180          cout << "\t -db_name  set the name of the DataBase.  [default = yoda_db]\n";          cout << "\t -db_name  set the name of the DataBase.  [default = chewbacca_db]\n";
181          cout << "\t -db_user  set the user of the DataBase.  [default = yoda_user]\n";          cout << "\t -db_user  set the user of the DataBase.  [default = chewbacca_user]\n";
182          cout << "\t -db_pwd  set the user of the DataBase.  [default = yoda_pwd]\n";          cout << "\t -db_pwd  set the user of the DataBase.  [default = chewbacca_pwd]\n";
183          cout << "\t -max_pkt_number  Maximum value for  Packet Counter, after this value it is resetted.  [default = 2^24 - 1]\n";          cout << "\t -max_pkt_number  Maximum value for  Packet Counter, after this value it is resetted.  [default = 2^24 - 1]\n";
184          cout << "\t -max_pkt_obt  Maximum value for  Packet OBT, after this value it is resetted.  [default = 2^32 - 1]\n";                cout << "\t -max_pkt_obt  Maximum value for  Packet OBT, after this value it is resetted.  [default = 2^32 - 1]\n";      
185          cout << "\t -orbit_number  Value of the orbital number. If 0 this is retrieved from the input file name.  [default = 0]\n";                  cout << "\t -orbit_number  Value of the orbital number. If 0 this is retrieved from the input file name.  [default = 0]\n";        
186          cout << "\t -session_number  Value of the session number. If 0 this is retrieved from the input file name.  [default = 0]\n";                          cout << "\t -session_number  Value of the session number. If 0 this is retrieved from the input file name.  [default = 0]\n";                
187          cout << "\t -time_Offset  Value of the timeOffset. If 0 this is retrieved using the orbital number.  [default = 0]\n";          cout << "\t -time_Offset  Value of the timeOffset. If 0 this is retrieved using the orbital number.  [default = 0]\n";
188          cout << "\t -tryMerge if you want to try to Merge ROOT files\n";          cout << "\t -tryMerge if you want to try to Merge ROOT files\n";
189                  //marco_new_01          cout << "\t -dontMerge if you don not want to try to Merge ROOT files\n";
190            //marco_new_01
191          cout << "\t -single_connection if you want to open only one connection to DB.\n";          cout << "\t -single_connection if you want to open only one connection to DB.\n";
192                          //       cout << "\t -delta_Time  set the allowed difference (seconds) in the Real Time between two root file. [default = 0]\n";          cout << "\t -tag if you want add the 'The owner of the file' - the tag lenght is 4 char\n";
193            //       cout << "\t -delta_Time  set the allowed difference (seconds) in the Real Time between two root file. [default = 0]\n";
194          //cout << "\t -multi  generate multiple root files \n";          //cout << "\t -multi  generate multiple root files \n";
195          exit(1);          exit(1);
196    }    }
# Line 201  void readOptions(int argc, char *argv[]) Line 209  void readOptions(int argc, char *argv[])
209          exit(1);          exit(1);
210      }      }
211    
212      //input file
213      fni= argv[1];
214      
215    for (int i = 2; i < argc; i++)    for (int i = 2; i < argc; i++)
216    {          {      
217          //marco_new_01          //marco_new_01
# Line 216  void readOptions(int argc, char *argv[]) Line 227  void readOptions(int argc, char *argv[])
227                          tryMerge = true;                          tryMerge = true;
228                  continue;                  continue;
229              }              }
230    
231              if (!strcmp(argv[i], "-dontMerge")) // EMI
232                {
233                            tryMerge = false;
234                    continue;
235                }
236                        
237            if (!strcmp(argv[i], "-time_Offset")){            if (!strcmp(argv[i], "-time_Offset")){
238                          if (++i >= argc){                          if (++i >= argc){
# Line 303  void readOptions(int argc, char *argv[]) Line 320  void readOptions(int argc, char *argv[])
320            simulated_data = true;            simulated_data = true;
321            continue;            continue;
322        }        }
323    
324          if (!strcmp(argv[i], "-gpamela"))
325          {
326              simulated_data = true;
327              do_vrl_check = false;
328              nome_output = (char *)gSystem->BaseName(fni);
329              tryMerge = false;
330              continue;
331          }
332                
333          if (!strcmp(argv[i], "-no-vrl")) //EMI
334            {
335              do_vrl_check = false;
336          }
337        if (!strcmp(argv[i], "-vrl"))        if (!strcmp(argv[i], "-vrl"))
338        {        {
339            do_vrl_check = true;            do_vrl_check = true;
# Line 367  void readOptions(int argc, char *argv[]) Line 397  void readOptions(int argc, char *argv[])
397                   exit(1);                   exit(1);
398               }               }
399               DIR* tempdir;               DIR* tempdir;
400               if ((tempdir = opendir(argv[i])) != 0) {               if ((tempdir = opendir(gSystem->ExpandPathName(argv[i]))) != 0) { // EMI
401                   outDir = argv[i];                   outDir = argv[i];
402                   closedir(tempdir);                   closedir(tempdir);
403               } else {               } else {
# Line 491  void readOptions(int argc, char *argv[]) Line 521  void readOptions(int argc, char *argv[])
521                               db_pwd = argv[i];                               db_pwd = argv[i];
522                                continue;                                continue;
523                            }                            }
524                   if (!strcmp(argv[i], "-tag")){
525                                  if (++i >= argc){
526                                      cerr << "-tag needs arguments. \n";
527                                      cout << "Try '-help' for more information. \n";
528                                      exit(1);
529                                  }
530                                  int len=strlen(argv[i])>TAGVALUELEN?TAGVALUELEN:strlen(argv[i]);
531                                  strncpy(tag_value,argv[i],len);
532                                  tag_value[len]=0;
533                                  continue;
534                              }
535                      
536                  //TODO: check that multiFile is always 0                  //TODO: check that multiFile is always 0
537         //       if (!strcmp(argv[i], "-multi")){multiFile = 1; cout<<"debug: multi= "<<multiFile<<endl;}                 //       if (!strcmp(argv[i], "-multi")){multiFile = 1; cout<<"debug: multi= "<<multiFile<<endl;}        
538     }     }
539        
   //input file  
   fni= argv[1];  
     
540    //TODO: maybe if simulated data I don't need nothig so I can skip the following lines    //TODO: maybe if simulated data I don't need nothig so I can skip the following lines
541    // and use instead something similar to:    // and use instead something similar to:
542    //if(simulated data){orbit_number=99999; mmm_number=999; download=999; }    if (simulated_data) {orbit_number=99999; mmm_number=999; download=999; }
543        
544    //I need the following lines only to retrieve orbit_number and mmm_number (session_number)from the filename    //I need the following lines only to retrieve orbit_number and mmm_number (session_number)from the filename
545    if((!orbit_number)||(!mmm_number))    if((!orbit_number)||(!mmm_number))
# Line 590  void DB_config() Line 628  void DB_config()
628                                                    
629                          if (!strcmp(db_name,""))                          if (!strcmp(db_name,""))
630                          {                          {
631                                  db_name="yoda_db";                                                db_name="chewbacca_db";        
632                          }                                                                                        }                                                              
633                          sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name);                                sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name);      
634                          connection=conn;                                                  connection=conn;                        
# Line 610  void DB_config() Line 648  void DB_config()
648                  }                  }
649                  else                  else
650                  {                  {
651                          db_user="yoda_user";                          db_user="chewbacca_user";
652                  }                  }
653                    
654          }          }
# Line 624  void DB_config() Line 662  void DB_config()
662                  }                  }
663                  else                  else
664                  {                  {
665                          db_pwd="yoda_pwd";                          db_pwd="chewbacca_pwd";
666                  }                        }      
667          }          }
668                    
# Line 637  void firstLog(){ Line 675  void firstLog(){
675          string msg = "Input file: " + (string)fni;          string msg = "Input file: " + (string)fni;
676          mainLogUtil->logAlways(msg);          mainLogUtil->logAlways(msg);
677    
678          msg = "Output directory for the generated root file(s): " + (string)outDir;          msg = "Output directory for the generated root file(s): " + (string)outDir;
679          mainLogUtil->logAlways(msg);              mainLogUtil->logAlways(msg);    
680            msg = "Output directory for the generated root file(s) expanded: " + (string)gSystem->ExpandPathName(outDir); // EMI
681            mainLogUtil->logAlways(msg);    //EMI
682    
683          msg = "Output root name for the generated root file(s): " + (string)nome_output;          msg = "Output root name for the generated root file(s): " + (string)nome_output;
684          mainLogUtil->logAlways(msg);              mainLogUtil->logAlways(msg);    
# Line 818  void mainRead_RealData(char fni[]) Line 858  void mainRead_RealData(char fni[])
858                          if(do_vrl_check){isCadreGood=false;}                          if(do_vrl_check){isCadreGood=false;}
859                          break;                                                            break;                                  
860                  }                  }
861                            skip_cadre = false;
862                  //check of the VRL header e setta route number                  //check of the VRL header e setta route number
863                  if(!VRL_Header_Check(ccHeader_VRL,LENGTH_HEADER_VRL))                            if(!VRL_Header_Check(ccHeader_VRL,LENGTH_HEADER_VRL))          
864                  {                                                {                              
# Line 897  void mainRead_RealData(char fni[]) Line 937  void mainRead_RealData(char fni[])
937                                  string msg = oss.str();                                  string msg = oss.str();
938                                  mainLogUtil->logError(msg);                                  mainLogUtil->logError(msg);
939                                                                    
940                                  //non mi fido del contatore del route                                  //non mi fido del contatore del route                                  
                                           
941                                  stringstream oss1;                                  stringstream oss1;
942                                  oss1<<"Route number unused = "<<route<<" Resetting ROUTE to old value = "<<old_route<<" (download="<<download<<")";                                  oss1<<"Route number unused = "<<route<<" Resetting ROUTE to old value = "<<old_route<<" (download="<<download<<")";
943                                  msg = oss1.str();                                  msg = oss1.str();
# Line 921  void mainRead_RealData(char fni[]) Line 960  void mainRead_RealData(char fni[])
960                                  mainLogUtil->logAll(msg);                                  mainLogUtil->logAll(msg);
961                          }                          }
962                          // is_new_route will be reset to false in PacketUser after the packet is used and stored                          // is_new_route will be reset to false in PacketUser after the packet is used and stored
963                                    
964                            
965                          //main processing of the data, searching for Pamela Packets                          //main processing of the data, searching for Pamela Packets
966                          for(int i=0; i<LENGTH_DATA_CADRE; i++)                          for(int i=0; i<LENGTH_DATA_CADRE; i++)
967                          {                                                {                      
968                                  StateManager::getInstance().getCurrentState()->readInput(ccData[i]);                            StateManager::getInstance().getCurrentState()->readInput(ccData[i]);
969                                  iByte_tot++;                            iByte_tot++;
970                                  if(exitdbg==true){cout<<"**** DBG EXIT FOR****"<<endl; break;}                            if(exitdbg==true){cout<<"**** DBG EXIT FOR****"<<endl; break;}
971                  }                          }
972                  }                  }
973                  else{                  else{
974                          iByte_tot+=LENGTH_DATA_CADRE;                          iByte_tot+=LENGTH_DATA_CADRE;
# Line 967  void mainRead_RealData(char fni[]) Line 1007  void mainRead_RealData(char fni[])
1007  //function that check the header VRL  //function that check the header VRL
1008  bool VRL_Header_Check(char* headVRL, int length)  bool VRL_Header_Check(char* headVRL, int length)
1009  {        {      
1010                            
           
1011  /*      stringstream oss;                                                /*      stringstream oss;                                              
1012          oss<<"Pippooooooo: at byte+ "<<iByte_tot<<" cadre ... route number = "<<(int)headVRL[3];          oss<<"Pippooooooo: at byte+ "<<iByte_tot<<" cadre ... route number = "<<(int)headVRL[3];
1013          string msg = oss.str();          string msg = oss.str();

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

  ViewVC Help
Powered by ViewVC 1.1.23