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

Diff of /chewbacca/PamOffLineSW/PacketUser.h

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

revision 1.4 by mocchiut, Thu Dec 18 14:47:00 2008 UTC revision 1.7 by mocchiut, Thu Feb 11 09:02:09 2010 UTC
# Line 1  Line 1 
1  //============================================================================  //============================================================================
2  // $Id: PacketUser.h,v 1.3 2008/12/18 12:58:37 mocchiut Exp $  // $Id: PacketUser.h,v 1.6 2009/12/24 10:31:13 mocchiut Exp $
3  // Description :  // Description :
4  //============================================================================  //============================================================================
5  #ifndef PACKETUSER_H_  #ifndef PACKETUSER_H_
# Line 8  Line 8 
8  #include <TTimeStamp.h>  #include <TTimeStamp.h>
9  #include "../event/PacketType.h"  #include "../event/PacketType.h"
10  #include "EventReader.h"  #include "EventReader.h"
11    #include "ReaderAlgorithms.h"
12    #include "../event/mcmd/McmdEvent.h"
13    #include "../event/mcmd/McmdRecord.h"
14    
15  #include "TROOT.h" //ROOT version > 5.14  #include "TROOT.h" //ROOT version > 5.14
16  #include "TSystem.h" // EMI  #include "TSystem.h" // EMI
17    #include "TArrayI.h" // EMI
18    
19    #include <vector>
20    
21  using namespace pamela;  using namespace pamela;
22  using namespace pamela::techmodel;  using namespace pamela::techmodel;
23    
24  namespace PamOffLineSW  namespace PamOffLineSW {
 {  
   
 class PacketUser  
 {  
25    
26  public:  
27          //destructor  /* class dbinfo{ */
28          virtual ~PacketUser();  /*   public: */
29          //the interface called by the external module: saves packets in ROOT files using the YODA part  /*   dbinfo( */
30          void usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, const PacketType* type,  /*   char * v_folder_name,  */
31                          unsigned long int counter, unsigned long int obt);  /*   char* v_file_name, */
32    /*   unsigned long int v_pkt_number_in,  */
33          //return the instance of the singleton  /*   unsigned long int v_pkt_number_fin,  */
34          static PacketUser& getInstance();        /*   unsigned long int v_obt_in, */
35          //to be called at the end of the game  /*   unsigned long int v_obt_fin,  */
36          void FinishLastGroup();  /*   unsigned long int v_mboot_num,  */
37    /*   unsigned long int v_time_offset,  */
38    /*   int v_bad_pkt, */
39    /*   int v_bad_pkt_read,  */
40    /*   int v_bad_pkt_CalRead,  */
41    /*   int v_num_PKT_Saved,  */
42    /*   char* v_nome_input,  */
43    /*   bool v__time_is_estimated */
44    /*   ){ */
45    /*     folder_name = strdup(v_folder_name);  */
46    /*     file_name = strdup(v_file_name); */
47    /*     pkt_number_in = v_pkt_number_in;  */
48    /*     pkt_number_fin = v_pkt_number_fin;  */
49    /*     obt_in = v_obt_in; */
50    /*     obt_fin = v_obt_fin;  */
51    /*     mboot_num = v_mboot_num;  */
52    /*     time_offset = v_time_offset;  */
53    /*     bad_pkt = v_bad_pkt; */
54    /*     bad_pkt_read = v_bad_pkt_read;  */
55    /*     bad_pkt_CalRead = v_bad_pkt_CalRead;  */
56    /*     num_PKT_Saved = v_num_PKT_Saved;  */
57    /*     nome_input = v_nome_input;  */
58    /*     _time_is_estimated = v__time_is_estimated; */
59    /*   } */
60    /*   ~dbinfo(){ */
61    /*     free(folder_name);  */
62    /*     free(file_name); */
63    /*   } */
64    /*   char* folder_name;  */
65    /*   char* file_name; */
66    /*   unsigned long int pkt_number_in;  */
67    /*   unsigned long int pkt_number_fin;  */
68    /*   unsigned long int obt_in; */
69    /*   unsigned long int obt_fin;  */
70    /*   unsigned long int mboot_num;  */
71    /*   unsigned long int time_offset;  */
72    /*   int bad_pkt; */
73    /*   int bad_pkt_read;  */
74    /*   int bad_pkt_CalRead;  */
75    /*   int num_PKT_Saved;  */
76    /*   char* nome_input;  */
77    /*   bool _time_is_estimated; */
78    /* }; */
79    
80    class PacketUser {
81    
82    public:
83      //destructor
84      virtual ~PacketUser();
85      //the interface called by the external module: saves packets in ROOT files using the YODA part
86      void usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, const PacketType* type,
87          unsigned long int counter, unsigned long int obt);
88    
89      //return the instance of the singleton
90      static PacketUser& getInstance();
91      //to be called at the end of the game
92      void FinishLastGroup();
93    
94  private:  private:
95          //the Event Reader handler    
96          pamela::techmodel::EventReader* reader;    // store dbinfo when file is bad but num. packet more than 1000
97          //the Pamela Run handler,  one for ech ROOT file created    //  vector <dbinfo*> m_dbinfos;
98          pamela::PamelaRun* pRun;  
99          //Constructor    //the Event Reader handler
100          PacketUser();    pamela::techmodel::EventReader* reader;
101          //The istance    //the Pamela Run handler,  one for ech ROOT file created
102          static PacketUser instance;    pamela::PamelaRun* pRun;
103          //How many times I found a discontinuity    //Constructor
104          static int numDiscontinity;    PacketUser();
105          //How many packets arrived here,            //The istance
106          static int numPKT;    static PacketUser instance;
107          //How many packetS saved in each ROOT files    //How many times I found a discontinuity
108          static int numPKTSaved;    static int numDiscontinity;
109          //Name of the final ROOT file    //How many packets arrived here,
110          char rootfilename[80];      static int numPKT;
111          //pkt counter of the first packet of the group    //How many packetS saved in each ROOT files
112          unsigned long int pkt_number_init;    static int numPKTSaved;
113          //pkt OBT of the first packet of the group    //Name of the final ROOT file
114          unsigned long int obt_init;    char rootfilename[80];
115          //pkt counter of the last packet of the group    //pkt counter of the first packet of the group
116          unsigned long int pkt_number_last;    unsigned long int pkt_number_init;
117          //pkt OBT of the last packet of the group    //pkt OBT of the first packet of the group
118          unsigned long int obt_last;    unsigned long int obt_init;
119          //the first packet's absolute time    //pkt counter of the last packet of the group
120          unsigned long int real_time_init;    unsigned long int pkt_number_last;
121          //the last packet's absolute time    //pkt OBT of the last packet of the group
122          unsigned long int real_time_last;    unsigned long int obt_last;
123          //tymesync and OBT informations    //the first packet's absolute time
124          unsigned long int obt_time_sync;    unsigned long int real_time_init;
125          unsigned long int last_time_sync_info;    //the last packet's absolute time
126          // (tassa) keep previous value of time_sync    unsigned long int real_time_last;
127          unsigned long int obt_time_sync_prevvalue;    //tymesync and OBT informations
128          unsigned long int last_time_sync_info_prevvalue;    unsigned long int obt_time_sync;
129          bool time_is_estimated;    unsigned long int last_time_sync_info;
130          //TimeOffset used to obtain absolute time    // (tassa) keep previous value of time_sync
131          unsigned long int timeOffset;    unsigned long int obt_time_sync_prevvalue;
132          //part of the ROOT filename used to retrieve timeOffset for special files    unsigned long int last_time_sync_info_prevvalue;
133          char nnnn_mmm_ppp[80];    bool time_is_estimated;
134          //boot number    //TimeOffset used to obtain absolute time
135          unsigned long int boot_number;    unsigned long int timeOffset;
136          unsigned long int boot_number_prevvalue;    //part of the ROOT filename used to retrieve timeOffset for special files
137          //(tassa)    char nnnn_mmm_ppp[80];
138          unsigned int id_to_recover[1000];    //boot number
139          int id_to_recover_index;      unsigned long int boot_number;
140          //number of packets with problems( in general CRC problems) detected in EventReader:    unsigned long int boot_number_prevvalue;
141          int bad_pkt_EventReader;    //(tassa)
142          //num  ber of Calibration packets with problems( in general CRC problems) detected in EventReader:    unsigned int id_to_recover[1000];
143          int bad_pkt_CalibReader;    int id_to_recover_index;
144          //number of good packets that comes from one or more corrupted cadres    //number of packets with problems( in general CRC problems) detected in EventReader:
145          int bad_pkt;    int bad_pkt_EventReader;
146              //num  ber of Calibration packets with problems( in general CRC problems) detected in EventReader:
147          //marco_new:    int bad_pkt_CalibReader;
148     //the ID of the current ROOT file in table Table_ROOT_Good    //number of good packets that comes from one or more corrupted cadres
149           unsigned int my_id;    int bad_pkt;
150    
151  //number of good Calibration packets in the ROOT files    //marco_new:
152  //      int good_pkt_Calib;//maybe I will use this in future    //the ID of the current ROOT file in table Table_ROOT_Good
153      unsigned int my_id;
154          //the table name in our DB for the ROOT files  
155          char* Table_ROOT_Good;    //number of good Calibration packets in the ROOT files
156          //the table name in our DB where I put the ROOT files that have not Real time associated    //    int good_pkt_Calib;//maybe I will use this in future
157          char* Table_ROOT_Bad;  
158          //table used to retrieve TimeOffset    //the table name in our DB for the ROOT files
159          char* Table_GL_RESURS_OFFSET;      const char* Table_ROOT_Good;
160          //the table name in our DB for MERGING    //the table name in our DB where I put the ROOT files that have not Real time associated
161          char* Table_ROOT_Merging;    const char* Table_ROOT_Bad;
162              //table used to retrieve TimeOffset
163          //starts a new root file    const char* Table_GL_RESURS_OFFSET;
164          void StartGroup();          //the table name in our DB for MERGING
165          //set the value of the counter and obt of the first packet of the group    const char* Table_ROOT_Merging;
166          void setInit(unsigned long int counter, unsigned long int obt);  
167          //finish the old ROOT file    //
168          void FinishGroup(char * filename);    Int_t recoverlimit;
169          //set the value of the counter and obt of the last packet of the group    // list of ID in root_table_bad with more than XXX packets
170          void setLast(unsigned long int counter, unsigned long int obt);            TArrayI *idtorecover;
171          //retrieve OBT_TIME_SYNC and LAST_TIME_SYNC_INFO from packet    //
172          void setTimeSync(char* packet, long int pktLenght, const PacketType* type);    Int_t arsize;
173          //retrieve boot number    // delete small files in root_table_bad from disk
174          void setBootNumber(char* packet, long int pktLenght, const PacketType* type);    void CleanDisk();
175          //set real_time_init and real_time_last  
176          void setReal_Time();    //starts a new root file
177          //    void StartGroup();
178          void recover_boot_number();    //set the value of the counter and obt of the first packet of the group
179      void setInit(unsigned long int counter, unsigned long int obt);
180          //retrieve the timeOffset from table=Table_GL_RESURS_OFFSET    //finish the old ROOT file
181          unsigned long int retrieveTimeOffset(char * table);    void FinishGroup(char * filename);
182      //set the value of the counter and obt of the last packet of the group
183          unsigned  int select_maxIDN_DB(char* table_name);    void setLast(unsigned long int counter, unsigned long int obt);
184      //retrieve OBT_TIME_SYNC and LAST_TIME_SYNC_INFO from packet
185          //function that saves informations in our DB        void setTimeSync(char* packet, long int pktLenght, const PacketType* type);
186          bool saveROOT_DB(char* table_name, char* folder_name, char* file_name,    //retrieve boot number
187                          unsigned long int pkt_number_in, unsigned long int pkt_number_fin,    void setBootNumber(char* packet, long int pktLenght, const PacketType* type);
188                          unsigned long int obt_in, unsigned long int obt_fin,    //set real_time_init and real_time_last
189                          unsigned long int  oT_sync, unsigned long int lT_sync_info,            void setReal_Time();
190                          unsigned long int mtime_init,   unsigned long int mtime_last,    
191                          unsigned long int mboot_num,    void setReal_TimeRECOVERY(
192                          unsigned long int time_offset,                              unsigned long int & _real_time_init,
193                          int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved,                              unsigned long int & _real_time_last,
194                          char* nome_input,bool _time_is_estimated);                              unsigned long int _obt_init,
195                                        unsigned long int _obt_last
196          ///new part merging                              );
197      
198                  //tipi di relazioni che il ROOT file puo' avere con un ROOT gia salvatto in DB            //
199                  //0 =AFTER  se c'e' una sovrapposizione temporale parziale, inizia dopo l'inizio di quello associato e finisce dopo la sua fine    void recover_boot_number();
200                  //1 =BEFORE se c'e' una sovrapposizione temporale parziale, ossia finisce prima della fine di quello associato ma inizia prima  
201                  //2 =SMALLER se c'e' una sovrapposizione temporale parziale: e' contenuto nel ROOT file associato    //retrieve the timeOffset from table=Table_GL_RESURS_OFFSET
202                  //3 =BIGGER  se c'e' una sovrapposizione temporale parziale: contiene il ROOT file associato        unsigned long int retrieveTimeOffset(const char * table);
203                  enum type_Rel_ROOT{  
204                  AFTER,     //se inizia dentro e finisce fuori    unsigned int select_maxIDN_DB(const char* table_name, const char* file_name);
205                          BEFORE,    //inizia prima ma finisce dentro  
206                          SMALLER,    //se inizia e finisce dentro    //function that saves informations in our DB
207                          BIGGER      //se inizia prima e finisce dopo                                                bool saveROOT_DB(const char* table_name, const char* folder_name, const char* file_name, unsigned long int pkt_number_in,
208                  };        unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, unsigned long int oT_sync,
209                  unsigned long int lT_sync_info, unsigned long int mtime_init, unsigned long int mtime_last,
210                  unsigned long int mboot_num, unsigned long int time_offset, int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead,
211          int num_PKT_Saved, const char* nome_input, bool _time_is_estimated);
212    
213          bool merge_ROOTfiles();    ///new part merging
214    
215      //tipi di relazioni che il ROOT file puo' avere con un ROOT gia salvatto in DB
216          bool saveMergeROOT_DB(char* table_name,    //0 =AFTER  se c'e' una sovrapposizione temporale parziale, inizia dopo l'inizio di quello associato e finisce dopo la sua fine
217                             unsigned  int root_id,    //1 =BEFORE se c'e' una sovrapposizione temporale parziale, ossia finisce prima della fine di quello associato ma inizia prima
218                                  unsigned long int pkt_number_in, unsigned long int pkt_number_fin,    //2 =SMALLER se c'e' una sovrapposizione temporale parziale: e' contenuto nel ROOT file associato
219                                  unsigned long int obt_in, unsigned long int obt_fin,    //3 =BIGGER  se c'e' una sovrapposizione temporale parziale: contiene il ROOT file associato
220                          unsigned long int mtime_init,   unsigned long int mtime_last,    enum type_Rel_ROOT {
221                          unsigned long int mboot_num,      AFTER, //se inizia dentro e finisce fuori
222                                  double percentage);      BEFORE, //inizia prima ma finisce dentro
223        SMALLER, //se inizia e finisce dentro
224                BIGGER
225          bool updateMergeROOT_DB(char* table_name,    //se inizia prima e finisce dopo
226                          unsigned  int root_id,    };
227                          unsigned long int pkt_number_in, unsigned long int pkt_number_fin,  
228                          unsigned long int obt_in, unsigned long int obt_fin,    bool merge_ROOTfiles();
229                  unsigned long int mtime_init,   unsigned long int mtime_last,  
230                          unsigned long int mboot_num,    bool saveMergeROOT_DB(const char* table_name, unsigned int root_id, unsigned long int pkt_number_in,
231                          double bad_perc,        unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin,
232                          unsigned int ID_record, type_Rel_ROOT type_rel);        unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage);
233            
234          //search in DB if there are ROOT files in the temporal range of interest and with the given relation    bool updateMergeROOT_DB(const char* table_name, unsigned int root_id, unsigned long int pkt_number_in,
235          TSQLResult* Select_merging(char* table_name, unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel);        unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin,
236          unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double bad_perc,
237          //Lock the tableTobeLocked table or all the tables I know if par=NULL        unsigned int ID_record, type_Rel_ROOT type_rel);
238          int LockTables(char* tableTobeLocked);  
239          //Unlock all the lockedtables    //search in DB if there are ROOT files in the temporal range of interest and with the given relation
240          int UnLockTables();    TSQLResult* Select_merging(const char* table_name, unsigned long int mtime_init, unsigned long int mtime_last,
241          //Open DB connection and lock table        type_Rel_ROOT type_rel);
242          void OpenDBConnection(char* tableTobeLocked);  
243          //Close DB connection and UNlock tables    //Lock the tableTobeLocked table or all the tables I know if par=NULL
244          void CloseDBConnection();    int LockTables(const char* tableTobeLocked);
245      //Unlock all the lockedtables
246  /***************************************************************************************/    int UnLockTables();
247          //UNUSED: return the system time in ms    //Open DB connection and lock table
248          unsigned long long Record_Time();    void OpenDBConnection(const char* tableTobeLocked);
249          //DBG functions that saves pkt    //Close DB connection and UNlock tables
250          void saveALL_PKT(char* headerPkt, char* pamPkt, long int length, bool append);    void CloseDBConnection();
251          //function used to save in a file the packet  
252          void savePKT_file(char* headerPkt,    /***************************************************************************************/
253                          char* pamPkt,    //UNUSED: return the system time in ms
254                          long int length,    unsigned long long Record_Time();
255                          bool append,    //DBG functions that saves pkt
256                          char* nomefile);    void saveALL_PKT(char* headerPkt, char* pamPkt, long int length, bool append);
257      //function used to save in a file the packet
258      void savePKT_file(char* headerPkt, char* pamPkt, long int length, bool append, char* nomefile);
259    
260  };  };
261    

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

  ViewVC Help
Powered by ViewVC 1.1.23