]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisGrid.cxx
Update
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisGrid.cxx
CommitLineData
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// AliAnalysisGrid - Base grid utility class. Provides interface for creating
20// a personalized JDL, finding and creating a dataset.
21//==============================================================================
22
23#include "TSystem.h"
24#include "AliAnalysisGrid.h"
25
26ClassImp(AliAnalysisGrid)
27
28//______________________________________________________________________________
29AliAnalysisGrid::AliAnalysisGrid(const AliAnalysisGrid& other)
348be253 30 :TNamed(other), fSpecialBits(0)
c57f56b7 31{
32// Copy ctor.
33}
34
35//______________________________________________________________________________
36AliAnalysisGrid &AliAnalysisGrid::operator=(const AliAnalysisGrid& other)
37{
38// Assignment.
39 if (this != &other) {
40 TNamed::operator=(other);
348be253 41 fSpecialBits = other.fSpecialBits;
c57f56b7 42 }
43 return *this;
44}
45
46//______________________________________________________________________________
47Bool_t AliAnalysisGrid::CreateToken(const char *username)
48{
49// Check if a valid token exists - if not create one
50 TString user = gSystem->Getenv("USER");
51 if (!user.Length()) {
52 printf("Error in AliAnalysisGrid::CreateToken: $USER environment empty");
53 return kFALSE;
54 }
55 Int_t err_msg = gSystem->Exec("no_command > /dev/null 2>/dev/null");
56 Int_t token_value = gSystem->Exec("bash alien-token-info > /dev/null 2>/dev/null");
57 if (token_value == err_msg) {
58 printf("Error in AliAnalysisGrid::CreateToken: You do not seem to have <alien-token-info> in your path.");
59 return kFALSE;
60 }
61
62 Bool_t to_create_token = kFALSE;
63 if (!token_value) {
64 // Token still valid, check alien_API_USER environment
65 TString token_user = gSystem->Getenv("alien_API_USER");
66 if (token_user.Length()) {
67 // Environment file sourced
68 if (!username) return kTRUE; // for default $USER
69 if (token_user == username) return kTRUE; // for <username>
70 // A valid token existing, and environment sourced, but for a different user
71 to_create_token = kTRUE;
72 }
73 } else {
74 // Token not valid anymore for <username>. Call alien-token-init
75 to_create_token = kTRUE;
76 }
77 if (to_create_token) {
78 printf("______________________________________________________________________________________\n");
79 printf("AliAnalysisGrid::CreateToken: Seems you need a token. Calling alien-token-init for you\n");
80 printf("______________________________________________________________________________________\n");
81 Int_t token_init = 0;
82 if (username) token_init = gSystem->Exec(Form("alien-token-init %s", username));
83 else token_init = gSystem->Exec("alien-token-init");
84 if (token_init == err_msg) {
85 printf(" Woops - semms alien-token-init is not in your path...\n");
86 return kFALSE;
87 } else if (token_init != 0) {
88 printf(" Woops - did not succeed...\n");
89 return kFALSE;
90 }
91 }
92 // We have a valid token - just source it
93 printf("______________________________________________________________________________________\n");
94 printf("AliAnalysisGrid::CreateToken: Your token needs to be sourced in the current shell\n");
95 printf(" USE: > source /tmp/gclient_env_%d\n", gSystem->GetUid(user));
96 printf("______________________________________________________________________________________\n");
97 return kFALSE;
98}
99
100//______________________________________________________________________________
101AliAnalysisGrid::EPluginRunMode AliAnalysisGrid::GetRunMode() const
102{
103// Get the current run mode.
104 if (TObject::TestBit(kTest)) return AliAnalysisGrid::kTest;
105 if (TObject::TestBit(kOffline)) return AliAnalysisGrid::kOffline;
106 if (TObject::TestBit(kSubmit)) return AliAnalysisGrid::kSubmit;
107 if (TObject::TestBit(kMerge)) return AliAnalysisGrid::kMerge;
108 return AliAnalysisGrid::kFull;
109}
110
111//______________________________________________________________________________
112void AliAnalysisGrid::SetRunMode(const char *mode)
113{
114// Set the alien plugin run mode. All modes require presence of a valid token
115// and sourcing the AliEn environment. Supported modes are:
116// - full (default): Generates requested datasets, locally generates the JDL,
117// saves existing analysis manager to the file analysis.root,
118// generates analysis macro, execution and validation scripts,
119// copies all these files to AliEn working space and submits
120// the job leaving user in an AliEn shell.
121// - test : Generates only 10 entries of the first requested dataset and
122// copies this locally as wn.xml, generates all files from the
123// full run mode except the JDL and executes the analysis locally.
124// This mode can be used to test if the analysis may run in grid.
125// - offline : No dataset is produced, but all other files are locally generated.
126// No file is copied in AliEn workspace. This mode can be used to
127// customize the automatic JDL/analysis macro.
128// - submit : Datasets are generated in AliEn but the JDL and all the other
129// files are supposed to exist in the local directory. The files
130// are copied to AliEn and the job is submitted. This mode should
131// be used in correlation with "offline mode" to submit customized
132// analysis macro/jdl.
133// - merge : Only MergeOutputs() method called to merge the registered
134// outputs of a job that finished.
135 TString smode(mode);
136 smode.ToLower();
137 TObject::SetBit(kTest, kFALSE);
138 TObject::SetBit(kOffline, kFALSE);
139 TObject::SetBit(kSubmit, kFALSE);
140 TObject::SetBit(kMerge, kFALSE);
141 if (smode.Contains("test")) {
142 TObject::SetBit(kTest, kTRUE);
143 return;
144 }
145 if (smode.Contains("offline")) {
146 TObject::SetBit(kOffline, kTRUE);
348be253 147 SetUseCopy(kFALSE);
148 SetCheckCopy(kFALSE);
c57f56b7 149 return;
150 }
151 if (smode.Contains("submit")) {
152 TObject::SetBit(kSubmit, kTRUE);
153 return;
154 }
155 if (smode.Contains("merge") || smode.Contains("terminate")) {
156 TObject::SetBit(kMerge, kTRUE);
157 return;
158 }
159 if (!smode.Contains("full")) {
160 Warning("SetRunMode","Run mode \"%s\" not known. Supported modes: \"full\", \"test\", \"offline\", \"submit\" and \"merge\"", mode);
161 Warning("SetRunMode","Run mode set to FULL");
162 }
163}