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