]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/macros/electrons/mylauncher.C
Updated instructions for new electron macros.
[u/mrichter/AliRoot.git] / PWG4 / macros / electrons / mylauncher.C
CommitLineData
abde65b8 1
2//
3// Copy files to AliEn space and submit AliEn job
4// Author: K. Read
5//
6
7void mylauncher()
8{
9 TString worksubdir = "work4";
10 // Name of JDL file to upload. Leave blank for no upload and no submit.
11 TString jdlfilename = "anaElectron.jdl";
12 // Name of executable to upload. Leave blank for no upload.
13 TString execfilename = "anaElectron.sh";
14 // List any other files to upload in string filenames separated by blanks.
15 TString filelist = "anaElectron.C ConfigAnalysisElectron.C mergeElectron.jdl mycollect.xml ANALYSIS.par ANALYSISalice.par AOD.par ESD.par STEERBase.par PWG4PartCorrBase.par PWG4PartCorrDep.par";
16 TString filename;
17
18 gSystem->Load("libNetx.so") ;
19 gSystem->Load("libRAliEn.so");
20
21 TGrid::Connect("alien://") ;
22 if (gGrid && gGrid->IsConnected()) {
23 TString homedir = gGrid->GetHomeDirectory(); // has a trailing slash
24 TString workdir = homedir + worksubdir;
25 if (gGrid->Cd(workdir)) {
26
27 // Upload files listed
28 if (filelist.Length()) {
29 arr = filelist.Tokenize(" ");
30 TObjString *os;
31 TIter next(arr);
32 while ((os=(TObjString*)next())) {
33 Info("Grid Upload", "Copying %s to your AliEn work directory", os->GetString().Data());
34 if (FileExists(os->GetString())) gGrid->Rm(os->GetString());
35 TFile::Cp(Form("file:%s",os->GetString().Data()), Form("alien://%s/%s", workdir.Data(), os->GetString().Data()));
36 }
37 delete arr;
38 }
39
40 // Upload executable if listed
41 if (execfilename.Length()) {
42 filename = Form("%sbin/%s", homedir.Data(), execfilename.Data());
43 if (FileExists(filename)) gGrid->Rm(filename);
44 Info("Grid Upload", "Copying executable file %s to your AliEn bin directory", execfilename.Data());
45 TFile::Cp(Form("file:%s",execfilename.Data()), Form("alien://%s", filename.Data()));
46 }
47
48 // Upload and submit JDL if listed
49 if (jdlfilename.Length()) {
50 filename = Form("%s/%s", workdir.Data(), jdlfilename.Data());
51 if (FileExists(filename)) gGrid->Rm(filename);
52 Info("Grid Upload", "Copying JDL file %s to your AliEn work directory", jdlfilename.Data());
53 TFile::Cp(Form("file:%s",jdlfilename.Data()), Form("alien://%s", filename.Data()));
54
55 TGridResult *res;
56 TString jobID = "";
57 res = gGrid->Command(Form("submit %s", jdlfilename.Data()));
58 Info("Launcher:", "Submitting %s ", jdlfilename.Data());
59 if (res) {
60 const char *cjobId = res->GetKey(0,"jobId");
61 if (!cjobId) {
62 Error("Launcher:", "Your JDL %s could not be submitted", jdlfilename.Data());
63 return;
64 }
65 else {
66 Info("Launcher:", "Your JDL %s was successfully submitted.\n\n\t\t\t THE JOB ID IS: %s\n",
67 jdlfilename.Data(), cjobId);
68 }
69 delete res;
70 }
71 }
72
73 // Launch alien shell
74 gSystem->Exec("aliensh");
75
76 }
77 }
78}
79
80Bool_t FileExists(const char *lfn) const
81{
82// Returns true if file exists.
83 if (!gGrid) {
84 Error("FileExists", "No connection to grid");
85 return kFALSE;
86 }
87 TGridResult *res = gGrid->Ls(lfn);
88 if (!res) return kFALSE;
89 TMap *map = dynamic_cast<TMap*>(res->At(0));
90 if (!map) {
91 delete res;
92 return kFALSE;
93 }
94 TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("name"));
95 if (!objs || !objs->GetString().Length()) {
96 delete res;
97 return kFALSE;
98 }
99 delete res;
100 return kTRUE;
101}