]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisAlien.cxx
Unintentional delete corrected.
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisAlien.cxx
index 1dc117915592c300104c9e2a38c5cb0e83d9c0a6..fe5c28092d7c76a354e2d917de2b1885b2bc160c 100644 (file)
@@ -20,6 +20,8 @@
 // a personalized JDL, finding and creating a dataset.
 //==============================================================================
 
+#include "AliAnalysisAlien.h"
+
 #include "Riostream.h"
 #include "TEnv.h"
 #include "TBits.h"
@@ -41,7 +43,7 @@
 #include "AliAnalysisManager.h"
 #include "AliVEventHandler.h"
 #include "AliAnalysisDataContainer.h"
-#include "AliAnalysisAlien.h"
+#include "AliMultiInputEventHandler.h"
 
 ClassImp(AliAnalysisAlien)
 
@@ -391,12 +393,35 @@ void AliAnalysisAlien::AddRunNumber(Int_t run)
    fRunNumbers += Form(fRunPrefix.Data(), run);
 }   
 
+//______________________________________________________________________________
+void AliAnalysisAlien::AddRunList(const char* runList)
+{
+// Add several runs into the list of runs; they are expected to be separated by a blank character.  
+  TString    sList = runList;
+  TObjArray *list  = sList.Tokenize(" ");
+  Int_t n = list->GetEntries();
+  for (Int_t i = 0; i < n; i++) {
+    TObjString *os = (TObjString*)list->At(i);
+    AddRunNumber(os->GetString().Atoi());
+  }
+  delete list;
+}
+
 //______________________________________________________________________________
 void AliAnalysisAlien::AddRunNumber(const char* run)
 {
 // Add a run number to the list of runs to be processed.
-   if (fRunNumbers.Length()) fRunNumbers += " ";
-   fRunNumbers += run;
+   TString runs = run;
+   TObjString *os;
+   TObjArray *arr = runs.Tokenize(" ");
+   TIter next(arr);
+   TString prefix; 
+   prefix.Append(fRunPrefix, fRunPrefix.Index("%d"));
+   while ((os=(TObjString*)next())){
+       if (fRunNumbers.Length()) fRunNumbers += " ";
+       fRunNumbers += Form("%s%s", prefix.Data(), os->GetString().Data());
+   }
+   delete arr;
 }   
 
 //______________________________________________________________________________
@@ -520,6 +545,10 @@ Bool_t AliAnalysisAlien::CheckInputData()
          Error("CkeckInputData", "AliEn path to base data directory must be set.\n = Use: SetGridDataDir()");
          return kFALSE;
       }
+      if (fMergeViaJDL) {
+         Error("CheckInputData", "Merging via jdl works only with run numbers, run range or provided xml");
+         return kFALSE;
+      }   
       Info("CheckInputData", "Analysis will make a single xml for base data directory %s",fGridDataDir.Data());
       if (fDataPattern.Contains("tag") && TestBit(AliAnalysisGrid::kTest))
          TObject::SetBit(AliAnalysisGrid::kUseTags, kTRUE); // ADDED (fix problem in determining the tag usage in test mode) 
@@ -755,7 +784,7 @@ Bool_t AliAnalysisAlien::CreateDataset(const char *pattern)
       TObjString *os;
       TIter next(arr);
       while ((os=(TObjString*)next())) {
-         path = Form("%s/%s ", fGridDataDir.Data(), os->GetString().Data());
+         path = Form("%s/%s/ ", fGridDataDir.Data(), os->GetString().Data());
          if (!DirectoryExists(path)) continue;
 //         CdWork();
          if (TestBit(AliAnalysisGrid::kTest)) file = "wn.xml";
@@ -996,6 +1025,8 @@ Bool_t AliAnalysisAlien::CreateJDL()
                   Error("CreateJDL", "Could not create alien output directory %s", fGridOutputDir.Data());
                   // error = kTRUE;
                }
+            } else {
+               Warning("CreateJDL", "#### Output directory %s exists! If this contains old data, jobs will fail with ERROR_SV !!! ###", fGridOutputDir.Data());
             }   
             gGrid->Cd(workdir);
          }   
