]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisAlien.cxx
CopyLocalDataset returns now the number of entries for which the files were actually...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisAlien.cxx
index e03b1e21c658957575d005d19f913f4e747fba69..af9744031a7fab42ad252615a3e6feb46ab25ba4 100644 (file)
 #include "AliAnalysisDataContainer.h"
 #include "AliMultiInputEventHandler.h"
 
+using std::ofstream;
+using std::ifstream;
+using std::ios;
+using std::endl;
 ClassImp(AliAnalysisAlien)
 #if 0
 ;
@@ -596,8 +600,8 @@ Bool_t AliAnalysisAlien::LoadModule(AliAnalysisTaskCfg *mod)
    TString lib;
    for (Int_t i=0; i<nlibs; i++) {
       lib = mod->GetLibrary(i);
-      if (fAdditionalLibs.Contains(lib)) continue;
       lib = Form("lib%s.so", lib.Data());
+      if (fAdditionalLibs.Contains(lib)) continue;
       if (!fAdditionalLibs.IsNull()) fAdditionalLibs += " ";
       fAdditionalLibs += lib;
    }
@@ -1040,18 +1044,18 @@ Bool_t AliAnalysisAlien::CheckInputData()
 }   
 
 //______________________________________________________________________________
-Bool_t AliAnalysisAlien::CopyLocalDataset(const char *griddir, const char *pattern, Int_t nfiles, const char *output, const char *archivefile, const char *outputdir)
+Int_t AliAnalysisAlien::CopyLocalDataset(const char *griddir, const char *pattern, Int_t nfiles, const char *output, const char *archivefile, const char *outputdir)
 {
 // Copy data from the given grid directory according a pattern and make a local
 // dataset.
 // archivefile (optional) results in that the archive containing the file <pattern> is copied. archivefile can contain a list of files (semicolon-separated) which are all copied
    if (!Connect()) {
       Error("CopyLocalDataset", "Cannot copy local dataset with no grid connection");
-      return kFALSE;
+      return 0;
    }
    if (!DirectoryExists(griddir)) {
       Error("CopyLocalDataset", "Data directory %s not existing.", griddir);
-      return kFALSE;
+      return 0;
    }
    TString command = Form("find -z -l %d %s %s", nfiles, griddir, pattern);
    printf("Running command: %s\n", command.Data());
@@ -1059,7 +1063,7 @@ Bool_t AliAnalysisAlien::CopyLocalDataset(const char *griddir, const char *patte
    Int_t nfound = res->GetEntries();
    if (!nfound) {
       Error("CopyLocalDataset", "No file found in <%s> having pattern <%s>", griddir, pattern);
-      return kFALSE;
+      return 0;
    }
    printf("... found %d files. Copying locally ...\n", nfound);
    
@@ -1080,6 +1084,7 @@ Bool_t AliAnalysisAlien::CopyLocalDataset(const char *griddir, const char *patte
    TString cdir = gSystem->WorkingDirectory();
    gSystem->MakeDirectory(outputdir);
    gSystem->ChangeDirectory(outputdir);
+   Int_t ncopied = 0;
    for (Int_t i=0; i<nfound; i++) {
       map = (TMap*)res->At(i);
       turl = map->GetValue("turl")->GetName();
@@ -1092,34 +1097,34 @@ Bool_t AliAnalysisAlien::CopyLocalDataset(const char *griddir, const char *patte
       TString targetFileName(filename);
       
       if (strlen(archivefile) > 0) {
-       // TODO here the archive in which the file resides should be determined
-       // however whereis returns only a guid, and guid2lfn does not work
-       // Therefore we use the one provided as argument for now
-       source = Form("%s/%s", gSystem->DirName(source.Data()), archivefile);
-       targetFileName = archivefile;
+// TODO here the archive in which the file resides should be determined
+// however whereis returns only a guid, and guid2lfn does not work
+// Therefore we use the one provided as argument for now
+         source = Form("%s/%s", gSystem->DirName(source.Data()), archivefile);
+         targetFileName = archivefile;
       }
       if (TFile::Cp(source, Form("file:./%s/%s", dirname.Data(), targetFileName.Data()))) {
-        Bool_t success = kTRUE;
-        if (additionalArchives)
-           for (Int_t j=0; j<additionalArchives->GetEntriesFast(); j++)
-           {
-              TString target;
-              target.Form("./%s/%s", dirname.Data(), additionalArchives->At(j)->GetName());
-              gSystem->MakeDirectory(gSystem->DirName(target));
-              success &= TFile::Cp(Form("%s/%s", gSystem->DirName(source.Data()), additionalArchives->At(j)->GetName()), Form("file:%s", target.Data()));
-           }
+         Bool_t success = kTRUE;
+         if (additionalArchives) {
+            for (Int_t j=0; j<additionalArchives->GetEntriesFast(); j++) {
+               TString target;
+               target.Form("./%s/%s", dirname.Data(), additionalArchives->At(j)->GetName());
+               gSystem->MakeDirectory(gSystem->DirName(target));
+               success &= TFile::Cp(Form("%s/%s", gSystem->DirName(source.Data()), additionalArchives->At(j)->GetName()), Form("file:%s", target.Data()));
+            }
+         }
 
-        if (success) {
-           if (strlen(archivefile) > 0) targetFileName = Form("%s#%s", targetFileName.Data(), gSystem->BaseName(turl.Data()));
-           out << cdir << Form("/%s/%s/%s", outputdir, dirname.Data(), targetFileName.Data()) << endl;
-        }
+         if (success) {
+            if (strlen(archivefile) > 0) targetFileName = Form("%s#%s", targetFileName.Data(), gSystem->BaseName(turl.Data()));
+            out << cdir << Form("/%s/%s/%s", outputdir, dirname.Data(), targetFileName.Data()) << endl;
+            ncopied++;
+         }
       }
    }
    gSystem->ChangeDirectory(cdir);
    delete res;
-   if (additionalArchives)
-     delete additionalArchives;
-   return kTRUE;
+   delete additionalArchives;
+   return ncopied;
 }   
 
 //______________________________________________________________________________
@@ -1674,7 +1679,17 @@ Bool_t AliAnalysisAlien::CreateJDL()
          }
       }
       if (fOutputArchive.Length()) {
-         arr = fOutputArchive.Tokenize(" ");
+         TString outputArchive = fOutputArchive;
+         if (!fRegisterExcludes.IsNull()) {
+            arr = fRegisterExcludes.Tokenize(" ");
+            TIter next1(arr);
+            while ((os=(TObjString*)next1())) {
+               outputArchive.ReplaceAll(Form("%s,",os->GetString().Data()),"");
+               outputArchive.ReplaceAll(os->GetString(),"");
+            } 
+            delete arr;
+         }     
+         arr = outputArchive.Tokenize(" ");
          TIter next(arr);
          Bool_t first = kTRUE;
          const char *comment = "Files to be archived";
@@ -1689,7 +1704,6 @@ Bool_t AliAnalysisAlien::CreateJDL()
          }      
          delete arr;
          // Output archive for the merging jdl
-         TString outputArchive;
          if (TestBit(AliAnalysisGrid::kDefaultOutputs)) {
             outputArchive = "log_archive.zip:std*@disk=1 ";
             // Add normal output files, extra files + terminate files
@@ -2227,9 +2241,11 @@ TChain *AliAnalysisAlien::GetChainForTestMode(const char *treeName) const
    Int_t count = 0;
     // Read the input list of files and add them to the chain
    TString line;
-   TChain *chain = new TChain(treeName);
+   TString streeName(treeName);
+   if (IsUseMCchain()) streeName = "TE";
+   TChain *chain = new TChain(streeName);
    TChain *chainFriend = 0;
-   if (!fFriendChainName.IsNull()) chainFriend = new TChain(treeName);       
+   if (!fFriendChainName.IsNull()) chainFriend = new TChain(streeName);       
    while (in.good())
    {
       in >> line;
@@ -2241,11 +2257,10 @@ TChain *AliAnalysisAlien::GetChainForTestMode(const char *treeName) const
          chain->Add(esdFile);
          file->Close();
          if (!fFriendChainName.IsNull()) {
-           if (esdFile.Index("#") > -1)
-             esdFile.Remove(esdFile.Index("#"));
-           esdFile = gSystem->DirName(esdFile);
-           esdFile += "/" + fFriendChainName;
-
+            if (esdFile.Index("#") > -1)
+               esdFile.Remove(esdFile.Index("#"));
+            esdFile = gSystem->DirName(esdFile);
+            esdFile += "/" + fFriendChainName;
             file = TFile::Open(esdFile);
             if (file && !file->IsZombie()) {
                file->Close();
@@ -2254,7 +2269,7 @@ TChain *AliAnalysisAlien::GetChainForTestMode(const char *treeName) const
                Fatal("GetChainForTestMode", "Cannot open friend file: %s", esdFile.Data());
                return 0;
             }   
-         }   
+         }
       } else {
          Error("GetChainforTestMode", "Skipping un-openable file: %s", esdFile.Data());
       }   
@@ -3331,9 +3346,9 @@ Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEn
    }
    // Check if submitting is managed by LPM manager
    if (fProductionMode) {
-      TString prodfile = fJDLName;
-      prodfile.ReplaceAll(".jdl", ".prod");
-      WriteProductionFile(prodfile);
+      //TString prodfile = fJDLName;
+      //prodfile.ReplaceAll(".jdl", ".prod");
+      //WriteProductionFile(prodfile);
       Info("StartAnalysis", "Job submitting is managed by LPM. Rerun in terminate mode after jobs finished.");
       return kFALSE;
    }   
@@ -3729,6 +3744,10 @@ void AliAnalysisAlien::WriteAnalysisMacro()
       out << "   TStopwatch timer;" << endl;
       out << "   timer.Start();" << endl << endl;
       // Change temp directory to current one
+      if (!IsLocalTest()) {  
+         out << "// connect to AliEn and make the chain" << endl;
+         out << "   if (!TGrid::Connect(\"alien://\")) return;" << endl;
+      }   
       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;
@@ -3878,10 +3897,6 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          out << "   gEnv->SetValue(\"XNet.ReconnectTimeout\",50);" << endl;
          out << "   gEnv->SetValue(\"XNet.FirstConnectMaxCnt\",1);" << endl << endl;
       } 
-      if (!IsLocalTest()) {  
-         out << "// connect to AliEn and make the chain" << endl;
-         out << "   if (!TGrid::Connect(\"alien://\")) return;" << endl;
-      }   
       out << "// read the analysis manager from file" << endl;
       TString analysisFile = fExecutable;
       analysisFile.ReplaceAll(".sh", ".root");
@@ -3896,6 +3911,10 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          else   
             out << "   plugin->SetFileForTestMode(\"" << fFileForTestMode << "\");" << endl;
          out << "   plugin->SetNtestFiles(" << fNtestFiles << ");" << endl;
