18 # include <AliAnalysisManager.h>
19 # include <AliAnalysisAlien.h>
93 fOptions.
Add(
"oper",
"FULL|TERMINATE|SUBMIT",
"Analysis operation",
"FULL");
94 fOptions.
Add(
"split",
"N|max",
"Max number of files before split",
"50");
95 fOptions.
Add(
"merge",
"N|max",
"Max number of files for merge",
"50");
96 fOptions.
Add(
"run",
"RUNS",
"Range, list, and/or file of runs",
"");
97 fOptions.
Add(
"alien",
"VERSION",
"Alien API version",
"V1.1x");
99 fOptions.
Add(
"pattern",
"GLOB",
"File/directory name pattern",
"");
101 fOptions.
Add(
"exclude",
"GLOB",
"Comma separated list of merge excludes",
"");
102 fOptions.
Add(
"files",
"FILE",
"file containing list of files",
"");
109 if (&o ==
this)
return *
this;
133 if (oper.EqualTo(
"FULL", TString::kIgnoreCase))
return kFull;
134 else if (oper.EqualTo(
"OFFLINE", TString::kIgnoreCase))
return kOffline;
135 else if (oper.EqualTo(
"SUBMIT", TString::kIgnoreCase))
return kSubmit;
136 else if (oper.EqualTo(
"TERMINATE", TString::kIgnoreCase))
return kTerminate;
137 else if (oper.EqualTo(
"TEST", TString::kIgnoreCase))
return kTest;
154 Error(
"GridRailway::RegisterRuns",
"No runs specified");
159 TObjArray* tokens = runs.Tokenize(
",+:");
160 TObjString* part = 0;
163 Bool_t individual =
false;
165 while ((part = static_cast<TObjString*>(next()))) {
167 if (s.Contains(
"-")) {
169 Warning(
"GridRailway::RegisterRuns",
"Run range already specified, "
170 "ignoring %s", s.Data());
174 Warning(
"GridRailway::RegisterRuns",
175 "Run ranges and individual run specs do not mix, "
176 "ignoring %s", s.Data());
180 if (ranges->GetEntriesFast() > 2) {
181 Warning(
"GridRailway::RegisterRuns",
"Invalid run range: %s",
186 Int_t first =
static_cast<TObjString*
>(ranges->At(0))->String().Atoi();
187 Int_t last =
static_cast<TObjString*
>(ranges->At(1))->String().Atoi();
188 nRuns = last-first+1;
198 Warning(
"GridRailway::RegisterRuns",
199 "Run ranges and individual run specs do not mix, "
200 "ignoring %s", s.Data());
211 Warning(
"GridRailway::RegisterRuns",
"Run ranges and list file "
212 "do not mix, ignoring %s", s.Data());
218 std::ifstream in(s.Data());
223 Warning(
"GridRailway::RegisterRuns",
"Failed to open %s", s.Data());
232 if (bare[0] ==
'#')
continue;
234 TObjArray* ltokens = bare.Tokenize(
" \t,");
235 TIter lnext(ltokens);
237 while ((str = static_cast<TObjString*>(lnext()))) {
238 const TString& token = str->String();
239 if (!token.IsDigit())
continue;
241 int r = token.Atoi();
276 gSystem->AddDynamicPath(
"/usr/lib");
279 if (!TGrid::Connect(Form(
"%s://",
fUrl.GetProtocol()))) {
280 Error(
"GridRailway::PreSetup",
"Failed to connect to AliEN");
283 if (!gGrid || !gGrid->IsConnected()) {
284 Error(
"GridRailway::PreSetup",
"Failed to connect to AliEN");
335 if (!sttl.EqualTo(
"max")) {
337 if (sttl.IsDigit()) ttl = sttl.Atoi();
340 Int_t id = sttl.Index(
"d", 0);
341 if (
id == kNPOS)
id = -1;
344 ttl += 24 * 60 * 60 * sdays.Atoi();
346 Int_t ih = sttl.Index(
"h",
id+1);
347 if (ih == kNPOS) ih = id;
349 TString shour(sttl(
id+1,ih-
id-1));
350 ttl += 60 * 60 * shour.Atoi();
352 Int_t im = sttl.Index(
"m", ih+1);
353 if (im == kNPOS) im = ih;
355 TString smin(sttl(ih+1, im-ih-1));
356 ttl += 60 * smin.Atoi();
358 Int_t is = sttl.Index(
"s", im+1);
360 TString ssec(sttl(im+1, is-im-1));
364 if (ttl != 0)
fHandler->SetTTL(ttl);
366 Warning(
"",
"Option ttl given but no value found");
372 fHandler->SetMasterResubmitThreshold(95);
375 fHandler->SetInputFormat(
"xml-single");
378 fHandler->SetAnalysisMacro(Form(
"%s.C", name.Data()));
379 fHandler->SetJDLName(Form(
"%s.jdl", name.Data()));
380 fHandler->SetExecutable(Form(
"%s.sh", name.Data()));
395 fHandler->SetExecutableCommand(
"aliroot -b -q -x");
412 TString exclude=
"AliAOD.root *EventStat*.root *event_stat*.root";
415 exOpt.ReplaceAll(
",",
" ");
417 exclude.Append(exOpt);
419 fHandler->SetMergeExcludes(exclude);
435 fHandler->SetGridWorkingDir(name.Data());
436 fHandler->SetGridOutputDir(
"output");
444 if (treeName.IsNull()) {
445 Warning(
"GridRailway::PreSetup",
"No tree name specified, assuming T");
448 if (treeName.EqualTo(
"esdTree")) pattern =
"AliESD";
449 else if (treeName.EqualTo(
"aodTree")) pattern =
"AliAOD";
459 TObjArray* outs[] = { mgr->GetOutputs(), mgr->GetParamOutputs(), 0 };
462 AliAnalysisDataContainer* cont = 0;
463 TIter nextCont(*out);
464 while ((cont = static_cast<AliAnalysisDataContainer*>(nextCont()))) {
465 TString outName(cont->GetFileName());
466 Bool_t term = (*out == outs[1]);
467 TString&
list = (outName ==
"default" ? listOfAODs :
468 !term ? listOfHists : listOfTerms);
469 if (outName ==
"default") {
470 if (!mgr->GetOutputEventHandler())
continue;
472 outName = mgr->GetOutputEventHandler()->GetOutputFileName();
474 if (list.Contains(outName))
continue;
475 if (!list.IsNull()) list.Append(
",");
476 list.Append(outName);
480 TString extra = mgr->GetExtraFiles();
481 if (!extra.IsNull()) {
482 if (!listOfAODs.IsNull()) listOfAODs.Append(
"+");
483 extra.ReplaceAll(
" ",
",");
484 listOfAODs.Append(extra);
489 TString outArchive = Form(
"stderr, stdout@disk=%d", nReplica);
490 if (!listOfHists.IsNull())
491 outArchive.Append(Form(
" hist_archive.zip:%s@disk=%d",
492 listOfHists.Data(), nReplica));
493 if (!listOfAODs.IsNull())
494 outArchive.Append(Form(
" aod_archive.zip:%s@disk=%d",
495 listOfAODs.Data(), nReplica));
500 if (listOfAODs.IsNull() && listOfHists.IsNull())
501 Fatal(
"PostSetup",
"No outputs defined");
502 if (!listOfTerms.IsNull())
503 fHandler->SetTerminateFiles(listOfTerms);
511 if (
fRuns.GetEntries() > 0 &&
512 fRuns.At(0)->GetUniqueID() != 0)
return;
517 if (path.IsNull() || pattern.IsNull()) {
518 Warning(
"ScanFiles",
"No search path (%s) or pattern (%s) specified",
519 path.Data(), pattern.Data());
523 TString cmd = Form(
"alien_find %s %s", path.Data(), pattern.Data());
526 Warning(
"ScanFiles",
"Command %s failed", cmd.Data());
530 std::stringstream
str(ret.Data());
538 if (files.IsNull()) {
543 std::ifstream in(files.Data());
545 Warning(
"",
"Failed to open the file %s", files.Data());
546 in.open(Form(
"../%s", files.Data()));
548 Warning(
"",
"Failed to open the file ../%s - giving up", files.Data());
562 if (!tmp.EndsWith(
".root")) {
586 std::ofstream outJobs(Form(
"%s.jobid", mgr->GetName()));
587 outJobs <<
fHandler->GetGridJobIDs() << std::endl;
590 std::ofstream outStages(Form(
"%s.stage", mgr->GetName()));
591 outStages <<
fHandler->GetGridStages() << std::endl;
610 fHandler->AddAdditionalLibrary(local);
621 Warning(
"GridRailway::OutputLocation",
"No AliEn handler");
625 if (ret.BeginsWith(
"/"))
return ret;
629 Warning(
"GridRailway::OutputLocation",
"No analysis manager");
632 ret.Prepend(Form(
"%s/", mgr->GetName()));
634 ret.Prepend(Form(
"%s/", gGrid->GetHomeDirectory()));
643 return "alien:///<datadir>[?<options>][#<treeName>]";
648 virtual const char*
Desc()
const {
return "AliEn"; }
659 TFile* plug = TFile::Open(Form(
"%s_plugin.root", escaped.Data()),
667 while ((lib = static_cast<TObjString*>(nextLib()))) {
668 if (!libs.IsNull()) libs.Append(
" ");
669 libs.Append(lib->String());
674 while ((par = static_cast<TObjString*>(nextPar()))) {
675 if (!pars.IsNull()) pars.Append(
" ");
676 pars.Append(par->String());
681 while ((src = static_cast<TObjString*>(nextSrc()))) {
682 if (!srcs.IsNull()) srcs.Append(
" ");
683 srcs.Append(src->String());
685 TString macDir(
"$ALICE_PHYSICS/PWGLF/FORWARD/trains");
687 std::ofstream t(
"Terminate.C");
689 Error(
"GridRailway::AuxSave",
"Failed to make terminate ROOT script");
693 t <<
"// Generated by GridRailway\n"
694 <<
"Bool_t Terminate(Bool_t localMerge=false)\n"
696 <<
" TString name = \"" << escaped <<
"\";\n"
697 <<
" TString libs = \"" << libs <<
"\";\n"
698 <<
" TString pars = \"" << pars <<
"\";\n"
699 <<
" TString srcs = \"" << srcs <<
"\";\n\n"
700 <<
" gSystem->Load(\"libANALYSIS\");\n"
701 <<
" gSystem->Load(\"libANALYSISalice\");\n"
702 <<
" gSystem->AddIncludePath(\"-I$ALICE_ROOT/include\");\n\n"
703 <<
" gSystem->AddIncludePath(\"-I$ALICE_PHYSICS/include\");\n\n"
704 <<
" gROOT->LoadMacro(\"" << macDir <<
"/GridTerminate.C+g\");\n\n"
705 <<
" return GridTerminate(name,libs,pars,srcs,localMerge);\n"
719 if (!runs.IsNull()) runs.Append(
" ");
720 runs.Append(TString::Format(fmt, first, last));
725 while ((o = next())) {
726 if (!runs.IsNull()) runs.Append(
" ");
727 runs.Append(Form(format, o->GetUniqueID()));
731 std::ofstream d(
"Download.C");
733 Error(
"GridRailway::AuxSave",
"Failed to make ROOT script Download.C");
736 d <<
"// Generated by GridRailway\n"
737 <<
"void Download(Bool_t unpack=true)\n"
739 <<
" TString base = \"" <<
fUrl.GetProtocol()<<
"://"<< outDir <<
"\";\n"
740 <<
" TString runs = \"" << runs <<
"\";\n\n"
741 <<
" gROOT->LoadMacro(\"" << macDir <<
"/GridDownload.C\");\n\n"
742 <<
" GridDownload(base, runs, unpack);\n"
748 std::ofstream w(
"Watch.C");
750 Error(
"GridRailway::AuxSave",
"Failed to make ROOT script Watch.C");
753 w <<
"// Generated by GridRailway\n"
754 <<
"void Watch(Bool_t batch=false, Int_t delay=5*60)\n"
756 <<
" TString name = \"" << escaped <<
"\";\n"
757 <<
" gROOT->LoadMacro(\"" << macDir <<
"/GridWatch.C+g\");\n\n"
758 <<
" GridWatch(name,batch,delay);\n"
764 if (!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler())
768 std::ofstream a(
"DownloadAODs.C");
770 Error(
"GridRailway::AuxSave",
"Failed to open DownloadAODs.C");
773 a <<
"// Generated by GridRailway\n"
774 <<
"void DownloadAODs(Bool_t verbose=false,Bool_t force=false)\n"
776 <<
" gROOT->LoadMacro(\"" << macDir <<
"/GridDownloadAODs.C\");\n"
777 <<
" GridDownloadAODs(\"" << outDir <<
"\",verbose,force);\n"
783 std::ofstream e(
"downloadAODs.sh");
785 Error(
"GridRailway::AuxSave",
"Failed to open downloadAODs.sh");
789 <<
"# Generated by GridRailway\n"
790 <<
"exec " << macDir <<
"/downloadAODs.sh -s 0 -e 10000 -f AliAOD.root "
791 <<
"-d " << outDir <<
" $@\n"
792 <<
"# EOF\n" << std::endl;
794 gSystem->Exec(
"chmod a+x downloadAODs.sh");
796 std::ofstream
c(
"MakeIndex.C");
798 Error(
"GridRailway::AuxSave",
"Failed to open MakeIndex.C");
801 c <<
"// Generated by GridRailway\n"
802 <<
"void MakeIndex()\n"
804 <<
" TString libs = \"" << libs <<
"\";\n"
805 <<
" TString pars = \"" << pars <<
"\";\n"
806 <<
" TString srcs = \"" << srcs <<
"\";\n\n"
807 <<
" gSystem->Load(\"libANALYSIS\");\n"
808 <<
" gSystem->Load(\"libANALYSISalice\");\n"
809 <<
" gSystem->AddIncludePath(\"-I$ALICE_ROOT/include\");\n\n"
810 <<
" gSystem->AddIncludePath(\"-I$ALICE_PHYSICS/include\");\n\n"
811 <<
" gROOT->LoadMacro(\"" << macDir <<
"/CreateIndex.C\");\n"
812 <<
" CreateIndex(\".\",\"aodTree\",0,libs,pars,srcs);\n"
virtual Bool_t PreSetup()
virtual const Char_t * UrlHelp() const
virtual Bool_t PostSetup()
return jsonbuilder str().c_str()
Base class for helpers using the AliAnalysisAlien plugin.
Option * Find(const TString &name) const
GridRailway(const GridRailway &o)
void AuxSave(const TString &escaped, Bool_t)
Int_t AsInt(const TString &name, Int_t def=0) const
GridRailway(const TUrl &url, Int_t verbose)
virtual Int_t RegisterRuns()
const TString & Get(const TString &name) const
Bool_t Has(const TString &name) const
GridRailway & operator=(const GridRailway &o)
PluginRailway & operator=(const PluginRailway &o)
virtual const char * Desc() const
virtual UShort_t Operation() const
virtual Bool_t AuxFile(TString &name, bool copy=false)
virtual const char * ModeString() const
Option * Add(const TString &name, const TString &arg, const TString &desc, const TString &val="")
virtual Long64_t Run(Long64_t nEvents=-1)
virtual Bool_t PostSetup()
virtual UShort_t Mode() const
virtual Bool_t PreSetup()
virtual Bool_t AuxFile(TString &name, bool copy=false)
AliAnalysisAlien * fHandler
void AddFiles(std::istream &in)
virtual TString OutputPath() const