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