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