- Added new input parameters in AliAnalysisManager::StartAnalysis(const char *type...
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 4 Dec 2007 14:08:03 +0000 (14:08 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 4 Dec 2007 14:08:03 +0000 (14:08 +0000)
- System info (CPU and memory usage) can be collected every N events using AliAnalysisManager::SetNSysInfo(N)
Works only in local case. Two plots drawn based on the syswatch.log file. The full tree saved in syswatch.root file

ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisManager.h

index 7b9bf0f..975bc28 100644 (file)
 #include <TChain.h>
 #include <TSystem.h>
 #include <TROOT.h>
+#include <TCanvas.h>
 
 #include "AliAnalysisTask.h"
 #include "AliAnalysisDataContainer.h"
 #include "AliAnalysisDataSlot.h"
 #include "AliVEventHandler.h"
+#include "AliSysInfo.h"
 #include "AliAnalysisManager.h"
 
 ClassImp(AliAnalysisManager)
@@ -48,10 +50,11 @@ AliAnalysisManager *AliAnalysisManager::fgAnalysisManager = NULL;
 AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
                    :TNamed(name,title),
                     fTree(NULL),
-                   fInputEventHandler(NULL),
-                   fOutputEventHandler(NULL),
-                   fMCtruthEventHandler(NULL),
+                    fInputEventHandler(NULL),
+                    fOutputEventHandler(NULL),
+                    fMCtruthEventHandler(NULL),
                     fCurrentEntry(-1),
+                    fNSysInfo(0),
                     fMode(kLocalAnalysis),
                     fInitOK(kFALSE),
                     fDebug(0),
@@ -77,10 +80,11 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
 AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
                    :TNamed(other),
                     fTree(NULL),
-                   fInputEventHandler(NULL),
-                   fOutputEventHandler(NULL),
-                   fMCtruthEventHandler(NULL),
+                    fInputEventHandler(NULL),
+                    fOutputEventHandler(NULL),
+                    fMCtruthEventHandler(NULL),
                     fCurrentEntry(-1),
+                    fNSysInfo(0),
                     fMode(other.fMode),
                     fInitOK(other.fInitOK),
                     fDebug(other.fDebug),
@@ -112,6 +116,7 @@ AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& othe
       fMCtruthEventHandler = other.fMCtruthEventHandler;
       fTree       = NULL;
       fCurrentEntry = -1;
+      fNSysInfo   = other.fNSysInfo;
       fMode       = other.fMode;
       fInitOK     = other.fInitOK;
       fDebug      = other.fDebug;
@@ -450,7 +455,6 @@ void AliAnalysisManager::UnpackOutput(TList *source)
          callEnv.Execute(output->GetData());
       }
       output->GetData()->Write();
-      file->Close();
       if (opwd) opwd->cd();
    }
    if (fDebug > 1) {
@@ -478,6 +482,47 @@ void AliAnalysisManager::Terminate()
    if (fInputEventHandler)   fInputEventHandler  ->TerminateIO();
    if (fOutputEventHandler)  fOutputEventHandler ->TerminateIO();
    if (fMCtruthEventHandler) fMCtruthEventHandler->TerminateIO();
+   TIter next1(fOutputs);
+   AliAnalysisDataContainer *output;
+   while ((output=(AliAnalysisDataContainer*)next1())) {
+      // Close all files at output
+      const char *filename = output->GetFileName();
+      if (!(strcmp(filename, "default"))) {
+         if (fOutputEventHandler) filename = fOutputEventHandler->GetOutputFileName();
+      }
+      
+      if (!filename || !strlen(filename)) continue;
+      TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+      if (!file || file->IsZombie()) continue;
+      file->Close();
+   }   
+
+   Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
+   if (getsysInfo) {
+      TDirectory *cdir = gDirectory;
+      TFile f("syswatch.root", "RECREATE");
+      if (!f.IsZombie()) {
+         TTree *tree = AliSysInfo::MakeTree("syswatch.log");
+         tree->SetMarkerStyle(kCircle);
+         tree->SetMarkerColor(kBlue);
+         tree->SetMarkerSize(0.5);
+         if (!gROOT->IsBatch()) {
+            tree->SetAlias("event", "id0");
+            tree->SetAlias("memUSED", "mi.fMemUsed");
+            tree->SetAlias("userCPU", "pI.fCpuUser");
+            TCanvas *c = new TCanvas("SysInfo","SysInfo",10,10,800,600);
+            c->Divide(2,1,0.01,0.01);
+            c->cd(1);
+            tree->Draw("memUSED:event","","", 1234567890, 0);
+            c->cd(2);
+            tree->Draw("userCPU:event","","", 1234567890, 0);
+         }   
+         tree->Write();
+         f.Close();
+         delete tree;
+      }
+      if (cdir) cdir->cd();
+   }      
 }
 
 //______________________________________________________________________________
