1 |
mocchiut |
1.1 |
//============================================================================ |
2 |
|
|
// $Id: PacketUser.h,v 1.37 2008-03-21 16:06:57 messineo 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 |
|
|
|
14 |
|
|
using namespace pamela; |
15 |
|
|
using namespace pamela::techmodel; |
16 |
|
|
|
17 |
|
|
namespace PamOffLineSW |
18 |
|
|
{ |
19 |
|
|
|
20 |
|
|
class PacketUser |
21 |
|
|
{ |
22 |
|
|
|
23 |
|
|
public: |
24 |
|
|
//destructor |
25 |
|
|
virtual ~PacketUser(); |
26 |
|
|
//the interface called by the external module: saves packets in ROOT files using the YODA part |
27 |
|
|
void usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, const PacketType* type, |
28 |
|
|
unsigned long int counter, unsigned long int obt); |
29 |
|
|
|
30 |
|
|
//return the instance of the singleton |
31 |
|
|
static PacketUser& getInstance(); |
32 |
|
|
//to be called at the end of the game |
33 |
|
|
void FinishLastGroup(); |
34 |
|
|
|
35 |
|
|
private: |
36 |
|
|
//the Event Reader handler |
37 |
|
|
pamela::techmodel::EventReader* reader; |
38 |
|
|
//the Pamela Run handler, one for ech ROOT file created |
39 |
|
|
pamela::PamelaRun* pRun; |
40 |
|
|
//Constructor |
41 |
|
|
PacketUser(); |
42 |
|
|
//The istance |
43 |
|
|
static PacketUser instance; |
44 |
|
|
//How many times I found a discontinuity |
45 |
|
|
static int numDiscontinity; |
46 |
|
|
//How many packets arrived here, |
47 |
|
|
static int numPKT; |
48 |
|
|
//How many packetS saved in each ROOT files |
49 |
|
|
static int numPKTSaved; |
50 |
|
|
//Name of the final ROOT file |
51 |
|
|
char rootfilename[80]; |
52 |
|
|
//pkt counter of the first packet of the group |
53 |
|
|
unsigned long int pkt_number_init; |
54 |
|
|
//pkt OBT of the first packet of the group |
55 |
|
|
unsigned long int obt_init; |
56 |
|
|
//pkt counter of the last packet of the group |
57 |
|
|
unsigned long int pkt_number_last; |
58 |
|
|
//pkt OBT of the last packet of the group |
59 |
|
|
unsigned long int obt_last; |
60 |
|
|
//the first packet's absolute time |
61 |
|
|
unsigned long int real_time_init; |
62 |
|
|
//the last packet's absolute time |
63 |
|
|
unsigned long int real_time_last; |
64 |
|
|
//tymesync and OBT informations |
65 |
|
|
unsigned long int obt_time_sync; |
66 |
|
|
unsigned long int last_time_sync_info; |
67 |
|
|
//TimeOffset used to obtain absolute time |
68 |
|
|
unsigned long int timeOffset; |
69 |
|
|
//part of the ROOT filename used to retrieve timeOffset for special files |
70 |
|
|
char nnnn_mmm_ppp[80]; |
71 |
|
|
|
72 |
|
|
//number of packets with problems( in general CRC problems) detected in EventReader: |
73 |
|
|
int bad_pkt_EventReader; |
74 |
|
|
//num ber of Calibration packets with problems( in general CRC problems) detected in EventReader: |
75 |
|
|
int bad_pkt_CalibReader; |
76 |
|
|
//number of good packets that comes from one or more corrupted cadres |
77 |
|
|
int bad_pkt; |
78 |
|
|
|
79 |
|
|
//number of good Calibration packets in the ROOT files |
80 |
|
|
// int good_pkt_Calib;//maybe I will remove this in future |
81 |
|
|
|
82 |
|
|
//the table name in our DB for the ROOT files |
83 |
|
|
char* Table_ROOT_Good; |
84 |
|
|
//the table name in our DB where I put the ROOT files that have not Real time associated |
85 |
|
|
char* Table_ROOT_Bad; |
86 |
|
|
//table used to retrieve TimeOffset |
87 |
|
|
char* Table_GL_RESURS_OFFSET; |
88 |
|
|
//the table name in our DB for the BAD PACKETS |
89 |
|
|
char* Table_PKT_Bad; |
90 |
|
|
//the table name in our DB for MERGING |
91 |
|
|
char* Table_ROOT_Merging; |
92 |
|
|
|
93 |
|
|
//starts a new root file |
94 |
|
|
void StartGroup(); |
95 |
|
|
//set the value of the counter and obt of the first packet of the group |
96 |
|
|
void setInit(unsigned long int counter, unsigned long int obt); |
97 |
|
|
//finish the old ROOT file |
98 |
|
|
void FinishGroup(char * filename); |
99 |
|
|
//set the value of the counter and obt of the last packet of the group |
100 |
|
|
void setLast(unsigned long int counter, unsigned long int obt); |
101 |
|
|
//retrieve OBT_TIME_SYNC and LAST_TIME_SYNC_INFO from packet |
102 |
|
|
void setTimeSync(char* packet, const PacketType* type); |
103 |
|
|
//set real_time_init and real_time_last |
104 |
|
|
void setReal_Time(); |
105 |
|
|
//retrieve the timeOffset |
106 |
|
|
unsigned long int retrieveTimeOffset(); |
107 |
|
|
|
108 |
|
|
//function that saves informations about some packets in our DB |
109 |
|
|
bool saveBADPKT_DB(char* table_name, |
110 |
|
|
char* folder_name, |
111 |
|
|
char* file_name, |
112 |
|
|
unsigned long int pkt_number, |
113 |
|
|
unsigned long int pkt_obt, |
114 |
|
|
char* nome_input, |
115 |
|
|
int reason, |
116 |
|
|
int rootID); |
117 |
|
|
|
118 |
|
|
//function that saves informations in our DB |
119 |
|
|
bool saveROOT_DB(char* table_name, char* folder_name, char* file_name, |
120 |
|
|
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, |
121 |
|
|
unsigned long int obt_in, unsigned long int obt_fin, |
122 |
|
|
unsigned long int oT_sync, unsigned long int lT_sync_info, |
123 |
|
|
unsigned long int mtime_init, unsigned long int mtime_last, |
124 |
|
|
unsigned long int time_offset, |
125 |
|
|
int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, |
126 |
|
|
char* nome_input); |
127 |
|
|
|
128 |
|
|
//function used to save in a file the packet |
129 |
|
|
void savePKT_file(char* headerPkt, |
130 |
|
|
char* pamPkt, |
131 |
|
|
long int length, |
132 |
|
|
bool append, |
133 |
|
|
char* nomefile); |
134 |
|
|
|
135 |
|
|
///new part merging |
136 |
|
|
|
137 |
|
|
//tipi di relazioni che il ROOT file puo' avere con un ROOT gia salvatto in DB |
138 |
|
|
enum type_Rel_ROOT{ |
139 |
|
|
AFTER, //se inizia dentro e finisce fuori |
140 |
|
|
BEFORE, //inizia prima ma finisce dentro |
141 |
|
|
SMALLER, //se inizia e finisce dentro |
142 |
|
|
BIGGER //se inizia prima e finisce dopo |
143 |
|
|
}; |
144 |
|
|
|
145 |
|
|
/* |
146 |
|
|
0 =AFTER se c'e' una sovrapposizione temporale parziale, inizia dopo l'inizio di quello associato e finisce dopo la sua fine |
147 |
|
|
2 =BEFORE se c'e' una sovrapposizione temporale parziale, ossia finisce prima della fine di quello associato ma inizia prima |
148 |
|
|
3 =SMALLER se c'e' una sovrapposizione temporale parziale: e' contenuto nel ROOT file associato |
149 |
|
|
4 =BIGGER se c'e' una sovrapposizione temporale parziale: contiene il ROOT file associato |
150 |
|
|
*/ |
151 |
|
|
|
152 |
|
|
|
153 |
|
|
bool merge_ROOTfiles(); |
154 |
|
|
|
155 |
|
|
|
156 |
|
|
bool saveMergeROOT_DB(char* table_name, |
157 |
|
|
unsigned int root_id, |
158 |
|
|
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, |
159 |
|
|
unsigned long int obt_in, unsigned long int obt_fin, |
160 |
|
|
unsigned long int mtime_init, unsigned long int mtime_last, |
161 |
|
|
int percentage); |
162 |
|
|
|
163 |
|
|
|
164 |
|
|
bool updateMergeROOT_DB(char* table_name, |
165 |
|
|
unsigned int root_id, |
166 |
|
|
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, |
167 |
|
|
unsigned long int obt_in, unsigned long int obt_fin, |
168 |
|
|
unsigned long int mtime_init, unsigned long int mtime_last, |
169 |
|
|
int bad_perc, |
170 |
|
|
unsigned int ID_record, type_Rel_ROOT type_rel); |
171 |
|
|
//butta |
172 |
|
|
bool OLD_updateMergeROOT_DB(char* table_name, |
173 |
|
|
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, |
174 |
|
|
unsigned long int obt_in, unsigned long int obt_fin, |
175 |
|
|
unsigned long int mtime_init, unsigned long int mtime_last, |
176 |
|
|
unsigned int ID_record); |
177 |
|
|
|
178 |
|
|
//unsigned int Return_IDN_merging(char* table_name, unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel); |
179 |
|
|
TSQLResult* Select_merging(char* table_name, unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel); |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
unsigned int select_maxIDN_DB(char* table_name); |
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
/***************************************************************************************/ |
188 |
|
|
/* |
189 |
|
|
//tipi di relazioni che il ROOT file puo' avere con un ROOT gia salvatto in DB |
190 |
|
|
enum type_Rel_ROOT{ |
191 |
|
|
AFTER=0, //inizia dove finisce l'altro: viene subito dopo |
192 |
|
|
AFTER2, //se inizia dentro e finisce fuori |
193 |
|
|
BEFORE, //finisco dove inizia l'altro |
194 |
|
|
BEFORE2, //inizia prima ma finisce dentro |
195 |
|
|
SMALLER, //se inizia e finisce dentro |
196 |
|
|
BIGGER //se inizia prima e finisce dopo |
197 |
|
|
}; |
198 |
|
|
|
199 |
|
|
|
200 |
|
|
0 =AFTER se temporalmente viene subito dopo il ROOT file associato |
201 |
|
|
1 =AFTER2 se c'e' una sovrapposizione temporale parziale, inizia dopo l'inizio di quello associato e finisce dopo la sua fine |
202 |
|
|
2 =BEFORE se temporalmente viene subito prima del ROOT file associato |
203 |
|
|
3 =BEFORE2 se c'e' una sovrapposizione temporale parziale, ossia finisce prima della fine di quello associato ma inizia prima |
204 |
|
|
4 =SMALLER se c'e' una sovrapposizione temporale parziale: e' contenuto nel ROOT file associato |
205 |
|
|
5 =BIGGER se c'e' una sovrapposizione temporale parziale: contiene il ROOT file associato |
206 |
|
|
|
207 |
|
|
bool OLD_merge_ROOTfiles(); |
208 |
|
|
unsigned int* Return_IDN_ASS(unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel, unsigned int my_id, unsigned int &num_ass); |
209 |
|
|
// unsigned int select_maxIDN_DB(char* table_name); |
210 |
|
|
bool saveROOT_ASS_DB(char* table_name, |
211 |
|
|
unsigned int my_idn, |
212 |
|
|
unsigned int idn_ass, |
213 |
|
|
int type_ass); |
214 |
|
|
*/ |
215 |
|
|
|
216 |
|
|
/**************************************************************************/ |
217 |
|
|
|
218 |
|
|
//UNUSED: return the system time in ms |
219 |
|
|
unsigned long long Record_Time(); |
220 |
|
|
//DBG functions that saves pkt |
221 |
|
|
void saveALL_PKT(char* headerPkt, char* pamPkt, long int length, bool append); |
222 |
|
|
|
223 |
|
|
}; |
224 |
|
|
|
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
#endif /*PACKETUSER_H_*/ |