Added new static method AliAnalysisManager::GetRunFromAlienPath() that extracts the...
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 4 Oct 2010 12:52:59 +0000 (12:52 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 4 Oct 2010 12:52:59 +0000 (12:52 +0000)
Use mgr->GetRunFromPath() in your task to get this.

ANALYSIS/AliAnalysisAlien.cxx
ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisManager.h

index b0be730..9fb263c 100644 (file)
@@ -2910,11 +2910,6 @@ void AliAnalysisAlien::WriteAnalysisMacro()
       }   
       out << "// connect to AliEn and make the chain" << endl;
       out << "   if (!TGrid::Connect(\"alien://\")) return;" << endl;
-      if (IsUsingTags()) {
-         out << "   TChain *chain = CreateChainFromTags(\"wn.xml\", anatype);" << endl << endl;
-      } else {
-         out << "   TChain *chain = CreateChain(\"wn.xml\", anatype);" << endl << endl;   
-      }   
       out << "// read the analysis manager from file" << endl;
       TString analysisFile = fExecutable;
       analysisFile.ReplaceAll(".sh", ".root");
@@ -2942,6 +2937,11 @@ void AliAnalysisAlien::WriteAnalysisMacro()
                out << "   AliLog::SetGlobalLogLevel(AliLog::kError);" << endl;
          }
       }   
+      if (IsUsingTags()) {
+         out << "   TChain *chain = CreateChainFromTags(\"wn.xml\", anatype);" << endl << endl;
+      } else {
+         out << "   TChain *chain = CreateChain(\"wn.xml\", anatype);" << endl << endl;   
+      }   
       out << "   mgr->StartAnalysis(\"localfile\", chain);" << endl;
       out << "   timer.Stop();" << endl;
       out << "   timer.Print();" << endl;
@@ -2992,6 +2992,8 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          out << "TChain* CreateChain(const char *xmlfile, const char *type=\"ESD\")" << endl;
          out << "{" << endl;
          out << "// Create a chain using url's from xml file" << endl;
+         out << "   TString filename;" << endl;
+         out << "   Int_t run = 0;" << endl;
          out << "   TString treename = type;" << endl;
          out << "   treename.ToLower();" << endl;
          out << "   treename += \"Tree\";" << endl;
@@ -3003,13 +3005,23 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          out << "      ::Error(\"CreateChain\", \"Cannot create an AliEn collection from %s\", xmlfile);" << endl;
          out << "      return NULL;" << endl;
          out << "   }" << endl;
+         out << "   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();" << endl;
          out << "   TChain *chain = new TChain(treename);" << endl;
          if(fFriendChainName!="") {
             out << "   TChain *chainFriend = new TChain(treename);" << endl;
          }
          out << "   coll->Reset();" << endl;
          out << "   while (coll->Next()) {" << endl;
-         out << "      chain->Add(coll->GetTURL(\"\"));" << endl;
+         out << "      filename = coll->GetTURL("");" << endl;
+         out << "      if (mgr) {" << endl;
+         out << "         Int_t nrun = AliAnalysisManager::GetRunFromAlienPath(filename);" << endl;
+         out << "         if (nrun && nrun != run) {" << endl;
+         out << "            printf(\"### Run number detected from chain: %d\\n\", nrun);" << endl;
+         out << "            mgr->SetRunFromPath(nrun);" << endl;
+         out << "            run = nrun;" << endl;
+         out << "         }" << endl;
+         out << "      }" << endl;
+         out << "      chain->Add(filename);" << endl;
          if(fFriendChainName!="") {
             out << "      TString fileFriend=coll->GetTURL(\"\");" << endl;
             out << "      fileFriend.ReplaceAll(\"AliAOD.root\",\""<<fFriendChainName.Data()<<"\");" << endl;
index a443ca7..dde4e73 100644 (file)
@@ -83,7 +83,8 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
                     fGridHandler(NULL),
                     fExtraFiles(""),
                     fAutoBranchHandling(kTRUE), 
-                    fTable()
+                    fTable(),
+                    fRunFromPath(0)
 {
 // Default constructor.
    fgAnalysisManager = this;
@@ -127,7 +128,8 @@ AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
                     fGridHandler(NULL),
                     fExtraFiles(),
                     fAutoBranchHandling(other.fAutoBranchHandling), 
-                    fTable()
+                    fTable(),
+                    fRunFromPath(0)
 {
 // Copy constructor.
    fTasks      = new TObjArray(*other.fTasks);
@@ -174,7 +176,8 @@ AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& othe
       fgCommonFileName = "AnalysisResults.root";
       fgAnalysisManager = this;
       fAutoBranchHandling = other.fAutoBranchHandling;
-      fTable.Clear("nodelete"); 
+      fTable.Clear("nodelete");
+      fRunFromPath = other.fRunFromPath;
    }
    return *this;
 }
@@ -208,7 +211,38 @@ Int_t AliAnalysisManager::GetEntry(Long64_t entry, Int_t getall)
      return entry;
    return fTree ? fTree->GetTree()->GetEntry(entry, getall) : 0;
 }
