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