]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/PWG0Helper.C
Class implements interface AliAnalysisCuts.
[u/mrichter/AliRoot.git] / PWG0 / PWG0Helper.C
CommitLineData
0bd1f8a0 1/* $Id$ */
2
3// Helper macros can be found in this file
4// A set of them can be used to connect to proof and execute selectors.
5
1f930d99 6TProof* connectProof(const char* proofServer)
0bd1f8a0 7{
1f930d99 8 TProof* proof = TProof::Open(proofServer);
0bd1f8a0 9
10 if (!proof)
11 {
12 printf("ERROR: PROOF connection not established.\n");
13 return 0;
14 }
15
0bd1f8a0 16 // enable the new packetizer
17 //proof->AddInput(new TNamed("PROOF_Packetizer", "TPacketizerProgressive"));
18
19 proof->ClearInput();
20
21 return proof;
22}
23
f10a1859 24Bool_t prepareQuery(TString libraries, TString packages, Int_t useAliRoot)
0bd1f8a0 25{
26 // if not proof load libraries
27 if (!gProof)
28 {
29 TObjArray* librariesList = libraries.Tokenize(";");
30 for (Int_t i=0; i<librariesList->GetEntries(); ++i)
31 {
32 TObjString* str = dynamic_cast<TObjString*> (librariesList->At(i));
33 if (!str)
34 continue;
35
36 printf("Loading %s...", str->String().Data());
37 Int_t result = CheckLoadLibrary(str->String());
38 if (result < 0)
39 {
40 printf("failed\n");
41 //return kFALSE;
42 }
43 else
44 printf("succeeded\n");
45 }
46 }
47 else
48 {
f10a1859 49 if (useAliRoot > 0)
50 ProofEnableAliRoot(useAliRoot);
0bd1f8a0 51
52 TObjArray* packagesList = packages.Tokenize(";");
53 for (Int_t i=0; i<packagesList->GetEntries(); ++i)
54 {
55 TObjString* str = dynamic_cast<TObjString*> (packagesList->At(i));
56 if (!str)
57 continue;
58
b5b6ea53 59 /*if (!EnablePackageLocal(str->String()))
0bd1f8a0 60 {
61 printf("Loading of package %s locally failed\n", str->String().Data());
62 return kFALSE;
b5b6ea53 63 }*/
0bd1f8a0 64
f10a1859 65 if (gProof->UploadPackage(Form("%s.par", str->String().Data())))
66 {
67 printf("Uploading of package %s failed\n", str->String().Data());
68 return kFALSE;
69 }
70
0bd1f8a0 71 if (gProof->EnablePackage(str->String()))
72 {
73 printf("Loading of package %s failed\n", str->String().Data());
74 return kFALSE;
75 }
76 }
77 }
78
79 return kTRUE;
80}
81
b6b218bd 82Int_t executeQuery(TChain* chain, TList* inputList, TString selectorName, const char* option = "", Long64_t entries = TChain::kBigNumber)
0bd1f8a0 83{
84 if (!gProof)
85 chain->GetUserInfo()->AddAll(inputList);
86 else
87 {
88 for (Int_t i=0; i<inputList->GetEntries(); ++i)
89 gProof->AddInput(inputList->At(i));
90 }
91
92 TStopwatch timer;
93 timer.Start();
94
95 Long64_t result = -1;
96
97 if (gProof)
1f930d99 98 {
99 chain->SetProof();
100 result = chain->Process(selectorName, option, entries);
101 }
0bd1f8a0 102 else
b6b218bd 103 result = chain->Process(selectorName, option, entries);
0bd1f8a0 104
105 if (result < 0)
106 printf("ERROR: Executing process failed with %d.\n", result);
107
108 timer.Stop();
109 timer.Print();
110
111 return result;
112}
113
e9c3977b 114const char* GetAliRootLocation(Int_t aliroot)
115{
116 switch (aliroot)
117 {
6eca43da 118 case 1: return "/afs/cern.ch/alice/caf/sw/ALICE/$ROOTVERSIONTAG/v4-04-Release/slc4_ia32_gcc34/aliroot"; break;
e9c3977b 119 default: return 0;
120 }
121}
122
f10a1859 123void ProofEnableAliRoot(Int_t aliroot)
0bd1f8a0 124{
125 // enables a locally deployed AliRoot in a PROOF cluster
126
127 /* executes the following commands on each node:
128 gSystem->Setenv("ALICE_ROOT", "/home/alicecaf/ALICE/aliroot-head")
129 gSystem->AddIncludePath("/home/alicecaf/ALICE/aliroot-head/include");
130 gSystem->SetDynamicPath(Form("%s:%s", gSystem->GetDynamicPath(), "/home/alicecaf/ALICE/aliroot-head/lib/tgt_linux"))
131 gSystem->Load("libMinuit");
132 gROOT->Macro("$ALICE_ROOT/macros/loadlibs.C");
133 */
134
e9c3977b 135 const char* location = GetAliRootLocation(aliroot);
b5b6ea53 136 const char* target = "tgt_linux";
0bd1f8a0 137
6eca43da 138 gProof->Exec(Form("TString str(gSystem->ExpandPathName(\"%s\")); gSystem->Setenv(\"ALICE_ROOT\", str);", location), kTRUE);
139
0bd1f8a0 140 gProof->AddIncludePath(Form("%s/include", location));
b5b6ea53 141 gProof->AddDynamicPath(Form("%s/lib/%s", location, target));
0bd1f8a0 142
143 // load all libraries
0bd1f8a0 144 gProof->Exec("gROOT->Macro(\"$ALICE_ROOT/macros/loadlibs.C\")");
145}
146
e9c3977b 147void ProofAddAliRootIncludePath(Int_t aliroot, const char* dir)
148{
149 // adds an include path inside the aliroot structure
150
151 const char* location = GetAliRootLocation(aliroot);
152 gProof->AddIncludePath(Form("%s/%s", location, dir));
153}
154
0bd1f8a0 155Bool_t EnablePackageLocal(const char* package)
156{
157 printf("Enabling package %s locally...\n", package);
158
4c351225 159 TString currentDir(gSystem->pwd());
0bd1f8a0 160 if (!gSystem->cd(package))
161 return kFALSE;
162
163 gROOT->ProcessLine(".x PROOF-INF/SETUP.C");
4c351225 164 gSystem->cd(currentDir);
0bd1f8a0 165
166 return kTRUE;
167}
168
169Int_t CheckLoadLibrary(const char* library)
170{
171 // checks if a library is already loaded, if not loads the library
172
173 if (strlen(gSystem->GetLibraries(Form("%s.so", library), "", kFALSE)) > 0)
174 return 1;
175
176 return gSystem->Load(library);
177}
178
179void redeployPackages(const char* proofServer, Bool_t localAliRoot = kTRUE)
180{
181 // deploys PWG0base and PWG0dep (the latter only when localAliRoot is true) that are expected in $ALICE_ROOT
182 // when localAliRoot is false ESD.par is also deployed
183
184 TProof::Reset(proofServer);
185 TVirtualProof* proof = TProof::Open(proofServer);
186 proof->ClearPackages();
187
188 if (localAliRoot)
189 ProofEnableAliRoot();
190 else
191 {
192 proof->UploadPackage("$ALICE_ROOT/ESD.par");
193 proof->EnablePackage("ESD");
194 }
195
196 proof->UploadPackage("$ALICE_ROOT/PWG0base.par");
197 proof->EnablePackage("PWG0base");
198
199 proof->UploadPackage("$ALICE_ROOT/PWG0dep.par");
200 proof->EnablePackage("PWG0dep");
201}