/[PAMELA software]/DarthVader/OrbitalInfo/src/OrbitalInfoCore.cpp
ViewVC logotype

Diff of /DarthVader/OrbitalInfo/src/OrbitalInfoCore.cpp

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

revision 1.4 by mocchiut, Fri Aug 4 10:31:29 2006 UTC revision 1.5 by mocchiut, Tue Sep 5 14:49:45 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 26  Line 26 
26  // YODA headers  // YODA headers
27  //  //
28  #include <PamelaRun.h>  #include <PamelaRun.h>
 #include <RegistryEvent.h>  
29  #include <PscuHeader.h>  #include <PscuHeader.h>
30  #include <PscuEvent.h>  #include <PscuEvent.h>
31  #include <EventHeader.h>  #include <EventHeader.h>
 #include <RegistryEvent.h>  
32  //  //
33  // RunInfo header  // RunInfo header
34  //  //
# Line 49  using namespace std; Line 47  using namespace std;
47  // CORE ROUTINE  // CORE ROUTINE
48  //  //
49  //  //
50    int OrbitalInfoCore(UInt_t run, TFile *file, TSQLServer *dbc, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){
 int OrbitalInfoCore(ULong64_t run, TFile *file, TSQLServer *dbc, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){  
51    Int_t i = 0;    Int_t i = 0;
52    //    //
53    TString processFolder = "OrbitalInfoFolder";    TString processFolder = "OrbitalInfoFolder";
# Line 84  int OrbitalInfoCore(ULong64_t run, TFile Line 81  int OrbitalInfoCore(ULong64_t run, TFile
81    const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath()));    const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath()));
82    //    //
83    TTree *OrbitalInfotr = 0;    TTree *OrbitalInfotr = 0;
84    Long64_t nevents = 0LL;    UInt_t nevents = 0;
85    //    //
86    // variables needed to reprocess data    // variables needed to reprocess data
87    //    //
88    TString OrbitalInfoversion;    TString OrbitalInfoversion;
89    ItoRunInfo *runinfo = 0;    ItoRunInfo *runinfo = 0;
90    TArrayL *runlist = 0;    TArrayI *runlist = 0;
91    TTree *OrbitalInfotrclone = 0;    TTree *OrbitalInfotrclone = 0;
92    Bool_t reproc = false;    Bool_t reproc = false;
93    Bool_t reprocall = false;    Bool_t reprocall = false;
# Line 99  int OrbitalInfoCore(ULong64_t run, TFile Line 96  int OrbitalInfoCore(ULong64_t run, TFile
96    UInt_t numbofrun = 0;    UInt_t numbofrun = 0;
97    stringstream ftmpname;    stringstream ftmpname;
98    TString fname;    TString fname;
99    Long64_t totfileentries = 0ULL;    UInt_t totfileentries = 0;
100    Long64_t idRun = 0LL;    UInt_t idRun = 0;
101    //    //
102    // variables needed to handle error signals    // variables needed to handle error signals
103    //    //
# Line 116  int OrbitalInfoCore(ULong64_t run, TFile Line 113  int OrbitalInfoCore(ULong64_t run, TFile
113    //    //
114    TFile *l0File = 0;    TFile *l0File = 0;
115    TTree *l0tr = 0;    TTree *l0tr = 0;
   TBranch *l0registry = 0;  
   pamela::RegistryEvent *l0reg=0;  
116    // EM: open also header branch    // EM: open also header branch
117    TBranch *l0head = 0;    TBranch *l0head = 0;
118    pamela::EventHeader *eh = 0;    pamela::EventHeader *eh = 0;
# Line 131  int OrbitalInfoCore(ULong64_t run, TFile Line 126  int OrbitalInfoCore(ULong64_t run, TFile
126    stringstream file3;    stringstream file3;
127    stringstream qy;    stringstream qy;
128    Int_t totevent = 0;    Int_t totevent = 0;
129    ULong64_t atime = 0ULL;    UInt_t atime = 0;
130    Int_t ei = 0;    UInt_t re = 0;
   Int_t re = 0;  
