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 <cTle.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 |
ULong64_t obtfirst; |
61 |
ULong64_t upperobt; |
62 |
UInt_t upperpkt; |
63 |
UInt_t upperentry; |
64 |
Int_t rtev; |
65 |
Int_t rhev; |
66 |
// |
67 |
// calibration variables |
68 |
// |
69 |
Int_t t1; |
70 |
Int_t t2; |
71 |
UInt_t fromtime; |
72 |
UInt_t obt1; |
73 |
UInt_t pkt1; |
74 |
UInt_t obt2; |
75 |
UInt_t pkt2; |
76 |
UInt_t valid; |
77 |
// |
78 |
// |
79 |
Bool_t NOBOOT; |
80 |
Bool_t debug; |
81 |
|
82 |
// Path to tle file |
83 |
TString tlefilename; |
84 |
|
85 |
// flag to control profiler actions |
86 |
Bool_t INSERT_RAW; |
87 |
Bool_t INSERT_ROOT; |
88 |
Bool_t VALIDATE; |
89 |
|
90 |
TDatime *clean_time; |
91 |
|
92 |
// |
93 |
typedef std::list<const char*> pcksList; |
94 |
static void getPacketsNames(pcksList &pcksNames){ |
95 |
pcksNames.push_back("PhysEndRun"); |
96 |
pcksNames.push_back("CalibCalPulse1"); |
97 |
pcksNames.push_back("CalibCalPulse2"); |
98 |
pcksNames.push_back("Physics"); |
99 |
pcksNames.push_back("CalibTrkBoth"); |
100 |
pcksNames.push_back("CalibTrk1"); |
101 |
pcksNames.push_back("CalibTrk2"); |
102 |
pcksNames.push_back("CalibTof"); |
103 |
pcksNames.push_back("CalibS4"); |
104 |
pcksNames.push_back("CalibCalPed"); |
105 |
pcksNames.push_back("Calib1_Ac1"); |
106 |
pcksNames.push_back("Calib2_Ac1"); |
107 |
pcksNames.push_back("Calib1_Ac2"); |
108 |
pcksNames.push_back("Calib2_Ac2"); |
109 |
pcksNames.push_back("CalibCal"); |
110 |
pcksNames.push_back("RunHeader"); |
111 |
pcksNames.push_back("RunTrailer"); |
112 |
pcksNames.push_back("CalibHeader"); |
113 |
pcksNames.push_back("CalibTrailer"); |
114 |
pcksNames.push_back("InitHeader"); |
115 |
pcksNames.push_back("InitTrailer"); |
116 |
pcksNames.push_back("EventTrk"); |
117 |
pcksNames.push_back("Log"); |
118 |
pcksNames.push_back("VarDump"); |
119 |
pcksNames.push_back("ArrDump"); |
120 |
pcksNames.push_back("TabDump"); |
121 |
pcksNames.push_back("Tmtc"); |
122 |
pcksNames.push_back("Mcmd"); |
123 |
pcksNames.push_back("ForcedFECmd"); |
124 |
pcksNames.push_back("Ac1Init"); |
125 |
pcksNames.push_back("CalInit"); |
126 |
pcksNames.push_back("TrkInit"); |
127 |
pcksNames.push_back("TofInit"); |
128 |
pcksNames.push_back("TrgInit"); |
129 |
pcksNames.push_back("NdInit"); |
130 |
pcksNames.push_back("S4Init"); |
131 |
pcksNames.push_back("Ac2Init"); |
132 |
pcksNames.push_back("CalAlarm"); |
133 |
pcksNames.push_back("Ac1Alarm"); |
134 |
pcksNames.push_back("TrkAlarm"); |
135 |
pcksNames.push_back("TrgAlarm"); |
136 |
pcksNames.push_back("TofAlarm"); |
137 |
pcksNames.push_back("S4Alarm"); |
138 |
pcksNames.push_back("Ac2Alarm"); |
139 |
pcksNames.push_back("TsbT"); |
140 |
pcksNames.push_back("TsbB"); |
141 |
}; |
142 |
// |
143 |
// Functions |
144 |
// |
145 |
void HandleRun(); |
146 |
void HandleRunFragments(Bool_t mishead, Bool_t mistrail, UInt_t firstev, UInt_t lastev); |
147 |
void HandleMissingHoT(Bool_t mishead, Bool_t mistrail, UInt_t firstev, UInt_t lastev); |
148 |
void HandleSuspiciousRun(); |
149 |
void FillClass(); |
150 |
void FillClass(Bool_t mishead, Bool_t mistrail, UInt_t firstev, UInt_t lastev); |
151 |
void HandleTRK_CALIB(Bool_t pk1, Bool_t pk2); |
152 |
// |
153 |
Bool_t IsDebug(){return(debug);}; |
154 |
Bool_t IsRunAlreadyInserted(); |
155 |
Bool_t IsRunConsistent(Bool_t mishead, Bool_t mistrail, UInt_t &firstev, UInt_t &lastev); |
156 |
// |
157 |
Bool_t MissingTRK_CALIB(UInt_t t1,UInt_t t2); |
158 |
// |
159 |
UInt_t PKT(UInt_t pkt_num); |
160 |
// |
161 |
ULong64_t OBT(UInt_t obt); |
162 |
// |
163 |
UInt_t AssignRunID(); |
164 |
|
165 |
// GL_TLE related functions |
166 |
int insertTle(cTle*); |
167 |
bool isTlePresent(cTle*); |
168 |
|
169 |
public: |
170 |
// |
171 |
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); // constructor |
172 |
// |
173 |
void Close(); // destructor |
174 |
// |
175 |
// |
176 |
// Setters |
177 |
// |
178 |
void SetConnection(TString host, TString user, TString password); |
179 |
void SetBOOTnumber(UInt_t boot); |
180 |
void SetRawName(TString str); |
181 |
void SetRootName(TString str); |
182 |
void SetDebugFlag(Bool_t debug); |
183 |
void SetID_RAW(UInt_t idr); |
184 |
void SetID_ROOT(UInt_t idr); |
185 |
void SetTsync(UInt_t ts); |
186 |
void SetObt0(UInt_t ts); |
187 |
void SetCommonGLRUN(UInt_t absth, UInt_t abstt); |
188 |
void SetNOBOOT(Bool_t noboot); |
189 |
void SetOlderThan(Long64_t oldthan); |
190 |
void SetTLEPath(TString str); |
191 |
void SetOrbitNo(); |
192 |
// |
193 |
Bool_t SetID_RAW(); |
194 |
// |
195 |
Int_t SetUpperLimits(); |
196 |
// |
197 |
// Getters |
198 |
// |
199 |
Bool_t GetNOBOOT(){return(NOBOOT);}; |
200 |
// |
201 |
UInt_t GetID_RAW(){return(id);}; |
202 |
UInt_t GetID_ROOT(){return(idroot);}; |
203 |
UInt_t GetBOOTnumber(){return(BOOTNO);}; |
204 |
// |
205 |
UInt_t GetAbsTime(UInt_t obt); |
206 |
UInt_t GetTsync(){return(tsync);}; |
207 |
// |
208 |
const PacketType* GetPacketType(const char* type); |
209 |
// |
210 |
TString GetRawFile(){return((TString)gSystem->BaseName(filerawname.Data()));}; |
211 |
TString GetRawPath(){return((TString)gSystem->DirName(filerawname.Data())+'/');}; |
212 |
TString GetRootFile(){return((TString)gSystem->BaseName(filerootname.Data()));}; |
213 |
TString GetRootPath(){return((TString)gSystem->DirName(filerootname.Data())+'/');}; |
214 |
TString GetRootName(){return(filerootname);}; |
215 |
TString GetRawName(){return(filerawname);}; |
216 |
|
217 |
const char* GetCleanTime(){return clean_time->AsSQLString();}; |
218 |
// |
219 |
// Functions |
220 |
// |
221 |
Int_t assignBOOT_NUMBER(); |
222 |
Int_t insertPamelaRootFile(); |
223 |
Int_t insertPamelaRawFile(); |
224 |
Int_t insertPamelaGL_TIMESYNC(); |
225 |
Int_t insertPamelaRUN(); |
226 |
Int_t insertCALO_CALIB(); |
227 |
Int_t insertTRK_CALIB(); |
228 |
Int_t insertS4_CALIB(); |
229 |
Int_t CleanGL_RUN_FRAGMENTS(); |
230 |
Int_t ValidateRuns(); |
231 |
Int_t assignVALIDATION(UInt_t ,Bool_t ); |
232 |
// |
233 |
// void OpenFile(); |
234 |
void CheckValidate(Long64_t olderthan); |
235 |
void CheckConnection(); |
236 |
void CheckFile(); |
237 |
// |
238 |
|
239 |
Bool_t InsertRoot(){return(INSERT_ROOT);}; |
240 |
Bool_t InsertRaw(){return(INSERT_RAW);}; |
241 |
Bool_t Validate(){return(VALIDATE);}; |
242 |
|
243 |
// Functions for TLE |
244 |
Int_t populateTLE(); |
245 |
|
246 |
}; |
247 |
#endif /* PAMELA_DB_OPERATIONS_H */ |