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