]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisAlien.cxx
Unintentional delete corrected.
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisAlien.cxx
index ca01a785a94bf1be6704c9421f4745ed4057fd5f..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";
@@ -2197,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;
@@ -2220,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;
@@ -2443,15 +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.ReplaceAll("$ALICE_ROOT","");
-            includePath.ReplaceAll("${ALICE_ROOT}","");
+            includePath.ReplaceAll("$ALICE_ROOT/","");
+            includePath.ReplaceAll("${ALICE_ROOT}/","");
             includePath.ReplaceAll("-I","");
-            includePath.Strip(TString::kTrailing, ':');
+            includePath.Remove(TString::kTrailing, ':');
             Info("StartAnalysis", "Adding extra includes: %s",includePath.Data()); 
             optionsList.Add(new TNamed("ALIROOT_EXTRA_INCLUDES",includePath.Data()));
          }
@@ -2474,11 +2508,13 @@ Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEn
                return kFALSE;
             }   
          } else {
-            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;
-            }         
+           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()) {
@@ -2519,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;
@@ -2538,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) {
@@ -2810,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());
@@ -2823,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(",");
@@ -2841,11 +2887,14 @@ Bool_t AliAnalysisAlien::SubmitMerging()
       delete list;
       Bool_t done = CheckMergedFiles(outputFile, runOutDir, fMaxMergeFiles, mergeJDLName);
       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;
 }
@@ -2947,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");
@@ -2997,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;
@@ -3019,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;
@@ -3050,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;
@@ -3079,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;
@@ -3243,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;
@@ -3358,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);
@@ -3410,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;
@@ -3440,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;
@@ -3517,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;