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