// a personalized JDL, finding and creating a dataset.
//==============================================================================
+#include "AliAnalysisAlien.h"
+
#include "Riostream.h"
#include "TEnv.h"
#include "TBits.h"
#include "AliAnalysisManager.h"
#include "AliVEventHandler.h"
#include "AliAnalysisDataContainer.h"
-#include "AliAnalysisAlien.h"
+#include "AliMultiInputEventHandler.h"
ClassImp(AliAnalysisAlien)
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;
}
//______________________________________________________________________________
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)
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";
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);
}
// 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
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
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");
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:
fNreplicas = 2;
fRunRange[0] = 0;
fRunRange[1] = 0;
+ fRunPrefix = "%d";
fNrunsPerMaster = 1;
fMaxMergeFiles = 100;
fRunNumbers = "";
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";
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;
}
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;
}
// 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;
}
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()));
}
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()) {
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;
TObjString *str;
while((str=(TObjString*)next())) {
gROOT->ProcessLine(Form("gProof->Load(\"%s+g\", kTRUE);", str->GetName()));
- }
+ }
if (list) delete list;
}
if (testMode) {
}
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;
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)) {
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());
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(",");
}
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;
}
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");
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;
// 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;
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;
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;
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;
}
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);
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;
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;
// 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;