@@ -516,7 +561,10 @@ AliAnalysisDataContainer *AliAnalysisManager::CreateContainer(const char *name,
          break;
       case kOutputContainer:
          fOutputs->Add(cont);
-         if (filename && strlen(filename)) cont->SetFileName(filename);
+         if (filename && strlen(filename)) {
+            cont->SetFileName(filename);
+            cont->SetDataOwned(kFALSE);  // data owned by the file
+         }   
          break;
       case kExchangeContainer:
          break;   
@@ -660,6 +708,13 @@ Bool_t AliAnalysisManager::InitAnalysis()
 void AliAnalysisManager::PrintStatus(Option_t *option) const
 {
 // Print task hierarchy.
+   if (!fInitOK) {
+      Info("PrintStatus", "Analysis manager %s not initialized : call InitAnalysis() first", GetName());
+      return;
+   }   
+   Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
+   if (getsysInfo)
+      Info("PrintStatus", "System information will be collected each %lld events", fNSysInfo);
    TIter next(fTopTasks);
    AliAnalysisTask *task;
    while ((task=(AliAnalysisTask*)next()))
@@ -674,9 +729,10 @@ void AliAnalysisManager::ResetAnalysis()
 }
 
 //______________________________________________________________________________
-void AliAnalysisManager::StartAnalysis(const char *type, TTree *tree)
+void AliAnalysisManager::StartAnalysis(const char *type, TTree *tree, Long64_t nentries, Long64_t firstentry)
 {
 // Start analysis for this manager. Analysis task can be: LOCAL, PROOF or GRID.
+// Process nentries starting from firstentry
    if (!fInitOK) {
       Error("StartAnalysis","Analysis manager was not initialized !");
       return;
@@ -706,7 +762,12 @@ void AliAnalysisManager::StartAnalysis(const char *type, TTree *tree)
       SetEventLoop(kTRUE);
    }   
 
-   TChain *chain = dynamic_cast<TChain*>(tree);
+   TChain *chain = 0;
+   TString ttype = "TTree";
+   if (tree->IsA() == TChain::Class()) {
+      chain = (TChain*)tree;
+      ttype = "TChain";
+   }   
 
    // Initialize locally all tasks
    TIter next(fTasks);
@@ -731,11 +792,10 @@ void AliAnalysisManager::StartAnalysis(const char *type, TTree *tree)
             return;
          } 
          // Run tree-based analysis via AliAnalysisSelector  
-//         gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/AliAnalysisSelector.cxx+");
          cout << "===== RUNNING LOCAL ANALYSIS " << GetName() << " ON TREE " << tree->GetName() << endl;
          sprintf(line, "AliAnalysisSelector *selector = new AliAnalysisSelector((AliAnalysisManager*)0x%lx);",(ULong_t)this);
          gROOT->ProcessLine(line);
-         sprintf(line, "((TTree*)0x%lx)->Process(selector);",(ULong_t)tree);
+         sprintf(line, "((%s*)0x%lx)->Process(selector, \"\",%lld, %lld);",ttype.Data(),(ULong_t)tree, nentries, firstentry);
          gROOT->ProcessLine(line);
          break;
       case kProofAnalysis:
@@ -748,7 +808,7 @@ void AliAnalysisManager::StartAnalysis(const char *type, TTree *tree)
          if (chain) {
             chain->SetProof();
             cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON CHAIN " << chain->GetName() << endl;
-            chain->Process("AliAnalysisSelector");
+            chain->Process("AliAnalysisSelector", "", nentries, firstentry);
          } else {
             printf("StartAnalysis: no chain\n");
             return;
@@ -763,6 +823,10 @@ void AliAnalysisManager::StartAnalysis(const char *type, TTree *tree)
 void AliAnalysisManager::ExecAnalysis(Option_t *option)
 {
 // Execute analysis.
+   static Long64_t ncalls = 0;
+   Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
+   if (getsysInfo && ncalls==0) AliSysInfo::AddStamp("Start", (Int_t)ncalls);
+   ncalls++;
    if (!fInitOK) {
      Error("ExecAnalysis", "Analysis manager was not initialized !");
       return;
@@ -801,7 +865,9 @@ void AliAnalysisManager::ExecAnalysis(Option_t *option)
       if (fInputEventHandler)   fInputEventHandler  ->FinishEvent();
       if (fOutputEventHandler)  fOutputEventHandler ->FinishEvent();
       if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
-//
+      // Gather system information if requested
+      if (getsysInfo && ((ncalls%fNSysInfo)==0)) 
+         AliSysInfo::AddStamp(Form("Event#%lld",ncalls),(Int_t)ncalls);
       return;
    }   
    // The event loop is not controlled by TSelector   
index 5eed139..0487656 100644 (file)
@@ -51,7 +51,8 @@ enum EAliAnalysisFlags {
    AliAnalysisManager(const AliAnalysisManager& other);
    AliAnalysisManager& operator=(const AliAnalysisManager& other);
    
-   void                StartAnalysis(const char *type="local", TTree *tree=0);
+   // Management
+   void                StartAnalysis(const char *type="local", TTree *tree=0, Long64_t nentries=1234567890, Long64_t firstentry=0);
 
    virtual void        Init(TTree *tree);   
    virtual Bool_t      Notify();
@@ -81,9 +82,11 @@ enum EAliAnalysisFlags {
    void                SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
    void                SetDebugLevel(UInt_t level) {fDebug = level;}
    void                SetDisableBranches(Bool_t disable=kTRUE) {TObject::SetBit(kDisableBranches,disable);}
+   void                SetCollectSysInfoEach(Int_t nevents=0) {fNSysInfo = nevents;}
    void                SetInputEventHandler(AliVEventHandler*  handler)  {fInputEventHandler   = handler;}
    void                SetOutputEventHandler(AliVEventHandler*  handler) {fOutputEventHandler  = handler;}
    void                SetMCtruthEventHandler(AliVEventHandler* handler) {fMCtruthEventHandler = handler;}
+   void                SetNSysInfo(Long64_t nevents) {fNSysInfo = nevents;}
    AliVEventHandler*   GetInputEventHandler()   {return fInputEventHandler;}
    AliVEventHandler*   GetOutputEventHandler()  {return fOutputEventHandler;}
    AliVEventHandler*   GetMCtruthEventHandler() {return fMCtruthEventHandler;}
@@ -124,6 +127,7 @@ private:
    AliVEventHandler       *fOutputEventHandler;  //  Optional common output event handler
    AliVEventHandler       *fMCtruthEventHandler; //  Optional common MC Truth event handler
    Long64_t                fCurrentEntry;        //! Current processed entry in the tree
+   Long64_t                fNSysInfo;            // Event frequency for collecting system information
    EAliAnalysisExecMode    fMode;                // Execution mode
    Bool_t                  fInitOK;              // Initialisation done
    UInt_t                  fDebug;               // Debug level
@@ -135,6 +139,6 @@ private:
    TObjArray              *fOutputs;             // List of containers with results
 
    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
-   ClassDef(AliAnalysisManager,1)  // Analysis manager class
+   ClassDef(AliAnalysisManager,2)  // Analysis manager class
 };   
 #endif