]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/macros/electrons/mylauncher.C
Reader: Add option to remove or not event with primary vertex not reconstructed
[u/mrichter/AliRoot.git] / PWG4 / macros / electrons / mylauncher.C
CommitLineData
abde65b8 1
2//
3727cc7a 3// AliEn Multi MasterJob Coordination
abde65b8 4// Author: K. Read
5//
6
7void mylauncher()
8{
3727cc7a 9 TString worksubdir = "work12"; //already existing work directory
10//TString worksubdir = "LHC09b4"; //a better name for MultiMode
abde65b8 11 // Name of JDL file to upload. Leave blank for no upload and no submit.
3727cc7a 12 TString jdlfilename = "anaJete.jdl";//ignored for MultiMode
abde65b8 13 // Name of executable to upload. Leave blank for no upload.
3727cc7a 14 TString collectfilename = "mycollect.xml";//ignored for MultiMode
15 // List any other files to upload in string filenames separated by blanks.
b21a4af6 16 TString execfilename = "";
abde65b8 17 // List any other files to upload in string filenames separated by blanks.
cbb6a40e 18 TString filelist = "run.C validate.sh anaJete.C ConfigJetAnalysisFastJet.C ConfigAnalysisElectron.C mergeout.jdl mergeoutscaled.jdl ANALYSIS.par ANALYSISalice.par AOD.par EMCALUtils.par ESD.par PHOSUtils.par STEERBase.par JETAN.par FASTJETAN.par PWG4PartCorrBase.par PWG4PartCorrDep.par";
abde65b8 19 TString filename;
20
3727cc7a 21 Bool_t kMultiMode = kFALSE;//uncomment for regular mode
22//Bool_t kMultiMode = kTRUE; //uncomment for coordinated multiple masterjobs
23//MultiMode Variables. All ignored for regular mode.
24 TString multijdlfilename = "anaJetemulti.jdl";
25//TString datatype = "AliESDs.root";//uncomment for ESDs
26 TString datatype = "AliAOD.root";//uncomment for AODs
27 TString findlist = "
28/alice/sim/LHC09b4/AOD/000
29/alice/sim/LHC09b4/AOD/001
30/alice/sim/LHC09b4/AOD/002"; //line-feed separated list of desired collections
31
32
abde65b8 33 gSystem->Load("libNetx.so") ;
34 gSystem->Load("libRAliEn.so");
35
36 TGrid::Connect("alien://") ;
37 if (gGrid && gGrid->IsConnected()) {
38 TString homedir = gGrid->GetHomeDirectory(); // has a trailing slash
39 TString workdir = homedir + worksubdir;
40 if (gGrid->Cd(workdir)) {
41
42 // Upload files listed
43 if (filelist.Length()) {
3727cc7a 44 arr = filelist.Tokenize(" ");
45 TObjString *os;
46 TIter next(arr);
47 while ((os=(TObjString*)next())) {
48 Info("Grid Upload", "Copying %s to your AliEn work directory", os->GetString().Data());
49 if (FileExists(os->GetString())) gGrid->Rm(os->GetString());
50 TFile::Cp(Form("file:%s",os->GetString().Data()), Form("alien://%s/%s", workdir.Data(), os->GetString().Data()));
51 }
52 delete arr;
53 }
54
55 // Prepare collection(s)
56 if(kMultiMode){
57 // Find collections if desired
58 if (findlist.Length()) {
59 arr = findlist.Tokenize("\n");
60 TObjString *os;
61 TIter next(arr);
62 Int_t count=0;
63 while ((os=(TObjString*)next())) {
64 TGridResult *res;
936886ce 65 Info("Find", "Making collection for %s", os->GetString().Data());
884b4024 66 res = gGrid->Command(Form("find -x collection %s %s > mycollect%02d.xml", os->GetString().Data(),datatype.Data(),count));
936886ce 67 if(!res) Info("Find", "Failed making collection for %s \n",os->GetString().Data());
3727cc7a 68 delete res;
69 count++;
70 }
71 }
72 }
73 else{
74 if (collectfilename.Length()) {
75 Info("Grid Upload", "Copying %s to your AliEn work directory", collectfilename.Data());
76 if (FileExists(collectfilename)) gGrid->Rm(collectfilename);
77 TFile::Cp(Form("file:%s",collectfilename.Data()), Form("alien://%s/%s", workdir.Data(), collectfilename.Data()));
78 }
abde65b8 79 }
80
81 // Upload executable if listed
82 if (execfilename.Length()) {
83 filename = Form("%sbin/%s", homedir.Data(), execfilename.Data());
84 if (FileExists(filename)) gGrid->Rm(filename);
85 Info("Grid Upload", "Copying executable file %s to your AliEn bin directory", execfilename.Data());
86 TFile::Cp(Form("file:%s",execfilename.Data()), Form("alien://%s", filename.Data()));
87 }
88
89 // Upload and submit JDL if listed
3727cc7a 90 if (kMultiMode) jdlfilename = multijdlfilename;
abde65b8 91 if (jdlfilename.Length()) {
92 filename = Form("%s/%s", workdir.Data(), jdlfilename.Data());
93 if (FileExists(filename)) gGrid->Rm(filename);
94 Info("Grid Upload", "Copying JDL file %s to your AliEn work directory", jdlfilename.Data());
95 TFile::Cp(Form("file:%s",jdlfilename.Data()), Form("alien://%s", filename.Data()));
96
3727cc7a 97 if (!kMultiMode) Int_t count=1;
98 for (Int_t index = 0; index < count; index++) {
99 TGridResult *res;
100 TString jobID = "";
101 if(kMultiMode){
884b4024 102 res = gGrid->Command(Form("submit %s %s %02d", jdlfilename.Data(),worksubdir.Data(),index));
103 Info("Launcher:", "Submitting %s %s %02d", jdlfilename.Data(),worksubdir.Data(),index);
3727cc7a 104 }
105 else{
106 res = gGrid->Command(Form("submit %s", jdlfilename.Data()));
107 Info("Launcher:", "Submitting %s", jdlfilename.Data());
108 }
109 if (res) {
110 const char *cjobId = res->GetKey(0,"jobId");
111 if (!cjobId) {
112 Error("Launcher:", "Your JDL %s could not be submitted", jdlfilename.Data());
113 return;
114 }
115 else {
116 Info("Launcher:", "Your JDL %s was successfully submitted.\n\n\t\t\t THE JOB ID IS: %s\n",
117 jdlfilename.Data(), cjobId);
118 }
119 delete res;
120 }
abde65b8 121 }
122 }
123
124 // Launch alien shell
125 gSystem->Exec("aliensh");
126
127 }
128 }
129}
130
131Bool_t FileExists(const char *lfn) const
132{
133// Returns true if file exists.
134 if (!gGrid) {
135 Error("FileExists", "No connection to grid");
136 return kFALSE;
137 }
138 TGridResult *res = gGrid->Ls(lfn);
139 if (!res) return kFALSE;
140 TMap *map = dynamic_cast<TMap*>(res->At(0));
141 if (!map) {
142 delete res;
143 return kFALSE;
144 }
145 TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("name"));
146 if (!objs || !objs->GetString().Length()) {
147 delete res;
148 return kFALSE;
149 }
150 delete res;
151 return kTRUE;
152}