]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/trains/BuildTrain.C
Fixed references from PWG2 -> PWGLF - very efficiently done using ETags.
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / trains / BuildTrain.C
1 /** 
2  * Build (compile) a train script 
3  * 
4  * @param script Script to compile 
5  * @param extra  Extra stuff for AcLic ("", "+", or "+g")
6  * @param useTmp Use a temporary file 
7  * 
8  * @return 
9  *
10  * @ingroup pwglf_forward_trains
11  */
12 Bool_t
13 BuildTrain(const char* script, const char* extra="", Bool_t useTmp=false)
14 {
15   // --- Load needed libraries ---------------------------------------
16   gROOT->LoadClass("TAlien",               "libRAliEn");
17   gROOT->LoadClass("TVirtualMC",           "libVMC");
18   gROOT->LoadClass("AliVEvent",            "libSTEERBase");
19   gROOT->LoadClass("AliESDEvent",          "libESD");
20   gROOT->LoadClass("AliAnalysisManager",   "libANALYSIS");
21   gROOT->LoadClass("AliAnalysisTaskSE",    "libANALYSISalice");
22   gROOT->LoadClass("AliAODForwardMult",    "libPWGLFforward2");
23
24   // --- Setup script path -------------------------------------------
25   const char* aliPath   = gSystem->ExpandPathName("$ALICE_ROOT");
26   const char* fwd2Path  = 
27     gSystem->ExpandPathName("$ALICE_ROOT/PWGLF/FORWARD/analysis2");
28   const char* macroPath = gROOT->GetMacroPath();
29   gROOT->SetMacroPath(Form(".:%s:%s/trains:%s/scripts",
30                            macroPath,fwd2Path,fwd2Path));
31   
32   // --- Setup include path ------------------------------------------
33   gSystem->AddIncludePath(Form("-I%s", fwd2Path));
34   gSystem->AddIncludePath(Form("-I%s/trains", fwd2Path));
35   gSystem->AddIncludePath(Form("-I%s", aliPath));
36   gSystem->AddIncludePath(Form("-I%s/include", aliPath));
37
38   // --- Check that we can find the script ---------------------------
39   TString path = gSystem->Which(gROOT->GetMacroPath(), script);
40   if (path.IsNull()) { 
41     path = gSystem->Which(gROOT->GetMacroPath(), Form("%s.C", script));
42     if (path.IsNull()) { 
43       Error("BuildTrain", "Cannot find script %s or %s.C in %s", 
44             script, script, gROOT->GetMacroPath());
45       return false;
46     }
47   }
48   
49   // --- Compile TrainSetup.C ----------------------------------------
50   Int_t ret = gROOT->LoadMacro(Form("%s/trains/TrainSetup.C+%s", 
51                                     fwd2Path, extra));
52   if (ret != 0) { 
53     Error("BuildTrain", "Failed to build TrainSetup");
54     return false;
55   }
56   
57   // --- Possibly make a temporary copy ------------------------------
58   if (useTmp) { 
59     TString tmp("Train");
60     FILE*   fp = gSystem->TempFileName(tmp, ".");
61     fclose(fp);
62     gSystem->Unlink(tmp);
63     tmp.Append(".C");
64     
65     gSystem->CopyFile(path, tmp);
66     path = tmp;
67   }
68
69   // --- Now compile the thing ---------------------------------------
70   ret = gROOT->LoadMacro(Form("%s+%s", path.Data(), extra));
71
72   // --- If we did a temporary file, remove stuff --------------------
73   if (useTmp) {
74     gSystem->Unlink(path);
75     path.ReplaceAll(".C",   "_C.d");  gSystem->Unlink(path);
76     path.ReplaceAll("_C.d", "_C.so"); gSystem->Unlink(path);
77   }
78
79   // --- Warning in case of problems ---------------------------------
80   if (ret != 0) 
81     Warning("BuildSetup", "Failed to build %s (%s)", path.Data(), script);
82
83   return ret == 0;
84 }
85 //
86 // EOF
87 //
88