41 if (what.IsNull())
return false;
45 TString search = Form(
".:..:%s:%s/PARfiles:%s:%s/PARfiles",
46 aliPhys.Data(), aliPhys.Data(),
47 aliRoot.Data(), aliRoot.Data());
48 char* found =
gSystem->Which(search.Data(), what.Data());
49 if (!found || found[0] ==
'\0') {
50 Error(
"ParUtilities::Find",
"PAR file %s not found in %s",
51 what.Data(), search.Data());
68 if (!parFile.EndsWith(
".par")) parFile.Append(
".par");
70 if (!
DoFind(parFile, src))
return false;
74 Info(
"",
"Found PAR %s at %s", what.Data(), src.Data());
75 if (
gSystem->Exec(Form(
"ln -s %s %s", src.Data(), parFile.Data())) != 0){
76 if (!
gSystem->AccessPathName(parFile.Data()))
return true;
77 Error(
"ParUtilities::Find",
"Failed to symlink %s to %s",
78 src.Data(), parFile.Data());
92 if (name.IsNull())
return true;
94 Error(
"ParUtilities::Load",
"No connection to a Proof cluster");
100 Info(
"ParUtilities::LoadLibrary",
"Uploading %s", name.Data());
103 if (!parFile.EndsWith(
".par")) parFile.Append(
".par");
105 if (!
DoFind(parFile, src))
return false;
108 Int_t ret = gProof->UploadPackage(src, TProof::kRemoveOld);
112 Error(
"ParUtilities::Load",
113 "Could not upload module %s.par", name.Data());
117 ret = gProof->EnablePackage(name);
118 Info(
"ParUtilities::Load",
"Enabled package %s (from %s)",
119 name.Data(), fn.Data());
132 if (what.IsNull())
return false;
135 if (!parFile.EndsWith(
".par")) parFile.Append(
".par");
138 gSystem->Exec(Form(
"tar xzf %s", parFile.Data()));
144 if (dir.EndsWith(
".par")) dir.ReplaceAll(
".par",
"");
145 if (!
gSystem->ChangeDirectory(dir)) {
146 Error(
"ParUtilities::Setup",
"Failed to change directory to %s",
152 if (!
gSystem->AccessPathName(
"PROOF-INF/BUILD.sh")) {
153 Info(
"ParUtilities::Setup",
"Building in PAR archive %s", parFile.Data());
154 if (
gSystem->Exec(
"PROOF-INF/BUILD.sh")) {
155 Error(
"ParUtilities::Setup",
"Failed to build in PAR directory %s",
157 gSystem->ChangeDirectory(cwd.Data());
163 gSystem->SetDynamicPath(Form(
"%s:%s",
gSystem->WorkingDirectory(),
166 if (!
gSystem->AccessPathName(
"PROOF-INF/SETUP.C")) {
168 gROOT->Macro(
"PROOF-INF/SETUP.C");
170 if (!
gSystem->ChangeDirectory(cwd.Data()))
return false;
207 TObjArray* depList = deps.Tokenize(
", ");
214 while ((dep = next()))
218 Info(
"ParUtilities::MakeScriptPAR",
"Loading macro %s", script.Data());
219 if (gROOT->LoadMacro(Form(
"%s++g", script.Data())) < 0) {
220 Error(
"ParUtilities::MakeScriptPAR",
221 "Failed to build local library %s", script.Data());
228 Info(
"ParUtilities::MakeScriptPAR",
"Making par file for %s",
231 Int_t idx = base.Last(
'.');
232 if (idx != kNPOS) base.Remove(idx);
237 if (script.EndsWith(
".C")) ext =
"C";
238 else if (script.EndsWith(
".cxx")) ext =
"cxx";
239 else { ext =
"C"; scr.Append(
".C"); }
242 TString path = TString::Format(
".:%s", TROOT::GetMacroPath());
243 char* loc =
gSystem->Which(path, scr);
245 Error(
"ParUtilities::MakeScriptPAR",
246 "Script %s not found in %s", scr.Data(), path.Data());
253 int ltempl = tmpdir.Length() + 1 + 5 + 6 + 1;
254 char* templ =
new char[ltempl];
255 snprintf(templ, ltempl,
"%s/trainXXXXXX", tmpdir.Data());
256 if (!mkdtemp(templ)) {
257 Error(
"ParUtilities::MakeScriptPAR",
258 "Failed to generate temporary directory from template %s",
262 Info(
"",
"Building PAR in %s", templ);
267 TString dir = TString::Format(
"%s/%s", templ, base.Data());
269 if (
gSystem->MakeDirectory(dir) < 0)
270 throw TString::Format(
"Could not make directory '%s'", base.Data());
271 if (
gSystem->MakeDirectory(Form(
"%s/PROOF-INF", dir.Data())))
272 throw TString::Format(
"Could not make directory %s/PROOF-INF",
274 Info(
"",
"Made directory %s", dir.Data());
277 TString dest = TString::Format(
"%s/%s.%s", dir.Data(),
278 base.Data(), ext.Data());
281 case -1:
throw TString::Format(
"Couldn't open %s for copy", scr.Data());
282 case -2:
throw TString::Format(
"File %s exists", dest.Data());
283 case -3:
throw TString::Format(
"Error while copying %s", scr.Data());
288 throw TString::Format(
"Failed to make build script");
290 throw TString::Format(
"Failed to make utility script");
292 throw TString::Format(
"Failed to make build macro");
294 throw TString::Format(
"Failed to setup macro");
297 ret =
gSystem->Exec(Form(
"(cd %s && tar -czf %s.par %s)",
298 templ, base.Data(),base.Data()));
300 throw TString::Format(
"Failed to create PAR file %s.PAR from %s",
301 base.Data(), dir.Data());
303 Info(
"",
"Made par archive %s/%s.par - moving here",
306 ret =
gSystem->Exec(Form(
"mv -f %s/%s.par %s.par", templ, base.Data(),
309 throw TString::Format(
"Failed to rename %s/%s.par to %s.par: %s",
310 templ, base.Data(), base.Data(),
315 Error(
"ParUtilities::MakeScriptPAR",
"%s", e.Data());
320 gSystem->Exec(Form(
"rm -rf %s", templ));
336 std::ofstream out(Form(
"%s/PROOF-INF/BUILD.sh", dir.Data()));
338 Error(
"ParUtilities::MakeScriptBuildScript",
339 "Failed to open out shell script");
343 <<
"if test x$ALICE_ROOT != x ; then\n"
344 <<
" export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ALICE_ROOT}/lib\n"
346 <<
"if test x$ALICE_PHYSICS != x ; then\n"
347 <<
" export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ALICE_PHYSICS}/lib\n"
349 <<
"# printenv | sort -u\n"
350 <<
"echo BUILD.sh@`hostname`: Building " << base <<
"\n"
351 <<
"root.exe -l -out -q PROOF-INF/BUILD.C 2>&1 | tee "
353 <<
"echo BUILD.sh@`hostname`: done: $?\n"
356 if (
gSystem->Chmod(Form(
"%s/PROOF-INF/BUILD.sh", dir.Data()), 0755) != 0) {
357 Error(
"ParUtilities::MakeScriptBuildScript",
358 "Failed to set exectuable flags on %s/PROOF-INF/BUILD.sh",
378 std::ofstream out(Form(
"%s/PROOF-INF/BUILD.C", dir.Data()));
380 Error(
"ParUtilities::MakeScriptBuildMacro",
"Failed to open build script");
383 out <<
"void BUILD() {\n"
384 <<
" gSystem->AddIncludePath(\"-DBUILD_PAR=1\");\n"
385 <<
" gROOT->LoadMacro(\"PROOF-INF/UTIL.C\");\n"
386 <<
" LoadROOTLibs();\n"
387 <<
" AddAliROOT();\n"
388 <<
" AddAliPhysics();\n";
392 while ((dep = next())) {
393 out <<
" AddDep(\"" << dep->GetName() <<
"\");\t"
394 <<
" LoadDep(\"" << dep->GetName() <<
"\");\n";
397 out <<
" // gDebug = 5;\n"
398 <<
" // gSystem->ListLibraries();\n"
399 <<
" int ret = gROOT->LoadMacro(\""
400 << base <<
"." << ext <<
"++g\");\n"
401 <<
" if (ret != 0) Fatal(\"BUILD\",\"Failed to build\");\n"
402 <<
" // else Info(\"BUILD\", \"Made " << base <<
"\");\n"
418 std::ofstream out(Form(
"%s/PROOF-INF/UTIL.C", dir.Data()));
420 Error(
"ParUtilities::MakeScriptUtilityScript",
421 "Failed to open utility script");
424 out <<
"void LoadROOTLibs() {\n"
425 <<
" gSystem->Load(\"libVMC\");\n"
426 <<
" gSystem->Load(\"libNet\");\n"
427 <<
" gSystem->Load(\"libTree\");\n"
428 <<
" gSystem->Load(\"libPhysics\");\n"
429 <<
" gSystem->Load(\"libMinuit\");\n"
431 out <<
"void AddAliROOT() {\n"
432 <<
" TString val(gSystem->Getenv(\"ALICE_ROOT\"));\n"
433 <<
" if (val.IsNull())\n"
434 <<
" Warning(\"Add\",\"ALICE_ROOT not defined\");\n"
436 <<
" gSystem->AddIncludePath(Form(\"-I%s/include\",val.Data()));\n"
438 out <<
"void AddAliPhysics() {\n"
439 <<
" TString val(gSystem->Getenv(\"ALICE_PHYSICS\"));\n"
440 <<
" if (val.IsNull())\n"
441 <<
" Warning(\"Add\",\"ALICE_PHYSICS not defined\");\n"
443 <<
" gSystem->AddIncludePath(Form(\"-I%s/include\",val.Data()));\n"
445 out <<
"void AddDep(const char* env) {\n"
446 <<
" TString val(gSystem->Getenv(Form(\"%s_INCLUDE\",env)));\n"
447 <<
" if (val.IsNull())\n"
448 <<
" Warning(\"Add\",\"%s_INCLUDE not defined\", env);\n"
450 <<
" // gSystem->AddIncludePath(Form(\"-I../%s\",val.Data()));\n"
451 <<
" // Prepend to include path\n"
452 <<
" TString incPath(gSystem->GetIncludePath());\n"
453 <<
" incPath.Prepend(Form(\"-I../%s \",val.Data()));\n"
454 <<
" gSystem->SetIncludePath(incPath);\n"
455 <<
" // Printf(\"Include path: %s\",incPath.Data());\n"
458 out <<
"void LoadDep(const char* name) {\n"
459 <<
" // Printf(\"Loading dependency \\\"%s\\\" ...\",name);\n"
460 <<
" // gSystem->AddDynamicPath(Form(\"../%s\",name));\n"
461 <<
" // Prepend to dynamic path\n"
462 <<
" TString dynPath(gSystem->GetDynamicPath());\n"
463 <<
" dynPath.Prepend(Form(\"../%s:\",name));\n"
464 <<
" gSystem->SetDynamicPath(dynPath);\n"
465 <<
" // Printf(\"Dynamic path: %s\",dynPath.Data());\n"
466 <<
" char* full = gSystem->DynamicPathName(name,true);\n"
468 <<
" full = gSystem->DynamicPathName(Form(\"lib%s\",name),true);\n"
470 <<
" full = gSystem->DynamicPathName(Form(\"lib%s.so\",name),true);\n"
472 <<
" full = gSystem->DynamicPathName(Form(\"%s_C.so\",name),true);\n"
474 <<
" full = gSystem->DynamicPathName(Form(\"%s_h.so\",name),true);\n"
476 <<
" Warning(\"LoadDep\",\"Module %s not found\", name);\n"
479 <<
" Printf(\"Loading \\\"%s\\\" for \\\"%s\\\"\",full,name);\n"
480 <<
" gSystem->Load(full);\n"
502 std::ofstream out(Form(
"%s/PROOF-INF/SETUP.C", dir.Data()));
504 Error(
"ParUtilities::MakeScriptSetupMacro",
505 "Failed to open setup script");
508 out <<
"void SETUP() {\n"
509 <<
" gROOT->LoadMacro(\"PROOF-INF/UTIL.C\");\n"
510 <<
" Printf(\"Loading \\\"" << base <<
"\\\" ...\");\n"
511 <<
" LoadROOTLibs();\n"
512 <<
" // Info(\"SETUP\",\"Loading libraries\");\n";
516 while ((dep = next()))
517 out <<
" LoadDep(\"" << dep->GetName() <<
"\");\n";
519 out <<
" // gDebug = 5;\n"
520 <<
" // Info(\"SETUP\",\"Loading " << base <<
"_"<< ext <<
".so\");\n"
521 <<
" gSystem->Load(\"" << base <<
"_" << ext <<
".so\");\n"
522 <<
" // gDebug = 0;\n"
523 <<
" gROOT->ProcessLine(\".include " << base <<
"\");\n"
524 <<
" gSystem->Setenv(\"" << base <<
"_INCLUDE\",\""
526 <<
" // Info(\"SETUP\", \"Done\");\n"
543 if (files.GetEntries() <= 0)
return true;
548 int ltempl = tmpdir.Length() + 1 + 5 + 6 + 1;
549 char* templ =
new char[ltempl];
550 snprintf(templ, ltempl,
"%s/trainXXXXXX", tmpdir.Data());
551 if (!mkdtemp(templ)) {
552 Error(
"ParUtilities::MakeAuxFilePAR",
553 "Failed to generate temporary directory from template %s",
557 if (verbose) Printf(
"Preparing PAR file in %s", templ);
561 TString dir = TString::Format(
"%s/%s", templ, name.Data());
563 if (
gSystem->MakeDirectory(dir) < 0)
564 throw TString::Format(
"Could not make directory '%s'", name.Data());
565 if (
gSystem->MakeDirectory(Form(
"%s/PROOF-INF", dir.Data())))
566 throw TString::Format(
"Could not make directory %s/PROOF-INF",
571 while ((o = next())) {
573 if (verbose) Printf(
"Got %s", fn.Data());
574 if (fn.BeginsWith(
"/")) {
575 Warning(
"MakeAuxFilePAR",
"Will not include absolute path %s",
580 if (
gSystem->AccessPathName(fn.Data())) {
581 Warning(
"MakeAuxFilePAR",
"Cannot access %s", fn.Data());
587 Int_t n = comps->GetEntriesFast();
588 if (verbose) Printf(
"Got %d path components in %s", n-1, fn.Data());
590 for (
Int_t i = 0; i < n-1; i++) {
591 TObjString* comp =
static_cast<TObjString*
>(comps->At(i));
593 if (c.IsNull())
continue;
594 if (c.EqualTo(
"."))
continue;
597 if (c.EqualTo(
"..")) { doMake =
false; lvl--; }
599 cur =
gSystem->ConcatFileName(cur, c);
601 Warning(
"MakeAuxFilePAR",
"Path %s points outside archive, ignored",
608 if (!
gSystem->AccessPathName(cur))
continue;
609 if (verbose) Printf(
"Making directory %s", cur.Data());
613 if (verbose) Printf(
"cur=%s for %s lvl=%d", cur.Data(), fn.Data(), lvl);
615 if (lvl < 0)
continue;
617 TString dest = TString::Format(
"%s/%s", cur.Data(),
619 if (verbose) Printf(
"%s -> %s", fn.Data(), dest.Data());
621 Int_t ret =
gSystem->Exec(Form(
"cp -f %s %s", fn.Data(), dest.Data()));
623 case -1:
throw TString::Format(
"Couldn't open %s for copy", fn.Data());
624 case -2:
throw TString::Format(
"File %s exists", dest.Data());
625 case -3:
throw TString::Format(
"Error while copying %s", fn.Data());
631 if (verbose) Printf(
"Making build script");
632 std::ofstream out(Form(
"%s/PROOF-INF/BUILD.sh", dir.Data()));
634 Error(
"ParUtilities::MakeAuxFilePAR",
635 "Failed to open out shell script");
638 out <<
"#!/bin/sh\n\n"
639 <<
"echo \"Nothing to be done\"\n\n"
640 <<
"# EOF" << std::endl;
642 if (
gSystem->Chmod(Form(
"%s/PROOF-INF/BUILD.sh", dir.Data()), 0755)) {
643 Error(
"ParUtilities::MakeAuxFilePAR",
644 "Failed to set exectuable flags on %s/PROOF-INF/BUILD.sh",
650 if (verbose) Printf(
"Making setup script");
652 std::ofstream out(Form(
"%s/PROOF-INF/SETUP.C", dir.Data()));
654 Error(
"ParUtilities::MakeAuxFilePAR",
655 "Failed to open out ROOT script");
662 out <<
"void SETUP()\n"
664 <<
" TString oldDir(gSystem->WorkingDirectory());\n"
665 <<
" TSystemDirectory* dir = new TSystemDirectory(\".\",\".\");\n"
666 <<
" TList* files = dir->GetListOfFiles();\n"
667 <<
" if (!gSystem->ChangeDirectory(oldDir)) {\n"
668 <<
" Error(\"SETUP\", \"Failed to go back to %s\",\n"
669 <<
" oldDir.Data());\n"
672 <<
" if (!files) {\n"
673 <<
" Warning(\"SETUP\", \"No files\");\n"
674 <<
" gSystem->Exec(\"pwd; ls -al\");\n"
677 <<
" files->Sort();\n"
678 <<
" TString pkgDir = gSystem->WorkingDirectory();\n"
679 <<
" TString sesDir = gProofServ->GetSessionDir();\n"
680 <<
" Info(\"\",\"Session dir: %s\",sesDir);\n"
681 <<
" TIter next(files);\n"
682 <<
" TSystemFile* file = 0;\n"
683 <<
" while ((file = static_cast<TSystemFile*>(next()))) {\n"
684 <<
" TString name(file->GetName());\n"
685 <<
" if (name == \".\" || name == \"..\") continue;\n"
686 <<
" TString title(file->GetTitle());\n"
687 <<
" TString full(gSystem->ConcatFileName(pkgDir.Data(),\n"
688 <<
" name.Data()));\n"
689 <<
" TString tgt(gSystem->ConcatFileName(sesDir.Data(),\n"
690 <<
" name.Data()));\n"
691 <<
" if (file->IsA()->InheritsFrom(TSystemDirectory::Class())){\n"
692 <<
" gSystem->mkdir(tgt.Data(), true);\n"
695 <<
" Info(\"\",\"Linking %s to %s\",full.Data(),tgt.Data());\n"
696 <<
" gSystem->Symlink(full, tgt);\n"
699 <<
"// EOF " << std::endl;
702 if (verbose) Printf(
"Packing up");
704 ret =
gSystem->Exec(Form(
"(cd %s && tar -c%szf %s.par %s)",
705 templ, (verbose ?
"v" :
""),
706 name.Data(),name.Data()));
708 throw TString::Format(
"Failed to create PAR file %s.PAR from %s",
709 name.Data(), name.Data());
712 if (verbose) Printf(
"Move here");
713 ret =
gSystem->Exec(Form(
"mv -f %s/%s.par %s.par", templ, name.Data(),
716 throw TString::Format(
"Failed to rename %s/%s.par to %s.par: %s",
717 templ, name.Data(), name.Data(),
722 Printf(
"List content");
723 gSystem->Exec(Form(
"tar tzf %s.par", name.Data()));
728 Error(
"ParUtilities::MakeAuxFilePAR",
"%s", e.Data());
733 gSystem->Exec(Form(
"rm -rf %s", templ));
static Bool_t MakeScriptPAR(Bool_t isLocal, const TString &script, const TString &deps, Railway *helper)
static Bool_t Load(const TString &name)
static Bool_t DoFind(const TString &what, TString &src)
static Bool_t Find(const TString &what)
static Bool_t MakeScriptBuildMacro(const TString &dir, const TString &base, const TString &ext, const TCollection *deps)
static Bool_t MakeScriptUtilityScript(const TString &dir)
Base class for analysis helpers.
static Bool_t MakeScriptSetupMacro(const TString &dir, const TString &base, const TString &ext, const TCollection *deps)
static Bool_t Build(const TString &what)
static Bool_t MakeScriptBuildScript(const TString &dir, const TString &base)
static Bool_t MakeAuxFilePAR(const TList &files, const TString &name, Bool_t verbose=false)
virtual Bool_t LoadLibrary(const TString &name, Bool_t slave=true, Bool_t forcePar=false)=0