1 |
mocchiut |
1.1 |
// |
2 |
|
|
// Look for calibrations in the file - Emiliano Mocchiutti |
3 |
|
|
// |
4 |
|
|
// CaloFINDCALIBS.c version 2.06 (2005-11-16) |
5 |
|
|
// |
6 |
|
|
// The only input needed is the path to the directory created by YODA for the data file you want to analyze. |
7 |
|
|
// |
8 |
|
|
// Changelog: |
9 |
|
|
// |
10 |
|
|
// 2.05 - 2.06 (2005-11-16): compiled! |
11 |
|
|
// |
12 |
|
|
// 2.04 - 2.05 (2005-08-04): changes to fix bugs using 64 bit architecture. |
13 |
|
|
// |
14 |
|
|
// 2.03 - 2.04 (2005-07-25): Don't load anymore yodaUtility.c use clone of routines instead |
15 |
|
|
// |
16 |
|
|
// 2.02 - 2.03 (2005-06-28): Inserted in the new software architecture. |
17 |
|
|
// |
18 |
|
|
// 2.01 - 2.02 (2005-06-07): Check if file is older than 050515_007. |
19 |
|
|
// |
20 |
|
|
// 2.00 - 2.01 (2005-06-06): Added CaloMySQLFINDCALIBS script to look at calibrations using MySQL database (corrispondent to CaloFINDCALIBS). |
21 |
|
|
// |
22 |
|
|
// 1.05 - 2.00 (2005-05-31): Added CaloMySQLFILLCALIBS program to fill the MySQL database with calorimeter calibration informations. |
23 |
|
|
// |
24 |
|
|
// 1.04 - 1.05 (2005-05-17): Changes according to the changes to CaloFindCalibs subroutine. |
25 |
|
|
// |
26 |
|
|
// 1.03 - 1.04 (2005-04-06): Changes according to the new CaloFindCalibs subroutine. |
27 |
|
|
// |
28 |
|
|
// 1.02 - 1.03 (2005-02-24): Changed variable definition from C/C++ style to ROOT style (int->Int_t). |
29 |
|
|
// |
30 |
|
|
// 1.01 - 1.02 (2005-01-17): Cleanup of the code |
31 |
|
|
// |
32 |
|
|
// 1.00 - 1.01 (2004-12-15): Include also yodaUtility.c |
33 |
|
|
// |
34 |
|
|
#include <fstream> |
35 |
|
|
#include <sstream> |
36 |
|
|
#include <TTree.h> |
37 |
|
|
#include <TClassEdit.h> |
38 |
|
|
#include <TObject.h> |
39 |
|
|
#include <TList.h> |
40 |
|
|
#include <TSystem.h> |
41 |
|
|
#include <TSystemDirectory.h> |
42 |
|
|
#include <TString.h> |
43 |
|
|
#include <TFile.h> |
44 |
|
|
#include <TClass.h> |
45 |
|
|
#include <TCanvas.h> |
46 |
|
|
#include <TH1.h> |
47 |
|
|
#include <TH1F.h> |
48 |
|
|
#include <TH2D.h> |
49 |
|
|
#include <TLatex.h> |
50 |
|
|
#include <TPad.h> |
51 |
|
|
#include <TPaveLabel.h> |
52 |
|
|
#include <TChain.h> |
53 |
|
|
#include <calomysqlstruct.h> |
54 |
|
|
#if !defined (__CINT__) |
55 |
|
|
#include <event/PamelaRun.h> |
56 |
|
|
#include <event/physics/calorimeter/CalorimeterEvent.h> |
57 |
|
|
#include <event/physics/trigger/TriggerEvent.h> |
58 |
|
|
#include <event/CalibCalPedEvent.h> |
59 |
|
|
#include <caloclasses.h> |
60 |
|
|
extern short int cquerymysql(char [], const char []); |
61 |
|
|
extern short int creadmysql(char [], char const [], struct Mystruct &); |
62 |
|
|
#endif |
63 |
|
|
#include <CaloFunctions.h> |
64 |
|
|
|
65 |
|
|
void CaloFINDCALIBS(TString filename){ |
66 |
|
|
gROOT->GetListOfCanvases()->Delete(); |
67 |
|
|
gDirectory->GetList()->Delete(); |
68 |
|
|
emicheckLib(); |
69 |
|
|
struct Calib calib; |
70 |
|
|
// |
71 |
|
|
for (Int_t s=0; s<4;s++){ |
72 |
|
|
for (Int_t d = 0; d<51; d++){ |
73 |
|
|
calib.ttime[s][d] = 0 ; |
74 |
|
|
calib.time[s][d] = 0 ; |
75 |
|
|
}; |
76 |
|
|
}; |
77 |
|
|
// |
78 |
|
|
// first of all find the calibrations in the file |
79 |
|
|
// |
80 |
|
|
Int_t wused = 0; |
81 |
|
|
CaloFindCalibs(filename, filename, wused, calib); |
82 |
|
|
// |
83 |
|
|
// print on the screen the results: |
84 |
|
|
// |
85 |
|
|
const char *ffile = filename; |
86 |
|
|
printf(" ------ %s ------- \n \n",ffile); |
87 |
|
|
Int_t calibex = 0; |
88 |
|
|
TString pfile; |
89 |
|
|
for (Int_t s=0; s<4;s++){ |
90 |
|
|
printf(" ** SECTION %i **\n",s); |
91 |
|
|
for (Int_t d = 0; d<51; d++){ |
92 |
|
|
if ( calib.ttime[s][d] != 0 ) { |
93 |
|
|
calibex++; |
94 |
|
|
if ( calib.fcode[s][d] != 10 ){ |
95 |
|
|
TString file2 = ""; |
96 |
|
|
stringcopy(file2,filename); |
97 |
|
|
pfile = (TString)whatnamewith(file2,calib.fcode[s][d]); |
98 |
|
|
} else { |
99 |
|
|
pfile = (TString)filename; |
100 |
|
|
}; |
101 |
|
|
const char *ffile = pfile; |
102 |
|
|
printf(" - from time %i to time %i use calibration at\n time %i, file: %s \n",calib.time[s][d],calib.time[s][d+1],calib.ttime[s][d],ffile); |
103 |
|
|
}; |
104 |
|
|
}; |
105 |
|
|
printf("\n"); |
106 |
|
|
}; |
107 |
|
|
printf(" ----------------------------------------------------------------------- \n \n"); |
108 |
|
|
if ( calibex < 4 ) { |
109 |
|
|
printf("No full calibration data in this file!\n"); |
110 |
|
|
}; |
111 |
|
|
// |
112 |
|
|
return; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
void CaloOLDFINDCALIBS(TString filename){ |
116 |
|
|
gROOT->GetListOfCanvases()->Delete(); |
117 |
|
|
gDirectory->GetList()->Delete(); |
118 |
|
|
emicheckLib(); |
119 |
|
|
struct Calib calib; |
120 |
|
|
|
121 |
|
|
// |
122 |
|
|
for (Int_t s=0; s<4;s++){ |
123 |
|
|
for (Int_t d = 0; d<50; d++){ |
124 |
|
|
calib.ttime[s][d] = 0 ; |
125 |
|
|
if ( d < 49 ) calib.time[s][d] = 0 ; |
126 |
|
|
}; |
127 |
|
|
}; |
128 |
|
|
// |
129 |
|
|
// first of all find the calibrations in the file |
130 |
|
|
// |
131 |
|
|
OLDCaloFindCalibs(filename, calib); |
132 |
|
|
// |
133 |
|
|
// print on the screen the results: |
134 |
|
|
// |
135 |
|
|
printf(" ---------------------------------------------------------- \n \n"); |
136 |
|
|
Int_t calibex = 0; |
137 |
|
|
for (Int_t s=0; s<4;s++){ |
138 |
|
|
Int_t stop = 0; |
139 |
|
|
for (Int_t d = 0; d<48; d++){ |
140 |
|
|
if ( calib.ttime[s][d] != 0 ) calibex++; |
141 |
|
|
if ( calib.time[s][0] != 0 ){ |
142 |
|
|
if ( d == 0 ) printf(" Section %i from time 0 to time %i use calibration at time %i \n",s,calib.time[s][d],calib.ttime[s][d]); |
143 |
|
|
if ( calib.time[s][d+1] != 0 ) { |
144 |
|
|
printf(" Section %i from time %i to time %i use calibration at time %i \n",s,calib.time[s][d],calib.time[s][d+1],calib.ttime[s][d+1]); |
145 |
|
|
} else { |
146 |
|
|
if ( !stop ){ |
147 |
|
|
printf(" Section %i from time %i use calibration at time %i \n",s,calib.time[s][d],calib.ttime[s][d+1]); |
148 |
|
|
stop = 1; |
149 |
|
|
}; |
150 |
|
|
}; |
151 |
|
|
} else { |
152 |
|
|
if ( calib.ttime[s][d] != 0 ) printf(" Section %i from time 0 use calibration at time %i \n",s,calib.ttime[s][d]); |
153 |
|
|
}; |
154 |
|
|
}; |
155 |
|
|
printf("\n"); |
156 |
|
|
}; |
157 |
|
|
printf(" ---------------------------------------------------------- \n"); |
158 |
|
|
const char *ffile = filename; |
159 |
|
|
printf(" %s \n",ffile); |
160 |
|
|
if ( calibex < 4 ) { |
161 |
|
|
printf("No full calibration data in this file!\n"); |
162 |
|
|
}; |
163 |
|
|
// |
164 |
|
|
return; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
void CaloMySQLFILLCALIBS(TString filename, Int_t FORCE = 0){ |
168 |
|
|
gDirectory->GetList()->Delete(); |
169 |
|
|
const char* startingdir = gSystem->WorkingDirectory(); |
170 |
|
|
TString path; |
171 |
|
|
stringcopy(path,startingdir); |
172 |
|
|
emicheckLib(); |
173 |
|
|
struct Calib calib; |
174 |
|
|
struct Mystruct mystruct; |
175 |
|
|
#if defined (__CINT__) |
176 |
|
|
const char *pam_lib=gSystem->Getenv("PAM_LIB"); |
177 |
|
|
stringstream libload; |
178 |
|
|
libload.str(""); |
179 |
|
|
libload << pam_lib << "/libqumy"; |
180 |
|
|
gSystem->Load(libload.str().c_str()); |
181 |
|
|
libload.str(""); |
182 |
|
|
libload << pam_lib << "/libqumy_C"; |
183 |
|
|
gSystem->Load(libload.str().c_str()); |
184 |
|
|
libload.str(""); |
185 |
|
|
libload << pam_lib << "/libreadmy"; |
186 |
|
|
gSystem->Load(libload.str().c_str()); |
187 |
|
|
libload.str(""); |
188 |
|
|
libload << pam_lib << "/libreadmy_C"; |
189 |
|
|
gSystem->Load(libload.str().c_str()); |
190 |
|
|
#endif |
191 |
|
|
printf("\n"); |
192 |
|
|
Int_t wused = 0; |
193 |
|
|
TString nfilen; |
194 |
|
|
Int_t calibex = 0; |
195 |
|
|
TString pfile; |
196 |
|
|
const char *ffile; |
197 |
|
|
Int_t chkmysql = 0; |
198 |
|
|
calib.db = "romemuons"; |
199 |
|
|
const string fil = (const char*)filename; |
200 |
|
|
Int_t posiz = fil.find("dw_"); |
201 |
|
|
if ( posiz == -1 ) posiz = fil.find("DW_"); |
202 |
|
|
Int_t posiz2 = posiz+13; |
203 |
|
|
TString file2; |
204 |
|
|
stringcopy(file2,filename,posiz,posiz2); |
205 |
|
|
const char *file = file2; |
206 |
|
|
// char *file = 0; |
207 |
|
|
//file = "dw_000000_000"; |
208 |
|
|
//char *file0 = filename; |
209 |
|
|
//string fil = filename; |
210 |
|
|
//Int_t posiz = fil.find("dw_"); |
211 |
|
|
//if ( posiz == -1 ) posiz = fil.find("DW_"); |
212 |
|
|
//if ( posiz == -1 ) return; |
213 |
|
|
//memcpy(file, file0+posiz, 13); |
214 |
|
|
stringstream tablename; |
215 |
|
|
tablename.str(""); |
216 |
|
|
tablename << "calocalib_" << file; |
217 |
|
|
TString tabula; |
218 |
|
|
tabula = tablename.str().c_str(); |
219 |
|
|
const string myfil = (const char *)filename; |
220 |
|
|
Int_t myposiz = myfil.find("dw_"); |
221 |
|
|
if ( myposiz == -1 ) myposiz = myfil.find("DW_"); |
222 |
|
|
if ( myposiz == -1 ) return; |
223 |
|
|
stringcopy(calib.basepath,filename,0,myposiz); |
224 |
|
|
// |
225 |
|
|
// check existence of database |
226 |
|
|
// |
227 |
|
|
printf("Check existence of database %s...\n",calib.db); |
228 |
|
|
stringstream qy; |
229 |
|
|
qy.str(""); |
230 |
|
|
qy << "use " << calib.db; |
231 |
|
|
chkmysql = cquerymysql(calib.db,qy.str().c_str()); |
232 |
|
|
if ( chkmysql ) { |
233 |
|
|
printf(" - the database %s does not exists -\nCreating database %s ... \n",calib.db,calib.db); |
234 |
|
|
qy.str(""); |
235 |
|
|
qy << "create database " << calib.db; |
236 |
|
|
chkmysql = cquerymysql("mysql",qy.str().c_str()); |
237 |
|
|
if ( chkmysql ) { |
238 |
|
|
if ( chkmysql == 1 ) printf("- ERROR: problems in MySQL initialization -\n\n"); |
239 |
|
|
if ( chkmysql == 2 ) printf("- ERROR: problems in MySQL login, check username and password -\n\n"); |
240 |
|
|
printf("ERROR: problems querying MySQL database! \nExiting...\n"); |
241 |
|
|
goto end; |
242 |
|
|
} else { |
243 |
|
|
printf("...done!\n\n"); |
244 |
|
|
}; |
245 |
|
|
} else { |
246 |
|
|
printf("...OK it exists! \n\n"); |
247 |
|
|
}; |
248 |
|
|
// |
249 |
|
|
if ( !FORCE ){ |
250 |
|
|
printf("Not in FORCE mode, check existence of table %s...\n",tablename.str().c_str()); |
251 |
|
|
// |
252 |
|
|
// if not in force mode check if calibration exists and contains any data: |
253 |
|
|
// |
254 |
|
|
qy.str(""); |
255 |
|
|
qy << "select * from " << tablename.str().c_str(); |
256 |
|
|
chkmysql = creadmysql(calib.db,qy.str().c_str(),mystruct); |
257 |
|
|
if ( chkmysql || mystruct.totime == -1 ) { |
258 |
|
|
if ( chkmysql == 1 || chkmysql == 2 ){ |
259 |
|
|
if ( chkmysql == 1 ) printf("- ERROR: problems in MySQL initialization -\n\n"); |
260 |
|
|
if ( chkmysql == 2 ) printf("- ERROR: problems in MySQL login, check username and password -\n\n"); |
261 |
|
|
goto end; |
262 |
|
|
}; |
263 |
|
|
if ( mystruct.totime == -1 ){ |
264 |
|
|
printf("- the table exists but it is empty, dropping empty table...\n"); |
265 |
|
|
qy.str(""); |
266 |
|
|
qy << "drop table " << tablename.str().c_str(); |
267 |
|
|
chkmysql = cquerymysql(calib.db,qy.str().c_str()); |
268 |
|
|
if ( chkmysql ) { |
269 |
|
|
if ( chkmysql == 1 ) printf("- ERROR: problems in MySQL initialization -\n\n"); |
270 |
|
|
if ( chkmysql == 2 ) printf("- ERROR: problems in MySQL login, check username and password -\n\n"); |
271 |
|
|
printf("ERROR: problems querying MySQL database! \nExiting...\n"); |
272 |
|
|
goto end; |
273 |
|
|
} else { |
274 |
|
|
printf("...done!\n\n"); |
275 |
|
|
chkmysql = 3; |
276 |
|
|
}; |
277 |
|
|
}; |
278 |
|
|
if ( chkmysql == 3 ){ |
279 |
|
|
printf("- the table %s does not exists - \nCreating calibration table %s ... \n",tablename.str().c_str(),tablename.str().c_str()); |
280 |
|
|
|
281 |
|
|
qy.str(""); |
282 |
|
|
qy << "create table " << tablename.str().c_str(); |
283 |
|
|
qy << " ( id int auto_increment not null, section tinyint(1) unsigned zerofill default '0' not null, obtjump tinyint(1) unsigned zerofill default '0' not null, fromtime int(30) unsigned default '0' not null, totime int(30) unsigned default '0' not null, calibtime int(30) unsigned default '0' not null, calcalibfile varchar(25) default '' not null, primary key (id) )"; |
284 |
|
|
chkmysql = cquerymysql(calib.db,qy.str().c_str()); |
285 |
|
|
if ( chkmysql ) { |
286 |
|
|
if ( chkmysql == 1 ) printf("- ERROR: problems in MySQL initialization -\n\n"); |
287 |
|
|
if ( chkmysql == 2 ) printf("- ERROR: problems in MySQL login, check username and password -\n\n"); |
288 |
|
|
printf("ERROR: problems querying MySQL database! \nExiting...\n"); |
289 |
|
|
goto end; |
290 |
|
|
} else { |
291 |
|
|
printf("...done!\n\n"); |
292 |
|
|
}; |
293 |
|
|
}; |
294 |
|
|
} else { |
295 |
|
|
printf("- the table exists -\nExiting! Use FORCE = 1 to override \n\n"); |
296 |
|
|
goto end; |
297 |
|
|
}; |
298 |
|
|
} else { |
299 |
|
|
// |
300 |
|
|
// if in force mode drop the old table |
301 |
|
|
// |
302 |
|
|
qy.str(""); |
303 |
|
|
qy << "drop table " << tablename.str().c_str(); |
304 |
|
|
chkmysql = cquerymysql(calib.db,qy.str().c_str()); |
305 |
|
|
qy.str(""); |
306 |
|
|
qy << "create table " << tablename.str().c_str(); |
307 |
|
|
qy << " ( id int auto_increment not null, section tinyint(1) unsigned zerofill default '0' not null, obtjump tinyint(1) unsigned zerofill default '0' not null, fromtime int(30) unsigned default '0' not null, totime int(30) unsigned default '0' not null, calibtime int(30) unsigned default '0' not null, calcalibfile varchar(25) default '' not null, primary key (id) )"; |
308 |
|
|
printf("Creating calibration table %s ... \n",tablename.str().c_str()); |
309 |
|
|
chkmysql = cquerymysql(calib.db,qy.str().c_str()); |
310 |
|
|
if ( chkmysql ) { |
311 |
|
|
if ( chkmysql == 1 ) printf("- ERROR: problems in MySQL initialization -\n\n"); |
312 |
|
|
if ( chkmysql == 2 ) printf("- ERROR: problems in MySQL login, check username and password -\n\n"); |
313 |
|
|
printf("ERROR: problems querying MySQL database! \nExiting...\n"); |
314 |
|
|
goto end; |
315 |
|
|
} else { |
316 |
|
|
printf("...done!\n"); |
317 |
|
|
}; |
318 |
|
|
}; |
319 |
|
|
// |
320 |
|
|
for (Int_t s=0; s<4;s++){ |
321 |
|
|
for (Int_t d = 0; d<51; d++){ |
322 |
|
|
calib.ttime[s][d] = 0 ; |
323 |
|
|
calib.time[s][d] = 0 ; |
324 |
|
|
}; |
325 |
|
|
}; |
326 |
|
|
// |
327 |
|
|
// first of all find the calibrations in the file |
328 |
|
|
// |
329 |
|
|
wused = 0; |
330 |
|
|
stringcopy(nfilen,filename); |
331 |
|
|
CaloFindCalibs(nfilen, nfilen, wused, calib); |
332 |
|
|
// |
333 |
|
|
// print on the screen the results: |
334 |
|
|
// |
335 |
|
|
ffile = (const char *)nfilen; |
336 |
|
|
printf(" ------ %s ------- \n \n",ffile); |
337 |
|
|
calibex = 0; |
338 |
|
|
file2 = ""; |
339 |
|
|
for (Int_t s=0; s<4;s++){ |
340 |
|
|
printf(" ** SECTION %i **\n",s); |
341 |
|
|
for (Int_t d = 0; d<51; d++){ |
342 |
|
|
if ( calib.ttime[s][d] != 0 ) { |
343 |
|
|
calibex++; |
344 |
|
|
if ( calib.fcode[s][d] != 10 ){ |
345 |
|
|
file2 = ""; |
346 |
|
|
stringcopy(file2,nfilen); |
347 |
|
|
pfile = (TString)whatnamewith(file2,calib.fcode[s][d]); |
348 |
|
|
} else { |
349 |
|
|
pfile = (TString)nfilen; |
350 |
|
|
}; |
351 |
|
|
|
352 |
|
|
// char *mfile = 0; |
353 |
|
|
//mfile = "dw_000000_000"; |
354 |
|
|
//char *mfile0 = pfile; |
355 |
|
|
//string mfil = pfile; |
356 |
|
|
//Int_t posiz = fil.find("dw_"); |
357 |
|
|
//if ( posiz == -1 ) posiz = fil.find("DW_"); |
358 |
|
|
//if ( posiz == -1 ) return; |
359 |
|
|
//memcpy(mfile, mfile0+posiz, 13); |
360 |
|
|
|
361 |
|
|
const string fil = (const char*)pfile; |
362 |
|
|
Int_t posiz = fil.find("dw_"); |
363 |
|
|
if ( posiz == -1 ) posiz = fil.find("DW_"); |
364 |
|
|
Int_t posiz2 = posiz+13; |
365 |
|
|
TString file2; |
366 |
|
|
stringcopy(file2,filename,posiz,posiz2); |
367 |
|
|
const char *mfile = file2; |
368 |
|
|
stringstream tablefilename; |
369 |
|
|
tablefilename.str(""); |
370 |
|
|
tablefilename << mfile; |
371 |
|
|
|
372 |
|
|
// |
373 |
|
|
const char *caliba=calib.basepath; |
374 |
|
|
printf(" - from time %i to time %i use calibration at\n time %i, file: %s%s00 \n",calib.time[s][d],calib.time[s][d+1],calib.ttime[s][d],caliba,tablefilename.str().c_str()); |
375 |
|
|
stringstream myquery; |
376 |
|
|
myquery.str(""); |
377 |
|
|
const char *tabula2 = tabula; |
378 |
|
|
// |
379 |
|
|
myquery << "insert into " << tabula2; |
380 |
|
|
myquery << " values (0," << s; |
381 |
|
|
myquery << "," << calib.obtjump; |
382 |
|
|
myquery << "," << calib.time[s][d]; |
383 |
|
|
myquery << "," << calib.time[s][d+1]; |
384 |
|
|
myquery << "," << calib.ttime[s][d]; |
385 |
|
|
myquery << ",\"" << tablefilename.str().c_str(); |
386 |
|
|
myquery << "\")"; |
387 |
|
|
Int_t chkmysql = cquerymysql(calib.db,myquery.str().c_str()); |
388 |
|
|
if ( chkmysql ) { |
389 |
|
|
if ( chkmysql == 1 ) printf("- ERROR: problems in MySQL initialization -\n\n"); |
390 |
|
|
if ( chkmysql == 2 ) printf("- ERROR: problems in MySQL login, check username and password -\n\n"); |
391 |
|
|
printf("ERROR: problems querying MySQL database! \nExiting...\n"); |
392 |
|
|
goto end; |
393 |
|
|
}; |
394 |
|
|
}; |
395 |
|
|
}; |
396 |
|
|
printf("\n"); |
397 |
|
|
}; |
398 |
|
|
printf(" ----------------------------------------------------------------------- \n \n"); |
399 |
|
|
if ( calibex < 4 ) { |
400 |
|
|
printf("No full calibration data in this file!\n"); |
401 |
|
|
}; |
402 |
|
|
// |
403 |
|
|
end: |
404 |
|
|
#if defined (__CINT__) |
405 |
|
|
char *pam_lib=gSystem->Getenv("PAM_LIB"); |
406 |
|
|
libload.str(""); |
407 |
|
|
libload << pam_lib << "/libreadmy"; |
408 |
|
|
gSystem->Unload(libload.str().c_str()); |
409 |
|
|
libload.str(""); |
410 |
|
|
libload << pam_lib << "/libreadmy_C"; |
411 |
|
|
gSystem->Unload(libload.str().c_str()); |
412 |
|
|
char *pam_lib=gSystem->Getenv("PAM_LIB"); |
413 |
|
|
stringstream libload; |
414 |
|
|
libload.str(""); |
415 |
|
|
libload << pam_lib << "/libqumy"; |
416 |
|
|
gSystem->Unload(libload.str().c_str()); |
417 |
|
|
libload.str(""); |
418 |
|
|
libload << pam_lib << "/libqumy_C"; |
419 |
|
|
gSystem->Unload(libload.str().c_str()); |
420 |
|
|
#endif |
421 |
|
|
return; |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
void CaloMySQLFINDCALIBS(TString filename){ |
425 |
|
|
emicheckLib(); |
426 |
|
|
const char* startingdir = gSystem->WorkingDirectory(); |
427 |
|
|
TString path; |
428 |
|
|
stringcopy(path,startingdir); |
429 |
|
|
struct Calib calib; |
430 |
|
|
struct Mystruct mystruct; |
431 |
|
|
// |
432 |
|
|
const string myfil = (const char *)filename; |
433 |
|
|
Int_t myposiz = myfil.find("dw_"); |
434 |
|
|
if ( myposiz == -1 ) myposiz = myfil.find("DW_"); |
435 |
|
|
if ( myposiz == -1 ) return; |
436 |
|
|
|
437 |
|
|
stringcopy(calib.basepath,filename,0,myposiz); |
438 |
|
|
stringcopy(calib.yodalev,filename,myposiz+13,myposiz+15); |
439 |
|
|
// |
440 |
|
|
calib.mysql = 1; |
441 |
|
|
// |
442 |
|
|
#if defined (__CINT__) |
443 |
|
|
const char *pam_lib=gSystem->Getenv("PAM_LIB"); |
444 |
|
|
stringstream libload; |
445 |
|
|
libload.str(""); |
446 |
|
|
libload << pam_lib << "/libreadmy"; |
447 |
|
|
gSystem->Load(libload.str().c_str()); |
448 |
|
|
libload.str(""); |
449 |
|
|
libload << pam_lib << "/libreadmy_C"; |
450 |
|
|
gSystem->Load(libload.str().c_str()); |
451 |
|
|
#endif |
452 |
|
|
Int_t chkmysql = 0; |
453 |
|
|
calib.db = "romemuons"; |
454 |
|
|
const string fil = (const char*)filename; |
455 |
|
|
Int_t posiz = fil.find("dw_"); |
456 |
|
|
if ( posiz == -1 ) posiz = fil.find("DW_"); |
457 |
|
|
Int_t posiz2 = posiz+13; |
458 |
|
|
TString file2; |
459 |
|
|
stringcopy(file2,filename,posiz,posiz2); |
460 |
|
|
const char *file = file2; |
461 |
|
|
stringstream tablename; |
462 |
|
|
tablename.str(""); |
463 |
|
|
tablename << "calocalib_" << file; |
464 |
|
|
// |
465 |
|
|
Int_t calibex = 0; |
466 |
|
|
Int_t etime = 0; |
467 |
|
|
const char *ffile = filename; |
468 |
|
|
// |
469 |
|
|
stringstream qy; |
470 |
|
|
qy.str(""); |
471 |
|
|
printf("\nTry the connection to the MySQL database in Trieste...\n"); |
472 |
|
|
qy << "select * from " << tablename.str().c_str(); |
473 |
|
|
chkmysql = creadmysql(calib.db,qy.str().c_str(),mystruct); |
474 |
|
|
if ( chkmysql || mystruct.totime == -1 ) { |
475 |
|
|
printf("\n- ERROR: problems querying MySQL database! -\n\n- ERROR: Cannot use the MySQL database! -\n\n"); |
476 |
|
|
if ( mystruct.totime == -1 ) printf("- ERROR: it seems there are no data in table called %s -\n\n",tablename.str().c_str()); |
477 |
|
|
if ( chkmysql == 1 ) printf("- ERROR: problems in MySQL initialization -\n\n"); |
478 |
|
|
if ( chkmysql == 2 ) printf("- ERROR: problems in MySQL login, check username and password -\n\n"); |
479 |
|
|
if ( chkmysql == 3 ) printf("- ERROR: it seems there is no table called %s -\n\n",tablename.str().c_str()); |
480 |
|
|
gSystem->ChangeDirectory(path); |
481 |
|
|
goto veryend; |
482 |
|
|
} else { |
483 |
|
|
printf("...OK the connection is fine! \n\n Using database \"%s\", table \"%s\"\n\n",calib.db,tablename.str().c_str()); |
484 |
|
|
}; |
485 |
|
|
calib.tablename = tablename.str().c_str(); |
486 |
|
|
|
487 |
|
|
calib.obtjump = 0; |
488 |
|
|
calib.time[0][0] = -1; |
489 |
|
|
calib.time[1][0] = -1; |
490 |
|
|
calib.time[2][0] = -1; |
491 |
|
|
calib.time[3][0] = -1; |
492 |
|
|
calibex = 0; |
493 |
|
|
etime = 0; |
494 |
|
|
printf(" ------ %s ------- \n \n",ffile); |
495 |
|
|
// stringstream qy; |
496 |
|
|
qy.str(""); |
497 |
|
|
const char *caliba; |
498 |
|
|
const char *yodala; |
499 |
|
|
const char *fila; |
500 |
|
|
for (Int_t s = 0; s < 4; s++){ |
501 |
|
|
etime = 0; |
502 |
|
|
printf(" ** SECTION %i **\n",s); |
503 |
|
|
while ( etime > -1 ){ |
504 |
|
|
if ( !calib.obtjump ){ |
505 |
|
|
if ( etime > calib.time[s][0] ){ |
506 |
|
|
Int_t chkmysql = 0; |
507 |
|
|
stringstream myfile; |
508 |
|
|
const char *tabula = calib.tablename; |
509 |
|
|
qy.str(""); |
510 |
|
|
qy << "select * from " << tabula; |
511 |
|
|
qy << " where section = " << s; |
512 |
|
|
qy << " and fromtime >= " << calib.time[s][0]; |
513 |
|
|
qy << " limit 1"; |
514 |
|
|
chkmysql = creadmysql(calib.db,qy.str().c_str(),mystruct); |
515 |
|
|
if ( mystruct.totime == -1 ){ |
516 |
|
|
etime = -2; |
517 |
|
|
goto notend; |
518 |
|
|
}; |
519 |
|
|
if ( chkmysql ) { |
520 |
|
|
printf("- ERROR: problems querying MySQL database! -\n- ERROR: Empty table? -\n\n"); |
521 |
|
|
goto veryend; |
522 |
|
|
} else { |
523 |
|
|
calib.time[s][0] = mystruct.totime; |
524 |
|
|
calib.time[s][1] = mystruct.fromtime; |
525 |
|
|
calib.ttime[s][0] = mystruct.calibtime; |
526 |
|
|
caliba = calib.basepath; |
527 |
|
|
yodala = calib.yodalev; |
528 |
|
|
fila = mystruct.calcalibfile; |
529 |
|
|
myfile.str(""); |
530 |
|
|
myfile << caliba; |
531 |
|
|
myfile << fila; |
532 |
|
|
myfile << yodala << "/"; |
533 |
|
|
calib.obtjump = mystruct.obtjump; |
534 |
|
|
printf(" - From time %i to time %i use calibration at\ntime %i, file: %s\n",calib.time[s][1],calib.time[s][0],calib.ttime[s][0],myfile.str().c_str()); |
535 |
|
|
calibex++; |
536 |
|
|
}; |
537 |
|
|
Int_t pedeerr = 0; |
538 |
|
|
pedeerr = CaloPede(myfile.str().c_str(),s,calib.ttime[s][0],calib); |
539 |
|
|
if ( pedeerr ) { |
540 |
|
|
printf("\n\nERROR: problems opening calibration file! \n\nERROR: YODA version of the calibration file is not %s? \n\n",yodala); |
541 |
|
|
goto veryend; |
542 |
|
|
}; |
543 |
|
|
}; |
544 |
|
|
}; |
545 |
|
|
etime = calib.time[0][0]+1; |
546 |
|
|
notend: |
547 |
|
|
printf(" "); |
548 |
|
|
}; |
549 |
|
|
printf("\n"); |
550 |
|
|
}; |
551 |
|
|
printf(" ----------------------------------------------------------------------- \n \n"); |
552 |
|
|
if ( calibex < 4 ) { |
553 |
|
|
printf("No full calibration data in this file!\n"); |
554 |
|
|
}; |
555 |
|
|
veryend: |
556 |
|
|
#if defined (__CINT__) |
557 |
|
|
gSystem->ChangeDirectory(path); |
558 |
|
|
char *pam_lib=gSystem->Getenv("PAM_LIB"); |
559 |
|
|
libload.str(""); |
560 |
|
|
libload << pam_lib << "/libreadmy"; |
561 |
|
|
gSystem->Unload(libload.str().c_str()); |
562 |
|
|
libload.str(""); |
563 |
|
|
libload << pam_lib << "/libreadmy_C"; |
564 |
|
|
gSystem->Unload(libload.str().c_str()); |
565 |
|
|
#endif |
566 |
|
|
return; |
567 |
|
|
} |