-   
+
+//______________________________________________________________________________
+Int_t AliAnalysisManager::GetRunFromAlienPath(const char *path)
+{
+// Attempt to extract run number from input data path. Works only for paths to
+// alice data in alien.
+//    sim:  /alice/sim/<production>/run_no/...
+//    data: /alice/data/year/period/000run_no/... (ESD or AOD)
+   TString s(path);
+   TString srun;
+   Int_t run = 0;
+   Int_t index = s.Index("/alice/sim");
+   if (index >= 0) {
+      for (Int_t i=0; i<3; i++) {
+         index = s.Index("/", index+1);
+         if (index<0) return 0;
+      }
+      srun = s(index+1,6);
+      run = atoi(srun);
+   }
+   index = s.Index("/alice/data");
+   if (index >= 0) {
+      for (Int_t i=0; i<4; i++) {
+         index = s.Index("/", index+1);
+         if (index<0) return 0;
+      }
+      srun = s(index+1,9);
+      run = atoi(srun);
+   }
+   return run;
+}   
+
 //______________________________________________________________________________
 Bool_t AliAnalysisManager::Init(TTree *tree)
 {
@@ -385,11 +419,11 @@ Bool_t AliAnalysisManager::Notify()
    }   
    
    if (fDebug > 1) printf("->AliAnalysisManager::Notify() file: %s\n", curfile->GetName());
+   Int_t run = AliAnalysisManager::GetRunFromAlienPath(curfile->GetName());
+   if (run) SetRunFromPath(run);
+   if (fDebug > 1) printf("   ### run found from path: %d\n", run); 
    TIter next(fTasks);
    AliAnalysisTask *task;
-   // Call Notify for all tasks
-   while ((task=(AliAnalysisTask*)next())) 
-      task->Notify();
        
    // Call Notify of the event handlers
    if (fInputEventHandler) {
@@ -404,6 +438,10 @@ Bool_t AliAnalysisManager::Notify()
        fMCtruthEventHandler->Notify(curfile->GetName());
    }
 
+   // Call Notify for all tasks
+   while ((task=(AliAnalysisTask*)next())) 
+      task->Notify();
+
    if (fDebug > 1) printf("<-AliAnalysisManager::Notify()\n");
    return kTRUE;
 }    
index 8cf3847..53bb19b 100644 (file)
@@ -100,6 +100,7 @@ enum EAliAnalysisFlags {
    TString             GetExtraFiles() const      {return fExtraFiles;}
    AliVEventPool*      GetEventPool()  const      {return fEventPool;}
    Bool_t              GetFileFromWrapper(const char *filename, const TList *source);
+   static Int_t        GetRunFromAlienPath(const char *path);
    AliAnalysisGrid*    GetGridHandler()           {return fGridHandler;}
    TObjArray          *GetInputs() const          {return fInputs;}
    AliVEventHandler*   GetInputEventHandler() const   {return fInputEventHandler;}
@@ -107,6 +108,7 @@ enum EAliAnalysisFlags {
    AliVEventHandler*   GetOutputEventHandler() const  {return fOutputEventHandler;}
    TObjArray          *GetOutputs() const         {return fOutputs;}
    TObjArray          *GetParamOutputs() const    {return fParamCont;}
+   Int_t               GetRunFromPath() const     {return fRunFromPath;}
    TObjArray          *GetTasks() const           {return fTasks;}
    TObjArray          *GetTopTasks() const        {return fTopTasks;}
    TTree              *GetTree() const            {return fTree;}
@@ -129,6 +131,7 @@ enum EAliAnalysisFlags {
    void                SetMCtruthEventHandler(AliVEventHandler* const handler) {fMCtruthEventHandler = handler;}
    void                SetNSysInfo(Long64_t nevents)              {fNSysInfo = nevents;}
    void                SetOutputEventHandler(AliVEventHandler* const handler);
+   void                SetRunFromPath(Int_t run)                  {fRunFromPath = run;}
    void                SetSelector(AliAnalysisSelector * const sel)      {fSelector = sel;}
    void                SetSaveCanvases(Bool_t flag=kTRUE)         {TObject::SetBit(kSaveCanvases,flag);}
    void                SetSkipTerminate(Bool_t flag)              {TObject::SetBit(kSkipTerminate,flag);}
@@ -198,6 +201,7 @@ private:
    TString                 fExtraFiles;          // List of extra files to be merged
    Bool_t                  fAutoBranchHandling;  // def=kTRUE, turn off if you use LoadBranch
    THashTable              fTable;               // keep branch ptrs in case of manual branch loading
+   Int_t                   fRunFromPath;         // Run number retrieved from path to input data
 
    static TString          fgCommonFileName;     //! Common output file name (not streamed)
    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance