]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisManager.cxx
Fixes for cmake
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisManager.cxx
index 5b8293722721b0d16c196ed6b7db9b9e4d744735..136f64ee76b0ee3b93b29347f699417494c79385 100644 (file)
@@ -432,6 +432,7 @@ void AliAnalysisManager::PackOutput(TList *target)
          const char *filename = output->GetFileName();
          if (!(strcmp(filename, "default")) && fOutputEventHandler) {
             isManagedByHandler = kTRUE;
+            printf("#### Handler output. Extra: %s\n", fExtraFiles.Data());
             filename = fOutputEventHandler->GetOutputFileName();
          }
          // Check if data was posted to this container. If not, issue an error.
@@ -466,7 +467,7 @@ void AliAnalysisManager::PackOutput(TList *target)
                } else {
                   if (output->GetData()->InheritsFrom(TTree::Class())) {
                      TTree *tree = (TTree*)output->GetData();
-                     tree->SetDirectory(file);
+                     // tree->SetDirectory(file);
                      tree->AutoSave();
                   } else {
                      output->GetData()->Write();
@@ -494,10 +495,18 @@ void AliAnalysisManager::PackOutput(TList *target)
             wrap->SetDeleteData(kFALSE);
             target->Add(wrap);
          } else {
-         // Special outputs
+         // Special outputs. The file must be opened and connected to the container.
             TDirectory *opwd = gDirectory;
             TFile *file = output->GetFile();
-            if (fDebug > 1 && file) printf("PackOutput %s: file merge, special output\n", output->GetName());
+            if (!file) {
+               AliAnalysisTask *producer = output->GetProducer();
+               Error("PackOutput", 
+                     "File %s for special container %s was NOT opened in %s::CreateOutputObjects !!!",
+                     output->GetFileName(), output->GetName(), producer->ClassName());
+               continue;
+            }   
+            TString outFilename = file->GetName();
+            if (fDebug > 1) printf("PackOutput %s: special output\n", output->GetName());
             if (isManagedByHandler) {
                // Terminate IO for files managed by the output handler
                if (file) file->Write();
@@ -506,40 +515,31 @@ void AliAnalysisManager::PackOutput(TList *target)
                   file->ls();
                }   
                fOutputEventHandler->TerminateIO();
-               continue;
-            }   
-            
-            if (!file) {
-               AliAnalysisTask *producer = output->GetProducer();
-               Error("PackOutput", 
-                     "File %s for special container %s was NOT opened in %s::CreateOutputObjects !!!",
-                     output->GetFileName(), output->GetName(), producer->ClassName());
-               continue;
-            }   
-            file->cd();
-            // Release object ownership to users after writing data to file
-            if (output->GetData()->InheritsFrom(TCollection::Class())) {
-               // If data is a collection, we set the name of the collection 
-               // as the one of the container and we save as a single key.
-               TCollection *coll = (TCollection*)output->GetData();
-               coll->SetName(output->GetName());
-               coll->Write(output->GetName(), TObject::kSingleKey);
-            } else {
-               if (output->GetData()->InheritsFrom(TTree::Class())) {
-                  TTree *tree = (TTree*)output->GetData();
-                  tree->SetDirectory(file);
-                  tree->AutoSave();
+            } else {               
+               file->cd();
+               // Release object ownership to users after writing data to file
+               if (output->GetData()->InheritsFrom(TCollection::Class())) {
+                  // If data is a collection, we set the name of the collection 
+                  // as the one of the container and we save as a single key.
+                  TCollection *coll = (TCollection*)output->GetData();
+                  coll->SetName(output->GetName());
+                  coll->Write(output->GetName(), TObject::kSingleKey);
                } else {
-                  output->GetData()->Write();
-               }   
-            }      
-            file->Clear();
-            if (fDebug > 2) {
-               printf("   file %s listing content:\n", output->GetFileName());
-               file->ls();
+                  if (output->GetData()->InheritsFrom(TTree::Class())) {
+                     TTree *tree = (TTree*)output->GetData();
+                     tree->SetDirectory(file);
+                     tree->AutoSave();
+                  } else {
+                     output->GetData()->Write();
+                  }   
+               }      
+               file->Clear();
+               if (fDebug > 2) {
+                  printf("   file %s listing content:\n", output->GetFileName());
+                  file->ls();
+               }
+               file->Close();
             }
-            TString outFilename = file->GetName();
-            file->Close();
             // Restore current directory
             if (opwd) opwd->cd();
             // Check if a special output location was provided or the output files have to be merged
@@ -547,13 +547,45 @@ void AliAnalysisManager::PackOutput(TList *target)
                TString remote = fSpecialOutputLocation;
                remote += "/";
                Int_t gid = gROOT->ProcessLine("gProofServ->GetGroupId();");
-               remote += Form("%s_%d_", gSystem->HostName(), gid);
-               remote += output->GetFileName();
+               if (remote.BeginsWith("alien://")) {
+                  gROOT->ProcessLine("TGrid::Connect(\"alien://pcapiserv01.cern.ch:10000\", gProofServ->GetUser());");
+                  remote += outFilename;
+                  remote.ReplaceAll(".root", Form("_%d.root", gid));
+               } else {   
+                  remote += Form("%s_%d_", gSystem->HostName(), gid);
+                  remote += outFilename;
+               }   
+               if (fDebug > 1) 
+                  Info("PackOutput", "Output file for container %s to be copied \n   at: %s. No merging.",
+                       output->GetName(), remote.Data());
                TFile::Cp ( outFilename.Data(), remote.Data() );
+               // Copy extra outputs
+               if (fExtraFiles.Length() && isManagedByHandler) {
+                  TObjArray *arr = fExtraFiles.Tokenize(" ");
+                  TObjString *os;
+                  TIter nextfilename(arr);
+                  while ((os=(TObjString*)nextfilename())) {
+                     outFilename = os->GetString();
+                     remote = fSpecialOutputLocation;
+                     remote += "/";
+                     if (remote.BeginsWith("alien://")) {
+                        remote += outFilename;
+                        remote.ReplaceAll(".root", Form("_%d.root", gid));
+                     } else {   
+                        remote += Form("%s_%d_", gSystem->HostName(), gid);
+                        remote += outFilename;
+                     }   
+                     if (fDebug > 1) 
+                        Info("PackOutput", "Extra AOD file %s to be copied \n   at: %s. No merging.",
+                             outFilename.Data(), remote.Data());
+                     TFile::Cp ( outFilename.Data(), remote.Data() );
+                  }   
+                  delete arr;
+               }   
             } else {
             // No special location specified-> use TProofOutputFile as merging utility
             // The file at this output slot must be opened in CreateOutputObjects
-               if (fDebug > 1) printf("   File %s to be merged...\n", output->GetFileName());
+               if (fDebug > 1) printf("   File for container %s to be merged via file merger...\n", output->GetName());
             }
          }      
       }
@@ -581,7 +613,7 @@ void AliAnalysisManager::ImportWrappers(TList *source)
          filename = fOutputEventHandler->GetOutputFileName();
       }
       if (cont->IsSpecialOutput() || inGrid) {
-         if (strlen(fSpecialOutputLocation.Data()) && !isManagedByHandler) continue;
+         if (strlen(fSpecialOutputLocation.Data())) continue;
          // Copy merged file from PROOF scratch space. 
          // In case of grid the files are already in the current directory.
          if (!inGrid) {
@@ -734,7 +766,16 @@ void AliAnalysisManager::Terminate()
    while ((output=(AliAnalysisDataContainer*)next1())) {
       // Close all files at output
       TDirectory *opwd = gDirectory;
-      if (output->GetFile()) output->GetFile()->Close();
+      if (output->GetFile()) {
+         output->GetFile()->Close();
+         // Copy merged outputs in alien if requested
+         if (fSpecialOutputLocation.Length() && 
+             fSpecialOutputLocation.BeginsWith("alien://")) {
+            Info("Terminate", "Copy file %s to %s", output->GetFile()->GetName(),fSpecialOutputLocation.Data()); 
+            TFile::Cp(output->GetFile()->GetName(), 
+                      Form("%s/%s", fSpecialOutputLocation.Data(), output->GetFile()->GetName()));
+         }             
+      }   
       if (opwd) opwd->cd();
    }   
 
@@ -1022,7 +1063,10 @@ void AliAnalysisManager::StartAnalysis(const char *type, TTree *tree, Long64_t n
       while ((task=(AliAnalysisTask*)nextTask())) {
          task->LocalInit();
       }
-      fGridHandler->StartAnalysis(nentries, firstentry);
+      if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
+         Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
+         return;
+      }   
 
       // Terminate grid analysis
       if (fSelector && fSelector->GetStatus() == -1) return;
@@ -1175,6 +1219,11 @@ TFile *AliAnalysisManager::OpenProofFile(const char *filename, const char *optio
    if (fMode!=kProofAnalysis || !fSelector) {
       Error("OpenProofFile","Cannot open PROOF file %s",filename);
       return NULL;
+   } 
+   if (fSpecialOutputLocation.Length()) {
+      TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+      if (!f) f = new TFile(filename, option);
+      return f;
    }   
    sprintf(line, "TProofOutputFile *pf = new TProofOutputFile(\"%s\");", filename);
    if (fDebug > 1) printf("=== %s\n", line);
@@ -1334,3 +1383,22 @@ Bool_t AliAnalysisManager::GetFileFromWrapper(const char *filename, TList *sourc
       Error("GetFileFromWrapper", "Could not get file %s from proof scratch space", filename);
    return gotit;
 }
+
+//______________________________________________________________________________
+void AliAnalysisManager::GetAnalysisTypeString(TString &type) const
+{
+// Fill analysis type in the provided string.
+   switch (fMode) {
+      case kLocalAnalysis:
+         type = "local";
+         return;
+      case kProofAnalysis:
+         type = "proof";
+         return;
+      case kGridAnalysis:
+         type = "grid";
+         return;
+      case kMixingAnalysis:
+         type = "mix";
+   }
+}