@@ -1116,7 +1147,7 @@ Bool_t AliAnalysisAlien::CreateJDL()
          // Output archive for the merging jdl
          TString outputArchive;
          if (TestBit(AliAnalysisGrid::kDefaultOutputs)) {
-            outputArchive = "log_archive.zip:std*,*.stat@disk=1 ";
+            outputArchive = "log_archive.zip:std*@disk=1 ";
             // Add normal output files, extra files + terminate files
             TString files = GetListOfFiles("outextter");
             // Do not register merge excludes
@@ -1130,7 +1161,7 @@ Bool_t AliAnalysisAlien::CreateJDL()
                delete arr;
             }
             files.ReplaceAll(".root", "*.root");
-            outputArchive += Form("root_archive.zip:%s@disk=%d",files.Data(),fNreplicas);
+            outputArchive += Form("root_archive.zip:%s,*.stat@disk=%d",files.Data(),fNreplicas);
          } else {
             TString files = fOutputArchive;
             files.ReplaceAll(".root", "*.root"); // nreplicas etc should be already atttached by use
@@ -1366,12 +1397,12 @@ Bool_t AliAnalysisAlien::WriteJDL(Bool_t copy)
      sjdl1.Prepend("# Generated merging jdl \
                     \n# $1 = full alien path to output directory to be merged \
                     \n# $2 = merging stage \
-                    \n# $3 = xml made via: find <OutputDir> *Stage<n-1>/*root_archive.zip\n");
+                    \n# xml made via: find <OutputDir> *Stage<n-1>/*root_archive.zip\n");
      sjdl2.Prepend(Form("Jobtag = {\n   \"comment:%s_FinalMerging\"\n};\n", jobTag.Data()));
      sjdl2.Prepend("# Generated merging jdl \
                     \n# $1 = full alien path to output directory to be merged \
                     \n# $2 = merging stage \
-                    \n# $3 = xml made via: find <OutputDir> *Stage<n-1>/*root_archive.zip\n");
+                    \n# xml made via: find <OutputDir> *Stage<n-1>/*root_archive.zip\n");
    }
    index = sjdl1.Index("JDLVariables");
    if (index >= 0) sjdl1.Insert(index, "\n# JDL variables\n");
@@ -1673,10 +1704,10 @@ const char *AliAnalysisAlien::GetJobStatus(Int_t jobidstart, Int_t lastid, Int_t
    Int_t pid;
    for (Int_t ijob=0; ijob<nentries; ijob++) {
       status = (TGridJobStatus *)list->At(ijob);
-      pid = gROOT->ProcessLine(Form("atoi(((TAlienJobStatus*)0x%lx)->GetKey(\"queueId\"));", (ULong_t)status));
+      pid = gROOT->ProcessLine(Form("atoi(((TAlienJobStatus*)%p)->GetKey(\"queueId\"));", status));
       if (pid<jobidstart) continue;
       if (pid == lastid) {
-         gROOT->ProcessLine(Form("sprintf((char*)0x%lx,((TAlienJobStatus*)0x%lx)->GetKey(\"status\"));",(ULong_t)mstatus, (ULong_t)status));
+         gROOT->ProcessLine(Form("sprintf((char*)%p,((TAlienJobStatus*)%p)->GetKey(\"status\"));",mstatus, status));
       }   
       switch (status->GetStatus()) {
          case TGridJobStatus::kWAITING:
@@ -1856,6 +1887,7 @@ void AliAnalysisAlien::SetDefaults()
    fNreplicas                  = 2;
    fRunRange[0]                = 0;
    fRunRange[1]                = 0;
+   fRunPrefix                  = "%d";
    fNrunsPerMaster             = 1;
    fMaxMergeFiles              = 100;
    fRunNumbers                 = "";
@@ -1876,7 +1908,7 @@ void AliAnalysisAlien::SetDefaults()
    fDataPattern                = "*AliESDs.root";  // Can be like: *AliESDs.root, */pass1/*AliESDs.root, ...
    fFriendChainName            = "";
    fGridOutputDir              = "output";
-   fOutputArchive              = "log_archive.zip:std*,*.stat@disk=1 root_archive.zip:*.root@disk=2";
+   fOutputArchive              = "log_archive.zip:std*@disk=1 root_archive.zip:*.root@disk=2";
    fOutputFiles                = "";  // Like "AliAODs.root histos.root"
    fInputFormat                = "xml-single";
    fJDLName                    = "analysis.jdl";
@@ -1942,12 +1974,12 @@ Bool_t AliAnalysisAlien::CheckMergedFiles(const char *filename, const char *alie
       printf("### Submiting final merging stage %d\n", stage);
       TString finalJDL = jdl;
       finalJDL.ReplaceAll(".jdl", "_final.jdl");
-      TString query = Form("submit %s %s %d Stage_%d.xml", finalJDL.Data(), aliendir, stage, stage);
+      TString query = Form("submit %s %s %d", finalJDL.Data(), aliendir, stage);
       Int_t jobId = SubmitSingleJob(query);
       if (!jobId) return kFALSE;      
    } else {
       printf("### Submiting merging stage %d\n", stage);
-      TString query = Form("submit %s %s %d wn.xml", jdl, aliendir, stage);
+      TString query = Form("submit %s %s %d", jdl, aliendir, stage);
       Int_t jobId = SubmitSingleJob(query);
       if (!jobId) return kFALSE;           
    }
@@ -2194,7 +2226,7 @@ Bool_t AliAnalysisAlien::MergeOutputs()
       return kFALSE;
    }   
    // Get the output path
-   if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("/%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data());
+   if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data());
    if (!DirectoryExists(fGridOutputDir)) {
       Error("MergeOutputs", "Grid output directory %s not found. Terminate() will NOT be executed", fGridOutputDir.Data());
       return kFALSE;
@@ -2217,6 +2249,8 @@ Bool_t AliAnalysisAlien::MergeOutputs()
    }   
    // Make sure we change the temporary directory
    gSystem->Setenv("TMPDIR", gSystem->pwd());
+   // Set temporary compilation directory to current one
+   gSystem->SetBuildDir(gSystem->pwd(), kTRUE);   
    TObjArray *list = fOutputFiles.Tokenize(",");
    TIter next(list);
    TObjString *str;
@@ -2440,12 +2474,18 @@ Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEn
             }
             if (list) delete list;            
          }
-         if (!extraLibs.IsNull()) optionsList.Add(new TNamed("ALIROOT_EXTRA_LIBS",extraLibs.Data()));
+        if (!extraLibs.IsNull()) {
+          Info("StartAnalysis", "Adding extra libs: %s",extraLibs.Data());
+          optionsList.Add(new TNamed("ALIROOT_EXTRA_LIBS",extraLibs.Data()));
+        }
          // Check extra includes
          if (!fIncludePath.IsNull()) {
             TString includePath = fIncludePath;
             includePath.ReplaceAll(" ",":");
-            includePath.Strip(TString::kTrailing, ':');
+            includePath.ReplaceAll("$ALICE_ROOT/","");
+            includePath.ReplaceAll("${ALICE_ROOT}/","");
+            includePath.ReplaceAll("-I","");
+            includePath.Remove(TString::kTrailing, ':');
             Info("StartAnalysis", "Adding extra includes: %s",includePath.Data()); 
             optionsList.Add(new TNamed("ALIROOT_EXTRA_INCLUDES",includePath.Data()));
          }
@@ -2461,18 +2501,20 @@ Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEn
                printf("%s  %s\n", obj->GetName(), obj->GetTitle());
             }   
             if (!gROOT->ProcessLine(Form("gProof->UploadPackage(\"%s\");",alirootLite.Data()))
-              && !gROOT->ProcessLine(Form("gProof->EnablePackage(\"%s\", (TList*)0x%lx);",alirootLite.Data(),(ULong_t)&optionsList))) {
+              && !gROOT->ProcessLine(Form("gProof->EnablePackage(\"%s\", (TList*)%p);",alirootLite.Data(),&optionsList))) {
                   Info("StartAnalysis", "AliRootProofLite enabled");
             } else {                      
                Error("StartAnalysis", "There was an error trying to enable package AliRootProofLite.par");
                return kFALSE;
             }   
          } else {
-            if (gROOT->ProcessLine(Form("gProof->EnablePackage(\"VO_ALICE@AliRoot::%s\", (TList*)0x%lx);", 
-                                   fAliROOTVersion.Data(), (ULong_t)&optionsList))) {
-               Error("StartAnalysis", "There was an error trying to enable package VO_ALICE@AliRoot::%s", fAliROOTVersion.Data());
-               return kFALSE;
-            }         
+           if ( ! fAliROOTVersion.IsNull() ) {
+             if (gROOT->ProcessLine(Form("gProof->EnablePackage(\"VO_ALICE@AliRoot::%s\", (TList*)%p, kTRUE);", 
+                                         fAliROOTVersion.Data(), &optionsList))) {
+                Error("StartAnalysis", "There was an error trying to enable package VO_ALICE@AliRoot::%s", fAliROOTVersion.Data());
+                return kFALSE;
+             }
+           }
          }
          // Enable first par files from fAdditionalLibs
          if (!parLibs.IsNull()) {
@@ -2513,7 +2555,7 @@ Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEn
             TString spkg = package->GetName();
             spkg.ReplaceAll(".par", "");
             gSystem->Exec(TString::Format("rm -rf %s", spkg.Data()));
-            if (gROOT->ProcessLine(Form("gProof->UploadPackage(\"%s\");", package->GetName()))) {
+            if (!gROOT->ProcessLine(Form("gProof->UploadPackage(\"%s\");", package->GetName()))) {
                if (gROOT->ProcessLine(Form("gProof->EnablePackage(\"%s\",kTRUE);", package->GetName()))) {
                   Error("StartAnalysis", "There was an error trying to enable package %s", package->GetName());
                   return kFALSE;
@@ -2532,7 +2574,7 @@ Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEn
          TObjString *str;
          while((str=(TObjString*)next())) {
             gROOT->ProcessLine(Form("gProof->Load(\"%s+g\", kTRUE);", str->GetName()));
-         }   
+         }
          if (list) delete list;
       }
       if (testMode) {
@@ -2547,7 +2589,7 @@ Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEn
          }   
          TFileCollection *coll = new TFileCollection();
          coll->AddFromFile(fFileForTestMode);
-         gROOT->ProcessLine(Form("gProof->RegisterDataSet(\"test_collection\", (TFileCollection*)0x%lx, \"OV\");", (ULong_t)coll));
+         gROOT->ProcessLine(Form("gProof->RegisterDataSet(\"test_collection\", (TFileCollection*)%p, \"OV\");", coll));
          gROOT->ProcessLine("gProof->ShowDataSets()");
       }
       return kTRUE;
@@ -2565,8 +2607,8 @@ Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEn
          fOutputFiles += extra;
       }
       // Compose the output archive.
