1 |
#ifndef PAMELA_DB_OPERATIONS_H |
2 |
#define PAMELA_DB_OPERATIONS_H |
3 |
|
4 |
#include <iostream> |
5 |
#include <list> |
6 |
|
7 |
#include <TSQLServer.h> |
8 |
#include <EventHeader.h> |
9 |
#include <PscuHeader.h> |
10 |
#include <mcmd/McmdEvent.h> |
11 |
#include <mcmd/McmdRecord.h> |
12 |
#include <RunHeaderEvent.h> |
13 |
#include <RunTrailerEvent.h> |
14 |
#include <CalibCalPedEvent.h> |
15 |
#include <CalibS4Event.h> |
16 |
#include <CalibTrk1Event.h> |
17 |
#include <CalibTrk2Event.h> |
18 |
#include <varDump/VarDumpEvent.h> |
19 |
#include <varDump/VarDumpRecord.h> |
20 |
#include <physics/S4/S4Event.h> |
21 |
|
22 |
#include <GLTables.h> |
23 |
|
24 |
#include <sgp4.h> |
25 |
|
26 |
using namespace pamela; |
27 |
|
28 |
/** |
29 |
* Collections of Pamela specific operations over a database |
30 |
*/ |
31 |
class PamelaDBOperations { |
32 |
|
33 |
private: |
34 |
TSQLServer *conn; |
35 |
TFile *file; |
36 |
// |
37 |
RunHeaderEvent *runh; |
38 |
EventHeader *ehh; |
39 |
PscuHeader *phh; |
40 |
RunTrailerEvent *runt; |
41 |
EventHeader *eht; |
42 |
PscuHeader *pht; |
43 |
// |
44 |
GL_RUN *glrun; |
45 |
// |
46 |
TString filerawname; |
47 |
TString filerootname; |
48 |
// |
49 |
UInt_t tsync; |
50 |
UInt_t toffset; |
51 |
// |
52 |
// Long64_t olderthan; |
53 |
UInt_t dworbit; |
54 |
// |
55 |
UInt_t BOOTNO; |
56 |
UInt_t obt0; |
57 |
UInt_t id; |
58 |
UInt_t idroot; |
59 |
UInt_t pktfirst; |
60 |
UInt_t obtfirst; |
61 |
UInt_t ppktfirst; |
62 |
UInt_t pobtfirst; |
63 |
Long64_t upperobt; |
64 |
Long64_t upperpkt; |
65 |
UInt_t upperentry; |
66 |
Int_t rtev; |
67 |
Int_t rhev; |
68 |
// |
69 |
// calibration variables |
70 |
// |
71 |
Int_t t1; |
72 |
Int_t t2; |
73 |
UInt_t fromtime; |
74 |
UInt_t obt1; |
75 |
UInt_t pkt1; |
76 |
UInt_t obt2; |
77 |
UInt_t pkt2; |
78 |
UInt_t valid; |
79 |
// |
80 |
// |
81 |
Bool_t NOBOOT; |
82 |
Bool_t debug; |
83 |
|
84 |
// Path to tle file |
85 |
TString tlefilename; |
86 |
|
87 |
// flag to control profiler actions |
88 |
Bool_t STATIC; |
89 |
Bool_t INSERT_RAW; |
90 |
Bool_t INSERT_ROOT; |
91 |
Bool_t VALIDATE; |
92 |
Bool_t NOFRAG; |
93 |
Bool_t AUTOBOOT; |
94 |
|
95 |
TDatime *clean_time; |
96 |
|
97 |
// |
98 |
typedef std::list<const char*> pcksList; |
99 |
static void getPacketsNames(pcksList &pcksNames){ |
100 |
pcksNames.push_back("PhysEndRun"); |
101 |
pcksNames.push_back("CalibCalPulse1"); |
102 |
pcksNames.push_back("CalibCalPulse2"); |
103 |
pcksNames.push_back("Physics"); |
104 |
pcksNames.push_back("CalibTrkBoth"); |
105 |
pcksNames.push_back("CalibTrk1"); |
106 |
pcksNames.push_back("CalibTrk2"); |
107 |
pcksNames.push_back("CalibTof"); |
108 |
pcksNames.push_back("CalibS4"); |
109 |
pcksNames.push_back("CalibCalPed"); |
110 |
pcksNames.push_back("Calib1_Ac1"); |
111 |
pcksNames.push_back("Calib2_Ac1"); |
112 |
pcksNames.push_back("Calib1_Ac2"); |
113 |
pcksNames.push_back("Calib2_Ac2"); |
114 |
pcksNames.push_back("CalibCal"); |
115 |
pcksNames.push_back("RunHeader"); |
116 |
pcksNames.push_back("RunTrailer"); |
117 |
pcksNames.push_back("CalibHeader"); |
118 |
pcksNames.push_back("CalibTrailer"); |
119 |
pcksNames.push_back("InitHeader"); |
120 |
pcksNames.push_back("InitTrailer"); |
121 |
pcksNames.push_back("EventTrk"); |
122 |
pcksNames.push_back("Log"); |
123 |
pcksNames.push_back("VarDump"); |
124 |
pcksNames.push_back("ArrDump"); |
125 |
pcksNames.push_back("TabDump"); |
126 |
pcksNames.push_back("Tmtc"); |
127 |
pcksNames.push_back("Mcmd"); |
128 |
pcksNames.push_back("ForcedFECmd"); |
129 |
pcksNames.push_back("Ac1Init"); |
130 |
pcksNames.push_back("CalInit"); |
131 |
pcksNames.push_back("TrkInit"); |
132 |
pcksNames.push_back("TofInit"); |
133 |
pcksNames.push_back("TrgInit"); |
134 |
pcksNames.push_back("NdInit"); |
135 |
pcksNames.push_back("S4Init"); |
136 |
pcksNames.push_back("Ac2Init"); |
137 |
pcksNames.push_back("CalAlarm"); |
138 |
pcksNames.push_back("Ac1Alarm"); |
139 |
pcksNames.push_back("TrkAlarm"); |
140 |
pcksNames.push_back("TrgAlarm"); |
141 |
pcksNames.push_back("TofAlarm"); |
142 |
pcksNames.push_back("S4Alarm"); |
143 |
pcksNames.push_back("Ac2Alarm"); |
144 |
pcksNames.push_back("TsbT"); |
145 |
pcksNames.push_back("TsbB"); |
146 |
}; |
147 |
// |
148 |
// Functions |
149 |
// |
150 |
void HandleRun(); |
151 |
void HandleRunFragments(Bool_t mishead, Bool_t mistrail, UInt_t firstev, UInt_t lastev); |
152 |
void HandleMissingHoT(Bool_t mishead, Bool_t mistrail, UInt_t firstev, UInt_t lastev); |
153 |
void HandleSuspiciousRun(); |
154 |
void FillClass(); |
155 |
void FillClass(Bool_t mishead, Bool_t mistrail, UInt_t firstev, UInt_t lastev); |
156 |
void HandleTRK_CALIB(Bool_t pk1, Bool_t pk2); |
157 |
// |
158 |
void RemoveCALIBS(); |
159 |
void ValidationOFF(); |
160 |
void ReArrangeRUNS(); |
161 |
void RemoveRUNS(); |
162 |
void RemoveFILES(); |
163 |
// |
164 |
Bool_t IsDebug(){return(debug);}; |
165 |
Bool_t IsRunAlreadyInserted(); |
166 |
Bool_t IsRunConsistent(Bool_t mishead, Bool_t mistrail, UInt_t &firstev, UInt_t &lastev); |
167 |
Bool_t AutoBoot(){return(AUTOBOOT);}; |
168 |
// |
169 |
Bool_t MissingTRK_CALIB(UInt_t t1,UInt_t t2); |
170 |
// |
171 |
Long64_t PKT(UInt_t pkt_num); |
172 |
// |
173 |
Long64_t OBT(UInt_t obt); |
174 |
// |
175 |
UInt_t AssignRunID(); |
176 |
|
177 |
// GL_TLE related functions |
178 |
int insertTle(cTle*); |
179 |
bool isTlePresent(cTle*); |
180 |
|
181 |
public: |
182 |
// |
183 |
PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename,UInt_t dwinput, Bool_t staticp); // constructor |
184 |
// |
185 |
void Close(); // destructor |
186 |
// |
187 |
// |
188 |
// Setters |
189 |
// |
190 |
void SetConnection(TString host, TString user, TString password); |
191 |
void SetBOOTnumber(UInt_t boot); |
192 |
void SetRawName(TString str); |
193 |
void SetRootName(TString str); |
194 |
void SetDebugFlag(Bool_t debug); |
195 |
void SetID_RAW(UInt_t idr); |
196 |
void SetID_ROOT(UInt_t idr); |
197 |
void SetTsync(UInt_t ts); |
198 |
void SetObt0(UInt_t ts); |
199 |
void SetCommonGLRUN(UInt_t absth, UInt_t abstt); |
200 |
void SetNOBOOT(Bool_t noboot); |
201 |
void SetOlderThan(Long64_t oldthan); |
202 |
void SetTLEPath(TString str); |
203 |
void SetOrbitNo(UInt_t dwinput); |
204 |
void SetNoFrag(Bool_t nf); |
205 |
void SetAutoBoot(Bool_t nf); |
206 |
// |
207 |
Bool_t SetID_RAW(); |
208 |
// |
209 |
Int_t SetUpperLimits(); |
210 |
// |
211 |
// Getters |
212 |
// |
213 |
Bool_t GetNOBOOT(){return(NOBOOT);}; |
214 |
// |
215 |
UInt_t GetID_RAW(){return(id);}; |
216 |
UInt_t GetID_ROOT(){return(idroot);}; |
217 |
UInt_t GetBOOTnumber(){return(BOOTNO);}; |
218 |
// |
219 |
UInt_t GetAbsTime(UInt_t obt); |
220 |
UInt_t GetTsync(){return(tsync);}; |
221 |
// |
222 |
const PacketType* GetPacketType(const char* type); |
223 |
// |
224 |
TString GetRawFile(){return((TString)gSystem->BaseName(filerawname.Data()));}; |
225 |
TString GetRootFile(){return((TString)gSystem->BaseName(filerootname.Data()));}; |
226 |
TString GetRootName(){return(filerootname);}; |
227 |
TString GetRawName(){return(filerawname);}; |
228 |
TString GetRawPath(); |
229 |
TString GetRootPath(); |
230 |
|
231 |
const char* GetCleanTime(){return clean_time->AsSQLString();}; |
232 |
// |
233 |
// Functions |
234 |
// |
235 |
Int_t assignBOOT_NUMBER(); |
236 |
Int_t insertPamelaRootFile(); |
237 |
Int_t insertPamelaRawFile(); |
238 |
Int_t insertPamelaGL_TIMESYNC(); |
239 |
Int_t insertPamelaRUN(); |
240 |
Int_t insertCALO_CALIB(); |
241 |
Int_t insertTRK_CALIB(); |
242 |
Int_t insertS4_CALIB(); |
243 |
Int_t CleanGL_RUN_FRAGMENTS(); |
244 |
Int_t CleanGL_RUN_FRAGMENTS(TString fcleanfile); |
245 |
Int_t ValidateRuns(); |
246 |
Int_t ValidateRuns(TString valfile); |
247 |
Int_t assignVALIDATION(UInt_t ,Bool_t ); |
248 |
Int_t removeFile(TString rootfilename); |
249 |
// |
250 |
// void OpenFile(); |
251 |
void CheckValidate(Long64_t olderthan); |
252 |
void CheckConnection(); |
253 |
void CheckFile(); |
254 |
// |
255 |
|
256 |
Bool_t NoFrag(){return(NOFRAG);}; |
257 |
Bool_t InsertRoot(){return(INSERT_ROOT);}; |
258 |
Bool_t InsertRaw(){return(INSERT_RAW);}; |
259 |
Bool_t Validate(){return(VALIDATE);}; |
260 |
|
261 |
// Functions for TLE |
262 |
Int_t populateTLE(); |
263 |
|
264 |
UInt_t ValidateTrkCalib( CalibTrk1Event* calibtrk , EventHeader* h); |
265 |
UInt_t ValidateTrkCalib( CalibTrk2Event* calibtrk , EventHeader* h){return ValidateTrkCalib((CalibTrk1Event*)calibtrk,h); }; |
266 |
|
267 |
UInt_t Check(); |
268 |
|
269 |
}; |
270 |
#endif /* PAMELA_DB_OPERATIONS_H */ |