]>
Commit | Line | Data |
---|---|---|
c57f56b7 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // Author: Mihaela Gheata, 01/09/2008 | |
17 | ||
18 | //============================================================================== | |
19 | // AliAnalysisAlien - AliEn utility class. Provides interface for creating | |
20 | // a personalized JDL, finding and creating a dataset. | |
21 | //============================================================================== | |
22 | ||
65eb22f8 | 23 | #include "AliAnalysisAlien.h" |
24 | ||
c57f56b7 | 25 | #include "Riostream.h" |
0f389141 | 26 | #include "TEnv.h" |
105631b5 | 27 | #include "TKey.h" |
7c2cd90a | 28 | #include "TBits.h" |
0f389141 | 29 | #include "TError.h" |
c57f56b7 | 30 | #include "TROOT.h" |
31 | #include "TSystem.h" | |
32 | #include "TFile.h" | |
830acc4c | 33 | #include "TFileCollection.h" |
3bdcb562 | 34 | #include "TChain.h" |
c57f56b7 | 35 | #include "TObjString.h" |
36 | #include "TObjArray.h" | |
77f34eae | 37 | #include "TMacro.h" |
c57f56b7 | 38 | #include "TGrid.h" |
39 | #include "TGridResult.h" | |
40 | #include "TGridCollection.h" | |
41 | #include "TGridJDL.h" | |
d2a409b2 | 42 | #include "TGridJobStatusList.h" |
43 | #include "TGridJobStatus.h" | |
c57f56b7 | 44 | #include "TFileMerger.h" |
45 | #include "AliAnalysisManager.h" | |
77f34eae | 46 | #include "AliAnalysisTaskCfg.h" |
bb885a9e | 47 | #include "AliVEventHandler.h" |
48 | #include "AliAnalysisDataContainer.h" | |
65eb22f8 | 49 | #include "AliMultiInputEventHandler.h" |
c57f56b7 | 50 | |
c82bb898 | 51 | using std::ofstream; |
52 | using std::ifstream; | |
53 | using std::ios; | |
54 | using std::endl; | |
c57f56b7 | 55 | ClassImp(AliAnalysisAlien) |
6c395669 | 56 | #if 0 |
57 | ; | |
58 | #endif | |
c57f56b7 | 59 | |
6c395669 | 60 | namespace { |
61 | Bool_t copyLocal2Alien(const char* where, const char* loc, const char* rem) | |
62 | { | |
63 | TString sl(Form("file:%s", loc)); | |
64 | TString sr(Form("alien://%s", rem)); | |
65 | Bool_t ret = TFile::Cp(sl, sr); | |
66 | if (!ret) { | |
67 | Warning(where, "Failed to copy %s to %s", sl.Data(), sr.Data()); | |
68 | } | |
69 | return ret; | |
70 | } | |
71 | } | |
72 | ||
c57f56b7 | 73 | //______________________________________________________________________________ |
74 | AliAnalysisAlien::AliAnalysisAlien() | |
75 | :AliAnalysisGrid(), | |
76 | fGridJDL(NULL), | |
0f389141 | 77 | fMergingJDL(NULL), |
c57f56b7 | 78 | fPrice(0), |
79 | fTTL(0), | |
80 | fSplitMaxInputFileNumber(0), | |
81 | fMaxInitFailed(0), | |
82 | fMasterResubmitThreshold(0), | |
bb885a9e | 83 | fNtestFiles(0), |
319593fb | 84 | fNrunsPerMaster(0), |
16a4353c | 85 | fMaxMergeFiles(0), |
b3e07543 | 86 | fMaxMergeStages(0), |
d2a409b2 | 87 | fNsubmitted(0), |
a3e84053 | 88 | fProductionMode(0), |
cd11251e | 89 | fOutputToRunNo(0), |
0f389141 | 90 | fMergeViaJDL(0), |
91 | fFastReadOption(0), | |
e1c22e21 | 92 | fOverwriteMode(1), |
149d288c | 93 | fNreplicas(2), |
3bdcb562 | 94 | fNproofWorkers(0), |
27734f0e | 95 | fNproofWorkersPerSlave(0), |
3bdcb562 | 96 | fProofReset(0), |
c57f56b7 | 97 | fRunNumbers(), |
98 | fExecutable(), | |
0a1c1f7f | 99 | fExecutableCommand(), |
c57f56b7 | 100 | fArguments(), |
631c0b05 | 101 | fExecutableArgs(), |
c57f56b7 | 102 | fAnalysisMacro(), |
103 | fAnalysisSource(), | |
d3b18c4c | 104 | fValidationScript(), |
d5c6455a | 105 | fAdditionalRootLibs(), |
c57f56b7 | 106 | fAdditionalLibs(), |
107 | fSplitMode(), | |
108 | fAPIVersion(), | |
109 | fROOTVersion(), | |
110 | fAliROOTVersion(), | |
648174cf | 111 | fExternalPackages(), |
c57f56b7 | 112 | fUser(), |
113 | fGridWorkingDir(), | |
114 | fGridDataDir(), | |
115 | fDataPattern(), | |
116 | fGridOutputDir(), | |
117 | fOutputArchive(), | |
118 | fOutputFiles(), | |
119 | fInputFormat(), | |
e7c71df0 | 120 | fDatasetName(), |
c57f56b7 | 121 | fJDLName(), |
d3b18c4c | 122 | fTerminateFiles(), |
bb885a9e | 123 | fMergeExcludes(), |
37d21c01 | 124 | fRegisterExcludes(), |
f965131e | 125 | fIncludePath(), |
bb885a9e | 126 | fCloseSE(), |
0df6ccf2 | 127 | fFriendChainName(), |
c6cb3634 | 128 | fJobTag(), |
648174cf | 129 | fOutputSingle(), |
5fce53f4 | 130 | fRunPrefix(), |
3bdcb562 | 131 | fProofCluster(), |
132 | fProofDataSet(), | |
133 | fFileForTestMode(), | |
134 | fRootVersionForProof(), | |
135 | fAliRootMode(), | |
d88e4159 | 136 | fProofProcessOpt(), |
f47d5cb4 | 137 | fMergeDirName(), |
4e5c5506 | 138 | fInputFiles(0), |
28ce6c9c | 139 | fPackages(0), |
77f34eae | 140 | fModules(0), |
d88e4159 | 141 | fProofParam(), |
142 | fDropToShell(true) | |
c57f56b7 | 143 | { |
144 | // Dummy ctor. | |
145 | SetDefaults(); | |
146 | } | |
147 | ||
148 | //______________________________________________________________________________ | |
149 | AliAnalysisAlien::AliAnalysisAlien(const char *name) | |
150 | :AliAnalysisGrid(name), | |
151 | fGridJDL(NULL), | |
0f389141 | 152 | fMergingJDL(NULL), |
c57f56b7 | 153 | fPrice(0), |
154 | fTTL(0), | |
155 | fSplitMaxInputFileNumber(0), | |
156 | fMaxInitFailed(0), | |
157 | fMasterResubmitThreshold(0), | |
bb885a9e | 158 | fNtestFiles(0), |
319593fb | 159 | fNrunsPerMaster(0), |
16a4353c | 160 | fMaxMergeFiles(0), |
b3e07543 | 161 | fMaxMergeStages(0), |
d2a409b2 | 162 | fNsubmitted(0), |
a3e84053 | 163 | fProductionMode(0), |
cd11251e | 164 | fOutputToRunNo(0), |
0f389141 | 165 | fMergeViaJDL(0), |
166 | fFastReadOption(0), | |
e1c22e21 | 167 | fOverwriteMode(1), |
149d288c | 168 | fNreplicas(2), |
3bdcb562 | 169 | fNproofWorkers(0), |
27734f0e | 170 | fNproofWorkersPerSlave(0), |
3bdcb562 | 171 | fProofReset(0), |
c57f56b7 | 172 | fRunNumbers(), |
173 | fExecutable(), | |
0a1c1f7f | 174 | fExecutableCommand(), |
c57f56b7 | 175 | fArguments(), |
631c0b05 | 176 | fExecutableArgs(), |
c57f56b7 | 177 | fAnalysisMacro(), |
178 | fAnalysisSource(), | |
d3b18c4c | 179 | fValidationScript(), |
d5c6455a | 180 | fAdditionalRootLibs(), |
c57f56b7 | 181 | fAdditionalLibs(), |
182 | fSplitMode(), | |
183 | fAPIVersion(), | |
184 | fROOTVersion(), | |
185 | fAliROOTVersion(), | |
648174cf | 186 | fExternalPackages(), |
c57f56b7 | 187 | fUser(), |
188 | fGridWorkingDir(), | |
189 | fGridDataDir(), | |
190 | fDataPattern(), | |
191 | fGridOutputDir(), | |
192 | fOutputArchive(), | |
193 | fOutputFiles(), | |
194 | fInputFormat(), | |
e7c71df0 | 195 | fDatasetName(), |
c57f56b7 | 196 | fJDLName(), |
d3b18c4c | 197 | fTerminateFiles(), |
bb885a9e | 198 | fMergeExcludes(), |
37d21c01 | 199 | fRegisterExcludes(), |
f965131e | 200 | fIncludePath(), |
bb885a9e | 201 | fCloseSE(), |
0df6ccf2 | 202 | fFriendChainName(), |
c6cb3634 | 203 | fJobTag(), |
648174cf | 204 | fOutputSingle(), |
5fce53f4 | 205 | fRunPrefix(), |
3bdcb562 | 206 | fProofCluster(), |
207 | fProofDataSet(), | |
208 | fFileForTestMode(), | |
209 | fRootVersionForProof(), | |
210 | fAliRootMode(), | |
d88e4159 | 211 | fProofProcessOpt(), |
f47d5cb4 | 212 | fMergeDirName(), |
4e5c5506 | 213 | fInputFiles(0), |
28ce6c9c | 214 | fPackages(0), |
77f34eae | 215 | fModules(0), |
d88e4159 | 216 | fProofParam(), |
217 | fDropToShell(true) | |
c57f56b7 | 218 | { |
219 | // Default ctor. | |
220 | SetDefaults(); | |
221 | } | |
222 | ||
223 | //______________________________________________________________________________ | |
224 | AliAnalysisAlien::AliAnalysisAlien(const AliAnalysisAlien& other) | |
225 | :AliAnalysisGrid(other), | |
226 | fGridJDL(NULL), | |
0f389141 | 227 | fMergingJDL(NULL), |
c57f56b7 | 228 | fPrice(other.fPrice), |
229 | fTTL(other.fTTL), | |
230 | fSplitMaxInputFileNumber(other.fSplitMaxInputFileNumber), | |
231 | fMaxInitFailed(other.fMaxInitFailed), | |
232 | fMasterResubmitThreshold(other.fMasterResubmitThreshold), | |
bb885a9e | 233 | fNtestFiles(other.fNtestFiles), |
319593fb | 234 | fNrunsPerMaster(other.fNrunsPerMaster), |
16a4353c | 235 | fMaxMergeFiles(other.fMaxMergeFiles), |
b3e07543 | 236 | fMaxMergeStages(other.fMaxMergeStages), |
d2a409b2 | 237 | fNsubmitted(other.fNsubmitted), |
a3e84053 | 238 | fProductionMode(other.fProductionMode), |
cd11251e | 239 | fOutputToRunNo(other.fOutputToRunNo), |
0f389141 | 240 | fMergeViaJDL(other.fMergeViaJDL), |
241 | fFastReadOption(other.fFastReadOption), | |
242 | fOverwriteMode(other.fOverwriteMode), | |
149d288c | 243 | fNreplicas(other.fNreplicas), |
3bdcb562 | 244 | fNproofWorkers(other.fNproofWorkers), |
27734f0e | 245 | fNproofWorkersPerSlave(other.fNproofWorkersPerSlave), |
3bdcb562 | 246 | fProofReset(other.fProofReset), |
c57f56b7 | 247 | fRunNumbers(other.fRunNumbers), |
248 | fExecutable(other.fExecutable), | |
0a1c1f7f | 249 | fExecutableCommand(other.fExecutableCommand), |
c57f56b7 | 250 | fArguments(other.fArguments), |
631c0b05 | 251 | fExecutableArgs(other.fExecutableArgs), |
c57f56b7 | 252 | fAnalysisMacro(other.fAnalysisMacro), |
253 | fAnalysisSource(other.fAnalysisSource), | |
d3b18c4c | 254 | fValidationScript(other.fValidationScript), |
d5c6455a | 255 | fAdditionalRootLibs(other.fAdditionalRootLibs), |
c57f56b7 | 256 | fAdditionalLibs(other.fAdditionalLibs), |
257 | fSplitMode(other.fSplitMode), | |
258 | fAPIVersion(other.fAPIVersion), | |
259 | fROOTVersion(other.fROOTVersion), | |
260 | fAliROOTVersion(other.fAliROOTVersion), | |
648174cf | 261 | fExternalPackages(other.fExternalPackages), |
c57f56b7 | 262 | fUser(other.fUser), |
263 | fGridWorkingDir(other.fGridWorkingDir), | |
264 | fGridDataDir(other.fGridDataDir), | |
265 | fDataPattern(other.fDataPattern), | |
266 | fGridOutputDir(other.fGridOutputDir), | |
267 | fOutputArchive(other.fOutputArchive), | |
268 | fOutputFiles(other.fOutputFiles), | |
269 | fInputFormat(other.fInputFormat), | |
e7c71df0 | 270 | fDatasetName(other.fDatasetName), |
c57f56b7 | 271 | fJDLName(other.fJDLName), |
d3b18c4c | 272 | fTerminateFiles(other.fTerminateFiles), |
bb885a9e | 273 | fMergeExcludes(other.fMergeExcludes), |
37d21c01 | 274 | fRegisterExcludes(other.fRegisterExcludes), |
f965131e | 275 | fIncludePath(other.fIncludePath), |
bb885a9e | 276 | fCloseSE(other.fCloseSE), |
0df6ccf2 | 277 | fFriendChainName(other.fFriendChainName), |
c6cb3634 | 278 | fJobTag(other.fJobTag), |
648174cf | 279 | fOutputSingle(other.fOutputSingle), |
5fce53f4 | 280 | fRunPrefix(other.fRunPrefix), |
3bdcb562 | 281 | fProofCluster(other.fProofCluster), |
282 | fProofDataSet(other.fProofDataSet), | |
283 | fFileForTestMode(other.fFileForTestMode), | |
284 | fRootVersionForProof(other.fRootVersionForProof), | |
285 | fAliRootMode(other.fAliRootMode), | |
d88e4159 | 286 | fProofProcessOpt(other.fProofProcessOpt), |
f47d5cb4 | 287 | fMergeDirName(other.fMergeDirName), |
4e5c5506 | 288 | fInputFiles(0), |
28ce6c9c | 289 | fPackages(0), |
77f34eae | 290 | fModules(0), |
d88e4159 | 291 | fProofParam(), |
292 | fDropToShell(other.fDropToShell) | |
c57f56b7 | 293 | { |
294 | // Copy ctor. | |
295 | fGridJDL = (TGridJDL*)gROOT->ProcessLine("new TAlienJDL()"); | |
0f389141 | 296 | fMergingJDL = (TGridJDL*)gROOT->ProcessLine("new TAlienJDL()"); |
a8739e8a | 297 | fRunRange[0] = other.fRunRange[0]; |
298 | fRunRange[1] = other.fRunRange[1]; | |
c57f56b7 | 299 | if (other.fInputFiles) { |
300 | fInputFiles = new TObjArray(); | |
301 | TIter next(other.fInputFiles); | |
302 | TObject *obj; | |
303 | while ((obj=next())) fInputFiles->Add(new TObjString(obj->GetName())); | |
304 | fInputFiles->SetOwner(); | |
305 | } | |
4e5c5506 | 306 | if (other.fPackages) { |
307 | fPackages = new TObjArray(); | |
308 | TIter next(other.fPackages); | |
309 | TObject *obj; | |
310 | while ((obj=next())) fPackages->Add(new TObjString(obj->GetName())); | |
311 | fPackages->SetOwner(); | |
312 | } | |
77f34eae | 313 | if (other.fModules) { |
314 | fModules = new TObjArray(); | |
315 | fModules->SetOwner(); | |
316 | TIter next(other.fModules); | |
317 | AliAnalysisTaskCfg *mod, *crt; | |
318 | while ((crt=(AliAnalysisTaskCfg*)next())) { | |
319 | mod = new AliAnalysisTaskCfg(*crt); | |
320 | fModules->Add(mod); | |
321 | } | |
322 | } | |
c57f56b7 | 323 | } |
324 | ||
325 | //______________________________________________________________________________ | |
326 | AliAnalysisAlien::~AliAnalysisAlien() | |
327 | { | |
328 | // Destructor. | |
77f34eae | 329 | delete fGridJDL; |
330 | delete fMergingJDL; | |
331 | delete fInputFiles; | |
332 | delete fPackages; | |
333 | delete fModules; | |
28ce6c9c | 334 | fProofParam.DeleteAll(); |
c57f56b7 | 335 | } |
336 | ||
337 | //______________________________________________________________________________ | |
338 | AliAnalysisAlien &AliAnalysisAlien::operator=(const AliAnalysisAlien& other) | |
339 | { | |
340 | // Assignment. | |
341 | if (this != &other) { | |
342 | AliAnalysisGrid::operator=(other); | |
343 | fGridJDL = (TGridJDL*)gROOT->ProcessLine("new TAlienJDL()"); | |
0f389141 | 344 | fMergingJDL = (TGridJDL*)gROOT->ProcessLine("new TAlienJDL()"); |
c57f56b7 | 345 | fPrice = other.fPrice; |
346 | fTTL = other.fTTL; | |
347 | fSplitMaxInputFileNumber = other.fSplitMaxInputFileNumber; | |
348 | fMaxInitFailed = other.fMaxInitFailed; | |
349 | fMasterResubmitThreshold = other.fMasterResubmitThreshold; | |
bb885a9e | 350 | fNtestFiles = other.fNtestFiles; |
a3e84053 | 351 | fNrunsPerMaster = other.fNrunsPerMaster; |
352 | fMaxMergeFiles = other.fMaxMergeFiles; | |
b3e07543 | 353 | fMaxMergeStages = other.fMaxMergeStages; |
a3e84053 | 354 | fNsubmitted = other.fNsubmitted; |
355 | fProductionMode = other.fProductionMode; | |
cd11251e | 356 | fOutputToRunNo = other.fOutputToRunNo; |
0f389141 | 357 | fMergeViaJDL = other.fMergeViaJDL; |
358 | fFastReadOption = other.fFastReadOption; | |
359 | fOverwriteMode = other.fOverwriteMode; | |
149d288c | 360 | fNreplicas = other.fNreplicas; |
3bdcb562 | 361 | fNproofWorkers = other.fNproofWorkers; |
27734f0e | 362 | fNproofWorkersPerSlave = other.fNproofWorkersPerSlave; |
3bdcb562 | 363 | fProofReset = other.fProofReset; |
c57f56b7 | 364 | fRunNumbers = other.fRunNumbers; |
365 | fExecutable = other.fExecutable; | |
0a1c1f7f | 366 | fExecutableCommand = other.fExecutableCommand; |
c57f56b7 | 367 | fArguments = other.fArguments; |
631c0b05 | 368 | fExecutableArgs = other.fExecutableArgs; |
c57f56b7 | 369 | fAnalysisMacro = other.fAnalysisMacro; |
370 | fAnalysisSource = other.fAnalysisSource; | |
d3b18c4c | 371 | fValidationScript = other.fValidationScript; |
d5c6455a | 372 | fAdditionalRootLibs = other.fAdditionalRootLibs; |
c57f56b7 | 373 | fAdditionalLibs = other.fAdditionalLibs; |
374 | fSplitMode = other.fSplitMode; | |
375 | fAPIVersion = other.fAPIVersion; | |
376 | fROOTVersion = other.fROOTVersion; | |
377 | fAliROOTVersion = other.fAliROOTVersion; | |
648174cf | 378 | fExternalPackages = other.fExternalPackages; |
c57f56b7 | 379 | fUser = other.fUser; |
380 | fGridWorkingDir = other.fGridWorkingDir; | |
381 | fGridDataDir = other.fGridDataDir; | |
382 | fDataPattern = other.fDataPattern; | |
383 | fGridOutputDir = other.fGridOutputDir; | |
384 | fOutputArchive = other.fOutputArchive; | |
385 | fOutputFiles = other.fOutputFiles; | |
386 | fInputFormat = other.fInputFormat; | |
e7c71df0 | 387 | fDatasetName = other.fDatasetName; |
c57f56b7 | 388 | fJDLName = other.fJDLName; |
d3b18c4c | 389 | fTerminateFiles = other.fTerminateFiles; |
bb885a9e | 390 | fMergeExcludes = other.fMergeExcludes; |
37d21c01 | 391 | fRegisterExcludes = other.fRegisterExcludes; |
f965131e | 392 | fIncludePath = other.fIncludePath; |
bb885a9e | 393 | fCloseSE = other.fCloseSE; |
0df6ccf2 | 394 | fFriendChainName = other.fFriendChainName; |
c6cb3634 | 395 | fJobTag = other.fJobTag; |
648174cf | 396 | fOutputSingle = other.fOutputSingle; |
5fce53f4 | 397 | fRunPrefix = other.fRunPrefix; |
3bdcb562 | 398 | fProofCluster = other.fProofCluster; |
399 | fProofDataSet = other.fProofDataSet; | |
400 | fFileForTestMode = other.fFileForTestMode; | |
401 | fRootVersionForProof = other.fRootVersionForProof; | |
402 | fAliRootMode = other.fAliRootMode; | |
d88e4159 | 403 | fProofProcessOpt = other.fProofProcessOpt; |
f47d5cb4 | 404 | fMergeDirName = other.fMergeDirName; |
d88e4159 | 405 | fDropToShell = other.fDropToShell; |
c57f56b7 | 406 | if (other.fInputFiles) { |
407 | fInputFiles = new TObjArray(); | |
408 | TIter next(other.fInputFiles); | |
409 | TObject *obj; | |
410 | while ((obj=next())) fInputFiles->Add(new TObjString(obj->GetName())); | |
411 | fInputFiles->SetOwner(); | |
412 | } | |
4e5c5506 | 413 | if (other.fPackages) { |
414 | fPackages = new TObjArray(); | |
415 | TIter next(other.fPackages); | |
416 | TObject *obj; | |
417 | while ((obj=next())) fPackages->Add(new TObjString(obj->GetName())); | |
418 | fPackages->SetOwner(); | |
419 | } | |
77f34eae | 420 | if (other.fModules) { |
421 | fModules = new TObjArray(); | |
422 | fModules->SetOwner(); | |
423 | TIter next(other.fModules); | |
424 | AliAnalysisTaskCfg *mod, *crt; | |
425 | while ((crt=(AliAnalysisTaskCfg*)next())) { | |
426 | mod = new AliAnalysisTaskCfg(*crt); | |
427 | fModules->Add(mod); | |
428 | } | |
429 | } | |
c57f56b7 | 430 | } |
431 | return *this; | |
432 | } | |
433 | ||
37d21c01 | 434 | //______________________________________________________________________________ |
435 | void AliAnalysisAlien::AddAdditionalLibrary(const char *name) | |
436 | { | |
437 | // Add a single additional library to be loaded. Extension must be present. | |
438 | TString lib(name); | |
439 | if (!lib.Contains(".")) { | |
440 | Error("AddAdditionalLibrary", "Extension not defined for %s", name); | |
441 | return; | |
442 | } | |
443 | if (fAdditionalLibs.Contains(name)) { | |
444 | Warning("AddAdditionalLibrary", "Library %s already added.", name); | |
445 | return; | |
446 | } | |
447 | if (!fAdditionalLibs.IsNull()) fAdditionalLibs += " "; | |
448 | fAdditionalLibs += lib; | |
449 | } | |
450 | ||
77f34eae | 451 | //______________________________________________________________________________ |
452 | void AliAnalysisAlien::AddModule(AliAnalysisTaskCfg *module) | |
453 | { | |
454 | // Adding a module. Checks if already existing. Becomes owned by this. | |
455 | if (!module) return; | |
456 | if (GetModule(module->GetName())) { | |
457 | Error("AddModule", "A module having the same name %s already added", module->GetName()); | |
458 | return; | |
459 | } | |
460 | if (!fModules) { | |
461 | fModules = new TObjArray(); | |
462 | fModules->SetOwner(); | |
463 | } | |
464 | fModules->Add(module); | |
465 | } | |
466 | ||
467 | //______________________________________________________________________________ | |
468 | void AliAnalysisAlien::AddModules(TObjArray *list) | |
469 | { | |
470 | // Adding a list of modules. Checks if already existing. Becomes owned by this. | |
471 | TIter next(list); | |
472 | AliAnalysisTaskCfg *module; | |
473 | while ((module = (AliAnalysisTaskCfg*)next())) AddModule(module); | |
474 | } | |
475 | ||
476 | //______________________________________________________________________________ | |
477 | Bool_t AliAnalysisAlien::CheckDependencies() | |
478 | { | |
479 | // Check if all dependencies are satisfied. Reorder modules if needed. | |
480 | Int_t nmodules = GetNmodules(); | |
481 | if (!nmodules) { | |
482 | Warning("CheckDependencies", "No modules added yet to check their dependencies"); | |
483 | return kTRUE; | |
484 | } | |
485 | AliAnalysisTaskCfg *mod = 0; | |
486 | AliAnalysisTaskCfg *dep = 0; | |
487 | TString depname; | |
488 | Int_t i, j, k; | |
489 | for (i=0; i<nmodules; i++) { | |
490 | mod = (AliAnalysisTaskCfg*) fModules->At(i); | |
491 | Int_t ndeps = mod->GetNdeps(); | |
492 | Int_t istart = i; | |
493 | for (j=0; j<ndeps; j++) { | |
494 | depname = mod->GetDependency(j); | |
495 | dep = GetModule(depname); | |
496 | if (!dep) { | |
497 | Error("CheckDependencies","Dependency %s not added for module %s", | |
498 | depname.Data(), mod->GetName()); | |
499 | return kFALSE; | |
500 | } | |
501 | if (dep->NeedsDependency(mod->GetName())) { | |
502 | Error("CheckDependencies","Modules %s and %s circularly depend on each other", | |
503 | mod->GetName(), dep->GetName()); | |
504 | return kFALSE; | |
505 | } | |
506 | Int_t idep = fModules->IndexOf(dep); | |
507 | // The dependency task must come first | |
508 | if (idep>i) { | |
509 | // Remove at idep and move all objects below up one slot | |
510 | // down to index i included. | |
511 | fModules->RemoveAt(idep); | |
3e40fd4c | 512 | for (k=idep-1; k>=i; k--) fModules->AddAt(fModules->RemoveAt(k),k+1); |
77f34eae | 513 | fModules->AddAt(dep, i++); |
514 | } | |
515 | //Redo from istart if dependencies were inserted | |
516 | if (i>istart) i=istart-1; | |
517 | } | |
518 | } | |
519 | return kTRUE; | |
520 | } | |
521 | ||
3e40fd4c | 522 | //______________________________________________________________________________ |
523 | AliAnalysisManager *AliAnalysisAlien::CreateAnalysisManager(const char *name, const char *filename) | |
524 | { | |
525 | // Create the analysis manager and optionally execute the macro in filename. | |
526 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
527 | if (mgr) return mgr; | |
528 | mgr = new AliAnalysisManager(name); | |
529 | mgr->SetGridHandler((AliAnalysisGrid*)this); | |
530 | if (strlen(filename)) { | |
531 | TString line = gSystem->ExpandPathName(filename); | |
532 | line.Prepend(".x "); | |
533 | gROOT->ProcessLine(line.Data()); | |
534 | } | |
535 | return mgr; | |
536 | } | |
537 | ||
77f34eae | 538 | //______________________________________________________________________________ |
539 | Int_t AliAnalysisAlien::GetNmodules() const | |
540 | { | |
541 | // Get number of modules. | |
542 | if (!fModules) return 0; | |
543 | return fModules->GetEntries(); | |
544 | } | |
545 | ||
546 | //______________________________________________________________________________ | |
547 | AliAnalysisTaskCfg *AliAnalysisAlien::GetModule(const char *name) | |
548 | { | |
549 | // Get a module by name. | |
550 | if (!fModules) return 0; | |
551 | return (AliAnalysisTaskCfg*)fModules->FindObject(name); | |
552 | } | |
553 | ||
554 | //______________________________________________________________________________ | |
555 | Bool_t AliAnalysisAlien::LoadModule(AliAnalysisTaskCfg *mod) | |
556 | { | |
557 | // Load a given module. | |
558 | if (mod->IsLoaded()) return kTRUE; | |
192ddca2 | 559 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); |
560 | if (!mgr) { | |
561 | Error("LoadModule", "No analysis manager created yet. Use CreateAnalysisManager first."); | |
562 | return kFALSE; | |
563 | } | |
77f34eae | 564 | Int_t ndeps = mod->GetNdeps(); |
565 | TString depname; | |
566 | for (Int_t j=0; j<ndeps; j++) { | |
567 | depname = mod->GetDependency(j); | |
568 | AliAnalysisTaskCfg *dep = GetModule(depname); | |
569 | if (!dep) { | |
570 | Error("LoadModule","Dependency %s not existing for module %s", | |
571 | depname.Data(), mod->GetName()); | |
572 | return kFALSE; | |
573 | } | |
574 | if (!LoadModule(dep)) { | |
575 | Error("LoadModule","Dependency %s for module %s could not be loaded", | |
576 | depname.Data(), mod->GetName()); | |
577 | return kFALSE; | |
578 | } | |
579 | } | |
580 | // Load libraries for the module | |
581 | if (!mod->CheckLoadLibraries()) { | |
582 | Error("LoadModule", "Cannot load all libraries for module %s", mod->GetName()); | |
583 | return kFALSE; | |
584 | } | |
192ddca2 | 585 | // Check if a custom file name was requested |
586 | if (strlen(mod->GetOutputFileName())) mgr->SetCommonFileName(mod->GetOutputFileName()); | |
587 | ||
588 | // Check if a custom terminate file name was requested | |
589 | if (strlen(mod->GetTerminateFileName())) { | |
590 | if (!fTerminateFiles.IsNull()) fTerminateFiles += ","; | |
591 | fTerminateFiles += mod->GetTerminateFileName(); | |
592 | } | |
593 | ||
77f34eae | 594 | // Execute the macro |
595 | if (mod->ExecuteMacro()<0) { | |
596 | Error("LoadModule", "Executing the macro %s with arguments: %s for module %s returned a negative value", | |
597 | mod->GetMacroName(), mod->GetMacroArgs(), mod->GetName()); | |
598 | return kFALSE; | |
599 | } | |
600 | // Configure dependencies | |
601 | if (mod->GetConfigMacro() && mod->ExecuteConfigMacro()<0) { | |
602 | Error("LoadModule", "There was an error executing the deps config macro %s for module %s", | |
603 | mod->GetConfigMacro()->GetTitle(), mod->GetName()); | |
604 | return kFALSE; | |
605 | } | |
5e8c7c22 | 606 | // Adjust extra libraries |
607 | Int_t nlibs = mod->GetNlibs(); | |
608 | TString lib; | |
609 | for (Int_t i=0; i<nlibs; i++) { | |
610 | lib = mod->GetLibrary(i); | |
5e8c7c22 | 611 | lib = Form("lib%s.so", lib.Data()); |
c9d6bd12 | 612 | if (fAdditionalLibs.Contains(lib)) continue; |
5e8c7c22 | 613 | if (!fAdditionalLibs.IsNull()) fAdditionalLibs += " "; |
614 | fAdditionalLibs += lib; | |
615 | } | |
77f34eae | 616 | return kTRUE; |
617 | } | |
618 | ||
139fe6ba | 619 | //______________________________________________________________________________ |
620 | Bool_t AliAnalysisAlien::GenerateTrain(const char *name) | |
621 | { | |
622 | // Generate the full train. | |
623 | fAdditionalLibs = ""; | |
624 | if (!LoadModules()) return kFALSE; | |
625 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
626 | if (!mgr->InitAnalysis()) return kFALSE; | |
d512d8e2 | 627 | mgr->RunLocalInit(); |
139fe6ba | 628 | mgr->PrintStatus(); |
629 | Int_t productionMode = fProductionMode; | |
630 | SetProductionMode(); | |
631 | TString macro = fAnalysisMacro; | |
632 | TString executable = fExecutable; | |
633 | TString validation = fValidationScript; | |
634 | TString execCommand = fExecutableCommand; | |
635 | SetAnalysisMacro(Form("%s.C", name)); | |
636 | SetExecutable(Form("%s.sh", name)); | |
a8e31fb0 | 637 | // SetExecutableCommand("aliroot -b -q "); |
139fe6ba | 638 | SetValidationScript(Form("%s_validation.sh", name)); |
639 | StartAnalysis(); | |
640 | SetProductionMode(productionMode); | |
641 | fAnalysisMacro = macro; | |
642 | fExecutable = executable; | |
643 | fExecutableCommand = execCommand; | |
644 | fValidationScript = validation; | |
645 | return kTRUE; | |
646 | } | |
647 | ||
77f34eae | 648 | //______________________________________________________________________________ |
21ca8e59 | 649 | Bool_t AliAnalysisAlien::GenerateTest(const char *name, const char *modname) |
77f34eae | 650 | { |
651 | // Generate test macros for a single module or for the full train. | |
5e8c7c22 | 652 | fAdditionalLibs = ""; |
77f34eae | 653 | if (strlen(modname)) { |
21ca8e59 | 654 | if (!CheckDependencies()) return kFALSE; |
655 | AliAnalysisTaskCfg *mod = GetModule(modname); | |
656 | if (!mod) { | |
657 | Error("GenerateTest", "cannot generate test for inexistent module %s", modname); | |
658 | return kFALSE; | |
659 | } | |
660 | if (!LoadModule(mod)) return kFALSE; | |
661 | } else if (!LoadModules()) return kFALSE; | |
662 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
663 | if (!mgr->InitAnalysis()) return kFALSE; | |
d512d8e2 | 664 | mgr->RunLocalInit(); |
21ca8e59 | 665 | mgr->PrintStatus(); |
666 | SetLocalTest(kTRUE); | |
667 | Int_t productionMode = fProductionMode; | |
668 | SetProductionMode(); | |
669 | TString macro = fAnalysisMacro; | |
670 | TString executable = fExecutable; | |
671 | TString validation = fValidationScript; | |
672 | TString execCommand = fExecutableCommand; | |
673 | SetAnalysisMacro(Form("%s.C", name)); | |
674 | SetExecutable(Form("%s.sh", name)); | |
d66aa2a9 | 675 | fOutputFiles = GetListOfFiles("outaod"); |
676 | // Add extra files registered to the analysis manager | |
677 | TString extra = GetListOfFiles("ext"); | |
678 | if (!extra.IsNull()) { | |
679 | extra.ReplaceAll(".root", "*.root"); | |
680 | if (!fOutputFiles.IsNull()) fOutputFiles += ","; | |
681 | fOutputFiles += extra; | |
682 | } | |
a8e31fb0 | 683 | // SetExecutableCommand("aliroot -b -q "); |
21ca8e59 | 684 | SetValidationScript(Form("%s_validation.sh", name)); |
685 | WriteAnalysisFile(); | |
686 | WriteAnalysisMacro(); | |
687 | WriteExecutable(); | |
688 | WriteValidationScript(); | |
ffbe06b9 | 689 | WriteMergingMacro(); |
690 | WriteMergeExecutable(); | |
691 | WriteValidationScript(kTRUE); | |
21ca8e59 | 692 | SetLocalTest(kFALSE); |
693 | SetProductionMode(productionMode); | |
694 | fAnalysisMacro = macro; | |
695 | fExecutable = executable; | |
696 | fExecutableCommand = execCommand; | |
697 | fValidationScript = validation; | |
77f34eae | 698 | return kTRUE; |
699 | } | |
700 | ||
701 | //______________________________________________________________________________ | |
702 | Bool_t AliAnalysisAlien::LoadModules() | |
703 | { | |
704 | // Load all modules by executing the AddTask macros. Checks first the dependencies. | |
5e8c7c22 | 705 | fAdditionalLibs = ""; |
21ca8e59 | 706 | Int_t nmodules = GetNmodules(); |
707 | if (!nmodules) { | |
708 | Warning("LoadModules", "No module to be loaded"); | |
709 | return kTRUE; | |
710 | } | |
3e40fd4c | 711 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); |
712 | if (!mgr) { | |
713 | Error("LoadModules", "No analysis manager created yet. Use CreateAnalysisManager first."); | |
714 | return kFALSE; | |
715 | } | |
77f34eae | 716 | if (!CheckDependencies()) return kFALSE; |
21ca8e59 | 717 | nmodules = GetNmodules(); |
77f34eae | 718 | AliAnalysisTaskCfg *mod; |
21ca8e59 | 719 | for (Int_t imod=0; imod<nmodules; imod++) { |
720 | mod = (AliAnalysisTaskCfg*)fModules->At(imod); | |
77f34eae | 721 | if (!LoadModule(mod)) return kFALSE; |
722 | } | |
77f34eae | 723 | return kTRUE; |
724 | } | |
725 | ||
74013535 | 726 | //______________________________________________________________________________ |
727 | void AliAnalysisAlien::SetRunPrefix(const char *prefix) | |
728 | { | |
729 | // Set the run number format. Can be a prefix or a format like "%09d" | |
730 | fRunPrefix = prefix; | |
731 | if (!fRunPrefix.Contains("%")) fRunPrefix += "%d"; | |
732 | } | |
733 | ||
f965131e | 734 | //______________________________________________________________________________ |
735 | void AliAnalysisAlien::AddIncludePath(const char *path) | |
736 | { | |
737 | // Add include path in the remote analysis macro. | |
738 | TString p(path); | |
739 | if (p.Contains("-I")) fIncludePath += Form("%s ", path); | |
740 | else fIncludePath += Form("-I%s ", path); | |
741 | } | |
742 | ||
c57f56b7 | 743 | //______________________________________________________________________________ |
744 | void AliAnalysisAlien::AddRunNumber(Int_t run) | |
745 | { | |
746 | // Add a run number to the list of runs to be processed. | |
747 | if (fRunNumbers.Length()) fRunNumbers += " "; | |
74013535 | 748 | fRunNumbers += Form(fRunPrefix.Data(), run); |
c57f56b7 | 749 | } |
750 | ||
98690895 | 751 | //______________________________________________________________________________ |
752 | void AliAnalysisAlien::AddRunList(const char* runList) | |
753 | { | |
754 | // Add several runs into the list of runs; they are expected to be separated by a blank character. | |
755 | TString sList = runList; | |
756 | TObjArray *list = sList.Tokenize(" "); | |
757 | Int_t n = list->GetEntries(); | |
758 | for (Int_t i = 0; i < n; i++) { | |
759 | TObjString *os = (TObjString*)list->At(i); | |
760 | AddRunNumber(os->GetString().Atoi()); | |
761 | } | |
762 | delete list; | |
763 | } | |
764 | ||
ee75cfc3 | 765 | //______________________________________________________________________________ |
766 | void AliAnalysisAlien::AddRunNumber(const char* run) | |
767 | { | |
768 | // Add a run number to the list of runs to be processed. | |
7aa5d539 | 769 | TString runs = run; |
770 | TObjString *os; | |
771 | TObjArray *arr = runs.Tokenize(" "); | |
772 | TIter next(arr); | |
773 | TString prefix; | |
774 | prefix.Append(fRunPrefix, fRunPrefix.Index("%d")); | |
775 | while ((os=(TObjString*)next())){ | |
776 | if (fRunNumbers.Length()) fRunNumbers += " "; | |
777 | fRunNumbers += Form("%s%s", prefix.Data(), os->GetString().Data()); | |
778 | } | |
779 | delete arr; | |
ee75cfc3 | 780 | } |
781 | ||
c57f56b7 | 782 | //______________________________________________________________________________ |
783 | void AliAnalysisAlien::AddDataFile(const char *lfn) | |
784 | { | |
785 | // Adds a data file to the input to be analysed. The file should be a valid LFN | |
786 | // or point to an existing file in the alien workdir. | |
787 | if (!fInputFiles) fInputFiles = new TObjArray(); | |
788 | fInputFiles->Add(new TObjString(lfn)); | |
789 | } | |
648174cf | 790 | |
791 | //______________________________________________________________________________ | |
792 | void AliAnalysisAlien::AddExternalPackage(const char *package) | |
793 | { | |
794 | // Adds external packages w.r.t to the default ones (root,aliroot and gapi) | |
795 | if (fExternalPackages) fExternalPackages += " "; | |
796 | fExternalPackages += package; | |
797 | } | |
798 | ||
c57f56b7 | 799 | //______________________________________________________________________________ |
800 | Bool_t AliAnalysisAlien::Connect() | |
801 | { | |
802 | // Try to connect to AliEn. User needs a valid token and /tmp/gclient_env_$UID sourced. | |
803 | if (gGrid && gGrid->IsConnected()) return kTRUE; | |
d3b18c4c | 804 | if (fProductionMode) return kTRUE; |
c57f56b7 | 805 | if (!gGrid) { |
806 | Info("Connect", "Trying to connect to AliEn ..."); | |
807 | TGrid::Connect("alien://"); | |
808 | } | |
809 | if (!gGrid || !gGrid->IsConnected()) { | |
810 | Error("Connect", "Did not managed to connect to AliEn. Make sure you have a valid token."); | |
811 | return kFALSE; | |
812 | } | |
813 | fUser = gGrid->GetUser(); | |
814 | Info("Connect", "\n##### Connected to AliEn as user %s. Setting analysis user to <%s>", fUser.Data(), fUser.Data()); | |
815 | return kTRUE; | |
816 | } | |
817 | ||
818 | //______________________________________________________________________________ | |
819 | void AliAnalysisAlien::CdWork() | |
820 | { | |
821 | // Check validity of alien workspace. Create directory if possible. | |
822 | if (!Connect()) { | |
823 | Error("CdWork", "Alien connection required"); | |
824 | return; | |
825 | } | |
826 | TString homedir = gGrid->GetHomeDirectory(); | |
827 | TString workdir = homedir + fGridWorkingDir; | |
923e2ca5 | 828 | if (DirectoryExists(workdir)) { |
829 | gGrid->Cd(workdir); | |
830 | return; | |
831 | } | |
832 | // Work directory not existing - create it | |
833 | gGrid->Cd(homedir); | |
b93f8109 | 834 | if (gGrid->Mkdir(workdir, "-p")) { |
923e2ca5 | 835 | gGrid->Cd(fGridWorkingDir); |
d3b18c4c | 836 | Info("CdWork", "\n##### Created alien working directory %s", fGridWorkingDir.Data()); |
923e2ca5 | 837 | } else { |
d3b18c4c | 838 | Warning("CdWork", "Working directory %s cannot be created.\n Using %s instead.", |
923e2ca5 | 839 | workdir.Data(), homedir.Data()); |
840 | fGridWorkingDir = ""; | |
841 | } | |
c57f56b7 | 842 | } |
843 | ||
348be253 | 844 | //______________________________________________________________________________ |
845 | Bool_t AliAnalysisAlien::CheckFileCopy(const char *alienpath) | |
846 | { | |
847 | // Check if file copying is possible. | |
d3b18c4c | 848 | if (fProductionMode) return kTRUE; |
b5ae4fe0 | 849 | TString salienpath(alienpath); |
850 | if (salienpath.Contains(" ")) { | |
851 | Error("CheckFileCopy", "path: <%s> contains blancs - FIX IT !",alienpath); | |
852 | return kFALSE; | |
853 | } | |
348be253 | 854 | if (!Connect()) { |
855 | Error("CheckFileCopy", "Not connected to AliEn. File copying cannot be tested."); | |
856 | return kFALSE; | |
857 | } | |
d3339be3 | 858 | Info("CheckFileCopy", "Checking possibility to copy files to your AliEn home directory... \ |
859 | \n +++ NOTE: You can disable this via: plugin->SetCheckCopy(kFALSE);"); | |
348be253 | 860 | // Check if alien_CLOSE_SE is defined |
861 | TString closeSE = gSystem->Getenv("alien_CLOSE_SE"); | |
862 | if (!closeSE.IsNull()) { | |
863 | Info("CheckFileCopy", "Your current close storage is pointing to: \ | |
864 | \n alien_CLOSE_SE = \"%s\"", closeSE.Data()); | |
865 | } else { | |
866 | Warning("CheckFileCopy", "Your current close storage is empty ! Depending on your location, file copying may fail."); | |
867 | } | |
868 | // Check if grid directory exists. | |
869 | if (!DirectoryExists(alienpath)) { | |
870 | Error("CheckFileCopy", "Alien path %s does not seem to exist", alienpath); | |
871 | return kFALSE; | |
872 | } | |
b5ae4fe0 | 873 | TString stest = "plugin_test_copy"; |
874 | TFile f(stest, "RECREATE"); | |
348be253 | 875 | // User may not have write permissions to current directory |
876 | if (f.IsZombie()) { | |
877 | Error("CheckFileCopy", "Cannot create local test file. Do you have write access to current directory: <%s> ?", | |
878 | gSystem->WorkingDirectory()); | |
879 | return kFALSE; | |
880 | } | |
881 | f.Close(); | |
b5ae4fe0 | 882 | if (FileExists(Form("alien://%s/%s",alienpath, stest.Data()))) gGrid->Rm(Form("alien://%s/%s",alienpath, stest.Data())); |
883 | if (!TFile::Cp(stest.Data(), Form("alien://%s/%s",alienpath, stest.Data()))) { | |
d3339be3 | 884 | Error("CheckFileCopy", "Cannot copy files to Alien destination: <%s> This may be temporary, or: \ |
348be253 | 885 | \n# 1. Make sure you have write permissions there. If this is the case: \ |
886 | \n# 2. Check the storage availability at: http://alimonitor.cern.ch/stats?page=SE/table \ | |
887 | \n# Do: export alien_CLOSE_SE=\"working_disk_SE\" \ | |
888 | \n# To make this permanent put in in your .bashrc (in .alienshrc is not enough) \ | |
889 | \n# Redo token: rm /tmp/x509up_u$UID then: alien-token-init <username>", alienpath); | |
b5ae4fe0 | 890 | gSystem->Unlink(stest.Data()); |
348be253 | 891 | return kFALSE; |
892 | } | |
b5ae4fe0 | 893 | gSystem->Unlink(stest.Data()); |
894 | gGrid->Rm(Form("%s/%s",alienpath,stest.Data())); | |
d3339be3 | 895 | Info("CheckFileCopy", "### ...SUCCESS ###"); |
348be253 | 896 | return kTRUE; |
897 | } | |
898 | ||
c57f56b7 | 899 | //______________________________________________________________________________ |
900 | Bool_t AliAnalysisAlien::CheckInputData() | |
901 | { | |
902 | // Check validity of input data. If necessary, create xml files. | |
d3b18c4c | 903 | if (fProductionMode) return kTRUE; |
a8739e8a | 904 | if (!fInputFiles && !fRunNumbers.Length() && !fRunRange[0]) { |
d2a409b2 | 905 | if (!fGridDataDir.Length()) { |
906 | Error("CkeckInputData", "AliEn path to base data directory must be set.\n = Use: SetGridDataDir()"); | |
907 | return kFALSE; | |
908 | } | |
9f020952 | 909 | if (fMergeViaJDL) { |
910 | Error("CheckInputData", "Merging via jdl works only with run numbers, run range or provided xml"); | |
911 | return kFALSE; | |
912 | } | |
d2a409b2 | 913 | Info("CheckInputData", "Analysis will make a single xml for base data directory %s",fGridDataDir.Data()); |
23329835 | 914 | if (fDataPattern.Contains("tag") && TestBit(AliAnalysisGrid::kTest)) |
915 | TObject::SetBit(AliAnalysisGrid::kUseTags, kTRUE); // ADDED (fix problem in determining the tag usage in test mode) | |
d2a409b2 | 916 | return kTRUE; |
c57f56b7 | 917 | } |
918 | // Process declared files | |
a2f5fc01 | 919 | Bool_t isCollection = kFALSE; |
920 | Bool_t isXml = kFALSE; | |
921 | Bool_t useTags = kFALSE; | |
c57f56b7 | 922 | Bool_t checked = kFALSE; |
d3b18c4c | 923 | if (!TestBit(AliAnalysisGrid::kTest)) CdWork(); |
c57f56b7 | 924 | TString file; |
925 | TString workdir = gGrid->GetHomeDirectory(); | |
926 | workdir += fGridWorkingDir; | |
927 | if (fInputFiles) { | |
928 | TObjString *objstr; | |
929 | TIter next(fInputFiles); | |
930 | while ((objstr=(TObjString*)next())) { | |
931 | file = workdir; | |
932 | file += "/"; | |
933 | file += objstr->GetString(); | |
934 | // Store full lfn path | |
935 | if (FileExists(file)) objstr->SetString(file); | |
936 | else { | |
937 | file = objstr->GetName(); | |
938 | if (!FileExists(objstr->GetName())) { | |
939 | Error("CheckInputData", "Data file %s not found or not in your working dir: %s", | |
940 | objstr->GetName(), workdir.Data()); | |
941 | return kFALSE; | |
942 | } | |
943 | } | |
944 | Bool_t iscoll, isxml, usetags; | |
945 | CheckDataType(file, iscoll, isxml, usetags); | |
946 | if (!checked) { | |
947 | checked = kTRUE; | |
a2f5fc01 | 948 | isCollection = iscoll; |
949 | isXml = isxml; | |
950 | useTags = usetags; | |
951 | TObject::SetBit(AliAnalysisGrid::kUseTags, useTags); | |
c57f56b7 | 952 | } else { |
a2f5fc01 | 953 | if ((iscoll != isCollection) || (isxml != isXml) || (usetags != useTags)) { |
c57f56b7 | 954 | Error("CheckInputData", "Some conflict was found in the types of inputs"); |
955 | return kFALSE; | |
956 | } | |
957 | } | |
958 | } | |
959 | } | |
960 | // Process requested run numbers | |
a8739e8a | 961 | if (!fRunNumbers.Length() && !fRunRange[0]) return kTRUE; |
c57f56b7 | 962 | // Check validity of alien data directory |
963 | if (!fGridDataDir.Length()) { | |
964 | Error("CkeckInputData", "AliEn path to base data directory must be set.\n = Use: SetGridDataDir()"); | |
965 | return kFALSE; | |
966 | } | |
923e2ca5 | 967 | if (!DirectoryExists(fGridDataDir)) { |
c57f56b7 | 968 | Error("CheckInputData", "Data directory %s not existing.", fGridDataDir.Data()); |
969 | return kFALSE; | |
970 | } | |
a2f5fc01 | 971 | if (isCollection) { |
c57f56b7 | 972 | Error("CheckInputData", "You are using raw AliEn collections as input. Cannot process run numbers."); |
973 | return kFALSE; | |
974 | } | |
975 | ||
a2f5fc01 | 976 | if (checked && !isXml) { |
c57f56b7 | 977 | Error("CheckInputData", "Cannot mix processing of full runs with non-xml files"); |
978 | return kFALSE; | |
979 | } | |
980 | // Check validity of run number(s) | |
981 | TObjArray *arr; | |
982 | TObjString *os; | |
74013535 | 983 | TString format; |
319593fb | 984 | Int_t nruns = 0; |
904f9f5f | 985 | TString schunk, schunk2; |
c57f56b7 | 986 | TString path; |
987 | if (!checked) { | |
988 | checked = kTRUE; | |
a2f5fc01 | 989 | useTags = fDataPattern.Contains("tag"); |
990 | TObject::SetBit(AliAnalysisGrid::kUseTags, useTags); | |
c57f56b7 | 991 | } |
a2f5fc01 | 992 | if (useTags != fDataPattern.Contains("tag")) { |
c57f56b7 | 993 | Error("CheckInputData", "Cannot mix input files using/not using tags"); |
994 | return kFALSE; | |
995 | } | |
996 | if (fRunNumbers.Length()) { | |
a8739e8a | 997 | Info("CheckDataType", "Using supplied run numbers (run ranges are ignored)"); |
c57f56b7 | 998 | arr = fRunNumbers.Tokenize(" "); |
999 | TIter next(arr); | |
1000 | while ((os=(TObjString*)next())) { | |
1001 | path = Form("%s/%s ", fGridDataDir.Data(), os->GetString().Data()); | |
923e2ca5 | 1002 | if (!DirectoryExists(path)) { |
1003 | Warning("CheckInputData", "Run number %s not found in path: <%s>", os->GetString().Data(), path.Data()); | |
a8739e8a | 1004 | continue; |
c57f56b7 | 1005 | } |
1006 | path = Form("%s/%s.xml", workdir.Data(),os->GetString().Data()); | |
1007 | TString msg = "\n##### file: "; | |
1008 | msg += path; | |
1009 | msg += " type: xml_collection;"; | |
a2f5fc01 | 1010 | if (useTags) msg += " using_tags: Yes"; |
c57f56b7 | 1011 | else msg += " using_tags: No"; |
23329835 | 1012 | Info("CheckDataType", "%s", msg.Data()); |
319593fb | 1013 | if (fNrunsPerMaster<2) { |
d2a409b2 | 1014 | AddDataFile(Form("%s.xml", os->GetString().Data())); |
319593fb | 1015 | } else { |
1016 | nruns++; | |
1017 | if (((nruns-1)%fNrunsPerMaster) == 0) { | |
1018 | schunk = os->GetString(); | |
1019 | } | |
1020 | if ((nruns%fNrunsPerMaster)!=0 && os!=arr->Last()) continue; | |
1021 | schunk += Form("_%s.xml", os->GetString().Data()); | |
d2a409b2 | 1022 | AddDataFile(schunk); |
319593fb | 1023 | } |
c57f56b7 | 1024 | } |
1025 | delete arr; | |
a8739e8a | 1026 | } else { |
1027 | Info("CheckDataType", "Using run range [%d, %d]", fRunRange[0], fRunRange[1]); | |
1028 | for (Int_t irun=fRunRange[0]; irun<=fRunRange[1]; irun++) { | |
74013535 | 1029 | format = Form("%%s/%s ", fRunPrefix.Data()); |
1030 | path = Form(format.Data(), fGridDataDir.Data(), irun); | |
923e2ca5 | 1031 | if (!DirectoryExists(path)) { |
a8739e8a | 1032 | continue; |
1033 | } | |
74013535 | 1034 | format = Form("%%s/%s.xml", fRunPrefix.Data()); |
1035 | path = Form(format.Data(), workdir.Data(),irun); | |
a8739e8a | 1036 | TString msg = "\n##### file: "; |
1037 | msg += path; | |
1038 | msg += " type: xml_collection;"; | |
a2f5fc01 | 1039 | if (useTags) msg += " using_tags: Yes"; |
a8739e8a | 1040 | else msg += " using_tags: No"; |
23329835 | 1041 | Info("CheckDataType", "%s", msg.Data()); |
319593fb | 1042 | if (fNrunsPerMaster<2) { |
74013535 | 1043 | format = Form("%s.xml", fRunPrefix.Data()); |
1044 | AddDataFile(Form(format.Data(),irun)); | |
319593fb | 1045 | } else { |
1046 | nruns++; | |
1047 | if (((nruns-1)%fNrunsPerMaster) == 0) { | |
74013535 | 1048 | schunk = Form(fRunPrefix.Data(),irun); |
319593fb | 1049 | } |
74013535 | 1050 | format = Form("_%s.xml", fRunPrefix.Data()); |
1051 | schunk2 = Form(format.Data(), irun); | |
319593fb | 1052 | if ((nruns%fNrunsPerMaster)!=0 && irun != fRunRange[1]) continue; |
904f9f5f | 1053 | schunk += schunk2; |
d2a409b2 | 1054 | AddDataFile(schunk); |
319593fb | 1055 | } |
a8739e8a | 1056 | } |
904f9f5f | 1057 | if (!fInputFiles) { |
1058 | schunk += schunk2; | |
1059 | AddDataFile(schunk); | |
1060 | } | |
c57f56b7 | 1061 | } |
1062 | return kTRUE; | |
1063 | } | |
1064 | ||
21ca8e59 | 1065 | //______________________________________________________________________________ |
4a8b667c | 1066 | Int_t AliAnalysisAlien::CopyLocalDataset(const char *griddir, const char *pattern, Int_t nfiles, const char *output, const char *archivefile, const char *outputdir) |
21ca8e59 | 1067 | { |
1068 | // Copy data from the given grid directory according a pattern and make a local | |
1069 | // dataset. | |
2ba4c287 | 1070 | // archivefile (optional) results in that the archive containing the file <pattern> is copied. archivefile can contain a list of files (semicolon-separated) which are all copied |
21ca8e59 | 1071 | if (!Connect()) { |
1072 | Error("CopyLocalDataset", "Cannot copy local dataset with no grid connection"); | |
4a8b667c | 1073 | return 0; |
21ca8e59 | 1074 | } |
1075 | if (!DirectoryExists(griddir)) { | |
1076 | Error("CopyLocalDataset", "Data directory %s not existing.", griddir); | |
4a8b667c | 1077 | return 0; |
21ca8e59 | 1078 | } |
1079 | TString command = Form("find -z -l %d %s %s", nfiles, griddir, pattern); | |
1080 | printf("Running command: %s\n", command.Data()); | |
1081 | TGridResult *res = gGrid->Command(command); | |
1082 | Int_t nfound = res->GetEntries(); | |
1083 | if (!nfound) { | |
1084 | Error("CopyLocalDataset", "No file found in <%s> having pattern <%s>", griddir, pattern); | |
4a8b667c | 1085 | return 0; |
21ca8e59 | 1086 | } |
1087 | printf("... found %d files. Copying locally ...\n", nfound); | |
2ba4c287 | 1088 | |
1089 | // archives | |
1090 | TObjArray* additionalArchives = 0; | |
1091 | if (strlen(archivefile) > 0 && TString(archivefile).Contains(";")) { | |
1092 | additionalArchives = TString(archivefile).Tokenize(";"); | |
1093 | archivefile = additionalArchives->At(0)->GetName(); | |
1094 | additionalArchives->RemoveAt(0); | |
1095 | additionalArchives->Compress(); | |
1096 | } | |
1097 | ||
21ca8e59 | 1098 | // Copy files locally |
1099 | ofstream out; | |
1100 | out.open(output, ios::out); | |
1101 | TMap *map; | |
1102 | TString turl, dirname, filename, temp; | |
1103 | TString cdir = gSystem->WorkingDirectory(); | |
139fe6ba | 1104 | gSystem->MakeDirectory(outputdir); |
1105 | gSystem->ChangeDirectory(outputdir); | |
4a8b667c | 1106 | Int_t ncopied = 0; |
21ca8e59 | 1107 | for (Int_t i=0; i<nfound; i++) { |
1108 | map = (TMap*)res->At(i); | |
1109 | turl = map->GetValue("turl")->GetName(); | |
1110 | filename = gSystem->BaseName(turl.Data()); | |
1111 | dirname = gSystem->DirName(turl.Data()); | |
1112 | dirname = gSystem->BaseName(dirname.Data()); | |
1113 | gSystem->MakeDirectory(dirname); | |
43b807f6 | 1114 | |
1115 | TString source(turl); | |
1116 | TString targetFileName(filename); | |
1117 | ||
1118 | if (strlen(archivefile) > 0) { | |
4a8b667c | 1119 | // TODO here the archive in which the file resides should be determined |
1120 | // however whereis returns only a guid, and guid2lfn does not work | |
1121 | // Therefore we use the one provided as argument for now | |
1122 | source = Form("%s/%s", gSystem->DirName(source.Data()), archivefile); | |
1123 | targetFileName = archivefile; | |
43b807f6 | 1124 | } |
1125 | if (TFile::Cp(source, Form("file:./%s/%s", dirname.Data(), targetFileName.Data()))) { | |
4a8b667c | 1126 | Bool_t success = kTRUE; |
1127 | if (additionalArchives) { | |
1128 | for (Int_t j=0; j<additionalArchives->GetEntriesFast(); j++) { | |
1129 | TString target; | |
1130 | target.Form("./%s/%s", dirname.Data(), additionalArchives->At(j)->GetName()); | |
1131 | gSystem->MakeDirectory(gSystem->DirName(target)); | |
1132 | success &= TFile::Cp(Form("%s/%s", gSystem->DirName(source.Data()), additionalArchives->At(j)->GetName()), Form("file:%s", target.Data())); | |
1133 | } | |
1134 | } | |
2ba4c287 | 1135 | |
4a8b667c | 1136 | if (success) { |
1137 | if (strlen(archivefile) > 0) targetFileName = Form("%s#%s", targetFileName.Data(), gSystem->BaseName(turl.Data())); | |
1138 | out << cdir << Form("/%s/%s/%s", outputdir, dirname.Data(), targetFileName.Data()) << endl; | |
1139 | ncopied++; | |
1140 | } | |
21ca8e59 | 1141 | } |
1142 | } | |
1143 | gSystem->ChangeDirectory(cdir); | |
1144 | delete res; | |
4a8b667c | 1145 | delete additionalArchives; |
1146 | return ncopied; | |
21ca8e59 | 1147 | } |
1148 | ||
c57f56b7 | 1149 | //______________________________________________________________________________ |
1150 | Bool_t AliAnalysisAlien::CreateDataset(const char *pattern) | |
1151 | { | |
1152 | // Create dataset for the grid data directory + run number. | |
3af861ff | 1153 | const Int_t gMaxEntries = 15000; |
d3b18c4c | 1154 | if (fProductionMode || TestBit(AliAnalysisGrid::kOffline)) return kTRUE; |
c57f56b7 | 1155 | if (!Connect()) { |
1156 | Error("CreateDataset", "Cannot create dataset with no grid connection"); | |
1157 | return kFALSE; | |
1158 | } | |
1159 | ||
1160 | // Cd workspace | |
d3b18c4c | 1161 | if (!TestBit(AliAnalysisGrid::kTest)) CdWork(); |
c57f56b7 | 1162 | TString workdir = gGrid->GetHomeDirectory(); |
1163 | workdir += fGridWorkingDir; | |
1164 | ||
1165 | // Compose the 'find' command arguments | |
74013535 | 1166 | TString format; |
c57f56b7 | 1167 | TString command; |
1168 | TString options = "-x collection "; | |
bb885a9e | 1169 | if (TestBit(AliAnalysisGrid::kTest)) options += Form("-l %d ", fNtestFiles); |
3af861ff | 1170 | else options += Form("-l %d ", gMaxEntries); // Protection for the find command |
c57f56b7 | 1171 | TString conditions = ""; |
3af861ff | 1172 | Int_t nstart = 0; |
1173 | Int_t ncount = 0; | |
1174 | Int_t stage = 0; | |
c57f56b7 | 1175 | TString file; |
1176 | TString path; | |
319593fb | 1177 | Int_t nruns = 0; |
904f9f5f | 1178 | TString schunk, schunk2; |
ab254fd1 | 1179 | TGridCollection *cbase=0, *cadd=0; |
d2a409b2 | 1180 | if (!fRunNumbers.Length() && !fRunRange[0]) { |
1181 | if (fInputFiles && fInputFiles->GetEntries()) return kTRUE; | |
1182 | // Make a single data collection from data directory. | |
1183 | path = fGridDataDir; | |
923e2ca5 | 1184 | if (!DirectoryExists(path)) { |
d2a409b2 | 1185 | Error("CreateDataset", "Path to data directory %s not valid",fGridDataDir.Data()); |
1186 | return kFALSE; | |
1187 | } | |
923e2ca5 | 1188 | // CdWork(); |
d2a409b2 | 1189 | if (TestBit(AliAnalysisGrid::kTest)) file = "wn.xml"; |
1190 | else file = Form("%s.xml", gSystem->BaseName(path)); | |
3af861ff | 1191 | while (1) { |
1192 | ncount = 0; | |
1193 | stage++; | |
1194 | if (gSystem->AccessPathName(file) || TestBit(AliAnalysisGrid::kTest) || fOverwriteMode) { | |
1195 | command = "find "; | |
1196 | command += Form("%s -o %d ",options.Data(), nstart); | |
1197 | command += path; | |
1198 | command += " "; | |
1199 | command += pattern; | |
1200 | command += conditions; | |
1201 | printf("command: %s\n", command.Data()); | |
1202 | TGridResult *res = gGrid->Command(command); | |
1203 | if (res) delete res; | |
1204 | // Write standard output to file | |
1205 | gROOT->ProcessLine(Form("gGrid->Stdout(); > __tmp%d__%s", stage, file.Data())); | |
1206 | Bool_t hasGrep = (gSystem->Exec("grep --version 2>/dev/null > /dev/null")==0)?kTRUE:kFALSE; | |
1207 | Bool_t nullFile = kFALSE; | |
1208 | if (!hasGrep) { | |
1209 | Warning("CreateDataset", "'grep' command not available on this system - cannot validate the result of the grid 'find' command"); | |
1210 | } else { | |
1211 | nullFile = (gSystem->Exec(Form("grep -c /event __tmp%d__%s 2>/dev/null > __tmp__",stage,file.Data()))==0)?kFALSE:kTRUE; | |
1212 | if (nullFile) { | |
1213 | Error("CreateDataset","Dataset %s produced by the previous find command is empty !", file.Data()); | |
1214 | gSystem->Exec("rm -f __tmp*"); | |
1215 | return kFALSE; | |
1216 | } | |
1217 | TString line; | |
1218 | ifstream in; | |
1219 | in.open("__tmp__"); | |
1220 | in >> line; | |
1221 | in.close(); | |
1222 | gSystem->Exec("rm -f __tmp__"); | |
1223 | ncount = line.Atoi(); | |
1224 | } | |
1225 | } | |
1226 | if (ncount == gMaxEntries) { | |
1227 | Info("CreateDataset", "Dataset %s has more than 15K entries. Trying to merge...", file.Data()); | |
1228 | cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"__tmp%d__%s\", 1000000);",stage,file.Data())); | |
1229 | if (!cbase) cbase = cadd; | |
1230 | else { | |
1231 | cbase->Add(cadd); | |
1232 | delete cadd; | |
defd7a3a | 1233 | } |
3af861ff | 1234 | nstart += ncount; |
1235 | } else { | |
1236 | if (cbase) { | |
1237 | cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"__tmp%d__%s\", 1000000);",stage,file.Data())); | |
1238 | printf("... please wait - TAlienCollection::Add() scales badly...\n"); | |
1239 | cbase->Add(cadd); | |
1240 | delete cadd; | |
1241 | cbase->ExportXML(Form("file://%s", file.Data()),kFALSE,kFALSE, file, "Merged entries for a run"); | |
1242 | delete cbase; cbase = 0; | |
1243 | } else { | |
1244 | TFile::Cp(Form("__tmp%d__%s",stage, file.Data()), file.Data()); | |
1245 | } | |
1246 | gSystem->Exec("rm -f __tmp*"); | |
1247 | Info("CreateDataset", "Created dataset %s with %d files", file.Data(), nstart+ncount); | |
1248 | break; | |
1249 | } | |
0f389141 | 1250 | } |
1251 | Bool_t fileExists = FileExists(file); | |
1252 | if (!TestBit(AliAnalysisGrid::kTest) && (!fileExists || fOverwriteMode)) { | |
d2a409b2 | 1253 | // Copy xml file to alien space |
0f389141 | 1254 | if (fileExists) gGrid->Rm(file); |
d2a409b2 | 1255 | TFile::Cp(Form("file:%s",file.Data()), Form("alien://%s/%s",workdir.Data(), file.Data())); |
1256 | if (!FileExists(file)) { | |
1257 | Error("CreateDataset", "Command %s did NOT succeed", command.Data()); | |
1258 | return kFALSE; | |
1259 | } | |
1260 | // Update list of files to be processed. | |
1261 | } | |
1262 | AddDataFile(Form("%s/%s", workdir.Data(), file.Data())); | |
1263 | return kTRUE; | |
1264 | } | |
c57f56b7 | 1265 | // Several runs |
a2f5fc01 | 1266 | Bool_t nullResult = kTRUE; |
a8739e8a | 1267 | if (fRunNumbers.Length()) { |
1268 | TObjArray *arr = fRunNumbers.Tokenize(" "); | |
1269 | TObjString *os; | |
1270 | TIter next(arr); | |
1271 | while ((os=(TObjString*)next())) { | |
3af861ff | 1272 | nstart = 0; |
1273 | stage = 0; | |
dc030a24 | 1274 | path = Form("%s/%s/ ", fGridDataDir.Data(), os->GetString().Data()); |
923e2ca5 | 1275 | if (!DirectoryExists(path)) continue; |
1276 | // CdWork(); | |
a8739e8a | 1277 | if (TestBit(AliAnalysisGrid::kTest)) file = "wn.xml"; |
1278 | else file = Form("%s.xml", os->GetString().Data()); | |
319593fb | 1279 | // If local collection file does not exist, create it via 'find' command. |
3af861ff | 1280 | while (1) { |
1281 | ncount = 0; | |
1282 | stage++; | |
1283 | if (gSystem->AccessPathName(file) || TestBit(AliAnalysisGrid::kTest) || fOverwriteMode) { | |
1284 | command = "find "; | |
1285 | command += Form("%s -o %d ",options.Data(), nstart); | |
1286 | command += path; | |
1287 | command += pattern; | |
1288 | command += conditions; | |
1289 | TGridResult *res = gGrid->Command(command); | |
1290 | if (res) delete res; | |
1291 | // Write standard output to file | |
1292 | gROOT->ProcessLine(Form("gGrid->Stdout(); > __tmp%d__%s", stage,file.Data())); | |
1293 | Bool_t hasGrep = (gSystem->Exec("grep --version 2>/dev/null > /dev/null")==0)?kTRUE:kFALSE; | |
1294 | Bool_t nullFile = kFALSE; | |
1295 | if (!hasGrep) { | |
1296 | Warning("CreateDataset", "'grep' command not available on this system - cannot validate the result of the grid 'find' command"); | |
1297 | } else { | |
1298 | nullFile = (gSystem->Exec(Form("grep -c /event __tmp%d__%s 2>/dev/null > __tmp__",stage,file.Data()))==0)?kFALSE:kTRUE; | |
1299 | if (nullFile) { | |
1300 | Warning("CreateDataset","Dataset %s produced by: <%s> is empty !", file.Data(), command.Data()); | |
1301 | gSystem->Exec("rm -f __tmp*"); | |
1302 | fRunNumbers.ReplaceAll(os->GetString().Data(), ""); | |
1604c9ed | 1303 | break; |
3af861ff | 1304 | } |
1305 | TString line; | |
1306 | ifstream in; | |
1307 | in.open("__tmp__"); | |
1308 | in >> line; | |
1309 | in.close(); | |
1310 | gSystem->Exec("rm -f __tmp__"); | |
1311 | ncount = line.Atoi(); | |
1312 | } | |
1313 | nullResult = kFALSE; | |
1314 | } | |
1315 | if (ncount == gMaxEntries) { | |
1316 | Info("CreateDataset", "Dataset %s has more than 15K entries. Trying to merge...", file.Data()); | |
1317 | if (fNrunsPerMaster > 1) { | |
1318 | Error("CreateDataset", "File %s has more than %d entries. Please set the number of runs per master to 1 !", | |
1319 | file.Data(),gMaxEntries); | |
1320 | return kFALSE; | |
1321 | } | |
1322 | cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"__tmp%d__%s\", 1000000);",stage,file.Data())); | |
1323 | if (!cbase) cbase = cadd; | |
1324 | else { | |
1325 | cbase->Add(cadd); | |
1326 | delete cadd; | |
defd7a3a | 1327 | } |
3af861ff | 1328 | nstart += ncount; |
1329 | } else { | |
c89a84bc | 1330 | if (cbase && fNrunsPerMaster<2) { |
3af861ff | 1331 | cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"__tmp%d__%s\", 1000000);",stage,file.Data())); |
1332 | printf("... please wait - TAlienCollection::Add() scales badly...\n"); | |
1333 | cbase->Add(cadd); | |
1334 | delete cadd; | |
1335 | cbase->ExportXML(Form("file://%s", file.Data()),kFALSE,kFALSE, file, "Merged entries for a run"); | |
1336 | delete cbase; cbase = 0; | |
1337 | } else { | |
1338 | TFile::Cp(Form("__tmp%d__%s",stage, file.Data()), file.Data()); | |
1339 | } | |
1340 | gSystem->Exec("rm -f __tmp*"); | |
1341 | Info("CreateDataset", "Created dataset %s with %d files", file.Data(), nstart+ncount); | |
1342 | break; | |
d3339be3 | 1343 | } |
3af861ff | 1344 | } |
a8739e8a | 1345 | if (TestBit(AliAnalysisGrid::kTest)) break; |
319593fb | 1346 | // Check if there is one run per master job. |
1347 | if (fNrunsPerMaster<2) { | |
1348 | if (FileExists(file)) { | |
0f389141 | 1349 | if (fOverwriteMode) gGrid->Rm(file); |
1350 | else { | |
1351 | Info("CreateDataset", "\n##### Dataset %s exist. Skipping creation...", file.Data()); | |
1352 | continue; | |
1353 | } | |
319593fb | 1354 | } |
1355 | // Copy xml file to alien space | |
1356 | TFile::Cp(Form("file:%s",file.Data()), Form("alien://%s/%s",workdir.Data(), file.Data())); | |
1357 | if (!FileExists(file)) { | |
1358 | Error("CreateDataset", "Command %s did NOT succeed", command.Data()); | |
1359 | delete arr; | |
1360 | return kFALSE; | |
1361 | } | |
1362 | } else { | |
1363 | nruns++; | |
1364 | if (((nruns-1)%fNrunsPerMaster) == 0) { | |
1365 | schunk = os->GetString(); | |
1366 | cbase = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"%s\", 1000000);",file.Data())); | |
1367 | } else { | |
1368 | cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"%s\", 1000000);",file.Data())); | |
84fcd93f | 1369 | printf(" Merging collection <%s> into masterjob input...\n", file.Data()); |
319593fb | 1370 | cbase->Add(cadd); |
1371 | delete cadd; | |
1372 | } | |
1373 | if ((nruns%fNrunsPerMaster)!=0 && os!=arr->Last()) { | |
1374 | continue; | |
1375 | } | |
1376 | schunk += Form("_%s.xml", os->GetString().Data()); | |
0f389141 | 1377 | if (FileExists(schunk)) { |
1378 | if (fOverwriteMode) gGrid->Rm(file); | |
1379 | else { | |
1380 | Info("CreateDataset", "\n##### Dataset %s exist. Skipping creation...", schunk.Data()); | |
1381 | continue; | |
1382 | } | |
319593fb | 1383 | } |
84fcd93f | 1384 | printf("Exporting merged collection <%s> and copying to AliEn\n", schunk.Data()); |
319593fb | 1385 | cbase->ExportXML(Form("file://%s", schunk.Data()),kFALSE,kFALSE, schunk, "Merged runs"); |
e95434bc | 1386 | TFile::Cp(Form("file:%s",schunk.Data()), Form("alien://%s/%s",workdir.Data(), schunk.Data())); |
319593fb | 1387 | if (!FileExists(schunk)) { |
1388 | Error("CreateDataset", "Copy command did NOT succeed for %s", schunk.Data()); | |
1389 | delete arr; | |
1390 | return kFALSE; | |
1391 | } | |
d3339be3 | 1392 | } |
a8739e8a | 1393 | } |
1394 | delete arr; | |
a2f5fc01 | 1395 | if (nullResult) { |
d3339be3 | 1396 | Error("CreateDataset", "No valid dataset corresponding to the query!"); |
1397 | return kFALSE; | |
1398 | } | |
a8739e8a | 1399 | } else { |
1400 | // Process a full run range. | |
1401 | for (Int_t irun=fRunRange[0]; irun<=fRunRange[1]; irun++) { | |
74013535 | 1402 | format = Form("%%s/%s ", fRunPrefix.Data()); |
3af861ff | 1403 | nstart = 0; |
1404 | stage = 0; | |
74013535 | 1405 | path = Form(format.Data(), fGridDataDir.Data(), irun); |
923e2ca5 | 1406 | if (!DirectoryExists(path)) continue; |
1407 | // CdWork(); | |
74013535 | 1408 | format = Form("%s.xml", fRunPrefix.Data()); |
a8739e8a | 1409 | if (TestBit(AliAnalysisGrid::kTest)) file = "wn.xml"; |
74013535 | 1410 | else file = Form(format.Data(), irun); |
0f389141 | 1411 | if (FileExists(file) && fNrunsPerMaster<2 && !TestBit(AliAnalysisGrid::kTest)) { |
1412 | if (fOverwriteMode) gGrid->Rm(file); | |
1413 | else { | |
1414 | Info("CreateDataset", "\n##### Dataset %s exist. Skipping creation...", file.Data()); | |
1415 | continue; | |
1416 | } | |
a8739e8a | 1417 | } |
319593fb | 1418 | // If local collection file does not exist, create it via 'find' command. |
3af861ff | 1419 | while (1) { |
1420 | ncount = 0; | |
1421 | stage++; | |
1422 | if (gSystem->AccessPathName(file) || TestBit(AliAnalysisGrid::kTest) || fOverwriteMode) { | |
1423 | command = "find "; | |
1424 | command += Form("%s -o %d ",options.Data(), nstart); | |
1425 | command += path; | |
1426 | command += pattern; | |
1427 | command += conditions; | |
1428 | TGridResult *res = gGrid->Command(command); | |
1429 | if (res) delete res; | |
1430 | // Write standard output to file | |
1431 | gROOT->ProcessLine(Form("gGrid->Stdout(); > __tmp%d__%s", stage,file.Data())); | |
1432 | Bool_t hasGrep = (gSystem->Exec("grep --version 2>/dev/null > /dev/null")==0)?kTRUE:kFALSE; | |
1433 | Bool_t nullFile = kFALSE; | |
1434 | if (!hasGrep) { | |
1435 | Warning("CreateDataset", "'grep' command not available on this system - cannot validate the result of the grid 'find' command"); | |
1436 | } else { | |
1437 | nullFile = (gSystem->Exec(Form("grep -c /event __tmp%d__%s 2>/dev/null > __tmp__",stage,file.Data()))==0)?kFALSE:kTRUE; | |
1438 | if (nullFile) { | |
1439 | Warning("CreateDataset","Dataset %s produced by: <%s> is empty !", file.Data(), command.Data()); | |
1440 | gSystem->Exec("rm -f __tmp*"); | |
1604c9ed | 1441 | break; |
3af861ff | 1442 | } |
1443 | TString line; | |
1444 | ifstream in; | |
1445 | in.open("__tmp__"); | |
1446 | in >> line; | |
1447 | in.close(); | |
1448 | gSystem->Exec("rm -f __tmp__"); | |
1449 | ncount = line.Atoi(); | |
1450 | } | |
1451 | nullResult = kFALSE; | |
1452 | } | |
1453 | if (ncount == gMaxEntries) { | |
1454 | Info("CreateDataset", "Dataset %s has more than 15K entries. Trying to merge...", file.Data()); | |
1455 | if (fNrunsPerMaster > 1) { | |
1456 | Error("CreateDataset", "File %s has more than %d entries. Please set the number of runs per master to 1 !", | |
1457 | file.Data(),gMaxEntries); | |
1458 | return kFALSE; | |
1459 | } | |
1460 | cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"__tmp%d__%s\", 1000000);",stage,file.Data())); | |
1461 | if (!cbase) cbase = cadd; | |
1462 | else { | |
1463 | cbase->Add(cadd); | |
1464 | delete cadd; | |
defd7a3a | 1465 | } |
3af861ff | 1466 | nstart += ncount; |
1467 | } else { | |
c89a84bc | 1468 | if (cbase && fNrunsPerMaster<2) { |
3af861ff | 1469 | cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"__tmp%d__%s\", 1000000);",stage,file.Data())); |
1470 | printf("... please wait - TAlienCollection::Add() scales badly...\n"); | |
1471 | cbase->Add(cadd); | |
1472 | delete cadd; | |
1473 | cbase->ExportXML(Form("file://%s", file.Data()),kFALSE,kFALSE, file, "Merged entries for a run"); | |
1474 | delete cbase; cbase = 0; | |
1475 | } else { | |
1476 | TFile::Cp(Form("__tmp%d__%s",stage, file.Data()), file.Data()); | |
1477 | } | |
1478 | Info("CreateDataset", "Created dataset %s with %d files", file.Data(), nstart+ncount); | |
1479 | break; | |
d3339be3 | 1480 | } |
319593fb | 1481 | } |
a8739e8a | 1482 | if (TestBit(AliAnalysisGrid::kTest)) break; |
319593fb | 1483 | // Check if there is one run per master job. |
1484 | if (fNrunsPerMaster<2) { | |
1485 | if (FileExists(file)) { | |
0f389141 | 1486 | if (fOverwriteMode) gGrid->Rm(file); |
1487 | else { | |
1488 | Info("CreateDataset", "\n##### Dataset %s exist. Skipping creation...", file.Data()); | |
1489 | continue; | |
1490 | } | |
319593fb | 1491 | } |
1492 | // Copy xml file to alien space | |
1493 | TFile::Cp(Form("file:%s",file.Data()), Form("alien://%s/%s",workdir.Data(), file.Data())); | |
1494 | if (!FileExists(file)) { | |
1495 | Error("CreateDataset", "Command %s did NOT succeed", command.Data()); | |
1496 | return kFALSE; | |
1497 | } | |
1498 | } else { | |
1499 | nruns++; | |
95e5b448 | 1500 | // Check if the collection for the chunk exist locally. |
1501 | Int_t nchunk = (nruns-1)/fNrunsPerMaster; | |
0f389141 | 1502 | if (FileExists(fInputFiles->At(nchunk)->GetName())) { |
1503 | if (fOverwriteMode) gGrid->Rm(fInputFiles->At(nchunk)->GetName()); | |
1504 | else continue; | |
1505 | } | |
84fcd93f | 1506 | printf(" Merging collection <%s> into %d runs chunk...\n",file.Data(),fNrunsPerMaster); |
319593fb | 1507 | if (((nruns-1)%fNrunsPerMaster) == 0) { |
74013535 | 1508 | schunk = Form(fRunPrefix.Data(), irun); |
319593fb | 1509 | cbase = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"%s\", 1000000);",file.Data())); |
1510 | } else { | |
1511 | cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"%s\", 1000000);",file.Data())); | |
1512 | cbase->Add(cadd); | |
1513 | delete cadd; | |
1514 | } | |
74013535 | 1515 | format = Form("%%s_%s.xml", fRunPrefix.Data()); |
1516 | schunk2 = Form(format.Data(), schunk.Data(), irun); | |
904f9f5f | 1517 | if ((nruns%fNrunsPerMaster)!=0 && irun!=fRunRange[1] && schunk2 != fInputFiles->Last()->GetName()) { |
319593fb | 1518 | continue; |
1519 | } | |
904f9f5f | 1520 | schunk = schunk2; |
319593fb | 1521 | if (FileExists(schunk)) { |
0f389141 | 1522 | if (fOverwriteMode) gGrid->Rm(schunk); |
1523 | else { | |
1524 | Info("CreateDataset", "\n##### Dataset %s exist. Skipping creation...", schunk.Data()); | |
1525 | continue; | |
1526 | } | |
319593fb | 1527 | } |
84fcd93f | 1528 | printf("Exporting merged collection <%s> and copying to AliEn.\n", schunk.Data()); |
319593fb | 1529 | cbase->ExportXML(Form("file://%s", schunk.Data()),kFALSE,kFALSE, schunk, "Merged runs"); |
95e5b448 | 1530 | if (FileExists(schunk)) { |
0f389141 | 1531 | if (fOverwriteMode) gGrid->Rm(schunk); |
1532 | else { | |
1533 | Info("CreateDataset", "\n##### Dataset %s exist. Skipping copy...", schunk.Data()); | |
1534 | continue; | |
1535 | } | |
95e5b448 | 1536 | } |
319593fb | 1537 | TFile::Cp(Form("file:%s",schunk.Data()), Form("alien://%s/%s",workdir.Data(), schunk.Data())); |
1538 | if (!FileExists(schunk)) { | |
1539 | Error("CreateDataset", "Copy command did NOT succeed for %s", schunk.Data()); | |
1540 | return kFALSE; | |
1541 | } | |
1542 | } | |
c57f56b7 | 1543 | } |
a2f5fc01 | 1544 | if (nullResult) { |
d3339be3 | 1545 | Error("CreateDataset", "No valid dataset corresponding to the query!"); |
1546 | return kFALSE; | |
1547 | } | |
a8739e8a | 1548 | } |
c57f56b7 | 1549 | return kTRUE; |
1550 | } | |
1551 | ||
1552 | //______________________________________________________________________________ | |
1553 | Bool_t AliAnalysisAlien::CreateJDL() | |
1554 | { | |
1555 | // Generate a JDL file according to current settings. The name of the file is | |
1556 | // specified by fJDLName. | |
ec5acdce | 1557 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); |
c57f56b7 | 1558 | Bool_t error = kFALSE; |
1559 | TObjArray *arr = 0; | |
1560 | Bool_t copy = kTRUE; | |
d3b18c4c | 1561 | if (fProductionMode || TestBit(AliAnalysisGrid::kOffline) || TestBit(AliAnalysisGrid::kTest)) copy = kFALSE; |
c57f56b7 | 1562 | Bool_t generate = kTRUE; |
1563 | if (TestBit(AliAnalysisGrid::kTest) || TestBit(AliAnalysisGrid::kSubmit)) generate = kFALSE; | |
1564 | if (!Connect()) { | |
1565 | Error("CreateJDL", "Alien connection required"); | |
1566 | return kFALSE; | |
1567 | } | |
1568 | // Check validity of alien workspace | |
d3b18c4c | 1569 | TString workdir; |
1570 | if (!fProductionMode && !fGridWorkingDir.BeginsWith("/alice")) workdir = gGrid->GetHomeDirectory(); | |
1571 | if (!fProductionMode && !TestBit(AliAnalysisGrid::kTest)) CdWork(); | |
c57f56b7 | 1572 | workdir += fGridWorkingDir; |
1573 | if (generate) { | |
1574 | TObjString *os; | |
1575 | if (!fInputFiles) { | |
1576 | Error("CreateJDL()", "Define some input files for your analysis."); | |
1577 | error = kTRUE; | |
1578 | } | |
1579 | // Compose list of input files | |
1580 | // Check if output files were defined | |
1581 | if (!fOutputFiles.Length()) { | |
1582 | Error("CreateJDL", "You must define at least one output file"); | |
1583 | error = kTRUE; | |
1584 | } | |
1585 | // Check if an output directory was defined and valid | |
1586 | if (!fGridOutputDir.Length()) { | |
1587 | Error("CreateJDL", "You must define AliEn output directory"); | |
1588 | error = kTRUE; | |
1589 | } else { | |
d3b18c4c | 1590 | if (!fProductionMode) { |
1591 | if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("%s/%s", workdir.Data(), fGridOutputDir.Data()); | |
1592 | if (!DirectoryExists(fGridOutputDir)) { | |
1593 | if (gGrid->Mkdir(fGridOutputDir,"-p")) { | |
1594 | Info("CreateJDL", "\n##### Created alien output directory %s", fGridOutputDir.Data()); | |
1595 | } else { | |
1596 | Error("CreateJDL", "Could not create alien output directory %s", fGridOutputDir.Data()); | |
1597 | // error = kTRUE; | |
1598 | } | |
67a3b254 | 1599 | } else { |
1600 | Warning("CreateJDL", "#### Output directory %s exists! If this contains old data, jobs will fail with ERROR_SV !!! ###", fGridOutputDir.Data()); | |
d3b18c4c | 1601 | } |
1602 | gGrid->Cd(workdir); | |
1603 | } | |
c57f56b7 | 1604 | } |
1605 | // Exit if any error up to now | |
1606 | if (error) return kFALSE; | |
1607 | // Set JDL fields | |
0f389141 | 1608 | if (!fUser.IsNull()) { |
1609 | fGridJDL->SetValue("User", Form("\"%s\"", fUser.Data())); | |
1610 | fMergingJDL->SetValue("User", Form("\"%s\"", fUser.Data())); | |
1611 | } | |
1612 | fGridJDL->SetExecutable(fExecutable, "This is the startup script"); | |
1613 | TString mergeExec = fExecutable; | |
1614 | mergeExec.ReplaceAll(".sh", "_merge.sh"); | |
1615 | fMergingJDL->SetExecutable(mergeExec, "This is the startup script"); | |
1616 | mergeExec.ReplaceAll(".sh", ".C"); | |
1617 | fMergingJDL->AddToInputSandbox(Form("LF:%s/%s", workdir.Data(),mergeExec.Data()), "List of input files to be uploaded to workers"); | |
b5b9dee8 | 1618 | if (!fArguments.IsNull()) |
1619 | fGridJDL->SetArguments(fArguments, "Arguments for the executable command"); | |
d3b18c4c | 1620 | if (IsOneStageMerging()) fMergingJDL->SetArguments(fGridOutputDir); |
f47d5cb4 | 1621 | else { |
1622 | if (fProductionMode) fMergingJDL->SetArguments("wn.xml $4"); // xml, stage | |
1623 | else fMergingJDL->SetArguments("wn.xml $2"); // xml, stage | |
1624 | } | |
b3e07543 | 1625 | |
1f0d1ca2 | 1626 | fGridJDL->SetValue("TTL", Form("\"%d\"",fTTL)); |
1627 | fGridJDL->SetDescription("TTL", Form("Time after which the job is killed (%d min.)", fTTL/60)); | |
1628 | fMergingJDL->SetValue("TTL", Form("\"%d\"",fTTL)); | |
1629 | fMergingJDL->SetDescription("TTL", Form("Time after which the job is killed (%d min.)", fTTL/60)); | |
1630 | ||
0f389141 | 1631 | if (fMaxInitFailed > 0) { |
c57f56b7 | 1632 | fGridJDL->SetValue("MaxInitFailed", Form("\"%d\"",fMaxInitFailed)); |
0f389141 | 1633 | fGridJDL->SetDescription("MaxInitFailed", "Maximum number of first failing jobs to abort the master job"); |
1634 | } | |
1635 | if (fSplitMaxInputFileNumber > 0) { | |
c57f56b7 | 1636 | fGridJDL->SetValue("SplitMaxInputFileNumber", Form("\"%d\"", fSplitMaxInputFileNumber)); |
0f389141 | 1637 | fGridJDL->SetDescription("SplitMaxInputFileNumber", "Maximum number of input files to be processed per subjob"); |
b3e07543 | 1638 | } |
1639 | if (!IsOneStageMerging()) { | |
f47d5cb4 | 1640 | fMergingJDL->SetValue("SplitMaxInputFileNumber", Form("\"%d\"",fMaxMergeFiles)); |
b3e07543 | 1641 | fMergingJDL->SetDescription("SplitMaxInputFileNumber", "Maximum number of input files to be merged in one go"); |
0f389141 | 1642 | } |
1643 | if (fSplitMode.Length()) { | |
c57f56b7 | 1644 | fGridJDL->SetValue("Split", Form("\"%s\"", fSplitMode.Data())); |
0f389141 | 1645 | fGridJDL->SetDescription("Split", "We split per SE or file"); |
b3e07543 | 1646 | } |
1647 | fMergingJDL->SetValue("Split", "\"se\""); | |
1648 | fMergingJDL->SetDescription("Split", "We split per SE for merging in stages"); | |
0f389141 | 1649 | if (!fAliROOTVersion.IsNull()) { |
1650 | fGridJDL->AddToPackages("AliRoot", fAliROOTVersion,"VO_ALICE", "List of requested packages"); | |
1651 | fMergingJDL->AddToPackages("AliRoot", fAliROOTVersion, "VO_ALICE", "List of requested packages"); | |
1652 | } | |
1653 | if (!fROOTVersion.IsNull()) { | |
c57f56b7 | 1654 | fGridJDL->AddToPackages("ROOT", fROOTVersion); |
0f389141 | 1655 | fMergingJDL->AddToPackages("ROOT", fROOTVersion); |
1656 | } | |
1657 | if (!fAPIVersion.IsNull()) { | |
c57f56b7 | 1658 | fGridJDL->AddToPackages("APISCONFIG", fAPIVersion); |
0f389141 | 1659 | fMergingJDL->AddToPackages("APISCONFIG", fAPIVersion); |
1660 | } | |
648174cf | 1661 | if (!fExternalPackages.IsNull()) { |
1662 | arr = fExternalPackages.Tokenize(" "); | |
1663 | TIter next(arr); | |
1664 | while ((os=(TObjString*)next())) { | |
1665 | TString pkgname = os->GetString(); | |
1666 | Int_t index = pkgname.Index("::"); | |
1667 | TString pkgversion = pkgname(index+2, pkgname.Length()); | |
1668 | pkgname.Remove(index); | |
1669 | fGridJDL->AddToPackages(pkgname, pkgversion); | |
0f389141 | 1670 | fMergingJDL->AddToPackages(pkgname, pkgversion); |
648174cf | 1671 | } |
1672 | delete arr; | |
1673 | } | |
0f389141 | 1674 | fGridJDL->SetInputDataListFormat(fInputFormat, "Format of input data"); |
1675 | fGridJDL->SetInputDataList("wn.xml", "Collection name to be processed on each worker node"); | |
b3e07543 | 1676 | fMergingJDL->SetInputDataListFormat(fInputFormat, "Format of input data"); |
1677 | fMergingJDL->SetInputDataList("wn.xml", "Collection name to be processed on each worker node"); | |
0f389141 | 1678 | fGridJDL->AddToInputSandbox(Form("LF:%s/%s", workdir.Data(), fAnalysisMacro.Data()), "List of input files to be uploaded to workers"); |
f10e8481 | 1679 | TString analysisFile = fExecutable; |
1680 | analysisFile.ReplaceAll(".sh", ".root"); | |
1681 | fGridJDL->AddToInputSandbox(Form("LF:%s/%s", workdir.Data(),analysisFile.Data())); | |
f866cba5 | 1682 | fMergingJDL->AddToInputSandbox(Form("LF:%s/%s", workdir.Data(),analysisFile.Data())); |
c57f56b7 | 1683 | if (fAdditionalLibs.Length()) { |
1684 | arr = fAdditionalLibs.Tokenize(" "); | |
1685 | TIter next(arr); | |
1686 | while ((os=(TObjString*)next())) { | |
1687 | if (os->GetString().Contains(".so")) continue; | |
1688 | fGridJDL->AddToInputSandbox(Form("LF:%s/%s", workdir.Data(), os->GetString().Data())); | |
0f389141 | 1689 | fMergingJDL->AddToInputSandbox(Form("LF:%s/%s", workdir.Data(), os->GetString().Data())); |
c57f56b7 | 1690 | } |
1691 | delete arr; | |
1692 | } | |
4e5c5506 | 1693 | if (fPackages) { |
1694 | TIter next(fPackages); | |
1695 | TObject *obj; | |
0f389141 | 1696 | while ((obj=next())) { |
4e5c5506 | 1697 | fGridJDL->AddToInputSandbox(Form("LF:%s/%s", workdir.Data(), obj->GetName())); |
0f389141 | 1698 | fMergingJDL->AddToInputSandbox(Form("LF:%s/%s", workdir.Data(), obj->GetName())); |
1699 | } | |
4e5c5506 | 1700 | } |
c57f56b7 | 1701 | if (fOutputArchive.Length()) { |
e4d9a069 | 1702 | TString outputArchive = fOutputArchive; |
1703 | if (!fRegisterExcludes.IsNull()) { | |
1704 | arr = fRegisterExcludes.Tokenize(" "); | |
1705 | TIter next1(arr); | |
1706 | while ((os=(TObjString*)next1())) { | |
1707 | outputArchive.ReplaceAll(Form("%s,",os->GetString().Data()),""); | |
1708 | outputArchive.ReplaceAll(os->GetString(),""); | |
1709 | } | |
1710 | delete arr; | |
1711 | } | |
1712 | arr = outputArchive.Tokenize(" "); | |
c57f56b7 | 1713 | TIter next(arr); |
0f389141 | 1714 | Bool_t first = kTRUE; |
1715 | const char *comment = "Files to be archived"; | |
1716 | const char *comment1 = comment; | |
1717 | while ((os=(TObjString*)next())) { | |
1718 | if (!first) comment = NULL; | |
1719 | if (!os->GetString().Contains("@") && fCloseSE.Length()) | |
1720 | fGridJDL->AddToOutputArchive(Form("%s@%s",os->GetString().Data(), fCloseSE.Data()), comment); | |
1721 | else | |
1722 | fGridJDL->AddToOutputArchive(os->GetString(), comment); | |
1723 | first = kFALSE; | |
1724 | } | |
c57f56b7 | 1725 | delete arr; |
f790bc1b | 1726 | // Output archive for the merging jdl |
f790bc1b | 1727 | if (TestBit(AliAnalysisGrid::kDefaultOutputs)) { |
b83f84f0 | 1728 | outputArchive = "log_archive.zip:std*@disk=1 "; |
f790bc1b | 1729 | // Add normal output files, extra files + terminate files |
1730 | TString files = GetListOfFiles("outextter"); | |
37d21c01 | 1731 | // Do not register files in fRegisterExcludes |
1732 | if (!fRegisterExcludes.IsNull()) { | |
1733 | arr = fRegisterExcludes.Tokenize(" "); | |
f790bc1b | 1734 | TIter next1(arr); |
1735 | while ((os=(TObjString*)next1())) { | |
1736 | files.ReplaceAll(Form("%s,",os->GetString().Data()),""); | |
1737 | files.ReplaceAll(os->GetString(),""); | |
1738 | } | |
66d71516 | 1739 | delete arr; |
0f389141 | 1740 | } |
f790bc1b | 1741 | files.ReplaceAll(".root", "*.root"); |
ec5acdce | 1742 | |
1743 | if (mgr->IsCollectThroughput()) | |
1744 | outputArchive += Form("root_archive.zip:%s,*.stat,*%s@disk=%d",files.Data(),mgr->GetFileInfoLog(),fNreplicas); | |
1745 | else | |
1746 | outputArchive += Form("root_archive.zip:%s,*.stat@disk=%d",files.Data(),fNreplicas); | |
f790bc1b | 1747 | } else { |
95f84779 | 1748 | TString files = fOutputArchive; |
1749 | files.ReplaceAll(".root", "*.root"); // nreplicas etc should be already atttached by use | |
1750 | outputArchive = files; | |
f790bc1b | 1751 | } |
0f389141 | 1752 | arr = outputArchive.Tokenize(" "); |
705adb3e | 1753 | TIter next2(arr); |
0f389141 | 1754 | comment = comment1; |
1755 | first = kTRUE; | |
705adb3e | 1756 | while ((os=(TObjString*)next2())) { |
0f389141 | 1757 | if (!first) comment = NULL; |
0cdf65a8 | 1758 | TString currentfile = os->GetString(); |
0cdf65a8 | 1759 | if (!currentfile.Contains("@") && fCloseSE.Length()) |
d3b18c4c | 1760 | fMergingJDL->AddToOutputArchive(Form("%s@%s",currentfile.Data(), fCloseSE.Data()), comment); |
0f389141 | 1761 | else |
0cdf65a8 | 1762 | fMergingJDL->AddToOutputArchive(currentfile, comment); |
0f389141 | 1763 | first = kFALSE; |
1764 | } | |
1765 | delete arr; | |
c57f56b7 | 1766 | } |
149d288c | 1767 | arr = fOutputFiles.Tokenize(","); |
c57f56b7 | 1768 | TIter next(arr); |
0f389141 | 1769 | Bool_t first = kTRUE; |
f790bc1b | 1770 | const char *comment = "Files to be saved"; |
43da816a | 1771 | while ((os=(TObjString*)next())) { |
e1eaf596 | 1772 | // Ignore ouputs in jdl that are also in outputarchive |
1773 | TString sout = os->GetString(); | |
f790bc1b | 1774 | sout.ReplaceAll("*", ""); |
1775 | sout.ReplaceAll(".root", ""); | |
e1eaf596 | 1776 | if (sout.Index("@")>0) sout.Remove(sout.Index("@")); |
1777 | if (fOutputArchive.Contains(sout)) continue; | |
37d21c01 | 1778 | // Ignore fRegisterExcludes |
1779 | if (fRegisterExcludes.Contains(sout)) continue; | |
0f389141 | 1780 | if (!first) comment = NULL; |
43da816a | 1781 | if (!os->GetString().Contains("@") && fCloseSE.Length()) |
0f389141 | 1782 | fGridJDL->AddToOutputSandbox(Form("%s@%s",os->GetString().Data(), fCloseSE.Data()), comment); |
43da816a | 1783 | else |
0f389141 | 1784 | fGridJDL->AddToOutputSandbox(os->GetString(), comment); |
b3e07543 | 1785 | first = kFALSE; |
f790bc1b | 1786 | if (fMergeExcludes.Contains(sout)) continue; |
1787 | if (!os->GetString().Contains("@") && fCloseSE.Length()) | |
1788 | fMergingJDL->AddToOutputSandbox(Form("%s@%s",os->GetString().Data(), fCloseSE.Data()), comment); | |
1789 | else | |
1790 | fMergingJDL->AddToOutputSandbox(os->GetString(), comment); | |
43da816a | 1791 | } |
c57f56b7 | 1792 | delete arr; |
0f389141 | 1793 | fGridJDL->SetPrice((UInt_t)fPrice, "AliEn price for this job"); |
1794 | fMergingJDL->SetPrice((UInt_t)fPrice, "AliEn price for this job"); | |
d3b18c4c | 1795 | TString validationScript = fValidationScript; |
0f389141 | 1796 | fGridJDL->SetValidationCommand(Form("%s/%s", workdir.Data(),validationScript.Data()), "Validation script to be run for each subjob"); |
d3b18c4c | 1797 | validationScript.ReplaceAll(".sh", "_merge.sh"); |
0f389141 | 1798 | fMergingJDL->SetValidationCommand(Form("%s/%s", workdir.Data(),validationScript.Data()), "Validation script to be run for each subjob"); |
1799 | if (fMasterResubmitThreshold) { | |
1800 | fGridJDL->SetValue("MasterResubmitThreshold", Form("\"%d%%\"", fMasterResubmitThreshold)); | |
1801 | fGridJDL->SetDescription("MasterResubmitThreshold", "Resubmit failed jobs until DONE rate reaches this percentage"); | |
1802 | } | |
d2a409b2 | 1803 | // Write a jdl with 2 input parameters: collection name and output dir name. |
1804 | WriteJDL(copy); | |
c57f56b7 | 1805 | } |
1806 | // Copy jdl to grid workspace | |
a8739e8a | 1807 | if (copy) { |
b5e4aaa7 | 1808 | // Check if an output directory was defined and valid |
1809 | if (!fGridOutputDir.Length()) { | |
1810 | Error("CreateJDL", "You must define AliEn output directory"); | |
1811 | return kFALSE; | |
1812 | } else { | |
1813 | if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("%s/%s", workdir.Data(), fGridOutputDir.Data()); | |
bb2e67a0 | 1814 | if (!fProductionMode && !DirectoryExists(fGridOutputDir)) { |
b93f8109 | 1815 | if (gGrid->Mkdir(fGridOutputDir,"-p")) { |
b5e4aaa7 | 1816 | Info("CreateJDL", "\n##### Created alien output directory %s", fGridOutputDir.Data()); |
1817 | } else { | |
1818 | Error("CreateJDL", "Could not create alien output directory %s", fGridOutputDir.Data()); | |
1819 | return kFALSE; | |
1820 | } | |
1821 | } | |
1822 | gGrid->Cd(workdir); | |
1823 | } | |
648174cf | 1824 | if (TestBit(AliAnalysisGrid::kSubmit)) { |
0f389141 | 1825 | TString mergeJDLName = fExecutable; |
1826 | mergeJDLName.ReplaceAll(".sh", "_merge.jdl"); | |
648174cf | 1827 | TString locjdl = Form("%s/%s", fGridOutputDir.Data(),fJDLName.Data()); |
0f389141 | 1828 | TString locjdl1 = Form("%s/%s", fGridOutputDir.Data(),mergeJDLName.Data()); |
1829 | if (fProductionMode) { | |
648174cf | 1830 | locjdl = Form("%s/%s", workdir.Data(),fJDLName.Data()); |
0f389141 | 1831 | locjdl1 = Form("%s/%s", workdir.Data(),mergeJDLName.Data()); |
1832 | } | |
648174cf | 1833 | if (FileExists(locjdl)) gGrid->Rm(locjdl); |
0f389141 | 1834 | if (FileExists(locjdl1)) gGrid->Rm(locjdl1); |
1835 | Info("CreateJDL", "\n##### Copying JDL file <%s> to your AliEn output directory", fJDLName.Data()); | |
6c395669 | 1836 | if (!copyLocal2Alien("CreateJDL", fJDLName, locjdl)) |
1837 | Fatal("","Terminating"); | |
1838 | // TFile::Cp(Form("file:%s",fJDLName.Data()), Form("alien://%s", locjdl.Data())); | |
0f389141 | 1839 | if (fMergeViaJDL) { |
1840 | Info("CreateJDL", "\n##### Copying merging JDL file <%s> to your AliEn output directory", mergeJDLName.Data()); | |
6c395669 | 1841 | // TFile::Cp(Form("file:%s",mergeJDLName.Data()), Form("alien://%s", locjdl1.Data())); |
1842 | if (!copyLocal2Alien("CreateJDL", mergeJDLName.Data(), locjdl1)) | |
1843 | Fatal("","Terminating"); | |
0f389141 | 1844 | } |
648174cf | 1845 | } |
c57f56b7 | 1846 | if (fAdditionalLibs.Length()) { |
e7c71df0 | 1847 | arr = fAdditionalLibs.Tokenize(" "); |
c57f56b7 | 1848 | TObjString *os; |
1849 | TIter next(arr); | |
1850 | while ((os=(TObjString*)next())) { | |
c57f56b7 | 1851 | if (os->GetString().Contains(".so")) continue; |
4e5c5506 | 1852 | Info("CreateJDL", "\n##### Copying dependency: <%s> to your alien workspace", os->GetString().Data()); |
c57f56b7 | 1853 | if (FileExists(os->GetString())) gGrid->Rm(os->GetString()); |
6c395669 | 1854 | // TFile::Cp(Form("file:%s",os->GetString().Data()), Form("alien://%s/%s", workdir.Data(), os->GetString().Data())); |
1855 | if (!copyLocal2Alien("CreateJDL", os->GetString().Data(), | |
1856 | Form("%s/%s", workdir.Data(), os->GetString().Data()))) | |
1857 | Fatal("","Terminating"); | |
c57f56b7 | 1858 | } |
1859 | delete arr; | |
1860 | } | |
4e5c5506 | 1861 | if (fPackages) { |
1862 | TIter next(fPackages); | |
1863 | TObject *obj; | |
1864 | while ((obj=next())) { | |
fdbbc7be | 1865 | if (FileExists(obj->GetName())) gGrid->Rm(obj->GetName()); |
4e5c5506 | 1866 | Info("CreateJDL", "\n##### Copying dependency: <%s> to your alien workspace", obj->GetName()); |
6c395669 | 1867 | // TFile::Cp(Form("file:%s",obj->GetName()), Form("alien://%s/%s", workdir.Data(), obj->GetName())); |
1868 | if (!copyLocal2Alien("CreateJDL",obj->GetName(), | |
1869 | Form("%s/%s", workdir.Data(), obj->GetName()))) | |
1870 | Fatal("","Terminating"); | |
4e5c5506 | 1871 | } |
1872 | } | |
c57f56b7 | 1873 | } |
1874 | return kTRUE; | |
1875 | } | |
1876 | ||
a8739e8a | 1877 | //______________________________________________________________________________ |
d2a409b2 | 1878 | Bool_t AliAnalysisAlien::WriteJDL(Bool_t copy) |
a8739e8a | 1879 | { |
1880 | // Writes one or more JDL's corresponding to findex. If findex is negative, | |
1881 | // all run numbers are considered in one go (jdl). For non-negative indices | |
1882 | // they correspond to the indices in the array fInputFiles. | |
1883 | if (!fInputFiles) return kFALSE; | |
d3b18c4c | 1884 | TObject *os; |
1885 | TString workdir; | |
1886 | if (!fProductionMode && !fGridWorkingDir.BeginsWith("/alice")) workdir = gGrid->GetHomeDirectory(); | |
a8739e8a | 1887 | workdir += fGridWorkingDir; |
f47d5cb4 | 1888 | TString stageName = "$2"; |
1889 | if (fProductionMode) stageName = "$4"; | |
1890 | if (!fMergeDirName.IsNull()) { | |
1891 | fMergingJDL->AddToInputDataCollection(Form("LF:$1/%s/Stage_%s.xml,nodownload",fMergeDirName.Data(),stageName.Data()), "Collection of files to be merged for current stage"); | |
1892 | fMergingJDL->SetOutputDirectory(Form("$1/%s/Stage_%s/#alien_counter_03i#",fMergeDirName.Data(),stageName.Data()), "Output directory"); | |
1893 | } else { | |
1894 | fMergingJDL->AddToInputDataCollection(Form("LF:$1/Stage_%s.xml,nodownload",stageName.Data()), "Collection of files to be merged for current stage"); | |
1895 | fMergingJDL->SetOutputDirectory(Form("$1/Stage_%s/#alien_counter_03i#",stageName.Data()), "Output directory"); | |
1896 | } | |
d3b18c4c | 1897 | if (fProductionMode) { |
a8739e8a | 1898 | TIter next(fInputFiles); |
b3e07543 | 1899 | while ((os=next())) { |
d3b18c4c | 1900 | fGridJDL->AddToInputDataCollection(Form("LF:%s,nodownload", os->GetName()), "Input xml collections"); |
b3e07543 | 1901 | } |
56754bf6 | 1902 | if (!fOutputToRunNo) |
1903 | fGridJDL->SetOutputDirectory(Form("%s/#alien_counter_04i#", fGridOutputDir.Data())); | |
1904 | else | |
1905 | fGridJDL->SetOutputDirectory(fGridOutputDir); | |
d3b18c4c | 1906 | } else { |
1907 | if (!fRunNumbers.Length() && !fRunRange[0]) { | |
1908 | // One jdl with no parameters in case input data is specified by name. | |
1909 | TIter next(fInputFiles); | |
1910 | while ((os=next())) | |
1911 | fGridJDL->AddToInputDataCollection(Form("LF:%s,nodownload", os->GetName()), "Input xml collections"); | |
1912 | if (!fOutputSingle.IsNull()) | |
1913 | fGridJDL->SetOutputDirectory(Form("#alienfulldir#/../%s",fOutputSingle.Data()), "Output directory"); | |
1914 | else { | |
1915 | fGridJDL->SetOutputDirectory(Form("%s/#alien_counter_03i#", fGridOutputDir.Data()), "Output directory"); | |
1916 | fMergingJDL->SetOutputDirectory(fGridOutputDir); | |
1917 | } | |
1918 | } else { | |
1919 | // One jdl to be submitted with 2 input parameters: data collection name and output dir prefix | |
1920 | fGridJDL->AddToInputDataCollection(Form("LF:%s/$1,nodownload", workdir.Data()), "Input xml collections"); | |
1921 | if (!fOutputSingle.IsNull()) { | |
1922 | if (!fOutputToRunNo) fGridJDL->SetOutputDirectory(Form("#alienfulldir#/%s",fOutputSingle.Data()), "Output directory"); | |
1923 | else fGridJDL->SetOutputDirectory(Form("%s/$2",fGridOutputDir.Data()), "Output directory"); | |
1924 | } else { | |
1925 | fGridJDL->SetOutputDirectory(Form("%s/$2/#alien_counter_03i#", fGridOutputDir.Data()), "Output directory"); | |
d3b18c4c | 1926 | } |
1927 | } | |
a8739e8a | 1928 | } |
1929 | ||
a8739e8a | 1930 | // Generate the JDL as a string |
1931 | TString sjdl = fGridJDL->Generate(); | |
0f389141 | 1932 | TString sjdl1 = fMergingJDL->Generate(); |
f47d5cb4 | 1933 | // Final merge jdl |
1934 | if (!fMergeDirName.IsNull()) { | |
1935 | fMergingJDL->SetOutputDirectory(Form("$1/%s",fMergeDirName.Data()), "Output directory"); | |
1936 | fMergingJDL->AddToInputSandbox(Form("LF:$1/%s/Stage_%s.xml",fMergeDirName.Data(),stageName.Data())); | |
1937 | } else { | |
1938 | fMergingJDL->SetOutputDirectory("$1", "Output directory"); | |
1939 | fMergingJDL->AddToInputSandbox(Form("LF:$1/Stage_%s.xml",stageName.Data())); | |
1940 | } | |
b3e07543 | 1941 | TString sjdl2 = fMergingJDL->Generate(); |
1942 | Int_t index, index1; | |
a8739e8a | 1943 | sjdl.ReplaceAll("\"LF:", "\n \"LF:"); |
1944 | sjdl.ReplaceAll("(member", "\n (member"); | |
1945 | sjdl.ReplaceAll("\",\"VO_", "\",\n \"VO_"); | |
1946 | sjdl.ReplaceAll("{", "{\n "); | |
1947 | sjdl.ReplaceAll("};", "\n};"); | |
1948 | sjdl.ReplaceAll("{\n \n", "{\n"); | |
1949 | sjdl.ReplaceAll("\n\n", "\n"); | |
1950 | sjdl.ReplaceAll("OutputDirectory", "OutputDir"); | |
0f389141 | 1951 | sjdl1.ReplaceAll("\"LF:", "\n \"LF:"); |
1952 | sjdl1.ReplaceAll("(member", "\n (member"); | |
1953 | sjdl1.ReplaceAll("\",\"VO_", "\",\n \"VO_"); | |
1954 | sjdl1.ReplaceAll("{", "{\n "); | |
1955 | sjdl1.ReplaceAll("};", "\n};"); | |
1956 | sjdl1.ReplaceAll("{\n \n", "{\n"); | |
1957 | sjdl1.ReplaceAll("\n\n", "\n"); | |
1958 | sjdl1.ReplaceAll("OutputDirectory", "OutputDir"); | |
b3e07543 | 1959 | sjdl2.ReplaceAll("\"LF:", "\n \"LF:"); |
1960 | sjdl2.ReplaceAll("(member", "\n (member"); | |
1961 | sjdl2.ReplaceAll("\",\"VO_", "\",\n \"VO_"); | |
1962 | sjdl2.ReplaceAll("{", "{\n "); | |
1963 | sjdl2.ReplaceAll("};", "\n};"); | |
1964 | sjdl2.ReplaceAll("{\n \n", "{\n"); | |
1965 | sjdl2.ReplaceAll("\n\n", "\n"); | |
1966 | sjdl2.ReplaceAll("OutputDirectory", "OutputDir"); | |
a8739e8a | 1967 | sjdl += "JDLVariables = \n{\n \"Packages\",\n \"OutputDir\"\n};\n"; |
f60ef0ba | 1968 | sjdl.Prepend(Form("Jobtag = {\n \"comment:%s\"\n};\n", fJobTag.Data())); |
a8739e8a | 1969 | index = sjdl.Index("JDLVariables"); |
1970 | if (index >= 0) sjdl.Insert(index, "\n# JDL variables\n"); | |
4739b2aa | 1971 | sjdl += "Workdirectorysize = {\"5000MB\"};"; |
b3e07543 | 1972 | sjdl1 += "Workdirectorysize = {\"5000MB\"};"; |
0f389141 | 1973 | sjdl1 += "JDLVariables = \n{\n \"Packages\",\n \"OutputDir\"\n};\n"; |
d3b18c4c | 1974 | index = fJobTag.Index(":"); |
1975 | if (index < 0) index = fJobTag.Length(); | |
1976 | TString jobTag = fJobTag; | |
f47d5cb4 | 1977 | if (fProductionMode) jobTag.Insert(index,"_Stage$4"); |
d3b18c4c | 1978 | sjdl1.Prepend(Form("Jobtag = {\n \"comment:%s_Merging\"\n};\n", jobTag.Data())); |
f47d5cb4 | 1979 | if (fProductionMode) { |
1980 | sjdl1.Prepend("# Generated merging jdl (production mode) \ | |
1981 | \n# $1 = full alien path to output directory to be merged \ | |
1982 | \n# $2 = train number \ | |
1983 | \n# $3 = production (like LHC10b) \ | |
1984 | \n# $4 = merging stage \ | |
1985 | \n# Stage_<n>.xml made via: find <OutputDir> *Stage<n-1>/*root_archive.zip\n"); | |
1986 | sjdl2.Prepend(Form("Jobtag = {\n \"comment:%s_FinalMerging\"\n};\n", jobTag.Data())); | |
1987 | sjdl2.Prepend("# Generated merging jdl \ | |
1988 | \n# $1 = full alien path to output directory to be merged \ | |
1989 | \n# $2 = train number \ | |
1990 | \n# $3 = production (like LHC10b) \ | |
1991 | \n# $4 = merging stage \ | |
1992 | \n# Stage_<n>.xml made via: find <OutputDir> *Stage<n-1>/*root_archive.zip\n"); | |
1993 | } else { | |
1994 | sjdl1.Prepend("# Generated merging jdl \ | |
1995 | \n# $1 = full alien path to output directory to be merged \ | |
1996 | \n# $2 = merging stage \ | |
03335324 | 1997 | \n# xml made via: find <OutputDir> *Stage<n-1>/*root_archive.zip\n"); |
f47d5cb4 | 1998 | sjdl2.Prepend(Form("Jobtag = {\n \"comment:%s_FinalMerging\"\n};\n", jobTag.Data())); |
1999 | sjdl2.Prepend("# Generated merging jdl \ | |
2000 | \n# $1 = full alien path to output directory to be merged \ | |
2001 | \n# $2 = merging stage \ | |
03335324 | 2002 | \n# xml made via: find <OutputDir> *Stage<n-1>/*root_archive.zip\n"); |
f47d5cb4 | 2003 | } |
0f389141 | 2004 | index = sjdl1.Index("JDLVariables"); |
2005 | if (index >= 0) sjdl1.Insert(index, "\n# JDL variables\n"); | |
b3e07543 | 2006 | index = sjdl2.Index("JDLVariables"); |
2007 | if (index >= 0) sjdl2.Insert(index, "\n# JDL variables\n"); | |
4739b2aa | 2008 | sjdl1 += "Workdirectorysize = {\"5000MB\"};"; |
b3e07543 | 2009 | sjdl2 += "Workdirectorysize = {\"5000MB\"};"; |
2010 | index = sjdl2.Index("Split ="); | |
2011 | if (index>=0) { | |
2012 | index1 = sjdl2.Index("\n", index); | |
2013 | sjdl2.Remove(index, index1-index+1); | |
2014 | } | |
2015 | index = sjdl2.Index("SplitMaxInputFileNumber"); | |
2016 | if (index>=0) { | |
2017 | index1 = sjdl2.Index("\n", index); | |
2018 | sjdl2.Remove(index, index1-index+1); | |
2019 | } | |
2020 | index = sjdl2.Index("InputDataCollection"); | |
2021 | if (index>=0) { | |
2022 | index1 = sjdl2.Index(";", index); | |
2023 | sjdl2.Remove(index, index1-index+1); | |
2024 | } | |
2025 | index = sjdl2.Index("InputDataListFormat"); | |
2026 | if (index>=0) { | |
2027 | index1 = sjdl2.Index("\n", index); | |
2028 | sjdl2.Remove(index, index1-index+1); | |
2029 | } | |
2030 | index = sjdl2.Index("InputDataList"); | |
2031 | if (index>=0) { | |
2032 | index1 = sjdl2.Index("\n", index); | |
2033 | sjdl2.Remove(index, index1-index+1); | |
2034 | } | |
f47d5cb4 | 2035 | sjdl2.ReplaceAll("wn.xml", Form("Stage_%s.xml",stageName.Data())); |
a8739e8a | 2036 | // Write jdl to file |
a8739e8a | 2037 | ofstream out; |
d2a409b2 | 2038 | out.open(fJDLName.Data(), ios::out); |
a8739e8a | 2039 | if (out.bad()) { |
d3b18c4c | 2040 | Error("WriteJDL", "Bad file name: %s", fJDLName.Data()); |
a8739e8a | 2041 | return kFALSE; |
2042 | } | |
2043 | out << sjdl << endl; | |
b3e07543 | 2044 | out.close(); |
0f389141 | 2045 | TString mergeJDLName = fExecutable; |
2046 | mergeJDLName.ReplaceAll(".sh", "_merge.jdl"); | |
2047 | if (fMergeViaJDL) { | |
2048 | ofstream out1; | |
2049 | out1.open(mergeJDLName.Data(), ios::out); | |
b3e07543 | 2050 | if (out1.bad()) { |
d3b18c4c | 2051 | Error("WriteJDL", "Bad file name: %s", mergeJDLName.Data()); |
0f389141 | 2052 | return kFALSE; |
2053 | } | |
2054 | out1 << sjdl1 << endl; | |
b3e07543 | 2055 | out1.close(); |
2056 | ofstream out2; | |
2057 | TString finalJDL = mergeJDLName; | |
2058 | finalJDL.ReplaceAll(".jdl", "_final.jdl"); | |
2059 | out2.open(finalJDL.Data(), ios::out); | |
2060 | if (out2.bad()) { | |
2061 | Error("WriteJDL", "Bad file name: %s", finalJDL.Data()); | |
2062 | return kFALSE; | |
2063 | } | |
2064 | out2 << sjdl2 << endl; | |
2065 | out2.close(); | |
0f389141 | 2066 | } |
a8739e8a | 2067 | |
2068 | // Copy jdl to grid workspace | |
2069 | if (!copy) { | |
d3b18c4c | 2070 | Info("WriteJDL", "\n##### You may want to review jdl:%s and analysis macro:%s before running in <submit> mode", fJDLName.Data(), fAnalysisMacro.Data()); |
a8739e8a | 2071 | } else { |
d2a409b2 | 2072 | TString locjdl = Form("%s/%s", fGridOutputDir.Data(),fJDLName.Data()); |
0f389141 | 2073 | TString locjdl1 = Form("%s/%s", fGridOutputDir.Data(),mergeJDLName.Data()); |
b3e07543 | 2074 | TString finalJDL = mergeJDLName; |
2075 | finalJDL.ReplaceAll(".jdl", "_final.jdl"); | |
2076 | TString locjdl2 = Form("%s/%s", fGridOutputDir.Data(),finalJDL.Data()); | |
0f389141 | 2077 | if (fProductionMode) { |
b5fe9cba | 2078 | locjdl = Form("%s/%s", workdir.Data(),fJDLName.Data()); |
0f389141 | 2079 | locjdl1 = Form("%s/%s", workdir.Data(),mergeJDLName.Data()); |
b3e07543 | 2080 | locjdl2 = Form("%s/%s", workdir.Data(),finalJDL.Data()); |
0f389141 | 2081 | } |
d2a409b2 | 2082 | if (FileExists(locjdl)) gGrid->Rm(locjdl); |
0f389141 | 2083 | if (FileExists(locjdl1)) gGrid->Rm(locjdl1); |
b3e07543 | 2084 | if (FileExists(locjdl2)) gGrid->Rm(locjdl2); |
d3b18c4c | 2085 | Info("WriteJDL", "\n##### Copying JDL file <%s> to your AliEn output directory", fJDLName.Data()); |
6c395669 | 2086 | // TFile::Cp(Form("file:%s",fJDLName.Data()), Form("alien://%s", locjdl.Data())); |
2087 | if (!copyLocal2Alien("WriteJDL",fJDLName.Data(),locjdl.Data())) | |
2088 | Fatal("","Terminating"); | |
0f389141 | 2089 | if (fMergeViaJDL) { |
b3e07543 | 2090 | Info("WriteJDL", "\n##### Copying merging JDL files <%s> to your AliEn output directory", mergeJDLName.Data()); |
6c395669 | 2091 | // TFile::Cp(Form("file:%s",mergeJDLName.Data()), Form("alien://%s", locjdl1.Data())); |
2092 | // TFile::Cp(Form("file:%s",finalJDL.Data()), Form("alien://%s", locjdl2.Data())); | |
2093 | if (!copyLocal2Alien("WriteJDL",mergeJDLName.Data(),locjdl1.Data())) | |
2094 | Fatal("","Terminating"); | |
2095 | if (!copyLocal2Alien("WriteJDL",finalJDL.Data(),locjdl2.Data())) | |
2096 | Fatal("","Terminating"); | |
0f389141 | 2097 | } |
a8739e8a | 2098 | } |
2099 | return kTRUE; | |
2100 | } | |
2101 | ||
c57f56b7 | 2102 | //______________________________________________________________________________ |
5513444a | 2103 | Bool_t AliAnalysisAlien::FileExists(const char *lfn) |
c57f56b7 | 2104 | { |
2105 | // Returns true if file exists. | |
5513444a | 2106 | if (!gGrid) return kFALSE; |
2ea55496 | 2107 | TString slfn = lfn; |
2108 | slfn.ReplaceAll("alien://",""); | |
2109 | TGridResult *res = gGrid->Ls(slfn); | |
c57f56b7 | 2110 | if (!res) return kFALSE; |
2111 | TMap *map = dynamic_cast<TMap*>(res->At(0)); | |
2112 | if (!map) { | |
2113 | delete res; | |
2114 | return kFALSE; | |
2115 | } | |
2116 | TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("name")); | |
2117 | if (!objs || !objs->GetString().Length()) { | |
2118 | delete res; | |
2119 | return kFALSE; | |
2120 | } | |
2121 | delete res; | |
2122 | return kTRUE; | |
2123 | } | |
2124 | ||
923e2ca5 | 2125 | //______________________________________________________________________________ |
2126 | Bool_t AliAnalysisAlien::DirectoryExists(const char *dirname) | |
2127 | { | |
2128 | // Returns true if directory exists. Can be also a path. | |
2129 | if (!gGrid) return kFALSE; | |
2130 | // Check if dirname is a path | |
2131 | TString dirstripped = dirname; | |
2132 | dirstripped = dirstripped.Strip(); | |
2133 | dirstripped = dirstripped.Strip(TString::kTrailing, '/'); | |
2134 | TString dir = gSystem->BaseName(dirstripped); | |
2135 | dir += "/"; | |
2136 | TString path = gSystem->DirName(dirstripped); | |
2137 | TGridResult *res = gGrid->Ls(path, "-F"); | |
2138 | if (!res) return kFALSE; | |
2139 | TIter next(res); | |
2140 | TMap *map; | |
2141 | TObject *obj; | |
2142 | while ((map=dynamic_cast<TMap*>(next()))) { | |
2143 | obj = map->GetValue("name"); | |
2144 | if (!obj) break; | |
2145 | if (dir == obj->GetName()) { | |
2146 | delete res; | |
2147 | return kTRUE; | |
2148 | } | |
2149 | } | |
2150 | delete res; | |
2151 | return kFALSE; | |
2152 | } | |
2153 | ||
c57f56b7 | 2154 | //______________________________________________________________________________ |
a2f5fc01 | 2155 | void AliAnalysisAlien::CheckDataType(const char *lfn, Bool_t &isCollection, Bool_t &isXml, Bool_t &useTags) |
c57f56b7 | 2156 | { |
2157 | // Check input data type. | |
a2f5fc01 | 2158 | isCollection = kFALSE; |
2159 | isXml = kFALSE; | |
2160 | useTags = kFALSE; | |
c57f56b7 | 2161 | if (!gGrid) { |
2162 | Error("CheckDataType", "No connection to grid"); | |
2163 | return; | |
2164 | } | |
a2f5fc01 | 2165 | isCollection = IsCollection(lfn); |
c57f56b7 | 2166 | TString msg = "\n##### file: "; |
2167 | msg += lfn; | |
a2f5fc01 | 2168 | if (isCollection) { |
c57f56b7 | 2169 | msg += " type: raw_collection;"; |
2170 | // special treatment for collections | |
a2f5fc01 | 2171 | isXml = kFALSE; |
c57f56b7 | 2172 | // check for tag files in the collection |
2173 | TGridResult *res = gGrid->Command(Form("listFilesFromCollection -z -v %s",lfn), kFALSE); | |
2174 | if (!res) { | |
2175 | msg += " using_tags: No (unknown)"; | |
23329835 | 2176 | Info("CheckDataType", "%s", msg.Data()); |
c57f56b7 | 2177 | return; |
2178 | } | |
2179 | const char* typeStr = res->GetKey(0, "origLFN"); | |
2180 | if (!typeStr || !strlen(typeStr)) { | |
2181 | msg += " using_tags: No (unknown)"; | |
23329835 | 2182 | Info("CheckDataType", "%s", msg.Data()); |
c57f56b7 | 2183 | return; |
2184 | } | |
2185 | TString file = typeStr; | |
a2f5fc01 | 2186 | useTags = file.Contains(".tag"); |
2187 | if (useTags) msg += " using_tags: Yes"; | |
c57f56b7 | 2188 | else msg += " using_tags: No"; |
23329835 | 2189 | Info("CheckDataType", "%s", msg.Data()); |
c57f56b7 | 2190 | return; |
2191 | } | |
2192 | TString slfn(lfn); | |
2193 | slfn.ToLower(); | |
a2f5fc01 | 2194 | isXml = slfn.Contains(".xml"); |
2195 | if (isXml) { | |
c57f56b7 | 2196 | // Open xml collection and check if there are tag files inside |
2197 | msg += " type: xml_collection;"; | |
2198 | TGridCollection *coll = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"alien://%s\",1);",lfn)); | |
2199 | if (!coll) { | |
2200 | msg += " using_tags: No (unknown)"; | |
23329835 | 2201 | Info("CheckDataType", "%s", msg.Data()); |
c57f56b7 | 2202 | return; |
2203 | } | |
2204 | TMap *map = coll->Next(); | |
2205 | if (!map) { | |
2206 | msg += " using_tags: No (unknown)"; | |
23329835 | 2207 | Info("CheckDataType", "%s", msg.Data()); |
c57f56b7 | 2208 | return; |
2209 | } | |
2210 | map = (TMap*)map->GetValue(""); | |
2211 | TString file; | |
2212 | if (map && map->GetValue("name")) file = map->GetValue("name")->GetName(); | |
a2f5fc01 | 2213 | useTags = file.Contains(".tag"); |
c57f56b7 | 2214 | delete coll; |
a2f5fc01 | 2215 | if (useTags) msg += " using_tags: Yes"; |
c57f56b7 | 2216 | else msg += " using_tags: No"; |
23329835 | 2217 | Info("CheckDataType", "%s", msg.Data()); |
c57f56b7 | 2218 | return; |
2219 | } | |
a2f5fc01 | 2220 | useTags = slfn.Contains(".tag"); |
c57f56b7 | 2221 | if (slfn.Contains(".root")) msg += " type: root file;"; |
f866cba5 | 2222 | else msg += " type: unknown file;"; |
a2f5fc01 | 2223 | if (useTags) msg += " using_tags: Yes"; |
c57f56b7 | 2224 | else msg += " using_tags: No"; |
23329835 | 2225 | Info("CheckDataType", "%s", msg.Data()); |
c57f56b7 | 2226 | } |
2227 | ||
4e5c5506 | 2228 | //______________________________________________________________________________ |
2229 | void AliAnalysisAlien::EnablePackage(const char *package) | |
2230 | { | |
2231 | // Enables a par file supposed to exist in the current directory. | |
2232 | TString pkg(package); | |
2233 | pkg.ReplaceAll(".par", ""); | |
2234 | pkg += ".par"; | |
2235 | if (gSystem->AccessPathName(pkg)) { | |
ebcdf05e | 2236 | Fatal("EnablePackage", "Package %s not found", pkg.Data()); |
4e5c5506 | 2237 | return; |
2238 | } | |
2239 | if (!TObject::TestBit(AliAnalysisGrid::kUsePars)) | |
2240 | Info("EnablePackage", "AliEn plugin will use .par packages"); | |
2241 | TObject::SetBit(AliAnalysisGrid::kUsePars, kTRUE); | |
2242 | if (!fPackages) { | |
2243 | fPackages = new TObjArray(); | |
2244 | fPackages->SetOwner(); | |
2245 | } | |
2246 | fPackages->Add(new TObjString(pkg)); | |
2247 | } | |
2248 | ||
3bdcb562 | 2249 | //______________________________________________________________________________ |
2250 | TChain *AliAnalysisAlien::GetChainForTestMode(const char *treeName) const | |
2251 | { | |
2252 | // Make a tree from files having the location specified in fFileForTestMode. | |
2253 | // Inspired from JF's CreateESDChain. | |
2254 | if (fFileForTestMode.IsNull()) { | |
2255 | Error("GetChainForTestMode", "For proof test mode please use SetFileForTestMode() pointing to a file that contains data file locations."); | |
2256 | return NULL; | |
2257 | } | |
2258 | if (gSystem->AccessPathName(fFileForTestMode)) { | |
2259 | Error("GetChainForTestMode", "File not found: %s", fFileForTestMode.Data()); | |
2260 | return NULL; | |
2261 | } | |
2262 | // Open the file | |
2263 | ifstream in; | |
2264 | in.open(fFileForTestMode); | |
2265 | Int_t count = 0; | |
2266 | // Read the input list of files and add them to the chain | |
b505f1f8 | 2267 | TString line; |
d6c60197 | 2268 | TString streeName(treeName); |
2269 | if (IsUseMCchain()) streeName = "TE"; | |
2270 | TChain *chain = new TChain(streeName); | |
b505f1f8 | 2271 | TChain *chainFriend = 0; |
d6c60197 | 2272 | if (!fFriendChainName.IsNull()) chainFriend = new TChain(streeName); |
b505f1f8 | 2273 | while (in.good()) |
2274 | { | |
3bdcb562 | 2275 | in >> line; |
ffbe06b9 | 2276 | if (line.IsNull() || line.BeginsWith("#")) continue; |
3bdcb562 | 2277 | if (count++ == fNtestFiles) break; |
2278 | TString esdFile(line); | |
2279 | TFile *file = TFile::Open(esdFile); | |
b505f1f8 | 2280 | if (file && !file->IsZombie()) { |
2281 | chain->Add(esdFile); | |
3bdcb562 | 2282 | file->Close(); |
b505f1f8 | 2283 | if (!fFriendChainName.IsNull()) { |
4b5d9e21 | 2284 | if (esdFile.Index("#") > -1) |
2285 | esdFile.Remove(esdFile.Index("#")); | |
2286 | esdFile = gSystem->DirName(esdFile); | |
2287 | esdFile += "/" + fFriendChainName; | |
b505f1f8 | 2288 | file = TFile::Open(esdFile); |
2289 | if (file && !file->IsZombie()) { | |
2290 | file->Close(); | |
2291 | chainFriend->Add(esdFile); | |
2292 | } else { | |
2293 | Fatal("GetChainForTestMode", "Cannot open friend file: %s", esdFile.Data()); | |
2294 | return 0; | |
2295 | } | |
4b5d9e21 | 2296 | } |
3bdcb562 | 2297 | } else { |
2298 | Error("GetChainforTestMode", "Skipping un-openable file: %s", esdFile.Data()); | |
2299 | } | |
b505f1f8 | 2300 | } |
2301 | in.close(); | |
2302 | if (!chain->GetListOfFiles()->GetEntries()) { | |
3bdcb562 | 2303 | Error("GetChainForTestMode", "No file from %s could be opened", fFileForTestMode.Data()); |
2304 | delete chain; | |
b505f1f8 | 2305 | delete chainFriend; |
3bdcb562 | 2306 | return NULL; |
b505f1f8 | 2307 | } |
3bdcb562 | 2308 | // chain->ls(); |
b505f1f8 | 2309 | if (!fFriendChainName.IsNull()) chain->AddFriend(chainFriend); |
2310 | return chain; | |
3bdcb562 | 2311 | } |
2312 | ||
d2a409b2 | 2313 | //______________________________________________________________________________ |
2314 | const char *AliAnalysisAlien::GetJobStatus(Int_t jobidstart, Int_t lastid, Int_t &nrunning, Int_t &nwaiting, Int_t &nerror, Int_t &ndone) | |
2315 | { | |
2316 | // Get job status for all jobs with jobid>jobidstart. | |
2317 | static char mstatus[20]; | |
2318 | mstatus[0] = '\0'; | |
2319 | nrunning = 0; | |
2320 | nwaiting = 0; | |
2321 | nerror = 0; | |
2322 | ndone = 0; | |
2323 | TGridJobStatusList *list = gGrid->Ps(""); | |
2324 | if (!list) return mstatus; | |
2325 | Int_t nentries = list->GetSize(); | |
2326 | TGridJobStatus *status; | |
2327 | Int_t pid; | |
2328 | for (Int_t ijob=0; ijob<nentries; ijob++) { | |
2329 | status = (TGridJobStatus *)list->At(ijob); | |
8ddad121 | 2330 | pid = gROOT->ProcessLine(Form("atoi(((TAlienJobStatus*)%p)->GetKey(\"queueId\"));", status)); |
d2a409b2 | 2331 | if (pid<jobidstart) continue; |
2332 | if (pid == lastid) { | |
8ddad121 | 2333 | gROOT->ProcessLine(Form("sprintf((char*)%p,((TAlienJobStatus*)%p)->GetKey(\"status\"));",mstatus, status)); |
d2a409b2 | 2334 | } |
2335 | switch (status->GetStatus()) { | |
2336 | case TGridJobStatus::kWAITING: | |
2337 | nwaiting++; break; | |
2338 | case TGridJobStatus::kRUNNING: | |
2339 | nrunning++; break; | |
2340 | case TGridJobStatus::kABORTED: | |
2341 | case TGridJobStatus::kFAIL: | |
2342 | case TGridJobStatus::kUNKNOWN: | |
2343 | nerror++; break; | |
2344 | case TGridJobStatus::kDONE: | |
2345 | ndone++; | |
2346 | } | |
2347 | } | |
2348 | list->Delete(); | |
2349 | delete list; | |
2350 | return mstatus; | |
2351 | } | |
2352 | ||
c57f56b7 | 2353 | //______________________________________________________________________________ |
2354 | Bool_t AliAnalysisAlien::IsCollection(const char *lfn) const | |
2355 | { | |
2356 | // Returns true if file is a collection. Functionality duplicated from | |
2357 | // TAlien::Type() because we don't want to directly depend on TAlien. | |
2358 | if (!gGrid) { | |
2359 | Error("IsCollection", "No connection to grid"); | |
2360 | return kFALSE; | |
2361 | } | |
2362 | TGridResult *res = gGrid->Command(Form("type -z %s",lfn),kFALSE); | |
2363 | if (!res) return kFALSE; | |
2364 | const char* typeStr = res->GetKey(0, "type"); | |
2365 | if (!typeStr || !strlen(typeStr)) return kFALSE; | |
2366 | if (!strcmp(typeStr, "collection")) return kTRUE; | |
2367 | delete res; | |
2368 | return kFALSE; | |
2369 | } | |
2370 | ||
fe2d7fc2 | 2371 | //______________________________________________________________________________ |
2372 | Bool_t AliAnalysisAlien::IsSingleOutput() const | |
2373 | { | |
2374 | // Check if single-ouput option is on. | |
2375 | return (!fOutputSingle.IsNull()); | |
2376 | } | |
2377 | ||
16a4353c | 2378 | //______________________________________________________________________________ |
2379 | void AliAnalysisAlien::Print(Option_t *) const | |
2380 | { | |
2381 | // Print current plugin settings. | |
84fcd93f | 2382 | printf("### AliEn analysis plugin current settings ###\n"); |
d3b18c4c | 2383 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); |
2384 | if (mgr && mgr->IsProofMode()) { | |
2385 | TString proofType = "= PLUGIN IN PROOF MODE ON CLUSTER:_________________"; | |
2386 | if (TestBit(AliAnalysisGrid::kTest)) | |
2387 | proofType = "= PLUGIN IN PROOF LITE MODE ON CLUSTER:____________"; | |
2388 | printf("%s %s\n", proofType.Data(), fProofCluster.Data()); | |
2389 | if (!fProofDataSet.IsNull()) | |
2390 | printf("= Requested data set:___________________________ %s\n", fProofDataSet.Data()); | |
2391 | if (fProofReset==1) | |
2392 | printf("= Soft reset signal will be send to master______ CHANGE BEHAVIOR AFTER COMPLETION\n"); | |
2393 | if (fProofReset>1) | |
2394 | printf("= Hard reset signal will be send to master______ CHANGE BEHAVIOR AFTER COMPLETION\n"); | |
2395 | if (!fRootVersionForProof.IsNull()) | |
2396 | printf("= ROOT version requested________________________ %s\n", fRootVersionForProof.Data()); | |
2397 | else | |
2398 | printf("= ROOT version requested________________________ default\n"); | |
2399 | printf("= AliRoot version requested_____________________ %s\n", fAliROOTVersion.Data()); | |
2400 | if (!fAliRootMode.IsNull()) | |
2401 | printf("= Requested AliRoot mode________________________ %s\n", fAliRootMode.Data()); | |
2402 | if (fNproofWorkers) | |
2403 | printf("= Number of PROOF workers limited to____________ %d\n", fNproofWorkers); | |
2404 | if (fNproofWorkersPerSlave) | |
2405 | printf("= Maximum number of workers per slave___________ %d\n", fNproofWorkersPerSlave); | |
2406 | if (TestSpecialBit(kClearPackages)) | |
2407 | printf("= ClearPackages requested...\n"); | |
2408 | if (fIncludePath.Data()) | |
2409 | printf("= Include path for runtime task compilation: ___ %s\n", fIncludePath.Data()); | |
2410 | printf("= Additional libs to be loaded or souces to be compiled runtime: <%s>\n",fAdditionalLibs.Data()); | |
2411 | if (fPackages && fPackages->GetEntries()) { | |
2412 | TIter next(fPackages); | |
2413 | TObject *obj; | |
2414 | TString list; | |
2415 | while ((obj=next())) list += obj->GetName(); | |
2416 | printf("= Par files to be used: ________________________ %s\n", list.Data()); | |
2417 | } | |
2418 | if (TestSpecialBit(kProofConnectGrid)) | |
2419 | printf("= Requested PROOF connection to grid\n"); | |
2420 | return; | |
2421 | } | |
e1c22e21 | 2422 | printf("= OverwriteMode:________________________________ %d\n", fOverwriteMode); |
2423 | if (fOverwriteMode) { | |
2424 | printf("***** NOTE: Overwrite mode will overwrite the input generated datasets and partial results from previous analysis. \ | |
2425 | \n***** To disable, use: plugin->SetOverwriteMode(kFALSE);\n"); | |
2426 | } | |
348be253 | 2427 | printf("= Copy files to grid: __________________________ %s\n", (IsUseCopy())?"YES":"NO"); |
2428 | printf("= Check if files can be copied to grid: ________ %s\n", (IsCheckCopy())?"YES":"NO"); | |
84fcd93f | 2429 | printf("= Production mode:______________________________ %d\n", fProductionMode); |
2430 | printf("= Version of API requested: ____________________ %s\n", fAPIVersion.Data()); | |
2431 | printf("= Version of ROOT requested: ___________________ %s\n", fROOTVersion.Data()); | |
2432 | printf("= Version of AliRoot requested: ________________ %s\n", fAliROOTVersion.Data()); | |
16a4353c | 2433 | if (fUser.Length()) |
84fcd93f | 2434 | printf("= User running the plugin: _____________________ %s\n", fUser.Data()); |
2435 | printf("= Grid workdir relative to user $HOME: _________ %s\n", fGridWorkingDir.Data()); | |
2436 | printf("= Grid output directory relative to workdir: ___ %s\n", fGridOutputDir.Data()); | |
2437 | printf("= Data base directory path requested: __________ %s\n", fGridDataDir.Data()); | |
2438 | printf("= Data search pattern: _________________________ %s\n", fDataPattern.Data()); | |
2439 | printf("= Input data format: ___________________________ %s\n", fInputFormat.Data()); | |
16a4353c | 2440 | if (fRunNumbers.Length()) |
84fcd93f | 2441 | printf("= Run numbers to be processed: _________________ %s\n", fRunNumbers.Data()); |
16a4353c | 2442 | if (fRunRange[0]) |
74013535 | 2443 | printf("= Run range to be processed: ___________________ %d-%d\n", fRunRange[0], fRunRange[1]); |
16a4353c | 2444 | if (!fRunRange[0] && !fRunNumbers.Length()) { |
2445 | TIter next(fInputFiles); | |
2446 | TObject *obj; | |
2447 | TString list; | |
2448 | while ((obj=next())) list += obj->GetName(); | |
84fcd93f | 2449 | printf("= Input files to be processed: _________________ %s\n", list.Data()); |
16a4353c | 2450 | } |
2451 | if (TestBit(AliAnalysisGrid::kTest)) | |
84fcd93f | 2452 | printf("= Number of input files used in test mode: _____ %d\n", fNtestFiles); |
2453 | printf("= List of output files to be registered: _______ %s\n", fOutputFiles.Data()); | |
2454 | printf("= List of outputs going to be archived: ________ %s\n", fOutputArchive.Data()); | |
2455 | printf("= List of outputs that should not be merged: ___ %s\n", fMergeExcludes.Data()); | |
37d21c01 | 2456 | printf("= List of outputs that should not be registered: %s\n", fRegisterExcludes.Data()); |
d3b18c4c | 2457 | printf("= List of outputs produced during Terminate: ___ %s\n", fTerminateFiles.Data()); |
84fcd93f | 2458 | printf("=====================================================================\n"); |
2459 | printf("= Job price: ___________________________________ %d\n", fPrice); | |
2460 | printf("= Time to live (TTL): __________________________ %d\n", fTTL); | |
2461 | printf("= Max files per subjob: ________________________ %d\n", fSplitMaxInputFileNumber); | |
16a4353c | 2462 | if (fMaxInitFailed>0) |
84fcd93f | 2463 | printf("= Max number of subjob fails to kill: __________ %d\n", fMaxInitFailed); |
16a4353c | 2464 | if (fMasterResubmitThreshold>0) |
84fcd93f | 2465 | printf("= Resubmit master job if failed subjobs >_______ %d\n", fMasterResubmitThreshold); |
149d288c | 2466 | printf("= Number of replicas for the output files_______ %d\n", fNreplicas); |
319593fb | 2467 | if (fNrunsPerMaster>0) |
84fcd93f | 2468 | printf("= Number of runs per master job: _______________ %d\n", fNrunsPerMaster); |
2469 | printf("= Number of files in one chunk to be merged: ___ %d\n", fMaxMergeFiles); | |
b5b9dee8 | 2470 | printf("= Name of the generated execution script: ______ %s\n", fExecutable.Data()); |
2471 | printf("= Executable command: __________________________ %s\n", fExecutableCommand.Data()); | |
16a4353c | 2472 | if (fArguments.Length()) |
84fcd93f | 2473 | printf("= Arguments for the execution script: __________ %s\n",fArguments.Data()); |
631c0b05 | 2474 | if (fExecutableArgs.Length()) |
2475 | printf("= Arguments after macro name in executable______ %s\n",fExecutableArgs.Data()); | |
84fcd93f | 2476 | printf("= Name of the generated analysis macro: ________ %s\n",fAnalysisMacro.Data()); |
2477 | printf("= User analysis files to be deployed: __________ %s\n",fAnalysisSource.Data()); | |
2478 | printf("= Additional libs to be loaded or souces to be compiled runtime: <%s>\n",fAdditionalLibs.Data()); | |
2479 | printf("= Master jobs split mode: ______________________ %s\n",fSplitMode.Data()); | |
16a4353c | 2480 | if (fDatasetName) |
84fcd93f | 2481 | printf("= Custom name for the dataset to be created: ___ %s\n", fDatasetName.Data()); |
2482 | printf("= Name of the generated JDL: ___________________ %s\n", fJDLName.Data()); | |
16a4353c | 2483 | if (fIncludePath.Data()) |
84fcd93f | 2484 | printf("= Include path for runtime task compilation: ___ %s\n", fIncludePath.Data()); |
16a4353c | 2485 | if (fCloseSE.Length()) |
84fcd93f | 2486 | printf("= Force job outputs to storage element: ________ %s\n", fCloseSE.Data()); |
16a4353c | 2487 | if (fFriendChainName.Length()) |
84fcd93f | 2488 | printf("= Open friend chain file on worker: ____________ %s\n", fFriendChainName.Data()); |
d3b18c4c | 2489 | if (fPackages && fPackages->GetEntries()) { |
16a4353c | 2490 | TIter next(fPackages); |
2491 | TObject *obj; | |
2492 | TString list; | |
2493 | while ((obj=next())) list += obj->GetName(); | |
84fcd93f | 2494 | printf("= Par files to be used: ________________________ %s\n", list.Data()); |
16a4353c | 2495 | } |
2496 | } | |
2497 | ||
c57f56b7 | 2498 | //______________________________________________________________________________ |
2499 | void AliAnalysisAlien::SetDefaults() | |
2500 | { | |
2501 | // Set default values for everything. What cannot be filled will be left empty. | |
2502 | if (fGridJDL) delete fGridJDL; | |
2503 | fGridJDL = (TGridJDL*)gROOT->ProcessLine("new TAlienJDL()"); | |
0f389141 | 2504 | fMergingJDL = (TGridJDL*)gROOT->ProcessLine("new TAlienJDL()"); |
c57f56b7 | 2505 | fPrice = 1; |
2506 | fTTL = 30000; | |
2507 | fSplitMaxInputFileNumber = 100; | |
2508 | fMaxInitFailed = 0; | |
2509 | fMasterResubmitThreshold = 0; | |
bb885a9e | 2510 | fNtestFiles = 10; |
149d288c | 2511 | fNreplicas = 2; |
a8739e8a | 2512 | fRunRange[0] = 0; |
2513 | fRunRange[1] = 0; | |
8e3bd06a | 2514 | fRunPrefix = "%d"; |
319593fb | 2515 | fNrunsPerMaster = 1; |
16a4353c | 2516 | fMaxMergeFiles = 100; |
c57f56b7 | 2517 | fRunNumbers = ""; |
2518 | fExecutable = "analysis.sh"; | |
5aa94dc3 | 2519 | fExecutableCommand = "root -b -q -x"; |
c57f56b7 | 2520 | fArguments = ""; |
631c0b05 | 2521 | fExecutableArgs = ""; |
c57f56b7 | 2522 | fAnalysisMacro = "myAnalysis.C"; |
2523 | fAnalysisSource = ""; | |
2524 | fAdditionalLibs = ""; | |
2525 | fSplitMode = "se"; | |
2526 | fAPIVersion = ""; | |
2527 | fROOTVersion = ""; | |
2528 | fAliROOTVersion = ""; | |
2529 | fUser = ""; // Your alien user name | |
2530 | fGridWorkingDir = ""; | |
2531 | fGridDataDir = ""; // Can be like: /alice/sim/PDC_08a/LHC08c9/ | |
2532 | fDataPattern = "*AliESDs.root"; // Can be like: *AliESDs.root, */pass1/*AliESDs.root, ... | |
0df6ccf2 | 2533 | fFriendChainName = ""; |
c57f56b7 | 2534 | fGridOutputDir = "output"; |
b83f84f0 | 2535 | fOutputArchive = "log_archive.zip:std*@disk=1 root_archive.zip:*.root@disk=2"; |
c57f56b7 | 2536 | fOutputFiles = ""; // Like "AliAODs.root histos.root" |
2537 | fInputFormat = "xml-single"; | |
2538 | fJDLName = "analysis.jdl"; | |
c6cb3634 | 2539 | fJobTag = "Automatically generated analysis JDL"; |
bb885a9e | 2540 | fMergeExcludes = ""; |
0f389141 | 2541 | fMergeViaJDL = 0; |
348be253 | 2542 | SetUseCopy(kTRUE); |
2543 | SetCheckCopy(kTRUE); | |
149d288c | 2544 | SetDefaultOutputs(kTRUE); |
e1c22e21 | 2545 | fOverwriteMode = 1; |
c57f56b7 | 2546 | } |
2547 | ||
0f389141 | 2548 | //______________________________________________________________________________ |
b3e07543 | 2549 | Bool_t AliAnalysisAlien::CheckMergedFiles(const char *filename, const char *aliendir, Int_t nperchunk, const char *jdl) |
0f389141 | 2550 | { |
b3e07543 | 2551 | // Checks current merge stage, makes xml for the next stage, counts number of files, submits next stage. |
2552 | // First check if the result is already in the output directory. | |
2553 | if (FileExists(Form("%s/%s",aliendir,filename))) { | |
2554 | printf("Final merged results found. Not merging again.\n"); | |
7c2cd90a | 2555 | return kFALSE; |
2556 | } | |
b3e07543 | 2557 | // Now check the last stage done. |
2558 | Int_t stage = 0; | |
2559 | while (1) { | |
2560 | if (!FileExists(Form("%s/Stage_%d.xml",aliendir, stage+1))) break; | |
2561 | stage++; | |
2562 | } | |
2563 | // Next stage of merging | |
2564 | stage++; | |
2565 | TString pattern = "*root_archive.zip"; | |
2566 | if (stage>1) pattern = Form("Stage_%d/*root_archive.zip", stage-1); | |
2567 | TGridResult *res = gGrid->Command(Form("find -x Stage_%d %s %s", stage, aliendir, pattern.Data())); | |
2568 | if (res) delete res; | |
2569 | // Write standard output to file | |
2570 | gROOT->ProcessLine(Form("gGrid->Stdout(); > %s", Form("Stage_%d.xml",stage))); | |
2571 | // Count the number of files inside | |
2572 | ifstream ifile; | |
2573 | ifile.open(Form("Stage_%d.xml",stage)); | |
2574 | if (!ifile.good()) { | |
2575 | ::Error("CheckMergedFiles", "Could not redirect result of the find command to file %s", Form("Stage_%d.xml",stage)); | |
7c2cd90a | 2576 | return kFALSE; |
b3e07543 | 2577 | } |
2578 | TString line; | |
2579 | Int_t nfiles = 0; | |
2580 | while (!ifile.eof()) { | |
2581 | ifile >> line; | |
2582 | if (line.Contains("/event")) nfiles++; | |
7c2cd90a | 2583 | } |
b3e07543 | 2584 | ifile.close(); |
2585 | if (!nfiles) { | |
2586 | ::Error("CheckMergedFiles", "Cannot start Stage_%d merging since Stage_%d did not produced yet output", stage, stage-1); | |
2587 | return kFALSE; | |
2588 | } else { | |
2589 | printf("=== Stage_%d produced %d files\n", stage-1, nfiles); | |
7ae54d70 | 2590 | } |
b3e07543 | 2591 | // Copy the file in the output directory |
2592 | printf("===> Copying collection %s in the output directory %s\n", Form("Stage_%d.xml",stage), aliendir); | |
43d5e2dc | 2593 | // TFile::Cp(Form("Stage_%d.xml",stage), Form("alien://%s/Stage_%d.xml",aliendir,stage)); |
6c395669 | 2594 | if (!copyLocal2Alien("CheckMergedFiles", Form("Stage_%d.xml",stage), |
2595 | Form("%s/Stage_%d.xml",aliendir,stage))) Fatal("","Terminating"); | |
b3e07543 | 2596 | // Check if this is the last stage to be done. |
2597 | Bool_t laststage = (nfiles<nperchunk); | |
2598 | if (fMaxMergeStages && stage>=fMaxMergeStages) laststage = kTRUE; | |
2599 | if (laststage) { | |
2600 | printf("### Submiting final merging stage %d\n", stage); | |
2601 | TString finalJDL = jdl; | |
2602 | finalJDL.ReplaceAll(".jdl", "_final.jdl"); | |
03335324 | 2603 | TString query = Form("submit %s %s %d", finalJDL.Data(), aliendir, stage); |
b3e07543 | 2604 | Int_t jobId = SubmitSingleJob(query); |
2605 | if (!jobId) return kFALSE; | |
2606 | } else { | |
2607 | printf("### Submiting merging stage %d\n", stage); | |
03335324 | 2608 | TString query = Form("submit %s %s %d", jdl, aliendir, stage); |
b3e07543 | 2609 | Int_t jobId = SubmitSingleJob(query); |
2610 | if (!jobId) return kFALSE; | |
7c2cd90a | 2611 | } |
b3e07543 | 2612 | return kTRUE; |
2613 | } | |
7c2cd90a | 2614 | |
105631b5 | 2615 | //______________________________________________________________________________ |
2616 | AliAnalysisManager *AliAnalysisAlien::LoadAnalysisManager(const char *fname) | |
2617 | { | |
2618 | // Loat the analysis manager from a file. | |
2619 | TFile *file = TFile::Open(fname); | |
2620 | if (!file) { | |
2621 | ::Error("LoadAnalysisManager", "Cannot open file %s", fname); | |
2622 | return 0; | |
2623 | } | |
2624 | TIter nextkey(file->GetListOfKeys()); | |
2625 | AliAnalysisManager *mgr = 0; | |
2626 | TKey *key; | |
2627 | while ((key=(TKey*)nextkey())) { | |
2628 | if (!strcmp(key->GetClassName(), "AliAnalysisManager")) | |
2629 | mgr = (AliAnalysisManager*)file->Get(key->GetName()); | |
2630 | } | |
2631 | if (!mgr) | |
2632 | ::Error("LoadAnalysisManager", "No analysis manager found in file %s", fname); | |
2633 | return mgr; | |
2634 | } | |
2635 | ||
7c2cd90a | 2636 | //______________________________________________________________________________ |
2637 | Int_t AliAnalysisAlien::SubmitSingleJob(const char *query) | |
2638 | { | |
2639 | // Submits a single job corresponding to the query and returns job id. If 0 submission failed. | |
2640 | if (!gGrid) return 0; | |
2641 | printf("=> %s ------> ",query); | |
2642 | TGridResult *res = gGrid->Command(query); | |
2643 | if (!res) return 0; | |
2644 | TString jobId = res->GetKey(0,"jobId"); | |
2645 | delete res; | |
2646 | if (jobId.IsNull()) { | |
2647 | printf("submission failed. Reason:\n"); | |
2648 | gGrid->Stdout(); | |
2649 | gGrid->Stderr(); | |
2650 | ::Error("SubmitSingleJob", "Your query %s could not be submitted", query); | |
2651 | return 0; | |
2652 | } | |
2653 | printf(" Job id: %s\n", jobId.Data()); | |
2654 | return atoi(jobId); | |
2655 | } | |
2656 | ||
ec5acdce | 2657 | //______________________________________________________________________________ |
2658 | Bool_t AliAnalysisAlien::MergeInfo(const char *output, const char *collection) | |
2659 | { | |
2660 | // Merges a collection of output files using concatenation. | |
d66aa2a9 | 2661 | TString scoll(collection); |
2662 | if (!scoll.Contains(".xml")) return kFALSE; | |
ec5acdce | 2663 | TGridCollection *coll = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\");", collection)); |
2664 | if (!coll) { | |
2665 | ::Error("MergeInfo", "Input XML %s collection empty.", collection); | |
2666 | return kFALSE; | |
2667 | } | |
2668 | // Iterate grid collection | |
2669 | TString outtmp; | |
2670 | Bool_t merged = kFALSE; | |
2671 | Int_t ifile = 0; | |
2672 | while (coll->Next()) { | |
2673 | TString fname = gSystem->DirName(coll->GetTURL()); | |
2674 | fname += "/"; | |
2675 | fname += output; | |
2676 | outtmp = Form("%d_%s", ifile, output); | |
2677 | if (!TFile::Cp(fname, outtmp)) { | |
2678 | ::Error("MergeInfo", "Could not copy %s", fname.Data()); | |
2679 | continue; | |
2680 | } | |
2681 | ifile++; | |
2682 | if (ifile<2) { | |
2683 | gSystem->Exec(Form("cp %s lastmerged", outtmp.Data())); | |
2684 | continue; | |
2685 | } | |
2686 | gSystem->Exec(Form("cat lastmerged %s > tempmerged", outtmp.Data())); | |
2687 | gSystem->Exec("cp tempmerged lastmerged"); | |
2688 | } | |
2689 | if (ifile) { | |
2690 | gSystem->Exec(Form("cp lastmerged %s", output)); | |
2691 | gSystem->Exec(Form("rm tempmerged lastmerged *_%s", output)); | |
2692 | merged = kTRUE; | |
2693 | } | |
2694 | return merged; | |
2695 | } | |
2696 | ||
7c2cd90a | 2697 | //______________________________________________________________________________ |
b3e07543 | 2698 | Bool_t AliAnalysisAlien::MergeOutput(const char *output, const char *basedir, Int_t nmaxmerge, Int_t stage) |
7c2cd90a | 2699 | { |
b3e07543 | 2700 | // Merge given output files from basedir. Basedir can be an alien output directory |
2701 | // but also an xml file with root_archive.zip locations. The file merger will merge nmaxmerge | |
2702 | // files in a group (ignored for xml input). Merging can be done in stages: | |
2703 | // stage=0 : will merge all existing files in a single stage, supporting resume if run locally | |
2704 | // stage=1 : works with an xml of all root_archive.zip in the output directory | |
2705 | // stage>1 : works with an xml of all root_archive.zip in the Stage_<n-1> directory | |
a2f5fc01 | 2706 | TString outputFile = output; |
0f389141 | 2707 | TString command; |
a2f5fc01 | 2708 | TString outputChunk; |
2709 | TString previousChunk = ""; | |
b3e07543 | 2710 | TObjArray *listoffiles = new TObjArray(); |
2711 | // listoffiles->SetOwner(); | |
a2f5fc01 | 2712 | Int_t countChunk = 0; |
2713 | Int_t countZero = nmaxmerge; | |
0f389141 | 2714 | Bool_t merged = kTRUE; |
d66aa2a9 | 2715 | Bool_t isGrid = kTRUE; |
a2f5fc01 | 2716 | Int_t index = outputFile.Index("@"); |
2717 | if (index > 0) outputFile.Remove(index); | |
7c2cd90a | 2718 | TString inputFile = outputFile; |
b3e07543 | 2719 | TString sbasedir = basedir; |
2720 | if (sbasedir.Contains(".xml")) { | |
2721 | // Merge files pointed by the xml - ignore nmaxmerge and set ichunk to 0 | |
2722 | nmaxmerge = 9999999; | |
2723 | TGridCollection *coll = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\");", basedir)); | |
2724 | if (!coll) { | |
2725 | ::Error("MergeOutput", "Input XML collection empty."); | |
2726 | return kFALSE; | |
2727 | } | |
2728 | // Iterate grid collection | |
2729 | while (coll->Next()) { | |
2730 | TString fname = gSystem->DirName(coll->GetTURL()); | |
2731 | fname += "/"; | |
2732 | fname += inputFile; | |
2733 | listoffiles->Add(new TNamed(fname.Data(),"")); | |
2734 | } | |
ffbe06b9 | 2735 | } else if (sbasedir.Contains(".txt")) { |
d66aa2a9 | 2736 | // The file having the .txt extension is expected to contain a list of |
2737 | // folders where the output files will be looked. For alien folders, | |
2738 | // the full folder LFN is expected (starting with alien://) | |
ffbe06b9 | 2739 | // Assume lfn's on each line |
2740 | TString line; | |
2741 | ifstream in; | |
2742 | in.open(sbasedir); | |
d66aa2a9 | 2743 | if (in.fail()) { |
2744 | ::Error("MergeOutput", "File %s cannot be opened. Merging stopped." ,sbasedir.Data()); | |
2745 | return kTRUE; | |
2746 | } | |
ffbe06b9 | 2747 | Int_t nfiles = 0; |
2748 | while (in.good()) { | |
2749 | in >> line; | |
2750 | if (line.IsNull() || line.BeginsWith("#")) continue; | |
d66aa2a9 | 2751 | line.Strip(); |
2752 | if (!line.Contains("alien:")) isGrid = kFALSE; | |
2753 | line += "/"; | |
2754 | line += outputFile; | |
ffbe06b9 | 2755 | nfiles++; |
2756 | listoffiles->Add(new TNamed(line.Data(),"")); | |
2757 | } | |
d66aa2a9 | 2758 | in.close(); |
ffbe06b9 | 2759 | if (!nfiles) { |
2760 | ::Error("MergeOutput","Input file %s contains no files to be merged\n", sbasedir.Data()); | |
2761 | delete listoffiles; | |
2762 | return kFALSE; | |
2763 | } | |
b3e07543 | 2764 | } else { |
2765 | command = Form("find %s/ *%s", basedir, inputFile.Data()); | |
2766 | printf("command: %s\n", command.Data()); | |
2767 | TGridResult *res = gGrid->Command(command); | |
2768 | if (!res) { | |
2769 | ::Error("MergeOutput","No result for the find command\n"); | |
2770 | delete listoffiles; | |
2771 | return kFALSE; | |
2772 | } | |
2773 | TIter nextmap(res); | |
2774 | TMap *map = 0; | |
2775 | while ((map=(TMap*)nextmap())) { | |
2776 | TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("turl")); | |
2777 | if (!objs || !objs->GetString().Length()) { | |
2778 | // Nothing found - skip this output | |
2779 | delete res; | |
2780 | delete listoffiles; | |
2781 | return kFALSE; | |
2782 | } | |
2783 | listoffiles->Add(new TNamed(objs->GetName(),"")); | |
2784 | } | |
2785 | delete res; | |
2786 | } | |
2787 | if (!listoffiles->GetEntries()) { | |
7c2cd90a | 2788 | ::Error("MergeOutput","No result for the find command\n"); |
b3e07543 | 2789 | delete listoffiles; |
0f389141 | 2790 | return kFALSE; |
2791 | } | |
2792 | ||
2793 | TFileMerger *fm = 0; | |
b3e07543 | 2794 | TIter next0(listoffiles); |
2795 | TObjArray *listoffilestmp = new TObjArray(); | |
2796 | listoffilestmp->SetOwner(); | |
2797 | TObject *nextfile; | |
2798 | TString snextfile; | |
2799 | // Keep only the files at upper level | |
2800 | Int_t countChar = 0; | |
2801 | while ((nextfile=next0())) { | |
2802 | snextfile = nextfile->GetName(); | |
2803 | Int_t crtCount = snextfile.CountChar('/'); | |
2804 | if (nextfile == listoffiles->First()) countChar = crtCount; | |
2805 | if (crtCount < countChar) countChar = crtCount; | |
2806 | } | |
2807 | next0.Reset(); | |
2808 | while ((nextfile=next0())) { | |
2809 | snextfile = nextfile->GetName(); | |
2810 | Int_t crtCount = snextfile.CountChar('/'); | |
2811 | if (crtCount > countChar) { | |
2812 | delete nextfile; | |
2813 | continue; | |
2814 | } | |
2815 | listoffilestmp->Add(nextfile); | |
2816 | } | |
2817 | delete listoffiles; | |
2818 | listoffiles = listoffilestmp; // Now contains 'good' files | |
2819 | listoffiles->Print(); | |
2820 | TIter next(listoffiles); | |
7c2cd90a | 2821 | // Check if there is a merge operation to resume. Works only for stage 0 or 1. |
a2f5fc01 | 2822 | outputChunk = outputFile; |
2823 | outputChunk.ReplaceAll(".root", "_*.root"); | |
0f389141 | 2824 | // Check for existent temporary merge files |
e1c22e21 | 2825 | // Check overwrite mode and remove previous partial results if needed |
7c2cd90a | 2826 | // Preserve old merging functionality for stage 0. |
2827 | if (stage==0) { | |
2828 | if (!gSystem->Exec(Form("ls %s 2>/dev/null", outputChunk.Data()))) { | |
2829 | while (1) { | |
2830 | // Skip as many input files as in a chunk | |
2ea55496 | 2831 | for (Int_t counter=0; counter<nmaxmerge; counter++) { |
b3e07543 | 2832 | nextfile = next(); |
2833 | if (!nextfile) { | |
2ea55496 | 2834 | ::Error("MergeOutput", "Mismatch found. Please remove partial merged files from local dir."); |
b3e07543 | 2835 | delete listoffiles; |
2ea55496 | 2836 | return kFALSE; |
2837 | } | |
b3e07543 | 2838 | snextfile = nextfile->GetName(); |
7c2cd90a | 2839 | } |
2840 | outputChunk = outputFile; | |
2841 | outputChunk.ReplaceAll(".root", Form("_%04d.root", countChunk)); | |
2842 | countChunk++; | |
2843 | if (gSystem->AccessPathName(outputChunk)) continue; | |
2844 | // Merged file with chunks up to <countChunk> found | |
2845 | ::Info("MergeOutput", "Resume merging of <%s> from <%s>\n", outputFile.Data(), outputChunk.Data()); | |
2846 | previousChunk = outputChunk; | |
2847 | break; | |
2848 | } | |
2849 | } | |
2850 | countZero = nmaxmerge; | |
2851 | ||
b3e07543 | 2852 | while ((nextfile=next())) { |
2853 | snextfile = nextfile->GetName(); | |
2ea55496 | 2854 | // Loop 'find' results and get next LFN |
7c2cd90a | 2855 | if (countZero == nmaxmerge) { |
2856 | // First file in chunk - create file merger and add previous chunk if any. | |
d66aa2a9 | 2857 | fm = new TFileMerger(isGrid); |
7c2cd90a | 2858 | fm->SetFastMethod(kTRUE); |
2859 | if (previousChunk.Length()) fm->AddFile(previousChunk.Data()); | |
2860 | outputChunk = outputFile; | |
2861 | outputChunk.ReplaceAll(".root", Form("_%04d.root", countChunk)); | |
2862 | } | |
2863 | // If last file found, put merged results in the output file | |
b3e07543 | 2864 | if (nextfile == listoffiles->Last()) outputChunk = outputFile; |
7c2cd90a | 2865 | // Add file to be merged and decrement chunk counter. |
b3e07543 | 2866 | fm->AddFile(snextfile); |
7c2cd90a | 2867 | countZero--; |
b3e07543 | 2868 | if (countZero==0 || nextfile == listoffiles->Last()) { |
7c2cd90a | 2869 | if (!fm->GetMergeList() || !fm->GetMergeList()->GetSize()) { |
2870 | // Nothing found - skip this output | |
2871 | ::Warning("MergeOutput", "No <%s> files found.", inputFile.Data()); | |
b3e07543 | 2872 | merged = kFALSE; |
2873 | break; | |
7c2cd90a | 2874 | } |
2875 | fm->OutputFile(outputChunk); | |
2876 | // Merge the outputs, then go to next chunk | |
2877 | if (!fm->Merge()) { | |
2878 | ::Error("MergeOutput", "Could not merge all <%s> files", outputFile.Data()); | |
b3e07543 | 2879 | merged = kFALSE; |
2880 | break; | |
7c2cd90a | 2881 | } else { |
2882 | ::Info("MergeOutputs", "\n##### Merged %d output files to <%s>", fm->GetMergeList()->GetSize(), outputChunk.Data()); | |
2883 | gSystem->Unlink(previousChunk); | |
2884 | } | |
b3e07543 | 2885 | if (nextfile == listoffiles->Last()) break; |
7c2cd90a | 2886 | countChunk++; |
2887 | countZero = nmaxmerge; | |
2888 | previousChunk = outputChunk; | |
0f389141 | 2889 | } |
0f389141 | 2890 | } |
b3e07543 | 2891 | delete listoffiles; |
2892 | delete fm; | |
7c2cd90a | 2893 | return merged; |
2894 | } | |
2895 | // Merging stage different than 0. | |
2896 | // Move to the begining of the requested chunk. | |
d66aa2a9 | 2897 | fm = new TFileMerger(isGrid); |
7c2cd90a | 2898 | fm->SetFastMethod(kTRUE); |
b3e07543 | 2899 | while ((nextfile=next())) fm->AddFile(nextfile->GetName()); |
2900 | delete listoffiles; | |
7c2cd90a | 2901 | if (!fm->GetMergeList() || !fm->GetMergeList()->GetSize()) { |
2902 | // Nothing found - skip this output | |
2903 | ::Warning("MergeOutput", "No <%s> files found.", inputFile.Data()); | |
2904 | delete fm; | |
2905 | return kFALSE; | |
2906 | } | |
b3e07543 | 2907 | fm->OutputFile(outputFile); |
7c2cd90a | 2908 | // Merge the outputs |
2909 | if (!fm->Merge()) { | |
2910 | ::Error("MergeOutput", "Could not merge all <%s> files", outputFile.Data()); | |
2911 | delete fm; | |
2912 | return kFALSE; | |
2913 | } else { | |
b3e07543 | 2914 | ::Info("MergeOutput", "\n##### Merged %d output files to <%s>", fm->GetMergeList()->GetSize(), outputFile.Data()); |
0f389141 | 2915 | } |
7c2cd90a | 2916 | delete fm; |
2917 | return kTRUE; | |
0f389141 | 2918 | } |
2919 | ||
c57f56b7 | 2920 | //______________________________________________________________________________ |
2921 | Bool_t AliAnalysisAlien::MergeOutputs() | |
2922 | { | |
2923 | // Merge analysis outputs existing in the AliEn space. | |
2924 | if (TestBit(AliAnalysisGrid::kTest)) return kTRUE; | |
2925 | if (TestBit(AliAnalysisGrid::kOffline)) return kFALSE; | |
2926 | if (!Connect()) { | |
2927 | Error("MergeOutputs", "Cannot merge outputs without grid connection. Terminate will NOT be executed"); | |
2928 | return kFALSE; | |
0f389141 | 2929 | } |
c9e8f7fd | 2930 | if (fMergeViaJDL) { |
2931 | if (!TestBit(AliAnalysisGrid::kMerge)) { | |
2932 | Info("MergeOutputs", "### Re-run with <MergeViaJDL> option in terminate mode of the plugin to submit merging jobs ###"); | |
2933 | return kFALSE; | |
2934 | } | |
2935 | if (fProductionMode) { | |
2936 | Info("MergeOutputs", "### Merging will be submitted by LPM manager... ###"); | |
2937 | return kFALSE; | |
2938 | } | |
0f389141 | 2939 | Info("MergeOutputs", "Submitting merging JDL"); |
a03be957 | 2940 | if (!SubmitMerging()) return kFALSE; |
0f389141 | 2941 | Info("MergeOutputs", "### Re-run with <MergeViaJDL> off to collect results after merging jobs are done ###"); |
c9e8f7fd | 2942 | Info("MergeOutputs", "### The Terminate() method is executed by the merging jobs"); |
001cb79e | 2943 | return kFALSE; |
c57f56b7 | 2944 | } |
2945 | // Get the output path | |
dc030a24 | 2946 | if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data()); |
923e2ca5 | 2947 | if (!DirectoryExists(fGridOutputDir)) { |
c57f56b7 | 2948 | Error("MergeOutputs", "Grid output directory %s not found. Terminate() will NOT be executed", fGridOutputDir.Data()); |
2949 | return kFALSE; | |
2950 | } | |
2951 | if (!fOutputFiles.Length()) { | |
2952 | Error("MergeOutputs", "No output file names defined. Are you running the right AliAnalysisAlien configuration ?"); | |
2953 | return kFALSE; | |
0f389141 | 2954 | } |
2955 | // Check if fast read option was requested | |
e1c22e21 | 2956 | Info("MergeOutputs", "Started local merging of output files from: alien://%s \ |
2957 | \n======= overwrite mode = %d", fGridOutputDir.Data(), (Int_t)fOverwriteMode); | |
0f389141 | 2958 | if (fFastReadOption) { |
d3339be3 | 2959 | Warning("MergeOutputs", "You requested FastRead option. Using xrootd flags to reduce timeouts. This may skip some files that could be accessed ! \ |
2960 | \n+++ NOTE: To disable this option, use: plugin->SetFastReadOption(kFALSE)"); | |
b3e07543 | 2961 | gEnv->SetValue("XNet.ConnectTimeout",50); |
2962 | gEnv->SetValue("XNet.RequestTimeout",50); | |
0f389141 | 2963 | gEnv->SetValue("XNet.MaxRedirectCount",2); |
b3e07543 | 2964 | gEnv->SetValue("XNet.ReconnectTimeout",50); |
0f389141 | 2965 | gEnv->SetValue("XNet.FirstConnectMaxCnt",1); |
c57f56b7 | 2966 | } |
e8b839ab | 2967 | // Make sure we change the temporary directory |
2968 | gSystem->Setenv("TMPDIR", gSystem->pwd()); | |
70c52cf3 | 2969 | // Set temporary compilation directory to current one |
2970 | gSystem->SetBuildDir(gSystem->pwd(), kTRUE); | |
149d288c | 2971 | TObjArray *list = fOutputFiles.Tokenize(","); |
c57f56b7 | 2972 | TIter next(list); |
2973 | TObjString *str; | |
a2f5fc01 | 2974 | TString outputFile; |
c57f56b7 | 2975 | Bool_t merged = kTRUE; |
2976 | while((str=(TObjString*)next())) { | |
a2f5fc01 | 2977 | outputFile = str->GetString(); |
2978 | Int_t index = outputFile.Index("@"); | |
2979 | if (index > 0) outputFile.Remove(index); | |
2980 | TString outputChunk = outputFile; | |
2981 | outputChunk.ReplaceAll(".root", "_*.root"); | |
319593fb | 2982 | // Skip already merged outputs |
a2f5fc01 | 2983 | if (!gSystem->AccessPathName(outputFile)) { |
e1c22e21 | 2984 | if (fOverwriteMode) { |
a2f5fc01 | 2985 | Info("MergeOutputs", "Overwrite mode. Existing file %s was deleted.", outputFile.Data()); |
2986 | gSystem->Unlink(outputFile); | |
2987 | if (!gSystem->Exec(Form("ls %s 2>/dev/null", outputChunk.Data()))) { | |
e1c22e21 | 2988 | Info("MergeOutput", "Overwrite mode: partial merged files %s will removed", |
a2f5fc01 | 2989 | outputChunk.Data()); |
2990 | gSystem->Exec(Form("rm -f %s", outputChunk.Data())); | |
e1c22e21 | 2991 | } |
2992 | } else { | |
a2f5fc01 | 2993 | Info("MergeOutputs", "Output file <%s> found. Not merging again.", outputFile.Data()); |
e1c22e21 | 2994 | continue; |
2995 | } | |
2996 | } else { | |
a2f5fc01 | 2997 | if (!gSystem->Exec(Form("ls %s 2>/dev/null", outputChunk.Data()))) { |
e1c22e21 | 2998 | Info("MergeOutput", "Overwrite mode: partial merged files %s will removed", |
a2f5fc01 | 2999 | outputChunk.Data()); |
3000 | gSystem->Exec(Form("rm -f %s", outputChunk.Data())); | |
e1c22e21 | 3001 | } |
3002 | } | |
37d21c01 | 3003 | if (fMergeExcludes.Contains(outputFile.Data()) || |
3004 | fRegisterExcludes.Contains(outputFile.Data())) continue; | |
16a4353c | 3005 | // Perform a 'find' command in the output directory, looking for registered outputs |
a2f5fc01 | 3006 | merged = MergeOutput(outputFile, fGridOutputDir, fMaxMergeFiles); |
0f389141 | 3007 | if (!merged) { |
3008 | Error("MergeOutputs", "Terminate() will NOT be executed"); | |
3009 | return kFALSE; | |
ff07ec61 | 3010 | } |
3011 | TFile *fileOpened = (TFile*)gROOT->GetListOfFiles()->FindObject(outputFile); | |
3012 | if (fileOpened) fileOpened->Close(); | |
c57f56b7 | 3013 | } |
0f389141 | 3014 | return kTRUE; |
c57f56b7 | 3015 | } |
3016 | ||
bb885a9e | 3017 | //______________________________________________________________________________ |
3018 | void AliAnalysisAlien::SetDefaultOutputs(Bool_t flag) | |
3019 | { | |
3020 | // Use the output files connected to output containers from the analysis manager | |
3021 | // rather than the files defined by SetOutputFiles | |
3022 | if (flag && !TObject::TestBit(AliAnalysisGrid::kDefaultOutputs)) | |
205b201f | 3023 | Info("SetDefaultOutputs", "Plugin will use the output files taken from analysis manager"); |
bb885a9e | 3024 | TObject::SetBit(AliAnalysisGrid::kDefaultOutputs, flag); |
3025 | } | |
3026 | ||
149d288c | 3027 | //______________________________________________________________________________ |
3028 | void AliAnalysisAlien::SetOutputFiles(const char *list) | |
3029 | { | |
3030 | // Manually set the output files list. | |
3031 | // Removes duplicates. Not allowed if default outputs are not disabled. | |
3032 | if (TObject::TestBit(AliAnalysisGrid::kDefaultOutputs)) { | |
3033 | Fatal("SetOutputFiles", "You have to explicitly call SetDefaultOutputs(kFALSE) to manually set output files."); | |
3034 | return; | |
3035 | } | |
3036 | Info("SetOutputFiles", "Output file list is set manually - you are on your own."); | |
3037 | fOutputFiles = ""; | |
3038 | TString slist = list; | |
3039 | if (slist.Contains("@")) Warning("SetOutputFiles","The plugin does not allow explicit SE's. Please use: SetNumberOfReplicas() instead."); | |
3040 | TObjArray *arr = slist.Tokenize(" "); | |
3041 | TObjString *os; | |
3042 | TIter next(arr); | |
3043 | TString sout; | |
3044 | while ((os=(TObjString*)next())) { | |
3045 | sout = os->GetString(); | |
3046 | if (sout.Index("@")>0) sout.Remove(sout.Index("@")); | |
3047 | if (fOutputFiles.Contains(sout)) continue; | |
3048 | if (!fOutputFiles.IsNull()) fOutputFiles += ","; | |
3049 | fOutputFiles += sout; | |
3050 | } | |
3051 | delete arr; | |
f790bc1b | 3052 | } |
149d288c | 3053 | |
3054 | //______________________________________________________________________________ | |
3055 | void AliAnalysisAlien::SetOutputArchive(const char *list) | |
3056 | { | |
3057 | // Manually set the output archive list. Free text - you are on your own... | |
3058 | // Not allowed if default outputs are not disabled. | |
3059 | if (TObject::TestBit(AliAnalysisGrid::kDefaultOutputs)) { | |
3060 | Fatal("SetOutputArchive", "You have to explicitly call SetDefaultOutputs(kFALSE) to manually set the output archives."); | |
3061 | return; | |
3062 | } | |
3063 | Info("SetOutputArchive", "Output archive is set manually - you are on your own."); | |
3064 | fOutputArchive = list; | |
3065 | } | |
3066 | ||
3067 | //______________________________________________________________________________ | |
3068 | void AliAnalysisAlien::SetPreferedSE(const char */*se*/) | |
3069 | { | |
3070 | // Setting a prefered output SE is not allowed anymore. | |
3071 | Warning("SetPreferedSE", "Setting a preferential SE is not allowed anymore via the plugin. Use SetNumberOfReplicas() and SetDefaultOutputs()"); | |
3072 | } | |
3073 | ||
28ce6c9c | 3074 | //______________________________________________________________________________ |
3075 | void AliAnalysisAlien::SetProofParameter(const char *pname, const char *value) | |
3076 | { | |
3077 | // Set some PROOF special parameter. | |
3078 | TPair *pair = dynamic_cast<TPair*>(fProofParam.FindObject(pname)); | |
3079 | if (pair) { | |
3080 | TObject *old = pair->Key(); | |
3081 | TObject *val = pair->Value(); | |
3082 | fProofParam.Remove(old); | |
3083 | delete old; | |
3084 | delete val; | |
3085 | } | |
3086 | fProofParam.Add(new TObjString(pname), new TObjString(value)); | |
3087 | } | |
3088 | ||
3089 | //______________________________________________________________________________ | |
3090 | const char *AliAnalysisAlien::GetProofParameter(const char *pname) const | |
3091 | { | |
3092 | // Returns a special PROOF parameter. | |
3093 | TPair *pair = dynamic_cast<TPair*>(fProofParam.FindObject(pname)); | |
3094 | if (!pair) return 0; | |
3095 | return pair->Value()->GetName(); | |
3096 | } | |
3097 | ||
5513444a | 3098 | //______________________________________________________________________________ |
3099 | Bool_t AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEntry*/) | |
c57f56b7 | 3100 | { |
3101 | // Start remote grid analysis. | |
3bdcb562 | 3102 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); |
3103 | Bool_t testMode = TestBit(AliAnalysisGrid::kTest); | |
3104 | if (!mgr || !mgr->IsInitialized()) { | |
3105 | Error("StartAnalysis", "You need an initialized analysis manager for this"); | |
3106 | return kFALSE; | |
3107 | } | |
3108 | // Are we in PROOF mode ? | |
3109 | if (mgr->IsProofMode()) { | |
baa34407 | 3110 | if (testMode) Info("StartAnalysis", "##### Starting PROOF analysis with Proof Lite via the plugin #####"); |
3111 | else Info("StartAnalysis", "##### Starting PROOF analysis on cluster <%s> via the plugin #####", fProofCluster.Data()); | |
3bdcb562 | 3112 | if (fProofCluster.IsNull()) { |
3113 | Error("StartAnalysis", "You need to specify the proof cluster name via SetProofCluster"); | |
3114 | return kFALSE; | |
3115 | } | |
3116 | if (fProofDataSet.IsNull() && !testMode) { | |
3117 | Error("StartAnalysis", "You need to specify a dataset using SetProofDataSet()"); | |
3118 | return kFALSE; | |
3119 | } | |
3120 | // Set the needed environment | |
3121 | gEnv->SetValue("XSec.GSI.DelegProxy","2"); | |
3122 | // Do we need to reset PROOF ? The success of the Reset operation cannot be checked | |
3123 | if (fProofReset && !testMode) { | |
3124 | if (fProofReset==1) { | |
3125 | Info("StartAnalysis", "Sending soft reset signal to proof cluster %s", fProofCluster.Data()); | |
3126 | gROOT->ProcessLine(Form("TProof::Reset(\"%s\", kFALSE);", fProofCluster.Data())); | |
3127 | } else { | |
3128 | Info("StartAnalysis", "Sending hard reset signal to proof cluster %s", fProofCluster.Data()); | |
3129 | gROOT->ProcessLine(Form("TProof::Reset(\"%s\", kTRUE);", fProofCluster.Data())); | |
3130 | } | |
3131 | Info("StartAnalysis", "Stopping the analysis. Please use SetProofReset(0) to resume."); | |
3132 | return kFALSE; | |
3133 | } | |
baa34407 | 3134 | |
3135 | if (!testMode) { | |
3136 | // Check if there is an old active session | |
3137 | Long_t nsessions = gROOT->ProcessLine(Form("TProof::Mgr(\"%s\")->QuerySessions(\"\")->GetEntries();", fProofCluster.Data())); | |
3138 | if (nsessions) { | |
3139 | Error("StartAnalysis","You have to reset your old session first\n"); | |
3140 | return kFALSE; | |
3141 | } | |
53911ca6 | 3142 | } |
3bdcb562 | 3143 | // Do we need to change the ROOT version ? The success of this cannot be checked. |
3144 | if (!fRootVersionForProof.IsNull() && !testMode) { | |
3145 | gROOT->ProcessLine(Form("TProof::Mgr(\"%s\")->SetROOTVersion(\"%s\");", | |
3146 | fProofCluster.Data(), fRootVersionForProof.Data())); | |
3147 | } | |
3148 | // Connect to PROOF and check the status | |
3149 | Long_t proof = 0; | |
27734f0e | 3150 | TString sworkers; |
3151 | if (fNproofWorkersPerSlave) sworkers = Form("workers=%dx", fNproofWorkersPerSlave); | |
3152 | else if (fNproofWorkers) sworkers = Form("workers=%d", fNproofWorkers); | |
3bdcb562 | 3153 | if (!testMode) { |
27734f0e | 3154 | if (!sworkers.IsNull()) |
3155 | proof = gROOT->ProcessLine(Form("TProof::Open(\"%s\", \"%s\");", fProofCluster.Data(), sworkers.Data())); | |
3bdcb562 | 3156 | else |
3157 | proof = gROOT->ProcessLine(Form("TProof::Open(\"%s\");", fProofCluster.Data())); | |
3158 | } else { | |
3159 | proof = gROOT->ProcessLine("TProof::Open(\"\");"); | |
3160 | if (!proof) { | |
3161 | Error("StartAnalysis", "Could not start PROOF in test mode"); | |
3162 | return kFALSE; | |
3163 | } | |
3164 | } | |
3165 | if (!proof) { | |
3166 | Error("StartAnalysis", "Could not connect to PROOF cluster <%s>", fProofCluster.Data()); | |
3167 | return kFALSE; | |
3168 | } | |
27734f0e | 3169 | if (fNproofWorkersPerSlave*fNproofWorkers > 0) |
3170 | gROOT->ProcessLine(Form("gProof->SetParallel(%d);", fNproofWorkers)); | |
28ce6c9c | 3171 | // Set proof special parameters if any |
3172 | TIter nextpp(&fProofParam); | |
3173 | TObject *proofparam; | |
3174 | while ((proofparam=nextpp())) { | |
3175 | TString svalue = GetProofParameter(proofparam->GetName()); | |
3176 | gROOT->ProcessLine(Form("gProof->SetParameter(\"%s\",%s);", proofparam->GetName(), svalue.Data())); | |
3177 | } | |
3bdcb562 | 3178 | // Is dataset existing ? |
3179 | if (!testMode) { | |
3180 | TString dataset = fProofDataSet; | |
3181 | Int_t index = dataset.Index("#"); | |
3182 | if (index>=0) dataset.Remove(index); | |
830acc4c | 3183 | // if (!gROOT->ProcessLine(Form("gProof->ExistsDataSet(\"%s\");",fProofDataSet.Data()))) { |
3184 | // Error("StartAnalysis", "Dataset %s not existing", fProofDataSet.Data()); | |
3185 | // return kFALSE; | |
3186 | // } | |
3187 | // Info("StartAnalysis", "Dataset %s found", dataset.Data()); | |
3bdcb562 | 3188 | } |
3189 | // Is ClearPackages() needed ? | |
3190 | if (TestSpecialBit(kClearPackages)) { | |
3191 | Info("StartAnalysis", "ClearPackages signal sent to PROOF. Use SetClearPackages(kFALSE) to reset this."); | |
3192 | gROOT->ProcessLine("gProof->ClearPackages();"); | |
3193 | } | |
3194 | // Is a given aliroot mode requested ? | |
3195 | TList optionsList; | |
1ac846e9 | 3196 | TString parLibs; |
830acc4c | 3197 | if (!fAliRootMode.IsNull()) { |
3bdcb562 | 3198 | TString alirootMode = fAliRootMode; |
3199 | if (alirootMode == "default") alirootMode = ""; | |
3200 | Info("StartAnalysis", "You are requesting AliRoot mode: %s", fAliRootMode.Data()); | |
3201 | optionsList.SetOwner(); | |
3202 | optionsList.Add(new TNamed("ALIROOT_MODE", alirootMode.Data())); | |
3203 | // Check the additional libs to be loaded | |
3204 | TString extraLibs; | |
1ac846e9 | 3205 | Bool_t parMode = kFALSE; |
dc1ffbcb | 3206 | if (!alirootMode.IsNull()) extraLibs = "ANALYSIS:OADB:ANALYSISalice"; |
3bdcb562 | 3207 | // Parse the extra libs for .so |
3208 | if (fAdditionalLibs.Length()) { | |
3209 | TObjArray *list = fAdditionalLibs.Tokenize(" "); | |
3210 | TIter next(list); | |
3211 | TObjString *str; | |
1ac846e9 | 3212 | while((str=(TObjString*)next())) { |
3213 | if (str->GetString().Contains(".so")) { | |
3214 | if (parMode) { | |
3215 | Warning("StartAnalysis", "Plugin does not support loading libs after par files in PROOF mode. Library %s and following will not load on workers", str->GetName()); | |
3216 | break; | |
3217 | } | |
3218 | TString stmp = str->GetName(); | |
3219 | if (stmp.BeginsWith("lib")) stmp.Remove(0,3); | |
3220 | stmp.ReplaceAll(".so",""); | |
3221 | if (!extraLibs.IsNull()) extraLibs += ":"; | |
3222 | extraLibs += stmp; | |
3223 | continue; | |
3224 | } | |
3225 | if (str->GetString().Contains(".par")) { | |
3226 | // The first par file found in the list will not allow any further .so | |
3227 | parMode = kTRUE; | |
3228 | if (!parLibs.IsNull()) parLibs += ":"; | |
3229 | parLibs += str->GetName(); | |
3230 | continue; | |
3231 | } | |
3bdcb562 | 3232 | } |
3233 | if (list) delete list; | |
3234 | } | |
dc030a24 | 3235 | if (!extraLibs.IsNull()) { |
3236 | Info("StartAnalysis", "Adding extra libs: %s",extraLibs.Data()); | |
3237 | optionsList.Add(new TNamed("ALIROOT_EXTRA_LIBS",extraLibs.Data())); | |
3238 | } | |
830acc4c | 3239 | // Check extra includes |
3240 | if (!fIncludePath.IsNull()) { | |
3241 | TString includePath = fIncludePath; | |
3242 | includePath.ReplaceAll(" ",":"); | |
dc030a24 | 3243 | includePath.ReplaceAll("$ALICE_ROOT/",""); |
3244 | includePath.ReplaceAll("${ALICE_ROOT}/",""); | |
8ddad121 | 3245 | includePath.ReplaceAll("-I",""); |
dc030a24 | 3246 | includePath.Remove(TString::kTrailing, ':'); |
830acc4c | 3247 | Info("StartAnalysis", "Adding extra includes: %s",includePath.Data()); |
3248 | optionsList.Add(new TNamed("ALIROOT_EXTRA_INCLUDES",includePath.Data())); | |
3249 | } | |
27734f0e | 3250 | // Check if connection to grid is requested |
3251 | if (TestSpecialBit(kProofConnectGrid)) | |
3252 | optionsList.Add(new TNamed("ALIROOT_ENABLE_ALIEN", "1")); | |
830acc4c | 3253 | // Enable AliRoot par |
3254 | if (testMode) { | |
3255 | // Enable proof lite package | |
3256 | TString alirootLite = gSystem->ExpandPathName("$ALICE_ROOT/ANALYSIS/macros/AliRootProofLite.par"); | |
3257 | for (Int_t i=0; i<optionsList.GetSize(); i++) { | |
3258 | TNamed *obj = (TNamed*)optionsList.At(i); | |
3259 | printf("%s %s\n", obj->GetName(), obj->GetTitle()); | |
3260 | } | |
3261 | if (!gROOT->ProcessLine(Form("gProof->UploadPackage(\"%s\");",alirootLite.Data())) | |
8ddad121 | 3262 | && !gROOT->ProcessLine(Form("gProof->EnablePackage(\"%s\", (TList*)%p);",alirootLite.Data(),&optionsList))) { |
830acc4c | 3263 | Info("StartAnalysis", "AliRootProofLite enabled"); |
3264 | } else { | |
3265 | Error("StartAnalysis", "There was an error trying to enable package AliRootProofLite.par"); | |
3266 | return kFALSE; | |
3267 | } | |
3268 | } else { | |
dc030a24 | 3269 | if ( ! fAliROOTVersion.IsNull() ) { |
3270 | if (gROOT->ProcessLine(Form("gProof->EnablePackage(\"VO_ALICE@AliRoot::%s\", (TList*)%p, kTRUE);", | |
3271 | fAliROOTVersion.Data(), &optionsList))) { | |
3272 | Error("StartAnalysis", "There was an error trying to enable package VO_ALICE@AliRoot::%s", fAliROOTVersion.Data()); | |
3273 | return kFALSE; | |
3274 | } | |
3275 | } | |
27734f0e | 3276 | } |
1ac846e9 | 3277 | // Enable first par files from fAdditionalLibs |
3278 | if (!parLibs.IsNull()) { | |
3279 | TObjArray *list = parLibs.Tokenize(":"); | |
3280 | TIter next(list); | |
3281 | TObjString *package; | |
3282 | while((package=(TObjString*)next())) { | |
40501bb7 | 3283 | TString spkg = package->GetName(); |
3284 | spkg.ReplaceAll(".par", ""); | |
3285 | gSystem->Exec(TString::Format("rm -rf %s", spkg.Data())); | |
b50a41c3 | 3286 | if (!gROOT->ProcessLine(Form("gProof->UploadPackage(\"%s\");", package->GetName()))) { |
4f136f18 | 3287 | TString enablePackage = (testMode)?Form("gProof->EnablePackage(\"%s\",kFALSE);", package->GetName()):Form("gProof->EnablePackage(\"%s\",kTRUE);", package->GetName()); |
3288 | if (gROOT->ProcessLine(enablePackage)) { | |
1ac846e9 | 3289 | Error("StartAnalysis", "There was an error trying to enable package %s", package->GetName()); |
3290 | return kFALSE; | |
3291 | } | |
3292 | } else { | |
3293 | Error("StartAnalysis", "There was an error trying to upload package %s", package->GetName()); | |
3294 | return kFALSE; | |
3295 | } | |
3296 | } | |
3297 | if (list) delete list; | |
3298 | } | |
3bdcb562 | 3299 | } else { |
3300 | if (fAdditionalLibs.Contains(".so") && !testMode) { | |
3301 | Error("StartAnalysis", "You request additional libs to be loaded but did not enabled any AliRoot mode. Please refer to: \ | |
3302 | \n http://aaf.cern.ch/node/83 and use a parameter for SetAliRootMode()"); | |
3303 | return kFALSE; | |
3304 | } | |
3305 | } | |
3306 | // Enable par files if requested | |
3307 | if (fPackages && fPackages->GetEntries()) { | |
3308 | TIter next(fPackages); | |
3309 | TObject *package; | |
3310 | while ((package=next())) { | |
1ac846e9 | 3311 | // Skip packages already enabled |
3312 | if (parLibs.Contains(package->GetName())) continue; | |
40501bb7 | 3313 | TString spkg = package->GetName(); |
3314 | spkg.ReplaceAll(".par", ""); | |
3315 | gSystem->Exec(TString::Format("rm -rf %s", spkg.Data())); | |
dc030a24 | 3316 | if (!gROOT->ProcessLine(Form("gProof->UploadPackage(\"%s\");", package->GetName()))) { |
27734f0e | 3317 | if (gROOT->ProcessLine(Form("gProof->EnablePackage(\"%s\",kTRUE);", package->GetName()))) { |
3bdcb562 | 3318 | Error("StartAnalysis", "There was an error trying to enable package %s", package->GetName()); |
3319 | return kFALSE; | |
3320 | } | |
3321 | } else { | |
3322 | Error("StartAnalysis", "There was an error trying to upload package %s", package->GetName()); | |
3323 | return kFALSE; | |
3324 | } | |
3325 | } | |
3326 | } | |
3327 | // Do we need to load analysis source files ? | |
3328 | // NOTE: don't load on client since this is anyway done by the user to attach his task. | |
3329 | if (fAnalysisSource.Length()) { | |
3330 | TObjArray *list = fAnalysisSource.Tokenize(" "); | |
3331 | TIter next(list); | |
3332 | TObjString *str; | |
3333 | while((str=(TObjString*)next())) { | |
3334 | gROOT->ProcessLine(Form("gProof->Load(\"%s+g\", kTRUE);", str->GetName())); | |
dc030a24 | 3335 | } |
3bdcb562 | 3336 | if (list) delete list; |
3337 | } | |
830acc4c | 3338 | if (testMode) { |
3339 | // Register dataset to proof lite. | |
3340 | if (fFileForTestMode.IsNull()) { | |
3341 | Error("GetChainForTestMode", "For proof test mode please use SetFileForTestMode() pointing to a file that contains data file locations."); | |
3342 | return kFALSE; | |
3343 | } | |
3344 | if (gSystem->AccessPathName(fFileForTestMode)) { | |
3345 | Error("GetChainForTestMode", "File not found: %s", fFileForTestMode.Data()); | |
3346 | return kFALSE; | |
3347 | } | |
3348 | TFileCollection *coll = new TFileCollection(); | |
3349 | coll->AddFromFile(fFileForTestMode); | |
8ddad121 | 3350 | gROOT->ProcessLine(Form("gProof->RegisterDataSet(\"test_collection\", (TFileCollection*)%p, \"OV\");", coll)); |
27734f0e | 3351 | gROOT->ProcessLine("gProof->ShowDataSets()"); |
830acc4c | 3352 | } |
3bdcb562 | 3353 | return kTRUE; |
3354 | } | |
c57f56b7 | 3355 | |
43da816a | 3356 | // Check if output files have to be taken from the analysis manager |
3357 | if (TestBit(AliAnalysisGrid::kDefaultOutputs)) { | |
f790bc1b | 3358 | // Add output files and AOD files |
3359 | fOutputFiles = GetListOfFiles("outaod"); | |
c07b9ce2 | 3360 | // Add extra files registered to the analysis manager |
f790bc1b | 3361 | TString extra = GetListOfFiles("ext"); |
3362 | if (!extra.IsNull()) { | |
149d288c | 3363 | extra.ReplaceAll(".root", "*.root"); |
f790bc1b | 3364 | if (!fOutputFiles.IsNull()) fOutputFiles += ","; |
149d288c | 3365 | fOutputFiles += extra; |
84fcd93f | 3366 | } |
149d288c | 3367 | // Compose the output archive. |
b83f84f0 | 3368 | fOutputArchive = "log_archive.zip:std*@disk=1 "; |
ec5acdce | 3369 | if (mgr->IsCollectThroughput()) |
3370 | fOutputArchive += Form("root_archive.zip:%s,*.stat,*%s@disk=%d",fOutputFiles.Data(),mgr->GetFileInfoLog(),fNreplicas); | |
3371 | else | |
3372 | fOutputArchive += Form("root_archive.zip:%s,*.stat@disk=%d",fOutputFiles.Data(),fNreplicas); | |
43da816a | 3373 | } |
f7b1cbc2 | 3374 | // if (!fCloseSE.Length()) fCloseSE = gSystem->Getenv("alien_CLOSE_SE"); |
c57f56b7 | 3375 | if (TestBit(AliAnalysisGrid::kOffline)) { |
3376 | Info("StartAnalysis","\n##### OFFLINE MODE ##### Files to be used in GRID are produced but not copied \ | |
3377 | \n there nor any job run. You can revise the JDL and analysis \ | |
3378 | \n macro then run the same in \"submit\" mode."); | |
3379 | } else if (TestBit(AliAnalysisGrid::kTest)) { | |
3380 | Info("StartAnalysis","\n##### LOCAL MODE ##### Your analysis will be run locally on a subset of the requested \ | |
3381 | \n dataset."); | |
3382 | } else if (TestBit(AliAnalysisGrid::kSubmit)) { | |
3383 | Info("StartAnalysis","\n##### SUBMIT MODE ##### Files required by your analysis are copied to your grid working \ | |
3384 | \n space and job submitted."); | |
3385 | } else if (TestBit(AliAnalysisGrid::kMerge)) { | |
3386 | Info("StartAnalysis","\n##### MERGE MODE ##### The registered outputs of the analysis will be merged"); | |
0f389141 | 3387 | if (fMergeViaJDL) CheckInputData(); |
5513444a | 3388 | return kTRUE; |
c57f56b7 | 3389 | } else { |
3390 | Info("StartAnalysis","\n##### FULL ANALYSIS MODE ##### Producing needed files and submitting your analysis job..."); | |
3391 | } | |
3392 | ||
348be253 | 3393 | Print(); |
c57f56b7 | 3394 | if (!Connect()) { |
3395 | Error("StartAnalysis", "Cannot start grid analysis without grid connection"); | |
5513444a | 3396 | return kFALSE; |
16a4353c | 3397 | } |
d3b18c4c | 3398 | if (IsCheckCopy() && gGrid) CheckFileCopy(gGrid->GetHomeDirectory()); |
c57f56b7 | 3399 | if (!CheckInputData()) { |
3400 | Error("StartAnalysis", "There was an error in preprocessing your requested input data"); | |
5513444a | 3401 | return kFALSE; |
c57f56b7 | 3402 | } |
d3339be3 | 3403 | if (!CreateDataset(fDataPattern)) { |
3404 | TString serror; | |
3405 | if (!fRunNumbers.Length() && !fRunRange[0]) serror = Form("path to data directory: <%s>", fGridDataDir.Data()); | |
3406 | if (fRunNumbers.Length()) serror = "run numbers"; | |
3407 | if (fRunRange[0]) serror = Form("run range [%d, %d]", fRunRange[0], fRunRange[1]); | |
3408 | serror += Form("\n or data pattern <%s>", fDataPattern.Data()); | |
3409 | Error("StartAnalysis", "No data to process. Please fix %s in your plugin configuration.", serror.Data()); | |
3410 | return kFALSE; | |
3411 | } | |
21ca8e59 | 3412 | WriteAnalysisFile(); |
c57f56b7 | 3413 | WriteAnalysisMacro(); |
3414 | WriteExecutable(); | |
3415 | WriteValidationScript(); | |
0f389141 | 3416 | if (fMergeViaJDL) { |
3417 | WriteMergingMacro(); | |
3418 | WriteMergeExecutable(); | |
3419 | WriteValidationScript(kTRUE); | |
3420 | } | |
5513444a | 3421 | if (!CreateJDL()) return kFALSE; |
3422 | if (TestBit(AliAnalysisGrid::kOffline)) return kFALSE; | |
3bdcb562 | 3423 | if (testMode) { |
c57f56b7 | 3424 | // Locally testing the analysis |
3425 | Info("StartAnalysis", "\n_______________________________________________________________________ \ | |
3426 | \n Running analysis script in a daughter shell as on a worker node \ | |
3427 | \n_______________________________________________________________________"); | |
149d288c | 3428 | TObjArray *list = fOutputFiles.Tokenize(","); |
c57f56b7 | 3429 | TIter next(list); |
3430 | TObjString *str; | |
a2f5fc01 | 3431 | TString outputFile; |
c57f56b7 | 3432 | while((str=(TObjString*)next())) { |
a2f5fc01 | 3433 | outputFile = str->GetString(); |
3434 | Int_t index = outputFile.Index("@"); | |
3435 | if (index > 0) outputFile.Remove(index); | |
3436 | if (!gSystem->AccessPathName(outputFile)) gSystem->Exec(Form("rm %s", outputFile.Data())); | |
c57f56b7 | 3437 | } |
3438 | delete list; | |
3439 | gSystem->Exec(Form("bash %s 2>stderr", fExecutable.Data())); | |
f50e4bc8 | 3440 | gSystem->Exec(Form("bash %s",fValidationScript.Data())); |
c57f56b7 | 3441 | // gSystem->Exec("cat stdout"); |
5513444a | 3442 | return kFALSE; |
c57f56b7 | 3443 | } |
5513444a | 3444 | // Check if submitting is managed by LPM manager |
a3e84053 | 3445 | if (fProductionMode) { |
7ac61826 | 3446 | //TString prodfile = fJDLName; |
3447 | //prodfile.ReplaceAll(".jdl", ".prod"); | |
3448 | //WriteProductionFile(prodfile); | |
5513444a | 3449 | Info("StartAnalysis", "Job submitting is managed by LPM. Rerun in terminate mode after jobs finished."); |
3450 | return kFALSE; | |
3451 | } | |
a8739e8a | 3452 | // Submit AliEn job(s) |
d2a409b2 | 3453 | gGrid->Cd(fGridOutputDir); |
a8739e8a | 3454 | TGridResult *res; |
c57f56b7 | 3455 | TString jobID = ""; |
d2a409b2 | 3456 | if (!fRunNumbers.Length() && !fRunRange[0]) { |
dd74a515 | 3457 | // Submit a given xml or a set of runs |
a8739e8a | 3458 | res = gGrid->Command(Form("submit %s", fJDLName.Data())); |
84fcd93f | 3459 | printf("*************************** %s\n",Form("submit %s", fJDLName.Data())); |
a8739e8a | 3460 | if (res) { |
3461 | const char *cjobId = res->GetKey(0,"jobId"); | |
3462 | if (!cjobId) { | |
a03be957 | 3463 | gGrid->Stdout(); |
3464 | gGrid->Stderr(); | |
a8739e8a | 3465 | Error("StartAnalysis", "Your JDL %s could not be submitted", fJDLName.Data()); |
5513444a | 3466 | return kFALSE; |
a8739e8a | 3467 | } else { |
3468 | Info("StartAnalysis", "\n_______________________________________________________________________ \ | |
3469 | \n##### Your JDL %s was successfully submitted. \nTHE JOB ID IS: %s \ | |
3470 | \n_______________________________________________________________________", | |
3471 | fJDLName.Data(), cjobId); | |
3472 | jobID = cjobId; | |
3473 | } | |
3474 | delete res; | |
a03be957 | 3475 | } else { |
3476 | Error("StartAnalysis", "No grid result after submission !!! Bailing out..."); | |
3477 | return kFALSE; | |
a8739e8a | 3478 | } |
3479 | } else { | |
d2a409b2 | 3480 | // Submit for a range of enumeration of runs. |
a03be957 | 3481 | if (!Submit()) return kFALSE; |
c57f56b7 | 3482 | } |
a8739e8a | 3483 | |
d88e4159 | 3484 | if (fDropToShell) { |
3485 | Info("StartAnalysis", "\n#### STARTING AN ALIEN SHELL FOR YOU. EXIT WHEN YOUR JOB %s HAS FINISHED. #### \ | |
3486 | \n You may exit at any time and terminate the job later using the option <terminate> \ | |
3487 | \n ##################################################################################", jobID.Data()); | |
3488 | gSystem->Exec("aliensh"); | |
3489 | } else { | |
3490 | Info("StartAnalysis", "\n#### SUBMITTED JOB %s TO ALIEN QUEUE #### \ | |
3491 | \n Remember to terminate the job later using the option <terminate> \ | |
3492 | \n ##################################################################################", jobID.Data()); | |
3493 | } | |
5513444a | 3494 | return kTRUE; |
c57f56b7 | 3495 | } |
3496 | ||
f790bc1b | 3497 | //______________________________________________________________________________ |
3498 | const char *AliAnalysisAlien::GetListOfFiles(const char *type) | |
3499 | { | |
3500 | // Get a comma-separated list of output files of the requested type. | |
3501 | // Type can be (case unsensitive): | |
3502 | // aod - list of aod files (std, extensions and filters) | |
3503 | // out - list of output files connected to containers (but not aod's or extras) | |
3504 | // ext - list of extra files registered to the manager | |
3505 | // ter - list of files produced in terminate | |
3506 | static TString files; | |
3507 | files = ""; | |
3508 | TString stype = type; | |
3509 | stype.ToLower(); | |
3510 | TString aodfiles, extra; | |
3511 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
3512 | if (!mgr) { | |
3513 | ::Error("GetListOfFiles", "Cannot call this without analysis manager"); | |
3514 | return files.Data(); | |
3515 | } | |
3516 | if (mgr->GetOutputEventHandler()) { | |
3517 | aodfiles = mgr->GetOutputEventHandler()->GetOutputFileName(); | |
3518 | TString extraaod = mgr->GetOutputEventHandler()->GetExtraOutputs(); | |
3519 | if (!extraaod.IsNull()) { | |
3520 | aodfiles += ","; | |
3521 | aodfiles += extraaod; | |
3522 | } | |
3523 | } | |
3524 | if (stype.Contains("aod")) { | |
3525 | files = aodfiles; | |
3526 | if (stype == "aod") return files.Data(); | |
3527 | } | |
3528 | // Add output files that are not in the list of AOD files | |
3529 | TString outputfiles = ""; | |
3530 | TIter next(mgr->GetOutputs()); | |
3531 | AliAnalysisDataContainer *output; | |
3532 | const char *filename = 0; | |
3533 | while ((output=(AliAnalysisDataContainer*)next())) { | |
3534 | filename = output->GetFileName(); | |
3535 | if (!(strcmp(filename, "default"))) continue; | |
3536 | if (outputfiles.Contains(filename)) continue; | |
3537 | if (aodfiles.Contains(filename)) continue; | |
3538 | if (!outputfiles.IsNull()) outputfiles += ","; | |
3539 | outputfiles += filename; | |
3540 | } | |
3541 | if (stype.Contains("out")) { | |
3542 | if (!files.IsNull()) files += ","; | |
3543 | files += outputfiles; | |
3544 | if (stype == "out") return files.Data(); | |
3545 | } | |
3546 | // Add extra files registered to the analysis manager | |
3547 | TString sextra; | |
3548 | extra = mgr->GetExtraFiles(); | |
3549 | if (!extra.IsNull()) { | |
3550 | extra.Strip(); | |
3551 | extra.ReplaceAll(" ", ","); | |
3552 | TObjArray *fextra = extra.Tokenize(","); | |
3553 | TIter nextx(fextra); | |
3554 | TObject *obj; | |
3555 | while ((obj=nextx())) { | |
3556 | if (aodfiles.Contains(obj->GetName())) continue; | |
3557 | if (outputfiles.Contains(obj->GetName())) continue; | |
3558 | if (sextra.Contains(obj->GetName())) continue; | |
3559 | if (!sextra.IsNull()) sextra += ","; | |
3560 | sextra += obj->GetName(); | |
3561 | } | |
3562 | delete fextra; | |
3563 | if (stype.Contains("ext")) { | |
3564 | if (!files.IsNull()) files += ","; | |
3565 | files += sextra; | |
3566 | } | |
3567 | } | |
3568 | if (stype == "ext") return files.Data(); | |
3569 | TString termfiles; | |
3570 | if (!fTerminateFiles.IsNull()) { | |
3571 | fTerminateFiles.Strip(); | |
3572 | fTerminateFiles.ReplaceAll(" ",","); | |
9c939f2b | 3573 | TObjArray *fextra = fTerminateFiles.Tokenize(","); |
f790bc1b | 3574 | TIter nextx(fextra); |
3575 | TObject *obj; | |
3576 | while ((obj=nextx())) { | |
3577 | if (aodfiles.Contains(obj->GetName())) continue; | |
3578 | if (outputfiles.Contains(obj->GetName())) continue; | |
3579 | if (termfiles.Contains(obj->GetName())) continue; | |
3580 | if (sextra.Contains(obj->GetName())) continue; | |
3581 | if (!termfiles.IsNull()) termfiles += ","; | |
3582 | termfiles += obj->GetName(); | |
3583 | } | |
3584 | delete fextra; | |
3585 | } | |
3586 | if (stype.Contains("ter")) { | |
3587 | if (!files.IsNull() && !termfiles.IsNull()) { | |
3588 | files += ","; | |
3589 | files += termfiles; | |
3590 | } | |
3591 | } | |
3592 | return files.Data(); | |
3593 | } | |
3594 | ||
d2a409b2 | 3595 | //______________________________________________________________________________ |
a03be957 | 3596 | Bool_t AliAnalysisAlien::Submit() |
d2a409b2 | 3597 | { |
3598 | // Submit all master jobs. | |
3599 | Int_t nmasterjobs = fInputFiles->GetEntries(); | |
3600 | Long_t tshoot = gSystem->Now(); | |
a03be957 | 3601 | if (!fNsubmitted && !SubmitNext()) return kFALSE; |
d2a409b2 | 3602 | while (fNsubmitted < nmasterjobs) { |
3603 | Long_t now = gSystem->Now(); | |
3604 | if ((now-tshoot)>30000) { | |
3605 | tshoot = now; | |
a03be957 | 3606 | if (!SubmitNext()) return kFALSE; |
d2a409b2 | 3607 | } |
3608 | } | |
a03be957 | 3609 | return kTRUE; |
d2a409b2 | 3610 | } |
3611 | ||
0f389141 | 3612 | //______________________________________________________________________________ |
a03be957 | 3613 | Bool_t AliAnalysisAlien::SubmitMerging() |
0f389141 | 3614 | { |
3615 | // Submit all merging jobs. | |
dc030a24 | 3616 | if (!fGridOutputDir.Contains("/")) fGridOutputDir = Form("%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data()); |
0f389141 | 3617 | gGrid->Cd(fGridOutputDir); |
3618 | TString mergeJDLName = fExecutable; | |
3619 | mergeJDLName.ReplaceAll(".sh", "_merge.jdl"); | |
9f020952 | 3620 | if (!fInputFiles) { |
3621 | Error("SubmitMerging", "You have to use explicit run numbers or run range to merge via JDL!"); | |
3622 | return kFALSE; | |
3623 | } | |
0f389141 | 3624 | Int_t ntosubmit = fInputFiles->GetEntries(); |
0f389141 | 3625 | for (Int_t i=0; i<ntosubmit; i++) { |
f866cba5 | 3626 | TString runOutDir = gSystem->BaseName(fInputFiles->At(i)->GetName()); |
3627 | runOutDir.ReplaceAll(".xml", ""); | |
7c2cd90a | 3628 | if (fOutputToRunNo) { |
3629 | // The output directory is the run number | |
3630 | printf("### Submitting merging job for run <%s>\n", runOutDir.Data()); | |
3631 | runOutDir = Form("%s/%s", fGridOutputDir.Data(), runOutDir.Data()); | |
3632 | } else { | |
17b4e9a4 | 3633 | if (!fRunNumbers.Length() && !fRunRange[0]) { |
3634 | // The output directory is the grid outdir | |
3635 | printf("### Submitting merging job for the full output directory %s.\n", fGridOutputDir.Data()); | |
3636 | runOutDir = fGridOutputDir; | |
3637 | } else { | |
3638 | // The output directory is the master number in 3 digits format | |
3639 | printf("### Submitting merging job for master <%03d>\n", i); | |
3640 | runOutDir = Form("%s/%03d",fGridOutputDir.Data(), i); | |
3641 | } | |
7c2cd90a | 3642 | } |
3643 | // Check now the number of merging stages. | |
2b222f7c | 3644 | TObjArray *list = fOutputFiles.Tokenize(","); |
3645 | TIter next(list); | |
3646 | TObjString *str; | |
3647 | TString outputFile; | |
3648 | while((str=(TObjString*)next())) { | |
3649 | outputFile = str->GetString(); | |
3650 | Int_t index = outputFile.Index("@"); | |
3651 | if (index > 0) outputFile.Remove(index); | |
37d21c01 | 3652 | if (!fMergeExcludes.Contains(outputFile) && |
3653 | !fRegisterExcludes.Contains(outputFile)) break; | |
2b222f7c | 3654 | } |
3655 | delete list; | |
b3e07543 | 3656 | Bool_t done = CheckMergedFiles(outputFile, runOutDir, fMaxMergeFiles, mergeJDLName); |
1d0b4d65 | 3657 | if (!done && (i==ntosubmit-1)) return kFALSE; |
17b4e9a4 | 3658 | if (!fRunNumbers.Length() && !fRunRange[0]) break; |
0f389141 | 3659 | } |
a03be957 | 3660 | if (!ntosubmit) return kTRUE; |
d88e4159 | 3661 | if (fDropToShell) { |
3662 | Info("StartAnalysis", "\n #### STARTING AN ALIEN SHELL FOR YOU. You can exit any time or inspect your jobs in a different shell.##########\ | |
3663 | \n Make sure your jobs are in a final state (you can resubmit failed ones via 'masterjob <id> resubmit ERROR_ALL')\ | |
3664 | \n Rerun in 'terminate' mode to submit all merging stages, each AFTER the previous one completed. The final merged \ | |
3665 | \n output will be written to your alien output directory, while separate stages in <Stage_n>. \ | |
3666 | \n ################################################################################################################"); | |
3667 | gSystem->Exec("aliensh"); | |
3668 | } else { | |
3669 | Info("StartAnalysis", "\n #### STARTED MERGING JOBS FOR YOU #### \ | |
3670 | \n Make sure your jobs are in a final state (you can resubmit failed ones via 'masterjob <id> resubmit ERROR_ALL') \ | |
3671 | \n Rerun in 'terminate' mode to submit all merging stages, each AFTER the previous one completed. The final merged \ | |
3672 | \n output will be written to your alien output directory, while separate stages in <Stage_n>. \ | |
3673 | \n ################################################################################################################"); | |
3674 | } | |
a03be957 | 3675 | return kTRUE; |
0f389141 | 3676 | } |
3677 | ||
d2a409b2 | 3678 | //______________________________________________________________________________ |
a03be957 | 3679 | Bool_t AliAnalysisAlien::SubmitNext() |
d2a409b2 | 3680 | { |
08d5b699 | 3681 | // Submit next bunch of master jobs if the queue is free. The first master job is |
3682 | // submitted right away, while the next will not be unless the previous was split. | |
3683 | // The plugin will not submit new master jobs if there are more that 500 jobs in | |
3684 | // waiting phase. | |
d2a409b2 | 3685 | static Bool_t iscalled = kFALSE; |
3686 | static Int_t firstmaster = 0; | |
3687 | static Int_t lastmaster = 0; | |
3688 | static Int_t npermaster = 0; | |
a03be957 | 3689 | if (iscalled) return kTRUE; |
d2a409b2 | 3690 | iscalled = kTRUE; |
3691 | Int_t nrunning=0, nwaiting=0, nerror=0, ndone=0; | |
3692 | Int_t ntosubmit = 0; | |
3693 | TGridResult *res; | |
3694 | TString jobID = ""; | |
3bdcb562 | 3695 | Int_t nmasterjobs = fInputFiles->GetEntries(); |
3696 | if (!fNsubmitted) { | |
3697 | ntosubmit = 1; | |
3698 | if (!IsUseSubmitPolicy()) { | |
90d50a8c | 3699 | if (nmasterjobs>5) |
3bdcb562 | 3700 | Info("SubmitNext","### Warning submit policy not used ! Submitting too many jobs at a time may be prohibitted. \ |
3701 | \n### You can use SetUseSubmitPolicy() to enable if you have problems."); | |
3702 | ntosubmit = nmasterjobs; | |
3703 | } | |
3704 | } else { | |
d2a409b2 | 3705 | TString status = GetJobStatus(firstmaster, lastmaster, nrunning, nwaiting, nerror, ndone); |
84fcd93f | 3706 | printf("=== master %d: %s\n", lastmaster, status.Data()); |
d2a409b2 | 3707 | // If last master not split, just return |
a03be957 | 3708 | if (status != "SPLIT") {iscalled = kFALSE; return kTRUE;} |
d2a409b2 | 3709 | // No more than 100 waiting jobs |
08d5b699 | 3710 | if (nwaiting>500) {iscalled = kFALSE; return kTRUE;} |
d2a409b2 | 3711 | npermaster = (nrunning+nwaiting+nerror+ndone)/fNsubmitted; |
08d5b699 | 3712 | if (npermaster) ntosubmit = (500-nwaiting)/npermaster; |
7586eedc | 3713 | if (!ntosubmit) ntosubmit = 1; |
84fcd93f | 3714 | printf("=== WAITING(%d) RUNNING(%d) DONE(%d) OTHER(%d) NperMaster=%d => to submit %d jobs\n", |
d2a409b2 | 3715 | nwaiting, nrunning, ndone, nerror, npermaster, ntosubmit); |
3716 | } | |
d2a409b2 | 3717 | for (Int_t i=0; i<ntosubmit; i++) { |
3718 | // Submit for a range of enumeration of runs. | |
a03be957 | 3719 | if (fNsubmitted>=nmasterjobs) {iscalled = kFALSE; return kTRUE;} |
d2a409b2 | 3720 | TString query; |
cd11251e | 3721 | TString runOutDir = gSystem->BaseName(fInputFiles->At(fNsubmitted)->GetName()); |
3722 | runOutDir.ReplaceAll(".xml", ""); | |
3723 | if (fOutputToRunNo) | |
3724 | query = Form("submit %s %s %s", fJDLName.Data(), fInputFiles->At(fNsubmitted)->GetName(), runOutDir.Data()); | |
3725 | else | |
3726 | query = Form("submit %s %s %03d", fJDLName.Data(), fInputFiles->At(fNsubmitted)->GetName(), fNsubmitted); | |
84fcd93f | 3727 | printf("********* %s\n",query.Data()); |
d2a409b2 | 3728 | res = gGrid->Command(query); |
3729 | if (res) { | |
98ca124f | 3730 | TString cjobId1 = res->GetKey(0,"jobId"); |
3731 | if (!cjobId1.Length()) { | |
d2a409b2 | 3732 | iscalled = kFALSE; |
a03be957 | 3733 | gGrid->Stdout(); |
3734 | gGrid->Stderr(); | |
3735 | Error("StartAnalysis", "Your JDL %s could not be submitted. The message was:", fJDLName.Data()); | |
3736 | return kFALSE; | |
d2a409b2 | 3737 | } else { |
3738 | Info("StartAnalysis", "\n_______________________________________________________________________ \ | |
3739 | \n##### Your JDL %s submitted (%d to go). \nTHE JOB ID IS: %s \ | |
3740 | \n_______________________________________________________________________", | |
98ca124f | 3741 | fJDLName.Data(), nmasterjobs-fNsubmitted-1, cjobId1.Data()); |
d2a409b2 | 3742 | jobID += cjobId1; |
3743 | jobID += " "; | |
98ca124f | 3744 | lastmaster = cjobId1.Atoi(); |
d2a409b2 | 3745 | if (!firstmaster) firstmaster = lastmaster; |
3746 | fNsubmitted++; | |
3747 | } | |
3748 | delete res; | |
a03be957 | 3749 | } else { |
3750 | Error("StartAnalysis", "No grid result after submission !!! Bailing out..."); | |
3751 | return kFALSE; | |
d2a409b2 | 3752 | } |
3753 | } | |
3754 | iscalled = kFALSE; | |
a03be957 | 3755 | return kTRUE; |
d2a409b2 | 3756 | } |
3757 | ||
c57f56b7 | 3758 | //______________________________________________________________________________ |
3759 | void AliAnalysisAlien::WriteAnalysisFile() | |
3760 | { | |
f10e8481 | 3761 | // Write current analysis manager into the file <analysisFile> |
3762 | TString analysisFile = fExecutable; | |
3763 | analysisFile.ReplaceAll(".sh", ".root"); | |
c57f56b7 | 3764 | if (!TestBit(AliAnalysisGrid::kSubmit)) { |
3765 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
3766 | if (!mgr || !mgr->IsInitialized()) { | |
3767 | Error("WriteAnalysisFile", "You need an initialized analysis manager for this"); | |
3768 | return; | |
3769 | } | |
3770 | // Check analysis type | |
3771 | TObject *handler; | |
3772 | if (mgr->GetMCtruthEventHandler()) TObject::SetBit(AliAnalysisGrid::kUseMC); | |
3773 | handler = (TObject*)mgr->GetInputEventHandler(); | |
3774 | if (handler) { | |
65eb22f8 | 3775 | if (handler->InheritsFrom("AliMultiInputEventHandler")) { |
3776 | AliMultiInputEventHandler *multiIH = (AliMultiInputEventHandler*)handler; | |
3777 | if (multiIH->GetFirstInputEventHandler()->InheritsFrom("AliESDInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseESD); | |
3778 | if (multiIH->GetFirstInputEventHandler()->InheritsFrom("AliAODInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseAOD); | |
3779 | } else { | |
3780 | if (handler->InheritsFrom("AliESDInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseESD); | |
3781 | if (handler->InheritsFrom("AliAODInputHandler")) TObject::SetBit(AliAnalysisGrid::kUseAOD); | |
3782 | } | |
c57f56b7 | 3783 | } |
3784 | TDirectory *cdir = gDirectory; | |
f10e8481 | 3785 | TFile *file = TFile::Open(analysisFile, "RECREATE"); |
c57f56b7 | 3786 | if (file) { |
e16a394c | 3787 | // Skip task Terminate calls for the grid job (but not in test mode, where we want to check also the terminate mode |
3788 | if (!TestBit(AliAnalysisGrid::kTest)) mgr->SetSkipTerminate(kTRUE); | |
fe2d7fc2 | 3789 | // Unless merging makes no sense |
3790 | if (IsSingleOutput()) mgr->SetSkipTerminate(kFALSE); | |
c57f56b7 | 3791 | mgr->Write(); |
3792 | delete file; | |
fe2d7fc2 | 3793 | // Enable termination for local jobs |
3794 | mgr->SetSkipTerminate(kFALSE); | |
c57f56b7 | 3795 | } |
3796 | if (cdir) cdir->cd(); | |
f10e8481 | 3797 | Info("WriteAnalysisFile", "\n##### Analysis manager: %s wrote to file <%s>\n", mgr->GetName(),analysisFile.Data()); |
c57f56b7 | 3798 | } |
3799 | Bool_t copy = kTRUE; | |
d3b18c4c | 3800 | if (fProductionMode || TestBit(AliAnalysisGrid::kOffline) || TestBit(AliAnalysisGrid::kTest)) copy = kFALSE; |
c57f56b7 | 3801 | if (copy) { |
3802 | CdWork(); | |
3803 | TString workdir = gGrid->GetHomeDirectory(); | |
3804 | workdir += fGridWorkingDir; | |
d3b18c4c | 3805 | Info("WriteAnalysisFile", "\n##### Copying file <%s> containing your initialized analysis manager to your alien workspace", analysisFile.Data()); |
f10e8481 | 3806 | if (FileExists(analysisFile)) gGrid->Rm(analysisFile); |
6c395669 | 3807 | if (!copyLocal2Alien("WriteAnalysisFile",analysisFile.Data(), |
3808 | Form("%s/%s", workdir.Data(),analysisFile.Data()))) Fatal("","Terminating"); | |
c57f56b7 | 3809 | } |
3810 | } | |
3811 | ||
3812 | //______________________________________________________________________________ | |
3813 | void AliAnalysisAlien::WriteAnalysisMacro() | |
3814 | { | |
3815 | // Write the analysis macro that will steer the analysis in grid mode. | |
3816 | if (!TestBit(AliAnalysisGrid::kSubmit)) { | |
3817 | ofstream out; | |
3818 | out.open(fAnalysisMacro.Data(), ios::out); | |
3819 | if (!out.good()) { | |
3820 | Error("WriteAnalysisMacro", "could not open file %s for writing", fAnalysisMacro.Data()); | |
3821 | return; | |
3822 | } | |
5b273635 | 3823 | Bool_t hasSTEERBase = kFALSE; |
3824 | Bool_t hasESD = kFALSE; | |
3825 | Bool_t hasAOD = kFALSE; | |
3826 | Bool_t hasANALYSIS = kFALSE; | |
7ea40ac8 | 3827 | Bool_t hasOADB = kFALSE; |
5b273635 | 3828 | Bool_t hasANALYSISalice = kFALSE; |
3829 | Bool_t hasCORRFW = kFALSE; | |
c57f56b7 | 3830 | TString func = fAnalysisMacro; |
3831 | TString type = "ESD"; | |
3832 | TString comment = "// Analysis using "; | |
c85cfc0f | 3833 | if (IsUseMCchain()) { |
3834 | type = "MC"; | |
3835 | comment += "MC"; | |
3836 | } else { | |
3837 | if (TObject::TestBit(AliAnalysisGrid::kUseESD)) comment += "ESD"; | |
3838 | if (TObject::TestBit(AliAnalysisGrid::kUseAOD)) { | |
3839 | type = "AOD"; | |
3840 | comment += "AOD"; | |
3841 | } | |
3842 | } | |
0df6ccf2 | 3843 | if (type!="AOD" && fFriendChainName!="") { |
3844 | Error("WriteAnalysisMacro", "Friend chain can be attached only to AOD"); | |
3845 | return; | |
3846 | } | |
c57f56b7 | 3847 | if (TObject::TestBit(AliAnalysisGrid::kUseMC)) comment += "/MC"; |
3848 | else comment += " data"; | |
3849 | out << "const char *anatype = \"" << type.Data() << "\";" << endl << endl; | |
3850 | func.ReplaceAll(".C", ""); | |
3851 | out << "void " << func.Data() << "()" << endl; | |
3852 | out << "{" << endl; | |
3853 | out << comment.Data() << endl; | |
3854 | out << "// Automatically generated analysis steering macro executed in grid subjobs" << endl << endl; | |
f7498086 | 3855 | out << " TStopwatch timer;" << endl; |
3856 | out << " timer.Start();" << endl << endl; | |
13f0c00b | 3857 | // Change temp directory to current one |
fdee57f1 | 3858 | if (!IsLocalTest()) { |
3859 | out << "// connect to AliEn and make the chain" << endl; | |
3860 | out << " if (!TGrid::Connect(\"alien://\")) return;" << endl; | |
3861 | } | |
13f0c00b | 3862 | out << "// Set temporary merging directory to current one" << endl; |
3863 | out << " gSystem->Setenv(\"TMPDIR\", gSystem->pwd());" << endl << endl; | |
70c52cf3 | 3864 | out << "// Set temporary compilation directory to current one" << endl; |
3865 | out << " gSystem->SetBuildDir(gSystem->pwd(), kTRUE);" << endl << endl; | |
b3e07543 | 3866 | // Reset existing include path |
3867 | out << "// Reset existing include path and add current directory first in the search" << endl; | |
3868 | out << " gSystem->SetIncludePath(\"-I.\");" << endl; | |
f790bc1b | 3869 | if (!fExecutableCommand.Contains("aliroot")) { |
3870 | out << "// load base root libraries" << endl; | |
3871 | out << " gSystem->Load(\"libTree\");" << endl; | |
3872 | out << " gSystem->Load(\"libGeom\");" << endl; | |
3873 | out << " gSystem->Load(\"libVMC\");" << endl; | |
3874 | out << " gSystem->Load(\"libPhysics\");" << endl << endl; | |
3875 | out << " gSystem->Load(\"libMinuit\");" << endl << endl; | |
3876 | } | |
d5c6455a | 3877 | if (fAdditionalRootLibs.Length()) { |
47a4137d | 3878 | // in principle libtree /lib geom libvmc etc. can go into this list, too |
3879 | out << "// Add aditional libraries" << endl; | |
3880 | TObjArray *list = fAdditionalRootLibs.Tokenize(" "); | |
3881 | TIter next(list); | |
3882 | TObjString *str; | |
3883 | while((str=(TObjString*)next())) { | |
3884 | if (str->GetString().Contains(".so")) | |
3885 | out << " gSystem->Load(\"" << str->GetString().Data() << "\");" << endl; | |
d5c6455a | 3886 | } |
47a4137d | 3887 | if (list) delete list; |
d5c6455a | 3888 | } |
57377eb5 | 3889 | out << "// Load analysis framework libraries" << endl; |
652561d5 | 3890 | TString setupPar = "AliAnalysisAlien::SetupPar"; |
4e5c5506 | 3891 | if (!fPackages) { |
f790bc1b | 3892 | if (!fExecutableCommand.Contains("aliroot")) { |
3893 | out << " gSystem->Load(\"libSTEERBase\");" << endl; | |
3894 | out << " gSystem->Load(\"libESD\");" << endl; | |
3895 | out << " gSystem->Load(\"libAOD\");" << endl; | |
3896 | } | |
4e5c5506 | 3897 | out << " gSystem->Load(\"libANALYSIS\");" << endl; |
7ea40ac8 | 3898 | out << " gSystem->Load(\"libOADB\");" << endl; |
57377eb5 | 3899 | out << " gSystem->Load(\"libANALYSISalice\");" << endl; |
3900 | out << " gSystem->Load(\"libCORRFW\");" << endl << endl; | |
4e5c5506 | 3901 | } else { |
4e5c5506 | 3902 | TIter next(fPackages); |
3903 | TObject *obj; | |
57377eb5 | 3904 | TString pkgname; |
57377eb5 | 3905 | while ((obj=next())) { |
3906 | pkgname = obj->GetName(); | |
4478e6f1 | 3907 | if (pkgname == "STEERBase" || |
3908 | pkgname == "STEERBase.par") hasSTEERBase = kTRUE; | |
3909 | if (pkgname == "ESD" || | |
3910 | pkgname == "ESD.par") hasESD = kTRUE; | |
3911 | if (pkgname == "AOD" || | |
3912 | pkgname == "AOD.par") hasAOD = kTRUE; | |
3913 | if (pkgname == "ANALYSIS" || | |
3914 | pkgname == "ANALYSIS.par") hasANALYSIS = kTRUE; | |
7ea40ac8 | 3915 | if (pkgname == "OADB" || |
3916 | pkgname == "OADB.par") hasOADB = kTRUE; | |
4478e6f1 | 3917 | if (pkgname == "ANALYSISalice" || |
3918 | pkgname == "ANALYSISalice.par") hasANALYSISalice = kTRUE; | |
3919 | if (pkgname == "CORRFW" || | |
3920 | pkgname == "CORRFW.par") hasCORRFW = kTRUE; | |
5b273635 | 3921 | } |
3922 | if (hasANALYSISalice) setupPar = "SetupPar"; | |
57377eb5 | 3923 | if (!hasSTEERBase) out << " gSystem->Load(\"libSTEERBase\");" << endl; |
5b273635 | 3924 | else out << " if (!" << setupPar << "(\"STEERBase\")) return;" << endl; |
57377eb5 | 3925 | if (!hasESD) out << " gSystem->Load(\"libESD\");" << endl; |
5b273635 | 3926 | else out << " if (!" << setupPar << "(\"ESD\")) return;" << endl; |
57377eb5 | 3927 | if (!hasAOD) out << " gSystem->Load(\"libAOD\");" << endl; |
5b273635 | 3928 | else out << " if (!" << setupPar << "(\"AOD\")) return;" << endl; |
57377eb5 | 3929 | if (!hasANALYSIS) out << " gSystem->Load(\"libANALYSIS\");" << endl; |
5b273635 | 3930 | else out << " if (!" << setupPar << "(\"ANALYSIS\")) return;" << endl; |
7ea40ac8 | 3931 | if (!hasOADB) out << " gSystem->Load(\"libOADB\");" << endl; |
3932 | else out << " if (!" << setupPar << "(\"OADB\")) return;" << endl; | |
57377eb5 | 3933 | if (!hasANALYSISalice) out << " gSystem->Load(\"libANALYSISalice\");" << endl; |
5b273635 | 3934 | else out << " if (!" << setupPar << "(\"ANALYSISalice\")) return;" << endl; |
57377eb5 | 3935 | if (!hasCORRFW) out << " gSystem->Load(\"libCORRFW\");" << endl << endl; |
5b273635 | 3936 | else out << " if (!" << setupPar << "(\"CORRFW\")) return;" << endl << endl; |
57377eb5 | 3937 | out << "// Compile other par packages" << endl; |
3938 | next.Reset(); | |
fcc9bb6f | 3939 | while ((obj=next())) { |
3940 | pkgname = obj->GetName(); | |
4478e6f1 | 3941 | if (pkgname == "STEERBase" || |
3942 | pkgname == "STEERBase.par" || | |
3943 | pkgname == "ESD" || | |
3944 | pkgname == "ESD.par" || | |
3945 | pkgname == "AOD" || | |
3946 | pkgname == "AOD.par" || | |
3947 | pkgname == "ANALYSIS" || | |
3948 | pkgname == "ANALYSIS.par" || | |
7ea40ac8 | 3949 | pkgname == "OADB" || |
3950 | pkgname == "OADB.par" || | |
4478e6f1 | 3951 | pkgname == "ANALYSISalice" || |
3952 | pkgname == "ANALYSISalice.par" || | |
3953 | pkgname == "CORRFW" || | |
3954 | pkgname == "CORRFW.par") continue; | |
5b273635 | 3955 | out << " if (!" << setupPar << "(\"" << obj->GetName() << "\")) return;" << endl; |
fcc9bb6f | 3956 | } |
4e5c5506 | 3957 | } |
b3e07543 | 3958 | out << "// include path" << endl; |
3959 | // Get the include path from the interpreter and remove entries pointing to AliRoot | |
3960 | out << " TString intPath = gInterpreter->GetIncludePath();" << endl; | |
3961 | out << " TObjArray *listpaths = intPath.Tokenize(\" \");" << endl; | |
3962 | out << " TIter nextpath(listpaths);" << endl; | |
3963 | out << " TObjString *pname;" << endl; | |
3964 | out << " while ((pname=(TObjString*)nextpath())) {" << endl; | |
3965 | out << " TString current = pname->GetName();" << endl; | |
3966 | out << " if (current.Contains(\"AliRoot\") || current.Contains(\"ALICE_ROOT\")) continue;" << endl; | |
3967 | out << " gSystem->AddIncludePath(current);" << endl; | |
3968 | out << " }" << endl; | |
3969 | out << " if (listpaths) delete listpaths;" << endl; | |
3970 | if (fIncludePath.Length()) out << " gSystem->AddIncludePath(\"" << fIncludePath.Data() << "\");" << endl; | |
3971 | out << " gROOT->ProcessLine(\".include $ALICE_ROOT/include\");" << endl; | |
3972 | out << " printf(\"Include path: %s\\n\", gSystem->GetIncludePath());" << endl << endl; | |
6da75e0b | 3973 | if (fAdditionalLibs.Length()) { |
3974 | out << "// Add aditional AliRoot libraries" << endl; | |
3975 | TObjArray *list = fAdditionalLibs.Tokenize(" "); | |
3976 | TIter next(list); | |
3977 | TObjString *str; | |
3978 | while((str=(TObjString*)next())) { | |
3979 | if (str->GetString().Contains(".so")) | |
3980 | out << " gSystem->Load(\"" << str->GetString().Data() << "\");" << endl; | |
652561d5 | 3981 | if (str->GetString().Contains(".par")) |
3982 | out << " if (!" << setupPar << "(\"" << str->GetString() << "\")) return;" << endl; | |
6da75e0b | 3983 | } |
3984 | if (list) delete list; | |
3985 | } | |
3986 | out << endl; | |
c57f56b7 | 3987 | out << "// analysis source to be compiled at runtime (if any)" << endl; |
3988 | if (fAnalysisSource.Length()) { | |
3989 | TObjArray *list = fAnalysisSource.Tokenize(" "); | |
3990 | TIter next(list); | |
3991 | TObjString *str; | |
3992 | while((str=(TObjString*)next())) { | |
3993 | out << " gROOT->ProcessLine(\".L " << str->GetString().Data() << "+g\");" << endl; | |
3994 | } | |
3995 | if (list) delete list; | |
3996 | } | |
3997 | out << endl; | |
b3e07543 | 3998 | // out << " printf(\"Currently load libraries:\\n\");" << endl; |
3999 | // out << " printf(\"%s\\n\", gSystem->GetLibraries());" << endl; | |
0f389141 | 4000 | if (fFastReadOption) { |
d3339be3 | 4001 | Warning("WriteAnalysisMacro", "!!! You requested FastRead option. Using xrootd flags to reduce timeouts in the grid jobs. This may skip some files that could be accessed !!! \ |
4002 | \n+++ NOTE: To disable this option, use: plugin->SetFastReadOption(kFALSE)"); | |
0f389141 | 4003 | out << "// fast xrootd reading enabled" << endl; |
4004 | out << " printf(\"!!! You requested FastRead option. Using xrootd flags to reduce timeouts. Note that this may skip some files that could be accessed !!!\");" << endl; | |
b3e07543 | 4005 | out << " gEnv->SetValue(\"XNet.ConnectTimeout\",50);" << endl; |
4006 | out << " gEnv->SetValue(\"XNet.RequestTimeout\",50);" << endl; | |
0f389141 | 4007 | out << " gEnv->SetValue(\"XNet.MaxRedirectCount\",2);" << endl; |
b3e07543 | 4008 | out << " gEnv->SetValue(\"XNet.ReconnectTimeout\",50);" << endl; |
0f389141 | 4009 | out << " gEnv->SetValue(\"XNet.FirstConnectMaxCnt\",1);" << endl << endl; |
21ca8e59 | 4010 | } |
c57f56b7 | 4011 | out << "// read the analysis manager from file" << endl; |
f10e8481 | 4012 | TString analysisFile = fExecutable; |
4013 | analysisFile.ReplaceAll(".sh", ".root"); | |
105631b5 | 4014 | out << " AliAnalysisManager *mgr = AliAnalysisAlien::LoadAnalysisManager(\"" |
4015 | << analysisFile << "\");" << endl; | |
4016 | out << " if (!mgr) return;" << endl; | |
21ca8e59 | 4017 | if (IsLocalTest()) { |
4018 | out << " AliAnalysisAlien *plugin = new AliAnalysisAlien();" << endl; | |
4019 | out << " plugin->SetRunMode(\"test\");" << endl; | |
139fe6ba | 4020 | if (fFileForTestMode.IsNull()) |
4021 | out << " plugin->SetFileForTestMode(\"data.txt\");" << endl; | |
4022 | else | |
4023 | out << " plugin->SetFileForTestMode(\"" << fFileForTestMode << "\");" << endl; | |
922b1fc7 | 4024 | out << " plugin->SetNtestFiles(" << fNtestFiles << ");" << endl; |
4b5d9e21 | 4025 | if (!fFriendChainName.IsNull()) |
4026 | out << " plugin->SetFriendChainName(\"" << fFriendChainName << "\");" << endl; | |
024dfa52 | 4027 | if (IsUseMCchain()) |
4028 | out << " plugin->SetUseMCchain();" << endl; | |
21ca8e59 | 4029 | out << " mgr->SetGridHandler(plugin);" << endl; |
627a5dbe | 4030 | if (AliAnalysisManager::GetAnalysisManager()) { |
7a366e0b | 4031 | out << " mgr->SetDebugLevel(" << AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() << ");" << endl; |
627a5dbe | 4032 | out << " mgr->SetNSysInfo(" << AliAnalysisManager::GetAnalysisManager()->GetNsysInfo() << ");" << endl; |
4033 | } else { | |
7a366e0b | 4034 | out << " mgr->SetDebugLevel(10);" << endl; |
627a5dbe | 4035 | out << " mgr->SetNSysInfo(100);" << endl; |
4036 | } | |
21ca8e59 | 4037 | } |
c57f56b7 | 4038 | out << " mgr->PrintStatus();" << endl; |
52b6a92b | 4039 | if (AliAnalysisManager::GetAnalysisManager()) { |
f866cba5 | 4040 | if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel()>3) { |
52b6a92b | 4041 | out << " gEnv->SetValue(\"XNet.Debug\", \"1\");" << endl; |
de52b69c | 4042 | } else { |
9a8288ff | 4043 | if (TestBit(AliAnalysisGrid::kTest)) |
4044 | out << " AliLog::SetGlobalLogLevel(AliLog::kWarning);" << endl; | |
4045 | else | |
4046 | out << " AliLog::SetGlobalLogLevel(AliLog::kError);" << endl; | |
52b6a92b | 4047 | } |
4048 | } | |
21ca8e59 | 4049 | if (!IsLocalTest()) { |
242accb2 | 4050 | out << " TChain *chain = CreateChain(\"wn.xml\", anatype);" << endl << endl; |
21ca8e59 | 4051 | out << " mgr->StartAnalysis(\"localfile\", chain);" << endl; |
4052 | } else { | |
4053 | out << " mgr->StartAnalysis(\"localfile\");" << endl; | |
242accb2 | 4054 | } |
f7498086 | 4055 | out << " timer.Stop();" << endl; |
4056 | out << " timer.Print();" << endl; | |
c57f56b7 | 4057 | out << "}" << endl << endl; |
21ca8e59 | 4058 | if (!IsLocalTest()) { |
fcc9bb6f | 4059 | out <<"//________________________________________________________________________________" << endl; |
c57f56b7 | 4060 | out << "TChain* CreateChain(const char *xmlfile, const char *type=\"ESD\")" << endl; |
4061 | out << "{" << endl; | |
4062 | out << "// Create a chain using url's from xml file" << endl; | |
242accb2 | 4063 | out << " TString filename;" << endl; |
4064 | out << " Int_t run = 0;" << endl; | |
c85cfc0f | 4065 | if (IsUseMCchain()) { |
4066 | out << " TString treename = \"TE\";" << endl; | |
4067 | } else { | |
4068 | out << " TString treename = type;" << endl; | |
4069 | out << " treename.ToLower();" << endl; | |
4070 | out << " treename += \"Tree\";" << endl; | |
4071 | } | |
e02fee64 | 4072 | out << " printf(\"***************************************\\n\");" << endl; |
4073 | out << " printf(\" Getting chain of trees %s\\n\", treename.Data());" << endl; | |
4074 | out << " printf(\"***************************************\\n\");" << endl; | |
c57f56b7 | 4075 | out << " TAlienCollection *coll = TAlienCollection::Open(xmlfile);" << endl; |
4076 | out << " if (!coll) {" << endl; | |
4077 | out << " ::Error(\"CreateChain\", \"Cannot create an AliEn collection from %s\", xmlfile);" << endl; | |
4078 | out << " return NULL;" << endl; | |
4079 | out << " }" << endl; | |
242accb2 | 4080 | out << " AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();" << endl; |
c57f56b7 | 4081 | out << " TChain *chain = new TChain(treename);" << endl; |
0df6ccf2 | 4082 | if(fFriendChainName!="") { |
4083 | out << " TChain *chainFriend = new TChain(treename);" << endl; | |
4084 | } | |
c57f56b7 | 4085 | out << " coll->Reset();" << endl; |
0df6ccf2 | 4086 | out << " while (coll->Next()) {" << endl; |
242accb2 | 4087 | out << " filename = coll->GetTURL("");" << endl; |
4088 | out << " if (mgr) {" << endl; | |
4089 | out << " Int_t nrun = AliAnalysisManager::GetRunFromAlienPath(filename);" << endl; | |
4090 | out << " if (nrun && nrun != run) {" << endl; | |
4091 | out << " printf(\"### Run number detected from chain: %d\\n\", nrun);" << endl; | |
4092 | out << " mgr->SetRunFromPath(nrun);" << endl; | |
4093 | out << " run = nrun;" << endl; | |
4094 | out << " }" << endl; | |
4095 | out << " }" << endl; | |
4096 | out << " chain->Add(filename);" << endl; | |
0df6ccf2 | 4097 | if(fFriendChainName!="") { |
4098 | out << " TString fileFriend=coll->GetTURL(\"\");" << endl; | |
4b5d9e21 | 4099 | out << " if (fileFriend.Index(\"#\") > -1) fileFriend.Remove(fileFriend.Index(\"#\"));" << endl; |
4100 | out << " fileFriend = gSystem->DirName(fileFriend);" << endl; | |
4101 | out << " fileFriend += \"/\";" << endl; | |
4102 | out << " fileFriend += \"" << fFriendChainName << "\";"; | |
4103 | out << " TFile *file = TFile::Open(fileFriend);" << endl; | |
4104 | out << " if (file) {" << endl; | |
4105 | out << " file->Close();" << endl; | |
4106 | out << " chainFriend->Add(fileFriend.Data());" << endl; | |
4107 | out << " } else {" << endl; | |
4108 | out << " ::Fatal(\"CreateChain\", \"Cannot open friend file: %s\", fileFriend.Data());" << endl; | |
4109 | out << " return 0;" << endl; | |
4110 | out << " }" << endl; | |
0df6ccf2 | 4111 | } |
4112 | out << " }" << endl; | |
c57f56b7 | 4113 | out << " if (!chain->GetNtrees()) {" << endl; |
4114 | out << " ::Error(\"CreateChain\", \"No tree found from collection %s\", xmlfile);" << endl; | |
4115 | out << " return NULL;" << endl; | |
4116 | out << " }" << endl; | |
0df6ccf2 | 4117 | if(fFriendChainName!="") { |
4118 | out << " chain->AddFriend(chainFriend);" << endl; | |
4119 | } | |
c57f56b7 | 4120 | out << " return chain;" << endl; |
fcc9bb6f | 4121 | out << "}" << endl << endl; |
c57f56b7 | 4122 | } |
5b273635 | 4123 | if (hasANALYSISalice) { |
4124 | out <<"//________________________________________________________________________________" << endl; | |
4125 | out << "Bool_t SetupPar(const char *package) {" << endl; | |
4126 | out << "// Compile the package and set it up." << endl; | |
4127 | out << " TString pkgdir = package;" << endl; | |
4128 | out << " pkgdir.ReplaceAll(\".par\",\"\");" << endl; | |
b50a41c3 | 4129 | out << " gSystem->Exec(TString::Format(\"tar xvzf %s.par\", pkgdir.Data()));" << endl; |
5b273635 | 4130 | out << " TString cdir = gSystem->WorkingDirectory();" << endl; |
4131 | out << " gSystem->ChangeDirectory(pkgdir);" << endl; | |
4132 | out << " // Check for BUILD.sh and execute" << endl; | |
4133 | out << " if (!gSystem->AccessPathName(\"PROOF-INF/BUILD.sh\")) {" << endl; | |
4134 | out << " printf(\"*******************************\\n\");" << endl; | |
4135 | out << " printf(\"*** Building PAR archive ***\\n\");" << endl; | |
4136 | out << " printf(\"*******************************\\n\");" << endl; | |
4137 | out << " if (gSystem->Exec(\"PROOF-INF/BUILD.sh\")) {" << endl; | |
4138 | out << " ::Error(\"SetupPar\", \"Cannot build par archive %s\", pkgdir.Data());" << endl; | |
4139 | out << " gSystem->ChangeDirectory(cdir);" << endl; | |
4140 | out << " return kFALSE;" << endl; | |
4141 | out << " }" << endl; | |
4142 | out << " } else {" << endl; | |
4143 | out << " ::Error(\"SetupPar\",\"Cannot access PROOF-INF/BUILD.sh for package %s\", pkgdir.Data());" << endl; | |
4144 | out << " gSystem->ChangeDirectory(cdir);" << endl; | |
4145 | out << " return kFALSE;" << endl; | |
4146 | out << " }" << endl; | |
4147 | out << " // Check for SETUP.C and execute" << endl; | |
4148 | out << " if (!gSystem->AccessPathName(\"PROOF-INF/SETUP.C\")) {" << endl; | |
4149 | out << " printf(\"*******************************\\n\");" << endl; | |
4150 | out << " printf(\"*** Setup PAR archive ***\\n\");" << endl; | |
4151 | out << " printf(\"*******************************\\n\");" << endl; | |
4152 | out << " gROOT->Macro(\"PROOF-INF/SETUP.C\");" << endl; | |
4153 | out << " } else {" << endl; | |
4154 | out << " ::Error(\"SetupPar\",\"Cannot access PROOF-INF/SETUP.C for package %s\", pkgdir.Data());" << endl; | |
4155 | out << " gSystem->ChangeDirectory(cdir);" << endl; | |
4156 | out << " return kFALSE;" << endl; | |
4157 | out << " }" << endl; | |
4158 | out << " // Restore original workdir" << endl; | |
4159 | out << " gSystem->ChangeDirectory(cdir);" << endl; | |
4160 | out << " return kTRUE;" << endl; | |
4161 | out << "}" << endl; | |
4162 | } | |
c57f56b7 | 4163 | Info("WriteAnalysisMacro", "\n##### Analysis macro to run on worker nodes <%s> written",fAnalysisMacro.Data()); |
4164 | } | |
4165 | Bool_t copy = kTRUE; | |
d3b18c4c | 4166 | if (fProductionMode || TestBit(AliAnalysisGrid::kOffline) || TestBit(AliAnalysisGrid::kTest)) copy = kFALSE; |
c57f56b7 | 4167 | if (copy) { |
4168 | CdWork(); | |
4169 | TString workdir = gGrid->GetHomeDirectory(); | |
4170 | workdir += fGridWorkingDir; | |
4171 | if (FileExists(fAnalysisMacro)) gGrid->Rm(fAnalysisMacro); | |
c57f56b7 | 4172 | Info("WriteAnalysisMacro", "\n##### Copying analysis macro: <%s> to your alien workspace", fAnalysisMacro.Data()); |
6c395669 | 4173 | // TFile::Cp(Form("file:%s",fAnalysisMacro.Data()), Form("alien://%s/%s", workdir.Data(), fAnalysisMacro.Data())); |
4174 | if (!copyLocal2Alien("WriteAnalysisMacro",fAnalysisMacro.Data(), | |
4175 | Form("alien://%s/%s", workdir.Data(), | |
4176 | fAnalysisMacro.Data()))) Fatal("","Terminating"); | |
c57f56b7 | 4177 | } |
4178 | } | |
4179 | ||
0f389141 | 4180 | //______________________________________________________________________________ |
4181 | void AliAnalysisAlien::WriteMergingMacro() | |
4182 | { | |
4183 | // Write a macro to merge the outputs per master job. | |
4184 | if (!fMergeViaJDL) return; | |
4185 | if (!fOutputFiles.Length()) { | |
4186 | Error("WriteMergingMacro", "No output file names defined. Are you running the right AliAnalysisAlien configuration ?"); | |
4187 | return; | |
4188 | } | |
ec5acdce | 4189 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); |
0f389141 | 4190 | TString mergingMacro = fExecutable; |
4191 | mergingMacro.ReplaceAll(".sh","_merge.C"); | |
139fe6ba | 4192 | if (gGrid && !fGridOutputDir.Contains("/")) fGridOutputDir = Form("%s/%s/%s", gGrid->GetHomeDirectory(), fGridWorkingDir.Data(), fGridOutputDir.Data()); |
0f389141 | 4193 | if (!TestBit(AliAnalysisGrid::kSubmit)) { |
4194 | ofstream out; | |
4195 | out.open(mergingMacro.Data(), ios::out); | |
4196 | if (!out.good()) { | |
4197 | Error("WriteMergingMacro", "could not open file %s for writing", fAnalysisMacro.Data()); | |
4198 | return; | |
4199 | } | |
5b273635 | 4200 | Bool_t hasSTEERBase = kFALSE; |
4201 | Bool_t hasESD = kFALSE; | |
4202 | Bool_t hasAOD = kFALSE; | |
4203 | Bool_t hasANALYSIS = kFALSE; | |
7ea40ac8 | 4204 | Bool_t hasOADB = kFALSE; |
5b273635 | 4205 | Bool_t hasANALYSISalice = kFALSE; |
4206 | Bool_t hasCORRFW = kFALSE; | |
0f389141 | 4207 | TString func = mergingMacro; |
4208 | TString comment; | |
4209 | func.ReplaceAll(".C", ""); | |
f47d5cb4 | 4210 | out << "void " << func.Data() << "(const char *dir, Int_t stage=0)" << endl; |
0f389141 | 4211 | out << "{" << endl; |
4212 | out << "// Automatically generated merging macro executed in grid subjobs" << endl << endl; | |
4213 | out << " TStopwatch timer;" << endl; | |
4214 | out << " timer.Start();" << endl << endl; | |
b3e07543 | 4215 | // Reset existing include path |
4216 | out << "// Reset existing include path and add current directory first in the search" << endl; | |
4217 | out << " gSystem->SetIncludePath(\"-I.\");" << endl; | |
7c2cd90a | 4218 | if (!fExecutableCommand.Contains("aliroot")) { |
4219 | out << "// load base root libraries" << endl; | |
4220 | out << " gSystem->Load(\"libTree\");" << endl; | |
4221 | out << " gSystem->Load(\"libGeom\");" << endl; | |
4222 | out << " gSystem->Load(\"libVMC\");" << endl; | |
4223 | out << " gSystem->Load(\"libPhysics\");" << endl << endl; | |
4224 | out << " gSystem->Load(\"libMinuit\");" << endl << endl; | |
4225 | } | |
0f389141 | 4226 | if (fAdditionalRootLibs.Length()) { |
4227 | // in principle libtree /lib geom libvmc etc. can go into this list, too | |
4228 | out << "// Add aditional libraries" << endl; | |
4229 | TObjArray *list = fAdditionalRootLibs.Tokenize(" "); | |
4230 | TIter next(list); | |
4231 | TObjString *str; | |
4232 | while((str=(TObjString*)next())) { | |
4233 | if (str->GetString().Contains(".so")) | |
4234 | out << " gSystem->Load(\"" << str->GetString().Data() << "\");" << endl; | |
4235 | } | |
4236 | if (list) delete list; | |
4237 | } | |
0f389141 | 4238 | out << "// Load analysis framework libraries" << endl; |
4239 | if (!fPackages) { | |
7c2cd90a | 4240 | if (!fExecutableCommand.Contains("aliroot")) { |
4241 | out << " gSystem->Load(\"libSTEERBase\");" << endl; | |
4242 | out << " gSystem->Load(\"libESD\");" << endl; | |
4243 | out << " gSystem->Load(\"libAOD\");" << endl; | |
4244 | } | |
0f389141 | 4245 | out << " gSystem->Load(\"libANALYSIS\");" << endl; |
7ea40ac8 | 4246 | out << " gSystem->Load(\"libOADB\");" << endl; |
0f389141 | 4247 | out << " gSystem->Load(\"libANALYSISalice\");" << endl; |
4248 | out << " gSystem->Load(\"libCORRFW\");" << endl << endl; | |
4249 | } else { | |
4250 | TIter next(fPackages); | |
4251 | TObject *obj; | |
4252 | TString pkgname; | |
5b273635 | 4253 | TString setupPar = "AliAnalysisAlien::SetupPar"; |
0f389141 | 4254 | while ((obj=next())) { |
4255 | pkgname = obj->GetName(); | |
4256 | if (pkgname == "STEERBase" || | |
4257 | pkgname == "STEERBase.par") hasSTEERBase = kTRUE; | |
4258 | if (pkgname == "ESD" || | |
4259 | pkgname == "ESD.par") hasESD = kTRUE; | |
4260 | if (pkgname == "AOD" || | |
4261 | pkgname == "AOD.par") hasAOD = kTRUE; | |
4262 | if (pkgname == "ANALYSIS" || | |
4263 | pkgname == "ANALYSIS.par") hasANALYSIS = kTRUE; | |
7ea40ac8 | 4264 | if (pkgname == "OADB" || |
4265 | pkgname == "OADB.par") hasOADB = kTRUE; | |
0f389141 | 4266 | if (pkgname == "ANALYSISalice" || |
4267 | pkgname == "ANALYSISalice.par") hasANALYSISalice = kTRUE; | |
4268 | if (pkgname == "CORRFW" || | |
4269 | pkgname == "CORRFW.par") hasCORRFW = kTRUE; | |
4270 | } | |
5b273635 | 4271 | if (hasANALYSISalice) setupPar = "SetupPar"; |
0f389141 | 4272 | if (!hasSTEERBase) out << " gSystem->Load(\"libSTEERBase\");" << endl; |
5b273635 | 4273 | else out << " if (!" << setupPar << "(\"STEERBase\")) return;" << endl; |
0f389141 | 4274 | if (!hasESD) out << " gSystem->Load(\"libESD\");" << endl; |
5b273635 | 4275 | else out << " if (!" << setupPar << "(\"ESD\")) return;" << endl; |
0f389141 | 4276 | if (!hasAOD) out << " gSystem->Load(\"libAOD\");" << endl; |
5b273635 | 4277 | else out << " if (!" << setupPar << "(\"AOD\")) return;" << endl; |
0bc15bcd | 4278 | out << " gSystem->Load(\"libOADB\");" << endl; |
0f389141 | 4279 | if (!hasANALYSIS) out << " gSystem->Load(\"libANALYSIS\");" << endl; |
5b273635 | 4280 | else out << " if (!" << setupPar << "(\"ANALYSIS\")) return;" << endl; |
7ea40ac8 | 4281 | if (!hasOADB) out << " gSystem->Load(\"libOADB\");" << endl; |
4282 | else out << " if (!" << setupPar << "(\"OADB\")) return;" << endl; | |
0f389141 | 4283 | if (!hasANALYSISalice) out << " gSystem->Load(\"libANALYSISalice\");" << endl; |
5b273635 | 4284 | else out << " if (!" << setupPar << "(\"ANALYSISalice\")) return;" << endl; |
0f389141 | 4285 | if (!hasCORRFW) out << " gSystem->Load(\"libCORRFW\");" << endl << endl; |
5b273635 | 4286 | else out << " if (!" << setupPar << "(\"CORRFW\")) return;" << endl << endl; |
0f389141 | 4287 | out << "// Compile other par packages" << endl; |
4288 | next.Reset(); | |
4289 | while ((obj=next())) { | |
4290 | pkgname = obj->GetName(); | |
4291 | if (pkgname == "STEERBase" || | |
4292 | pkgname == "STEERBase.par" || | |
4293 | pkgname == "ESD" || | |
4294 | pkgname == "ESD.par" || | |
4295 | pkgname == "AOD" || | |
4296 | pkgname == "AOD.par" || | |
4297 | pkgname == "ANALYSIS" || | |
4298 | pkgname == "ANALYSIS.par" || | |
7ea40ac8 | 4299 | pkgname == "OADB" || |
4300 | pkgname == "OADB.par" || | |
0f389141 | 4301 | pkgname == "ANALYSISalice" || |
4302 | pkgname == "ANALYSISalice.par" || | |
4303 | pkgname == "CORRFW" || | |
4304 | pkgname == "CORRFW.par") continue; | |
5b273635 | 4305 | out << " if (!" << setupPar << "(\"" << obj->GetName() << "\")) return;" << endl; |
0f389141 | 4306 | } |
4307 | } | |
b3e07543 | 4308 | out << "// include path" << endl; |
4309 | // Get the include path from the interpreter and remove entries pointing to AliRoot | |
4310 | out << " TString intPath = gInterpreter->GetIncludePath();" << endl; | |
4311 | out << " TObjArray *listpaths = intPath.Tokenize(\" \");" << endl; | |
4312 | out << " TIter nextpath(listpaths);" << endl; | |
4313 | out << " TObjString *pname;" << endl; | |
4314 | out << " while ((pname=(TObjString*)nextpath())) {" << endl; | |
4315 | out << " TString current = pname->GetName();" << endl; | |
4316 | out << " if (current.Contains(\"AliRoot\") || current.Contains(\"ALICE_ROOT\")) continue;" << endl; | |
4317 | out << " gSystem->AddIncludePath(current);" << endl; | |
4318 | out << " }" << endl; | |
4319 | out << " if (listpaths) delete listpaths;" << endl; | |
4320 | if (fIncludePath.Length()) out << " gSystem->AddIncludePath(\"" << fIncludePath.Data() << "\");" << endl; | |
4321 | out << " gROOT->ProcessLine(\".include $ALICE_ROOT/include\");" << endl; | |
4322 | out << " printf(\"Include path: %s\\n\", gSystem->GetIncludePath());" << endl << endl; | |
0f389141 | 4323 | if (fAdditionalLibs.Length()) { |
4324 | out << "// Add aditional AliRoot libraries" << endl; | |
4325 | TObjArray *list = fAdditionalLibs.Tokenize(" "); | |
4326 | TIter next(list); | |
4327 | TObjString *str; | |
4328 | while((str=(TObjString*)next())) { | |
4329 | if (str->GetString().Contains(".so")) | |
4330 | out << " gSystem->Load(\"" << str->GetString().Data() << "\");" << endl; | |
4331 | } | |
4332 | if (list) delete list; | |
4333 | } | |
4334 | out << endl; | |
4335 | out << "// Analysis source to be compiled at runtime (if any)" << endl; | |
4336 | if (fAnalysisSource.Length()) { | |
4337 | TObjArray *list = fAnalysisSource.Tokenize(" "); | |
4338 | TIter next(list); | |
4339 | TObjString *str; | |
4340 | while((str=(TObjString*)next())) { | |
4341 | out << " gROOT->ProcessLine(\".L " << str->GetString().Data() << "+g\");" << endl; | |
4342 | } | |
4343 | if (list) delete list; | |
4344 | } | |
149d288c | 4345 | out << endl; |
4346 | ||
0f389141 | 4347 | if (fFastReadOption) { |
4348 | Warning("WriteMergingMacro", "!!! You requested FastRead option. Using xrootd flags to reduce timeouts in the grid merging jobs. Note that this may skip some files that could be accessed !!!"); | |
4349 | out << "// fast xrootd reading enabled" << endl; | |
4350 | out << " printf(\"!!! You requested FastRead option. Using xrootd flags to reduce timeouts. Note that this may skip some files that could be accessed !!!\");" << endl; | |
b3e07543 | 4351 | out << " gEnv->SetValue(\"XNet.ConnectTimeout\",50);" << endl; |
4352 | out << " gEnv->SetValue(\"XNet.RequestTimeout\",50);" << endl; | |
0f389141 | 4353 | out << " gEnv->SetValue(\"XNet.MaxRedirectCount\",2);" << endl; |
b3e07543 | 4354 | out << " gEnv->SetValue(\"XNet.ReconnectTimeout\",50);" << endl; |
0f389141 | 4355 | out << " gEnv->SetValue(\"XNet.FirstConnectMaxCnt\",1);" << endl << endl; |
e8b839ab | 4356 | } |
4357 | // Change temp directory to current one | |
fdee57f1 | 4358 | out << "// Connect to AliEn" << endl; |
4359 | out << " if (!TGrid::Connect(\"alien://\")) return;" << endl; | |
e8b839ab | 4360 | out << "// Set temporary merging directory to current one" << endl; |
4361 | out << " gSystem->Setenv(\"TMPDIR\", gSystem->pwd());" << endl << endl; | |
70c52cf3 | 4362 | out << "// Set temporary compilation directory to current one" << endl; |
4363 | out << " gSystem->SetBuildDir(gSystem->pwd(), kTRUE);" << endl << endl; | |
7c2cd90a | 4364 | out << " TString outputDir = dir;" << endl; |
f790bc1b | 4365 | out << " TString outputFiles = \"" << GetListOfFiles("out") << "\";" << endl; |
37d21c01 | 4366 | out << " TString mergeExcludes = \"" << fMergeExcludes << " " << fRegisterExcludes << "\";" << endl; |
58268c13 | 4367 | out << " TObjArray *list = outputFiles.Tokenize(\",\");" << endl; |
0f389141 | 4368 | out << " TIter *iter = new TIter(list);" << endl; |
4369 | out << " TObjString *str;" << endl; | |
a2f5fc01 | 4370 | out << " TString outputFile;" << endl; |
0f389141 | 4371 | out << " Bool_t merged = kTRUE;" << endl; |
ec5acdce | 4372 | TString analysisFile = fExecutable; |
4373 | analysisFile.ReplaceAll(".sh", ".root"); | |
4374 | out << " AliAnalysisManager *mgr = AliAnalysisAlien::LoadAnalysisManager(\"" | |
4375 | << analysisFile << "\");" << endl; | |
4376 | out << " if (!mgr) {" << endl; | |
4377 | out << " printf(\"ERROR: Analysis manager could not be extracted from file \");" << endl; | |
4378 | out << " return;" << endl; | |
4379 | out << " }" << endl; | |
d66aa2a9 | 4380 | if (IsLocalTest()) { |
4381 | out << " printf(\"===================================\n\");" << endl; | |
4382 | out << " printf(\"Testing merging...\\n\");" << endl; | |
4383 | out << " printf(\"===================================\n\");" << endl; | |
4384 | } | |
0f389141 | 4385 | out << " while((str=(TObjString*)iter->Next())) {" << endl; |
a2f5fc01 | 4386 | out << " outputFile = str->GetString();" << endl; |
7c2cd90a | 4387 | out << " if (outputFile.Contains(\"*\")) continue;" << endl; |
a2f5fc01 | 4388 | out << " Int_t index = outputFile.Index(\"@\");" << endl; |
4389 | out << " if (index > 0) outputFile.Remove(index);" << endl; | |
0f389141 | 4390 | out << " // Skip already merged outputs" << endl; |
a2f5fc01 | 4391 | out << " if (!gSystem->AccessPathName(outputFile)) {" << endl; |
d66aa2a9 | 4392 | out << " printf(\"Output file <%s> found. Not merging again.\\n\",outputFile.Data());" << endl; |
0f389141 | 4393 | out << " continue;" << endl; |
4394 | out << " }" << endl; | |
a2f5fc01 | 4395 | out << " if (mergeExcludes.Contains(outputFile.Data())) continue;" << endl; |
b3e07543 | 4396 | out << " merged = AliAnalysisAlien::MergeOutput(outputFile, outputDir, " << fMaxMergeFiles << ", stage);" << endl; |
0f389141 | 4397 | out << " if (!merged) {" << endl; |
a2f5fc01 | 4398 | out << " printf(\"ERROR: Cannot merge %s\\n\", outputFile.Data());" << endl; |
7c2cd90a | 4399 | out << " return;" << endl; |
0f389141 | 4400 | out << " }" << endl; |
4401 | out << " }" << endl; | |
d66aa2a9 | 4402 | if (mgr && mgr->IsCollectThroughput() && !IsLocalTest()) { |
ec5acdce | 4403 | out << " TString infolog = \"" << mgr->GetFileInfoLog() << "\";" << endl; |
4404 | out << " AliAnalysisAlien::MergeInfo(infolog, outputDir);" << endl; | |
4405 | } | |
7c2cd90a | 4406 | out << " // all outputs merged, validate" << endl; |
4407 | out << " ofstream out;" << endl; | |
4408 | out << " out.open(\"outputs_valid\", ios::out);" << endl; | |
4409 | out << " out.close();" << endl; | |
4410 | out << " // read the analysis manager from file" << endl; | |
d66aa2a9 | 4411 | if (IsLocalTest()) { |
4412 | out << " printf(\"===================================\n\");" << endl; | |
4413 | out << " printf(\"Testing Terminate()...\\n\");" << endl; | |
4414 | out << " printf(\"===================================\n\");" << endl; | |
4415 | } else { | |
4416 | out << " if (!outputDir.Contains(\"Stage\")) return;" << endl; | |
4417 | } | |
5c4250fc | 4418 | out << " mgr->SetRunFromPath(mgr->GetRunFromAlienPath(dir));" << endl; |
b385fec0 | 4419 | out << " mgr->SetSkipTerminate(kFALSE);" << endl; |
f866cba5 | 4420 | out << " mgr->PrintStatus();" << endl; |
ec5acdce | 4421 | if (mgr) { |
4422 | if (mgr->GetDebugLevel()>3) { | |
f866cba5 | 4423 | out << " gEnv->SetValue(\"XNet.Debug\", \"1\");" << endl; |
4424 | } else { | |
9a8288ff | 4425 | if (TestBit(AliAnalysisGrid::kTest)) |
4426 | out << " AliLog::SetGlobalLogLevel(AliLog::kWarning);" << endl; | |
4427 | else | |
4428 | out << " AliLog::SetGlobalLogLevel(AliLog::kError);" << endl; | |
f866cba5 | 4429 | } |
4430 | } | |
9a8288ff | 4431 | out << " TTree *tree = NULL;" << endl; |
4432 | out << " mgr->StartAnalysis(\"gridterminate\", tree);" << endl; | |
0f389141 | 4433 | out << "}" << endl << endl; |
5b273635 | 4434 | if (hasANALYSISalice) { |
4435 | out <<"//________________________________________________________________________________" << endl; | |
4436 | out << "Bool_t SetupPar(const char *package) {" << endl; | |
4437 | out << "// Compile the package and set it up." << endl; | |
4438 | out << " TString pkgdir = package;" << endl; | |
4439 | out << " pkgdir.ReplaceAll(\".par\",\"\");" << endl; | |
b50a41c3 | 4440 | out << " gSystem->Exec(TString::Format(\"tar xvzf %s.par\", pkgdir.Data()));" << endl; |
5b273635 | 4441 | out << " TString cdir = gSystem->WorkingDirectory();" << endl; |
4442 | out << " gSystem->ChangeDirectory(pkgdir);" << endl; | |
4443 | out << " // Check for BUILD.sh and execute" << endl; | |
4444 | out << " if (!gSystem->AccessPathName(\"PROOF-INF/BUILD.sh\")) {" << endl; | |
4445 | out << " printf(\"*******************************\\n\");" << endl; | |
4446 | out << " printf(\"*** Building PAR archive ***\\n\");" << endl; | |
4447 | out << " printf(\"*******************************\\n\");" << endl; | |
4448 | out << " if (gSystem->Exec(\"PROOF-INF/BUILD.sh\")) {" << endl; | |
4449 | out << " ::Error(\"SetupPar\", \"Cannot build par archive %s\", pkgdir.Data());" << endl; | |
4450 | out << " gSystem->ChangeDirectory(cdir);" << endl; | |
4451 | out << " return kFALSE;" << endl; | |
4452 | out << " }" << endl; | |
4453 | out << " } else {" << endl; | |
4454 | out << " ::Error(\"SetupPar\",\"Cannot access PROOF-INF/BUILD.sh for package %s\", pkgdir.Data());" << endl; | |
4455 | out << " gSystem->ChangeDirectory(cdir);" << endl; | |
4456 | out << " return kFALSE;" << endl; | |
4457 | out << " }" << endl; | |
4458 | out << " // Check for SETUP.C and execute" << endl; | |
4459 | out << " if (!gSystem->AccessPathName(\"PROOF-INF/SETUP.C\")) {" << endl; | |
4460 | out << " printf(\"*******************************\\n\");" << endl; | |
4461 | out << " printf(\"*** Setup PAR archive ***\\n\");" << endl; | |
4462 | out << " printf(\"*******************************\\n\");" << endl; | |
4463 | out << " gROOT->Macro(\"PROOF-INF/SETUP.C\");" << endl; | |
4464 | out << " } else {" << endl; | |
4465 | out << " ::Error(\"SetupPar\",\"Cannot access PROOF-INF/SETUP.C for package %s\", pkgdir.Data());" << endl; | |
4466 | out << " gSystem->ChangeDirectory(cdir);" << endl; | |
4467 | out << " return kFALSE;" << endl; | |
4468 | out << " }" << endl; | |
4469 | out << " // Restore original workdir" << endl; | |
4470 | out << " gSystem->ChangeDirectory(cdir);" << endl; | |
4471 | out << " return kTRUE;" << endl; | |
4472 | out << "}" << endl; | |
4473 | } | |
0f389141 | 4474 | } |
4475 | Bool_t copy = kTRUE; | |
d3b18c4c | 4476 | if (fProductionMode || TestBit(AliAnalysisGrid::kOffline) || TestBit(AliAnalysisGrid::kTest)) copy = kFALSE; |
0f389141 | 4477 | if (copy) { |
4478 | CdWork(); | |
4479 | TString workdir = gGrid->GetHomeDirectory(); | |
4480 | workdir += fGridWorkingDir; | |
4481 | if (FileExists(mergingMacro)) gGrid->Rm(mergingMacro); | |
4482 | Info("WriteMergingMacro", "\n##### Copying merging macro: <%s> to your alien workspace", mergingMacro.Data()); | |
6c395669 | 4483 | // TFile::Cp(Form("file:%s",mergingMacro.Data()), Form("alien://%s/%s", workdir.Data(), mergingMacro.Data())); |
4484 | if (!copyLocal2Alien("WriteMergeMacro",mergingMacro.Data(), | |
4485 | Form("%s/%s", workdir.Data(), mergingMacro.Data()))) Fatal("","Terminating"); | |
0f389141 | 4486 | } |
4487 | } | |
4488 | ||
4489 | //______________________________________________________________________________ | |
4490 | Bool_t AliAnalysisAlien::SetupPar(const char *package) | |
4491 | { | |
205b201f | 4492 | // Compile the par file archive pointed by <package>. This must be present in the current directory. |
0f389141 | 4493 | // Note that for loading the compiled library. The current directory should have precedence in |
4494 | // LD_LIBRARY_PATH | |
4495 | TString pkgdir = package; | |
4496 | pkgdir.ReplaceAll(".par",""); | |
b50a41c3 | 4497 | gSystem->Exec(TString::Format("tar xzf %s.par", pkgdir.Data())); |
0f389141 | 4498 | TString cdir = gSystem->WorkingDirectory(); |
4499 | gSystem->ChangeDirectory(pkgdir); | |
4500 | // Check for BUILD.sh and execute | |
4501 | if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) { | |
4502 | printf("**************************************************\n"); | |
4503 | printf("*** Building PAR archive %s\n", package); | |
4504 | printf("**************************************************\n"); | |
4505 | if (gSystem->Exec("PROOF-INF/BUILD.sh")) { | |
4506 | ::Error("SetupPar", "Cannot build par archive %s", pkgdir.Data()); | |
4507 | gSystem->ChangeDirectory(cdir); | |
4508 | return kFALSE; | |
4509 | } | |
4510 | } else { | |
4511 | ::Error("SetupPar","Cannot access PROOF-INF/BUILD.sh for package %s", pkgdir.Data()); | |
4512 | gSystem->ChangeDirectory(cdir); | |
4513 | return kFALSE; | |
4514 | } | |
4515 | // Check for SETUP.C and execute | |
4516 | if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) { | |
4517 | printf("**************************************************\n"); | |
4518 | printf("*** Setup PAR archive %s\n", package); | |
4519 | printf("**************************************************\n"); | |
4520 | gROOT->Macro("PROOF-INF/SETUP.C"); | |
4521 | printf("*** Loaded library: %s\n", gSystem->GetLibraries(pkgdir,"",kFALSE)); | |
4522 | } else { | |
4523 | ::Error("SetupPar","Cannot access PROOF-INF/SETUP.C for package %s", pkgdir.Data()); | |
4524 | gSystem->ChangeDirectory(cdir); | |
4525 | return kFALSE; | |
4526 | } | |
4527 | // Restore original workdir | |
4528 | gSystem->ChangeDirectory(cdir); | |
4529 | return kTRUE; | |
4530 | } | |
4531 | ||
c57f56b7 | 4532 | //______________________________________________________________________________ |
4533 | void AliAnalysisAlien::WriteExecutable() | |
4534 | { | |
4535 | // Generate the alien executable script. | |
5aa94dc3 | 4536 | // Patch executable with -x to catch error code |
4537 | if (fExecutableCommand.Contains("root") && | |
4538 | fExecutableCommand.Contains("-q") && | |
4539 | !fExecutableCommand.Contains("-x")) fExecutableCommand += " -x"; | |
c57f56b7 | 4540 | if (!TestBit(AliAnalysisGrid::kSubmit)) { |
4541 | ofstream out; | |
4542 | out.open(fExecutable.Data(), ios::out); | |
4543 | if (out.bad()) { | |
5513444a | 4544 | Error("WriteExecutable", "Bad file name for executable: %s", fExecutable.Data()); |
c57f56b7 | 4545 | return; |
4546 | } | |
4547 | out << "#!/bin/bash" << endl; | |
2a4d5166 | 4548 | // Make sure we can properly compile par files |
4549 | out << "export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH" << endl; | |
c57f56b7 | 4550 | out << "echo \"=========================================\"" << endl; |
4551 | out << "echo \"############## PATH : ##############\"" << endl; | |
4552 | out << "echo $PATH" << endl; | |
4553 | out << "echo \"############## LD_LIBRARY_PATH : ##############\"" << endl; | |
4554 | out << "echo $LD_LIBRARY_PATH" << endl; | |
4555 | out << "echo \"############## ROOTSYS : ##############\"" << endl; | |
4556 | out << "echo $ROOTSYS" << endl; | |
4557 | out << "echo \"############## which root : ##############\"" << endl; | |
4558 | out << "which root" << endl; | |
4559 | out << "echo \"############## ALICE_ROOT : ##############\"" << endl; | |
4560 | out << "echo $ALICE_ROOT" << endl; | |
4561 | out << "echo \"############## which aliroot : ##############\"" << endl; | |
4562 | out << "which aliroot" << endl; | |
9c5ddadc | 4563 | out << "echo \"############## system limits : ##############\"" << endl; |
4564 | out << "ulimit -a" << endl; | |
4565 | out << "echo \"############## memory : ##############\"" << endl; | |
4566 | out << "free -m" << endl; | |
c57f56b7 | 4567 | out << "echo \"=========================================\"" << endl << endl; |
0a1c1f7f | 4568 | out << fExecutableCommand << " "; |
370c9880 | 4569 | out << fAnalysisMacro.Data() << " " << fExecutableArgs.Data() << endl; |
4570 | out << "RET=$?" << endl; | |
4571 | out << "if [ \"$RET\" != \"0\" ];then" << endl; | |
4572 | out << " echo \"======== ERROR : " << fAnalysisMacro.Data() << " finished with NON zero code: $RET ========\"" << endl; | |
4573 | out << " if [ \"$RET\" -gt 128 ] && [ \"$RET\" -lt 160 ]; then"<<endl; | |
4574 | out << " let sig=\"$RET - 128\""<<endl; | |
4575 | out << " sigs='HUP INT QUIT ILL TRAP ABRT BUS FPE"<<endl; | |
4576 | out << " KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT"<<endl; | |
4577 | out << " CHLD CONT STOP TSTP TTIN TTOU URG XCPU"<<endl; | |
4578 | out << " XFSZ VTALRM PROF WINCH IO PWR SYS'"<<endl; | |
4579 | out << " sig=SIG`echo $sigs | awk '{ print $'\"$sig\"' }'`"<<endl; | |
4580 | out << " echo \"======== it appears to have been killed with signal: $sig ========\""<<endl; | |
4581 | out << " fi"<<endl; | |
4582 | out << " exit $RET"<< endl; | |
4583 | out << "fi" << endl << endl ; | |
4584 | out << "echo \"======== " << fAnalysisMacro.Data() << " finished with exit code: $RET ========\"" << endl; | |
9c5ddadc | 4585 | out << "echo \"############## memory after: ##############\"" << endl; |
4586 | out << "free -m" << endl; | |
c57f56b7 | 4587 | } |
4588 | Bool_t copy = kTRUE; | |
d3b18c4c | 4589 | if (fProductionMode || TestBit(AliAnalysisGrid::kOffline) || TestBit(AliAnalysisGrid::kTest)) copy = kFALSE; |
c57f56b7 | 4590 | if (copy) { |
4591 | CdWork(); | |
4592 | TString workdir = gGrid->GetHomeDirectory(); | |
923e2ca5 | 4593 | TString bindir = Form("%s/bin", workdir.Data()); |
b93f8109 | 4594 | if (!DirectoryExists(bindir)) gGrid->Mkdir(bindir,"-p"); |
c57f56b7 | 4595 | workdir += fGridWorkingDir; |
4596 | TString executable = Form("%s/bin/%s", gGrid->GetHomeDirectory(), fExecutable.Data()); | |
4597 | if (FileExists(executable)) gGrid->Rm(executable); | |
d3b18c4c | 4598 | Info("WriteExecutable", "\n##### Copying executable file <%s> to your AliEn bin directory", fExecutable.Data()); |
6c395669 | 4599 | // TFile::Cp(Form("file:%s",fExecutable.Data()), Form("alien://%s", executable.Data())); |
4600 | if (!copyLocal2Alien("WriteExecutable",fExecutable.Data(), | |
4601 | executable.Data())) Fatal("","Terminating"); | |
c57f56b7 | 4602 | } |
4603 | } | |
4604 | ||
0f389141 | 4605 | //______________________________________________________________________________ |
4606 | void AliAnalysisAlien::WriteMergeExecutable() | |
4607 | { | |
4608 | // Generate the alien executable script for the merging job. | |
4609 | if (!fMergeViaJDL) return; | |
4610 | TString mergeExec = fExecutable; | |
4611 | mergeExec.ReplaceAll(".sh", "_merge.sh"); | |
4612 | if (!TestBit(AliAnalysisGrid::kSubmit)) { | |
4613 | ofstream out; | |
4614 | out.open(mergeExec.Data(), ios::out); | |
4615 | if (out.bad()) { | |
4616 | Error("WriteMergingExecutable", "Bad file name for executable: %s", mergeExec.Data()); | |
4617 | return; | |
4618 | } | |
4619 | out << "#!/bin/bash" << endl; | |
2a4d5166 | 4620 | // Make sure we can properly compile par files |
4621 | out << "export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH" << endl; | |
0f389141 | 4622 | out << "echo \"=========================================\"" << endl; |
4623 | out << "echo \"############## PATH : ##############\"" << endl; | |
4624 | out << "echo $PATH" << endl; | |
4625 | out << "echo \"############## LD_LIBRARY_PATH : ##############\"" << endl; | |
4626 | out << "echo $LD_LIBRARY_PATH" << endl; | |
4627 | out << "echo \"############## ROOTSYS : ##############\"" << endl; | |
4628 | out << "echo $ROOTSYS" << endl; | |
4629 | out << "echo \"############## which root : ##############\"" << endl; | |
4630 | out << "which root" << endl; | |
4631 | out << "echo \"############## ALICE_ROOT : ##############\"" << endl; | |
4632 | out << "echo $ALICE_ROOT" << endl; | |
4633 | out << "echo \"############## which aliroot : ##############\"" << endl; | |
4634 | out << "which aliroot" << endl; | |
4635 | out << "echo \"############## system limits : ##############\"" << endl; | |
4636 | out << "ulimit -a" << endl; | |
4637 | out << "echo \"############## memory : ##############\"" << endl; | |
4638 | out << "free -m" << endl; | |
4639 | out << "echo \"=========================================\"" << endl << endl; | |
0f389141 | 4640 | TString mergeMacro = fExecutable; |
4641 | mergeMacro.ReplaceAll(".sh", "_merge.C"); | |
f790bc1b | 4642 | if (IsOneStageMerging()) |
4643 | out << "export ARG=\"" << mergeMacro << "(\\\"$1\\\")\"" << endl; | |
4644 | else | |
f47d5cb4 | 4645 | out << "export ARG=\"" << mergeMacro << "(\\\"$1\\\",$2)\"" << endl; |
0f389141 | 4646 | out << fExecutableCommand << " " << "$ARG" << endl; |
370c9880 | 4647 | out << "RET=$?" << endl; |
4648 | out << "if [ \"$RET\" != \"0\" ];then" << endl; | |
4649 | out << " echo \"======== ERROR : " << fAnalysisMacro.Data() << " finished with NON zero code: $RET ========\"" << endl; | |
4650 | out << " if [ \"$RET\" -gt 128 ] && [ \"$RET\" -lt 160 ]; then"<<endl; | |
4651 | out << " let sig=\"$RET - 128\""<<endl; | |
4652 | out << " sigs='HUP INT QUIT ILL TRAP ABRT BUS FPE"<<endl; | |
4653 | out << " KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT"<<endl; | |
4654 | out << " CHLD CONT STOP TSTP TTIN TTOU URG XCPU"<<endl; | |
4655 | out << " XFSZ VTALRM PROF WINCH IO PWR SYS'"<<endl; | |
4656 | out << " sig=SIG`echo $sigs | awk '{ print $'\"$sig\"' }'`"<<endl; | |
4657 | out << " echo \"======== it appears to have been killed with signal: $sig ========\""<<endl; | |
4658 | out << " fi"<<endl; | |
4659 | out << " exit $RET"<< endl; | |
4660 | out << "fi" << endl << endl ; | |
0f389141 | 4661 | out << "echo \"======== " << mergeMacro.Data() << " finished with exit code: $? ========\"" << endl; |
4662 | out << "echo \"############## memory after: ##############\"" << endl; | |
4663 | out << "free -m" << endl; | |
0f389141 | 4664 | } |
4665 | Bool_t copy = kTRUE; | |
d3b18c4c | 4666 | if (fProductionMode || TestBit(AliAnalysisGrid::kOffline) || TestBit(AliAnalysisGrid::kTest)) copy = kFALSE; |
0f389141 | 4667 | if (copy) { |
4668 | CdWork(); | |
4669 | TString workdir = gGrid->GetHomeDirectory(); | |
4670 | TString bindir = Form("%s/bin", workdir.Data()); | |
b93f8109 | 4671 | if (!DirectoryExists(bindir)) gGrid->Mkdir(bindir,"-p"); |
0f389141 | 4672 | workdir += fGridWorkingDir; |
4673 | TString executable = Form("%s/bin/%s", gGrid->GetHomeDirectory(), mergeExec.Data()); | |
4674 | if (FileExists(executable)) gGrid->Rm(executable); | |
d3b18c4c | 4675 | Info("WriteMergeExecutable", "\n##### Copying executable file <%s> to your AliEn bin directory", mergeExec.Data()); |
6c395669 | 4676 | // TFile::Cp(Form("file:%s",mergeExec.Data()), Form("alien://%s", executable.Data())); |
4677 | if (!copyLocal2Alien("WriteMergeExecutable", | |
4678 | mergeExec.Data(), executable.Data())) Fatal("","Terminating"); | |
0f389141 | 4679 | } |
4680 | } | |
4681 | ||
c57f56b7 | 4682 | //______________________________________________________________________________ |
5513444a | 4683 | void AliAnalysisAlien::WriteProductionFile(const char *filename) const |
4684 | { | |
4685 | // Write the production file to be submitted by LPM manager. The format is: | |
f5e8c702 | 4686 | // First line: full_path_to_jdl estimated_no_subjobs_per_master |
5513444a | 4687 | // Next lines: full_path_to_dataset XXX (XXX is a string) |
4688 | // To submit, one has to: submit jdl XXX for all lines | |
4689 | ofstream out; | |
4690 | out.open(filename, ios::out); | |
4691 | if (out.bad()) { | |
4692 | Error("WriteProductionFile", "Bad file name: %s", filename); | |
4693 | return; | |
4694 | } | |
d3b18c4c | 4695 | TString workdir; |
4696 | if (!fProductionMode && !fGridWorkingDir.BeginsWith("/alice")) | |
4697 | workdir = gGrid->GetHomeDirectory(); | |
5513444a | 4698 | workdir += fGridWorkingDir; |
f5e8c702 | 4699 | Int_t njobspermaster = 1000*fNrunsPerMaster/fSplitMaxInputFileNumber; |
5513444a | 4700 | TString locjdl = Form("%s/%s", workdir.Data(),fJDLName.Data()); |
f5e8c702 | 4701 | out << locjdl << " " << njobspermaster << endl; |
5513444a | 4702 | Int_t nmasterjobs = fInputFiles->GetEntries(); |
4703 | for (Int_t i=0; i<nmasterjobs; i++) { | |
409b4ada | 4704 | TString runOutDir = gSystem->BaseName(fInputFiles->At(i)->GetName()); |
4705 | runOutDir.ReplaceAll(".xml", ""); | |
4706 | if (fOutputToRunNo) | |
4707 | out << Form("%s", fInputFiles->At(i)->GetName()) << " " << runOutDir << endl; | |
4708 | else | |
4709 | out << Form("%s", fInputFiles->At(i)->GetName()) << " " << Form("%03d", i) << endl; | |
5513444a | 4710 | } |
d3b18c4c | 4711 | if (gGrid) { |
4712 | Info("WriteProductionFile", "\n##### Copying production file <%s> to your work directory", filename); | |
4713 | if (FileExists(filename)) gGrid->Rm(filename); | |
6c395669 | 4714 | // TFile::Cp(Form("file:%s",filename), Form("alien://%s/%s", workdir.Data(),filename)); |
4715 | if (!copyLocal2Alien("WriteProductionFile", filename, | |
4716 | Form("%s/%s", workdir.Data(),filename))) Fatal("","Terminating"); | |
d3b18c4c | 4717 | } |
5513444a | 4718 | } |
4719 | ||
4720 | //______________________________________________________________________________ | |
0f389141 | 4721 | void AliAnalysisAlien::WriteValidationScript(Bool_t merge) |
c57f56b7 | 4722 | { |
4723 | // Generate the alien validation script. | |
4724 | // Generate the validation script | |
4725 | TObjString *os; | |
d3b18c4c | 4726 | if (fValidationScript.IsNull()) { |
4727 | fValidationScript = fExecutable; | |
4728 | fValidationScript.ReplaceAll(".sh", "_validation.sh"); | |
4729 | } | |
4730 | TString validationScript = fValidationScript; | |
4731 | if (merge) validationScript.ReplaceAll(".sh", "_merge.sh"); | |
c57f56b7 | 4732 | if (!Connect()) { |
4733 | Error("WriteValidationScript", "Alien connection required"); | |
4734 | return; | |
4735 | } | |
d3b18c4c | 4736 | if (!fTerminateFiles.IsNull()) { |
4737 | fTerminateFiles.Strip(); | |
4738 | fTerminateFiles.ReplaceAll(" ",","); | |
4739 | } | |
a2f5fc01 | 4740 | TString outStream = ""; |
4741 | if (!TestBit(AliAnalysisGrid::kTest)) outStream = " >> stdout"; | |
c57f56b7 | 4742 | if (!TestBit(AliAnalysisGrid::kSubmit)) { |
4743 | ofstream out; | |
0d5d317c | 4744 | out.open(validationScript, ios::out); |
c57f56b7 | 4745 | out << "#!/bin/bash" << endl; |
4746 | out << "##################################################" << endl; | |
4747 | out << "validateout=`dirname $0`" << endl; | |
4748 | out << "validatetime=`date`" << endl; | |
4749 | out << "validated=\"0\";" << endl; | |
4750 | out << "error=0" << endl; | |
4751 | out << "if [ -z $validateout ]" << endl; | |
4752 | out << "then" << endl; | |
4753 | out << " validateout=\".\"" << endl; | |
4754 | out << "fi" << endl << endl; | |
4755 | out << "cd $validateout;" << endl; | |
4756 | out << "validateworkdir=`pwd`;" << endl << endl; | |
a2f5fc01 | 4757 | out << "echo \"*******************************************************\"" << outStream << endl; |
4758 | out << "echo \"* Automatically generated validation script *\"" << outStream << endl; | |
c57f56b7 | 4759 | out << "" << endl; |
a2f5fc01 | 4760 | out << "echo \"* Time: $validatetime \"" << outStream << endl; |
4761 | out << "echo \"* Dir: $validateout\"" << outStream << endl; | |
4762 | out << "echo \"* Workdir: $validateworkdir\"" << outStream << endl; | |
4763 | out << "echo \"* ----------------------------------------------------*\"" << outStream << endl; | |
4764 | out << "ls -la ./" << outStream << endl; | |
4765 | out << "echo \"* ----------------------------------------------------*\"" << outStream << endl << endl; | |
c57f56b7 | 4766 | out << "##################################################" << endl; |
ebec370a | 4767 | out << "" << endl; |
4768 | ||
4769 | out << "if [ ! -f stderr ] ; then" << endl; | |
4770 | out << " error=1" << endl; | |
a2f5fc01 | 4771 | out << " echo \"* ########## Job not validated - no stderr ###\" " << outStream << endl; |
4772 | out << " echo \"Error = $error\" " << outStream << endl; | |
ebec370a | 4773 | out << "fi" << endl; |
4774 | ||
b34c9f51 | 4775 | out << "parArch=`grep -Ei \"Cannot Build the PAR Archive\" stderr`" << endl; |
4776 | out << "segViol=`grep -Ei \"Segmentation violation\" stderr`" << endl; | |
4777 | out << "segFault=`grep -Ei \"Segmentation fault\" stderr`" << endl; | |
4778 | out << "glibcErr=`grep -Ei \"*** glibc detected ***\" stderr`" << endl; | |
4779 | out << "" << endl; | |
4780 | ||
ebec370a | 4781 | out << "if [ \"$parArch\" != \"\" ] ; then" << endl; |
4782 | out << " error=1" << endl; | |
a2f5fc01 | 4783 | out << " echo \"* ########## Job not validated - PAR archive not built ###\" " << outStream << endl; |
4784 | out << " echo \"$parArch\" " << outStream << endl; | |
4785 | out << " echo \"Error = $error\" " << outStream << endl; | |
ebec370a | 4786 | out << "fi" << endl; |
4787 | ||
4788 | out << "if [ \"$segViol\" != \"\" ] ; then" << endl; | |
4789 | out << " error=1" << endl; | |
a2f5fc01 | 4790 | out << " echo \"* ########## Job not validated - Segment. violation ###\" " << outStream << endl; |
4791 | out << " echo \"$segViol\" " << outStream << endl; | |
4792 | out << " echo \"Error = $error\" " << outStream << endl; | |
ebec370a | 4793 | out << "fi" << endl; |
4794 | ||
4795 | out << "if [ \"$segFault\" != \"\" ] ; then" << endl; | |
4796 | out << " error=1" << endl; | |
a2f5fc01 | 4797 | out << " echo \"* ########## Job not validated - Segment. fault ###\" " << outStream << endl; |
4798 | out << " echo \"$segFault\" " << outStream << endl; | |
4799 | out << " echo \"Error = $error\" " << outStream << endl; | |
ebec370a | 4800 | out << "fi" << endl; |
4801 | ||
b34c9f51 | 4802 | out << "if [ \"$glibcErr\" != \"\" ] ; then" << endl; |
4803 | out << " error=1" << endl; | |
a2f5fc01 | 4804 | out << " echo \"* ########## Job not validated - *** glibc detected *** ###\" " << outStream << endl; |
4805 | out << " echo \"$glibcErr\" " << outStream << endl; | |
4806 | out << " echo \"Error = $error\" " << outStream << endl; | |
b34c9f51 | 4807 | out << "fi" << endl; |
4808 | ||
ebec370a | 4809 | // Part dedicated to the specific analyses running into the train |
4810 | ||
d3b18c4c | 4811 | TString outputFiles = fOutputFiles; |
4812 | if (merge && !fTerminateFiles.IsNull()) { | |
4813 | outputFiles += ","; | |
4814 | outputFiles += fTerminateFiles; | |
4815 | } | |
4816 | TObjArray *arr = outputFiles.Tokenize(","); | |
c57f56b7 | 4817 | TIter next1(arr); |
a2f5fc01 | 4818 | TString outputFile; |
bbd88db8 | 4819 | while (!merge && (os=(TObjString*)next1())) { |
4820 | // No need to validate outputs produced by merging since the merging macro does this | |
a2f5fc01 | 4821 | outputFile = os->GetString(); |
4822 | Int_t index = outputFile.Index("@"); | |
4823 | if (index > 0) outputFile.Remove(index); | |
bbd88db8 | 4824 | if (fTerminateFiles.Contains(outputFile)) continue; |
a2f5fc01 | 4825 | if (outputFile.Contains("*")) continue; |
4826 | out << "if ! [ -f " << outputFile.Data() << " ] ; then" << endl; | |
c57f56b7 | 4827 | out << " error=1" << endl; |
7c2cd90a | 4828 | out << " echo \"Output file " << outputFile << " not found. Job FAILED !\"" << outStream << endl; |
4829 | out << " echo \"Output file " << outputFile << " not found. Job FAILED !\" >> stderr" << endl; | |
c57f56b7 | 4830 | out << "fi" << endl; |
4831 | } | |
4832 | delete arr; | |
7c2cd90a | 4833 | out << "if ! [ -f outputs_valid ] ; then" << endl; |
4834 | out << " error=1" << endl; | |
4835 | out << " echo \"Output files were not validated by the analysis manager\" >> stdout" << endl; | |
4836 | out << " echo \"Output files were not validated by the analysis manager\" >> stderr" << endl; | |
4837 | out << "fi" << endl; | |
923e2ca5 | 4838 | |
c57f56b7 | 4839 | out << "if [ $error = 0 ] ; then" << endl; |
a2f5fc01 | 4840 | out << " echo \"* ---------------- Job Validated ------------------*\"" << outStream << endl; |
149d288c | 4841 | if (!IsKeepLogs()) { |
4842 | out << " echo \"* === Logs std* will be deleted === \"" << endl; | |
a2f5fc01 | 4843 | outStream = ""; |
149d288c | 4844 | out << " rm -f std*" << endl; |
4845 | } | |
c57f56b7 | 4846 | out << "fi" << endl; |
4847 | ||
a2f5fc01 | 4848 | out << "echo \"* ----------------------------------------------------*\"" << outStream << endl; |
4849 | out << "echo \"*******************************************************\"" << outStream << endl; | |
c57f56b7 | 4850 | out << "cd -" << endl; |
4851 | out << "exit $error" << endl; | |
4852 | } | |
4853 | Bool_t copy = kTRUE; | |
d3b18c4c | 4854 | if (fProductionMode || TestBit(AliAnalysisGrid::kOffline) || TestBit(AliAnalysisGrid::kTest)) copy = kFALSE; |
c57f56b7 | 4855 | if (copy) { |
4856 | CdWork(); | |
4857 | TString workdir = gGrid->GetHomeDirectory(); | |
4858 | workdir += fGridWorkingDir; | |
d3b18c4c | 4859 | Info("WriteValidationScript", "\n##### Copying validation script <%s> to your AliEn working space", validationScript.Data()); |
0d5d317c | 4860 | if (FileExists(validationScript)) gGrid->Rm(validationScript); |
6c395669 | 4861 | // TFile::Cp(Form("file:%s",validationScript.Data()), Form("alien://%s/%s", workdir.Data(),validationScript.Data())); |
4862 | if (!copyLocal2Alien("WriteValidationScript", validationScript.Data(), | |
4863 | Form("%s/%s",workdir.Data(), validationScript.Data()))) Fatal("","Terminating"); | |
c57f56b7 | 4864 | } |
4865 | } |