86 |
// |
// |
87 |
const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
88 |
// |
// |
89 |
// Variables for level2 |
// Variables for level2 |
90 |
// |
// |
91 |
TTree *ac = 0; |
TTree *ac = 0; |
92 |
UInt_t nevents = 0; |
UInt_t nevents = 0; |
130 |
pamela::anticounter::AnticounterEvent *acc = 0; |
pamela::anticounter::AnticounterEvent *acc = 0; |
131 |
// |
// |
132 |
// Define other basic variables |
// Define other basic variables |
133 |
// |
// |
134 |
UInt_t procev = 0; |
UInt_t procev = 0; |
135 |
stringstream file2; |
stringstream file2; |
136 |
stringstream file3; |
stringstream file3; |
159 |
acfolder.str(""); |
acfolder.str(""); |
160 |
acfolder << tempname.str().c_str(); |
acfolder << tempname.str().c_str(); |
161 |
tempname << "/ac2tree_run"; |
tempname << "/ac2tree_run"; |
162 |
tempname << run << ".root"; |
tempname << run << ".root"; |
163 |
// |
// |
164 |
// DB classes |
// DB classes |
165 |
// |
// |
182 |
memset(Counter, 0, 2*16*sizeof(UShort_t)); |
memset(Counter, 0, 2*16*sizeof(UShort_t)); |
183 |
memset(Counter_old, 0, 2*16*sizeof(UShort_t)); |
memset(Counter_old, 0, 2*16*sizeof(UShort_t)); |
184 |
// |
// |
185 |
Long64_t maxsize = 10000000000LL; |
Long64_t maxsize = 10000000000LL; |
186 |
TTree::SetMaxTreeSize(maxsize); |
TTree::SetMaxTreeSize(maxsize); |
187 |
// |
// |
188 |
// |
// |
192 |
// 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 |
// 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 |
193 |
// if run != 0 we must process only that run but first we have to check if the tree Anticounter already exist in the file |
// if run != 0 we must process only that run but first we have to check if the tree Anticounter already exist in the file |
194 |
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
195 |
// |
// |
196 |
if ( run == 0 ) reproc = true; |
if ( run == 0 ) reproc = true; |
197 |
// |
// |
198 |
// Output file is "outputfile" |
// Output file is "outputfile" |
199 |
// |
// |
200 |
outputfile = name.str().c_str(); |
outputfile = name.str().c_str(); |
201 |
if ( verbose ) printf("\n Output filename is: \n %s \n\n",outputfile.Data()); |
if ( verbose ) printf("\n Output filename is: \n %s \n\n",outputfile.Data()); |
202 |
// |
// |
203 |
// |
// |
204 |
if ( !file->IsOpen() ){ |
if ( !file->IsOpen() ){ |
205 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: cannot open file for writing\n"); |
if ( verbose ) printf(" ANTICOUNTER - ERROR: cannot open file for writing\n"); |
206 |
throw -701; |
throw -701; |
207 |
}; |
}; |
208 |
// |
// |
209 |
// Retrieve GL_RUN variables from the level2 file |
// Retrieve GL_RUN variables from the level2 file |
210 |
// |
// |
211 |
acversion = AcInfo(false); // we should decide how to handle versioning system |
acversion = AcInfo(false); // we should decide how to handle versioning system |
212 |
// |
// |
213 |
// create an interface to RunInfo called "runinfo" |
// create an interface to RunInfo called "runinfo" |
225 |
} else { |
} else { |
226 |
sgnl = 0; |
sgnl = 0; |
227 |
}; |
}; |
228 |
|
{ |
229 |
// |
// |
230 |
// number of events in the file BEFORE the first event of our run |
// number of events in the file BEFORE the first event of our run |
231 |
// |
// |
232 |
nobefrun = runinfo->GetFirstEntry(); |
nobefrun = runinfo->GetFirstEntry(); |
233 |
// |
// |
234 |
// total number of events in the file |
// total number of events in the file |
235 |
// |
// |
236 |
totfileentries = runinfo->GetFileEntries(); |
totfileentries = runinfo->GetFileEntries(); |
237 |
// |
// |
291 |
tempac = acclone->CloneTree(-1,"fast"); |
tempac = acclone->CloneTree(-1,"fast"); |
292 |
tempac->SetName("Anticounter-old"); |
tempac->SetName("Anticounter-old"); |
293 |
tempfile->Write(); |
tempfile->Write(); |
294 |
tempfile->Close(); |
tempfile->Close(); |
295 |
} |
} |
296 |
// |
// |
297 |
// Delete the old tree from old file and memory |
// Delete the old tree from old file and memory |
303 |
}; |
}; |
304 |
// |
// |
305 |
// create anticounter tree ac |
// create anticounter tree ac |
306 |
// |
// |
307 |
file->cd(); |
file->cd(); |
308 |
ac = new TTree("Anticounter-new","PAMELA Level2 Anticounter data"); |
ac = new TTree("Anticounter-new","PAMELA Level2 Anticounter data"); |
309 |
ac->SetAutoSave(900000000000000LL); |
ac->SetAutoSave(900000000000000LL); |
317 |
acclone = (TTree*)tempfile->Get("Anticounter-old"); |
acclone = (TTree*)tempfile->Get("Anticounter-old"); |
318 |
acclone->SetAutoSave(900000000000000LL); |
acclone->SetAutoSave(900000000000000LL); |
319 |
acclone->SetBranchAddress("AcLevel2",&acl2clone); |
acclone->SetBranchAddress("AcLevel2",&acl2clone); |
320 |
// |
// |
321 |
if ( nobefrun > 0 ){ |
if ( nobefrun > 0 ){ |
322 |
if ( verbose ) { |
if ( verbose ) { |
323 |
printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
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); |
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); |
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++){ |
for (UInt_t j = 0; j < nobefrun; j++){ |
328 |
// |
// |
329 |
acclone->GetEntry(j); |
acclone->GetEntry(j); |
330 |
// |
// |
331 |
// copy acl2clone to acl2 |
// copy acl2clone to acl2 |
332 |
// |
// |
340 |
// |
// |
341 |
}; |
}; |
342 |
if ( verbose ) printf(" Finished successful copying!\n"); |
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. |
// Get the list of run to be processed, if only one run has to be processed the list will contain one entry only. |
379 |
if ( runinfo->ID_ROOT_L0 == 0 ){ |
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); |
if ( verbose ) printf("\n ANTICOUNTER - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun); |
381 |
code = -5; |
code = -5; |
382 |
goto closeandexit; |
goto closeandexit; |
383 |
}; |
}; |
384 |
// |
// |
385 |
// prepare the timesync for the db |
// prepare the timesync for the db |
387 |
TString host = glt->CGetHost(); |
TString host = glt->CGetHost(); |
388 |
TString user = glt->CGetUser(); |
TString user = glt->CGetUser(); |
389 |
TString psw = glt->CGetPsw(); |
TString psw = glt->CGetPsw(); |
390 |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
391 |
if ( !dbc->IsConnected() ) throw -705; |
if ( !dbc->IsConnected() ) throw -705; |
392 |
stringstream myquery; |
stringstream myquery; |
393 |
myquery.str(""); |
myquery.str(""); |
438 |
if ( verbose ) printf(" ANTICOUNTER - ERROR: no Header branch in Level0 tree\n"); |
if ( verbose ) printf(" ANTICOUNTER - ERROR: no Header branch in Level0 tree\n"); |
439 |
l0File->Close(); |
l0File->Close(); |
440 |
code = -8; |
code = -8; |
441 |
goto closeandexit; |
goto closeandexit; |
442 |
}; |
}; |
443 |
l0ac = l0tr->GetBranch("Anticounter"); |
l0ac = l0tr->GetBranch("Anticounter"); |
444 |
if ( !l0ac ) { |
if ( !l0ac ) { |
478 |
// |
// |
479 |
for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ |
for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ |
480 |
// |
// |
481 |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
482 |
// |
// |
483 |
l0head->GetEntry(re); |
l0head->GetEntry(re); |
484 |
// |
// |
485 |
// absolute time of this event |
// absolute time of this event |
486 |
// |
// |
487 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
488 |
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
489 |
// |
// |
490 |
// paranoid check |
// paranoid check |
491 |
// |
// |
533 |
for(Int_t jj = 0; jj < 16; jj++) |
for(Int_t jj = 0; jj < 16; jj++) |
534 |
Counter_old[kk][jj] = Counter[kk][jj]; |
Counter_old[kk][jj] = Counter[kk][jj]; |
535 |
} |
} |
536 |
|
|
537 |
for(Int_t jj = 0; jj < 16; jj++) |
for(Int_t jj = 0; jj < 16; jj++) |
538 |
{ |
{ |
539 |
Counter[kk][jj] = acc->counters[kk][jj]; |
Counter[kk][jj] = acc->counters[kk][jj]; |
544 |
Trigger[kk] = acc->trigg[kk]; |
Trigger[kk] = acc->trigg[kk]; |
545 |
CRCcheck[kk] = acc->CRCcheck[kk]; |
CRCcheck[kk] = acc->CRCcheck[kk]; |
546 |
} |
} |
547 |
|
|
548 |
/***********************************************/ |
/***********************************************/ |
549 |
//process data |
//process data |
550 |
/***********************************************/ |
/***********************************************/ |
575 |
cnt=cnt<<1; |
cnt=cnt<<1; |
576 |
} |
} |
577 |
acl2->hitstatus[s] = Hitstatus[s]; |
acl2->hitstatus[s] = Hitstatus[s]; |
578 |
// |
// |
579 |
//Status |
//Status |
580 |
/****************************************/ |
/****************************************/ |
581 |
if(s==0){ |
if(s==0){ |
582 |
if(Trigger[0] != (Trigg_old[0]+1)) |
if(Trigger[0] != (Trigg_old[0]+1)) |
583 |
acl2->status[0] = acl2->status[0] | 0x1; |
acl2->status[0] = acl2->status[0] | 0x1; |
584 |
if(Status[0] & 0x001F < 0x001F) |
if((Status[0] & 0x001F) < 0x001F) |
585 |
acl2->status[0] = acl2->status[0] | 0x2; |
acl2->status[0] = acl2->status[0] | 0x2; |
586 |
if(CRCcheck[0] == 0) |
if(CRCcheck[0] == 0) |
587 |
acl2->status[0] = acl2->status[0] | 0x4; |
acl2->status[0] = acl2->status[0] | 0x4; |
594 |
else { |
else { |
595 |
if(Trigger[1] != (Trigg_old[1]+2)) |
if(Trigger[1] != (Trigg_old[1]+2)) |
596 |
acl2->status[1] = acl2->status[1] | 0x1; |
acl2->status[1] = acl2->status[1] | 0x1; |
597 |
if(Status[1] & 0x001F < 0x001F) |
if((Status[1] & 0x001F) < 0x001F) |
598 |
acl2->status[1] = acl2->status[1] | 0x2; |
acl2->status[1] = acl2->status[1] | 0x2; |
599 |
if(CRCcheck[1] == 0) |
if(CRCcheck[1] == 0) |
600 |
acl2->status[1] = acl2->status[1] | 0x4; |
acl2->status[1] = acl2->status[1] | 0x4; |
607 |
// |
// |
608 |
// End Anticounter specific code |
// End Anticounter specific code |
609 |
// |
// |
610 |
/************************************************/ |
/************************************************/ |
611 |
acl2->unpackError = acc->unpackError; |
acl2->unpackError = acc->unpackError; |
612 |
// |
// |
613 |
// Fill the rootple |
// Fill the rootple |
614 |
// |
// |
615 |
ac->Fill(); |
ac->Fill(); |
616 |
// |
// |
617 |
// |
// |
618 |
jumpev: |
jumpev: |
619 |
debug = false; |
debug = false; |
620 |
// |
// |
621 |
}; |
}; |
622 |
// |
// |
623 |
// Here you may want to clear some variables before processing another run |
// Here you may want to clear some variables before processing another run |
624 |
// |
// |
625 |
delete dbtime; |
delete dbtime; |
626 |
}; // process all the runs |
}; // process all the runs |
627 |
// |
// |
628 |
if ( verbose ) printf("\n Finished processing data \n"); |
if ( verbose ) printf("\n Finished processing data \n"); |
629 |
|
} |
630 |
// |
// |
631 |
closeandexit: |
closeandexit: |
632 |
// |
// |
635 |
if ( !reprocall && reproc && code >= 0 ){ |
if ( !reprocall && reproc && code >= 0 ){ |
636 |
if ( totfileentries > noaftrun ){ |
if ( totfileentries > noaftrun ){ |
637 |
if ( verbose ){ |
if ( verbose ){ |
638 |
printf("\n Post-processing: copying events from the old tree after the processed run\n"); |
printf("\n Post-processing: copying events from the old tree after the processed run\n"); |
639 |
printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run); |
printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run); |
640 |
printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries); |
printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries); |
641 |
}; |
}; |
643 |
// |
// |
644 |
// Get entry from old tree |
// Get entry from old tree |
645 |
// |
// |
646 |
acclone->GetEntry(j); |
acclone->GetEntry(j); |
647 |
// |
// |
648 |
// copy acl2clone to acl2 |
// copy acl2clone to acl2 |
649 |
// |
// |
658 |
}; |
}; |
659 |
}; |
}; |
660 |
// |
// |
661 |
// Close files, delete old tree(s), write and close level2 file |
// Close files, delete old tree(s), write and close level2 file |
662 |
// |
// |
663 |
if ( l0File ) l0File->Close(); |
if ( l0File ) l0File->Close(); |
664 |
if ( tempfile ) tempfile->Close(); |
if ( tempfile ) tempfile->Close(); |
665 |
if ( myfold ) gSystem->Unlink(tempname.str().c_str()); |
if ( myfold ) gSystem->Unlink(tempname.str().c_str()); |
666 |
// |
// |
667 |
if ( code < 0 && verbose ) printf("\n ANTICOUNTER - ERROR: an error occurred, try to save anyway...\n"); |
if ( code < 0 && verbose ) printf("\n ANTICOUNTER - ERROR: an error occurred, try to save anyway...\n"); |
668 |
if ( verbose ) printf("\n Writing and closing rootple\n"); |
if ( verbose ) printf("\n Writing and closing rootple\n"); |
669 |
if ( runinfo ) runinfo->Close(); |
if ( runinfo ) runinfo->Close(); |
670 |
if ( ac ) ac->SetName("Anticounter"); |
if ( ac ) ac->SetName("Anticounter"); |
671 |
if ( file ){ |
if ( file ){ |
672 |
file->cd(); |
file->cd(); |
673 |
file->Write(); |
file->Write(); |
683 |
if ( acl2 ) delete acl2; |
if ( acl2 ) delete acl2; |
684 |
if ( acl2clone ) delete acl2clone; |
if ( acl2clone ) delete acl2clone; |
685 |
if ( glroot ) delete glroot; |
if ( glroot ) delete glroot; |
686 |
if ( runinfo ) delete runinfo; |
if ( runinfo ) delete runinfo; |
687 |
// |
// |
688 |
if(code < 0) throw code; |
if(code < 0) throw code; |
689 |
return(code); |
return(code); |