Added possibility to save canvases created by Terminate as pictures.
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 18 Nov 2009 08:38:36 +0000 (08:38 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 18 Nov 2009 08:38:36 +0000 (08:38 +0000)
ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisManager.h

index 8f94c6d..d34a434 100644 (file)
@@ -36,6 +36,7 @@
 #include <TSystem.h>
 #include <TROOT.h>
 #include <TCanvas.h>
+#include <TStopwatch.h>
 
 #include "AliAnalysisSelector.h"
 #include "AliAnalysisGrid.h"
@@ -712,12 +713,33 @@ void AliAnalysisManager::Terminate()
   // the results graphically.
    if (fDebug > 0) printf("->AliAnalysisManager::Terminate()\n");
    AliAnalysisTask *task;
+   AliAnalysisDataContainer *output;
    TIter next(fTasks);
+   TStopwatch timer;
    // Call Terminate() for tasks
-   while ((task=(AliAnalysisTask*)next())) task->Terminate();
+   while ((task=(AliAnalysisTask*)next())) {
+      // Save all the canvases produced by the Terminate
+      TString pictname = Form("%s_%s", task->GetName(), task->ClassName());
+      Int_t istart = gROOT->GetListOfCanvases()->GetEntries()-1;
+      task->Terminate();
+      if (TObject::TestBit(kSaveCanvases)) {
+         timer.Start();
+         while (timer.CpuTime()<5) {
+            timer.Continue();
+            gSystem->ProcessEvents();
+         }   
+         Int_t iend = gROOT->GetListOfCanvases()->GetEntries()-1;
+         if (istart == iend) continue;
+         TCanvas *canvas;
+         for (Int_t ipict=0; ipict<iend-istart; ipict++) {
+            canvas = (TCanvas*)gROOT->GetListOfCanvases()->At(istart+ipict);
+            if (!canvas) continue;         
+            canvas->SaveAs(Form("%s_%02d.gif", pictname.Data(),ipict));
+         }   
+      }
+   }   
    //
    TIter next1(fOutputs);
-   AliAnalysisDataContainer *output;
    while ((output=(AliAnalysisDataContainer*)next1())) {
       // Special outputs or grid files have the files already closed and written.
       if (fMode == kGridAnalysis) continue;
index bd1794e..1ffcc6e 100644 (file)
@@ -48,7 +48,8 @@ enum EAliAnalysisExecMode {
 enum EAliAnalysisFlags {
    kEventLoop        = BIT(14),
    kDisableBranches  = BIT(15),
-   kUseDataSet       = BIT(16)
+   kUseDataSet       = BIT(16),
+   kSaveCanvases     = BIT(17)
 };   
 
    AliAnalysisManager(const char *name = "mgr", const char *title="");
@@ -104,6 +105,7 @@ enum EAliAnalysisFlags {
    void                SetEventPool(AliVEventPool* epool) {fEventPool = epool;}
    void                SetNSysInfo(Long64_t nevents) {fNSysInfo = nevents;}
    void                SetSelector(AliAnalysisSelector *sel) {fSelector = sel;}
+   void                SetSaveCanvases(Bool_t flag=kTRUE) {TObject::SetBit(kSaveCanvases,flag);}
    AliVEventHandler*   GetInputEventHandler()   {return fInputEventHandler;}
    AliVEventHandler*   GetOutputEventHandler()  {return fOutputEventHandler;}
    AliVEventHandler*   GetMCtruthEventHandler() {return fMCtruthEventHandler;}