-      fOutputArchive = "log_archive.zip:std*,*.stat@disk=1 ";
-      fOutputArchive += Form("root_archive.zip:%s@disk=%d",fOutputFiles.Data(),fNreplicas);
+      fOutputArchive = "log_archive.zip:std*@disk=1 ";
+      fOutputArchive += Form("root_archive.zip:%s,*.stat@disk=%d",fOutputFiles.Data(),fNreplicas);
    }
 //   if (!fCloseSE.Length()) fCloseSE = gSystem->Getenv("alien_CLOSE_SE");
    if (TestBit(AliAnalysisGrid::kOffline)) {
@@ -2804,10 +2846,14 @@ Bool_t AliAnalysisAlien::Submit()
 Bool_t AliAnalysisAlien::SubmitMerging()
 {
 // Submit all merging jobs.
-   if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("/%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data());
+   if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data());
    gGrid->Cd(fGridOutputDir);
    TString mergeJDLName = fExecutable;
    mergeJDLName.ReplaceAll(".sh", "_merge.jdl");
+   if (!fInputFiles) {
+      Error("SubmitMerging", "You have to use explicit run numbers or run range to merge via JDL!");
+      return kFALSE;
+   }   
    Int_t ntosubmit = fInputFiles->GetEntries();
    for (Int_t i=0; i<ntosubmit; i++) {
       TString runOutDir = gSystem->BaseName(fInputFiles->At(i)->GetName());
@@ -2817,9 +2863,15 @@ Bool_t AliAnalysisAlien::SubmitMerging()
          printf("### Submitting merging job for run <%s>\n", runOutDir.Data());
          runOutDir = Form("%s/%s", fGridOutputDir.Data(), runOutDir.Data());
       } else {
-         // The output directory is the master number in 3 digits format
-         printf("### Submitting merging job for master <%03d>\n", i);
-         runOutDir = Form("%s/%03d",fGridOutputDir.Data(), i);
+         if (!fRunNumbers.Length() && !fRunRange[0]) {
+            // The output directory is the grid outdir
+            printf("### Submitting merging job for the full output directory %s.\n", fGridOutputDir.Data());
+            runOutDir = fGridOutputDir;
+         } else {
+            // The output directory is the master number in 3 digits format
+            printf("### Submitting merging job for master <%03d>\n", i);
+            runOutDir = Form("%s/%03d",fGridOutputDir.Data(), i);
+         }   
       }
       // Check now the number of merging stages.
       TObjArray *list = fOutputFiles.Tokenize(",");
@@ -2834,12 +2886,15 @@ Bool_t AliAnalysisAlien::SubmitMerging()
       }
       delete list;
       Bool_t done = CheckMergedFiles(outputFile, runOutDir, fMaxMergeFiles, mergeJDLName);
-      if (!done) return kFALSE;
+      if (!done && (i==ntosubmit-1)) return kFALSE;
+      if (!fRunNumbers.Length() && !fRunRange[0]) break;
    }
    if (!ntosubmit) return kTRUE;