+         if (!fFriendChainName.IsNull()) 
+            out << "   plugin->SetFriendChainName(\"" << fFriendChainName << "\");" << endl;
+         if (IsUseMCchain())
+            out << "   plugin->SetUseMCchain();" << endl;
          out << "   mgr->SetGridHandler(plugin);" << endl;
          if (AliAnalysisManager::GetAnalysisManager()) {
             out << "   mgr->SetDebugLevel(" << AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() << ");" << endl;
@@ -3966,9 +3985,18 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          out << "      chain->Add(filename);" << endl;
          if(fFriendChainName!="") {
             out << "      TString fileFriend=coll->GetTURL(\"\");" << endl;
-            out << "      fileFriend.ReplaceAll(\"AliAOD.root\",\""<<fFriendChainName.Data()<<"\");" << endl;
-            out << "      fileFriend.ReplaceAll(\"AliAODs.root\",\""<<fFriendChainName.Data()<<"\");" << endl;
-            out << "      chainFriend->Add(fileFriend.Data());" << 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;
+            out << "      }" << endl;
          }
          out << "   }" << endl;
          out << "   if (!chain->GetNtrees()) {" << endl;
@@ -4215,12 +4243,12 @@ void AliAnalysisAlien::WriteMergingMacro()
          out << "   gEnv->SetValue(\"XNet.FirstConnectMaxCnt\",1);" << endl << endl;
       }
       // Change temp directory to current one
+      out << "// Connect to AliEn" << endl;
+      out << "   if (!TGrid::Connect(\"alien://\")) return;" << endl;
       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;  
       out << "   TString outputFiles = \"" << GetListOfFiles("out") << "\";" << endl;
       out << "   TString mergeExcludes = \"" << fMergeExcludes << " " << fRegisterExcludes << "\";" << endl;