/[PAMELA software]/DarthVader/NDLevel2/src/NDCore.cpp
ViewVC logotype

Diff of /DarthVader/NDLevel2/src/NDCore.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by mocchiut, Fri Aug 4 10:31:28 2006 UTC revision 1.5 by mocchiut, Tue Sep 5 14:49:42 2006 UTC
# Line 13  Line 13 
13  #include <TClassEdit.h>  #include <TClassEdit.h>
14  #include <TObject.h>  #include <TObject.h>
15  #include <TList.h>  #include <TList.h>
16  #include <TArrayL.h>  #include <TArrayI.h>
17  #include <TSystem.h>  #include <TSystem.h>
18  #include <TSystemDirectory.h>  #include <TSystemDirectory.h>
19  #include <TString.h>  #include <TString.h>
# Line 29  Line 29 
29  // YODA headers  // YODA headers
30  //  //
31  #include <PamelaRun.h>  #include <PamelaRun.h>
 #include <RegistryEvent.h>  
32  #include <PscuHeader.h>  #include <PscuHeader.h>
33  #include <PscuEvent.h>  #include <PscuEvent.h>
34  #include <EventHeader.h>  #include <EventHeader.h>
 #include <RegistryEvent.h>  
35  #include <physics/neutronDetector/NeutronEvent.h>  #include <physics/neutronDetector/NeutronEvent.h>
36  #include <physics/neutronDetector/NeutronRecord.h>  #include <physics/neutronDetector/NeutronRecord.h>
37  //#include <yodaUtility.h>  //#include <yodaUtility.h>
# Line 55  using namespace std; Line 53  using namespace std;
53  // CORE ROUTINE  // CORE ROUTINE
54  //  //
55  //  //
56  int NDCore(ULong64_t run, TFile *file, TSQLServer *dbc, Int_t NDargc, char *NDargv[]){  int NDCore(UInt_t run, TFile *file, TSQLServer *dbc, Int_t NDargc, char *NDargv[]){
57    //      //  
58    Int_t i = 0;    Int_t i = 0;
59    //    //
# Line 91  int NDCore(ULong64_t run, TFile *file, T Line 89  int NDCore(ULong64_t run, TFile *file, T
89    // Variables for level2    // Variables for level2
90    //    //
91    TTree *NDtr = 0;    TTree *NDtr = 0;
92    Long64_t nevents = 0LL;    UInt_t nevents = 0;
93    //    //
94    // variables needed to reprocess data    // variables needed to reprocess data
95    //    //
96    TString NDversion;    TString NDversion;
97    ItoRunInfo *runinfo = 0;    ItoRunInfo *runinfo = 0;
98    TArrayL *runlist = 0;    TArrayI *runlist = 0;
99    TTree *NDtrclone = 0;    TTree *NDtrclone = 0;
100    Bool_t reproc = false;    Bool_t reproc = false;
101    Bool_t reprocall = false;    Bool_t reprocall = false;
# Line 106  int NDCore(ULong64_t run, TFile *file, T Line 104  int NDCore(ULong64_t run, TFile *file, T
104    UInt_t numbofrun = 0;    UInt_t numbofrun = 0;
105    stringstream ftmpname;    stringstream ftmpname;
106    TString fname;    TString fname;
107    Long64_t totfileentries = 0ULL;    UInt_t totfileentries = 0;
108    Long64_t idRun = 0LL;    UInt_t idRun = 0;
109    Int_t tmpSize =0;    Int_t tmpSize =0;
110    Float_t yTrig =0;    Float_t yTrig =0;
111    Float_t yUpperBackground =0;    Float_t yUpperBackground =0;
# Line 128  int NDCore(ULong64_t run, TFile *file, T Line 126  int NDCore(ULong64_t run, TFile *file, T
126    TFile *l0File = 0;    TFile *l0File = 0;
127    TTree *l0tr = 0;    TTree *l0tr = 0;
128    TBranch *l0head = 0;    TBranch *l0head = 0;
   TBranch *l0registry = 0;  
129    TBranch *l0ND =0;    TBranch *l0ND =0;
   pamela::RegistryEvent *l0reg=0;  
130    pamela::EventHeader *eh = 0;    pamela::EventHeader *eh = 0;
131      pamela::PscuHeader *ph = 0;
132    pamela::neutron::NeutronRecord *l0nr = 0;    pamela::neutron::NeutronRecord *l0nr = 0;
133    pamela::neutron::NeutronEvent  *l0ne = 0;    pamela::neutron::NeutronEvent  *l0ne = 0;
134    //    //
# Line 142  int NDCore(ULong64_t run, TFile *file, T Line 139  int NDCore(ULong64_t run, TFile *file, T
139    stringstream file3;    stringstream file3;
140    stringstream qy;    stringstream qy;
141    Int_t totevent = 0;    Int_t totevent = 0;
142    ULong64_t atime = 0ULL;    UInt_t atime = 0;
143    Int_t ei = 0;    UInt_t re = 0;
   Int_t re = 0;  
144    //    //
145    // Working filename    // Working filename
146    //    //
# Line 171  int NDCore(ULong64_t run, TFile *file, T Line 167  int NDCore(ULong64_t run, TFile *file, T
167    // DB classes    // DB classes
168    //    //
169    GL_ROOT *glroot = new GL_ROOT();    GL_ROOT *glroot = new GL_ROOT();
170      GL_TIMESYNC *dbtime = 0;
171    //    //
172    // Let's start!    // Let's start!
173    //    //
# Line 178  int NDCore(ULong64_t run, TFile *file, T Line 175  int NDCore(ULong64_t run, TFile *file, T
175    // if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file    // if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file
176    // 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.
177    //    //
178    if ( run == 0ULL )  reproc = true;    if ( run == 0 )  reproc = true;
179    //    //
180    //    //
181    // Output file is "outputfile"    // Output file is "outputfile"
# Line 201  int NDCore(ULong64_t run, TFile *file, T Line 198  int NDCore(ULong64_t run, TFile *file, T
198    sgnl = 0;    sgnl = 0;
199    sgnl = runinfo->Update(run, "ND",NDversion);    sgnl = runinfo->Update(run, "ND",NDversion);
200    if ( sgnl ){    if ( sgnl ){
201      //printf(" ND - ERROR: RunInfo exited with non-zero status\n");      if ( debug ) printf(" ND - ERROR: RunInfo exited with non-zero status\n");
202      code = sgnl;      code = sgnl;
203      goto closeandexit;      goto closeandexit;
204    } else {    } else {
# Line 233  int NDCore(ULong64_t run, TFile *file, T Line 230  int NDCore(ULong64_t run, TFile *file, T
230      // tree does not exist, we are not reprocessing      // tree does not exist, we are not reprocessing
231      //      //
232      reproc = false;      reproc = false;
233      if ( run == 0ULL ) {      if ( run == 0 ) {
234        if (verbose) printf(" ND - WARNING: you are reprocessing data but ND tree does not exist!\n");        if (verbose) printf(" ND - WARNING: you are reprocessing data but ND tree does not exist!\n");
235      }      }
236      if ( runinfo->IsReprocessing() && run != 0ULL ) {      if ( runinfo->IsReprocessing() && run != 0 ) {
237        if (verbose) printf(" ND - WARNING: it seems you are not reprocessing data but ND\n versioning information already exists in RunInfo.\n");        if (verbose) printf(" ND - WARNING: it seems you are not reprocessing data but ND\n versioning information already exists in RunInfo.\n");
238      }      }
239    } else {    } else {
# Line 247  int NDCore(ULong64_t run, TFile *file, T Line 244  int NDCore(ULong64_t run, TFile *file, T
244      //      //
245      // update versioning information      // update versioning information
246      //      //
     // sgnl = runinfo->Update(run, "ND",NDversion);  
247      if (verbose) printf("\n Preparing the pre-processing...\n");      if (verbose) printf("\n Preparing the pre-processing...\n");
248      //      //
249      if ( run == 0ULL ){      if ( run == 0 ){
250        //        //
251        // we are reprocessing all the file        // we are reprocessing all the file
252        // 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        // 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
# Line 265  int NDCore(ULong64_t run, TFile *file, T Line 261  int NDCore(ULong64_t run, TFile *file, T
261        //        //
262        reprocall = false;        reprocall = false;
263        //        //
264        if (verbose) printf("\n ND - WARNING: Reprocessing run number %llu \n",run);        if (verbose) printf("\n ND - WARNING: Reprocessing run number %u \n",run);
265        //        //
266        // copying old tree to a new file        // copying old tree to a new file
267        //        //
# Line 301  int NDCore(ULong64_t run, TFile *file, T Line 297  int NDCore(ULong64_t run, TFile *file, T
297      if ( nobefrun > 0 ){      if ( nobefrun > 0 ){
298        if (verbose) {        if (verbose) {
299          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");  
300          printf(" Copying %u events in the file which are before the beginning of the run %llu \n",nobefrun,run);          printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
301          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);
302        }        }
303        for (UInt_t j = 0; j < nobefrun; j++){        for (UInt_t j = 0; j < nobefrun; j++){
# Line 336  int NDCore(ULong64_t run, TFile *file, T Line 332  int NDCore(ULong64_t run, TFile *file, T
332      idRun = runlist->At(irun);      idRun = runlist->At(irun);
333      if (verbose) {      if (verbose) {
334        printf("\n\n\n ####################################################################### \n");        printf("\n\n\n ####################################################################### \n");
335        printf("                    PROCESSING RUN NUMBER %i \n",(int)idRun);        printf("                    PROCESSING RUN NUMBER %u \n",idRun);
336        printf(" ####################################################################### \n\n\n");        printf(" ####################################################################### \n\n\n");
337      }      }
338      //      //
339      runinfo->ID_REG_RUN = 0ULL;      runinfo->ID_ROOT_L0 = 0;
340      //      //
341      // store in the runinfo class the GL_RUN variables for our run      // store in the runinfo class the GL_RUN variables for our run
342      //      //
343      sgnl = 0;      sgnl = 0;
344      sgnl = runinfo->GetRunInfo(idRun);      sgnl = runinfo->GetRunInfo(idRun);
345      if ( sgnl ){      if ( sgnl ){
346        //printf(" ND - ERROR: RunInfo exited with non-zero status\n");        if ( debug ) printf(" ND - ERROR: RunInfo exited with non-zero status\n");
347        code = sgnl;        code = sgnl;
348        goto closeandexit;        goto closeandexit;
349      } else {      } else {
350        sgnl = 0;        sgnl = 0;
351      };      };
352      //      //
353      // now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN      // now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0
354      //      //
355      if ( runinfo->ID_REG_RUN == 0 ){      if ( runinfo->ID_ROOT_L0 == 0 ){
356        //printf("\n ND - ERROR: no run with ID_RUN = %i \n\n Exiting... \n\n",(int)idRun);        if ( debug ) printf("\n ND - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
357        code = -5;        code = -5;
358        goto closeandexit;            goto closeandexit;    
359      };      };
360      //      //
361        // prepare the timesync for the db
362        //
363        dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
364        //
365      // Search in the DB the path and name of the LEVEL0 file to be processed.      // Search in the DB the path and name of the LEVEL0 file to be processed.
366      //      //
367      glroot->Query_GL_ROOT(runinfo->ID_REG_RUN,dbc);      glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
368      //      //
369      ftmpname.str("");      ftmpname.str("");
370      ftmpname << glroot->PATH.Data() << "/";      ftmpname << glroot->PATH.Data() << "/";
# Line 373  int NDCore(ULong64_t run, TFile *file, T Line 373  int NDCore(ULong64_t run, TFile *file, T
373      //      //
374      // print out informations      // print out informations
375      //      //
376      totevent = runinfo->EV_REG_PHYS_TO - runinfo->EV_REG_PHYS_FROM + 1;      totevent = runinfo->NEVENTS;
377      if (verbose) {      if (verbose) {
378        printf("\n LEVEL0 data file: %s \n",fname.Data());        printf("\n LEVEL0 data file: %s \n",fname.Data());
379        printf(" RUN HEADER absolute time is:  %llu \n",runinfo->RUNHEADER_TIME);        printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME);
380        printf(" RUN TRAILER absolute time is: %llu \n",runinfo->RUNTRAILER_TIME);        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
381        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);        printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM,runinfo->EV_FROM+totevent);
382      }      }
383      //      //
384      // Open Level0 file      // Open Level0 file
385      //      //
386      l0File = new TFile(fname.Data());      l0File = new TFile(fname.Data());
387      if ( !l0File ) {      if ( !l0File ) {
388        //printf(" ND - ERROR: problems opening  Level0 file\n");        if ( debug ) printf(" ND - ERROR: problems opening  Level0 file\n");
389        code = -6;        code = -6;
390        goto closeandexit;        goto closeandexit;
391      };      };
392      l0tr = (TTree*)l0File->Get("Physics");      l0tr = (TTree*)l0File->Get("Physics");
393      if ( !l0tr ) {      if ( !l0tr ) {
394        //printf(" ND - ERROR: no Physics tree in Level0 file\n");        if ( debug ) printf(" ND - ERROR: no Physics tree in Level0 file\n");
395        l0File->Close();        l0File->Close();
396        code = -7;        code = -7;
397        goto closeandexit;        goto closeandexit;
398      };      };
399      l0head = l0tr->GetBranch("Header");      l0head = l0tr->GetBranch("Header");
400      if ( !l0head ) {      if ( !l0head ) {
401        //printf(" ND - ERROR: no Header branch in Level0 tree\n");        if ( debug ) printf(" ND - ERROR: no Header branch in Level0 tree\n");
402        l0File->Close();        l0File->Close();
403        code = -8;        code = -8;
404        goto closeandexit;            goto closeandexit;    
405      };      };
     l0registry = l0tr->GetBranch("Registry");  
     if ( !l0registry ) {  
       //printf(" ND - ERROR: no Registry branch in Level0 tree\n");  
       l0File->Close();  
       code = -9;  
       goto closeandexit;      
     };  
406      l0ND = l0tr->GetBranch("Neutron");      l0ND = l0tr->GetBranch("Neutron");
407      if ( !l0ND ) {      if ( !l0ND ) {
408        //printf(" ND - ERROR: no ND branch in Level0 tree\n");        if ( debug ) printf(" ND - ERROR: no ND branch in Level0 tree\n");
409        l0File->Close();        l0File->Close();
410        code = -603;        code = -603;
411        goto closeandexit;        goto closeandexit;
412      };      };
413    
414      //      //
     l0tr->SetBranchAddress("Registry", &l0reg);  
415      l0tr->SetBranchAddress("Neutron", &l0ne);      l0tr->SetBranchAddress("Neutron", &l0ne);
416      l0tr->SetBranchAddress("Header", &eh);      l0tr->SetBranchAddress("Header", &eh);
417      //      //
418      nevents = l0registry->GetEntries();      nevents = l0ND->GetEntries();
419      //      //
420      if ( nevents < 1 ) {      if ( nevents < 1 ) {
421        //printf(" ND - ERROR: Level0 file is empty\n\n");        if ( debug ) printf(" ND - ERROR: Level0 file is empty\n\n");
422        l0File->Close();        l0File->Close();
423        code = -11;        code = -11;
424        goto closeandexit;        goto closeandexit;
425      };      };
426      //      //
427      if ( runinfo->EV_REG_PHYS_TO > nevents-1 ) {      if ( runinfo->EV_TO > nevents-1 ) {
428        //printf(" ND - ERROR: too few entries in the registry tree\n");        if ( debug ) printf(" ND - ERROR: too few entries in the tree\n");
429        l0File->Close();        l0File->Close();
430        code = -12;        code = -12;
431        goto closeandexit;        goto closeandexit;
# Line 443  int NDCore(ULong64_t run, TFile *file, T Line 435  int NDCore(ULong64_t run, TFile *file, T
435      //      //
436      if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n");      if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n");
437      //      //
438      for ( re = runinfo->EV_REG_PHYS_FROM; re <= runinfo->EV_REG_PHYS_TO; re++){      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
439        //        //
440        if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);          if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
441        //        //
442        l0registry->GetEntry(re);        l0head->GetEntry(re);
443        //        //
444        // absolute time of this event        // absolute time of this event
445        //        //
446        atime = l0reg->absTime;        ph = eh->GetPscuHeader();
447        //        atime = dbtime->DBabsTime(ph->GetOrbitalTime());  
       // physics events is at entry number ei where  
       //  
       ei = l0reg->event;  
448        //        //
449        // paranoid check        // paranoid check
450        //        //
# Line 468  int NDCore(ULong64_t run, TFile *file, T Line 457  int NDCore(ULong64_t run, TFile *file, T
457        //        //
458        // start processing        // start processing
459        //        //
       //      nd = new NDLevel2();  
460        nd->Clear();        nd->Clear();
461        //        //
462        l0ND->GetEntry(ei);        l0ND->GetEntry(re);
463        tmpSize = l0ne->Records->GetEntries();        tmpSize = l0ne->Records->GetEntries();
464        if (!tmpSize) continue;        if (!tmpSize) continue;
465        if (l0ne->unpackError == 1) continue;        if (l0ne->unpackError == 1) continue;
# Line 499  int NDCore(ULong64_t run, TFile *file, T Line 487  int NDCore(ULong64_t run, TFile *file, T
487      //      //
488      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
489      //      //
490      ei = 0;      delete dbtime;
491    }; // process all the runs    }; // process all the runs
492    //    //
493    if (verbose) printf("\n Finished processing data \n");    if (verbose) printf("\n Finished processing data \n");
# Line 523  int NDCore(ULong64_t run, TFile *file, T Line 511  int NDCore(ULong64_t run, TFile *file, T
511          //          //
512          // copy ndclone to nd          // copy ndclone to nd
513          //          //
         //      nd = new NDLevel2();  
514          nd->Clear();          nd->Clear();
515          memcpy(&nd,&ndclone,sizeof(ndclone));          memcpy(&nd,&ndclone,sizeof(ndclone));
516          //          //
# Line 540  int NDCore(ULong64_t run, TFile *file, T Line 527  int NDCore(ULong64_t run, TFile *file, T
527    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
528    if ( tempfile ) tempfile->Close();                if ( tempfile ) tempfile->Close();            
529    gSystem->Unlink(tempname.str().c_str());    gSystem->Unlink(tempname.str().c_str());
530      //
   //if ( code < 0 ) printf("\n ND - ERROR: an error occurred, try to save anyway...\n");  
   //printf("\n Writing and closing rootple\n");  
531    if ( runinfo ) runinfo->Close();        if ( runinfo ) runinfo->Close();    
532    if ( NDtr ) NDtr->SetName("NeutronD");        if ( NDtr ) NDtr->SetName("NeutronD");    
533    if ( file ){    if ( file ){
# Line 559  int NDCore(ULong64_t run, TFile *file, T Line 544  int NDCore(ULong64_t run, TFile *file, T
544    //    //
545    if ( nd ) delete nd;    if ( nd ) delete nd;
546    if ( ndclone ) delete ndclone;    if ( ndclone ) delete ndclone;
547      if ( glroot ) delete glroot;
548    if ( runinfo ) delete runinfo;    if ( runinfo ) delete runinfo;
549    //    //
550    if(code < 0)  throw code;    if(code < 0)  throw code;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.23