-   Info("StartAnalysis", "\n#### STARTING AN ALIEN SHELL FOR YOU. EXIT WHEN YOUR MERGING JOBS HAVE FINISHED. #### \
-   \n You may exit at any time and terminate the job later using the option <terminate> but disabling SetMergeViaJDL\
-   \n ##################################################################################");
+   Info("StartAnalysis", "\n #### STARTING AN ALIEN SHELL FOR YOU. You can exit any time or inspect your jobs in a different shell.##########\
+                          \n Make sure your jobs are in a final state (you can resubmit failed ones via 'masterjob <id> resubmit ERROR_ALL')\
+                          \n Rerun in 'terminate' mode to submit all merging stages, each AFTER the previous one completed. The final merged \
+                          \n output will be written to your alien output directory, while separate stages in <Stage_n>. \
+                          \n ################################################################################################################");
    gSystem->Exec("aliensh");
    return kTRUE;
 }
@@ -2941,8 +2996,14 @@ void AliAnalysisAlien::WriteAnalysisFile()
       if (mgr->GetMCtruthEventHandler()) TObject::SetBit(AliAnalysisGrid::kUseMC);
       handler = (TObject*)mgr->GetInputEventHandler();
       if (handler) {
-         if (handler->InheritsFrom("AliESDInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseESD);
-         if (handler->InheritsFrom("AliAODInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseAOD);
+         if (handler->InheritsFrom("AliMultiInputEventHandler")) {
+            AliMultiInputEventHandler *multiIH = (AliMultiInputEventHandler*)handler;
+            if (multiIH->GetFirstInputEventHandler()->InheritsFrom("AliESDInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseESD);
+            if (multiIH->GetFirstInputEventHandler()->InheritsFrom("AliAODInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseAOD);
+         } else {
+            if (handler->InheritsFrom("AliESDInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseESD);
+            if (handler->InheritsFrom("AliAODInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseAOD);
+         }
       }
       TDirectory *cdir = gDirectory;
       TFile *file = TFile::Open(analysisFile, "RECREATE");
@@ -2991,11 +3052,16 @@ void AliAnalysisAlien::WriteAnalysisMacro()
       TString func = fAnalysisMacro;
       TString type = "ESD";
       TString comment = "// Analysis using ";
-      if (TObject::TestBit(AliAnalysisGrid::kUseESD)) comment += "ESD";
-      if (TObject::TestBit(AliAnalysisGrid::kUseAOD)) {
-         type = "AOD";
-         comment += "AOD";
-      }   
+      if (IsUseMCchain()) {
+         type = "MC";
+         comment += "MC";
+      } else {   
+         if (TObject::TestBit(AliAnalysisGrid::kUseESD)) comment += "ESD";
+         if (TObject::TestBit(AliAnalysisGrid::kUseAOD)) {
+            type = "AOD";
+            comment += "AOD";
+         }   
+      }
       if (type!="AOD" && fFriendChainName!="") {
          Error("WriteAnalysisMacro", "Friend chain can be attached only to AOD");
          return;
@@ -3013,6 +3079,8 @@ void AliAnalysisAlien::WriteAnalysisMacro()
       // Change temp directory to current one
       out << "// Set temporary merging directory to current one" << endl;
       out << "   gSystem->Setenv(\"TMPDIR\", gSystem->pwd());" << endl << endl;   
+      out << "// Set temporary compilation directory to current one" << endl;
+      out << "   gSystem->SetBuildDir(gSystem->pwd(), kTRUE);" << endl << endl;   
       // Reset existing include path
       out << "// Reset existing include path and add current directory first in the search" << endl;
       out << "   gSystem->SetIncludePath(\"-I.\");" << endl;
@@ -3044,6 +3112,7 @@ void AliAnalysisAlien::WriteAnalysisMacro()
             out << "   gSystem->Load(\"libESD\");" << endl;
             out << "   gSystem->Load(\"libAOD\");" << endl;
          }   
+         out << "   gSystem->Load(\"libOADB\");" << endl;
          out << "   gSystem->Load(\"libANALYSIS\");" << endl;
          out << "   gSystem->Load(\"libANALYSISalice\");" << endl;
          out << "   gSystem->Load(\"libCORRFW\");" << endl << endl;
@@ -3073,6 +3142,7 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          else out << "   if (!" << setupPar << "(\"ESD\")) return;" << endl;
          if (!hasAOD)       out << "   gSystem->Load(\"libAOD\");" << endl;
          else out << "   if (!" << setupPar << "(\"AOD\")) return;" << endl;
+         out << "   gSystem->Load(\"libOADB\");" << endl;
          if (!hasANALYSIS)  out << "   gSystem->Load(\"libANALYSIS\");" << endl;
          else out << "   if (!" << setupPar << "(\"ANALYSIS\")) return;" << endl;
          if (!hasANALYSISalice)   out << "   gSystem->Load(\"libANALYSISalice\");" << endl;
@@ -3237,9 +3307,13 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          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;
+         if (IsUseMCchain()) {
+            out << "   TString treename = \"TE\";" << endl;
+         } else {   
+            out << "   TString treename = type;" << endl;
+            out << "   treename.ToLower();" << endl;
+            out << "   treename += \"Tree\";" << endl;
+         }   
          out << "   printf(\"***************************************\\n\");" << endl;
          out << "   printf(\"    Getting chain of trees %s\\n\", treename.Data());" << endl;
          out << "   printf(\"***************************************\\n\");" << endl;
@@ -3352,7 +3426,7 @@ void AliAnalysisAlien::WriteMergingMacro()
    }   
    TString mergingMacro = fExecutable;
    mergingMacro.ReplaceAll(".sh","_merge.C");
-   if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("/%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data());
+   if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data());
    if (!TestBit(AliAnalysisGrid::kSubmit)) {  
       ofstream out;
       out.open(mergingMacro.Data(), ios::out);
@@ -3404,6 +3478,7 @@ void AliAnalysisAlien::WriteMergingMacro()
             out << "   gSystem->Load(\"libESD\");" << endl;
             out << "   gSystem->Load(\"libAOD\");" << endl;
          }
+         out << "   gSystem->Load(\"libOADB\");" << endl;
          out << "   gSystem->Load(\"libANALYSIS\");" << endl;
          out << "   gSystem->Load(\"libANALYSISalice\");" << endl;
          out << "   gSystem->Load(\"libCORRFW\");" << endl << endl;
@@ -3434,6 +3509,7 @@ void AliAnalysisAlien::WriteMergingMacro()
          else out << "   if (!" << setupPar << "(\"ESD\")) return;" << endl;
          if (!hasAOD)       out << "   gSystem->Load(\"libAOD\");" << endl;
          else out << "   if (!" << setupPar << "(\"AOD\")) return;" << endl;
+         out << "   gSystem->Load(\"libOADB\");" << endl;
          if (!hasANALYSIS)  out << "   gSystem->Load(\"libANALYSIS\");" << endl;
          else out << "   if (!" << setupPar << "(\"ANALYSIS\")) return;" << endl;
          if (!hasANALYSISalice)   out << "   gSystem->Load(\"libANALYSISalice\");" << endl;
@@ -3511,6 +3587,8 @@ void AliAnalysisAlien::WriteMergingMacro()
       // Change temp directory to current one
       out << "// Set temporary merging directory to current one" << endl;
       out << "   gSystem->Setenv(\"TMPDIR\", gSystem->pwd());" << endl << endl;   
+      out << "// Set temporary compilation directory to current one" << endl;
+      out << "   gSystem->SetBuildDir(gSystem->pwd(), kTRUE);" << endl << endl;   
       out << "// Connect to AliEn" << endl;
       out << "   if (!TGrid::Connect(\"alien://\")) return;" << endl;
       out << "   TString outputDir = dir;" << endl;