Added separate flag to mark that the LocalInit phase was done + method AliAnalysisMan...
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 7 Nov 2011 10:13:02 +0000 (10:13 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 7 Nov 2011 10:13:02 +0000 (10:13 +0000)
ANALYSIS/AliAnalysisAlien.cxx
ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisManager.h

index 3f075c2..ebb2053 100644 (file)
@@ -598,6 +598,7 @@ Bool_t AliAnalysisAlien::GenerateTrain(const char *name)
    if (!LoadModules()) return kFALSE;
    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
    if (!mgr->InitAnalysis()) return kFALSE;
+   mgr->RunLocalInit();
    mgr->PrintStatus();
    Int_t productionMode = fProductionMode;
    SetProductionMode();
@@ -634,6 +635,7 @@ Bool_t AliAnalysisAlien::GenerateTest(const char *name, const char *modname)
    } else if (!LoadModules()) return kFALSE;
    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
    if (!mgr->InitAnalysis()) return kFALSE;
+   mgr->RunLocalInit();
    mgr->PrintStatus();
    SetLocalTest(kTRUE);
    Int_t productionMode = fProductionMode;
index 8bb9aff..7fbad0c 100644 (file)
@@ -1513,6 +1513,22 @@ void AliAnalysisManager::ResetAnalysis()
 }
 
 //______________________________________________________________________________
+void AliAnalysisManager::RunLocalInit()
+{
+// Run LocalInit method for all tasks.
+   TDirectory *cdir = gDirectory;
+   if (IsTrainInitialized()) return;
+   TIter nextTask(fTasks);
+   AliAnalysisTask *task;
+   while ((task=(AliAnalysisTask*)nextTask())) {
+      gROOT->cd();
+      task->LocalInit();
+   }
+   cdir->cd();
+   TObject::SetBit(kTasksInitialized, kTRUE);
+}   
+
+//______________________________________________________________________________
 Long64_t AliAnalysisManager::StartAnalysis(const char *type, Long64_t nentries, Long64_t firstentry)
 {
 // Start analysis having a grid handler.
@@ -1549,11 +1565,7 @@ Long64_t AliAnalysisManager::StartAnalysis(const char *type, TTree * const tree,
    TString anaType = type;
    anaType.ToLower();
    fMode = kLocalAnalysis;
-   Bool_t runlocalinit = kTRUE;
-   if (anaType.Contains("file")) {
-      runlocalinit = kFALSE;
-      fIsRemote = kTRUE;
-   }   
+   if (anaType.Contains("file"))      fIsRemote = kTRUE;
    if (anaType.Contains("proof"))     fMode = kProofAnalysis;
    else if (anaType.Contains("grid")) fMode = kGridAnalysis;
    else if (anaType.Contains("mix"))  fMode = kMixingAnalysis;
@@ -1570,12 +1582,7 @@ Long64_t AliAnalysisManager::StartAnalysis(const char *type, TTree * const tree,
          // Write analysis manager in the analysis file
          cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
          // run local task configuration
-         TIter nextTask(fTasks);
-         AliAnalysisTask *task;
-         while ((task=(AliAnalysisTask*)nextTask())) {
-            task->LocalInit();
-            gROOT->cd();
-         }
+         RunLocalInit();
          if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
             Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
             cdir->cd();
@@ -1621,13 +1628,7 @@ Long64_t AliAnalysisManager::StartAnalysis(const char *type, TTree * const tree,
    // Initialize locally all tasks (happens for all modes)
    TIter next(fTasks);
    AliAnalysisTask *task;
-   if (runlocalinit) {
-      while ((task=(AliAnalysisTask*)next())) {
-         task->LocalInit();
-         gROOT->cd();
-      }
-      if (getsysInfo) AliSysInfo::AddStamp("LocalInit_all", 0);
-   }   
+   RunLocalInit();
    
    switch (fMode) {
       case kLocalAnalysis:
@@ -1809,12 +1810,8 @@ Long64_t AliAnalysisManager::StartAnalysis(const char *type, const char *dataset
    }   
 
    // Initialize locally all tasks
-   TIter next(fTasks);
-   AliAnalysisTask *task;
-   while ((task=(AliAnalysisTask*)next())) {
-      task->LocalInit();
-   }
-   
+   RunLocalInit();
+      
    line = Form("gProof->AddInput((TObject*)%p);", this);
    gROOT->ProcessLine(line);
    Long_t retv;
index 2ec2083..5d3ce14 100644 (file)
@@ -63,7 +63,8 @@ enum EAliAnalysisFlags {
    kExternalLoop     = BIT(18),
    kSkipTerminate    = BIT(19),
    kUseProgressBar   = BIT(20),
-   kTrueNotify       = BIT(21)
+   kTrueNotify       = BIT(21),
+   kTasksInitialized = BIT(22)
 };   
 
    AliAnalysisManager(const char *name = "mgr", const char *title="");
@@ -130,6 +131,7 @@ enum EAliAnalysisFlags {
    Bool_t              IsRemote() const           {return fIsRemote;}
    Bool_t              IsUsingDataSet() const     {return TObject::TestBit(kUseDataSet);}
    void                LoadBranch(const char *n)  { if(fAutoBranchHandling) return; DoLoadBranch(n); }
+   void                RunLocalInit();
    void                SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
    void                SetAutoBranchLoading(Bool_t b) { fAutoBranchHandling = b; }
    void                SetCurrentEntry(Long64_t entry)            {fCurrentEntry = entry;}
@@ -180,6 +182,7 @@ enum EAliAnalysisFlags {
    void                 CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted);
    Bool_t               InitAnalysis();
    Bool_t               IsInitialized() const {return fInitOK;}
+   Bool_t               IsTrainInitialized() const {return TObject::TestBit(kTasksInitialized);}
    Bool_t               IsExternalLoop() const {return TObject::TestBit(kExternalLoop);}
    Bool_t               IsEventLoop() const {return TObject::TestBit(kEventLoop);}
    Bool_t               IsSkipTerminate() const {return TObject::TestBit(kSkipTerminate);}