]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/qaRec/makeResults.C
modify macros interface
[u/mrichter/AliRoot.git] / TRD / qaRec / makeResults.C
index 176a776d9942371274bde9ded2ab5064b935e0e1..967ef155c8aa86c678cf31cd6f9f0ee4f6e169b7 100644 (file)
+#if ! defined (__CINT__) || defined (__MAKECINT__)
+#include "TError.h"
+#include <TClass.h>
+#include <TFileMerger.h>
+#include <TCanvas.h>
+#include <TH1.h>
+#include <TGraph.h>
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TPython.h>
+#include <TString.h>
+#include <TROOT.h>
+#include <TSystem.h>
+#include <TStyle.h>
+
+#include "qaRec/AliTRDrecoTask.h"
+
+#endif
+
 #include "run.h"
-#define BIT(n)        (1 << (n))
-#define TESTBIT(n,i)  ((Bool_t)(((n) & BIT(i)) != 0))
-
-
-const Int_t fSteerTask = 0xffffffff;
-Char_t *fTaskClass[fknTasks] = {
-  "AliTRDtrackInfoGen"
-  ,"AliTRDtrackingEfficiency"
-  ,"AliTRDtrackingEfficiencyCombined"
-  ,"AliTRDtrackingResolution"
-  ,"AliTRDcalibration"
-  ,"AliTRDpidChecker"
-  ,"AliTRDcheckDetector"
-};
-
-const Int_t nlibs = 3;
-Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libTRDqaRec.so"};
-void makeResults(Char_t *dir=".")
+
+Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libTRDqaRec.so", "libPyROOT"};
+
+void makeResults(Char_t *tasks = "ALL", Char_t* dir=0x0)
 {
+       // Load Libraries in interactive mode
+  Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
   for(Int_t ilib=0; ilib<nlibs; ilib++){
-    if(!gSystem->Load(libs[ilib])) continue;
+    if(gSystem->Load(libs[ilib]) >= 0) continue;
     printf("Failed to load %s.\n", libs[ilib]);
     return;
   }
+
+
   gStyle->SetOptStat(0);
+  Bool_t mc      = kTRUE;
+  Bool_t friends = kTRUE;
+
+  // select tasks to process; we should move it to an 
+  // individual function and move the task identifiers 
+  // outside the const space
+  TObjArray *tasksArray = TString(tasks).Tokenize(" ");
+  Int_t fSteerTask = 0;
+  for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
+    TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
+    if(s.CompareTo("ALL") == 0){
+      for(Int_t itask = 1; itask < fknTasks; itask++) SETBIT(fSteerTask, itask);
+      continue;
+    } else if(s.CompareTo("NOFR") == 0){ 
+      friends = kFALSE;
+    } else if(s.CompareTo("NOMC") == 0){ 
+      mc = kFALSE;
+    } else { 
+      Bool_t foundOpt = kFALSE;  
+      for(Int_t itask = 1; itask < fknTasks; itask++){
+        if(s.CompareTo(fTaskOpt[itask]) != 0) continue;
+        SETBIT(fSteerTask, itask);
+        foundOpt = kTRUE;
+        break;
+      }
+      if(!foundOpt) Info("makeResults.C", Form("Task %s not implemented (yet).", s.Data()));
+    }
+  }
+
 
-  Int_t ndir = 1;
+  // catch the list of files using the ROOT Python Interface
+  TPython *pyshell = new TPython();
+  pyshell->Exec("import commands");
 
   // file merger object
-  TFileMerger *fFM = 0x0;
+  TFileMerger *fFM = new TFileMerger();
   TClass *ctask = 0x0;
   TObject *o = 0x0;
   TObjArray *fContainer = 0x0;
   AliTRDrecoTask *task = 0x0;
 
-  printf("\n\tPROCESSING DATA FOR TASKS:\n");
-  for(Int_t itask = 3; itask <4/*fknTasks*/ ; itask++){
+  printf("\n\tPROCESSING DATA FOR TASKS [%d]:\n", fSteerTask);
+  for(Int_t itask = 1; itask <fknTasks; itask++){
     if(!TESTBIT(fSteerTask, itask)) continue;
 
     ctask = new TClass(fTaskClass[itask]);
     task = (AliTRDrecoTask*)ctask->New();
-    task->SetDebugLevel(2);
+    task->SetDebugLevel(0);
+    task->SetMCdata(mc);
+    task->SetFriends(friends);
     printf("\t%s [%s]\n", task->GetTitle(), task->GetName());
 
-    fFM = new TFileMerger(kTRUE);
-    fFM->OutputFile(Form("merge/TRD.Task%s.root",  task->GetName()));
-    
-    Int_t idir = 0;
-    while(idir<ndir){
-      fFM->AddFile(Form("./TRD.Task%s.root",  task->GetName()));
-      idir++;
+     // setup filelist
+    TString pathname(dir ? "." : gSystem->ExpandPathName("$PWD"));
+    TString filestring((const Char_t*) pyshell->Eval(Form("commands.getstatusoutput(\"find %s | grep TRD.Task%s.root\")[1]", pathname.Data(), task->GetName())));
+    TObjArray *filenames = filestring.Tokenize("\n");
+    Int_t nFiles = filenames->GetEntriesFast();
+    if(!nFiles){
+      printf("No Files found for Task %s\n", task->GetName());
+      delete task;
+      delete ctask;
+      continue;
     }
-    fFM->Merge();
-    delete fFM;
-    task->Load(Form("merge/TRD.Task%s.root", task->GetName()));
-    task->PostProcess();
+
+    if(nFiles>1){
+      fFM = new(fFM) TFileMerger(kTRUE);
+      fFM->OutputFile(Form("merge/TRD.Task%s.root",  task->GetName()));
+      for(Int_t ifile = 0; ifile < nFiles; ifile++){
+        TString filename = (dynamic_cast<TObjString *>(filenames->UncheckedAt(ifile)))->String();
+        if(filename.Contains("merge")) continue;
+        printf("\tProcessing %s ...\n", filename.Data());
+        fFM->AddFile(filename.Data());
+      }
+      fFM->Merge();
+      fFM->~TFileMerger();
+      task->Load(Form("%s/merge/TRD.Task%s.root",gSystem->ExpandPathName("$PWD"), task->GetName()));
+    } else task->Load((dynamic_cast<TObjString *>(filenames->UncheckedAt(0)))->String().Data());
+
+
     if(!(fContainer = task->Container())) {
       delete task;
       delete ctask;
       continue;
     } 
+    
+    task->PostProcess();
     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
-      Int_t ifirst, ilast;
-      task->GetRefFigure(ipic, ifirst, ilast);
+      TCanvas *c = new TCanvas("c", "", 500, 500);
+      Int_t ifirst, ilast; Option_t *opt;
+      TH1 *h = 0x0; TGraph *g = 0x0;
+      task->GetRefFigure(ipic, ifirst, ilast, opt);
       if(!(o = fContainer->At(ifirst))) continue;
       
       if(o->InheritsFrom("TH1")){ 
@@ -87,9 +148,12 @@ void makeResults(Char_t *dir=".")
           g->Draw("pl");
         }
       }
-      if(gPad) gPad->SaveAs(Form("%s_fig%d.gif", task->GetName(), ipic));
+      c->SaveAs(Form("%s_fig%d.gif", task->GetName(), ipic));
+      delete c;
     }
     delete task;
     delete ctask;
   }
-}
\ No newline at end of file
+  delete pyshell;
+}
+