1 |
// |
2 |
#include <sstream> |
3 |
// |
4 |
#include <TObject.h> |
5 |
#include <TSystem.h> |
6 |
#include <TArrayL.h> |
7 |
#include <TFile.h> |
8 |
#include <TTree.h> |
9 |
#include <TDirectory.h> |
10 |
#include <TSQLServer.h> |
11 |
#include <TSQLRow.h> |
12 |
#include <TSQLResult.h> |
13 |
// |
14 |
#include <GLTables.h> |
15 |
#include <RunInfo.h> |
16 |
ClassImp(SoftInfo); |
17 |
ClassImp(ItoRunInfo); |
18 |
// |
19 |
using namespace std; |
20 |
// |
21 |
|
22 |
SoftInfo::SoftInfo() { |
23 |
TRIG_ver = ""; |
24 |
TOF_ver = ""; |
25 |
AC_ver = ""; |
26 |
TRK_ver = ""; |
27 |
ORB_ver = ""; |
28 |
CAL_ver = ""; |
29 |
ND_ver = ""; |
30 |
S4_ver = ""; |
31 |
} |
32 |
|
33 |
ItoRunInfo::ItoRunInfo() { |
34 |
reprocessing = false; |
35 |
updating = false; |
36 |
isreadonly = true; |
37 |
first_file_entry = 0; |
38 |
last_file_entry = 0; |
39 |
file_entries = 0ULL; |
40 |
totnorun = 0LL; |
41 |
version = new SoftInfo(); |
42 |
version->TRIG_ver = ""; |
43 |
version->TOF_ver = ""; |
44 |
version->AC_ver = ""; |
45 |
version->TRK_ver = ""; |
46 |
version->CAL_ver = ""; |
47 |
version->ND_ver = ""; |
48 |
version->S4_ver = ""; |
49 |
version->ORB_ver = ""; |
50 |
norun = 0; |
51 |
runlist = new TArrayL(0,NULL); |
52 |
file = new TFile(); |
53 |
newtree = new TTree(); |
54 |
} |
55 |
|
56 |
ItoRunInfo::ItoRunInfo(TFile *processFl){ |
57 |
// |
58 |
file=(TFile*)processFl; |
59 |
dbc=NULL; |
60 |
processFolder = ""; |
61 |
idRun = 0ULL; |
62 |
Detector = "NONE"; |
63 |
// |
64 |
reprocessing = false; |
65 |
updating = false; |
66 |
first_file_entry = 0; |
67 |
last_file_entry = 0; |
68 |
file_entries = 0ULL; |
69 |
version = new SoftInfo(); |
70 |
version->TRIG_ver = ""; |
71 |
version->TOF_ver = ""; |
72 |
version->AC_ver = ""; |
73 |
version->TRK_ver = ""; |
74 |
version->ORB_ver = ""; |
75 |
version->CAL_ver = ""; |
76 |
version->ND_ver = ""; |
77 |
version->S4_ver = ""; |
78 |
norun = 0; |
79 |
totnorun = 0; |
80 |
// runlist = new TArrayL(0,NULL); |
81 |
// |
82 |
} |
83 |
|
84 |
ItoRunInfo::ItoRunInfo(TSQLServer *db, TFile *processFl, TString processFld){ |
85 |
// |
86 |
file=(TFile*)processFl; |
87 |
dbc=(TSQLServer*)db; |
88 |
processFolder = processFld; |
89 |
// |
90 |
reprocessing = false; |
91 |
updating = false; |
92 |
first_file_entry = 0; |
93 |
last_file_entry = 0; |
94 |
file_entries = 0ULL; |
95 |
version = new SoftInfo(); |
96 |
version->TRIG_ver = ""; |
97 |
version->TOF_ver = ""; |
98 |
version->AC_ver = ""; |
99 |
version->TRK_ver = ""; |
100 |
version->ORB_ver = ""; |
101 |
version->CAL_ver = ""; |
102 |
version->ND_ver = ""; |
103 |
version->S4_ver = ""; |
104 |
norun = 0; |
105 |
totnorun = 0; |
106 |
runlist = new TArrayL(0,NULL); |
107 |
// |
108 |
} |
109 |
|
110 |
Int_t ItoRunInfo::Update(ULong64_t run, TString Detector, TString Version){ |
111 |
// |
112 |
isreadonly = false; |
113 |
idRun = run; |
114 |
// |
115 |
Bool_t debug = false; |
116 |
// |
117 |
Bool_t ismydir = false; |
118 |
// |
119 |
if ( !strcmp(processFolder.Data(),"") ){ |
120 |
processFolder = "runinfoFolder"; |
121 |
ismydir = true; |
122 |
}; |
123 |
// |
124 |
GL_RUN *oldrun = new GL_RUN(); |
125 |
GL_RUN *newrun = new GL_RUN(); |
126 |
SoftInfo *oldver = new SoftInfo(); |
127 |
SoftInfo *newver = new SoftInfo(); |
128 |
// |
129 |
ID = 0ULL; |
130 |
ID_REG_RUN = 0ULL; |
131 |
ID_REG_RUN_L2 = 0ULL; |
132 |
RUNHEADER_TIME = 0ULL; |
133 |
RUNTRAILER_TIME = 0ULL; |
134 |
EV_REG_PHYS_FROM = 0; |
135 |
EV_REG_PHYS_TO = 0; |
136 |
EV_REG_RUNHEADER = 0; |
137 |
EV_REG_RUNTRAILER = 0; |
138 |
TRK_CALIB_USED = 0; |
139 |
EFF_WRK_SCHEDULE = 0; |
140 |
PRH_VAR_TRG_MODE_A = 0; |
141 |
PRH_VAR_TRG_MODE_B = 0; |
142 |
ACQ_BUILD_INFO = 0; |
143 |
ACQ_VAR_INFO = 0; |
144 |
version->TRIG_ver = ""; |
145 |
version->TOF_ver = ""; |
146 |
version->AC_ver = ""; |
147 |
version->TRK_ver = ""; |
148 |
version->ORB_ver = ""; |
149 |
version->CAL_ver = ""; |
150 |
version->ND_ver = ""; |
151 |
version->S4_ver = ""; |
152 |
// |
153 |
norun = 0; |
154 |
runlist = new TArrayL(0,NULL); |
155 |
//runlist->Reset(); |
156 |
// |
157 |
Bool_t found = false; |
158 |
Int_t error = 0; |
159 |
// |
160 |
// TFile *temprfile = 0; |
161 |
// TTree *temprrun = 0; |
162 |
// stringstream temprname; |
163 |
// stringstream tempdir; |
164 |
// const char* routdir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
165 |
// |
166 |
TTree *oldtree = 0; |
167 |
// |
168 |
// |
169 |
// Try to get the tree Run in the processed file |
170 |
// |
171 |
oldtree = (TTree*)file->Get("Run"); |
172 |
// |
173 |
// Look for detector's versions if we are updating a single detector |
174 |
// |
175 |
if ( debug ) printf("Detector -%s- \n",Detector.Data()); |
176 |
if ( !strcmp(Detector.Data(),"NONE") ){ |
177 |
version->TRIG_ver = Version; |
178 |
version->TOF_ver = Version; |
179 |
version->AC_ver = Version; |
180 |
version->TRK_ver = Version; |
181 |
version->ORB_ver = Version; |
182 |
version->CAL_ver = Version; |
183 |
version->S4_ver = Version; |
184 |
version->ND_ver = Version; |
185 |
} else { |
186 |
if ( !strcmp(Detector.Data(),"TRIG") ) version->TRIG_ver = Version; |
187 |
if ( !strcmp(Detector.Data(),"TOF") ) version->TOF_ver = Version; |
188 |
if ( !strcmp(Detector.Data(),"AC") ) version->AC_ver = Version; |
189 |
if ( !strcmp(Detector.Data(),"TRK") ) version->TRK_ver = Version; |
190 |
if ( !strcmp(Detector.Data(),"CALO") ) version->CAL_ver = Version; |
191 |
if ( !strcmp(Detector.Data(),"S4") ) version->S4_ver = Version; |
192 |
if ( !strcmp(Detector.Data(),"ND") ) version->ND_ver = Version; |
193 |
if ( !strcmp(Detector.Data(),"ORB") ) version->ORB_ver = Version; |
194 |
if ( strcmp(Detector.Data(),"TRIG") && strcmp(Detector.Data(),"TOF") && strcmp(Detector.Data(),"AC") && strcmp(Detector.Data(),"TRK") && strcmp(Detector.Data(),"CALO") && strcmp(Detector.Data(),"S4") && strcmp(Detector.Data(),"ND") && strcmp(Detector.Data(),"ORB") ) return(-804); |
195 |
}; |
196 |
// |
197 |
if ( !oldtree ) { |
198 |
// |
199 |
if ( strcmp(Detector.Data(),"NONE") ) return(-803); |
200 |
updating = false; |
201 |
if ( debug ) printf(" RunInfo: creating Run tree in this file\n"); |
202 |
// |
203 |
} else { |
204 |
// |
205 |
// temprname.str(""); |
206 |
// temprname << routdir; |
207 |
// temprname << "/" << processFolder.Data(); |
208 |
// gSystem->MakeDirectory(temprname.str().c_str()); |
209 |
// tempdir.str(""); |
210 |
// tempdir << temprname.str().c_str(); |
211 |
// temprname << "/runinfo_run"; |
212 |
// temprname << idRun << ".root"; |
213 |
// if ( debug ) printf(" file temporaneo is %s \n",temprname.str().c_str()); |
214 |
// // |
215 |
// temprfile = new TFile(temprname.str().c_str(),"RECREATE"); |
216 |
// // |
217 |
// temprrun = new TTree(); |
218 |
// // |
219 |
// if ( !temprfile ) return(-805); |
220 |
// if ( !oldtree ) return(-806); |
221 |
// if ( !temprrun ) return(-807); |
222 |
// // |
223 |
// temprrun = oldtree->CloneTree(-1,"fast"); |
224 |
// // |
225 |
// temprfile->cd(); |
226 |
// temprrun->SetName("Run-old"); |
227 |
// temprfile->Write(); |
228 |
// if ( temprrun ) temprrun->Delete(); |
229 |
// temprfile->Close(); |
230 |
// // |
231 |
// oldtree->Delete("all"); |
232 |
// |
233 |
updating = true; |
234 |
if ( debug ) printf(" RunInfo: updating versioning information \n"); |
235 |
// |
236 |
}; |
237 |
// |
238 |
file->cd(); |
239 |
// |
240 |
// Prepare a new tree to upgrade the contents of the old tree |
241 |
// |
242 |
newtree = new TTree("Run-new","PAMELA Level2 data from the GL_RUN table"); |
243 |
newtree->Branch("RunInfo","GL_RUN",&newrun); |
244 |
newtree->Branch("SoftInfo","SoftInfo",&newver); |
245 |
// |
246 |
// |
247 |
if ( !updating ){ |
248 |
if ( idRun == 0ULL ){ |
249 |
if ( debug ) printf("\n RUNINFO - ERROR: reprocessing data but no RunInfo tree in Level2 file. \n"); |
250 |
return(-805); |
251 |
}; |
252 |
// |
253 |
runlist = new TArrayL(1); |
254 |
// |
255 |
error = Query_GL_RUN(idRun, dbc); |
256 |
// |
257 |
if ( error ){ |
258 |
if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n"); |
259 |
return(error); |
260 |
}; |
261 |
if ( ID == 0ULL ){ |
262 |
if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %llu \n",idRun); |
263 |
return(-5); |
264 |
}; |
265 |
// |
266 |
// |
267 |
// |
268 |
newrun->ID = ID; |
269 |
newrun->ID_REG_RUN = ID_REG_RUN; |
270 |
newrun->ID_REG_RUN_L2 = ID_REG_RUN_L2; |
271 |
newrun->RUNHEADER_TIME = RUNHEADER_TIME; |
272 |
newrun->RUNTRAILER_TIME = RUNTRAILER_TIME; |
273 |
newrun->EV_REG_PHYS_FROM = EV_REG_PHYS_FROM; |
274 |
newrun->EV_REG_PHYS_TO = EV_REG_PHYS_TO; |
275 |
newrun->EV_REG_RUNHEADER = EV_REG_RUNHEADER; |
276 |
newrun->EV_REG_RUNTRAILER = EV_REG_RUNTRAILER; |
277 |
newrun->TRK_CALIB_USED = TRK_CALIB_USED; |
278 |
newrun->EFF_WRK_SCHEDULE = EFF_WRK_SCHEDULE; |
279 |
newrun->PRH_VAR_TRG_MODE_A = PRH_VAR_TRG_MODE_A; |
280 |
newrun->PRH_VAR_TRG_MODE_B = PRH_VAR_TRG_MODE_B; |
281 |
newrun->ACQ_BUILD_INFO = ACQ_BUILD_INFO; |
282 |
newrun->ACQ_VAR_INFO = ACQ_VAR_INFO; |
283 |
newver->TRIG_ver = version->TRIG_ver; |
284 |
newver->TOF_ver = version->TOF_ver; |
285 |
newver->AC_ver = version->AC_ver; |
286 |
newver->TRK_ver = version->TRK_ver; |
287 |
newver->ORB_ver = version->ORB_ver; |
288 |
newver->CAL_ver = version->CAL_ver; |
289 |
newver->S4_ver = version->S4_ver; |
290 |
newver->ND_ver = version->ND_ver; |
291 |
// |
292 |
// fill the tree; |
293 |
// |
294 |
newtree->Fill(); |
295 |
// |
296 |
totnorun = 1; |
297 |
reprocessing = false; |
298 |
first_file_entry = 0; |
299 |
last_file_entry = (UInt_t)(EV_REG_PHYS_TO - EV_REG_PHYS_FROM); |
300 |
norun = 1; |
301 |
runlist->AddAt((Long64_t)ID,0); |
302 |
// |
303 |
newtree->SetName("Run"); |
304 |
// |
305 |
file->cd(); |
306 |
// file->Write("Run"); |
307 |
//newtree->Delete(); |
308 |
delete newver; |
309 |
delete newrun; |
310 |
delete oldver; |
311 |
delete oldrun; |
312 |
// |
313 |
return(0); |
314 |
// |
315 |
} else { |
316 |
// |
317 |
// temprfile = new TFile(temprname.str().c_str(),"READ"); |
318 |
// oldtree = (TTree*)temprfile->Get("Run-old"); |
319 |
// |
320 |
oldtree->SetBranchAddress("RunInfo",&oldrun); |
321 |
oldtree->SetBranchAddress("SoftInfo",&oldver); |
322 |
// |
323 |
totnorun = oldtree->GetEntries(); |
324 |
// |
325 |
runlist = new TArrayL((Int_t)totnorun); |
326 |
// |
327 |
found = false; |
328 |
// |
329 |
for ( UInt_t run = 0; run < totnorun; run++){ |
330 |
// |
331 |
oldtree->GetEntry(run); |
332 |
// |
333 |
newrun->ID = oldrun->ID; |
334 |
newrun->ID_REG_RUN = oldrun->ID_REG_RUN; |
335 |
newrun->ID_REG_RUN_L2 = oldrun->ID_REG_RUN_L2; |
336 |
newrun->RUNHEADER_TIME = oldrun->RUNHEADER_TIME; |
337 |
newrun->RUNTRAILER_TIME = oldrun->RUNTRAILER_TIME; |
338 |
newrun->EV_REG_PHYS_FROM = oldrun->EV_REG_PHYS_FROM; |
339 |
newrun->EV_REG_PHYS_TO = oldrun->EV_REG_PHYS_TO; |
340 |
newrun->EV_REG_RUNHEADER = oldrun->EV_REG_RUNHEADER; |
341 |
newrun->EV_REG_RUNTRAILER = oldrun->EV_REG_RUNTRAILER; |
342 |
newrun->TRK_CALIB_USED = oldrun->TRK_CALIB_USED; |
343 |
newrun->EFF_WRK_SCHEDULE = oldrun->EFF_WRK_SCHEDULE; |
344 |
newrun->PRH_VAR_TRG_MODE_A = oldrun->PRH_VAR_TRG_MODE_A; |
345 |
newrun->PRH_VAR_TRG_MODE_B = oldrun->PRH_VAR_TRG_MODE_B; |
346 |
newrun->ACQ_BUILD_INFO = oldrun->ACQ_BUILD_INFO; |
347 |
newrun->ACQ_VAR_INFO = oldrun->ACQ_VAR_INFO; |
348 |
newver->TRIG_ver = oldver->TRIG_ver; |
349 |
newver->TOF_ver = oldver->TOF_ver; |
350 |
newver->AC_ver = oldver->AC_ver; |
351 |
newver->TRK_ver = oldver->TRK_ver; |
352 |
newver->ORB_ver = oldver->ORB_ver; |
353 |
newver->CAL_ver = oldver->CAL_ver; |
354 |
newver->S4_ver = oldver->S4_ver; |
355 |
newver->ND_ver = oldver->ND_ver; |
356 |
// |
357 |
file_entries += (oldrun->EV_REG_PHYS_TO - oldrun->EV_REG_PHYS_FROM + 1); |
358 |
// |
359 |
if ( debug ) printf("totnorun %i idRun %i newrun->ID %i \n",(int)totnorun,(int)idRun,(int)newrun->ID); |
360 |
// |
361 |
if ( idRun == 0ULL || idRun == newrun->ID ) { |
362 |
// |
363 |
if ( debug ) printf(" Updating run number %llu \n",idRun); |
364 |
// |
365 |
found = true; |
366 |
// |
367 |
runlist->AddAt(newrun->ID,norun); |
368 |
norun++; |
369 |
// |
370 |
if ( !strcmp(Detector.Data(),"NONE") ){ |
371 |
// |
372 |
// update infromations querying the DB |
373 |
// |
374 |
error = Query_GL_RUN(newrun->ID, dbc); |
375 |
// |
376 |
if ( error ){ |
377 |
if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n"); |
378 |
return(error); |
379 |
}; |
380 |
// |
381 |
newrun->ID = ID; |
382 |
newrun->ID_REG_RUN = ID_REG_RUN; |
383 |
newrun->ID_REG_RUN_L2 = ID_REG_RUN_L2; |
384 |
newrun->RUNHEADER_TIME = RUNHEADER_TIME; |
385 |
newrun->RUNTRAILER_TIME = RUNTRAILER_TIME; |
386 |
newrun->EV_REG_PHYS_FROM = EV_REG_PHYS_FROM; |
387 |
newrun->EV_REG_PHYS_TO = EV_REG_PHYS_TO; |
388 |
newrun->EV_REG_RUNHEADER = EV_REG_RUNHEADER; |
389 |
newrun->EV_REG_RUNTRAILER = EV_REG_RUNTRAILER; |
390 |
newrun->TRK_CALIB_USED = TRK_CALIB_USED; |
391 |
newrun->EFF_WRK_SCHEDULE = EFF_WRK_SCHEDULE; |
392 |
newrun->PRH_VAR_TRG_MODE_A = PRH_VAR_TRG_MODE_A; |
393 |
newrun->PRH_VAR_TRG_MODE_B = PRH_VAR_TRG_MODE_B; |
394 |
newrun->ACQ_BUILD_INFO = ACQ_BUILD_INFO; |
395 |
newrun->ACQ_VAR_INFO = ACQ_VAR_INFO; |
396 |
} else { |
397 |
// |
398 |
if ( !strcmp(Detector.Data(),"TRIG") ){ |
399 |
newver->TRIG_ver = version->TRIG_ver; |
400 |
newver->TOF_ver = oldver->TOF_ver; |
401 |
newver->AC_ver = oldver->AC_ver; |
402 |
newver->TRK_ver = oldver->TRK_ver; |
403 |
newver->ORB_ver = oldver->ORB_ver; |
404 |
newver->CAL_ver = oldver->CAL_ver; |
405 |
newver->S4_ver = oldver->S4_ver; |
406 |
newver->ND_ver = oldver->ND_ver; |
407 |
if ( strcmp(oldver->TRIG_ver.Data(),"") ) reprocessing = true; |
408 |
}; |
409 |
if ( !strcmp(Detector.Data(),"TOF") ){ |
410 |
newver->TRIG_ver = oldver->TRIG_ver; |
411 |
newver->TOF_ver = version->TOF_ver; |
412 |
newver->AC_ver = oldver->AC_ver; |
413 |
newver->TRK_ver = oldver->TRK_ver; |
414 |
newver->ORB_ver = oldver->ORB_ver; |
415 |
newver->CAL_ver = oldver->CAL_ver; |
416 |
newver->S4_ver = oldver->S4_ver; |
417 |
newver->ND_ver = oldver->ND_ver; |
418 |
if ( strcmp(oldver->TOF_ver.Data(),"") ) reprocessing = true; |
419 |
}; |
420 |
if ( !strcmp(Detector.Data(),"AC") ){ |
421 |
newver->TRIG_ver = oldver->TRIG_ver; |
422 |
newver->TOF_ver = oldver->TOF_ver; |
423 |
newver->TRK_ver = oldver->TRK_ver; |
424 |
newver->ORB_ver = oldver->ORB_ver; |
425 |
newver->CAL_ver = oldver->CAL_ver; |
426 |
newver->S4_ver = oldver->S4_ver; |
427 |
newver->ND_ver = oldver->ND_ver; |
428 |
newver->AC_ver = version->AC_ver; |
429 |
if ( strcmp(oldver->AC_ver.Data(),"") ) reprocessing = true; |
430 |
}; |
431 |
if ( !strcmp(Detector.Data(),"TRK") ){ |
432 |
newver->TRIG_ver = oldver->TRIG_ver; |
433 |
newver->TOF_ver = oldver->TOF_ver; |
434 |
newver->CAL_ver = oldver->CAL_ver; |
435 |
newver->ORB_ver = oldver->ORB_ver; |
436 |
newver->S4_ver = oldver->S4_ver; |
437 |
newver->ND_ver = oldver->ND_ver; |
438 |
newver->AC_ver = oldver->AC_ver; |
439 |
newver->TRK_ver = version->TRK_ver; |
440 |
if ( strcmp(oldver->TRK_ver.Data(),"") ) reprocessing = true; |
441 |
}; |
442 |
if ( !strcmp(Detector.Data(),"ORB") ){ |
443 |
newver->TRIG_ver = oldver->TRIG_ver; |
444 |
newver->TOF_ver = oldver->TOF_ver; |
445 |
newver->CAL_ver = oldver->CAL_ver; |
446 |
newver->TRK_ver = oldver->TRK_ver; |
447 |
newver->S4_ver = oldver->S4_ver; |
448 |
newver->ND_ver = oldver->ND_ver; |
449 |
newver->AC_ver = oldver->AC_ver; |
450 |
newver->ORB_ver = version->ORB_ver; |
451 |
if ( strcmp(oldver->ORB_ver.Data(),"") ) reprocessing = true; |
452 |
}; |
453 |
if ( !strcmp(Detector.Data(),"CALO") ){ |
454 |
newver->TRIG_ver = oldver->TRIG_ver; |
455 |
newver->TOF_ver = oldver->TOF_ver; |
456 |
newver->S4_ver = oldver->S4_ver; |
457 |
newver->ORB_ver = oldver->ORB_ver; |
458 |
newver->ND_ver = oldver->ND_ver; |
459 |
newver->AC_ver = oldver->AC_ver; |
460 |
newver->TRK_ver = oldver->TRK_ver; |
461 |
newver->CAL_ver = version->CAL_ver; |
462 |
if ( strcmp(oldver->CAL_ver.Data(),"") ) reprocessing = true; |
463 |
}; |
464 |
if ( !strcmp(Detector.Data(),"S4") ){ |
465 |
newver->TRIG_ver = oldver->TRIG_ver; |
466 |
newver->TOF_ver = oldver->TOF_ver; |
467 |
newver->ND_ver = oldver->ND_ver; |
468 |
newver->AC_ver = oldver->AC_ver; |
469 |
newver->TRK_ver = oldver->TRK_ver; |
470 |
newver->ORB_ver = oldver->ORB_ver; |
471 |
newver->CAL_ver = oldver->CAL_ver; |
472 |
newver->S4_ver = version->S4_ver; |
473 |
if ( strcmp(oldver->S4_ver.Data(),"") ) reprocessing = true; |
474 |
}; |
475 |
if ( !strcmp(Detector.Data(),"ND") ){ |
476 |
newver->TRIG_ver = oldver->TRIG_ver; |
477 |
newver->TOF_ver = oldver->TOF_ver; |
478 |
newver->S4_ver = oldver->S4_ver; |
479 |
newver->AC_ver = oldver->AC_ver; |
480 |
newver->ORB_ver = oldver->ORB_ver; |
481 |
newver->TRK_ver = oldver->TRK_ver; |
482 |
newver->CAL_ver = oldver->CAL_ver; |
483 |
newver->ND_ver = version->ND_ver; |
484 |
if ( strcmp(oldver->ND_ver.Data(),"") ) reprocessing = true; |
485 |
}; |
486 |
}; |
487 |
// |
488 |
last_file_entry = first_file_entry + (oldrun->EV_REG_PHYS_TO - oldrun->EV_REG_PHYS_FROM + 1); |
489 |
// |
490 |
} else { |
491 |
if ( !found ) first_file_entry += (oldrun->EV_REG_PHYS_TO - oldrun->EV_REG_PHYS_FROM + 1); |
492 |
}; |
493 |
// |
494 |
file->cd(); |
495 |
newtree->Fill(); |
496 |
// |
497 |
}; |
498 |
// |
499 |
// temprfile->Close(); |
500 |
// gSystem->Unlink(temprname.str().c_str()); |
501 |
// if ( ismydir ) gSystem->Unlink(tempdir.str().c_str()); |
502 |
file->cd(); |
503 |
if ( oldtree ) oldtree->Delete("all"); |
504 |
newtree->SetName("Run"); |
505 |
// file->Write("Run"); |
506 |
// newtree->Delete(); |
507 |
delete newver; |
508 |
delete newrun; |
509 |
delete oldver; |
510 |
delete oldrun; |
511 |
// |
512 |
if ( !found ){ |
513 |
if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %llu \n",idRun); |
514 |
return(-5); |
515 |
}; |
516 |
// |
517 |
// newtree->Write(); |
518 |
}; |
519 |
return(0); |
520 |
} |
521 |
|
522 |
Int_t ItoRunInfo::Read(ULong64_t idRun){ |
523 |
// |
524 |
isreadonly = true; |
525 |
// |
526 |
Bool_t debug = false; |
527 |
// |
528 |
SoftInfo *newver = new SoftInfo(); |
529 |
GL_RUN *newrun = new GL_RUN(); |
530 |
// |
531 |
// Try to get the tree Run in the processed file |
532 |
// |
533 |
newtree = (TTree*)file->Get("Run"); |
534 |
// |
535 |
if ( !newtree ) { |
536 |
// |
537 |
printf("\n RUNINFO - ERROR: no RunInfo tree in Level2 file. \n"); |
538 |
return(-801); |
539 |
// |
540 |
} else { |
541 |
// |
542 |
printf(" RunInfo: opening RunInfo tree \n"); |
543 |
// |
544 |
newtree->SetBranchAddress("RunInfo",&newrun); |
545 |
newtree->SetBranchAddress("SoftInfo",&newver); |
546 |
// |
547 |
totnorun = newtree->GetEntries(); |
548 |
// |
549 |
runlist = new TArrayL((Int_t)totnorun); |
550 |
// |
551 |
first_file_entry = 0; |
552 |
// |
553 |
for ( UInt_t run = 0; run < totnorun; run++){ |
554 |
// |
555 |
newtree->GetEntry(run); |
556 |
// |
557 |
file_entries += (newrun->EV_REG_PHYS_TO - newrun->EV_REG_PHYS_FROM + 1); |
558 |
// |
559 |
if ( debug ) printf("totnorun %i newrun->ID %i \n",(int)totnorun,(int)newrun->ID); |
560 |
// |
561 |
ID = newrun->ID; |
562 |
ID_REG_RUN = newrun->ID_REG_RUN; |
563 |
ID_REG_RUN_L2 = newrun->ID_REG_RUN_L2; |
564 |
RUNHEADER_TIME = newrun->RUNHEADER_TIME; |
565 |
RUNTRAILER_TIME = newrun->RUNTRAILER_TIME; |
566 |
EV_REG_PHYS_FROM = newrun->EV_REG_PHYS_FROM; |
567 |
EV_REG_PHYS_TO = newrun->EV_REG_PHYS_TO; |
568 |
EV_REG_RUNHEADER = newrun->EV_REG_RUNHEADER; |
569 |
EV_REG_RUNTRAILER = newrun->EV_REG_RUNTRAILER; |
570 |
TRK_CALIB_USED = newrun->TRK_CALIB_USED; |
571 |
EFF_WRK_SCHEDULE = newrun->EFF_WRK_SCHEDULE; |
572 |
PRH_VAR_TRG_MODE_A = newrun->PRH_VAR_TRG_MODE_A; |
573 |
PRH_VAR_TRG_MODE_B = newrun->PRH_VAR_TRG_MODE_B; |
574 |
ACQ_BUILD_INFO = newrun->ACQ_BUILD_INFO; |
575 |
ACQ_VAR_INFO = newrun->ACQ_VAR_INFO; |
576 |
version->TRIG_ver = newver->TRIG_ver; |
577 |
version->TOF_ver = newver->TOF_ver; |
578 |
version->AC_ver = newver->AC_ver; |
579 |
version->TRK_ver = newver->TRK_ver; |
580 |
version->ORB_ver = newver->ORB_ver; |
581 |
version->CAL_ver = newver->CAL_ver; |
582 |
version->S4_ver = newver->S4_ver; |
583 |
version->ND_ver = newver->ND_ver; |
584 |
if ( idRun == ID || idRun == 0ULL ){ |
585 |
runlist->AddAt(newrun->ID,norun); |
586 |
norun++; |
587 |
}; |
588 |
last_file_entry = first_file_entry + (newrun->EV_REG_PHYS_TO - newrun->EV_REG_PHYS_FROM + 1); |
589 |
}; |
590 |
}; |
591 |
if ( debug ) printf("norun %i \n",(int)norun); |
592 |
Int_t error = 0; |
593 |
error = GetRunInfo(idRun); |
594 |
delete newver; |
595 |
delete newrun; |
596 |
if ( error ) return(error); |
597 |
return(0); |
598 |
} |
599 |
|
600 |
void ItoRunInfo::Close(){ |
601 |
reprocessing = false; |
602 |
updating = false; |
603 |
first_file_entry = 0; |
604 |
last_file_entry = 0; |
605 |
file_entries = 0ULL; |
606 |
norun = 0; |
607 |
runlist = new TArrayL(0,NULL); |
608 |
file = new TFile(); |
609 |
if ( isreadonly ) newtree->Delete(); |
610 |
} |
611 |
|
612 |
void ItoRunInfo::Clear(){ |
613 |
if ( newtree ) newtree->Delete(); |
614 |
} |
615 |
|
616 |
UInt_t ItoRunInfo::GetRunForEntry(UInt_t entry){ |
617 |
// |
618 |
UInt_t startfrom = 0; |
619 |
// |
620 |
if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ) return(ID); |
621 |
// |
622 |
if ( entry > (UInt_t)last_file_entry ){ |
623 |
for ( UInt_t nrun = 0; nrun < norun; nrun++){ |
624 |
if ( ID == (ULong64_t)runlist->At(nrun) ) { |
625 |
startfrom = nrun+1; |
626 |
break; |
627 |
}; |
628 |
}; |
629 |
} else { |
630 |
startfrom = 0; |
631 |
}; |
632 |
// |
633 |
if ( startfrom >= norun ) startfrom = 0; |
634 |
// |
635 |
retry: |
636 |
// |
637 |
for ( UInt_t nrun = startfrom; nrun < norun; nrun++){ |
638 |
GetRunInfo((ULong64_t)runlist->At(nrun)); |
639 |
if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ){ |
640 |
return((UInt_t)runlist->At(nrun)); |
641 |
}; |
642 |
}; |
643 |
if ( startfrom ){ |
644 |
startfrom = 0; |
645 |
goto retry; |
646 |
}; |
647 |
printf(" ERROR! run not found \n"); |
648 |
return(0); |
649 |
} |
650 |
|
651 |
Int_t ItoRunInfo::GetRunInfo(ULong64_t run){ |
652 |
Bool_t found = false; |
653 |
SoftInfo *nwver = new SoftInfo(); |
654 |
GL_RUN *nwrun = new GL_RUN(); |
655 |
// |
656 |
newtree->SetBranchAddress("RunInfo",&nwrun); |
657 |
newtree->SetBranchAddress("SoftInfo",&nwver); |
658 |
// |
659 |
last_file_entry = 0; |
660 |
first_file_entry = 0; |
661 |
// |
662 |
totnorun = newtree->GetEntries(); |
663 |
// |
664 |
for ( UInt_t nrun = 0; nrun < totnorun; nrun++){ |
665 |
newtree->GetEntry(nrun); |
666 |
// |
667 |
if ( nwrun->ID == run || run == 0ULL ){ |
668 |
ID = nwrun->ID; |
669 |
ID_REG_RUN = nwrun->ID_REG_RUN; |
670 |
ID_REG_RUN_L2 = nwrun->ID_REG_RUN_L2; |
671 |
RUNHEADER_TIME = nwrun->RUNHEADER_TIME; |
672 |
RUNTRAILER_TIME = nwrun->RUNTRAILER_TIME; |
673 |
EV_REG_PHYS_FROM = nwrun->EV_REG_PHYS_FROM; |
674 |
EV_REG_PHYS_TO = nwrun->EV_REG_PHYS_TO; |
675 |
EV_REG_RUNHEADER = nwrun->EV_REG_RUNHEADER; |
676 |
EV_REG_RUNTRAILER = nwrun->EV_REG_RUNTRAILER; |
677 |
TRK_CALIB_USED = nwrun->TRK_CALIB_USED; |
678 |
EFF_WRK_SCHEDULE = nwrun->EFF_WRK_SCHEDULE; |
679 |
PRH_VAR_TRG_MODE_A = nwrun->PRH_VAR_TRG_MODE_A; |
680 |
PRH_VAR_TRG_MODE_B = nwrun->PRH_VAR_TRG_MODE_B; |
681 |
ACQ_BUILD_INFO = nwrun->ACQ_BUILD_INFO; |
682 |
ACQ_VAR_INFO = nwrun->ACQ_VAR_INFO; |
683 |
version->TRIG_ver = nwver->TRIG_ver; |
684 |
version->TOF_ver = nwver->TOF_ver; |
685 |
version->AC_ver = nwver->AC_ver; |
686 |
version->TRK_ver = nwver->TRK_ver; |
687 |
version->ORB_ver = nwver->ORB_ver; |
688 |
version->CAL_ver = nwver->CAL_ver; |
689 |
version->S4_ver = nwver->S4_ver; |
690 |
version->ND_ver = nwver->ND_ver; |
691 |
found = true; |
692 |
last_file_entry = first_file_entry + (nwrun->EV_REG_PHYS_TO - nwrun->EV_REG_PHYS_FROM + 1); |
693 |
}; |
694 |
if ( !found ) first_file_entry += (nwrun->EV_REG_PHYS_TO - nwrun->EV_REG_PHYS_FROM + 1); |
695 |
}; |
696 |
delete nwver; |
697 |
delete nwrun; |
698 |
if ( found ) return(0); |
699 |
return(-800); |
700 |
} |
701 |
|