/[PAMELA software]/DarthVader/S4Level2/src/S4Core.cpp
ViewVC logotype

Annotation of /DarthVader/S4Level2/src/S4Core.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations) (download)
Fri Sep 7 21:14:19 2007 UTC (17 years, 4 months ago) by mocchiut
Branch: MAIN
Changes since 1.17: +9 -4 lines
Close MySQL connection before start the main loop in core routines

1 mocchiut 1.1 //
2 pam-rm2 1.11 // Given a calibration and a data file this program create an ntuple with LEVEL2 S4 variables
3     //
4     //
5 mocchiut 1.1 // C/C++ headers
6     //
7     #include <fstream>
8     #include <string.h>
9     #include <iostream>
10     #include <cstring>
11     #include <stdio.h>
12     //
13     // ROOT headers
14     //
15 mocchiut 1.4 #include <TGraph.h>
16     #include <TF1.h>
17 mocchiut 1.1 #include <TTree.h>
18     #include <TClassEdit.h>
19     #include <TObject.h>
20     #include <TList.h>
21 mocchiut 1.4 #include <TArrayI.h>
22     #include <TArrayD.h>
23 mocchiut 1.1 #include <TSystem.h>
24     #include <TSystemDirectory.h>
25     #include <TString.h>
26     #include <TFile.h>
27     #include <TClass.h>
28     #include <TSQLServer.h>
29     #include <TSQLRow.h>
30     #include <TSQLResult.h>
31     #include <TClonesArray.h>
32     #include <stdlib.h>
33     #include <math.h>
34     //
35 mocchiut 1.10 // RunInfo header
36     //
37     #include <RunInfo.h>
38     #include <GLTables.h>
39     //
40 mocchiut 1.1 // YODA headers
41     //
42     #include <PamelaRun.h>
43     #include <PscuHeader.h>
44     #include <PscuEvent.h>
45     #include <EventHeader.h>
46     #include <CalibS4Event.h>
47     #include <physics/S4/S4Event.h>
48     //
49     // This program headers
50     //
51     #include <S4Level2.h>
52     #include <S4Core.h>
53     #include <S4Verl2.h>
54 pam-rm2 1.11 //
55 mocchiut 1.1 using namespace std;
56 mocchiut 1.4 //
57     /*
58     * Fit function Received from Valeria Malvezzi 06/02/2006
59     */
60     Double_t fitf(Double_t *x, Double_t *par){
61     Double_t fitval =(par[0]*x[0])+par[1];
62     return fitval;
63     }
64    
65     /*
66     * Fit the S4 calibration with a straight line - Received from Valeria Malvezzi 06/02/2006
67     */
68     TArrayD *S4_paramfit(UInt_t atime, TSQLServer *dbc){
69     //
70     TArrayD *parametri = new TArrayD(2);
71     //
72     GL_S4_CALIB *glS4calib = new GL_S4_CALIB();
73     //
74 mocchiut 1.18 // if ( !dbc->IsConnected() ) throw -504;
75 mocchiut 1.16 Int_t s4sig = glS4calib->Query_GL_S4_CALIB(atime, dbc);
76 mocchiut 1.17 if ( s4sig != -57 && s4sig < 0 ){
77     parametri->AddAt(0.,0);
78     parametri->AddAt(0.,1);
79     return parametri;
80     };
81 mocchiut 1.16 if ( s4sig < 0 ) throw s4sig;
82 mocchiut 1.4 //
83     GL_ROOT *glroot = new GL_ROOT();
84 mocchiut 1.18 // if ( !dbc->IsConnected() ) throw -504;
85 mocchiut 1.4 glroot->Query_GL_ROOT(glS4calib->ID_ROOT_L0,dbc);
86     //
87     stringstream ftmpname;
88     ftmpname.str("");
89     ftmpname << glroot->PATH.Data() << "/";
90     ftmpname << glroot->NAME.Data();
91     //
92     TFile *file = 0;
93     file = new TFile(ftmpname.str().c_str());
94     //
95     if ( !file ) return(NULL);
96     //
97     TTree *tr = 0;
98     tr = (TTree*)file->Get("CalibS4");
99     if ( !tr ){
100     file->Close();
101     return(NULL);
102     };
103     //
104     pamela::CalibS4Event *S4CalibEvent = 0;
105     tr->SetBranchAddress("CalibS4", &S4CalibEvent);
106     if ( tr->GetEntries() < glS4calib->EV_ROOT ) return(NULL);
107     //
108     tr->GetEntry(glS4calib->EV_ROOT);
109     //
110 pam-rm2 1.11 // Variables initialization
111 mocchiut 1.4 //
112     Double_t mip[3]={1, 30, 300};
113     Double_t adc[3] = {0.,0.,0.};
114     //
115 pam-rm2 1.11 // Fit calibrations and find parameters to calibrate data
116 mocchiut 1.4 //
117     pamela::S4::S4Event *s4Record = 0;
118     //
119     for (Int_t j = 0; j < 4; j++){
120     for (Int_t i = 0; i < 128; i++){
121     s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i));
122     switch (j) {
123     case 0 :{
124     adc[0]=adc[0]+((s4Record->S4_DATA)-32);
125     break;
126     };
127     case 1 :{
128     adc[1]=adc[1]+((s4Record->S4_DATA)-32);
129     break;
130     };
131     case 3 :{
132     adc[2]=adc[2]+((s4Record->S4_DATA)-32);
133     break;
134     };
135     };
136     };
137     };
138     //
139     adc[0]=adc[0]/128;
140     adc[1]=adc[1]/128;
141     adc[2]=adc[2]/128;
142     // if ( IsDebug() ) printf(" adc1 = %g adc2 = %g adc3 = %g\n",adc[0],adc[1],adc[2]);
143     TGraph *fitpar = new TGraph (3, adc, mip);
144 pam-rm2 1.11 TF1 *func = new TF1("fitf", fitf, -1., 400., 2); // function definition with 2 parameters
145 mocchiut 1.4 //
146 pam-rm2 1.11 func->SetParameters(0.3,1.); // parameters initialization to 1
147     func->SetParNames("m","q"); //parameter's name
148     fitpar->Fit(func,"qr"); //function fit
149 mocchiut 1.4 parametri->AddAt(func->GetParameter(0),0);
150     parametri->AddAt(func->GetParameter(1),1);
151     // if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.7 || parametri[1] > 1.1 ) valid = 0;
152     //
153     delete glroot;
154     delete glS4calib;
155     delete fitpar;
156     delete func;
157     file->Close();
158     //
159     return parametri;
160     };
161    
162     //
163 mocchiut 1.1 // CORE ROUTINE
164     //
165     //
166 mocchiut 1.4 int S4Core(UInt_t run, TFile *file, TSQLServer *dbc, Int_t S4argc, char *S4argv[]){
167 mocchiut 1.1 //
168 pam-rm2 1.11 // Set these to true to have a verbose output.
169 mocchiut 1.1 //
170 mocchiut 1.4 Bool_t debug = false;
171     Bool_t verbose = false;
172 mocchiut 1.1 //
173 pam-rm2 1.11 //
174     // Output directory is the working directoy.
175     //
176     const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath()));
177     //
178     Int_t i = 0;
179 mocchiut 1.14 TString processFolder = Form("S4Folder_%u",run);
180 mocchiut 1.1 if ( S4argc > 0 ){
181     i = 0;
182     while ( i < S4argc ){
183     if ( !strcmp(S4argv[i],"-processFolder") ) {
184     if ( S4argc < i+1 ){
185     throw -3;
186     };
187     processFolder = (TString)S4argv[i+1];
188     i++;
189     };
190     if ( (!strcmp(S4argv[i],"--debug")) || (!strcmp(S4argv[i],"-g"))) {
191     verbose = true;
192 mocchiut 1.13 debug = true;
193 mocchiut 1.1 };
194     if ( (!strcmp(S4argv[i],"--verbose")) || (!strcmp(S4argv[i],"-v"))) {
195     verbose = true;
196     };
197     i++;
198     };
199     };
200     // Variables for level2
201     //
202     TTree *S4tr = 0;
203 mocchiut 1.4 UInt_t nevents = 0;
204 mocchiut 1.1 //
205 pam-rm2 1.11 // Variables needed to reprocess data
206 mocchiut 1.1 //
207 mocchiut 1.9 Long64_t maxsize = 10000000000LL;
208     TTree::SetMaxTreeSize(maxsize);
209     //
210 mocchiut 1.1 TString S4version;
211     ItoRunInfo *runinfo = 0;
212 mocchiut 1.4 TArrayI *runlist = 0;
213 mocchiut 1.1 TTree *S4trclone = 0;
214     Bool_t reproc = false;
215     Bool_t reprocall = false;
216     UInt_t nobefrun = 0;
217     UInt_t noaftrun = 0;
218     UInt_t numbofrun = 0;
219     stringstream ftmpname;
220     TString fname;
221 mocchiut 1.4 UInt_t totfileentries = 0;
222     UInt_t idRun = 0;
223     Double_t ParamFit0 = 0.;
224     Double_t ParamFit1 = 0.;
225 mocchiut 1.1 //
226     // variables needed to handle error signals
227     //
228     Int_t code = 0;
229     Int_t sgnl;
230     //
231     // S4 level2 classes
232     //
233     S4Level2 *s4 = new S4Level2();
234     S4Level2 *s4clone = new S4Level2();
235     //
236     // define variables for opening and reading level0 file
237     //
238     TFile *l0File = 0;
239     TTree *l0tr = 0;
240     TBranch *l0head = 0;
241     TBranch *l0S4 =0;
242     pamela::S4::S4Event *l0s4e = 0;
243     pamela::EventHeader *eh = 0;
244 mocchiut 1.4 pamela::PscuHeader *ph = 0;
245 mocchiut 1.1 //
246     // Define other basic variables
247     //
248     UInt_t procev = 0;
249     stringstream file2;
250     stringstream file3;
251     stringstream qy;
252     Int_t totevent = 0;
253 mocchiut 1.4 UInt_t atime = 0;
254     // Int_t ei = 0;
255     UInt_t re = 0;
256 mocchiut 1.1 //
257     // Working filename
258     //
259     TString outputfile;
260     stringstream name;
261     name.str("");
262     name << outDir << "/";
263     //
264     // temporary file and folder
265     //
266     TFile *tempfile = 0;
267     TTree *tempS4 = 0;
268     stringstream tempname;
269     stringstream S4folder;
270 mocchiut 1.17 Bool_t myfold = false;
271 mocchiut 1.1 tempname.str("");
272     tempname << outDir;
273     tempname << "/" << processFolder.Data();
274     S4folder.str("");
275     S4folder << tempname.str().c_str();
276     tempname << "/S4tree_run";
277     tempname << run << ".root";
278     //
279     // DB classes
280     //
281     GL_ROOT *glroot = new GL_ROOT();
282 mocchiut 1.4 GL_TIMESYNC *dbtime = 0;
283 mocchiut 1.1 //
284     // Let's start!
285     //
286     // 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
287     // if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file
288     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
289     //
290 mocchiut 1.4 if ( run == 0 ) reproc = true;
291 mocchiut 1.1 //
292     //
293     // Output file is "outputfile"
294     //
295     if ( !file->IsOpen() ){
296     //printf(" S4 - ERROR: cannot open file for writing\n");
297     throw -501;
298     };
299     //
300     // Retrieve GL_RUN variables from the level2 file
301     //
302     S4version = S4Info(false); // we should decide how to handle versioning system
303     //
304     // create an interface to RunInfo called "runinfo"
305     //
306     runinfo = new ItoRunInfo(file);
307     //
308     // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
309     //
310     sgnl = 0;
311     sgnl = runinfo->Update(run,"S4",S4version);
312     if ( sgnl ){
313     //printf(" S4 - ERROR: RunInfo exited with non-zero status\n");
314     code = sgnl;
315     goto closeandexit;
316     } else {
317     sgnl = 0;
318     };
319     //
320     // number of events in the file BEFORE the first event of our run
321     //
322     nobefrun = runinfo->GetFirstEntry();
323     //
324     // total number of events in the file
325     //
326     totfileentries = runinfo->GetFileEntries();
327     //
328     // first file entry AFTER the last event of our run
329     //
330     noaftrun = runinfo->GetLastEntry() + 1;
331     //
332     // number of run to be processed
333     //
334     numbofrun = runinfo->GetNoRun();
335 mocchiut 1.15 UInt_t totnorun = runinfo->GetRunEntries();
336 mocchiut 1.1 //
337     // Try to access the S4 tree in the file, if it exists we are reprocessing data if not we are processing a new run
338     //
339     S4trclone = (TTree*)file->Get("S4");
340     //
341     if ( !S4trclone ){
342     //
343     // tree does not exist, we are not reprocessing
344     //
345     reproc = false;
346 mocchiut 1.4 if ( run == 0 ){
347 mocchiut 1.1 if (verbose) printf(" S4 - WARNING: you are reprocessing data but S4 tree does not exist!\n");
348     }
349 mocchiut 1.4 if ( runinfo->IsReprocessing() && run != 0 ) {
350 mocchiut 1.1 if (verbose) printf(" S4 - WARNING: it seems you are not reprocessing data but S4\n versioning information already exists in RunInfo.\n");
351     }
352     } else {
353     //
354     // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
355     //
356 mocchiut 1.9 S4trclone->SetAutoSave(900000000000000LL);
357 mocchiut 1.1 reproc = true;
358     //
359     // update versioning information
360     //
361     if (verbose) printf("\n Preparing the pre-processing...\n");
362     //
363 mocchiut 1.15 if ( run == 0 || totnorun == 1 ){
364 mocchiut 1.1 //
365     // we are reprocessing all the file
366     // 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
367     //
368     reprocall = true;
369     //
370     if (verbose) printf("\n S4 - WARNING: Reprocessing all runs\n");
371     //
372     } else {
373     //
374     // 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
375     //
376     reprocall = false;
377     //
378 mocchiut 1.4 if (verbose) printf("\n S4 - WARNING: Reprocessing run number %u \n",run);
379 mocchiut 1.1 //
380     // copying old tree to a new file
381     //
382 mocchiut 1.17 gSystem->MakeDirectory(S4folder.str().c_str());
383     myfold = true;
384 mocchiut 1.1 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
385     tempS4 = S4trclone->CloneTree(-1,"fast");
386     tempS4->SetName("S4-old");
387     tempfile->Write();
388     tempfile->Close();
389     }
390     //
391     // Delete the old tree from old file and memory
392     //
393     S4trclone->Delete("all");
394     //
395     if (verbose) printf(" ...done!\n");
396     //
397     };
398     //
399     // create mydetector tree mydect
400     //
401     file->cd();
402     S4tr = new TTree("S4-new","PAMELA Level2 S4 data");
403 mocchiut 1.9 S4tr->SetAutoSave(900000000000000LL);
404 mocchiut 1.1 S4tr->Branch("S4Level2","S4Level2",&s4);
405     //
406     if ( reproc && !reprocall ){
407     //
408     // open new file and retrieve also tree informations
409     //
410     tempfile = new TFile(tempname.str().c_str(),"READ");
411     S4trclone = (TTree*)tempfile->Get("S4-old");
412 mocchiut 1.9 S4trclone->SetAutoSave(900000000000000LL);
413 mocchiut 1.1 S4trclone->SetBranchAddress("S4Level2",&s4clone);
414     //
415     if ( nobefrun > 0 ){
416     if (verbose){
417     printf("\n Pre-processing: copying events from the old tree before the processed run\n");
418 mocchiut 1.4 printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
419 mocchiut 1.1 printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
420     }
421     for (UInt_t j = 0; j < nobefrun; j++){
422     //
423     S4trclone->GetEntry(j);
424     //
425     // copy s4clone to mydec
426     //
427 mocchiut 1.2 s4->Clear();
428 mocchiut 1.4 //
429 mocchiut 1.1 memcpy(&s4,&s4clone,sizeof(s4clone));
430     //
431     // Fill entry in the new tree
432     //
433     S4tr->Fill();
434     //
435     };
436     if (verbose) printf(" Finished successful copying!\n");
437     };
438     };
439     //
440     // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
441     //
442     runlist = runinfo->GetRunList();
443     //
444     // Loop over the run to be processed
445     //
446     for (UInt_t irun=0; irun < numbofrun; irun++){
447     //
448     // retrieve the first run ID to be processed using the RunInfo list
449     //
450     idRun = runlist->At(irun);
451     if (verbose){
452     printf("\n\n\n ####################################################################### \n");
453 mocchiut 1.4 printf(" PROCESSING RUN NUMBER %u \n",idRun);
454 mocchiut 1.1 printf(" ####################################################################### \n\n\n");
455     }
456     //
457 mocchiut 1.4 runinfo->ID_ROOT_L0 = 0;
458 mocchiut 1.1 //
459     // store in the runinfo class the GL_RUN variables for our run
460     //
461     sgnl = 0;
462     sgnl = runinfo->GetRunInfo(idRun);
463     if ( sgnl ){
464 mocchiut 1.4 if ( debug ) printf(" S4 - ERROR: RunInfo exited with non-zero status\n");
465 mocchiut 1.1 code = sgnl;
466     goto closeandexit;
467     } else {
468     sgnl = 0;
469     };
470     //
471 mocchiut 1.5 // now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0
472 mocchiut 1.1 //
473 mocchiut 1.4 if ( runinfo->ID_ROOT_L0 == 0 ){
474     if ( debug ) printf("\n S4 - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
475 mocchiut 1.1 code = -5;
476     goto closeandexit;
477     };
478     //
479 mocchiut 1.4 // prepare the timesync for the db
480     //
481 mocchiut 1.18 // if ( !dbc->IsConnected() ) throw -504;
482 mocchiut 1.4 dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
483     //
484 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
485     //
486 mocchiut 1.18 // if ( !dbc->IsConnected() ) throw -504;
487 mocchiut 1.4 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
488 mocchiut 1.1 //
489     ftmpname.str("");
490     ftmpname << glroot->PATH.Data() << "/";
491     ftmpname << glroot->NAME.Data();
492     fname = ftmpname.str().c_str();
493     //
494     // print out informations
495     //
496 mocchiut 1.4 totevent = runinfo->NEVENTS;
497 mocchiut 1.1 if (verbose){
498     printf("\n LEVEL0 data file: %s \n",fname.Data());
499 mocchiut 1.4 printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME);
500     printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
501     printf(" %i events to be processed for run %u: from %u to %u \n\n",totevent,idRun,runinfo->EV_FROM,(runinfo->EV_FROM+totevent));
502 mocchiut 1.1 }
503     //
504     // Open Level0 file
505     //
506     l0File = new TFile(fname.Data());
507     if ( !l0File ) {
508 mocchiut 1.4 if ( debug ) printf(" S4 - ERROR: problems opening Level0 file\n");
509 mocchiut 1.1 code = -6;
510     goto closeandexit;
511     };
512 mocchiut 1.4 //
513 mocchiut 1.1 l0tr = (TTree*)l0File->Get("Physics");
514     if ( !l0tr ) {
515 mocchiut 1.4 if ( debug ) printf(" S4 - ERROR: no Physics tree in Level0 file\n");
516 mocchiut 1.1 l0File->Close();
517     code = -7;
518     goto closeandexit;
519     };
520     l0head = l0tr->GetBranch("Header");
521     if ( !l0head ) {
522 mocchiut 1.4 if ( debug ) printf(" S4 - ERROR: no Header branch in Level0 tree\n");
523 mocchiut 1.1 l0File->Close();
524     code = -8;
525     goto closeandexit;
526     };
527     l0S4 = l0tr->GetBranch("S4");
528     if ( !l0S4 ) {
529 mocchiut 1.4 if ( debug ) printf(" S4 - ERROR: no S4 branch in Level0 tree\n");
530 mocchiut 1.1 l0File->Close();
531     code = -503;
532     goto closeandexit;
533     };
534     //
535     l0tr->SetBranchAddress("S4", &l0s4e);
536     l0tr->SetBranchAddress("Header", &eh);
537     //
538 mocchiut 1.4 nevents = l0S4->GetEntries();
539 mocchiut 1.1 //
540     if ( nevents < 1 ) {
541 mocchiut 1.4 if ( debug ) printf(" S4 - ERROR: Level0 file is empty\n\n");
542 mocchiut 1.1 l0File->Close();
543     code = -11;
544     goto closeandexit;
545     };
546     //
547 mocchiut 1.5 if ( runinfo->EV_TO > nevents-1 ) {
548 mocchiut 1.4 if ( debug ) printf(" S4 - ERROR: too few entries in the S4 tree\n");
549 mocchiut 1.1 l0File->Close();
550     code = -12;
551     goto closeandexit;
552     };
553     //
554     // Check if we have to load parameter files (or calibration associated to runs and not to events)
555     // second query: which is the value of paramfit relative to the calibration?
556     //
557 mocchiut 1.4 TArrayD *params = 0;
558     params = S4_paramfit(runinfo->RUNHEADER_TIME, dbc);
559     if ( !params ){
560     code = -13;
561     goto closeandexit;
562     };
563     //
564     ParamFit0 = params->At(0);
565     ParamFit1 = params->At(1);
566 mocchiut 1.1 //
567     // run over all the events of the run
568     //
569     if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n");
570     //
571 mocchiut 1.18 if ( dbc ){
572     dbc->Close();
573     // delete dbc;
574     };
575     //
576 mocchiut 1.4 for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
577 mocchiut 1.1 //
578     if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
579     //
580 mocchiut 1.4 l0head->GetEntry(re);
581 mocchiut 1.1 //
582     // absolute time of this event
583     //
584 mocchiut 1.4 ph = eh->GetPscuHeader();
585     atime = dbtime->DBabsTime(ph->GetOrbitalTime());
586 mocchiut 1.1 //
587     // paranoid check
588     //
589     if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME) ) {
590     if (verbose) printf(" S4 - WARNING: event at time outside the run time window, skipping it\n");
591     goto jumpev;
592     };
593     //
594     procev++;
595     //
596     // start processing
597     //
598 mocchiut 1.2 s4->Clear();
599 mocchiut 1.4 l0S4->GetEntry(re);
600 mocchiut 1.6 if (l0s4e->unpackError == 0){
601     s4->S4adc = l0s4e->S4_DATA;
602     //
603     if ((l0s4e->S4_DATA) > 31 ){
604     s4->S4calibrated = ParamFit0*((l0s4e->S4_DATA)-32)+ParamFit1;
605     }else{
606     s4->S4calibrated = 0;
607     }
608     };
609 mocchiut 1.4 //
610 mocchiut 1.7 s4->unpackError = l0s4e->unpackError;
611     //
612 mocchiut 1.1 S4tr->Fill();
613     //
614     //
615     jumpev:
616     debug = false;
617     //
618     };
619     //
620     // Here you may want to clear some variables before processing another run
621     //
622 mocchiut 1.4 delete dbtime;
623     if ( params ) delete params;
624     //
625 mocchiut 1.1 }; // process all the runs
626     //
627     if (verbose) printf("\n Finished processing data \n");
628     //
629     closeandexit:
630     //
631     // 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.
632     //
633     if ( !reprocall && reproc && code >= 0 ){
634     if ( totfileentries > noaftrun ){
635     if (verbose){
636     printf("\n Post-processing: copying events from the old tree after the processed run\n");
637     printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
638     printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
639     }
640     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
641     //
642     // Get entry from old tree
643     //
644     S4trclone->GetEntry(j);
645     //
646     // copy s4clone to s4
647     //
648 mocchiut 1.2 // s4 = new S4Level2();
649     s4->Clear();
650 mocchiut 1.1 memcpy(&s4,&s4clone,sizeof(s4clone));
651     //
652     // Fill entry in the new tree
653     //
654     S4tr->Fill();
655     };
656     if (verbose) printf(" Finished successful copying!\n");
657     };
658     };
659     //
660     // Close files, delete old tree(s), write and close level2 file
661     //
662     if ( l0File ) l0File->Close();
663     if ( tempfile ) tempfile->Close();
664 mocchiut 1.17 if ( myfold) gSystem->Unlink(tempname.str().c_str());
665 mocchiut 1.4 //
666 mocchiut 1.1 if ( runinfo ) runinfo->Close();
667     if ( S4tr ) S4tr->SetName("S4");
668     if ( file ){
669     file->cd();
670     file->Write();
671     };
672     //
673 mocchiut 1.17 if ( myfold ) gSystem->Unlink(S4folder.str().c_str());
674 mocchiut 1.1 //
675     // the end
676     //
677     if (verbose) printf("\n Exiting...\n");
678 mocchiut 1.4 if ( S4tr ) S4tr->Delete();
679 mocchiut 1.3 //
680     if ( s4 ) delete s4;
681     if ( s4clone ) delete s4clone;
682     if ( glroot ) delete glroot;
683     if ( runinfo ) delete runinfo;
684     //
685 mocchiut 1.1 if(code < 0) throw code;
686     return(code);
687     }
688    
689    

  ViewVC Help
Powered by ViewVC 1.1.23