From Mihaela: Added possibility to have more than one friend chains to AOD. Usage...
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 29 Aug 2013 07:44:57 +0000 (07:44 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 29 Aug 2013 07:44:57 +0000 (07:44 +0000)
ANALYSIS/AliAnalysisAlien.cxx

index a3c6672e0d29002c9cbf3d861c34c79ff787e3fa..b0579ceda09b8bc26cddb3be5c3bd029853cc4e0 100644 (file)
@@ -2314,8 +2314,21 @@ TChain *AliAnalysisAlien::GetChainForTestMode(const char *treeName) const
    TString streeName(treeName);
    if (IsUseMCchain()) streeName = "TE";
    TChain *chain = new TChain(streeName);
-   TChain *chainFriend = 0;
-   if (!fFriendChainName.IsNull()) chainFriend = new TChain(streeName);       
+   TList *friends = new TList();
+   TChain *cfriend = 0;
+   if (!fFriendChainName.IsNull()) {
+      TObjArray *list = fFriendChainName.Tokenize(" ");
+      TIter next(list);
+      TObjString *str;
+      while((str=(TObjString*)next())) {
+         cfriend = new TChain(streeName, str->GetName());
+         friends->Add(cfriend);
+         chain->AddFriend(cfriend);
+      }
+      delete list;
+   } 
+   TString bpath;
+   TIter nextfriend(friends);
    while (in.good())
    {
       in >> line;
@@ -2329,16 +2342,22 @@ TChain *AliAnalysisAlien::GetChainForTestMode(const char *treeName) const
          if (!fFriendChainName.IsNull()) {
             if (esdFile.Index("#") > -1)
                esdFile.Remove(esdFile.Index("#"));
-            esdFile = gSystem->DirName(esdFile);
-            esdFile += "/" + fFriendChainName;
-            file = TFile::Open(esdFile);
-            if (file && !file->IsZombie()) {
-               file->Close();
-               chainFriend->Add(esdFile);
-            } else {
-               Fatal("GetChainForTestMode", "Cannot open friend file: %s", esdFile.Data());
-               return 0;
-            }   
+            bpath = gSystem->DirName(esdFile);
+            bpath += "/";
+            TString fileFriend;
+            nextfriend.Reset();
+            while ((cfriend=(TChain*)nextfriend())) {
+               fileFriend = bpath;
+               fileFriend += cfriend->GetTitle();
+               file = TFile::Open(fileFriend);
+               if (file && !file->IsZombie()) {
+                  file->Close();
+                  cfriend->Add(fileFriend);
+               } else {
+                  Fatal("GetChainForTestMode", "Cannot open friend file: %s", fileFriend.Data());
+                  return 0;
+               } 
+            }     
          }
       } else {
          Error("GetChainforTestMode", "Skipping un-openable file: %s", esdFile.Data());
@@ -2348,11 +2367,10 @@ TChain *AliAnalysisAlien::GetChainForTestMode(const char *treeName) const
    if (!chain->GetListOfFiles()->GetEntries()) {
        Error("GetChainForTestMode", "No file from %s could be opened", fFileForTestMode.Data());
        delete chain;
-       delete chainFriend;
+       friends->Delete();
+       delete friends;
        return NULL;
    }
-//    chain->ls();
-   if (!fFriendChainName.IsNull()) chain->AddFriend(chainFriend);
    return chain;
 }    
 
@@ -2606,6 +2624,10 @@ void AliAnalysisAlien::SetFriendChainName(const char *name, const char *libnames
    // Set file name for the chain of friends and optionally additional libs to be loaded.
    // Libs should be separated by blancs.
    fFriendChainName = name;
+   fFriendChainName.ReplaceAll(",", " ");
+   fFriendChainName.Strip();
+   fFriendChainName.ReplaceAll("  ", " ");
+   
    fFriendLibs = libnames;
    if (fFriendLibs.Length()) {
      if(!fFriendLibs.Contains(".so"))
@@ -4196,8 +4218,20 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          out << "   }" << endl;
          out << "   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();" << endl;
          out << "   TChain *chain = new TChain(treename);" << endl;
-         if(fFriendChainName!="") {
-            out << "   TChain *chainFriend = new TChain(treename);" << endl;
+         if(!fFriendChainName.IsNull()) {
+            out << "   TList *friends = new TList();" << endl;
+            out << "   TIter nextfriend(friends);" << endl;
+            out << "   TChain *cfriend = 0;" << endl;
+            TObjArray *list = fFriendChainName.Tokenize(" ");
+            TIter next(list);
+            TObjString *str;
+            while((str=(TObjString*)next())) {
+               out << "   cfriend = new TChain(treename, \"" << str->GetName() << "\");" << endl;
+               out << "   friends->Add(cfriend);" << endl;
+               out << "   chain->AddFriend(cfriend);" << endl;
+            }
+            delete list;   
+//            out << "   TChain *chainFriend = new TChain(treename);" << endl;
          }
          out << "   coll->Reset();" << endl;
          out << "   while (coll->Next()) {" << endl;
@@ -4211,19 +4245,24 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          out << "         }" << endl;
          out << "      }" << endl;
          out << "      chain->Add(filename);" << endl;
-         if(fFriendChainName!="") {
-            out << "      TString fileFriend=coll->GetTURL(\"\");" << endl;
-            out << "      if (fileFriend.Index(\"#\") > -1) fileFriend.Remove(fileFriend.Index(\"#\"));" << endl;
-            out << "      fileFriend = gSystem->DirName(fileFriend);" << endl;
-            out << "      fileFriend += \"/\";" << endl;
-            out << "      fileFriend += \"" << fFriendChainName << "\";";
-            out << "      TFile *file = TFile::Open(fileFriend);" << endl;
-            out << "      if (file) {" << endl;
-            out << "         file->Close();" << endl;
-            out << "         chainFriend->Add(fileFriend.Data());" << endl;
-            out << "      } else {" << endl;
-            out << "         ::Fatal(\"CreateChain\", \"Cannot open friend file: %s\", fileFriend.Data());" << endl;
-            out << "         return 0;" << endl;
+         if(!fFriendChainName.IsNull()) {
+            out << "      TString bpath=coll->GetTURL(\"\");" << endl;
+            out << "      if (bpath.Index(\"#\") > -1) bpath.Remove(bpath.Index(\"#\"));" << endl;
+            out << "      bpath = gSystem->DirName(bpath);" << endl;
+            out << "      bpath += \"/\";" << endl;
+            out << "      TString fileFriend;" << endl;
+            out << "      nextfriend.Reset();" << endl;
+            out << "      while ((cfriend=(TChain*)nextfriend())) {" << endl;
+            out << "         fileFriend = bpath;" << endl;
+            out << "         fileFriend += cfriend->GetTitle();" << endl;
+            out << "         TFile *file = TFile::Open(fileFriend);" << endl;
+            out << "         if (file) {" << endl;
+            out << "            file->Close();" << endl;
+            out << "            cfriend->Add(fileFriend.Data());" << endl;
+            out << "         } else {" << endl;
+            out << "            ::Fatal(\"CreateChain\", \"Cannot open friend file: %s\", fileFriend.Data());" << endl;
+            out << "            return 0;" << endl;
+            out << "         }" << endl;
             out << "      }" << endl;
          }
          out << "   }" << endl;
@@ -4231,9 +4270,6 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          out << "      ::Error(\"CreateChain\", \"No tree found from collection %s\", xmlfile);" << endl;
          out << "      return NULL;" << endl;
          out << "   }" << endl;
-         if(fFriendChainName!="") {
-            out << "   chain->AddFriend(chainFriend);" << endl;
-         }
          out << "   return chain;" << endl;
          out << "}" << endl << endl;
       }