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

Contents of /chewbacca/PamOffLineSW/PacketUser.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Thu Dec 18 14:47:00 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: v1r02, v1r00, v1r01
Changes since 1.3: +2 -1 lines
File MIME type: text/plain
Default values changed, symbolic path handling implemented, cleanup of backup files, do not delete files from ROOT_TABLE_MERGING

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

  ViewVC Help
Powered by ViewVC 1.1.23