/[PAMELA software]/DarthVader/ToFLevel2/src/ToFCore.cpp
ViewVC logotype

Contents of /DarthVader/ToFLevel2/src/ToFCore.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Fri Jun 30 09:22:03 2006 UTC (18 years, 8 months ago) by mocchiut
Branch: MAIN
Changes since 1.2: +8 -3 lines
Memory leak bug fixed

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 <TArrayL.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 // YODA headers
31 //
32 #include <PamelaRun.h>
33 #include <RegistryEvent.h>
34 #include <physics/trigger/TriggerEvent.h>
35 #include <physics/tof/TofEvent.h>
36 //
37 // RunInfo header
38 //
39 #include <RunInfo.h>
40 //
41 // This program headers
42 //
43 #include <ToFCore.h>
44 #include <ToFLevel2.h>
45 #include <ToFVerl2.h>
46 //
47 //
48 // Declaration of the core fortran routines
49 //
50 #define tofl2com tofl2com_
51 extern "C" int tofl2com();
52 #define toftrk toftrk_
53 extern "C" int toftrk();
54 #define rdtofcal rdtofcal_
55 extern "C" int rdtofcal(char []);
56
57 //
58 // Tracker classes headers and definitions
59 //
60 #include <TrkLevel2.h>
61 //
62 using namespace std;
63 //
64 //
65 // CORE ROUTINE
66 //
67 //
68 int ToFCore(ULong64_t run, TFile *file, TSQLServer *dbc, Int_t ToFargc, char *ToFargv[]){
69 //
70 //
71 // Set these to true to have a very verbose output.
72 //
73 Bool_t verbose = false;
74 Bool_t debug = false;
75 //
76 TString processFolder = "ToFFolder";
77 if ( ToFargc > 0 ){
78 Int_t i = 0;
79 while ( i < ToFargc ){
80 if ( !strcmp(ToFargv[i],"-processFolder") ) {
81 if ( ToFargc < i+1 ){
82 throw -3;
83 };
84 processFolder = (TString)ToFargv[i+1];
85 i++;
86 };
87 if ( !strcmp(ToFargv[i],"-v") || !strcmp(ToFargv[i],"--verbose") ) {
88 verbose = true;
89 };
90 if ( !strcmp(ToFargv[i],"-g") || !strcmp(ToFargv[i],"--debug") ) {
91 debug = true;
92 };
93 i++;
94 };
95 };
96 //
97 //
98 // Output directory is the working directoy.
99 //
100 const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath()));
101 //
102 // Variables for level2
103 //
104 TTree *tracker = 0;
105 TTree *toft = 0;
106 Long64_t nevents = 0LL;
107 //
108 // variables needed to reprocess data
109 //
110 TString tofversion;
111 ItoRunInfo *runinfo = 0;
112 TArrayL *runlist = 0;
113 TTree *toftclone = 0;
114 Bool_t reproc = false;
115 Bool_t reprocall = false;
116 UInt_t nobefrun = 0;
117 UInt_t noaftrun = 0;
118 UInt_t numbofrun = 0;
119 stringstream ftmpname;
120 TString fname;
121 Long64_t totfileentries = 0ULL;
122 Long64_t idRun = 0LL;
123 //
124 // variables needed to handle error signals
125 //
126 Int_t code = 0;
127 Int_t sgnl;
128 //
129 // tof level2 classes
130 //
131 ToFLevel2 *tof = new ToFLevel2();
132 ToFLevel2 *tofclone = new ToFLevel2();
133 //
134 // tracker level2 variables
135 //
136 TrkLevel2 *trk = new TrkLevel2();
137 Long64_t nevtrkl2 = 0;
138 //
139 // define variables for opening and reading level0 file
140 //
141 TFile *l0File = 0;
142 TTree *l0tr = 0;
143 TBranch *l0head = 0;
144 TBranch *l0registry = 0;
145 TBranch *l0trig = 0;
146 TBranch *l0tof = 0;
147 pamela::RegistryEvent *l0reg=0;
148 pamela::trigger::TriggerEvent *trig = 0;
149 pamela::tof::TofEvent *tofEvent = 0;
150 //
151 // Define other basic variables
152 //
153 UInt_t procev = 0;
154 stringstream file2;
155 stringstream file3;
156 stringstream qy;
157 Int_t itr = -1;
158 Int_t totevent = 0;
159 ULong64_t atime = 0ULL;
160 Int_t ei = 0;
161 Int_t re = 0;
162 //
163 // Working filename
164 //
165 TString outputfile;
166 stringstream name;
167 name.str("");
168 name << outdir << "/";
169 //
170 // temporary file and folder
171 //
172 TFile *tempfile = 0;
173 TTree *temptof = 0;
174 stringstream tempname;
175 stringstream toffolder;
176 tempname.str("");
177 tempname << outdir;
178 tempname << "/" << processFolder.Data();
179 toffolder.str("");
180 toffolder << tempname.str().c_str();
181 gSystem->MakeDirectory(toffolder.str().c_str());
182 tempname << "/toftree_run";
183 tempname << run << ".root";
184 //
185 // variables needed to load magnetic field maps
186 //
187 Int_t ntrkentry = 0;
188 ULong64_t tttrkpar1 = 0ULL;
189 Bool_t trkpar1 = true;
190 ULong64_t tttofpar1 = 0ULL;
191 Bool_t tofpar1 = true;
192 //
193 // DB classes
194 //
195 GL_ROOT *glroot = new GL_ROOT();
196 GL_PARAM *glparam = new GL_PARAM();
197 //
198 // declaring external output and input structures
199 //
200 extern struct ToFInput tofinput_;
201 extern struct ToFOutput tofoutput_;
202 //
203 // Let's start!
204 //
205 //
206 // 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
207 // if run != 0 we must process only that run but first we have to check if the tree ToF already exist in the file
208 // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
209 //
210 if ( run == 0ULL ) reproc = true;
211 //
212 //
213 // Output file is "outputfile"
214 //
215 if ( !file->IsOpen() ){
216 if ( verbose ) printf(" ToF - ERROR: cannot open file for writing\n");
217 throw -301;
218 };
219 //
220 // Does it contain the Tracker tree?
221 //
222 tracker = (TTree*)file->Get("Tracker");
223 if ( !tracker ) {
224 if ( verbose ) printf(" TOF - ERROR: no tracker tree\n");
225 code = -302;
226 goto closeandexit;
227 };
228 //
229 // get tracker level2 data pointer
230 //
231 tracker->SetBranchAddress("TrkLevel2",&trk);
232 nevtrkl2 = tracker->GetEntries();
233 //
234 // Retrieve GL_RUN variables from the level2 file
235 //
236 tofversion = ToFInfo(false); // we should decide how to handle versioning system
237 //
238 // create an interface to RunInfo called "runinfo"
239 //
240 // ItoRunInfo= interface with RunInfo and GL_RUN
241 runinfo = new ItoRunInfo(file);
242 //
243 // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
244 //
245 sgnl = 0;
246 sgnl = runinfo->Update(run, "TOF",tofversion);
247 if ( sgnl ){
248 if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
249 code = sgnl;
250 goto closeandexit;
251 } else {
252 sgnl = 0;
253 };
254 //
255 // number of events in the file BEFORE the first event of our run
256 //
257 nobefrun = runinfo->GetFirstEntry();
258 //
259 // total number of events in the file
260 //
261 totfileentries = runinfo->GetFileEntries();
262 //
263 // first file entry AFTER the last event of our run
264 //
265 noaftrun = runinfo->GetLastEntry() + 1;
266 //
267 // number of run to be processed
268 //
269 numbofrun = runinfo->GetNoRun();
270 //
271 // Try to access the ToF tree in the file, if it exists we are reprocessing data if not we are processing a new run
272 //
273 toftclone = (TTree*)file->Get("ToF");
274 //
275 if ( !toftclone ){
276 //
277 // tree does not exist, we are not reprocessing
278 //
279 reproc = false;
280 if ( run == 0ULL && verbose ) printf(" ToF - WARNING: you are reprocessing data but ToF tree does not exist!\n");
281 if ( runinfo->IsReprocessing() && run != 0ULL && verbose ) printf(" ToF - WARNING: it seems you are not reprocessing data but ToF\n versioning information already exists in RunInfo.\n");
282
283 } else {
284 //
285 // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
286 //
287 reproc = true;
288 //
289 // update versioning information
290 //
291 if ( verbose ) printf("\n Preparing the pre-processing...\n");
292 //
293 if ( run == 0ULL ){
294 //
295 // we are reprocessing all the file
296 // 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
297 //
298 reprocall = true;
299 //
300 if ( verbose ) printf("\n ToF - WARNING: Reprocessing all runs\n");
301 //
302 } else {
303 //
304 // 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
305 //
306 reprocall = false;
307 //
308 if ( verbose ) printf("\n ToF - WARNING: Reprocessing run number %llu \n",run);
309 //
310 // copying old tree to a new file
311 //
312 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
313 temptof = toftclone->CloneTree(-1,"fast");
314 temptof->SetName("ToF-old");
315 tempfile->Write();
316 tempfile->Close();
317 }
318 //
319 // Delete the old tree from old file and memory
320 //
321 toftclone->Delete("all");
322 //
323 if ( verbose ) printf(" ...done!\n");
324 //
325 };
326 //
327 // create ToF detector tree toft
328 //
329 file->cd();
330 toft = new TTree("ToF-new","PAMELA Level2 ToF data");
331 toft->Branch("ToFLevel2","ToFLevel2",&tof);
332 //
333 if ( reproc && !reprocall ){
334 //
335 // open new file and retrieve all tree informations
336 //
337 tempfile = new TFile(tempname.str().c_str(),"READ");
338 toftclone = (TTree*)tempfile->Get("ToF-old");
339 toftclone->SetBranchAddress("ToFLevel2",&tofclone);
340 //
341 if ( nobefrun > 0 ){
342 if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n");
343 if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %llu \n",nobefrun,run);
344 if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
345 for (UInt_t j = 0; j < nobefrun; j++){
346 //
347 toftclone->GetEntry(j);
348 //
349 // copy tofclone to tof
350 //
351 //tof = new ToFLevel2();
352 tof->Clear();
353 memcpy(&tof,&tofclone,sizeof(tofclone));
354 //
355 // Fill entry in the new tree
356 //
357 toft->Fill();
358 //
359 };
360 if ( verbose ) printf(" Finished successful copying!\n");
361 };
362 };
363 //
364 // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
365 //
366 runlist = runinfo->GetRunList();
367 //
368 // Loop over the run to be processed
369 //
370 for (UInt_t irun=0; irun < numbofrun; irun++){
371 //
372 // retrieve the first run ID to be processed using the RunInfo list
373 //
374 idRun = runlist->At(irun);
375 if ( verbose ) printf("\n\n\n ####################################################################### \n");
376 if ( verbose ) printf(" PROCESSING RUN NUMBER %i \n",(int)idRun);
377 if ( verbose ) printf(" ####################################################################### \n\n\n");
378 //
379 runinfo->ID_REG_RUN = 0ULL;
380 //
381 // store in the runinfo class the GL_RUN variables for our run
382 //
383 sgnl = 0;
384 sgnl = runinfo->GetRunInfo(idRun);
385 if ( sgnl ){
386 if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
387 code = sgnl;
388 goto closeandexit;
389 } else {
390 sgnl = 0;
391 };
392 //
393 // now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN
394 //
395 if ( runinfo->ID_REG_RUN == 0 ){
396 if ( verbose ) printf("\n TOF - ERROR: no run with ID_RUN = %i \n\n Exiting... \n\n",(int)idRun);
397 code = -5;
398 goto closeandexit;
399 };
400 //
401 // Search in the DB the path and name of the LEVEL0 file to be processed.
402 //
403 glroot->Query_GL_ROOT(runinfo->ID_REG_RUN,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->EV_REG_PHYS_TO - runinfo->EV_REG_PHYS_FROM + 1;
413 if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data());
414 if ( verbose ) printf(" RUN HEADER absolute time is: %llu \n",runinfo->RUNHEADER_TIME);
415 if ( verbose ) printf(" RUN TRAILER absolute time is: %llu \n",runinfo->RUNTRAILER_TIME);
416 if ( verbose ) printf(" %i events to be processed for run %llu: from %i to %i (reg entries)\n\n",totevent,idRun,runinfo->EV_REG_PHYS_FROM,runinfo->EV_REG_PHYS_TO);
417 //
418 // Open Level0 file
419 //
420 l0File = new TFile(fname.Data());
421 if ( !l0File ) {
422 if ( verbose ) printf(" TOF - ERROR: problems opening Level0 file\n");
423 code = -6;
424 goto closeandexit;
425 };
426 l0tr = (TTree*)l0File->Get("Physics");
427 if ( !l0tr ) {
428 if ( verbose ) printf(" TOF - ERROR: no Physics tree in Level0 file\n");
429 l0File->Close();
430 code = -7;
431 goto closeandexit;
432 };
433 l0head = l0tr->GetBranch("Header");
434 if ( !l0head ) {
435 if ( verbose ) printf(" TOF - ERROR: no Header branch in Level0 tree\n");
436 l0File->Close();
437 code = -8;
438 goto closeandexit;
439 };
440 l0registry = l0tr->GetBranch("Registry");
441 if ( !l0registry ) {
442 if ( verbose ) printf(" TOF - ERROR: no Registry branch in Level0 tree\n");
443 l0File->Close();
444 code = -9;
445 goto closeandexit;
446 };
447 l0trig = l0tr->GetBranch("Trigger");
448 if ( !l0trig ) {
449 if ( verbose ) printf(" TOF - ERROR: no Trigger branch in Level0 tree\n");
450 l0File->Close();
451 code = -300;
452 goto closeandexit;
453 };
454 l0tof = l0tr->GetBranch("Tof");
455 if ( !l0tof ) {
456 if ( verbose ) printf(" TOF - ERROR: no ToF branch in Level0 tree\n");
457 l0File->Close();
458 code = -303;
459 goto closeandexit;
460 };
461 //
462 l0tr->SetBranchAddress("Trigger", &trig);
463 l0tr->SetBranchAddress("Tof", &tofEvent);
464 l0tr->SetBranchAddress("Registry", &l0reg);
465 //
466 nevents = l0registry->GetEntries();
467 //
468 if ( nevents < 1 ) {
469 if ( verbose ) printf(" TOF - ERROR: Level0 file is empty\n\n");
470 l0File->Close();
471 code = -11;
472 goto closeandexit;
473 };
474 //
475 if ( runinfo->EV_REG_PHYS_TO > nevents-1 ) {
476 if ( verbose ) printf(" TOF - ERROR: too few entries in the registry tree\n");
477 l0File->Close();
478 code = -12;
479 goto closeandexit;
480 };
481 //
482 // Check if we have to load parameter files (or calibration associated to runs and not to events)
483 //
484 // for example let's assume that we could have different magnetic field maps for different runs:
485 //
486 if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runinfo->RUNHEADER_TIME ) ){
487 trkpar1 = false;
488 // read from DB infos about Magnetic filed maps
489 glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,"field",dbc); // parameters stored in DB in GL_PRAM table
490 tttrkpar1 = glparam->TO_TIME;
491 // ----------------------------
492 // Read the magnetic field
493 // ----------------------------
494 if ( verbose ) printf(" Reading magnetic field maps: \n");
495 trk->LoadField(glparam->PATH+glparam->NAME);
496 if ( verbose ) printf("\n");
497 };
498 // Bug Found: Emiliano 30 May 2006
499 // if ( tofpar1 || ( tttofpar1 != 0 && tttofpar1 < runinfo->RUNHEADER_TIME ) ){
500 // tofpar1 = false;
501 // //
502 // glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,"tof param",dbc); // parameters stored in DB in GL_PRAM table
503 // //
504 // tttofpar1 = glparam->TO_TIME;
505 // rdtofcal((char *)(glparam->PATH+glparam->NAME).Data());
506 // };
507 // Corrected:
508 if ( tofpar1 || ( tttofpar1 != 0 && tttofpar1 < runinfo->RUNHEADER_TIME ) ){
509 tofpar1 = false;
510 //
511 Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,"tof param",dbc); // parameters stored in DB in GL_PRAM table
512 if ( error<0 ) {
513 code = error;
514 goto closeandexit;
515 };
516 //
517 tttofpar1 = glparam->TO_TIME;
518 rdtofcal((char *)(glparam->PATH+glparam->NAME).Data());
519 };
520 //
521 // run over all the events of the run
522 //
523 if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n");
524 //
525 for ( re = runinfo->EV_REG_PHYS_FROM; re <= runinfo->EV_REG_PHYS_TO; re++){
526 //
527 if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
528 //
529 l0registry->GetEntry(re);
530 //
531 // absolute time of this event
532 //
533 atime = l0reg->absTime;
534 //
535 // physics events is at entry number ei where
536 //
537 ei = l0reg->event;
538 //
539 // paranoid check
540 //
541 if ( atime > runinfo->RUNTRAILER_TIME || atime < runinfo->RUNHEADER_TIME ) {
542 if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n");
543 goto jumpev;
544 };
545 //
546 // retrieve tracker informations, the LEVEL2 entry which correspond to our event will be "itr"
547 //
548 if ( !reprocall ){
549 itr = nobefrun + (re - runinfo->EV_REG_PHYS_FROM);
550 } else {
551 itr = runinfo->GetFirstEntry() + (re - runinfo->EV_REG_PHYS_FROM);
552 };
553 if ( itr > nevtrkl2 ){ // nevtrkl2 tracker entry number
554 if ( verbose ) printf(" TOF - ERROR: no tracker events with entry = %i in Level2 file\n",itr);
555 l0File->Close();
556 code = -313;
557 goto closeandexit;
558 };
559 tracker->GetEntry(itr);
560 ///
561 //
562 l0tof->GetEntry(ei);
563 l0trig->GetEntry(ei);
564 ///
565 //
566 procev++;
567 //
568 // start processing
569 //
570 tof->Clear();
571 //tof = new ToFLevel2();
572
573 //
574 // Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure
575
576 for (Int_t gg=0; gg<4;gg++){
577 for (Int_t hh=0; hh<12;hh++){
578 tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];
579 tofinput_.adc[hh][gg]=tofEvent->adc[gg][hh];
580 };
581 };
582
583 for (Int_t hh=0; hh<5;hh++){
584 tofinput_.patterntrig[hh]=trig->patterntrig[hh];
585 };
586 //
587 // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
588 //
589 //
590 // Calculate tracks informations from ToF alone
591 //
592 tofl2com();
593 //
594 // and now we must copy from the output structure to the level2 class:
595 //
596 // common variables not related to the track
597 for (Int_t kk=0; kk<3;kk++){
598 tof->xtofpos[kk] = tofoutput_.xtofpos[kk];
599 tof->ytofpos[kk] = tofoutput_.ytofpos[kk];
600 }
601
602 for (Int_t kk=0; kk<6;kk++){
603 tof->tof_i_flag[kk]=tofoutput_.tof_i_flag[kk];
604 tof->tof_j_flag[kk]=tofoutput_.tof_j_flag[kk];
605 }
606
607 for (Int_t kk=0; kk<13;kk++){
608 tof->betatof_a[kk] = tofoutput_.betatof_a[kk];
609 }
610
611 for (Int_t hh=0; hh<12;hh++){
612 for (Int_t kk=0; kk<4;kk++){
613 tof->adctof_c[hh][kk] = tofoutput_.adctof_c[hh][kk];
614 }
615 }
616
617 for (Int_t hh=0; hh<12;hh++){
618 for (Int_t kk=0; kk<4;kk++){
619 tof->tdc_c[hh][kk] = tofoutput_.tdc_c[hh][kk];
620 }
621 }
622
623 //
624 // Calculate track-related variables
625 //
626 //
627 // Calculate variables related to tracks only if we have at least one track (from selftrigger and/or tracker)
628 //
629 ntrkentry = 0;
630 //
631 // if ( trk->GetNTracks() > 0 ){
632 if ( trk->ntrk() > 0 ){
633 //
634 // We have at least one track
635 //
636 //
637 // Run over tracks
638 //
639 // example: how to use tracker data
640 for(Int_t nt=0; nt < trk->ntrk(); nt++){
641 //
642 TrkTrack *ptt = trk->GetStoredTrack(nt);
643 //
644 // Copy the alpha vector in the input structure
645 //
646 for (Int_t e = 0; e < 5 ; e++){
647 tofinput_.al_pp[e] = ptt->al[e];
648 };
649 //
650 // Get tracker related variables for this track
651 //
652 toftrk();
653 //
654 // Copy values in the class from the structure (we need to use a temporary class to store variables).
655 //
656 ToFTrkVar *t_tof = new ToFTrkVar();
657 for (Int_t kk=0; kk<13;kk++){
658 t_tof->beta_a[kk] = tofoutput_.beta_a[kk];
659 }
660
661 for (Int_t hh=0; hh<12;hh++){
662 for (Int_t kk=0; kk<4;kk++){
663 t_tof->adc_c[hh][kk] = tofoutput_.adc_c[hh][kk];
664 }
665 }
666 //
667 // Store the tracker track number in order to be sure to have shyncronized data during analysis
668 //
669 t_tof->trkseqno = nt;
670 //
671 // create a new object for this event with track-related variables
672 //
673 TClonesArray &t = *tof->ToFTrk;
674 new(t[ntrkentry]) ToFTrkVar(*t_tof);
675 //
676 delete t_tof;
677 //
678 ntrkentry++;
679 //
680 }; // loop on all the tracks
681 };
682 //
683 // Fill the rootple
684 //
685 toft->Fill();
686 //
687 //
688 jumpev:
689 debug = false;
690 //
691 };
692 }; // process all the runs
693 //
694 if ( verbose ) printf("\n Finished processing data \n");
695 //
696 closeandexit:
697 //
698 // 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.
699 //
700 if ( !reprocall && reproc && code >= 0 ){
701 if ( totfileentries > noaftrun ){
702 if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n");
703 if ( verbose ) printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
704 if ( verbose ) printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
705 for (UInt_t j = noaftrun; j < totfileentries; j++ ){
706 //
707 // Get entry from old tree
708 //
709 toftclone->GetEntry(j);
710 //
711 // copy tofclone to tof
712 //
713 // tof = new ToFLevel2();
714 tof->Clear();
715 memcpy(&tof,&tofclone,sizeof(tofclone));
716 //
717 // Fill entry in the new tree
718 //
719 toft->Fill();
720 };
721 if ( verbose ) printf(" Finished successful copying!\n");
722 };
723 };
724 //
725 // Close files, delete old tree(s), write and close level2 file
726 //
727 if ( l0File ) l0File->Close();
728 if ( tempfile ) tempfile->Close();
729 gSystem->Unlink(tempname.str().c_str());
730 if ( tracker ) tracker->Delete(); // delete tracker tree from memory only to avoid writing a copy to file!
731 //
732 if ( code < 0 && verbose ) printf("\n TOF - ERROR: an error occurred, try to save anyway...\n");
733 if ( verbose ) printf("\n Writing and closing rootple\n");
734 if ( runinfo ) runinfo->Close();
735 if ( toft ) toft->SetName("ToF");
736 if ( file ){
737 file->cd();
738 file->Write("ToF");
739 };
740 //
741 gSystem->Unlink(toffolder.str().c_str());
742 //
743 // the end
744 //
745 if ( verbose ) printf("\n Exiting...\n");
746 if(toft)toft->Delete();
747 if ( code < 0 ) throw code;
748 return(code);
749 }

  ViewVC Help
Powered by ViewVC 1.1.23