131    //    //
132    // Working filename    // Working filename
133    //    //
# Line 160  int OrbitalInfoCore(ULong64_t run, TFile Line 154  int OrbitalInfoCore(ULong64_t run, TFile
154    // DB classes    // DB classes
155    //    //
156    GL_ROOT *glroot = new GL_ROOT();    GL_ROOT *glroot = new GL_ROOT();
157      GL_TIMESYNC *dbtime = 0;
158    //    //
159    // Let's start!    // Let's start!
160    //    //
# Line 167  int OrbitalInfoCore(ULong64_t run, TFile Line 162  int OrbitalInfoCore(ULong64_t run, TFile
162    // 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
163    // 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.
164    //    //
165    if ( run == 0ULL )  reproc = true;    if ( run == 0 )  reproc = true;
166    //    //
167    //    //
168    // Output file is "outputfile"    // Output file is "outputfile"
# Line 224  int OrbitalInfoCore(ULong64_t run, TFile Line 219  int OrbitalInfoCore(ULong64_t run, TFile
219      // tree does not exist, we are not reprocessing      // tree does not exist, we are not reprocessing
220      //      //
221      reproc = false;      reproc = false;
222      if ( run == 0ULL ){      if ( run == 0 ){
223        if (verbose) printf(" OrbitalInfo - WARNING: you are reprocessing data but OrbitalInfo tree does not exist!\n");        if (verbose) printf(" OrbitalInfo - WARNING: you are reprocessing data but OrbitalInfo tree does not exist!\n");
224      }      }
225      if ( runinfo->IsReprocessing() && run != 0ULL ) {      if ( runinfo->IsReprocessing() && run != 0 ) {
226        if (verbose) printf(" OrbitalInfo - WARNING: it seems you are not reprocessing data but OrbitalInfo\n versioning information already exists in RunInfo.\n");        if (verbose) printf(" OrbitalInfo - WARNING: it seems you are not reprocessing data but OrbitalInfo\n versioning information already exists in RunInfo.\n");
227      }      }
228    } else {    } else {
# Line 239  int OrbitalInfoCore(ULong64_t run, TFile Line 234  int OrbitalInfoCore(ULong64_t run, TFile
234      //      //
235      if (verbose) printf("\n Preparing the pre-processing...\n");      if (verbose) printf("\n Preparing the pre-processing...\n");
236      //      //
237      if ( run == 0ULL ){      if ( run == 0 ){
238        //        //
239        // we are reprocessing all the file        // we are reprocessing all the file
240        // 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 254  int OrbitalInfoCore(ULong64_t run, TFile Line 249  int OrbitalInfoCore(ULong64_t run, TFile
249        //        //
250        reprocall = false;        reprocall = false;
251        //        //
252        if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing run number %llu \n",run);        if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing run number %u \n",run);
253        //        //
254        // copying old tree to a new file        // copying old tree to a new file
255        //        //
# Line 290  int OrbitalInfoCore(ULong64_t run, TFile Line 285  int OrbitalInfoCore(ULong64_t run, TFile
285      if ( nobefrun > 0 ){      if ( nobefrun > 0 ){
286        if (verbose){        if (verbose){
287        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");  
288        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);
289        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);
290        }        }
291        for (UInt_t j = 0; j < nobefrun; j++){        for (UInt_t j = 0; j < nobefrun; j++){
# Line 299  int OrbitalInfoCore(ULong64_t run, TFile Line 294  int OrbitalInfoCore(ULong64_t run, TFile
294          //          //
295          // copy orbitalinfoclone to mydec          // copy orbitalinfoclone to mydec
296          //          //
         //      orbitalinfo = new OrbitalInfo();  
297          orbitalinfo->Clear();          orbitalinfo->Clear();
298            //
299          memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));          memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
300          //          //
301          // Fill entry in the new tree          // Fill entry in the new tree
# Line 329  int OrbitalInfoCore(ULong64_t run, TFile Line 324  int OrbitalInfoCore(ULong64_t run, TFile
324        printf(" ####################################################################### \n\n\n");        printf(" ####################################################################### \n\n\n");
325      }      }
326      //      //
327      runinfo->ID_REG_RUN = 0ULL;      runinfo->ID_ROOT_L0 = 0;
328      //      //
329      // store in the runinfo class the GL_RUN variables for our run      // store in the runinfo class the GL_RUN variables for our run
330      //      //
331      sgnl = 0;      sgnl = 0;
332      sgnl = runinfo->GetRunInfo(idRun);      sgnl = runinfo->GetRunInfo(idRun);
333      if ( sgnl ){      if ( sgnl ){
334        //printf("\n OrbitalInfo - ERROR: RunInfo exited with non-zero status\n");        if ( debug ) printf("\n OrbitalInfo - ERROR: RunInfo exited with non-zero status\n");
335        code = sgnl;        code = sgnl;
336        goto closeandexit;        goto closeandexit;
337      } else {      } else {
# Line 345  int OrbitalInfoCore(ULong64_t run, TFile Line 340  int OrbitalInfoCore(ULong64_t run, TFile
340      //      //
341      // 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_REG_RUN
342      //      //
343      if ( runinfo->ID_REG_RUN == 0 ){      if ( runinfo->ID_ROOT_L0 == 0 ){
344        //printf("\n OrbitalInfo - ERROR: no run with ID_RUN = %i \n\n Exiting... \n\n",(int)idRun);        if ( debug ) printf("\n OrbitalInfo - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
345        code = -5;        code = -5;
346        goto closeandexit;            goto closeandexit;    
347      };      };
348      //      //
349        // prepare the timesync for the db
350        //
351        dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
352        //
353      // 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.
354      //      //
355      glroot->Query_GL_ROOT(runinfo->ID_REG_RUN,dbc);      glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
356      //      //
357      ftmpname.str("");      ftmpname.str("");
358      ftmpname << glroot->PATH.Data() << "/";      ftmpname << glroot->PATH.Data() << "/";
# Line 362  int OrbitalInfoCore(ULong64_t run, TFile Line 361  int OrbitalInfoCore(ULong64_t run, TFile
361      //      //
362      // print out informations      // print out informations
363      //      //
364      totevent = runinfo->EV_REG_PHYS_TO - runinfo->EV_REG_PHYS_FROM + 1;      totevent = runinfo->NEVENTS;
365      if (verbose){      if (verbose){
366        printf("\n LEVEL0 data file: %s \n",fname.Data());        printf("\n LEVEL0 data file: %s \n",fname.Data());
367        printf(" RUN HEADER absolute time is:  %llu \n",runinfo->RUNHEADER_TIME);        printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME);
368        printf(" RUN TRAILER absolute time is: %llu \n",runinfo->RUNTRAILER_TIME);        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
369        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);
370      }//      }//
371      // Open Level0 file      // Open Level0 file
372      l0File = new TFile(fname.Data());      l0File = new TFile(fname.Data());
373      if ( !l0File ) {      if ( !l0File ) {
374        //printf(" OrbitalInfo - ERROR: problems opening Level0 file\n");        if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n");
375        code = -6;        code = -6;
376        goto closeandexit;        goto closeandexit;
377      };      };
378      l0tr = (TTree*)l0File->Get("Physics");      l0tr = (TTree*)l0File->Get("Physics");
379      if ( !l0tr ) {      if ( !l0tr ) {
380        //printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n");        if ( debug ) printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n");
381        l0File->Close();        l0File->Close();
382        code = -7;        code = -7;
383        goto closeandexit;        goto closeandexit;
# Line 386  int OrbitalInfoCore(ULong64_t run, TFile Line 385  int OrbitalInfoCore(ULong64_t run, TFile
385      // EM: open header branch as well      // EM: open header branch as well
386      l0head = l0tr->GetBranch("Header");      l0head = l0tr->GetBranch("Header");
387      if ( !l0head ) {      if ( !l0head ) {
388        //if ( verbose ) printf(" CALORIMETER - ERROR: no Header branch in Level0 tree\n");        if ( debug ) printf(" OrbitalInfo - ERROR: no Header branch in Level0 tree\n");
389        l0File->Close();        l0File->Close();
390        code = -8;        code = -8;
391        goto closeandexit;            goto closeandexit;    
392      };      };
393      l0tr->SetBranchAddress("Header", &eh);      l0tr->SetBranchAddress("Header", &eh);
394      // end EM      // end EM
395      l0registry = l0tr->GetBranch("Registry");      nevents = l0head->GetEntries();
     if ( !l0registry ) {  
       //printf(" OrbitalInfo - ERROR: no Registry branch in Level0 tree\n");  
       l0File->Close();  
       code = -9;  
       goto closeandexit;      
     };  
     //  
     l0tr->SetBranchAddress("Registry", &l0reg);  
     //  
     nevents = l0registry->GetEntries();  
396      //      //
397      if ( nevents < 1 ) {      if ( nevents < 1 ) {
398        //printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
399        l0File->Close();        l0File->Close();
400        code = -11;        code = -11;
401        goto closeandexit;        goto closeandexit;
402      };      };
403      //      //
404      if ( runinfo->EV_REG_PHYS_TO > nevents-1 ) {      if ( runinfo->EV_TO > nevents-1 ) {
405        //printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");        if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");
406        l0File->Close();        l0File->Close();
407        code = -12;        code = -12;
408        goto closeandexit;        goto closeandexit;
# Line 423  int OrbitalInfoCore(ULong64_t run, TFile Line 412  int OrbitalInfoCore(ULong64_t run, TFile
412      //      //
413      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");
414      //      //
415      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++){
416        //        //
417        if ( procev%1000 == 0 && procev > 0 && verbose) printf(" %iK \n",procev/1000);            if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
418        //        //
419        l0registry->GetEntry(re);        l0head->GetEntry(re);
420        //        //
421        // absolute time of this event        // absolute time of this event
422        //        //
423        atime = l0reg->absTime;        ph = eh->GetPscuHeader();
424        //        atime = dbtime->DBabsTime(ph->GetOrbitalTime());  
       // physics events is at entry number ei where  
       //  
       ei = l0reg->event;  
425        //        //
426        // paranoid check        // paranoid check
427        //        //
# Line 449  int OrbitalInfoCore(ULong64_t run, TFile Line 435  int OrbitalInfoCore(ULong64_t run, TFile
435        // start processing        // start processing
436        //        //
437        orbitalinfo->Clear();        orbitalinfo->Clear();
438        //orbitalinfo = new OrbitalInfo();        //
439        orbitalinfo->absTime = l0reg->absTime;        // CHANGE HERE!!!!
440          //
441          orbitalinfo->absTime = atime;
442        // EM: add OBT and plt_num infos from the header        // EM: add OBT and plt_num infos from the header
       l0head->GetEntry(ei);  
443        ph = eh->GetPscuHeader();        ph = eh->GetPscuHeader();
444        orbitalinfo->pkt_num = ph->GetCounter();        orbitalinfo->pkt_num = ph->GetCounter();
445        orbitalinfo->OBT = ph->GetOrbitalTime();        orbitalinfo->OBT = ph->GetOrbitalTime();
# Line 467  int OrbitalInfoCore(ULong64_t run, TFile Line 454  int OrbitalInfoCore(ULong64_t run, TFile
454      //      //
455      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
456      //      //
457      ei = 0;      delete dbtime;
458    }; // process all the runs    }; // process all the runs
459    //    //
460    if (verbose) printf("\n Finished processing data \n");    if (verbose) printf("\n Finished processing data \n");
# Line 492  int OrbitalInfoCore(ULong64_t run, TFile Line 479  int OrbitalInfoCore(ULong64_t run, TFile
479          // copy orbitalinfoclone to OrbitalInfo          // copy orbitalinfoclone to OrbitalInfo
480          //          //
481          orbitalinfo->Clear();          orbitalinfo->Clear();
482          //      orbitalinfo = new OrbitalInfo();          //
483          memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));          memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
484          //          //
485          // Fill entry in the new tree          // Fill entry in the new tree
# Line 508  int OrbitalInfoCore(ULong64_t run, TFile Line 495  int OrbitalInfoCore(ULong64_t run, TFile
495    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
496    if ( tempfile ) tempfile->Close();                if ( tempfile ) tempfile->Close();            
497    gSystem->Unlink(tempname.str().c_str());    gSystem->Unlink(tempname.str().c_str());
498      //
   //if ( code < 0 ) printf("\n OrbitalInfo - ERROR: an error occurred, try to save anyway...\n");  
   //printf("\n Writing and closing rootple\n");  
499    if ( runinfo ) runinfo->Close();        if ( runinfo ) runinfo->Close();    
500    if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");        if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");    
501    if ( file ){    if ( file ){

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

  ViewVC Help
Powered by ViewVC 1.1.23