1 |
// |
2 |
// C/C++ headers |
3 |
// |
4 |
#include <fstream> |
5 |
#include <string.h> |
6 |
// |
7 |
// ROOT headers |
8 |
// |
9 |
#include <TTree.h> |
10 |
#include <TClassEdit.h> |
11 |
#include <TObject.h> |
12 |
#include <TList.h> |
13 |
#include <TArrayI.h> |
14 |
#include <TSystem.h> |
15 |
#include <TSystemDirectory.h> |
16 |
#include <TString.h> |
17 |
#include <TFile.h> |
18 |
#include <TClass.h> |
19 |
#include <TCanvas.h> |
20 |
#include <TH1.h> |
21 |
#include <TH1F.h> |
22 |
#include <TH2D.h> |
23 |
#include <TLatex.h> |
24 |
#include <TPad.h> |
25 |
#include <TSQLServer.h> |
26 |
#include <TSQLRow.h> |
27 |
#include <TSQLResult.h> |
28 |
//#include <TClonesArray.h> |
29 |
// |
30 |
// RunInfo header |
31 |
// |
32 |
#include <RunInfo.h> |
33 |
// |
34 |
// YODA headers |
35 |
// |
36 |
#include <PamelaRun.h> |
37 |
#include <physics/trigger/TriggerEvent.h> |
38 |
#include <physics/anticounter/AnticounterEvent.h> |
39 |
// |
40 |
// RunInfo header |
41 |
// |
42 |
//#include <RunInfo.h> |
43 |
// |
44 |
// This program headers |
45 |
// |
46 |
#include <AcCore.h> |
47 |
#include <AcLevel2.h> |
48 |
#include <AcVerl2.h> |
49 |
// |
50 |
using namespace std; |
51 |
// |
52 |
// CORE ROUTINE |
53 |
// |
54 |
// |
55 |
int AcCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t Acargc, char *Acargv[]){ |
56 |
Int_t i = 0; |
57 |
Bool_t verbose = false; |
58 |
Bool_t debug = false; |
59 |
// |
60 |
TString processFolder = Form("AcFolder_%u",run); |
61 |
if ( Acargc > 0 ){ |
62 |
i = 0; |
63 |
while ( i < Acargc ){ |
64 |
if ( !strcmp(Acargv[i],"-processFolder") ) { |
65 |
if ( Acargc < i+1 ){ |
66 |
throw -3; |
67 |
}; |
68 |
processFolder = (TString)Acargv[i+1]; |
69 |
i++; |
70 |
}; |
71 |
if ( !strcmp(Acargv[i],"-v") || !strcmp(Acargv[i],"--verbose") ) { |
72 |
verbose = true; |
73 |
}; |
74 |
if ( !strcmp(Acargv[i],"-g") || !strcmp(Acargv[i],"--debug") ) { |
75 |
verbose = true; |
76 |
debug = true; |
77 |
}; |
78 |
i++; |
79 |
}; |
80 |
}; |
81 |
// |
82 |
// Set these to true to have a very verbose output. |
83 |
// |
84 |
// |
85 |
// Output directory is the working directoy. |
86 |
// |
87 |
const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
88 |
// |
89 |
// Variables for level2 |
90 |
// |
91 |
TTree *ac = 0; |
92 |
UInt_t nevents = 0; |
93 |
// |
94 |
// variables needed to reprocess data |
95 |
// |
96 |
TString acversion; |
97 |
ItoRunInfo *runinfo = 0; |
98 |
TArrayI *runlist = 0; |
99 |
TTree *acclone = 0; |
100 |
Bool_t reproc = false; |
101 |
Bool_t reprocall = false; |
102 |
UInt_t nobefrun = 0; |
103 |
UInt_t noaftrun = 0; |
104 |
UInt_t numbofrun = 0; |
105 |
stringstream ftmpname; |
106 |
TString fname; |
107 |
UInt_t totfileentries = 0; |
108 |
UInt_t idRun = 0; |
109 |
// |
110 |
// variables needed to handle error signals |
111 |
// |
112 |
Int_t code = 0; |
113 |
Int_t sgnl; |
114 |
// |
115 |
// anticounter level2 classes |
116 |
// |
117 |
AcLevel2 *acl2 = new AcLevel2(); |
118 |
AcLevel2 *acl2clone = new AcLevel2(); |
119 |
// note: the string "mydect" is now "ac", "mydetector" is "anticounter" (mydectversion -> acversion, mydectclone -> acclone); |
120 |
// the string "mydec" (without t) -> acl2 (acl2, acl2clone) |
121 |
// |
122 |
// define variables for opening and reading level0 file |
123 |
// |
124 |
TFile *l0File = 0; |
125 |
TTree *l0tr = 0; |
126 |
TBranch *l0head = 0; |
127 |
TBranch *l0ac = 0; |
128 |
pamela::EventHeader *eh = 0; |
129 |
pamela::PscuHeader *ph = 0; |
130 |
pamela::anticounter::AnticounterEvent *acc = 0; |
131 |
// |
132 |
// Define other basic variables |
133 |
// |
134 |
UInt_t procev = 0; |
135 |
stringstream file2; |
136 |
stringstream file3; |
137 |
stringstream qy; |
138 |
Int_t totevent = 0; |
139 |
UInt_t atime = 0; |
140 |
UInt_t re = 0; |
141 |
// |
142 |
// Working filename |
143 |
// |
144 |
TString outputfile; |
145 |
stringstream name; |
146 |
name.str(""); |
147 |
name << outdir << "/"; |
148 |
// |
149 |
// temporary file and folder |
150 |
// |
151 |
TFile *tempfile = 0; |
152 |
TTree *tempac = 0; |
153 |
stringstream tempname; |
154 |
stringstream acfolder; |
155 |
Bool_t myfold = false; |
156 |
tempname.str(""); |
157 |
tempname << outdir; |
158 |
tempname << "/" << processFolder.Data(); |
159 |
acfolder.str(""); |
160 |
acfolder << tempname.str().c_str(); |
161 |
tempname << "/ac2tree_run"; |
162 |
tempname << run << ".root"; |
163 |
UInt_t totnorun = 0; |
164 |
// |
165 |
// DB classes |
166 |
// |
167 |
GL_ROOT *glroot = new GL_ROOT(); |
168 |
GL_TIMESYNC *dbtime = 0; |
169 |
// |
170 |
UShort_t CRCcheck[2]= {0,0}; |
171 |
UShort_t Status[2]= {0,0}; |
172 |
UShort_t Hitmap[2]= {0,0}; |
173 |
UShort_t Hitstatus[2]= {0,0}; |
174 |
UShort_t Trigger[2] = {0,0}; |
175 |
UShort_t Trigg_old[2] = {0,0}; |
176 |
UShort_t Counter[2][16]; |
177 |
UShort_t Counter_old[2][16]; |
178 |
UShort_t Shift[2][16]; |
179 |
Int_t vec[2][16][16]; |
180 |
Int_t tmp = 0; |
181 |
memset(vec, 0, 2*16*16*sizeof(UShort_t)); |
182 |
memset(Shift, 0, 2*16*sizeof(UShort_t)); |
183 |
memset(Counter, 0, 2*16*sizeof(UShort_t)); |
184 |
memset(Counter_old, 0, 2*16*sizeof(UShort_t)); |
185 |
// |
186 |
Long64_t maxsize = 10000000000LL; |
187 |
TTree::SetMaxTreeSize(maxsize); |
188 |
// |
189 |
// |
190 |
// Let's start! |
191 |
// |
192 |
// |
193 |
// As a first thing we must check what we have to do: if run = 0 we must process all events in the file has been passed |
194 |
// if run != 0 we must process only that run but first we have to check if the tree Anticounter already exist in the file |
195 |
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
196 |
// |
197 |
if ( run == 0 ) reproc = true; |
198 |
// |
199 |
// Output file is "outputfile" |
200 |
// |
201 |
outputfile = name.str().c_str(); |
202 |
if ( verbose ) printf("\n Output filename is: \n %s \n\n",outputfile.Data()); |
203 |
// |
204 |
// |
205 |
if ( !file->IsOpen() ){ |
206 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: cannot open file for writing\n"); |
207 |
throw -701; |
208 |
}; |
209 |
// |
210 |
// Retrieve GL_RUN variables from the level2 file |
211 |
// |
212 |
acversion = AcInfo(false); // we should decide how to handle versioning system |
213 |
// |
214 |
// create an interface to RunInfo called "runinfo" |
215 |
// |
216 |
runinfo = new ItoRunInfo(file); |
217 |
// |
218 |
// open "Run" tree in level2 file, if not existing return an error (sngl != 0) |
219 |
// |
220 |
sgnl = 0; |
221 |
sgnl = runinfo->Update(run,"AC",acversion); |
222 |
if ( sgnl ){ |
223 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: RunInfo exited with non-zero status\n"); |
224 |
code = sgnl; |
225 |
goto closeandexit; |
226 |
} else { |
227 |
sgnl = 0; |
228 |
}; |
229 |
// |
230 |
// number of events in the file BEFORE the first event of our run |
231 |
// |
232 |
nobefrun = runinfo->GetFirstEntry(); |
233 |
// |
234 |
// total number of events in the file |
235 |
// |
236 |
totfileentries = runinfo->GetFileEntries(); |
237 |
// |
238 |
// first file entry AFTER the last event of our run |
239 |
// |
240 |
noaftrun = runinfo->GetLastEntry() + 1; |
241 |
// |
242 |
// number of run to be processed |
243 |
// |
244 |
numbofrun = runinfo->GetNoRun(); |
245 |
totnorun = runinfo->GetRunEntries(); |
246 |
// |
247 |
// Try to access the Anticounter tree in the file, if it exists we are reprocessing data if not we are processing a new run |
248 |
// |
249 |
acclone = (TTree*)file->Get("Anticounter"); |
250 |
// |
251 |
if ( !acclone ){ |
252 |
// |
253 |
// tree does not exist, we are not reprocessing |
254 |
// |
255 |
reproc = false; |
256 |
if ( run == 0 && verbose ) printf(" ANTICOUNTER - WARNING: you are reprocessing data but AC tree does not exist!\n"); |
257 |
if ( verbose && runinfo->IsReprocessing() && run != 0 ) printf(" ANTICOUNTER - WARNING: it seems you are not reprocessing data but Anticounter\n versioning information already exists in RunInfo.\n"); |
258 |
|
259 |
} else { |
260 |
// |
261 |
// tree exists, we are reprocessing data. Are we reprocessing a single run or all the file? |
262 |
// |
263 |
acclone->SetAutoSave(900000000000000LL); |
264 |
reproc = true; |
265 |
// |
266 |
// |
267 |
if ( verbose ) printf("\n Preparing the pre-processing...\n"); |
268 |
// |
269 |
if ( run == 0 || totnorun == 1 ){ |
270 |
// |
271 |
// we are reprocessing all the file |
272 |
// if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately |
273 |
// |
274 |
reprocall = true; |
275 |
// |
276 |
if ( verbose ) printf("\n ANTICOUNTER - WARNING: Reprocessing all runs\n"); |
277 |
// |
278 |
} else { |
279 |
// |
280 |
// we are reprocessing a single run, we must copy to the new tree the events in the file which preceed the first event of the run |
281 |
// |
282 |
reprocall = false; |
283 |
// |
284 |
if ( verbose ) printf("\n ANTICOUNTER - WARNING: Reprocessing run number %u \n",run); |
285 |
// |
286 |
// copying old tree to a new file |
287 |
// |
288 |
gSystem->MakeDirectory(acfolder.str().c_str()); |
289 |
myfold = true; |
290 |
tempfile = new TFile(tempname.str().c_str(),"RECREATE"); |
291 |
tempac = acclone->CloneTree(-1,"fast"); |
292 |
tempac->SetName("Anticounter-old"); |
293 |
tempfile->Write(); |
294 |
tempfile->Close(); |
295 |
} |
296 |
// |
297 |
// Delete the old tree from old file and memory |
298 |
// |
299 |
acclone->Delete("all"); |
300 |
// |
301 |
if ( verbose ) printf(" ...done!\n"); |
302 |
// |
303 |
}; |
304 |
// |
305 |
// create anticounter tree ac |
306 |
// |
307 |
file->cd(); |
308 |
ac = new TTree("Anticounter-new","PAMELA Level2 Anticounter data"); |
309 |
ac->SetAutoSave(900000000000000LL); |
310 |
ac->Branch("AcLevel2","AcLevel2",&acl2); |
311 |
// |
312 |
if ( reproc && !reprocall ){ |
313 |
// |
314 |
// open new file and retrieve alo tree informations |
315 |
// |
316 |
tempfile = new TFile(tempname.str().c_str(),"READ"); |
317 |
acclone = (TTree*)tempfile->Get("Anticounter-old"); |
318 |
acclone->SetAutoSave(900000000000000LL); |
319 |
acclone->SetBranchAddress("AcLevel2",&acl2clone); |
320 |
// |
321 |
if ( nobefrun > 0 ){ |
322 |
if ( verbose ) { |
323 |
printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
324 |
printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run); |
325 |
printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); |
326 |
}; |
327 |
for (UInt_t j = 0; j < nobefrun; j++){ |
328 |
// |
329 |
if ( acclone->GetEntry(j) <=0 ) throw -36; |
330 |
// |
331 |
// copy acl2clone to acl2 |
332 |
// |
333 |
// acl2->Clear(); |
334 |
// |
335 |
memcpy(&acl2,&acl2clone,sizeof(acl2clone)); |
336 |
// |
337 |
// Fill entry in the new tree |
338 |
// |
339 |
ac->Fill(); |
340 |
// |
341 |
}; |
342 |
if ( verbose ) printf(" Finished successful copying!\n"); |
343 |
}; |
344 |
}; |
345 |
// |
346 |
// Get the list of run to be processed, if only one run has to be processed the list will contain one entry only. |
347 |
// |
348 |
runlist = runinfo->GetRunList(); |
349 |
// |
350 |
// Loop over the run to be processed |
351 |
// |
352 |
for (UInt_t irun=0; irun < numbofrun; irun++){ |
353 |
// |
354 |
// retrieve the first run ID to be processed using the RunInfo list |
355 |
// |
356 |
idRun = runlist->At(irun); |
357 |
if ( verbose ){ |
358 |
printf("\n\n\n ####################################################################### \n"); |
359 |
printf(" PROCESSING RUN NUMBER %u \n",idRun); |
360 |
printf(" ####################################################################### \n\n\n"); |
361 |
}; |
362 |
// |
363 |
runinfo->ID_ROOT_L0 = 0; |
364 |
// |
365 |
// store in the runinfo class the GL_RUN variables for our run |
366 |
// |
367 |
sgnl = 0; |
368 |
sgnl = runinfo->GetRunInfo(idRun); |
369 |
if ( sgnl ){ |
370 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: RunInfo exited with non-zero status\n"); |
371 |
code = sgnl; |
372 |
goto closeandexit; |
373 |
} else { |
374 |
sgnl = 0; |
375 |
}; |
376 |
// |
377 |
// now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0 |
378 |
// |
379 |
if ( runinfo->ID_ROOT_L0 == 0 ){ |
380 |
if ( verbose ) printf("\n ANTICOUNTER - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun); |
381 |
code = -5; |
382 |
goto closeandexit; |
383 |
}; |
384 |
// |
385 |
// prepare the timesync for the db |
386 |
// |
387 |
TString host = glt->CGetHost(); |
388 |
TString user = glt->CGetUser(); |
389 |
TString psw = glt->CGetPsw(); |
390 |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
391 |
if ( !dbc->IsConnected() ) throw -705; |
392 |
stringstream myquery; |
393 |
myquery.str(""); |
394 |
myquery << "SET time_zone='+0:00';"; |
395 |
delete dbc->Query(myquery.str().c_str()); |
396 |
delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"); |
397 |
|
398 |
dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc); |
399 |
// |
400 |
// Search in the DB the path and name of the LEVEL0 file to be processed. |
401 |
// |
402 |
// if ( !dbc->IsConnected() ) throw -705; |
403 |
glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc); |
404 |
// |
405 |
ftmpname.str(""); |
406 |
ftmpname << glroot->PATH.Data() << "/"; |
407 |
ftmpname << glroot->NAME.Data(); |
408 |
fname = ftmpname.str().c_str(); |
409 |
// |
410 |
// print out informations |
411 |
// |
412 |
totevent = runinfo->NEVENTS; |
413 |
if ( verbose ) { |
414 |
printf("\n LEVEL0 data file: %s \n",fname.Data()); |
415 |
printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME); |
416 |
printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME); |
417 |
printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM,runinfo->EV_FROM+totevent); |
418 |
}; |
419 |
// |
420 |
// if ( !totevent ) goto closeandexit; |
421 |
// |
422 |
// Open Level0 file |
423 |
// |
424 |
if ( l0File ) l0File->Close(); |
425 |
l0File = new TFile(fname.Data()); |
426 |
if ( !l0File ) { |
427 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: problems opening Level0 file\n"); |
428 |
code = -6; |
429 |
goto closeandexit; |
430 |
}; |
431 |
l0tr = (TTree*)l0File->Get("Physics"); |
432 |
if ( !l0tr ) { |
433 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: no Physics tree in Level0 file\n"); |
434 |
l0File->Close(); |
435 |
code = -7; |
436 |
goto closeandexit; |
437 |
}; |
438 |
l0head = l0tr->GetBranch("Header"); |
439 |
if ( !l0head ) { |
440 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: no Header branch in Level0 tree\n"); |
441 |
l0File->Close(); |
442 |
code = -8; |
443 |
goto closeandexit; |
444 |
}; |
445 |
l0ac = l0tr->GetBranch("Anticounter"); |
446 |
if ( !l0ac ) { |
447 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: no Anticounter branch in Level0 tree\n"); |
448 |
l0File->Close(); |
449 |
code = -704; |
450 |
goto closeandexit; |
451 |
}; |
452 |
// |
453 |
l0tr->SetBranchAddress("Anticounter", &acc); |
454 |
l0tr->SetBranchAddress("Header", &eh); |
455 |
// |
456 |
nevents = l0ac->GetEntries(); |
457 |
// |
458 |
if ( nevents < 1 && totevent ) { |
459 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: Level0 file is empty\n\n"); |
460 |
l0File->Close(); |
461 |
code = -11; |
462 |
goto closeandexit; |
463 |
}; |
464 |
// |
465 |
if ( runinfo->EV_TO > nevents-1 && totevent ) { |
466 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: too few entries in the tree\n"); |
467 |
l0File->Close(); |
468 |
code = -12; |
469 |
goto closeandexit; |
470 |
}; |
471 |
// |
472 |
// run over all the events of the run |
473 |
// |
474 |
if ( dbc ){ |
475 |
dbc->Close(); |
476 |
delete dbc; |
477 |
dbc = 0; |
478 |
}; |
479 |
// |
480 |
if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n"); |
481 |
// |
482 |
memset(Counter, 0, 2*16*sizeof(UShort_t)); |
483 |
memset(Counter_old, 0, 2*16*sizeof(UShort_t)); |
484 |
memset(Trigger, 0, 2*sizeof(UShort_t)); |
485 |
memset(Trigg_old, 0, 2*sizeof(UShort_t)); |
486 |
// |
487 |
for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ |
488 |
// |
489 |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
490 |
// |
491 |
if ( l0head->GetEntry(re) <= 0 ) throw -36; |
492 |
// |
493 |
// absolute time of this event |
494 |
// |
495 |
ph = eh->GetPscuHeader(); |
496 |
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
497 |
// |
498 |
// paranoid check |
499 |
// |
500 |
if ( atime > (runinfo->RUNTRAILER_TIME+1) || atime < (runinfo->RUNHEADER_TIME-1) ) { |
501 |
if ( verbose ) printf(" ANTICOUNTER - WARNING: event at time outside the run time window, skipping it atime %u TR %u HE %u \n",atime,runinfo->RUNTRAILER_TIME,runinfo->RUNHEADER_TIME); |
502 |
if ( verbose || debug ) printf(" %u %u %u %u \n",dbtime->GetTimesync(),dbtime->GetObt0(),dbtime->GetT0(),dbtime->GetType()); |
503 |
goto jumpev; |
504 |
}; |
505 |
// |
506 |
procev++; |
507 |
// |
508 |
// start processing |
509 |
// |
510 |
acl2->Clear(); |
511 |
// |
512 |
if ( l0ac->GetEntry(re) <= 0 ) throw -36; |
513 |
// |
514 |
/***********************************************/ |
515 |
// Here starts Anticounter specific code (Silvio) |
516 |
// |
517 |
memset(vec, 0, 2*16*16*sizeof(UShort_t)); |
518 |
memset(Shift, 0, 2*16*sizeof(UShort_t)); |
519 |
memset(CRCcheck, 0, 2*sizeof(UShort_t)); |
520 |
memset(Status, 0, 2*sizeof(UShort_t)); |
521 |
memset(Hitmap, 0, 2*sizeof(UShort_t)); |
522 |
memset(Hitstatus, 0, 2*sizeof(UShort_t)); |
523 |
tmp = 0; |
524 |
// |
525 |
for(Int_t gg = 0; gg < 2; gg++) |
526 |
{ |
527 |
Hitstatus[gg] = 0; |
528 |
} |
529 |
// |
530 |
//fetch data |
531 |
// |
532 |
for(Int_t kk = 0; kk < 2; kk++) |
533 |
{ |
534 |
if(re>0) |
535 |
{ |
536 |
Trigg_old[kk] = Trigger[kk]; |
537 |
for(Int_t jj = 0; jj < 16; jj++) |
538 |
Counter_old[kk][jj] = Counter[kk][jj]; |
539 |
} |
540 |
|
541 |
for(Int_t jj = 0; jj < 16; jj++) |
542 |
{ |
543 |
Counter[kk][jj] = acc->counters[kk][jj]; |
544 |
Shift[kk][jj] = acc->shift[kk][jj]; |
545 |
} |
546 |
Status[kk] = acc->status[kk]; |
547 |
Hitmap[kk] = acc->hitmap[kk]; |
548 |
Trigger[kk] = acc->trigg[kk]; |
549 |
CRCcheck[kk] = acc->CRCcheck[kk]; |
550 |
} |
551 |
|
552 |
/***********************************************/ |
553 |
//process data |
554 |
/***********************************************/ |
555 |
//shiftregisters |
556 |
for(Int_t b = 0; b < 2; b++){ //card |
557 |
for(Int_t k = 0; k < 16; k++){ //shift register |
558 |
Int_t cnt=1; |
559 |
for(Int_t l = 0; l < 16; l++){ //bin |
560 |
tmp = ((Shift[b][k] & cnt) > 0 ? 1 : 0); |
561 |
vec[b][k][l]=tmp; |
562 |
cnt=cnt<<1; |
563 |
} |
564 |
//cnt=1; |
565 |
} |
566 |
} |
567 |
// |
568 |
//fill Level1 file |
569 |
/************************************************/ |
570 |
for(Int_t s = 0; s < 2; s++) { |
571 |
acl2->hitmap[s] = Hitmap[s]; |
572 |
acl2->trigger[s] = Trigger[s]; |
573 |
Int_t cnt=1; |
574 |
for(Int_t k = 0; k < 16; k++) { |
575 |
for(Int_t bin = 5; bin < 9; bin++) { //acceptance window |
576 |
if(vec[s][bin][k]==1) |
577 |
Hitstatus[s] = Hitstatus[s] | cnt; |
578 |
} |
579 |
cnt=cnt<<1; |
580 |
} |
581 |
acl2->hitstatus[s] = Hitstatus[s]; |
582 |
// |
583 |
//Status |
584 |
/****************************************/ |
585 |
if(s==0){ |
586 |
if(Trigger[0] != (Trigg_old[0]+1)) |
587 |
acl2->status[0] = acl2->status[0] | 0x1; |
588 |
if((Status[0] & 0x001F) < 0x001F) |
589 |
acl2->status[0] = acl2->status[0] | 0x2; |
590 |
if(CRCcheck[0] == 0) |
591 |
acl2->status[0] = acl2->status[0] | 0x4; |
592 |
for(Int_t gg = 0; gg < 16; gg++){ |
593 |
if((Counter[0][gg] == Counter_old[0][gg]) && re>0 && Counter[0][gg] !=0) |
594 |
{ |
595 |
acl2->status[0] = acl2->status[0] | 0x8; |
596 |
} |
597 |
|
598 |
} |
599 |
} |
600 |
else { |
601 |
if(Trigger[1] != (Trigg_old[1]+2)) // this is not working (always true the if condition) |
602 |
acl2->status[1] = acl2->status[1] | 0x1; |
603 |
if((Status[1] & 0x001F) < 0x001F) |
604 |
acl2->status[1] = acl2->status[1] | 0x2; |
605 |
if(CRCcheck[1] == 0) |
606 |
acl2->status[1] = acl2->status[1] | 0x4; |
607 |
for(Int_t gg = 0; gg < 16; gg++){ |
608 |
if((Counter[1][gg] == Counter_old[1][gg]) && re>0 && Counter[1][gg] !=0) |
609 |
{ |
610 |
acl2->status[1] = acl2->status[1] | 0x8 ; |
611 |
} |
612 |
} |
613 |
} |
614 |
} |
615 |
// |
616 |
// End Anticounter specific code |
617 |
// |
618 |
/************************************************/ |
619 |
acl2->unpackError = acc->unpackError; |
620 |
// |
621 |
// Fill the rootple |
622 |
// |
623 |
ac->Fill(); |
624 |
// |
625 |
// |
626 |
jumpev: |
627 |
debug = false; |
628 |
// |
629 |
}; |
630 |
// |
631 |
// Here you may want to clear some variables before processing another run |
632 |
// |
633 |
delete dbtime; |
634 |
}; // process all the runs |
635 |
// |
636 |
if ( verbose ) printf("\n Finished processing data \n"); |
637 |
// |
638 |
closeandexit: |
639 |
// |
640 |
// we have finished processing the run(s). If we processed a single run now we must copy all the events after our run from the old tree to the new one and delete the old tree. |
641 |
// |
642 |
if ( !reprocall && reproc && code >= 0 ){ |
643 |
if ( totfileentries > noaftrun ){ |
644 |
if ( verbose ){ |
645 |
printf("\n Post-processing: copying events from the old tree after the processed run\n"); |
646 |
printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run); |
647 |
printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries); |
648 |
}; |
649 |
for (UInt_t j = noaftrun; j < totfileentries; j++ ){ |
650 |
// |
651 |
// Get entry from old tree |
652 |
// |
653 |
if ( acclone->GetEntry(j) <= 0 ) throw -36; |
654 |
// |
655 |
// copy acl2clone to acl2 |
656 |
// |
657 |
// acl2->Clear(); |
658 |
memcpy(&acl2,&acl2clone,sizeof(acl2clone)); |
659 |
// |
660 |
// Fill entry in the new tree |
661 |
// |
662 |
ac->Fill(); |
663 |
}; |
664 |
if ( verbose ) printf(" Finished successful copying!\n"); |
665 |
}; |
666 |
}; |
667 |
// |
668 |
// Close files, delete old tree(s), write and close level2 file |
669 |
// |
670 |
if ( l0File ) l0File->Close(); |
671 |
if ( tempfile ) tempfile->Close(); |
672 |
if ( myfold ) gSystem->Unlink(tempname.str().c_str()); |
673 |
// |
674 |
if ( code < 0 && verbose ) printf("\n ANTICOUNTER - ERROR: an error occurred, try to save anyway...\n"); |
675 |
if ( verbose ) printf("\n Writing and closing rootple\n"); |
676 |
if ( ac ) ac->SetName("Anticounter"); |
677 |
if ( file ){ |
678 |
file->cd(); |
679 |
if ( ac ) ac->Write("Anticounter",TObject::kOverwrite); // 10 RED bug fixed |
680 |
}; |
681 |
// |
682 |
if ( myfold ) gSystem->Unlink(acfolder.str().c_str()); |
683 |
// |
684 |
// the end |
685 |
// |
686 |
if ( verbose ) printf("\n Exiting...\n"); |
687 |
// |
688 |
if ( glroot ) delete glroot; |
689 |
if ( runinfo ) runinfo->Close(); |
690 |
if ( runinfo ) delete runinfo; |
691 |
// |
692 |
if(code < 0) throw code; |
693 |
return(code); |
694 |
} |
695 |
|
696 |
|